From 2ef8f361d7b39a79b2120ae5b5d98da159e61bc3 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 1 Jun 2019 16:58:28 -0700 Subject: [PATCH] Merge non-sense, who knows, here goes --- 4coder_API/4coder_custom.h | 2 - 4coder_API/4coder_types.h | 86 +- 4coder_api_transition_30_31.cpp | 155 +- 4coder_api_transition_30_31_helpers.cpp | 379 +- 4coder_app_links_allocator.cpp | 54 + 4coder_auto_indent.cpp | 88 +- 4coder_base_commands.cpp | 579 +- 4coder_base_types.cpp | 5937 +++++++++++++++++-- 4coder_base_types.h | 1277 +++- 4coder_build_commands.cpp | 249 +- 4coder_build_commands.h | 6 - 4coder_clipboard.cpp | 91 +- 4coder_combined_write_commands.cpp | 62 +- 4coder_config.cpp | 734 +-- 4coder_config.h | 79 +- 4coder_default_framework.cpp | 117 +- 4coder_default_framework.h | 4 +- 4coder_default_framework_variables.cpp | 10 +- 4coder_default_hooks.cpp | 334 +- 4coder_default_include.cpp | 9 +- 4coder_experiments.cpp | 442 +- 4coder_fancy.cpp | 22 +- 4coder_fancy.h | 2 +- 4coder_file.h | 78 +- 4coder_font_helper.cpp | 37 +- 4coder_function_list.cpp | 116 +- 4coder_function_list.h | 6 - 4coder_generated/app_functions.h | 145 +- 4coder_generated/command_metadata.h | 1342 ++--- 4coder_helper.cpp | 730 ++- 4coder_helper.h | 23 +- 4coder_insertion.cpp | 63 +- 4coder_insertion.h | 4 +- 4coder_jump_direct.cpp | 26 +- 4coder_jump_lister.cpp | 22 +- 4coder_jump_sticky.cpp | 180 +- 4coder_jump_sticky.h | 5 + 4coder_jumping.cpp | 185 +- 4coder_jumping.h | 17 + 4coder_lib/4coder_arena.cpp | 46 +- 4coder_lib/4coder_arena.h | 49 +- 4coder_lib/4coder_heap.cpp | 18 +- 4coder_lib/4coder_heap.h | 60 +- 4coder_lib/4coder_string.h | 1022 ++-- 4coder_lib/4coder_table.h | 160 +- 4coder_lib/4coder_utf8.h | 244 +- 4coder_lib/4cpp_default_keywords.h | 8 +- 4coder_lib/4cpp_lexer.h | 499 +- 4coder_lib/4cpp_lexer_tables.c | 102 +- 4coder_lib/4cpp_lexer_types.h | 32 +- 4coder_lists.cpp | 359 +- 4coder_malloc_allocator.cpp | 48 + 4coder_metadata_generator.cpp | 259 +- 4coder_miblo_numbers.cpp | 227 +- 4coder_os_comp_cracking.h | 62 - 4coder_project_commands.cpp | 973 ++- 4coder_project_commands.h | 22 +- 4coder_remapping_commands.cpp | 34 +- 4coder_scope_commands.cpp | 152 +- 4coder_search.cpp | 407 +- 4coder_search.h | 8 +- 4coder_seek.cpp | 244 +- 4coder_stringf.cpp | 72 + 4coder_system_command.cpp | 31 +- 4coder_ui_helper.cpp | 212 +- 4coder_ui_helper.h | 28 +- 4ed.cpp | 208 +- 4ed.h | 7 +- 4ed_api_implementation.cpp | 439 +- 4ed_app_models.h | 4 +- 4ed_app_target.cpp | 11 +- 4ed_buffer.cpp | 78 +- 4ed_buffer.h | 7 +- 4ed_cli.cpp | 27 +- 4ed_code_wrap.cpp | 20 +- 4ed_command.cpp | 4 +- 4ed_defines.h | 31 - 4ed_dynamic_variables.cpp | 42 +- 4ed_dynamic_variables.h | 2 +- 4ed_edit.cpp | 65 +- 4ed_file.cpp | 72 +- 4ed_file.h | 5 +- 4ed_file_lex.cpp | 382 +- 4ed_font.cpp | 6 +- 4ed_font_provider_freetype.cpp | 35 +- 4ed_font_provider_freetype.h | 2 - 4ed_history.cpp | 53 +- 4ed_history.h | 2 +- 4ed_hot_directory.cpp | 63 +- 4ed_hot_directory.h | 8 +- 4ed_layout.cpp | 6 +- 4ed_mem.cpp | 83 +- 4ed_memory_bank.cpp | 4 +- 4ed_parse_context.cpp | 45 +- 4ed_parse_context.h | 4 +- 4ed_ptr_check.cpp | 4 - 4ed_render_format.cpp | 22 +- 4ed_render_target.h | 3 +- 4ed_system.h | 6 +- 4ed_text_layout.cpp | 3 +- 4ed_view.cpp | 74 +- 4ed_view.h | 17 +- 4ed_working_set.cpp | 350 +- 4ed_working_set.h | 16 +- build.bat | 2 +- build_site.bat | 3 - build_site.sh | 5 - build_string.bat | 3 - build_string.sh | 5 - buildsuper_x64.bat | 2 + meta/4ed_build.cpp | 262 +- meta/4ed_file_moving.h | 104 +- meta/4ed_fsm_table_generator.cpp | 127 +- meta/4ed_meta_defines.h | 6 +- meta/4ed_meta_generate_parser.cpp | 2 +- meta/4ed_meta_keywords.h | 16 +- meta/4ed_meta_parser.cpp | 389 +- meta/4ed_metagen.cpp | 962 +-- old_string_api.h | 245 + opengl/4ed_opengl_render.cpp | 11 +- platform_all/4ed_shared_init_logic.cpp | 11 +- platform_all/4ed_system_shared.cpp | 46 +- platform_all/4ed_system_shared.h | 6 +- platform_all/4ed_work_queues.cpp | 10 +- platform_linux/linux_4ed.cpp | 3 +- platform_mac/mac_4ed.cpp | 2 +- platform_mac/mac_4ed.m | 6 +- platform_win32/win32_4ed.cpp | 255 +- platform_win32/win32_4ed_functions.cpp | 13 +- platform_win32/win32_utf8.cpp | 69 +- platform_win32/win32_utf8.h | 20 +- project.4coder | 32 +- site/4ed_abstract_document.cpp | 2255 ------- site/4ed_sitegen.cpp | 369 -- site/source_material/binding_list.txt | 22 - site/source_material/docs.txt | 67 - site/source_material/feature_list.txt | 70 - site/source_material/home.txt | 23 - site/source_material/introduction.txt | 3 - site/source_material/lexer_introduction.txt | 7 - site/source_material/roadmap.txt | 30 - site/source_material/site_header.txt | 11 - site/source_material/tutorials.txt | 17 - string/4coder_string_build_num.txt | 5 - string/4ed_string_builder.cpp | 454 -- string/4tech_standard_preamble.h | 31 - string/internal_4coder_string.cpp | 2296 ------- things_ive_broken.txt | 21 + 148 files changed, 14530 insertions(+), 15053 deletions(-) create mode 100644 4coder_app_links_allocator.cpp create mode 100644 4coder_jumping.h create mode 100644 4coder_malloc_allocator.cpp delete mode 100644 4coder_os_comp_cracking.h create mode 100644 4coder_stringf.cpp delete mode 100644 4ed_defines.h delete mode 100644 build_site.bat delete mode 100755 build_site.sh delete mode 100644 build_string.bat delete mode 100755 build_string.sh create mode 100644 old_string_api.h delete mode 100644 site/4ed_abstract_document.cpp delete mode 100644 site/4ed_sitegen.cpp delete mode 100644 site/source_material/binding_list.txt delete mode 100644 site/source_material/docs.txt delete mode 100644 site/source_material/feature_list.txt delete mode 100644 site/source_material/home.txt delete mode 100644 site/source_material/introduction.txt delete mode 100644 site/source_material/lexer_introduction.txt delete mode 100644 site/source_material/roadmap.txt delete mode 100644 site/source_material/site_header.txt delete mode 100644 site/source_material/tutorials.txt delete mode 100644 string/4coder_string_build_num.txt delete mode 100644 string/4ed_string_builder.cpp delete mode 100644 string/4tech_standard_preamble.h delete mode 100644 string/internal_4coder_string.cpp create mode 100644 things_ive_broken.txt diff --git a/4coder_API/4coder_custom.h b/4coder_API/4coder_custom.h index d3a59a36..124bac28 100644 --- a/4coder_API/4coder_custom.h +++ b/4coder_API/4coder_custom.h @@ -22,8 +22,6 @@ #include "4coder_API/4coder_types.h" #include "4coder_generated/app_functions.h" -#include "4coder_base_types.cpp" - extern "C" _GET_VERSION_SIG(get_alpha_4coder_version){ return((maj == MAJOR && min == MINOR && patch == PATCH)); } diff --git a/4coder_API/4coder_types.h b/4coder_API/4coder_types.h index c8a33a69..c5e1bc84 100644 --- a/4coder_API/4coder_types.h +++ b/4coder_API/4coder_types.h @@ -429,30 +429,6 @@ STRUCT Mouse_State{ }; }; -/* DOC(Range describes an integer range typically used for ranges within a buffer. Ranges are not used to pass into the API, but this struct is used for returns. - -Throughout the API ranges are thought of in the form [min,max) where max is "one past the end" of the range that is actually read/edited/modified.) */ -UNION Range{ - STRUCT{ - /* DOC(This is the smaller value in the range.) */ - i32 min; - /* DOC(This is the larger value in the range.) */ - i32 max; - }; - STRUCT{ - /* DOC(This is the start of the range, unioned with min.) */ - i32 start; - /* DOC(This is the end of the range, unioned with max.) */ - i32 end; - }; - STRUCT{ - /* DOC(This is the first value in the range, unioned with min.) */ - i32 first; - /* DOC(This is one_past_the_last value in the range, unioned with max.) */ - i32 one_past_last; - }; -}; - /* DOC(An array of ranges. This is just a plain pointer bundled with a count, no additional special structure.) */ STRUCT Range_Array{ /* DOC(A pointer to the array of ranges.) */ @@ -629,6 +605,25 @@ STRUCT Partial_Cursor{ i32 character; }; +STRUCT Range_Partial_Cursor{ + struct{ + Partial_Cursor min; + Partial_Cursor max; + }; + struct{ + Partial_Cursor begin; + Partial_Cursor end; + }; + struct{ + Partial_Cursor start; + Partial_Cursor end; + }; + struct{ + Partial_Cursor first; + Partial_Cursor one_past_last; + }; +}; + STRUCT File_Attributes{ u64 size; u64 last_write_time; @@ -785,9 +780,11 @@ ENUM(u32, Glyph_Flag){ /* 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{ /* DOC(This specifies the prompt portion of the drop down bar.) */ - String prompt; + String_Const_u8 prompt; /* DOC(This specifies the main string portion of the drop down bar.) */ - String string; + String_Const_u8 string; + /* DOC(This specifies the memory capacity allocated for string.) */ + umem string_capacity; }; STRUCT Query_Bar_Ptr_Array{ @@ -902,6 +899,7 @@ ENUM(i32, Record_Error){ RecordError_InvalidBuffer, RecordError_NoHistoryAttached, RecordError_IndexOutOfBounds, + RecordError_SubIndexOutOfBounds, RecordError_InitialStateDummyRecord, RecordError_WrongRecordTypeAtIndex, }; @@ -920,8 +918,8 @@ STRUCT Record_Info{ i32 edit_number; union{ struct{ - String string_forward; - String string_backward; + String_Const_u8 string_forward; + String_Const_u8 string_backward; i32 first; } single; struct{ @@ -971,16 +969,6 @@ what event triggered the abort event.) */ b32 abort; }; -/* -DOC(Data is used for passing and returing pointer size pairs.) -*/ -STRUCT Data{ - /* DOC(A pointer to the data.) */ - u8 *data; - /* DOC(The size of the data in bytes.) */ - u64 size; -}; - STRUCT Frame_Info{ i32 index; f32 literal_dt; @@ -1048,8 +1036,8 @@ TYPEDEF_FUNC i32 Hook_Function(struct Application_Links *app); TYPEDEF_FUNC i32 Open_File_Hook_Function(struct Application_Links *app, Buffer_ID buffer_id); #define OPEN_FILE_HOOK_SIG(name) i32 name(struct Application_Links *app, Buffer_ID buffer_id) -TYPEDEF_FUNC i32 File_Edit_Range_Function(struct Application_Links *app, Buffer_ID buffer_id, Range range, String text); -#define FILE_EDIT_RANGE_SIG(name) i32 name(struct Application_Links *app, Buffer_ID buffer_id, Range range, String text) +TYPEDEF_FUNC i32 File_Edit_Range_Function(struct Application_Links *app, Buffer_ID buffer_id, Range range, String_Const_u8 text); +#define FILE_EDIT_RANGE_SIG(name) i32 name(struct Application_Links *app, Buffer_ID buffer_id, Range range, String_Const_u8 text) TYPEDEF_FUNC i32 File_Edit_Finished_Function(struct Application_Links *app, Buffer_ID *buffer_ids, i32 buffer_id_count); #define FILE_EDIT_FINISHED_SIG(name) i32 name(struct Application_Links *app, Buffer_ID *buffer_ids, i32 buffer_id_count) @@ -1072,21 +1060,19 @@ TYPEDEF_FUNC Color_Table Modify_Color_Table_Function(struct Application_Links *a ENUM(u32, Clipboard_Change_Flag){ ClipboardFlag_FromOS = 0x1, }; -TYPEDEF_FUNC void Clipboard_Change_Hook_Function(struct Application_Links *app, String contents, Clipboard_Change_Flag flags); -#define CLIPBOARD_CHANGE_HOOK_SIG(name) void name(struct Application_Links *app, String contents, Clipboard_Change_Flag flags) +TYPEDEF_FUNC void Clipboard_Change_Hook_Function(struct Application_Links *app, String_Const_u8 contents, Clipboard_Change_Flag flags); +#define CLIPBOARD_CHANGE_HOOK_SIG(name) void name(struct Application_Links *app, String_Const_u8 contents, Clipboard_Change_Flag flags) TYPEDEF_FUNC Rect_i32 Get_View_Buffer_Region_Function(struct Application_Links *app, View_ID view_id, Rect_i32 sub_region); #define GET_VIEW_BUFFER_REGION_SIG(name) Rect_i32 name(struct Application_Links *app, View_ID view_id, Rect_i32 sub_region) STRUCT Buffer_Name_Conflict_Entry{ Buffer_ID buffer_id; - char *file_name; - i32 file_name_len; - char *base_name; - i32 base_name_len; - char *unique_name_in_out; - i32 unique_name_len_in_out; - i32 unique_name_capacity; + String_Const_u8 file_name; + String_Const_u8 base_name; + u8 *unique_name_in_out; + umem unique_name_len_in_out; + umem unique_name_capacity; }; TYPEDEF_FUNC void Buffer_Name_Resolver_Function(struct Application_Links *app, Buffer_Name_Conflict_Entry *conflicts, i32 conflict_count); @@ -1141,7 +1127,7 @@ typedef i32 _Get_Version_Function(i32 maj, i32 min, i32 patch); #define _GET_VERSION_SIG(n) i32 n(i32 maj, i32 min, i32 patch) STRUCT color_picker{ - String title; + String_Const_u8 title; argb_color *dest; b32 *finished; }; diff --git a/4coder_api_transition_30_31.cpp b/4coder_api_transition_30_31.cpp index 6b2d25da..0f5170c8 100644 --- a/4coder_api_transition_30_31.cpp +++ b/4coder_api_transition_30_31.cpp @@ -30,6 +30,7 @@ static b32 get_buffer_summary(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_Summary *buffer){ b32 result = false; if (buffer_exists(app, buffer_id)){ + Scratch_Block scratch(app); Access_Flag buffer_access_flags = 0; buffer_get_access_flags(app, buffer_id, &buffer_access_flags); if ((buffer_access_flags & ~access) == 0){ @@ -39,12 +40,17 @@ get_buffer_summary(Application_Links *app, Buffer_ID buffer_id, Access_Flag acce buffer->buffer_id = buffer_id; buffer_get_size(app, buffer_id, &buffer->size); buffer_get_line_count(app, buffer_id, &buffer->line_count); - String file_name = make_fixed_width_string(buffer->file_name); - buffer_get_file_name(app, buffer_id, &file_name, 0); - buffer->file_name_len = file_name.size; - String buffer_name = make_fixed_width_string(buffer->buffer_name); - buffer_get_unique_buffer_name(app, buffer_id, &buffer_name, 0); - buffer->buffer_name_len = buffer_name.size; + + String_Const_u8 file_name_get = {}; + buffer_get_file_name(app, buffer_id, scratch, &file_name_get); + block_copy(buffer->file_name, file_name_get.str, file_name_get.size); + buffer->file_name_len = (i32)file_name_get.size; + + String_Const_u8 buffer_name_get = {}; + buffer_get_unique_buffer_name(app, buffer_id, scratch, &buffer_name_get); + block_copy(buffer->buffer_name, buffer_name_get.str, buffer_name_get.size); + buffer->buffer_name_len = (i32)buffer_name_get.size; + buffer_get_dirty_state(app, buffer_id, &buffer->dirty); buffer_get_setting(app, buffer_id, BufferSetting_Lex, &buffer->is_lexed); buffer->tokens_are_ready = buffer_tokens_are_ready(app, buffer_id); @@ -93,69 +99,9 @@ get_view_summary(Application_Links *app, View_ID view_id, Access_Flag access, Vi return(result); } -static b32 -exec_system_command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer_id, - char *path, int32_t path_len, char *command, i32 command_len, Command_Line_Interface_Flag flags){ - b32 result = false; - - String path_string = make_string(path, path_len); - String command_string = make_string(command, command_len); - Child_Process_ID child_process_id = 0; - if (create_child_process(app, path_string, command_string, &child_process_id)){ - result = true; - - Buffer_ID buffer_attach_id = 0; - if (buffer_id.name != 0 && buffer_id.name_len > 0){ - String buffer_name = make_string(buffer_id.name, buffer_id.name_len); - if (!get_buffer_by_name(app, buffer_name, AccessAll, &buffer_attach_id)){ - if (create_buffer(app, buffer_name, BufferCreate_AlwaysNew|BufferCreate_NeverAttachToFile, &buffer_attach_id)){ - buffer_set_setting(app, buffer_attach_id, BufferSetting_ReadOnly, true); - buffer_set_setting(app, buffer_attach_id, BufferSetting_Unimportant, true); - } - } - } - else if (buffer_id.id != 0){ - buffer_attach_id = buffer_id.id; - } - - if (buffer_attach_id != 0){ - Child_Process_Set_Target_Flags set_buffer_flags = 0; - if (!HasFlag(flags, CLI_OverlapWithConflict)){ - set_buffer_flags |= ChildProcessSet_FailIfBufferAlreadyAttachedToAProcess; - } - if (HasFlag(flags, CLI_CursorAtEnd)){ - set_buffer_flags |= ChildProcessSet_CursorAtEnd; - } - - if (child_process_set_target_buffer(app, child_process_id, buffer_attach_id, set_buffer_flags)){ - Buffer_Summary buffer = {}; - get_buffer_summary(app, buffer_attach_id, AccessAll, &buffer); - buffer_replace_range(app, buffer_attach_id, make_range(0, buffer.size), make_lit_string("")); - if (HasFlag(flags, CLI_SendEndSignal)){ - buffer_send_end_signal(app, buffer_attach_id); - } - if (view != 0){ - view_set_buffer(app, view->view_id, buffer_attach_id, 0); - get_view_summary(app, view->view_id, AccessAll, view); - } - } - } - } - - return(result); -} - -static b32 -exec_system_command(Application_Links *app, View_ID view, Buffer_Identifier buffer_id, - char *path, int32_t path_len, char *command, i32 command_len, Command_Line_Interface_Flag flags){ - View_Summary view_summary = {}; - get_view_summary(app, view, AccessAll, &view_summary); - return(exec_system_command(app, &view_summary, buffer_id, path, path_len, command, command_len, flags)); -} - static b32 clipboard_post(Application_Links *app, i32 clipboard_id, char *str, i32 len){ - return(clipboard_post(app, clipboard_id, make_string(str, len))); + return(clipboard_post(app, clipboard_id, SCu8(str, len))); } static i32 @@ -167,10 +113,11 @@ clipboard_count(Application_Links *app, i32 clipboard_id){ static i32 clipboard_index(Application_Links *app, i32 clipboard_id, i32 item_index, char *out, i32 len){ - i32 required_size = 0; - String string = make_string_cap(out, 0, len); - clipboard_index(app, clipboard_id, item_index, &string, &required_size); - return(required_size); + Scratch_Block scratch(app); + String_Const_u8 string = {}; + clipboard_index(app, clipboard_id, item_index, scratch, &string); + block_copy(out, string.str, clamp_top((i32)string.size, len)); + return((i32)string.size); } static Buffer_Summary @@ -207,7 +154,7 @@ static Buffer_Summary get_buffer_by_name(Application_Links *app, char *name, i32 len, Access_Flag access){ Buffer_ID id = 0; Buffer_Summary buffer = {}; - if (get_buffer_by_name(app, make_string(name, len), access, &id)){ + if (get_buffer_by_name(app, SCu8(name, len), access, &id)){ get_buffer_summary(app, id, access, &buffer); } return(buffer); @@ -217,7 +164,7 @@ static Buffer_Summary get_buffer_by_file_name(Application_Links *app, char *name, i32 len, Access_Flag access){ Buffer_ID id = 0; Buffer_Summary buffer = {}; - if (get_buffer_by_file_name(app, make_string(name, len), access, &id)){ + if (get_buffer_by_file_name(app, SCu8(name, len), access, &id)){ get_buffer_summary(app, id, access, &buffer); } return(buffer); @@ -237,7 +184,7 @@ static b32 buffer_replace_range(Application_Links *app, Buffer_Summary *buffer, i32 start, i32 one_past_last, char *str, i32 len){ b32 result = false; if (buffer != 0 && buffer->exists){ - result = buffer_replace_range(app, buffer->buffer_id, make_range(start, one_past_last), make_string(str, len)); + result = buffer_replace_range(app, buffer->buffer_id, make_range(start, one_past_last), SCu8(str, len)); get_buffer_summary(app, buffer->buffer_id, AccessAll, buffer); } return(result); @@ -343,7 +290,7 @@ static Buffer_Summary create_buffer(Application_Links *app, char *filename, i32 filename_len, Buffer_Create_Flag flags){ Buffer_Summary buffer = {}; Buffer_ID buffer_id = 0; - if (create_buffer(app, make_string(filename, filename_len), flags, &buffer_id)){ + if (create_buffer(app, SCu8(filename, filename_len), flags, &buffer_id)){ get_buffer_summary(app, buffer_id, AccessAll, &buffer); } return(buffer); @@ -353,7 +300,7 @@ static b32 save_buffer(Application_Links *app, Buffer_Summary *buffer, char *file_name, i32 file_name_len, u32 flags){ b32 result = false; if (buffer != 0 && buffer->exists){ - result = buffer_save(app, buffer->buffer_id, make_string(file_name, file_name_len), flags); + result = buffer_save(app, buffer->buffer_id, SCu8(file_name, file_name_len), flags); get_buffer_summary(app, buffer->buffer_id, AccessAll, buffer); } return(result); @@ -367,7 +314,7 @@ kill_buffer(Application_Links *app, Buffer_Identifier buffer, Buffer_Kill_Flag f } else if (buffer.name != 0){ Buffer_ID id = 0; - if (get_buffer_by_name(app, make_string(buffer.name, buffer.name_len), AccessAll, &id)){ + if (get_buffer_by_name(app, SCu8(buffer.name, buffer.name_len), AccessAll, &id)){ buffer_kill(app, id, flags, &result); } } @@ -446,14 +393,6 @@ open_view(Application_Links *app, View_Summary *view_location, View_Split_Positi return(view); } -static View_ID -open_view(Application_Links *app, View_ID view_location, View_Split_Position position){ - View_Summary summary = {}; - get_view_summary(app, view_location, AccessAll, &summary); - summary = open_view(app, &summary, position); - return(summary.view_id); -} - static b32 close_view(Application_Links *app, View_Summary *view){ b32 result = false; @@ -499,12 +438,6 @@ view_get_managed_scope(Application_Links *app, View_ID view_id){ return(scope); } -typedef i32 View_Split_Kind; -enum{ - ViewSplitKind_Ratio, - ViewSplitKind_FixedPixels, -}; - static b32 view_compute_cursor(Application_Links *app, View_Summary *view, Buffer_Seek seek, Full_Cursor *cursor_out){ b32 result = false; @@ -615,7 +548,7 @@ get_face_id(Application_Links *app, Buffer_Summary *buffer){ static void print_message(Application_Links *app, char *str, i32 len){ - print_message(app, make_string(str, len)); + print_message(app, SCu8(str, len)); } #if 0 @@ -632,51 +565,57 @@ change_theme(Application_Links *app, char *name, i32 len){ static i32 directory_get_hot(Application_Links *app, char *out, i32 capacity){ - i32 required_size = 0; - String string = make_string_cap(out, 0, capacity); - get_hot_directory(app, &string, &required_size); - return(required_size); + Scratch_Block scratch(app); + String_Const_u8 string = {}; + get_hot_directory(app, scratch, &string); + block_copy(out, string.str, clamp_top((i32)string.size, capacity)); + return((i32)string.size); } static b32 directory_set_hot(Application_Links *app, char *str, i32 len){ - return(set_hot_directory(app, make_string(str, len))); + return(set_hot_directory(app, SCu8(str, len))); } static File_List get_file_list(Application_Links *app, char *dir, i32 len){ File_List list = {}; - get_file_list(app, make_string(dir, len), &list); + get_file_list(app, SCu8(dir, len), &list); return(list); } static b32 file_exists(Application_Links *app, char *file_name, i32 len){ File_Attributes attributes = {}; - file_get_attributes(app, make_string(file_name, len), &attributes); + file_get_attributes(app, SCu8(file_name, len), &attributes); return(attributes.last_write_time > 0); } static b32 directory_cd(Application_Links *app, char *dir, i32 *len, i32 capacity, char *rel_path, i32 rel_len){ - String directory = make_string_cap(dir, *len, capacity); - String relative_path = make_string(rel_path, rel_len); - b32 result = directory_cd(app, &directory, relative_path); - *len = directory.size; + String_Const_u8 directory = SCu8(dir, *len); + String_Const_u8 relative_path = SCu8(rel_path, rel_len); + Scratch_Block scratch(app); + String_Const_u8 new_directory = {}; + b32 result = directory_cd(app, directory, relative_path, scratch, &new_directory); + i32 new_len = clamp_top((i32)new_directory.size, capacity); + block_copy(dir, new_directory.str, new_len); + *len = new_len; return(result); } static i32 get_4ed_path(Application_Links *app, char *out, i32 capacity){ - i32 required_size = 0; - String string = make_string_cap(out, 0, capacity); - get_4ed_path(app, &string, &required_size); - return(required_size); + Scratch_Block scratch(app); + String_Const_u8 string = {}; + get_4ed_path(app, scratch, &string); + block_copy(out, string.str, clamp_top((i32)string.size, capacity)); + return((i32)string.size); } static void set_window_title(Application_Links *app, char *title){ - String title_string = make_string_slowly(title); + String_Const_u8 title_string = SCu8(title); set_window_title(app, title_string); } diff --git a/4coder_api_transition_30_31_helpers.cpp b/4coder_api_transition_30_31_helpers.cpp index 720773ab..22dafbc7 100644 --- a/4coder_api_transition_30_31_helpers.cpp +++ b/4coder_api_transition_30_31_helpers.cpp @@ -24,6 +24,71 @@ #if !defined(REMOVE_TRANSITION_HELPER_31) +static b32 +exec_system_command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer_id, + char *path, int32_t path_len, char *command, i32 command_len, Command_Line_Interface_Flag flags){ + return(exec_system_command(app, (view == 0)?0:view->view_id, buffer_id, + SCu8(path, path_len), SCu8(command, command_len), flags)); + +#if 0 + b32 result = false; + + String_Const_u8 path_string = SCu8((u8*)path, path_len); + String_Const_u8 command_string = SCu8((u8*)command, command_len); + Child_Process_ID child_process_id = 0; + if (create_child_process(app, path_string, command_string, &child_process_id)){ + result = true; + + Buffer_ID buffer_attach_id = 0; + if (buffer_id.name != 0 && buffer_id.name_len > 0){ + String_Const_u8 buffer_name = SCu8((u8*)buffer_id.name, buffer_id.name_len); + if (!get_buffer_by_name(app, buffer_name, AccessAll, &buffer_attach_id)){ + if (create_buffer(app, buffer_name, BufferCreate_AlwaysNew|BufferCreate_NeverAttachToFile, &buffer_attach_id)){ + buffer_set_setting(app, buffer_attach_id, BufferSetting_ReadOnly, true); + buffer_set_setting(app, buffer_attach_id, BufferSetting_Unimportant, true); + } + } + } + else if (buffer_id.id != 0){ + buffer_attach_id = buffer_id.id; + } + + if (buffer_attach_id != 0){ + Child_Process_Set_Target_Flags set_buffer_flags = 0; + if (!HasFlag(flags, CLI_OverlapWithConflict)){ + set_buffer_flags |= ChildProcessSet_FailIfBufferAlreadyAttachedToAProcess; + } + if (HasFlag(flags, CLI_CursorAtEnd)){ + set_buffer_flags |= ChildProcessSet_CursorAtEnd; + } + + if (child_process_set_target_buffer(app, child_process_id, buffer_attach_id, set_buffer_flags)){ + Buffer_Summary buffer = {}; + get_buffer_summary(app, buffer_attach_id, AccessAll, &buffer); + buffer_replace_range(app, buffer_attach_id, make_range(0, buffer.size), string_u8_litexpr("")); + if (HasFlag(flags, CLI_SendEndSignal)){ + buffer_send_end_signal(app, buffer_attach_id); + } + if (view != 0){ + view_set_buffer(app, view->view_id, buffer_attach_id, 0); + get_view_summary(app, view->view_id, AccessAll, view); + } + } + } + } + + return(result); +#endif +} + +static b32 +exec_system_command(Application_Links *app, View_ID view, Buffer_Identifier buffer_id, + char *path, int32_t path_len, char *command, i32 command_len, Command_Line_Interface_Flag flags){ + View_Summary view_summary = {}; + get_view_summary(app, view, AccessAll, &view_summary); + return(exec_system_command(app, &view_summary, buffer_id, path, path_len, command, command_len, flags)); +} + static char buffer_get_char(Application_Links *app, Buffer_Summary *buffer, i32 pos){ return(buffer==0?0:buffer_get_char(app, buffer->buffer_id, pos)); @@ -45,14 +110,31 @@ get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Toke } static b32 -read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, i32 line, String *str, +read_line(Application_Links *app, Arena *arena, Buffer_Summary *buffer, i32 line, String *str, Partial_Cursor *start_out, Partial_Cursor *one_past_last_out){ - return(buffer==0?0:read_line(app, part, buffer->buffer_id, line, str, start_out, one_past_last_out)); + String_Const_u8 string = {}; + Range_Partial_Cursor out = {}; + b32 result = (buffer != 0 && is_valid_line(app, buffer->buffer_id, line)); + if (result){ + out = get_line_range(app, buffer->buffer_id, line); + string = scratch_read(app, arena, buffer->buffer_id, make_range_from_cursors(out)); + } + *start_out = out.start; + *one_past_last_out = out.one_past_last; + *str = string_old_from_new(string); + return(result); } static b32 -read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, i32 line, String *str){ - return(buffer==0?0:read_line(app, part, buffer->buffer_id, line, str)); +read_line(Application_Links *app, Arena *arena, Buffer_Summary *buffer, i32 line, String *str){ + String_Const_u8 string = {}; + b32 result = (buffer != 0 && is_valid_line(app, buffer->buffer_id, line)); + if (result){ + Range_Partial_Cursor range = get_line_range(app, buffer->buffer_id, line); + string = scratch_read(app, arena, buffer->buffer_id, make_range_from_cursors(range)); + } + *str = string_old_from_new(string); + return(result); } @@ -67,19 +149,10 @@ init_stream_tokens(Stream_Tokens_DEP *stream, Application_Links *app, Buffer_Sum } static String -token_get_lexeme(Application_Links *app, Buffer_Summary *buffer, Cpp_Token *token, char *out_buffer, i32 out_buffer_size){ +token_get_lexeme(Application_Links *app, Arena *arena, Buffer_Summary *buffer, Cpp_Token *token){ String result = {}; - if (buffer != 0){ - result = token_get_lexeme(app, buffer->buffer_id, token, out_buffer, out_buffer_size); - } - return(result); -} - -static String -token_get_lexeme(Application_Links *app, Partition *part, Buffer_Summary *buffer, Cpp_Token *token){ - String result = {}; - if (buffer != 0){ - result = token_get_lexeme(app, part, buffer->buffer_id, token); + if (buffer != 0 && token != 0){ + result = string_old_from_new(token_get_lexeme(app, arena, buffer->buffer_id, *token)); } return(result); } @@ -88,7 +161,12 @@ static String get_token_or_word_under_pos(Application_Links *app, Buffer_Summary *buffer, i32 pos, char *space, i32 capacity){ String result = {}; if (buffer != 0){ - result = get_token_or_word_under_pos(app, buffer->buffer_id, pos, space, capacity); + Scratch_Block scratch(app); + String_Const_u8 string = get_token_or_word_under_pos(app, scratch, buffer->buffer_id, pos); + i32 size = (i32)string.size; + size = clamp_top(size, capacity); + block_copy(space, string.str, size); + result = make_string_cap(space, size, capacity); } return(result); } @@ -174,17 +252,17 @@ buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_Summary *buffer, in } static Cpp_Token_Array -buffer_get_all_tokens(Application_Links *app, Partition *part, Buffer_Summary *buffer){ +buffer_get_all_tokens(Application_Links *app, Arena *arena, Buffer_Summary *buffer){ Cpp_Token_Array result = {}; if (buffer != 0){ - result = buffer_get_all_tokens(app, part, buffer->buffer_id); + result = buffer_get_all_tokens(app, arena, buffer->buffer_id); } return(result); } static i32 -buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Partition *part, i32 start_pos, b32 seek_forward, Seek_Boundary_Flag flags){ - return(buffer==0?0:buffer_boundary_seek(app, buffer->buffer_id, part, start_pos, seek_forward, flags)); +buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Arena *arena, i32 start_pos, b32 seek_forward, Seek_Boundary_Flag flags){ + return(buffer==0?0:buffer_boundary_seek(app, buffer->buffer_id, arena, start_pos, seek_forward, flags)); } static void @@ -204,35 +282,35 @@ buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, i static void buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 end, char *str, i32 size, i32 *result){ if (buffer != 0){ - buffer_seek_string_forward(app, buffer->buffer_id, pos, end, str, size, result); + buffer_seek_string_forward(app, buffer->buffer_id, pos, end, SCu8(str, size), result); } } static void buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 end, char *str, i32 size, i32 *result){ if (buffer != 0){ - buffer_seek_string_backward(app, buffer->buffer_id, pos, end, str, size, result); + buffer_seek_string_backward(app, buffer->buffer_id, pos, end, SCu8(str, size), result); } } static void buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 end, char *str, i32 size, i32 *result){ if (buffer != 0){ - buffer_seek_string_insensitive_forward(app, buffer->buffer_id, pos, end, str, size, result); + buffer_seek_string_insensitive_forward(app, buffer->buffer_id, pos, end, SCu8(str, size), result); } } static void buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 end, char *str, i32 size, i32 *result){ if (buffer != 0){ - buffer_seek_string_insensitive_backward(app, buffer->buffer_id, pos, end, str, size, result); + buffer_seek_string_insensitive_backward(app, buffer->buffer_id, pos, end, SCu8(str, size), result); } } static void buffer_seek_string(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 end, i32 min, char *str, i32 size, i32 *result, Buffer_Seek_String_Flags flags){ if (buffer != 0){ - buffer_seek_string(app, buffer->buffer_id, pos, end, min, str, size, result, flags); + buffer_seek_string(app, buffer->buffer_id, pos, end, min, SCu8(str, size), result, flags); } } @@ -245,7 +323,12 @@ static String read_identifier_at_pos(Application_Links *app, Buffer_Summary *buffer, i32 pos, char *space, i32 max, Range *range_out){ String result = {}; if (buffer != 0){ - result = read_identifier_at_pos(app, buffer->buffer_id, pos, space, max, range_out); + Scratch_Block scratch(app); + String_Const_u8 string = read_identifier_at_pos(app, scratch, buffer->buffer_id, pos, range_out); + i32 size = (i32)string.size; + size = clamp_top(size, max); + block_copy(space, string.str, size); + result = make_string_cap(space, size, max); } return(result); } @@ -277,7 +360,9 @@ view_buffer_snipe_range(Application_Links *app, View_Summary *view, Buffer_Summa static void query_replace_base(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, i32 pos, String r, String w){ - query_replace_base(app, view==0?0:view->view_id, buffer==0?0:buffer->buffer_id, pos, r, w); + query_replace_base(app, view==0?0:view->view_id, buffer==0?0:buffer->buffer_id, pos, + string_new_u8_from_old(r), + string_new_u8_from_old(w)); } static Statement_Parser @@ -320,18 +405,18 @@ find_prev_scope(Application_Links *app, Buffer_Summary *buffer, i32 start_pos, u } static Range_Array -get_enclosure_ranges(Application_Links *app, Partition *part, Buffer_Summary *buffer, i32 pos, u32 flags){ +get_enclosure_ranges(Application_Links *app, Arena *arena, Buffer_Summary *buffer, i32 pos, u32 flags){ Range_Array result = {}; if (buffer != 0){ - result = get_enclosure_ranges(app, part, buffer->buffer_id, pos, flags); + result = get_enclosure_ranges(app, arena, buffer->buffer_id, pos, flags); } return(result); } static void -mark_enclosures(Application_Links *app, Partition *scratch, Managed_Scope render_scope, Buffer_Summary *buffer, i32 pos, u32 flags, Marker_Visual_Type type, int_color *back_colors, int_color *fore_colors, i32 color_count){ +mark_enclosures(Application_Links *app, Managed_Scope render_scope, Buffer_Summary *buffer, i32 pos, u32 flags, Marker_Visual_Type type, int_color *back_colors, int_color *fore_colors, i32 color_count){ if (buffer != 0){ - mark_enclosures(app, scratch, render_scope, buffer->buffer_id, pos, flags, type, back_colors, fore_colors, color_count); + mark_enclosures(app, render_scope, buffer->buffer_id, pos, flags, type, back_colors, fore_colors, color_count); } } @@ -345,7 +430,7 @@ buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, i32 line_ } static Buffer_Batch_Edit -make_batch_from_indent_marks(Application_Links *app, Partition *arena, Buffer_Summary *buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){ +make_batch_from_indent_marks(Application_Links *app, Arena *arena, Buffer_Summary *buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){ Buffer_Batch_Edit result = {}; if (buffer != 0){ make_batch_from_indent_marks(app, arena, buffer->buffer_id, first_line, one_past_last_line, indent_marks, opts); @@ -354,9 +439,9 @@ make_batch_from_indent_marks(Application_Links *app, Partition *arena, Buffer_Su } static void -set_line_indents(Application_Links *app, Partition *part, Buffer_Summary *buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){ +set_line_indents(Application_Links *app, Arena *arena, Buffer_Summary *buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){ if (buffer != 0){ - set_line_indents(app, part, buffer->buffer_id, first_line, one_past_last_line, indent_marks, opts); + set_line_indents(app, arena, buffer->buffer_id, first_line, one_past_last_line, indent_marks, opts); } } @@ -370,7 +455,7 @@ find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Arra } static i32* -get_indentation_marks(Application_Links *app, Partition *arena, Buffer_Summary *buffer, +get_indentation_marks(Application_Links *app, Arena *arena, Buffer_Summary *buffer, Cpp_Token_Array tokens, i32 first_line, i32 one_past_last_line, b32 exact_align, i32 tab_width){ return(buffer==0?0:get_indentation_marks(app, arena, buffer->buffer_id, tokens, first_line, one_past_last_line, exact_align, tab_width)); @@ -396,8 +481,8 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cp } static b32 -buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buffer, i32 start, i32 end, i32 tab_width, Auto_Indent_Flag flags){ - return(buffer==0?0:buffer_auto_indent(app, part, buffer->buffer_id, start, end, tab_width, flags)); +buffer_auto_indent(Application_Links *app, Arena *arena, Buffer_Summary *buffer, i32 start, i32 end, i32 tab_width, Auto_Indent_Flag flags){ + return(buffer==0?0:buffer_auto_indent(app, arena, buffer->buffer_id, start, end, tab_width, flags)); } static b32 @@ -405,13 +490,6 @@ buffer_auto_indent(Application_Links *app, Buffer_Summary *buffer, i32 start, i3 return(buffer==0?0:buffer_auto_indent(app, buffer->buffer_id, start, end, tab_width, flags)); } -static void -print_positions_buffered(Application_Links *app, Buffer_Summary *buffer, Function_Positions *positions_array, i32 positions_count, Buffered_Write_Stream *stream){ - if (buffer != 0){ - print_positions_buffered(app, buffer->buffer_id, positions_array, positions_count, stream); - } -} - static Get_Positions_Results get_function_positions(Application_Links *app, Buffer_Summary *buffer, i32 first_token_index, Function_Positions *positions_array, i32 positions_max){ Get_Positions_Results result = {}; @@ -422,9 +500,9 @@ get_function_positions(Application_Links *app, Buffer_Summary *buffer, i32 first } static void -list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *optional_target_buffer){ +list_all_functions(Application_Links *app, Buffer_Summary *optional_target_buffer){ if (optional_target_buffer != 0){ - list_all_functions(app, part, optional_target_buffer->buffer_id); + list_all_functions(app, optional_target_buffer->buffer_id); } } @@ -440,14 +518,14 @@ c_line_comment_starts_at_position(Application_Links *app, Buffer_Summary *buffer static void write_string(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, String string){ - write_string(app, view==0?0:view->view_id, buffer==0?0:buffer->buffer_id, string); + write_string(app, view==0?0:view->view_id, buffer==0?0:buffer->buffer_id, string_new_u8_from_old(string)); } static b32 open_file(Application_Links *app, Buffer_Summary *buffer_out, char *filename, i32 filename_len, b32 background, b32 never_new){ b32 result = false; Buffer_ID id_out = 0; - result = open_file(app, &id_out, filename, filename_len, background, never_new); + result = open_file(app, &id_out, SCu8(filename, filename_len), background, never_new); if (result && buffer_out != 0){ get_buffer_summary(app, id_out, AccessAll, buffer_out); } @@ -541,7 +619,7 @@ refresh_buffer(Application_Links *app, Buffer_Summary *buffer){ } static Sticky_Jump_Array -parse_buffer_to_jump_array(Application_Links *app, Partition *arena, Buffer_Summary buffer){ +parse_buffer_to_jump_array(Application_Links *app, Arena *arena, Buffer_Summary buffer){ return(parse_buffer_to_jump_array(app, arena, buffer.buffer_id)); } @@ -562,33 +640,18 @@ get_buffer_face_description(Application_Links *app, Buffer_Summary *buffer){ static void set_buffer_face_by_name(Application_Links *app, Buffer_Summary *buffer, char *name, i32 len){ if (buffer != 0){ - set_buffer_face_by_name(app, buffer->buffer_id, name, len); + set_buffer_face_by_name(app, buffer->buffer_id, SCu8(name, len)); } } -static i32 -get_build_directory(Application_Links *app, Buffer_Summary *buffer, String *dir_out){ - return(get_build_directory(app, buffer==0?0:buffer->buffer_id, dir_out)); -} - -static i32 -standard_build_search(Application_Links *app, View_Summary *view, String *dir, String *command, b32 perform_backup, b32 use_path_in_command, String filename, String command_name){ - return(standard_build_search(app, view==0?0:view->view_id, dir, command, perform_backup, use_path_in_command, filename, command_name)); -} - -static i32 -execute_standard_build_search(Application_Links *app, View_Summary *view, String *dir, String *command, i32 perform_backup){ - return(execute_standard_build_search(app, view==0?0:view->view_id, dir, command, perform_backup)); -} - static void execute_standard_build(Application_Links *app, View_Summary *view, Buffer_ID active_buffer){ - execute_standard_build(app, view==0?0:view->view_id, active_buffer); + standard_search_and_build(app, view==0?0:view->view_id, active_buffer); } static b32 -post_buffer_range_to_clipboard(Application_Links *app, Partition *scratch, i32 clipboard_index, Buffer_Summary *buffer, i32 first, i32 one_past_last){ - return(post_buffer_range_to_clipboard(app, scratch, clipboard_index, buffer==0?0:buffer->buffer_id, first, one_past_last)); +post_buffer_range_to_clipboard(Application_Links *app, i32 clipboard_index, Buffer_Summary *buffer, i32 first, i32 one_past_last){ + return(post_buffer_range_to_clipboard(app, clipboard_index, buffer==0?0:buffer->buffer_id, first, one_past_last)); } static void @@ -597,13 +660,13 @@ view_set_vertical_focus(Application_Links *app, View_Summary *view, i32 y_top, i } static b32 -advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_Summary *view, i32 skip_repeats, i32 skip_sub_error, i32 direction, Name_Line_Column_Location *location_out){ - return(advance_cursor_in_jump_view(app, part, view==0?0:view->view_id, skip_repeats, skip_sub_error, direction, location_out)); +advance_cursor_in_jump_view(Application_Links *app, View_Summary *view, i32 skip_repeats, i32 skip_sub_error, i32 direction, Name_Line_Column_Location *location_out){ + return(advance_cursor_in_jump_view(app, view==0?0:view->view_id, skip_repeats, skip_sub_error, direction, location_out)); } static Parsed_Jump -seek_next_jump_in_view(Application_Links *app, Partition *part, View_Summary *view, i32 skip_sub_errors, i32 direction, i32 *line_out){ - return(seek_next_jump_in_view(app, part, view==0?0:view->view_id, skip_sub_errors, direction, line_out)); +seek_next_jump_in_view(Application_Links *app, Arena *arena, View_Summary *view, i32 skip_sub_errors, i32 direction, i32 *line_out){ + return(seek_next_jump_in_view(app, arena, view==0?0:view->view_id, skip_sub_errors, direction, line_out)); } static void @@ -617,18 +680,8 @@ goto_jump_in_order(Application_Links *app, Marker_List *list, View_Summary *jump } static void -open_jump_lister(Application_Links *app, Partition *scratch, Heap *heap, View_Summary *ui_view, Buffer_ID list_buffer_id, Jump_Lister_Activation_Rule activation_rule, View_Summary *optional_target_view){ - open_jump_lister(app, scratch, heap, ui_view==0?0:ui_view->view_id, list_buffer_id, activation_rule, optional_target_view==0?0:optional_target_view->view_id); -} - -static void -activate_project_command(Application_Links *app, Partition *scratch, Heap *heap, View_Summary *view, Lister_State *state, String text_field, void *user_data, b32 activated_by_mouse){ - activate_project_command(app, scratch, heap, view==0?0:view->view_id, state, text_field, user_data, activated_by_mouse); -} - -static void -activate_snippet(Application_Links *app, Partition *scratch, Heap *heap, View_Summary *view, struct Lister_State *state, String text_field, void *user_data, b32 activated_by_mouse){ - activate_snippet(app, scratch, heap, view==0?0:view->view_id, state, text_field, user_data, activated_by_mouse); +open_jump_lister(Application_Links *app, Heap *heap, View_Summary *ui_view, Buffer_ID list_buffer_id, Jump_Lister_Activation_Rule activation_rule, View_Summary *optional_target_view){ + open_jump_lister(app, heap, ui_view==0?0:ui_view->view_id, list_buffer_id, activation_rule, optional_target_view==0?0:optional_target_view->view_id); } static void @@ -643,7 +696,7 @@ character_pos_to_pos(Application_Links *app, View_Summary *view, i32 character_p static b32 view_open_file(Application_Links *app, View_Summary *view, char *filename, i32 filename_len, b32 never_new){ - return(view_open_file(app, view==0?0:view->view_id, filename, filename_len, never_new)); + return(view_open_file(app, view==0?0:view->view_id, SCu8(filename, filename_len), never_new)); } static f32 @@ -681,8 +734,8 @@ refresh_view(Application_Links *app, View_Summary *view){ } static String -get_string_in_view_range(Application_Links *app, Partition *arena, View_Summary *view){ - return(get_string_in_view_range(app, arena, view==0?0:view->view_id)); +get_string_in_view_range(Application_Links *app, Arena *arena, View_Summary *view){ + return(string_old_from_new(get_string_in_view_range(app, arena, view==0?0:view->view_id))); } static b32 @@ -748,28 +801,160 @@ get_prev_view_looped_primary_panels(Application_Links *app, View_Summary *view_s } static void -list__parameters(Application_Links *app, Heap *heap, Partition *scratch, String *strings, i32 count, Search_Range_Flag match_flags, View_Summary default_target_view){ - list__parameters(app, heap, scratch, strings, count, match_flags, default_target_view.view_id); +list__parameters(Application_Links *app, Heap *heap, String_Const_u8 *strings, i32 count, Search_Range_Flag match_flags, View_Summary default_target_view){ + list__parameters(app, heap, strings, count, match_flags, default_target_view.view_id); } static void -list_query__parameters(Application_Links *app, Heap *heap, Partition *scratch, b32 substrings, b32 case_insensitive, View_Summary default_target_view){ - list_query__parameters(app, heap, scratch, substrings, case_insensitive, default_target_view.view_id); +list_query__parameters(Application_Links *app, Heap *heap, b32 substrings, b32 case_insensitive, View_Summary default_target_view){ + list_query__parameters(app, heap, substrings, case_insensitive, default_target_view.view_id); } static Buffer_ID create_or_switch_to_buffer_by_name(Application_Links *app, char *name, i32 name_length, View_Summary default_target_view){ - return(create_or_switch_to_buffer_by_name(app, make_string(name, name_length), default_target_view.view_id)); + return(create_or_switch_to_buffer_and_clear_by_name(app, SCu8(name, name_length), default_target_view.view_id)); } static void -list_identifier__parameters(Application_Links *app, Heap *heap, Partition *scratch, b32 substrings, b32 case_insensitive, View_Summary default_target_view){ - list_identifier__parameters(app, heap, scratch, substrings, case_insensitive, default_target_view.view_id); +list_identifier__parameters(Application_Links *app, Heap *heap, b32 substrings, b32 case_insensitive, View_Summary default_target_view){ + list_identifier__parameters(app, heap, substrings, case_insensitive, default_target_view.view_id); } static void -list_type_definition__parameters(Application_Links *app, Heap *heap, Partition *scratch, String str, View_Summary default_target_view){ - list_type_definition__parameters(app, heap, scratch, str, default_target_view.view_id); +list_type_definition__parameters(Application_Links *app, Heap *heap, String str, View_Summary default_target_view){ + list_type_definition__parameters(app, heap, string_new_u8_from_old(str), default_target_view.view_id); +} + +static b32 +backspace_utf8(String *str){ + b32 result = false; + uint8_t *s = (uint8_t*)str->str; + if (str->size > 0){ + u32 i = str->size-1; + for (; i > 0; --i){ + if (s[i] <= 0x7F || s[i] >= 0xC0){ + break; + } + } + str->size = i; + result = true; + } + return(result); +} + +static void +change_mapping(Application_Links *app, String mapping){ + change_mapping(app, string_new_u8_from_old(mapping)); +} + +static void +query_replace_parameter(Application_Links *app, String replace_str, i32 start_pos, b32 add_replace_query_bar){ + query_replace_parameter(app, SCu8(string_new_from_old(replace_str)), start_pos, add_replace_query_bar); +} + +static String +hot_directory_push(Application_Links *app, Arena *arena){ + return(string_old_from_new(push_hot_directory(app, arena))); +} + +static void +append_int_to_str_left_pad(String *str, i32 x, i32 minimum_width, char pad_char){ + i32 length = int_to_str_size(x); + i32 left_over = minimum_width - length; + if (left_over > 0){ + append_padding(str, pad_char, str->size + left_over); + } + append_int_to_str(str, x); +} + +static void +condense_whitespace(String *a){ + *a = skip_chop_whitespace(*a); + int size = a->size; + a->size = 0; + int i = 0; + for (;i < size;){ + if (char_is_whitespace(a->str[i])){ + a->str[a->size++] = ' '; + for (;(i < size) && char_is_whitespace(a->str[i]);){ + ++i; + } + } + else{ + a->str[a->size++] = a->str[i++]; + } + } +} + +static Face_ID +get_existing_face_id_matching_name(Application_Links *app, char *name, i32 len){ + return(get_existing_face_id_matching_name(app, SCu8(name, len))); +} + +static Face_ID +get_face_id_by_name(Application_Links *app, char *name, i32 len, Face_Description *base_description){ + return(get_face_id_by_name(app, SCu8(name, len), base_description)); +} + +static void +set_global_face_by_name(Application_Links *app, char *name, i32 len, b32 apply_to_all_buffers){ + set_global_face_by_name(app, SCu8(name, len), apply_to_all_buffers); +} + +static void +insert_string__no_buffering(Buffer_Insertion *insertion, String string){ + insert_string__no_buffering(insertion, string_new_u8_from_old(string)); +} + +static void +insert_string(Buffer_Insertion *insertion, String string){ + insert_string(insertion, string_new_u8_from_old(string)); +} + +static void +save_all_dirty_buffers_with_postfix(Application_Links *app, String postfix){ + save_all_dirty_buffers_with_postfix(app, string_new_u8_from_old(postfix)); +} + +static void +delete_file_base(Application_Links *app, String file_name, Buffer_ID buffer_id){ + delete_file_base(app, string_new_u8_from_old(file_name), buffer_id); +} + +static b32 +ms_style_verify(String line, i32 left_paren_pos, i32 right_paren_pos){ + return(ms_style_verify(string_new_u8_from_old(line), left_paren_pos, right_paren_pos)); +} + +static i32 +try_skip_rust_arrow(String line){ + return((i32)(try_skip_rust_arrow(string_new_u8_from_old(line)))); +} + +static b32 +check_is_note(String line, i32 colon_pos){ + return(check_is_note(string_new_u8_from_old(line), colon_pos)); +} + +static void +close_all_files_with_extension(Application_Links *app, CString_Array extension_array){ + Scratch_Block scratch(app); + String_Const_u8_Array array = {}; + array.count = extension_array.count; + array.strings = push_array(scratch, String_Const_u8, array.count); + for (i32 i = 0; i < array.count; i += 1){ + array.strings[i] = SCu8(extension_array.strings[i]); + } + close_all_files_with_extension(app, array); +} + +static void +open_all_files_in_directory_pattern_match(Application_Links *app, + String dir, + Project_File_Pattern_Array whitelist, + Project_File_Pattern_Array blacklist, + u32 flags){ + open_all_files_in_directory_pattern_match(app, string_new_u8_from_old(dir), whitelist, blacklist, flags); } #endif diff --git a/4coder_app_links_allocator.cpp b/4coder_app_links_allocator.cpp new file mode 100644 index 00000000..4e7aabaa --- /dev/null +++ b/4coder_app_links_allocator.cpp @@ -0,0 +1,54 @@ +/* + * 4coder app links base allocator + */ + +// TOP + +internal void +scratch_block__init(Scratch_Block *block, Arena *arena){ + block->temp = begin_temp(arena); +} + +Scratch_Block::Scratch_Block(Temp_Memory t){ + this->temp = t; +} + +Scratch_Block::Scratch_Block(Arena *arena){ + scratch_block__init(this, arena); +} + +Scratch_Block::Scratch_Block(Application_Links *app){ + scratch_block__init(this, context_get_arena(app)); +} + +Scratch_Block::~Scratch_Block(){ + end_temp(this->temp); +} + +Scratch_Block::operator Arena*(){ + return(this->temp.temp_memory_arena.arena); +} + +void Scratch_Block::restore(void){ + end_temp(this->temp); +} + +//////////////////////////////// + +internal Arena +make_arena_app_links(Application_Links *app, umem chunk_size, umem align){ + return(make_arena(context_get_base_allocator(app), chunk_size, align)); +} + +internal Arena +make_arena_app_links(Application_Links *app, umem chunk_size){ + return(make_arena_app_links(app, chunk_size, 8)); +} + +internal Arena +make_arena_app_links(Application_Links *app){ + return(make_arena_app_links(app, KB(16), 8)); +} + +// BOTTOM + diff --git a/4coder_auto_indent.cpp b/4coder_auto_indent.cpp index d223a0ab..082308e0 100644 --- a/4coder_auto_indent.cpp +++ b/4coder_auto_indent.cpp @@ -49,9 +49,8 @@ buffer_find_hard_start(Application_Links *app, Buffer_ID buffer, i32 line_start, return(result); } -// TODO(allen): rewrite with arena and linked list batch. static Buffer_Batch_Edit -make_batch_from_indent_marks(Application_Links *app, Partition *arena, Buffer_ID buffer, +make_batch_from_indent_marks(Application_Links *app, Arena *arena, Buffer_ID buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){ i32 *shifted_indent_marks = indent_marks - first_line; @@ -60,7 +59,7 @@ make_batch_from_indent_marks(Application_Links *app, Partition *arena, Buffer_ID i32 edit_max = one_past_last_line - first_line; Buffer_Edit *edits = push_array(arena, Buffer_Edit, edit_max); - char *str_base = push_array(arena, char, 0); + List_String_Const_u8 list = {}; for (i32 line_number = first_line; line_number < one_past_last_line; @@ -77,51 +76,49 @@ make_batch_from_indent_marks(Application_Links *app, Partition *arena, Buffer_ID } if (correct_indentation != hard_start.indent_pos){ - i32 str_size = correct_indentation; + umem str_size = 0; + char *str = 0; if (opts.use_tabs){ - str_size = correct_indentation/opts.tab_width + correct_indentation%opts.tab_width; - } - char *str = push_array(arena, char, str_size); - if (opts.use_tabs){ - i32 indent = 0; - i32 j = 0; - for (;indent + opts.tab_width <= correct_indentation; - indent += opts.tab_width){ - str[j++] = '\t'; - } - for (;indent < correct_indentation; - indent += 1){ - str[j++] = ' '; - } + i32 tab_count = correct_indentation/opts.tab_width; + i32 indent = tab_count*opts.tab_width; + i32 space_count = correct_indentation - indent; + str_size = tab_count + space_count; + str = push_array(arena, char, str_size); + block_fill_u8(str, tab_count, '\t'); + block_fill_u8(str + tab_count, space_count, ' '); } else{ - for (i32 j = 0; j < correct_indentation;){ - str[j++] = ' '; - } + str_size = correct_indentation; + str = push_array(arena, char, str_size); + block_fill_u8(str, str_size, ' '); } - Buffer_Edit new_edit = {}; - new_edit.str_start = (i32)(str - str_base); - new_edit.len = str_size; - new_edit.start = line_start_pos; - new_edit.end = hard_start.char_pos; - edits[edit_count++] = new_edit; + umem str_position = list.total_size; + string_list_push(arena, &list, SCu8(str, str_size)); + + edits[edit_count].str_start = (i32)str_position; + edits[edit_count].len = (i32)str_size; + edits[edit_count].start = line_start_pos; + edits[edit_count].end = hard_start.char_pos; + edit_count += 1; } Assert(edit_count <= edit_max); } + String_Const_u8 contiguous_text = string_list_flatten(arena, list); + Buffer_Batch_Edit result = {}; - result.str = str_base; - result.str_len = (i32)(push_array(arena, char, 0) - str_base); + result.str = (char*)contiguous_text.str; + result.str_len = (i32)contiguous_text.size; result.edits = edits; result.edit_count = edit_count; return(result); } static void -set_line_indents(Application_Links *app, Partition *part, Buffer_ID buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){ - Buffer_Batch_Edit batch = make_batch_from_indent_marks(app, part, buffer, first_line, one_past_last_line, indent_marks, opts); +set_line_indents(Application_Links *app, Arena *arena, Buffer_ID buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){ + Buffer_Batch_Edit batch = make_batch_from_indent_marks(app, arena, buffer, first_line, one_past_last_line, indent_marks, opts); if (batch.edit_count > 0){ buffer_batch_edit(app, buffer, batch.str, batch.edits, batch.edit_count); } @@ -232,7 +229,7 @@ find_anchor_token(Application_Links *app, Buffer_ID buffer, Cpp_Token_Array toke } static i32* -get_indentation_marks(Application_Links *app, Partition *arena, Buffer_ID buffer, +get_indentation_marks(Application_Links *app, Arena *arena, Buffer_ID buffer, Cpp_Token_Array tokens, i32 first_line, i32 one_past_last_line, b32 exact_align, i32 tab_width){ i32 indent_mark_count = one_past_last_line - first_line; @@ -549,18 +546,18 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_ID buffer, Cpp_Toke } static b32 -buffer_auto_indent(Application_Links *app, Partition *part, Buffer_ID buffer, i32 start, i32 end, i32 tab_width, Auto_Indent_Flag flags){ +buffer_auto_indent(Application_Links *app, Arena *scratch, Buffer_ID buffer, i32 start, i32 end, i32 tab_width, Auto_Indent_Flag flags){ b32 result = false; if (buffer_exists(app, buffer) && buffer_tokens_are_ready(app, buffer)){ result = true; - Temp_Memory temp = begin_temp_memory(part); + Temp_Memory temp = begin_temp(scratch); // Stage 1: Read the tokens to be used for indentation. Cpp_Token_Array tokens = {}; buffer_token_count(app, buffer, &tokens.count); tokens.max_count = tokens.count; - tokens.tokens = push_array(part, Cpp_Token, tokens.count); + tokens.tokens = push_array(scratch, Cpp_Token, tokens.count); buffer_read_tokens(app, buffer, 0, tokens.count, tokens.tokens); // Stage 2: Decide where the first and last lines are. @@ -576,7 +573,7 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_ID buffer, i3 // Stage 3: Decide Indent Amounts // Get an array representing how much each line in // the range [line_start,line_end) should be indented. - i32 *indent_marks = get_indentation_marks(app, part, buffer, tokens, line_start, line_end, (flags & AutoIndent_ExactAlignBlock), tab_width); + i32 *indent_marks = get_indentation_marks(app, scratch, buffer, tokens, line_start, line_end, (flags & AutoIndent_ExactAlignBlock), tab_width); // Stage 4: Set the Line Indents Indent_Options opts = {}; @@ -584,9 +581,9 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_ID buffer, i3 opts.use_tabs = (flags & AutoIndent_UseTab); opts.tab_width = tab_width; - set_line_indents(app, part, buffer, line_start, line_end, indent_marks, opts); + set_line_indents(app, scratch, buffer, line_start, line_end, indent_marks, opts); - end_temp_memory(temp); + end_temp(temp); } return(result); @@ -594,7 +591,8 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_ID buffer, i3 static b32 buffer_auto_indent(Application_Links *app, Buffer_ID buffer, i32 start, i32 end, i32 tab_width, Auto_Indent_Flag flags){ - return(buffer_auto_indent(app, &global_part, buffer, start, end, tab_width, flags)); + Arena *scratch = context_get_arena(app); + return(buffer_auto_indent(app, scratch, buffer, start, end, tab_width, flags)); } // @@ -618,7 +616,8 @@ CUSTOM_DOC("Audo-indents the entire current buffer.") view_get_buffer(app, view, AccessOpen, &buffer); i32 buffer_size = 0; buffer_get_size(app, buffer, &buffer_size); - buffer_auto_indent(app, &global_part, buffer, 0, buffer_size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); + Arena *scratch = context_get_arena(app); + buffer_auto_indent(app, scratch, buffer, 0, buffer_size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); } CUSTOM_COMMAND_SIG(auto_tab_line_at_cursor) @@ -630,7 +629,8 @@ CUSTOM_DOC("Auto-indents the line on which the cursor sits.") view_get_buffer(app, view, AccessOpen, &buffer); i32 pos = 0; view_get_cursor_pos(app, view, &pos); - buffer_auto_indent(app, &global_part, buffer, pos, pos, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); + Arena *scratch = context_get_arena(app); + buffer_auto_indent(app, scratch, buffer, pos, pos, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); move_past_lead_whitespace(app, view, buffer); } @@ -642,7 +642,8 @@ CUSTOM_DOC("Auto-indents the range between the cursor and the mark.") Buffer_ID buffer = 0; view_get_buffer(app, view, AccessOpen, &buffer); Range range = get_view_range(app, view); - buffer_auto_indent(app, &global_part, buffer, range.min, range.max, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); + Arena *scratch = context_get_arena(app); + buffer_auto_indent(app, scratch, buffer, range.min, range.max, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); move_past_lead_whitespace(app, view, buffer); } @@ -661,7 +662,8 @@ CUSTOM_DOC("Inserts a character and auto-indents the line on which the cursor si } i32 pos = 0; view_get_cursor_pos(app, view, &pos); - buffer_auto_indent(app, &global_part, buffer, pos, pos, DEF_TAB_WIDTH, flags); + Arena *scratch = context_get_arena(app); + buffer_auto_indent(app, scratch, buffer, pos, pos, DEF_TAB_WIDTH, flags); move_past_lead_whitespace(app, view, buffer); } diff --git a/4coder_base_commands.cpp b/4coder_base_commands.cpp index fbc7dad5..cf3aa89f 100644 --- a/4coder_base_commands.cpp +++ b/4coder_base_commands.cpp @@ -33,15 +33,15 @@ write_character_parameter(Application_Links *app, u8 *character, u32 length){ if (character[0] != '\n'){ Record_Info record = get_single_record(app, buffer, first_index); if (record.error == RecordError_NoError && record.kind == RecordKind_Single){ - String string = record.single.string_forward; - i32 last_end = record.single.first + string.size; + String_Const_u8 string = record.single.string_forward; + i32 last_end = record.single.first + (i32)string.size; if (last_end == pos && string.size > 0){ char c = string.str[string.size - 1]; if (c != '\n'){ - if (char_is_whitespace(character[0]) && char_is_whitespace(c)){ + if (character_is_whitespace(character[0]) && character_is_whitespace(c)){ do_merge = true; } - else if (char_is_alpha_numeric(character[0]) && char_is_alpha_numeric(c)){ + else if (character_is_alpha_numeric(character[0]) && character_is_alpha_numeric(c)){ do_merge = true; } } @@ -50,7 +50,7 @@ write_character_parameter(Application_Links *app, u8 *character, u32 length){ } // NOTE(allen): perform the edit - b32 edit_success = buffer_replace_range(app, buffer, make_range(pos), make_string((char*)character, length)); + b32 edit_success = buffer_replace_range(app, buffer, make_range(pos), SCu8(character, length)); // NOTE(allen): finish merging records if necessary if (do_merge){ @@ -101,7 +101,7 @@ CUSTOM_DOC("Deletes the character to the right of the cursor.") view_compute_cursor(app, view, seek_pos(start), &cursor); view_compute_cursor(app, view, seek_character_pos(cursor.character_pos + 1), &cursor); i32 end = cursor.pos; - buffer_replace_range(app, buffer, make_range(start, end), make_lit_string("")); + buffer_replace_range(app, buffer, make_range(start, end), string_u8_litexpr("")); } } } @@ -123,7 +123,7 @@ CUSTOM_DOC("Deletes the character to the left of the cursor.") view_compute_cursor(app, view, seek_pos(end), &cursor); view_compute_cursor(app, view, seek_character_pos(cursor.character_pos - 1), &cursor); i32 start = cursor.pos; - if (buffer_replace_range(app, buffer, make_range(start, end), make_lit_string(""))){ + if (buffer_replace_range(app, buffer, make_range(start, end), string_u8_litexpr(""))){ view_set_cursor(app, view, seek_pos(start), true); } } @@ -162,7 +162,7 @@ CUSTOM_DOC("Deletes the text in the range between the cursor and the mark.") Buffer_ID buffer = 0; view_get_buffer(app, view, AccessOpen, &buffer); Range range = get_view_range(app, view); - buffer_replace_range(app, buffer, range, make_lit_string("")); + buffer_replace_range(app, buffer, range, string_u8_litexpr("")); } //////////////////////////////// @@ -192,7 +192,7 @@ CUSTOM_DOC("Sets the left size of the view near the x position of the cursor.") get_active_view(app, AccessProtected, &view); GUI_Scroll_Vars scroll = {}; view_get_scroll_vars(app, view, &scroll); - f32 x = clamp_bottom(0.f, get_view_x(app, view) - 30.f); + f32 x = clamp_bot(0.f, get_view_x(app, view) - 30.f); scroll.target_x = (i32)(x + .5f); view_set_scroll(app, view, scroll); } @@ -353,7 +353,7 @@ get_page_jump(Application_Links *app, View_ID view){ f32 line_count = (f32)(height)/metrics.line_height; i32 line_count_rounded = (i32)line_count; page_jump = (f32)line_count_rounded - 3.f; - page_jump = clamp_bottom(1.f, page_jump); + page_jump = clamp_bot(1.f, page_jump); } return(page_jump); } @@ -425,7 +425,7 @@ CUSTOM_DOC("Moves the cursor one character to the left.") view_get_cursor_pos(app, view, &pos); Full_Cursor cursor = {}; view_compute_cursor(app, view, seek_pos(pos), &cursor); - i32 new_pos = clamp_bottom(0, cursor.character_pos - 1); + i32 new_pos = clamp_bot(0, cursor.character_pos - 1); view_set_cursor(app, view, seek_character_pos(new_pos), true); no_mark_snap_to_cursor_if_shift(app, view); } @@ -473,9 +473,9 @@ CUSTOM_DOC("Converts all ascii text in the range between the cursor and the mark char *mem = (char*)app->memory; buffer_read_range(app, buffer, range.min, range.max, mem); for (i32 i = 0; i < size; ++i){ - mem[i] = char_to_upper(mem[i]); + mem[i] = character_to_upper(mem[i]); } - buffer_replace_range(app, buffer, range, make_string(mem, size)); + buffer_replace_range(app, buffer, range, SCu8(mem, size)); view_set_cursor(app, view, seek_pos(range.max), true); } } @@ -493,9 +493,9 @@ CUSTOM_DOC("Converts all ascii text in the range between the cursor and the mark char *mem = (char*)app->memory; buffer_read_range(app, buffer, range.min, range.max, mem); for (i32 i = 0; i < size; ++i){ - mem[i] = char_to_lower(mem[i]); + mem[i] = character_to_lower(mem[i]); } - buffer_replace_range(app, buffer, range, make_string(mem, size)); + buffer_replace_range(app, buffer, range, SCu8(mem, size)); view_set_cursor(app, view, seek_pos(range.max), true); } } @@ -543,7 +543,7 @@ CUSTOM_DOC("Removes trailing whitespace from all lines in the current buffer.") } last_hard = buffer_size; } - else if (char_is_whitespace(at_pos)){ + else if (character_is_whitespace(at_pos)){ // NOTE(allen): do nothing } else{ @@ -777,12 +777,13 @@ CUSTOM_DOC("Attempts to close 4coder.") CUSTOM_COMMAND_SIG(goto_line) CUSTOM_DOC("Queries the user for a number, and jumps the cursor to the corresponding line.") { + u8 string_space[256]; Query_Bar bar = {}; - char string_space[256]; - bar.prompt = make_lit_string("Goto Line: "); - bar.string = make_fixed_width_string(string_space); + bar.prompt = string_u8_litexpr("Goto Line: "); + bar.string = SCu8(string_space, (umem)0); + bar.string_capacity = sizeof(string_space); if (query_user_number(app, &bar)){ - i32 line_number = str_to_int_s(bar.string); + i32 line_number = (i32)string_to_integer(bar.string, 10); View_ID view = 0; get_active_view(app, AccessProtected, &view); view_set_cursor(app, view, seek_line_char(line_number, 0), true); @@ -802,7 +803,7 @@ isearch__update_highlight(Application_Links *app, View_ID view, Managed_Object h } static void -isearch(Application_Links *app, b32 start_reversed, String query_init, b32 on_the_query_init_string){ +isearch(Application_Links *app, b32 start_reversed, String_Const_u8 query_init, b32 on_the_query_init_string){ View_ID view = 0; get_active_view(app, AccessProtected, &view); Buffer_ID buffer_id = 0; @@ -828,16 +829,17 @@ isearch(Application_Links *app, b32 start_reversed, String query_init, b32 on_th i32 start_pos = pos; Range match = make_range(pos, pos); - char bar_string_space[256]; - bar.string = make_fixed_width_string(bar_string_space); - copy(&bar.string, query_init); + u8 bar_string_space[256]; + bar.string = SCu8(bar_string_space, query_init.size); + block_copy(bar.string.str, query_init.str, query_init.size); - String isearch_str = make_lit_string("I-Search: "); - String rsearch_str = make_lit_string("Reverse-I-Search: "); + String_Const_char isearch_str = string_litexpr("I-Search: "); + String_Const_char rsearch_str = string_litexpr("Reverse-I-Search: "); b32 first_step = true; - Managed_Scope view_scope = view_get_managed_scope(app, view); + Managed_Scope view_scope = 0; + view_get_managed_scope(app, view, &view_scope); Managed_Object highlight = alloc_buffer_markers_on_buffer(app, buffer_id, 2, &view_scope); Marker_Visual visual = create_marker_visual(app, highlight); marker_visual_set_effect(app, visual, @@ -853,10 +855,10 @@ isearch(Application_Links *app, b32 start_reversed, String query_init, b32 on_th for (;;){ // NOTE(allen): Change the bar's prompt to match the current direction. if (reverse){ - bar.prompt = rsearch_str; + bar.prompt = SCu8(rsearch_str); } else{ - bar.prompt = isearch_str; + bar.prompt = SCu8(isearch_str); } b32 step_forward = false; @@ -874,22 +876,28 @@ isearch(Application_Links *app, b32 start_reversed, String query_init, b32 on_th b32 made_change = false; if (in.key.keycode == '\n' || in.key.keycode == '\t'){ if (in.key.modifiers[MDFR_CONTROL_INDEX]){ - copy(&bar.string, previous_isearch_query); + bar.string.size = cstring_length(previous_isearch_query); + block_copy(bar.string.str, previous_isearch_query, bar.string.size); } else{ - String previous_isearch_query_str = make_fixed_width_string(previous_isearch_query); - append(&previous_isearch_query_str, bar.string); - terminate_with_null(&previous_isearch_query_str); + umem size = bar.string.size; + size = clamp_top(size, sizeof(previous_isearch_query) - 1); + block_copy(previous_isearch_query, bar.string.str, size); + previous_isearch_query[size] = 0; break; } } else if (length != 0 && key_is_unmodified(&in.key)){ - append(&bar.string, make_string(character, length)); + String_u8 string = Su8(bar.string, sizeof(bar_string_space)); + string_append(&string, SCu8(character, length)); + bar.string = string.string; made_change = true; } else if (in.key.keycode == key_back){ if (key_is_unmodified(&in.key)){ - made_change = backspace_utf8(&bar.string); + umem old_bar_string_size = bar.string.size; + bar.string = backspace_utf8(bar.string); + made_change = (bar.string.size < old_bar_string_size); backspace = true; } else if (in.key.modifiers[MDFR_CONTROL_INDEX]){ @@ -938,42 +946,42 @@ isearch(Application_Links *app, b32 start_reversed, String query_init, b32 on_th if (!backspace){ if (reverse){ i32 new_pos = 0; - buffer_seek_string_insensitive_backward(app, buffer_id, start_pos - 1, 0, bar.string.str, bar.string.size, &new_pos); + buffer_seek_string_insensitive_backward(app, buffer_id, start_pos - 1, 0, bar.string, &new_pos); if (new_pos >= 0){ if (step_backward){ pos = new_pos; start_pos = new_pos; - buffer_seek_string_insensitive_backward(app, buffer_id, start_pos - 1, 0, bar.string.str, bar.string.size, &new_pos); + buffer_seek_string_insensitive_backward(app, buffer_id, start_pos - 1, 0, bar.string, &new_pos); if (new_pos < 0){ new_pos = start_pos; } } match.start = new_pos; - match.end = match.start + bar.string.size; + match.end = match.start + (i32)bar.string.size; } } else{ i32 new_pos = 0; - buffer_seek_string_insensitive_forward(app, buffer_id, start_pos + 1, 0, bar.string.str, bar.string.size, &new_pos); + buffer_seek_string_insensitive_forward(app, buffer_id, start_pos + 1, 0, bar.string, &new_pos); i32 buffer_size = 0; buffer_get_size(app, buffer_id, &buffer_size); if (new_pos < buffer_size){ if (step_forward){ pos = new_pos; start_pos = new_pos; - buffer_seek_string_insensitive_forward(app, buffer_id, start_pos + 1, 0, bar.string.str, bar.string.size, &new_pos); + buffer_seek_string_insensitive_forward(app, buffer_id, start_pos + 1, 0, bar.string, &new_pos); if (new_pos >= buffer_size){ new_pos = start_pos; } } match.start = new_pos; - match.end = match.start + bar.string.size; + match.end = match.start + (i32)bar.string.size; } } } else{ - if (match.end > match.start + bar.string.size){ - match.end = match.start + bar.string.size; + if (match.end > match.start + (i32)bar.string.size){ + match.end = match.start + (i32)bar.string.size; } } @@ -986,9 +994,10 @@ isearch(Application_Links *app, b32 start_reversed, String query_init, b32 on_th cursor_is_hidden = false; if (in.abort){ - String previous_isearch_query_str = make_fixed_width_string(previous_isearch_query); - append(&previous_isearch_query_str, bar.string); - terminate_with_null(&previous_isearch_query_str); + umem size = bar.string.size; + size = clamp_top(size, sizeof(previous_isearch_query) - 1); + block_copy(previous_isearch_query, bar.string.str, size); + previous_isearch_query[size] = 0; view_set_cursor(app, view, seek_pos(first_pos), true); } } @@ -996,15 +1005,13 @@ isearch(Application_Links *app, b32 start_reversed, String query_init, b32 on_th CUSTOM_COMMAND_SIG(search) CUSTOM_DOC("Begins an incremental search down through the current buffer for a user specified string.") { - String query = {}; - isearch(app, false, query, false); + isearch(app, false, SCu8(), false); } CUSTOM_COMMAND_SIG(reverse_search) CUSTOM_DOC("Begins an incremental search up through the current buffer for a user specified string.") { - String query = {}; - isearch(app, true, query, false); + isearch(app, true, SCu8(), false); } CUSTOM_COMMAND_SIG(search_identifier) @@ -1016,8 +1023,8 @@ CUSTOM_DOC("Begins an incremental search down through the current buffer for the view_get_buffer(app, view, AccessProtected, &buffer_id); i32 pos = 0; view_get_cursor_pos(app, view, &pos); - char space[256]; - String query = read_identifier_at_pos(app, buffer_id, pos, space, sizeof(space), 0); + Scratch_Block scratch(app); + String_Const_u8 query = read_identifier_at_pos(app, scratch, buffer_id, pos, 0); isearch(app, false, query, true); } @@ -1030,8 +1037,8 @@ CUSTOM_DOC("Begins an incremental search up through the current buffer for the w view_get_buffer(app, view, AccessProtected, &buffer_id); i32 pos = 0; view_get_cursor_pos(app, view, &pos); - char space[256]; - String query = read_identifier_at_pos(app, buffer_id, pos, space, sizeof(space), 0); + Scratch_Block scratch(app); + String_Const_u8 query = read_identifier_at_pos(app, scratch, buffer_id, pos, 0); isearch(app, true, query, true); } @@ -1039,18 +1046,20 @@ CUSTOM_COMMAND_SIG(replace_in_range) CUSTOM_DOC("Queries the user for two strings, and replaces all occurences of the first string in the range between the cursor and the mark with the second string.") { Query_Bar replace = {}; - char replace_space[1024]; - replace.prompt = make_lit_string("Replace: "); - replace.string = make_fixed_width_string(replace_space); + u8 replace_space[1024]; + replace.prompt = string_u8_litexpr("Replace: "); + replace.string = SCu8(replace_space, (umem)0); + replace.string_capacity = sizeof(replace_space); Query_Bar with = {}; - char with_space[1024]; - with.prompt = make_lit_string("With: "); - with.string = make_fixed_width_string(with_space); + u8 with_space[1024]; + with.prompt = string_u8_litexpr("With: "); + with.string = SCu8(with_space, (umem)0); + with.string_capacity = sizeof(with_space); if (query_user_string(app, &replace) && replace.string.size != 0 && query_user_string(app, &with)){ - String r = replace.string; - String w = with.string; + String_Const_u8 r = replace.string; + String_Const_u8 w = with.string; View_ID view = 0; get_active_view(app, AccessOpen, &view); @@ -1060,26 +1069,27 @@ CUSTOM_DOC("Queries the user for two strings, and replaces all occurences of the Range range = get_view_range(app, view); i32 pos = range.min; - i32 new_pos; - buffer_seek_string_forward(app, buffer_id, pos, 0, r.str, r.size, &new_pos); + i32 new_pos = 0; + buffer_seek_string_forward(app, buffer_id, pos, 0, r, &new_pos); global_history_edit_group_begin(app); for (;new_pos + r.size <= range.end;){ - buffer_replace_range(app, buffer_id, make_range(new_pos, new_pos + r.size), w); + buffer_replace_range(app, buffer_id, make_range(new_pos, new_pos + (i32)r.size), w); range = get_view_range(app, view); - pos = new_pos + w.size; - buffer_seek_string_forward(app, buffer_id, pos, 0, r.str, r.size, &new_pos); + pos = new_pos + (i32)w.size; + buffer_seek_string_forward(app, buffer_id, pos, 0, r, &new_pos); } global_history_edit_group_end(app); } } static void -query_replace_base(Application_Links *app, View_ID view, Buffer_ID buffer_id, i32 pos, String r, String w){ +query_replace_base(Application_Links *app, View_ID view, Buffer_ID buffer_id, i32 pos, String_Const_u8 r, String_Const_u8 w){ i32 new_pos = 0; - buffer_seek_string_forward(app, buffer_id, pos, 0, r.str, r.size, &new_pos); + buffer_seek_string_forward(app, buffer_id, pos, 0, r, &new_pos); - Managed_Scope view_scope = view_get_managed_scope(app, view); + Managed_Scope view_scope = 0; + view_get_managed_scope(app, view, &view_scope); Managed_Object highlight = alloc_buffer_markers_on_buffer(app, buffer_id, 2, &view_scope); Marker_Visual visual = create_marker_visual(app, highlight); marker_visual_set_effect(app, visual, VisualType_CharacterHighlightRanges, Stag_Highlight, Stag_At_Highlight, 0); @@ -1091,7 +1101,7 @@ query_replace_base(Application_Links *app, View_ID view, Buffer_ID buffer_id, i3 User_Input in = {}; for (;new_pos < buffer_size;){ - Range match = make_range(new_pos, new_pos + r.size); + Range match = make_range(new_pos, new_pos + (i32)r.size); isearch__update_highlight(app, view, highlight, match.min, match.max); in = get_user_input(app, EventOnAnyKey, EventOnMouseLeftButton|EventOnMouseRightButton); @@ -1100,13 +1110,13 @@ query_replace_base(Application_Links *app, View_ID view, Buffer_ID buffer_id, i3 if (in.key.character == 'y' || in.key.character == 'Y' || in.key.character == '\n' || in.key.character == '\t'){ buffer_replace_range(app, buffer_id, match, w); - pos = match.start + w.size; + pos = match.start + (i32)w.size; } else{ pos = match.max; } - buffer_seek_string_forward(app, buffer_id, pos, 0, r.str, r.size, &new_pos); + buffer_seek_string_forward(app, buffer_id, pos, 0, r, &new_pos); } managed_object_free(app, highlight); @@ -1120,23 +1130,24 @@ query_replace_base(Application_Links *app, View_ID view, Buffer_ID buffer_id, i3 } static void -query_replace_parameter(Application_Links *app, String replace_str, i32 start_pos, b32 add_replace_query_bar){ - Query_Bar replace; - replace.prompt = make_lit_string("Replace: "); +query_replace_parameter(Application_Links *app, String_Const_u8 replace_str, i32 start_pos, b32 add_replace_query_bar){ + Query_Bar replace = {}; + replace.prompt = string_u8_litexpr("Replace: "); replace.string = replace_str; if (add_replace_query_bar){ start_query_bar(app, &replace, 0); } - Query_Bar with; - char with_space[1024]; - with.prompt = make_lit_string("With: "); - with.string = make_fixed_width_string(with_space); + Query_Bar with = {}; + u8 with_space[1024]; + with.prompt = string_u8_litexpr("With: "); + with.string = SCu8(with_space, (umem)0); + with.string_capacity = sizeof(with_space); if (query_user_string(app, &with)){ - String r = replace.string; - String w = with.string; + String_Const_u8 r = replace.string; + String_Const_u8 w = with.string; View_ID view = 0; get_active_view(app, AccessProtected, &view); @@ -1144,9 +1155,8 @@ query_replace_parameter(Application_Links *app, String replace_str, i32 start_po view_get_buffer(app, view, AccessProtected, &buffer_id); i32 pos = start_pos; - Query_Bar bar; - bar.prompt = make_lit_string("Replace? (y)es, (n)ext, (esc)\n"); - bar.string = null_string; + Query_Bar bar = {}; + bar.prompt = string_u8_litexpr("Replace? (y)es, (n)ext, (esc)\n"); start_query_bar(app, &bar, 0); query_replace_base(app, view, buffer_id, pos, r, w); @@ -1162,9 +1172,10 @@ CUSTOM_DOC("Queries the user for two strings, and incrementally replaces every o view_get_buffer(app, view, AccessOpen, &buffer); if (buffer != 0){ Query_Bar replace = {}; - char replace_space[1024]; - replace.prompt = make_lit_string("Replace: "); - replace.string = make_fixed_width_string(replace_space); + u8 replace_space[1024]; + replace.prompt = string_u8_litexpr("Replace: "); + replace.string = SCu8(replace_space, (umem)0); + replace.string_capacity = sizeof(replace_space); if (query_user_string(app, &replace)){ if (replace.string.size > 0){ i32 pos = 0; @@ -1186,8 +1197,8 @@ CUSTOM_DOC("Queries the user for a string, and incrementally replace every occur i32 pos = 0; view_get_cursor_pos(app, view, &pos); Range range = {}; - char space[256]; - String replace = read_identifier_at_pos(app, buffer_id, pos, space, sizeof(space), &range); + Scratch_Block scratch(app); + String_Const_u8 replace = read_identifier_at_pos(app, scratch, buffer_id, pos, &range); if (replace.size != 0){ query_replace_parameter(app, replace, range.min, true); } @@ -1202,25 +1213,24 @@ CUSTOM_DOC("Queries the user for a string, and incrementally replace every occur Buffer_ID buffer = 0; view_get_buffer(app, view, AccessOpen, &buffer); if (buffer != 0){ - Partition *part = &global_part; - Temp_Memory temp = begin_temp_memory(part); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); Range range = get_view_range(app, view); i32 replace_length = range.max - range.min; if (replace_length != 0){ - char *replace_space = push_array(part, char, replace_length); - if (buffer_read_range(app, buffer, range.min, range.max, replace_space)){ - String replace = make_string(replace_space, replace_length); - query_replace_parameter(app, replace, range.min, true); + u8 *replace_space = push_array(scratch, u8, replace_length); + if (buffer_read_range(app, buffer, range.min, range.max, (char*)replace_space)){ + query_replace_parameter(app, SCu8(replace_space, replace_length), range.min, true); } } - end_temp_memory(temp); + end_temp(temp); } } //////////////////////////////// static void -save_all_dirty_buffers_with_postfix(Application_Links *app, String postfix){ +save_all_dirty_buffers_with_postfix(Application_Links *app, String_Const_u8 postfix){ Arena *scratch = context_get_arena(app); Buffer_ID buffer = 0; for (get_buffer_next(app, 0, AccessOpen, &buffer); @@ -1229,15 +1239,12 @@ save_all_dirty_buffers_with_postfix(Application_Links *app, String postfix){ Dirty_State dirty = 0; buffer_get_dirty_state(app, buffer, &dirty); if (dirty == DirtyState_UnsavedChanges){ - Temp_Memory_Arena temp = begin_temp_memory(scratch); - String file_name = buffer_push_file_name(app, buffer, scratch); - if (file_name.size >= postfix.size){ - String file_name_post = substr_tail(file_name, file_name.size - postfix.size); - if (match(file_name_post, postfix)){ - buffer_save(app, buffer, file_name, 0); - } + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 file_name = buffer_push_file_name(app, buffer, scratch); + if (string_match(string_postfix(file_name, postfix.size), postfix)){ + buffer_save(app, buffer, file_name, 0); } - end_temp_memory(temp); + end_temp(temp); } } } @@ -1245,26 +1252,25 @@ save_all_dirty_buffers_with_postfix(Application_Links *app, String postfix){ CUSTOM_COMMAND_SIG(save_all_dirty_buffers) CUSTOM_DOC("Saves all buffers marked dirty (showing the '*' indicator).") { - String empty = {}; + String_Const_u8 empty = {}; save_all_dirty_buffers_with_postfix(app, empty); } static void -delete_file_base(Application_Links *app, String file_name, Buffer_ID buffer_id){ - String path = path_of_directory(file_name); - char space[4096]; - String cmd = make_fixed_width_string(space); -#if defined(IS_WINDOWS) - append(&cmd, "del "); -#elif defined(IS_LINUX) || defined(IS_MAC) - append(&cmd, "rm "); +delete_file_base(Application_Links *app, String_Const_u8 file_name, Buffer_ID buffer_id){ + String_Const_u8 path = string_remove_last_folder(file_name); + Scratch_Block scratch(app); + List_String_Const_u8 list = {}; +#if OS_WINDOWS + string_list_push_u8_lit(scratch, &list, "del "); +#elif OS_LINUX || OS_MAC + string_list_push_u8_lit(scratch, &list, "rm "); #else # error no delete file command for this platform #endif - append(&cmd, '"'); - append(&cmd, front_of_directory(file_name)); - append(&cmd, '"'); - exec_system_command(app, 0, buffer_identifier(0), path.str, path.size, cmd.str, cmd.size, 0); + string_list_pushf(scratch, &list, "\"%.*s\"", string_expand(file_name)); + String_Const_u8 cmd = string_list_flatten(scratch, list, StringFill_NullTerminate); + exec_system_command(app, 0, buffer_identifier(0), path, cmd, 0); kill_buffer(app, buffer_identifier(buffer_id), 0, BufferKill_AlwaysKill); } @@ -1275,25 +1281,36 @@ CUSTOM_DOC("Deletes the file of the current buffer if 4coder has the appropriate get_active_view(app, AccessAll, &view); Buffer_ID buffer = 0; view_get_buffer(app, view, AccessAll, &buffer); - Arena *scratch = context_get_arena(app); - Temp_Memory_Arena temp = begin_temp_memory(scratch); - String file_name = buffer_push_file_name(app, buffer, scratch); + Scratch_Block scratch(app); + String_Const_u8 file_name = buffer_push_file_name(app, buffer, scratch); if (file_name.size > 0){ - char space[4096]; - Query_Bar bar; - bar.prompt = make_fixed_width_string(space); - append(&bar.prompt, "Delete '"); - append(&bar.prompt, file_name); - append(&bar.prompt, "' (Y)es, (n)o"); - bar.string = null_string; + Query_Bar bar = {}; + bar.prompt = string_u8_pushf(scratch, "Delete '%.*s' (Y)es, (n)o", string_expand(file_name)); if (start_query_bar(app, &bar, 0) != 0){ - User_Input in = get_user_input(app, EventOnAnyKey, 0); - if (in.key.keycode == 'Y'){ - delete_file_base(app, file_name, buffer); + b32 cancelled = false; + for (;!cancelled;){ + User_Input in = get_user_input(app, EventOnAnyKey, 0); + switch (in.key.keycode){ + case 'Y': + { + delete_file_base(app, file_name, buffer); + }break; + + case key_shift: + case key_ctrl: + case key_alt: + case key_cmnd: + case key_caps: + {}break; + + default: + { + cancelled = true; + }break; + } } } } - end_temp_memory(temp); } CUSTOM_COMMAND_SIG(save_to_query) @@ -1305,41 +1322,33 @@ CUSTOM_DOC("Queries the user for a file name and saves the contents of the curre view_get_buffer(app, view, AccessAll, &buffer); Arena *scratch = context_get_arena(app); - Temp_Memory_Arena temp = begin_temp_memory(scratch); - String buffer_name = buffer_push_unique_buffer_name(app, buffer, scratch); + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 buffer_name = buffer_push_unique_buffer_name(app, buffer, scratch); // Query the user + u8 name_space[4096]; Query_Bar bar = {}; - char prompt_space[4096]; - bar.prompt = make_fixed_width_string(prompt_space); - append(&bar.prompt, "Save '"); - append(&bar.prompt, buffer_name); - append(&bar.prompt, "' to: "); - - char name_space[4096]; - bar.string = make_fixed_width_string(name_space); + bar.prompt = string_u8_pushf(scratch, "Save '%.*s' to: ", string_expand(buffer_name)); + bar.string = SCu8(name_space, (umem)0); + bar.string_capacity = sizeof(name_space); if (query_user_string(app, &bar)){ if (bar.string.size != 0){ - char new_file_name_space[4096]; - String new_file_name = make_fixed_width_string(new_file_name_space); - i32 hot_dir_size = directory_get_hot(app, 0, 0); - if (new_file_name.size + hot_dir_size <= new_file_name.memory_size){ - new_file_name.size += directory_get_hot(app, new_file_name.str + new_file_name.size, new_file_name.memory_size - new_file_name.size); - if (append(&new_file_name, bar.string)){ - if (buffer_save(app, buffer, new_file_name, BufferSave_IgnoreDirtyFlag)){ - Buffer_ID new_buffer = 0; - create_buffer(app, new_file_name, BufferCreate_NeverNew|BufferCreate_JustChangedFile, &new_buffer); - if (new_buffer != 0 && new_buffer != buffer){ - kill_buffer(app, buffer_identifier(buffer), 0, BufferKill_AlwaysKill); - view_set_buffer(app, view, new_buffer, 0); - } - } + List_String_Const_u8 new_file_name_list = {}; + string_list_push(scratch, &new_file_name_list, push_hot_directory(app, scratch)); + string_list_push(scratch, &new_file_name_list, bar.string); + String_Const_u8 new_file_name = string_list_flatten(scratch, new_file_name_list); + if (buffer_save(app, buffer, new_file_name, BufferSave_IgnoreDirtyFlag)){ + Buffer_ID new_buffer = 0; + create_buffer(app, new_file_name, BufferCreate_NeverNew|BufferCreate_JustChangedFile, &new_buffer); + if (new_buffer != 0 && new_buffer != buffer){ + kill_buffer(app, buffer_identifier(buffer), 0, BufferKill_AlwaysKill); + view_set_buffer(app, view, new_buffer, 0); } } } } - end_temp_memory(temp); + end_temp(temp); } CUSTOM_COMMAND_SIG(rename_file_query) @@ -1351,32 +1360,24 @@ CUSTOM_DOC("Queries the user for a new name and renames the file of the current view_get_buffer(app, view, AccessAll, &buffer); Arena *scratch = context_get_arena(app); - Temp_Memory_Arena temp = begin_temp_memory(scratch); - - String file_name = buffer_push_file_name(app, buffer, scratch);; + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 file_name = buffer_push_file_name(app, buffer, scratch);; if (file_name.size > 0){ // Query the user + String_Const_u8 front = string_front_of_path(file_name); + u8 name_space[4096]; Query_Bar bar = {}; - - char prompt_space[4096]; - bar.prompt = make_fixed_width_string(prompt_space); - append(&bar.prompt, "Rename '"); - append(&bar.prompt, front_of_directory(file_name)); - append(&bar.prompt, "' to: "); - - char name_space[4096]; - bar.string = make_fixed_width_string(name_space); + bar.prompt = string_u8_pushf(scratch, "Rename '%.*s' to: ", string_expand(front)); + bar.string = SCu8(name_space, (umem)0); + bar.string_capacity = sizeof(name_space); if (query_user_string(app, &bar)){ if (bar.string.size != 0){ // TODO(allen): There should be a way to say, "detach a buffer's file" and "attach this file to a buffer" - char new_file_name_space[4096]; - String new_file_name = make_fixed_width_string(new_file_name_space); - copy(&new_file_name, file_name); - remove_last_folder(&new_file_name); - append(&new_file_name, bar.string); - terminate_with_null(&new_file_name); - + List_String_Const_u8 new_file_name_list = {}; + string_list_push(scratch, &new_file_name_list, file_name); + string_list_push(scratch, &new_file_name_list, bar.string); + String_Const_u8 new_file_name = string_list_flatten(scratch, new_file_name_list, StringFill_NullTerminate); if (buffer_save(app, buffer, new_file_name, BufferSave_IgnoreDirtyFlag)){ Buffer_ID new_buffer = 0; create_buffer(app, new_file_name, BufferCreate_NeverNew|BufferCreate_JustChangedFile, &new_buffer); @@ -1390,38 +1391,28 @@ CUSTOM_DOC("Queries the user for a new name and renames the file of the current } - end_temp_memory(temp); + end_temp(temp); } CUSTOM_COMMAND_SIG(make_directory_query) CUSTOM_DOC("Queries the user for a name and creates a new directory with the given name.") { - char hot_space[2048]; - i32 hot_length = directory_get_hot(app, hot_space, sizeof(hot_space)); - if (hot_length < sizeof(hot_space)){ - String hot = make_string(hot_space, hot_length); - - // Query the user - Query_Bar bar; - - char prompt_space[4096]; - bar.prompt = make_fixed_width_string(prompt_space); - append(&bar.prompt, "Make directory at '"); - append(&bar.prompt, hot); - append(&bar.prompt, "': "); - - char name_space[4096]; - bar.string = make_fixed_width_string(name_space); - if (!query_user_string(app, &bar)) return; - if (bar.string.size == 0) return; - - char cmd_space[4096]; - String cmd = make_fixed_width_string(cmd_space); - append(&cmd, "mkdir "); - if (append_checked(&cmd, bar.string)){ - exec_system_command(app, 0, buffer_identifier(0), hot.str, hot.size, cmd.str, cmd.size, 0); - } - } + Scratch_Block scratch(app); + + String_Const_u8 hot = push_hot_directory(app, scratch); + + // Query the user + u8 name_space[4096]; + Query_Bar bar = {}; + bar.prompt = string_u8_pushf(scratch, "Make directory at '%.*s': ", string_expand(hot)); + bar.string = SCu8(name_space, (umem)0); + bar.string_capacity = sizeof(name_space); + + if (!query_user_string(app, &bar)) return; + if (bar.string.size == 0) return; + + String_Const_u8 cmd = string_u8_pushf(scratch, "mkdir %.*s", string_expand(bar.string)); + exec_system_command(app, 0, buffer_identifier(0), hot, cmd, 0); } //////////////////////////////// @@ -1455,11 +1446,11 @@ CUSTOM_DOC("Swaps the line under the cursor with the line above it, and moves th i32 this_line_pos = this_line_cursor.pos; i32 next_line_pos = next_line_cursor.pos; - Partition *part = &global_part; - Temp_Memory temp = begin_temp_memory(part); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); i32 length = next_line_pos - prev_line_pos; - char *swap = push_array(part, char, length + 1); + char *swap = push_array(scratch, char, length + 1); i32 first_len = next_line_pos - this_line_pos; if (buffer_read_range(app, buffer, this_line_pos, next_line_pos, swap)){ @@ -1480,12 +1471,12 @@ CUSTOM_DOC("Swaps the line under the cursor with the line above it, and moves th } if (buffer_read_range(app, buffer, prev_line_pos, this_line_pos, swap + first_len)){ - buffer_replace_range(app, buffer, make_range(prev_line_pos, next_line_pos), make_string(swap, length)); + buffer_replace_range(app, buffer, make_range(prev_line_pos, next_line_pos), SCu8(swap, length)); view_set_cursor(app, view, seek_line_char(prev_line, 1), true); } } - end_temp_memory(temp); + end_temp(temp); } } } @@ -1524,18 +1515,11 @@ CUSTOM_DOC("Create a copy of the line on which the cursor sits.") view_get_cursor_pos(app, view, &cursor_pos); Full_Cursor cursor = {}; view_compute_cursor(app, view, seek_pos(cursor_pos), &cursor); - Partition *part = &global_part; - Temp_Memory temp = begin_temp_memory(part); - String line_string = {}; - char *before_line = push_array(part, char, 1); - if (read_line(app, part, buffer_id, cursor.line, &line_string)){ - *before_line = '\n'; - line_string.str = before_line; - line_string.size += 1; - i32 pos = buffer_get_line_end(app, buffer_id, cursor.line); - buffer_replace_range(app, buffer_id, make_range(pos), line_string); - } - end_temp_memory(temp); + Scratch_Block scratch(app); + String_Const_u8 line_string = scratch_read_line(app, scratch, buffer_id, cursor.line); + String_Const_u8 insertion = string_u8_pushf(scratch, "\n%.*s", string_expand(line_string)); + i32 pos = buffer_get_line_end(app, buffer_id, cursor.line); + buffer_replace_range(app, buffer_id, make_range(pos), insertion); } CUSTOM_COMMAND_SIG(delete_line) @@ -1551,9 +1535,6 @@ CUSTOM_DOC("Delete the line the on which the cursor sits.") Full_Cursor cursor = {}; view_compute_cursor(app, view, seek_pos(cursor_pos), &cursor); - Partition *part = &global_part; - - Temp_Memory temp = begin_temp_memory(part); i32 start = buffer_get_line_start(app, buffer_id, cursor.line); i32 end = buffer_get_line_end(app, buffer_id, cursor.line) + 1; i32 buffer_size = 0; @@ -1568,9 +1549,7 @@ CUSTOM_DOC("Delete the line the on which the cursor sits.") } } - buffer_replace_range(app, buffer_id, make_range(start, end), make_lit_string("")); - - end_temp_memory(temp); + buffer_replace_range(app, buffer_id, make_range(start, end), string_u8_litexpr("")); } //////////////////////////////// @@ -1578,52 +1557,64 @@ CUSTOM_DOC("Delete the line the on which the cursor sits.") static b32 get_cpp_matching_file(Application_Links *app, Buffer_ID buffer, Buffer_ID *buffer_out){ b32 result = false; - Arena *scratch = context_get_arena(app); - Temp_Memory_Arena temp = begin_temp_memory(scratch); - String file_name = {}; - buffer_get_file_name(app, buffer, 0, &file_name.memory_size); - file_name.memory_size += 4; - file_name.str = push_array(scratch, char, file_name.memory_size); - buffer_get_file_name(app, buffer, &file_name, 0); - buffer_push_file_name(app, buffer, scratch); + Scratch_Block scratch(app); + String_Const_u8 file_name = buffer_push_file_name(app, buffer, scratch); if (file_name.size > 0){ - String extension = file_extension(file_name); - String new_extensions[2] = {}; + String_Const_u8 extension = string_file_extension(file_name); + String_Const_u8 new_extensions[2] = {}; i32 new_extensions_count = 0; - if (match(extension, "cpp") || match(extension, "cc")){ - new_extensions[0] = make_lit_string("h"); - new_extensions[1] = make_lit_string("hpp"); + if (string_match(extension, string_u8_litexpr("cpp")) || string_match(extension, string_u8_litexpr("cc"))){ + new_extensions[0] = string_u8_litexpr("h"); + new_extensions[1] = string_u8_litexpr("hpp"); new_extensions_count = 2; } - else if (match(extension, "c")){ - new_extensions[0] = make_lit_string("h"); + else if (string_match(extension, string_u8_litexpr("c"))){ + new_extensions[0] = string_u8_litexpr("h"); new_extensions_count = 1; } - else if (match(extension, "h")){ - new_extensions[0] = make_lit_string("c"); - new_extensions[1] = make_lit_string("cpp"); + else if (string_match(extension, string_u8_litexpr("h"))){ + new_extensions[0] = string_u8_litexpr("c"); + new_extensions[1] = string_u8_litexpr("cpp"); new_extensions_count = 2; } - else if (match(extension, "hpp")){ - new_extensions[0] = make_lit_string("cpp"); + else if (string_match(extension, string_u8_litexpr("hpp"))){ + new_extensions[0] = string_u8_litexpr("cpp"); new_extensions_count = 1; } - remove_extension(&file_name); - i32 base_pos = file_name.size; - for (i32 i = 0; i < new_extensions_count; ++i){ - String ext = new_extensions[i]; - file_name.size = base_pos; - append(&file_name, ext); - - if (open_file(app, buffer_out, file_name.str, file_name.size, false, true)){ + + String_Const_u8 file_without_extension = string_file_without_extension(file_name); + for (i32 i = 0; i < new_extensions_count; i += 1){ + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 new_extension = new_extensions[i]; + String_Const_u8 new_file_name = string_u8_pushf(scratch, "%.*s.%.*s", string_expand(file_without_extension), string_expand(new_extension)); + if (open_file(app, buffer_out, new_file_name, false, true)){ result = true; break; } + end_temp(temp); } + + +#if 0 + char *space = push_array(scratch, char, file_name.size + 16); + String file_name_old = make_string_cap(space, 0, (i32)file_name.size + 16); + append(&file_name_old, string_old_from_new(file_name)); + remove_extension(&file_name_old); + i32 base_pos = file_name_old.size; + for (i32 i = 0; i < new_extensions_count; ++i){ + + String ext = string_old_from_new(new_extensions[i]); + file_name.size = base_pos; + append(&file_name_old, ext); + if (open_file(app, buffer_out, file_name_old.str, file_name_old.size, false, true)){ + result = true; + break; + } + + } +#endif } - end_temp_memory(temp); - return(result); } @@ -1635,39 +1626,33 @@ CUSTOM_DOC("Reads a filename from surrounding '\"' characters and attempts to op Buffer_ID buffer_id = 0; view_get_buffer(app, view, AccessProtected, &buffer_id); if (buffer_exists(app, buffer_id)){ - Arena *arena = context_get_arena(app); - Temp_Memory_Arena temp = begin_temp_memory(arena); + Scratch_Block scratch(app); i32 pos = 0; view_get_cursor_pos(app, view, &pos); - i32 start = 0; - i32 end = 0; - buffer_seek_delimiter_forward(app, buffer_id, pos, '"', &end); - buffer_seek_delimiter_backward(app, buffer_id, pos, '"', &start); - ++start; + Range range = {}; + buffer_seek_delimiter_forward(app, buffer_id, pos, '"', &range.end); + buffer_seek_delimiter_backward(app, buffer_id, pos, '"', &range.start); + range.start += 1; - i32 quoted_name_size = end - start; - char *quoted_name = push_array(arena, char, quoted_name_size); - if (buffer_read_range(app, buffer_id, start, end, quoted_name)){ - String file_name = {}; - buffer_get_file_name(app, buffer_id, 0, &file_name.memory_size); - file_name.memory_size += quoted_name_size + 1; - file_name.str = push_array(arena, char, file_name.memory_size); - buffer_get_file_name(app, buffer_id, &file_name, 0); - remove_last_folder(&file_name); - append(&file_name, make_string(quoted_name, quoted_name_size)); - terminate_with_null(&file_name); - - get_next_view_looped_primary_panels(app, view, AccessAll); - if (view != 0){ - if (view_open_file(app, view, file_name.str, file_name.size, true)){ - view_set_active(app, view); - } - } + String_Const_u8 quoted_name = scratch_read(app, scratch, buffer_id, range); + + String_Const_u8 file_name = buffer_push_file_name(app, buffer_id, scratch); + String_Const_u8 path = string_remove_last_folder(file_name); + + if (character_is_slash(string_get_character(path, path.size - 1))){ + path = string_chop(path, 1); } - end_temp_memory(temp); + String_Const_u8 new_file_name = string_u8_pushf(scratch, "%.*s/%.*s", string_expand(path), string_expand(quoted_name)); + + view = get_next_view_looped_primary_panels(app, view, AccessAll); + if (view != 0){ + if (view_open_file(app, view, new_file_name, true)){ + view_set_active(app, view); + } + } } } @@ -1680,7 +1665,7 @@ CUSTOM_DOC("If the current file is a *.cpp or *.h, attempts to open the correspo view_get_buffer(app, view, AccessAll, &buffer); Buffer_ID new_buffer = 0; if (get_cpp_matching_file(app, buffer, &new_buffer)){ - get_next_view_looped_primary_panels(app, view, AccessAll); + view = get_next_view_looped_primary_panels(app, view, AccessAll); view_set_buffer(app, view, new_buffer, 0); view_set_active(app, view); } @@ -1764,10 +1749,10 @@ CUSTOM_DOC("Saves the current buffer.") Buffer_ID buffer = 0; view_get_buffer(app, view, AccessProtected, &buffer); Arena *scratch = context_get_arena(app); - Temp_Memory_Arena temp = begin_temp_memory(scratch); - String file_name = buffer_push_file_name(app, buffer, scratch); + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 file_name = buffer_push_file_name(app, buffer, scratch); buffer_save(app, buffer, file_name, 0); - end_temp_memory(temp); + end_temp(temp); } CUSTOM_COMMAND_SIG(reopen) @@ -1789,13 +1774,13 @@ record_get_new_cursor_position_undo(Application_Links *app, Buffer_ID buffer_id, default: case RecordKind_Single: { - new_edit_position = record.single.first + record.single.string_backward.size; + new_edit_position = record.single.first + (i32)record.single.string_backward.size; }break; case RecordKind_Group: { Record_Info sub_record = {}; buffer_history_get_group_sub_record(app, buffer_id, index, 0, &sub_record); - new_edit_position = sub_record.single.first + sub_record.single.string_backward.size; + new_edit_position = sub_record.single.first + (i32)sub_record.single.string_backward.size; }break; } return(new_edit_position); @@ -1815,13 +1800,13 @@ record_get_new_cursor_position_redo(Application_Links *app, Buffer_ID buffer_id, default: case RecordKind_Single: { - new_edit_position = record.single.first + record.single.string_forward.size; + new_edit_position = record.single.first + (i32)record.single.string_forward.size; }break; case RecordKind_Group: { Record_Info sub_record = {}; buffer_history_get_group_sub_record(app, buffer_id, index, record.group.count - 1, &sub_record); - new_edit_position = sub_record.single.first + sub_record.single.string_forward.size; + new_edit_position = sub_record.single.first + (i32)sub_record.single.string_forward.size; }break; } return(new_edit_position); @@ -1871,7 +1856,7 @@ CUSTOM_DOC("Advances forwards through the undo history of the current buffer.") CUSTOM_COMMAND_SIG(undo_all_buffers) CUSTOM_DOC("Advances backward through the undo history in the buffer containing the most recent regular edit.") { - Partition *scratch = &global_part; + Arena *scratch = context_get_arena(app); i32 highest_edit_number = -1; Buffer_ID first_buffer_match = 0; Buffer_ID last_buffer_match = 0; @@ -1901,7 +1886,7 @@ CUSTOM_DOC("Advances backward through the undo history in the buffer containing } } - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); Buffer_ID *match_buffers = push_array(scratch, Buffer_ID, match_count); i32 *new_positions = push_array(scratch, i32, match_count); match_count = 0; @@ -1944,13 +1929,13 @@ CUSTOM_DOC("Advances backward through the undo history in the buffer containing view_buffer_set(app, match_buffers, new_positions, match_count); - end_temp_memory(temp); + end_temp(temp); } CUSTOM_COMMAND_SIG(redo_all_buffers) CUSTOM_DOC("Advances forward through the undo history in the buffer containing the most recent regular edit.") { - Partition *scratch = &global_part; + Arena *scratch = context_get_arena(app); i32 lowest_edit_number = 0x7FFFFFFF; Buffer_ID first_buffer_match = 0; Buffer_ID last_buffer_match = 0; @@ -1982,7 +1967,7 @@ CUSTOM_DOC("Advances forward through the undo history in the buffer containing t } } - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); Buffer_ID *match_buffers = push_array(scratch, Buffer_ID, match_count); i32 *new_positions = push_array(scratch, i32, match_count); match_count = 0; @@ -2027,7 +2012,7 @@ CUSTOM_DOC("Advances forward through the undo history in the buffer containing t view_buffer_set(app, match_buffers, new_positions, match_count); - end_temp_memory(temp); + end_temp(temp); } //////////////////////////////// diff --git a/4coder_base_types.cpp b/4coder_base_types.cpp index 6e6087cd..a266857c 100644 --- a/4coder_base_types.cpp +++ b/4coder_base_types.cpp @@ -4,6 +4,9 @@ // TOP +#if !defined(FCODER_BASE_TYPES_CPP) +#define FCODER_BASE_TYPES_CPP + #define C_MATH 1 static i32 @@ -21,29 +24,125 @@ round32(f32 v){ return(floor32(v + 0.5f)); } +static i8 +round_up_i8(i8 x, i8 b){ + x += b - 1; + x -= x%b; + return(x); +} +static u8 +round_up_u8(u8 x, u8 b){ + x += b - 1; + x -= x%b; + return(x); +} +static i16 +round_up_i16(i16 x, i16 b){ + x += b - 1; + x -= x%b; + return(x); +} +static u16 +round_up_u16(u16 x, u16 b){ + x += b - 1; + x -= x%b; + return(x); +} static i32 -trun32(f32 v){ - return((i32)(v)); +round_up_i32(i32 x, i32 b){ + x += b - 1; + x -= x%b; + return(x); +} +static u32 +round_up_u32(u32 x, u32 b){ + x += b - 1; + x -= x%b; + return(x); +} +static i64 +round_up_i64(i64 x, i64 b){ + x += b - 1; + x -= x%b; + return(x); +} +static u64 +round_up_u64(u64 x, u64 b){ + x += b - 1; + x -= x%b; + return(x); +} +static imem +round_up_imem(imem x, imem b){ + x += b - 1; + x -= x%b; + return(x); +} +static umem +round_up_umem(umem x, umem b){ + x += b - 1; + x -= x%b; + return(x); } +static i8 +round_down_i8(i8 x, i8 b){ + x -= x%b; + return(x); +} +static u8 +round_down_u8(u8 x, u8 b){ + x -= x%b; + return(x); +} +static i16 +round_down_i16(i16 x, i16 b){ + x -= x%b; + return(x); +} +static u16 +round_down_u16(u16 x, u16 b){ + x -= x%b; + return(x); +} static i32 -div_ceil(i32 n, i32 d){ - return( ((n) % (d) != 0) + ((n) / (d)) ); +round_down_i32(i32 x, i32 b){ + x -= x%b; + return(x); +} +static u32 +round_down_u32(u32 x, u32 b){ + x -= x%b; + return(x); +} +static i64 +round_down_i64(i64 x, i64 b){ + x -= x%b; + return(x); +} +static u64 +round_down_u64(u64 x, u64 b){ + x -= x%b; + return(x); +} +static imem +round_down_imem(imem x, imem b){ + x -= x%b; + return(x); +} +static umem +round_down_umem(umem x, umem b){ + x -= x%b; + return(x); } -static i32 -l_round_up_i32(i32 x, i32 b){ - i32 t = x + b - 1; - return(t - (t%b)); +static f32 +f32_integer(f32 x){ + return((f32)((i32)x)); } static u32 -l_round_up_u32(u32 x, u32 b){ - i32 t = x + b - 1; - return(t - (t%b)); -} - -static u32 round_up_pot_u32(u32 x){ +round_up_pot_u32(u32 x){ --x; x |= x >> 1; x |= x >> 2; @@ -56,13 +155,123 @@ static u32 round_up_pot_u32(u32 x){ //////////////////////////////// -// scalars +static Data +make_data(void *memory, umem size){ + Data data = {(u8*)memory, size}; + return(data); +} -#define DEG_TO_RAD (0.0174533f) +global_const Data zero_data = {}; + +#define data_initr(m,s) {(m), (s)} +#define data_initr_struct(s) {(s), sizeof(*(s))} +#define data_initr_array(a) {(a), sizeof(a)} +#define data_initr_string(s) {(s), sizeof(s) - 1} + +//////////////////////////////// + +static void +block_zero(void *mem, umem size){ + for (u8 *p = (u8*)mem, *e = p + size; p < e; p += 1){ + *p = 0; + } +} +static void +block_fill_ones(void *mem, umem size){ + for (u8 *p = (u8*)mem, *e = p + size; p < e; p += 1){ + *p = 0xFF; + } +} +static void +block_copy(void *dst, void *src, umem size){ + u8 *d = (u8*)dst; + u8 *s = (u8*)src; + if (d < s){ + u8 *e = d + size; + for (; d < e; d += 1, s += 1){ + *d = *s; + } + } + else if (d > s){ + u8 *e = d; + d += size - 1; + s += size - 1; + for (; d >= e; d -= 1, s -= 1){ + *d = *s; + } + } +} +static b32 +block_match(void *a, void *b, umem size){ + b32 result = true; + for (u8 *pa = (u8*)a, *pb = (u8*)b, *ea = pa + size; pa < ea; pa += 1, pb += 1){ + if (*pa != *pb){ + result = false; + break; + } + } + return(result); +} +static i32 +block_compare(void *a, void *b, umem size){ + i32 result = 0; + for (u8 *pa = (u8*)a, *pb = (u8*)b, *ea = pa + size; pa < ea; pa += 1, pb += 1){ + i32 dif = (i32)*pa - (i32)*pb; + if (dif != 0){ + result = (dif > 0)?1:-1; + break; + } + } + return(result); +} +static void +block_fill_u8(void *a, umem size, u8 val){ + for (u8 *ptr = (u8*)a, *e = ptr + size; ptr < e; ptr += 1){ + *ptr = val; + } +} +static void +block_fill_u16(void *a, umem size, u16 val){ + Assert(size%sizeof(u16) == 0); + umem count = size/sizeof(u16); + for (u16 *ptr = (u16*)a, *e = ptr + count; ptr < e; ptr += 1){ + *ptr = val; + } +} +static void +block_fill_u32(void *a, umem size, u32 val){ + Assert(size%sizeof(u32) == 0); + umem count = size/sizeof(u32); + for (u32 *ptr = (u32*)a, *e = ptr + count; ptr < e; ptr += 1){ + *ptr = val; + } +} +static void +block_fill_u64(void *a, umem size, u64 val){ + Assert(size%sizeof(u64) == 0); + umem count = size/sizeof(u64); + for (u64 *ptr = (u64*)a, *e = ptr + count; ptr < e; ptr += 1){ + *ptr = val; + } +} + +#define block_zero_struct(p) block_zero((p), sizeof(*(p))) +#define block_zero_array(a) block_zero((a), sizeof(a)) + +#define block_copy_struct(d,s) block_copy((d), (s), sizeof(*(d))) +#define block_copy_array(d,s) block_copy((d), (s), sizeof(d)) +#define block_copy_dynamic_array(d,s,c) block_copy((d), (s), sizeof(*(d))*(c)) + +#define block_match_struct(a,b) block_match((a), (b), sizeof(*(a))) +#define block_match_array(a,b) block_match((a), (b), sizeof(a)) + +//////////////////////////////// static f32 -ABS(f32 x){ - if (x < 0) x = -x; +abs_f32(f32 x){ + if (x < 0){ + x = -x; + } return(x); } @@ -70,603 +279,1134 @@ ABS(f32 x){ #include static f32 -MOD(f32 x, i32 m){ +mod_f32(f32 x, i32 m){ f32 whole; f32 frac = modff(x, &whole); f32 r = ((i32)(whole) % m) + frac; return(r); } - -static f32 -SQRT(f32 x){ - f32 r = sqrtf(x); - return(r); -} - -static f32 -SIN(f32 x_degrees){ - f32 r = sinf(x_degrees * DEG_TO_RAD); - return(r); -} - -static f32 -COS(f32 x_degrees){ - f32 r = cosf(x_degrees * DEG_TO_RAD); - return(r); -} #endif //////////////////////////////// -// vectors - -static Vec2 -V2(f32 x, f32 y){ - Vec2 result = {}; - result.x = x; - result.y = y; - return(result); +static Vec2_i8 +V2i8(i8 x, i8 y){ + Vec2_i8 v = {x, y}; + return(v); } - -static Vec3 -V3(f32 x, f32 y, f32 z){ - Vec3 result = {}; - result.x = x; - result.y = y; - result.z = z; - return(result); +static Vec3_i8 +V3i8(i8 x, i8 y, i8 z){ + Vec3_i8 v = {x, y, z}; + return(v); } - -static Vec4 -V4(f32 x, f32 y, f32 z, f32 w){ - Vec4 result = {}; - result.x = x; - result.y = y; - result.z = z; - result.w = w; - return(result); +static Vec4_i8 +V4i8(i8 x, i8 y, i8 z, i8 w){ + Vec4_i8 v = {x, y, z, w}; + return(v); } - -static Vec2 -V2(Vec2_i32 pi){ - return(V2((f32)pi.x, (f32)pi.y)); +static Vec2_i16 +V2i16(i16 x, i16 y){ + Vec2_i16 v = {x, y}; + return(v); } - -static Vec3 -V3(Vec3_i32 pi){ - return(V3((f32)pi.x, (f32)pi.y, (f32)pi.z)); +static Vec3_i16 +V3i16(i16 x, i16 y, i16 z){ + Vec3_i16 v = {x, y, z}; + return(v); } - -static Vec4 -V4(Vec4_i32 pi){ - return(V4((f32)pi.x, (f32)pi.y, (f32)pi.z, (f32)pi.w)); +static Vec4_i16 +V4i16(i16 x, i16 y, i16 z, i16 w){ + Vec4_i16 v = {x, y, z, w}; + return(v); } - -static Vec2 -V2(Vec2 pi){ - return(pi); -} - -static Vec3 -V3(Vec3 pi){ - return(pi); -} - -static Vec4 -V4(Vec4 pi){ - return(pi); -} - static Vec2_i32 V2i32(i32 x, i32 y){ - Vec2_i32 result = {}; - result.x = x; - result.y = y; - return(result); + Vec2_i32 v = {x, y}; + return(v); } - static Vec3_i32 V3i32(i32 x, i32 y, i32 z){ - Vec3_i32 result = {}; - result.x = x; - result.y = y; - result.z = z; - return(result); + Vec3_i32 v = {x, y, z}; + return(v); } - static Vec4_i32 V4i32(i32 x, i32 y, i32 z, i32 w){ - Vec4_i32 result = {}; - result.x = x; - result.y = y; - result.z = z; - result.w = w; - return(result); + Vec4_i32 v = {x, y, z, w}; + return(v); +} +static Vec2_f32 +V2f32(f32 x, f32 y){ + Vec2_f32 v = {x, y}; + return(v); +} +static Vec3_f32 +V3f32(f32 x, f32 y, f32 z){ + Vec3_f32 v = {x, y, z}; + return(v); +} +static Vec4_f32 +V4f32(f32 x, f32 y, f32 z, f32 w){ + Vec4_f32 v = {x, y, z, w}; + return(v); } +static Vec2_i8 +V2i8(Vec2_i8 o){ + return(V2i8((i8)o.x, (i8)o.y)); +} +static Vec2_i8 +V2i8(Vec2_i16 o){ + return(V2i8((i8)o.x, (i8)o.y)); +} +static Vec2_i8 +V2i8(Vec2_i32 o){ + return(V2i8((i8)o.x, (i8)o.y)); +} +static Vec2_i8 +V2i8(Vec2_f32 o){ + return(V2i8((i8)o.x, (i8)o.y)); +} +static Vec3_i8 +V3i8(Vec3_i8 o){ + return(V3i8((i8)o.x, (i8)o.y, (i8)o.z)); +} +static Vec3_i8 +V3i8(Vec3_i16 o){ + return(V3i8((i8)o.x, (i8)o.y, (i8)o.z)); +} +static Vec3_i8 +V3i8(Vec3_i32 o){ + return(V3i8((i8)o.x, (i8)o.y, (i8)o.z)); +} +static Vec3_i8 +V3i8(Vec3_f32 o){ + return(V3i8((i8)o.x, (i8)o.y, (i8)o.z)); +} +static Vec4_i8 +V4i8(Vec4_i8 o){ + return(V4i8((i8)o.x, (i8)o.y, (i8)o.z, (i8)o.w)); +} +static Vec4_i8 +V4i8(Vec4_i16 o){ + return(V4i8((i8)o.x, (i8)o.y, (i8)o.z, (i8)o.w)); +} +static Vec4_i8 +V4i8(Vec4_i32 o){ + return(V4i8((i8)o.x, (i8)o.y, (i8)o.z, (i8)o.w)); +} +static Vec4_i8 +V4i8(Vec4_f32 o){ + return(V4i8((i8)o.x, (i8)o.y, (i8)o.z, (i8)o.w)); +} +static Vec2_i16 +V2i16(Vec2_i8 o){ + return(V2i16((i16)o.x, (i16)o.y)); +} +static Vec2_i16 +V2i16(Vec2_i16 o){ + return(V2i16((i16)o.x, (i16)o.y)); +} +static Vec2_i16 +V2i16(Vec2_i32 o){ + return(V2i16((i16)o.x, (i16)o.y)); +} +static Vec2_i16 +V2i16(Vec2_f32 o){ + return(V2i16((i16)o.x, (i16)o.y)); +} +static Vec3_i16 +V3i16(Vec3_i8 o){ + return(V3i16((i16)o.x, (i16)o.y, (i16)o.z)); +} +static Vec3_i16 +V3i16(Vec3_i16 o){ + return(V3i16((i16)o.x, (i16)o.y, (i16)o.z)); +} +static Vec3_i16 +V3i16(Vec3_i32 o){ + return(V3i16((i16)o.x, (i16)o.y, (i16)o.z)); +} +static Vec3_i16 +V3i16(Vec3_f32 o){ + return(V3i16((i16)o.x, (i16)o.y, (i16)o.z)); +} +static Vec4_i16 +V4i16(Vec4_i8 o){ + return(V4i16((i16)o.x, (i16)o.y, (i16)o.z, (i16)o.w)); +} +static Vec4_i16 +V4i16(Vec4_i16 o){ + return(V4i16((i16)o.x, (i16)o.y, (i16)o.z, (i16)o.w)); +} +static Vec4_i16 +V4i16(Vec4_i32 o){ + return(V4i16((i16)o.x, (i16)o.y, (i16)o.z, (i16)o.w)); +} +static Vec4_i16 +V4i16(Vec4_f32 o){ + return(V4i16((i16)o.x, (i16)o.y, (i16)o.z, (i16)o.w)); +} static Vec2_i32 -V2i32(Vec2_f32 pi){ - return(V2i32((i32)pi.x, (i32)pi.y)); +V2i32(Vec2_i8 o){ + return(V2i32((i32)o.x, (i32)o.y)); } - -static Vec3_i32 -V3i32(Vec3_f32 pi){ - return(V3i32((i32)pi.x, (i32)pi.y, (i32)pi.z)); -} - -static Vec4_i32 -V4i32(Vec4_f32 pi){ - return(V4i32((i32)pi.x, (i32)pi.y, (i32)pi.z, (i32)pi.w)); -} - static Vec2_i32 -V2i32(Vec2_i32 pi){ - return(pi); +V2i32(Vec2_i16 o){ + return(V2i32((i32)o.x, (i32)o.y)); +} +static Vec2_i32 +V2i32(Vec2_i32 o){ + return(V2i32((i32)o.x, (i32)o.y)); +} +static Vec2_i32 +V2i32(Vec2_f32 o){ + return(V2i32((i32)o.x, (i32)o.y)); } - static Vec3_i32 -V3i32(Vec3_i32 pi){ - return(pi); +V3i32(Vec3_i8 o){ + return(V3i32((i32)o.x, (i32)o.y, (i32)o.z)); +} +static Vec3_i32 +V3i32(Vec3_i16 o){ + return(V3i32((i32)o.x, (i32)o.y, (i32)o.z)); +} +static Vec3_i32 +V3i32(Vec3_i32 o){ + return(V3i32((i32)o.x, (i32)o.y, (i32)o.z)); +} +static Vec3_i32 +V3i32(Vec3_f32 o){ + return(V3i32((i32)o.x, (i32)o.y, (i32)o.z)); } - static Vec4_i32 -V4i32(Vec4_i32 pi){ - return(pi); +V4i32(Vec4_i8 o){ + return(V4i32((i32)o.x, (i32)o.y, (i32)o.z, (i32)o.w)); +} +static Vec4_i32 +V4i32(Vec4_i16 o){ + return(V4i32((i32)o.x, (i32)o.y, (i32)o.z, (i32)o.w)); +} +static Vec4_i32 +V4i32(Vec4_i32 o){ + return(V4i32((i32)o.x, (i32)o.y, (i32)o.z, (i32)o.w)); +} +static Vec4_i32 +V4i32(Vec4_f32 o){ + return(V4i32((i32)o.x, (i32)o.y, (i32)o.z, (i32)o.w)); +} +static Vec2_f32 +V2f32(Vec2_i8 o){ + return(V2f32((f32)o.x, (f32)o.y)); +} +static Vec2_f32 +V2f32(Vec2_i16 o){ + return(V2f32((f32)o.x, (f32)o.y)); +} +static Vec2_f32 +V2f32(Vec2_i32 o){ + return(V2f32((f32)o.x, (f32)o.y)); +} +static Vec2_f32 +V2f32(Vec2_f32 o){ + return(V2f32((f32)o.x, (f32)o.y)); +} +static Vec3_f32 +V3f32(Vec3_i8 o){ + return(V3f32((f32)o.x, (f32)o.y, (f32)o.z)); +} +static Vec3_f32 +V3f32(Vec3_i16 o){ + return(V3f32((f32)o.x, (f32)o.y, (f32)o.z)); +} +static Vec3_f32 +V3f32(Vec3_i32 o){ + return(V3f32((f32)o.x, (f32)o.y, (f32)o.z)); +} +static Vec3_f32 +V3f32(Vec3_f32 o){ + return(V3f32((f32)o.x, (f32)o.y, (f32)o.z)); +} +static Vec4_f32 +V4f32(Vec4_i8 o){ + return(V4f32((f32)o.x, (f32)o.y, (f32)o.z, (f32)o.w)); +} +static Vec4_f32 +V4f32(Vec4_i16 o){ + return(V4f32((f32)o.x, (f32)o.y, (f32)o.z, (f32)o.w)); +} +static Vec4_f32 +V4f32(Vec4_i32 o){ + return(V4f32((f32)o.x, (f32)o.y, (f32)o.z, (f32)o.w)); +} +static Vec4_f32 +V4f32(Vec4_f32 o){ + return(V4f32((f32)o.x, (f32)o.y, (f32)o.z, (f32)o.w)); } -static Vec2 -operator+(Vec2 a, Vec2 b){ - Vec2 result; - result.x = a.x + b.x; - result.y = a.y + b.y; - return(result); -} +#define V2 V2f32 +#define V3 V3f32 +#define V4 V4f32 -static Vec3 -operator+(Vec3 a, Vec3 b){ - Vec3 result; - result.x = a.x + b.x; - result.y = a.y + b.y; - result.z = a.z + b.z; - return(result); -} - -static Vec4 -operator+(Vec4 a, Vec4 b){ - Vec4 result; - result.x = a.x + b.x; - result.y = a.y + b.y; - result.z = a.z + b.z; - result.w = a.w + b.w; - return(result); -} - -static Vec2 -operator-(Vec2 a, Vec2 b){ - Vec2 result; - result.x = a.x - b.x; - result.y = a.y - b.y; - return(result); -} - -static Vec3 -operator-(Vec3 a, Vec3 b){ - Vec3 result; - result.x = a.x - b.x; - result.y = a.y - b.y; - result.z = a.z - b.z; - return(result); -} - -static Vec4 -operator-(Vec4 a, Vec4 b){ - Vec4 result; - result.x = a.x - b.x; - result.y = a.y - b.y; - result.z = a.z - b.z; - result.w = a.w - b.w; - return(result); -} - -static Vec2 -operator*(Vec2 a, f32 k){ - Vec2 result; - result.x = a.x * k; - result.y = a.y * k; - return(result); -} - -static Vec3 -operator*(Vec3 a, f32 k){ - Vec3 result; - result.x = a.x * k; - result.y = a.y * k; - result.z = a.z * k; - return(result); -} - -static Vec4 -operator*(Vec4 a, f32 k){ - Vec4 result; - result.x = a.x * k; - result.y = a.y * k; - result.z = a.z * k; - result.w = a.w * k; - return(result); -} - -static Vec2 -operator*(f32 k, Vec2 a){ - Vec2 result; - result.x = a.x * k; - result.y = a.y * k; - return(result); -} - -static Vec3 -operator*(f32 k, Vec3 a){ - Vec3 result; - result.x = a.x * k; - result.y = a.y * k; - result.z = a.z * k; - return(result); -} - -static Vec4 -operator*(f32 k, Vec4 a){ - Vec4 result; - result.x = a.x * k; - result.y = a.y * k; - result.z = a.z * k; - result.w = a.w * k; - return(result); -} - -static Vec2& -operator+=(Vec2 &a, Vec2 b){ - a = (a + b); +static Vec2_i8 +operator+(Vec2_i8 a, Vec2_i8 b){ + a.x += b.x; + a.y += b.y; return(a); } - -static Vec3& -operator+=(Vec3 &a, Vec3 b){ - a = (a + b); +static Vec3_i8 +operator+(Vec3_i8 a, Vec3_i8 b){ + a.x += b.x; + a.y += b.y; + a.z += b.z; return(a); } - -static Vec4& -operator+=(Vec4 &a, Vec4 b){ - a = (a + b); +static Vec4_i8 +operator+(Vec4_i8 a, Vec4_i8 b){ + a.x += b.x; + a.y += b.y; + a.z += b.z; + a.w += b.w; return(a); } - -static Vec2& -operator-=(Vec2 &a, Vec2 b){ - a = (a - b); +static Vec2_i16 +operator+(Vec2_i16 a, Vec2_i16 b){ + a.x += b.x; + a.y += b.y; return(a); } - -static Vec3& -operator-=(Vec3 &a, Vec3 b){ - a = (a - b); +static Vec3_i16 +operator+(Vec3_i16 a, Vec3_i16 b){ + a.x += b.x; + a.y += b.y; + a.z += b.z; return(a); } - -static Vec4& -operator-=(Vec4 &a, Vec4 b){ - a = (a - b); +static Vec4_i16 +operator+(Vec4_i16 a, Vec4_i16 b){ + a.x += b.x; + a.y += b.y; + a.z += b.z; + a.w += b.w; return(a); } - -static Vec2& -operator*=(Vec2 &a, f32 k){ - a = (a*k); - return(a); -} - -static Vec3& -operator*=(Vec3 &a, f32 k){ - a = (a*k); - return(a); -} - -static Vec4& -operator*=(Vec4 &a, f32 k){ - a = (a*k); - return(a); -} - -static b32 -operator==(Vec2 a, Vec2 b){ - return(a.x == b.x && a.y == b.y); -} - -static b32 -operator!=(Vec2 a, Vec2 b){ - return(!(a.x == b.x && a.y == b.y)); -} - -static b32 -operator==(Vec3 a, Vec3 b){ - return(a.x == b.x && a.y == b.y && a.z == b.z); -} - -static b32 -operator!=(Vec3 a, Vec3 b){ - return(!(a.x == b.x && a.y == b.y && a.z == b.z)); -} - -static b32 -operator==(Vec4 a, Vec4 b){ - return(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w); -} - -static b32 -operator!=(Vec4 a, Vec4 b){ - return(!(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w)); -} - static Vec2_i32 operator+(Vec2_i32 a, Vec2_i32 b){ - Vec2_i32 result; - result.x = a.x + b.x; - result.y = a.y + b.y; - return(result); + a.x += b.x; + a.y += b.y; + return(a); } - static Vec3_i32 operator+(Vec3_i32 a, Vec3_i32 b){ - Vec3_i32 result; - result.x = a.x + b.x; - result.y = a.y + b.y; - result.z = a.z + b.z; - return(result); + a.x += b.x; + a.y += b.y; + a.z += b.z; + return(a); } - static Vec4_i32 operator+(Vec4_i32 a, Vec4_i32 b){ - Vec4_i32 result; - result.x = a.x + b.x; - result.y = a.y + b.y; - result.z = a.z + b.z; - result.w = a.w + b.w; - return(result); + a.x += b.x; + a.y += b.y; + a.z += b.z; + a.w += b.w; + return(a); +} +static Vec2_f32 +operator+(Vec2_f32 a, Vec2_f32 b){ + a.x += b.x; + a.y += b.y; + return(a); +} +static Vec3_f32 +operator+(Vec3_f32 a, Vec3_f32 b){ + a.x += b.x; + a.y += b.y; + a.z += b.z; + return(a); +} +static Vec4_f32 +operator+(Vec4_f32 a, Vec4_f32 b){ + a.x += b.x; + a.y += b.y; + a.z += b.z; + a.w += b.w; + return(a); } -static Vec2_i32 -operator-(Vec2_i32 a, Vec2_i32 b){ - Vec2_i32 result; - result.x = a.x - b.x; - result.y = a.y - b.y; - return(result); +static Vec2_i8& +operator+=(Vec2_i8 &a, Vec2_i8 b){ + a.x += b.x; + a.y += b.y; + return(a); } - -static Vec3_i32 -operator-(Vec3_i32 a, Vec3_i32 b){ - Vec3_i32 result; - result.x = a.x - b.x; - result.y = a.y - b.y; - result.z = a.z - b.z; - return(result); +static Vec3_i8& +operator+=(Vec3_i8 &a, Vec3_i8 b){ + a.x += b.x; + a.y += b.y; + a.z += b.z; + return(a); } - -static Vec4_i32 -operator-(Vec4_i32 a, Vec4_i32 b){ - Vec4_i32 result; - result.x = a.x - b.x; - result.y = a.y - b.y; - result.z = a.z - b.z; - result.w = a.w - b.w; - return(result); +static Vec4_i8& +operator+=(Vec4_i8 &a, Vec4_i8 b){ + a.x += b.x; + a.y += b.y; + a.z += b.z; + a.w += b.w; + return(a); } - -static Vec2_i32 -operator*(Vec2_i32 a, i32 k){ - Vec2_i32 result; - result.x = a.x * k; - result.y = a.y * k; - return(result); +static Vec2_i16& +operator+=(Vec2_i16 &a, Vec2_i16 b){ + a.x += b.x; + a.y += b.y; + return(a); } - -static Vec3_i32 -operator*(Vec3_i32 a, i32 k){ - Vec3_i32 result; - result.x = a.x * k; - result.y = a.y * k; - result.z = a.z * k; - return(result); +static Vec3_i16& +operator+=(Vec3_i16 &a, Vec3_i16 b){ + a.x += b.x; + a.y += b.y; + a.z += b.z; + return(a); } - -static Vec4_i32 -operator*(Vec4_i32 a, i32 k){ - Vec4_i32 result; - result.x = a.x * k; - result.y = a.y * k; - result.z = a.z * k; - result.w = a.w * k; - return(result); +static Vec4_i16& +operator+=(Vec4_i16 &a, Vec4_i16 b){ + a.x += b.x; + a.y += b.y; + a.z += b.z; + a.w += b.w; + return(a); } - -static Vec2_i32 -operator*(i32 k, Vec2_i32 a){ - Vec2_i32 result; - result.x = a.x * k; - result.y = a.y * k; - return(result); -} - -static Vec3_i32 -operator*(i32 k, Vec3_i32 a){ - Vec3_i32 result; - result.x = a.x * k; - result.y = a.y * k; - result.z = a.z * k; - return(result); -} - -static Vec4_i32 -operator*(i32 k, Vec4_i32 a){ - Vec4_i32 result; - result.x = a.x * k; - result.y = a.y * k; - result.z = a.z * k; - result.w = a.w * k; - return(result);} - static Vec2_i32& operator+=(Vec2_i32 &a, Vec2_i32 b){ - a = (a + b); + a.x += b.x; + a.y += b.y; return(a); } - static Vec3_i32& operator+=(Vec3_i32 &a, Vec3_i32 b){ - a = (a + b); + a.x += b.x; + a.y += b.y; + a.z += b.z; return(a); } - static Vec4_i32& operator+=(Vec4_i32 &a, Vec4_i32 b){ - a = (a + b); + a.x += b.x; + a.y += b.y; + a.z += b.z; + a.w += b.w; + return(a); +} +static Vec2_f32& +operator+=(Vec2_f32 &a, Vec2_f32 b){ + a.x += b.x; + a.y += b.y; + return(a); +} +static Vec3_f32& +operator+=(Vec3_f32 &a, Vec3_f32 b){ + a.x += b.x; + a.y += b.y; + a.z += b.z; + return(a); +} +static Vec4_f32& +operator+=(Vec4_f32 &a, Vec4_f32 b){ + a.x += b.x; + a.y += b.y; + a.z += b.z; + a.w += b.w; return(a); } +static Vec2_i8 +operator-(Vec2_i8 a, Vec2_i8 b){ + a.x -= b.x; + a.y -= b.y; + return(a); +} +static Vec3_i8 +operator-(Vec3_i8 a, Vec3_i8 b){ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + return(a); +} +static Vec4_i8 +operator-(Vec4_i8 a, Vec4_i8 b){ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + a.w -= b.w; + return(a); +} +static Vec2_i16 +operator-(Vec2_i16 a, Vec2_i16 b){ + a.x -= b.x; + a.y -= b.y; + return(a); +} +static Vec3_i16 +operator-(Vec3_i16 a, Vec3_i16 b){ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + return(a); +} +static Vec4_i16 +operator-(Vec4_i16 a, Vec4_i16 b){ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + a.w -= b.w; + return(a); +} +static Vec2_i32 +operator-(Vec2_i32 a, Vec2_i32 b){ + a.x -= b.x; + a.y -= b.y; + return(a); +} +static Vec3_i32 +operator-(Vec3_i32 a, Vec3_i32 b){ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + return(a); +} +static Vec4_i32 +operator-(Vec4_i32 a, Vec4_i32 b){ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + a.w -= b.w; + return(a); +} +static Vec2_f32 +operator-(Vec2_f32 a, Vec2_f32 b){ + a.x -= b.x; + a.y -= b.y; + return(a); +} +static Vec3_f32 +operator-(Vec3_f32 a, Vec3_f32 b){ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + return(a); +} +static Vec4_f32 +operator-(Vec4_f32 a, Vec4_f32 b){ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + a.w -= b.w; + return(a); +} + +static Vec2_i8& +operator-=(Vec2_i8 &a, Vec2_i8 b){ + a.x -= b.x; + a.y -= b.y; + return(a); +} +static Vec3_i8& +operator-=(Vec3_i8 &a, Vec3_i8 b){ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + return(a); +} +static Vec4_i8& +operator-=(Vec4_i8 &a, Vec4_i8 b){ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + a.w -= b.w; + return(a); +} +static Vec2_i16& +operator-=(Vec2_i16 &a, Vec2_i16 b){ + a.x -= b.x; + a.y -= b.y; + return(a); +} +static Vec3_i16& +operator-=(Vec3_i16 &a, Vec3_i16 b){ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + return(a); +} +static Vec4_i16& +operator-=(Vec4_i16 &a, Vec4_i16 b){ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + a.w -= b.w; + return(a); +} static Vec2_i32& operator-=(Vec2_i32 &a, Vec2_i32 b){ - a = (a - b); + a.x -= b.x; + a.y -= b.y; return(a); } - static Vec3_i32& operator-=(Vec3_i32 &a, Vec3_i32 b){ - a = (a - b); + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; return(a); } - static Vec4_i32& operator-=(Vec4_i32 &a, Vec4_i32 b){ - a = (a - b); + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + a.w -= b.w; + return(a); +} +static Vec2_f32& +operator-=(Vec2_f32 &a, Vec2_f32 b){ + a.x -= b.x; + a.y -= b.y; + return(a); +} +static Vec3_f32& +operator-=(Vec3_f32 &a, Vec3_f32 b){ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + return(a); +} +static Vec4_f32& +operator-=(Vec4_f32 &a, Vec4_f32 b){ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + a.w -= b.w; return(a); } +static Vec2_i8 +operator*(i8 s, Vec2_i8 v){ + v.x *= s; + v.y *= s; + return(v); +} +static Vec2_i8 +operator*(Vec2_i8 v, i8 s){ + v.x *= s; + v.y *= s; + return(v); +} +static Vec3_i8 +operator*(i8 s, Vec3_i8 v){ + v.x *= s; + v.y *= s; + v.z *= s; + return(v); +} +static Vec3_i8 +operator*(Vec3_i8 v, i8 s){ + v.x *= s; + v.y *= s; + v.z *= s; + return(v); +} +static Vec4_i8 +operator*(i8 s, Vec4_i8 v){ + v.x *= s; + v.y *= s; + v.z *= s; + v.w *= s; + return(v); +} +static Vec4_i8 +operator*(Vec4_i8 v, i8 s){ + v.x *= s; + v.y *= s; + v.z *= s; + v.w *= s; + return(v); +} +static Vec2_i16 +operator*(i16 s, Vec2_i16 v){ + v.x *= s; + v.y *= s; + return(v); +} +static Vec2_i16 +operator*(Vec2_i16 v, i16 s){ + v.x *= s; + v.y *= s; + return(v); +} +static Vec3_i16 +operator*(i16 s, Vec3_i16 v){ + v.x *= s; + v.y *= s; + v.z *= s; + return(v); +} +static Vec3_i16 +operator*(Vec3_i16 v, i16 s){ + v.x *= s; + v.y *= s; + v.z *= s; + return(v); +} +static Vec4_i16 +operator*(i16 s, Vec4_i16 v){ + v.x *= s; + v.y *= s; + v.z *= s; + v.w *= s; + return(v); +} +static Vec4_i16 +operator*(Vec4_i16 v, i16 s){ + v.x *= s; + v.y *= s; + v.z *= s; + v.w *= s; + return(v); +} +static Vec2_i32 +operator*(i32 s, Vec2_i32 v){ + v.x *= s; + v.y *= s; + return(v); +} +static Vec2_i32 +operator*(Vec2_i32 v, i32 s){ + v.x *= s; + v.y *= s; + return(v); +} +static Vec3_i32 +operator*(i32 s, Vec3_i32 v){ + v.x *= s; + v.y *= s; + v.z *= s; + return(v); +} +static Vec3_i32 +operator*(Vec3_i32 v, i32 s){ + v.x *= s; + v.y *= s; + v.z *= s; + return(v); +} +static Vec4_i32 +operator*(i32 s, Vec4_i32 v){ + v.x *= s; + v.y *= s; + v.z *= s; + v.w *= s; + return(v); +} +static Vec4_i32 +operator*(Vec4_i32 v, i32 s){ + v.x *= s; + v.y *= s; + v.z *= s; + v.w *= s; + return(v); +} +static Vec2_f32 +operator*(f32 s, Vec2_f32 v){ + v.x *= s; + v.y *= s; + return(v); +} +static Vec2_f32 +operator*(Vec2_f32 v, f32 s){ + v.x *= s; + v.y *= s; + return(v); +} +static Vec3_f32 +operator*(f32 s, Vec3_f32 v){ + v.x *= s; + v.y *= s; + v.z *= s; + return(v); +} +static Vec3_f32 +operator*(Vec3_f32 v, f32 s){ + v.x *= s; + v.y *= s; + v.z *= s; + return(v); +} +static Vec4_f32 +operator*(f32 s, Vec4_f32 v){ + v.x *= s; + v.y *= s; + v.z *= s; + v.w *= s; + return(v); +} +static Vec4_f32 +operator*(Vec4_f32 v, f32 s){ + v.x *= s; + v.y *= s; + v.z *= s; + v.w *= s; + return(v); +} + +static Vec2_i8& +operator*=(Vec2_i8 &v, i8 s){ + v.x *= s; + v.y *= s; + return(v); +} +static Vec3_i8& +operator*=(Vec3_i8 &v, i8 s){ + v.x *= s; + v.y *= s; + v.z *= s; + return(v); +} +static Vec4_i8& +operator*=(Vec4_i8 &v, i8 s){ + v.x *= s; + v.y *= s; + v.z *= s; + v.w *= s; + return(v); +} +static Vec2_i16& +operator*=(Vec2_i16 &v, i16 s){ + v.x *= s; + v.y *= s; + return(v); +} +static Vec3_i16& +operator*=(Vec3_i16 &v, i16 s){ + v.x *= s; + v.y *= s; + v.z *= s; + return(v); +} +static Vec4_i16& +operator*=(Vec4_i16 &v, i16 s){ + v.x *= s; + v.y *= s; + v.z *= s; + v.w *= s; + return(v); +} static Vec2_i32& -operator*=(Vec2_i32 &a, i32 k){ - a = (a*k); - return(a); +operator*=(Vec2_i32 &v, i32 s){ + v.x *= s; + v.y *= s; + return(v); } - static Vec3_i32& -operator*=(Vec3_i32 &a, i32 k){ - a = (a*k); - return(a); +operator*=(Vec3_i32 &v, i32 s){ + v.x *= s; + v.y *= s; + v.z *= s; + return(v); } - static Vec4_i32& -operator*=(Vec4_i32 &a, i32 k){ - a = (a*k); - return(a); +operator*=(Vec4_i32 &v, i32 s){ + v.x *= s; + v.y *= s; + v.z *= s; + v.w *= s; + return(v); +} +static Vec2_f32& +operator*=(Vec2_f32 &v, f32 s){ + v.x *= s; + v.y *= s; + return(v); +} +static Vec3_f32& +operator*=(Vec3_f32 &v, f32 s){ + v.x *= s; + v.y *= s; + v.z *= s; + return(v); +} +static Vec4_f32& +operator*=(Vec4_f32 &v, f32 s){ + v.x *= s; + v.y *= s; + v.z *= s; + v.w *= s; + return(v); } +static Vec2_i8 +operator/(Vec2_i8 v, i8 s){ + v.x /= s; + v.y /= s; + return(v); +} +static Vec3_i8 +operator/(Vec3_i8 v, i8 s){ + v.x /= s; + v.y /= s; + v.z /= s; + return(v); +} +static Vec4_i8 +operator/(Vec4_i8 v, i8 s){ + v.x /= s; + v.y /= s; + v.z /= s; + v.w /= s; + return(v); +} +static Vec2_i16 +operator/(Vec2_i16 v, i16 s){ + v.x /= s; + v.y /= s; + return(v); +} +static Vec3_i16 +operator/(Vec3_i16 v, i16 s){ + v.x /= s; + v.y /= s; + v.z /= s; + return(v); +} +static Vec4_i16 +operator/(Vec4_i16 v, i16 s){ + v.x /= s; + v.y /= s; + v.z /= s; + v.w /= s; + return(v); +} +static Vec2_i32 +operator/(Vec2_i32 v, i32 s){ + v.x /= s; + v.y /= s; + return(v); +} +static Vec3_i32 +operator/(Vec3_i32 v, i32 s){ + v.x /= s; + v.y /= s; + v.z /= s; + return(v); +} +static Vec4_i32 +operator/(Vec4_i32 v, i32 s){ + v.x /= s; + v.y /= s; + v.z /= s; + v.w /= s; + return(v); +} +static Vec2_f32 +operator/(Vec2_f32 v, f32 s){ + v.x /= s; + v.y /= s; + return(v); +} +static Vec3_f32 +operator/(Vec3_f32 v, f32 s){ + v.x /= s; + v.y /= s; + v.z /= s; + return(v); +} +static Vec4_f32 +operator/(Vec4_f32 v, f32 s){ + v.x /= s; + v.y /= s; + v.z /= s; + v.w /= s; + return(v); +} + +static Vec2_i8& +operator/=(Vec2_i8 &v, i8 s){ + v.x /= s; + v.y /= s; + return(v); +} +static Vec3_i8& +operator/=(Vec3_i8 &v, i8 s){ + v.x /= s; + v.y /= s; + v.z /= s; + return(v); +} +static Vec4_i8& +operator/=(Vec4_i8 &v, i8 s){ + v.x /= s; + v.y /= s; + v.z /= s; + v.w /= s; + return(v); +} +static Vec2_i16& +operator/=(Vec2_i16 &v, i16 s){ + v.x /= s; + v.y /= s; + return(v); +} +static Vec3_i16& +operator/=(Vec3_i16 &v, i16 s){ + v.x /= s; + v.y /= s; + v.z /= s; + return(v); +} +static Vec4_i16& +operator/=(Vec4_i16 &v, i16 s){ + v.x /= s; + v.y /= s; + v.z /= s; + v.w /= s; + return(v); +} +static Vec2_i32& +operator/=(Vec2_i32 &v, i32 s){ + v.x /= s; + v.y /= s; + return(v); +} +static Vec3_i32& +operator/=(Vec3_i32 &v, i32 s){ + v.x /= s; + v.y /= s; + v.z /= s; + return(v); +} +static Vec4_i32& +operator/=(Vec4_i32 &v, i32 s){ + v.x /= s; + v.y /= s; + v.z /= s; + v.w /= s; + return(v); +} +static Vec2_f32& +operator/=(Vec2_f32 &v, f32 s){ + v.x /= s; + v.y /= s; + return(v); +} +static Vec3_f32& +operator/=(Vec3_f32 &v, f32 s){ + v.x /= s; + v.y /= s; + v.z /= s; + return(v); +} +static Vec4_f32& +operator/=(Vec4_f32 &v, f32 s){ + v.x /= s; + v.y /= s; + v.z /= s; + v.w /= s; + return(v); +} + +static b32 +operator==(Vec2_i8 a, Vec2_i8 b){ + return(a.x == b.x && a.y == b.y); +} +static b32 +operator==(Vec3_i8 a, Vec3_i8 b){ + return(a.x == b.x && a.y == b.y && a.z == b.z); +} +static b32 +operator==(Vec4_i8 a, Vec4_i8 b){ + return(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w); +} +static b32 +operator==(Vec2_i16 a, Vec2_i16 b){ + return(a.x == b.x && a.y == b.y); +} +static b32 +operator==(Vec3_i16 a, Vec3_i16 b){ + return(a.x == b.x && a.y == b.y && a.z == b.z); +} +static b32 +operator==(Vec4_i16 a, Vec4_i16 b){ + return(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w); +} static b32 operator==(Vec2_i32 a, Vec2_i32 b){ return(a.x == b.x && a.y == b.y); } - -static b32 -operator!=(Vec2_i32 a, Vec2_i32 b){ - return(!(a.x == b.x && a.y == b.y)); -} - static b32 operator==(Vec3_i32 a, Vec3_i32 b){ return(a.x == b.x && a.y == b.y && a.z == b.z); } - -static b32 -operator!=(Vec3_i32 a, Vec3_i32 b){ - return(!(a.x == b.x && a.y == b.y && a.z == b.z)); -} - static b32 operator==(Vec4_i32 a, Vec4_i32 b){ return(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w); } +static b32 +operator==(Vec2_f32 a, Vec2_f32 b){ + return(a.x == b.x && a.y == b.y); +} +static b32 +operator==(Vec3_f32 a, Vec3_f32 b){ + return(a.x == b.x && a.y == b.y && a.z == b.z); +} +static b32 +operator==(Vec4_f32 a, Vec4_f32 b){ + return(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w); +} +static b32 +operator!=(Vec2_i8 a, Vec2_i8 b){ + return(a.x != b.x || a.y != b.y); +} +static b32 +operator!=(Vec3_i8 a, Vec3_i8 b){ + return(a.x != b.x || a.y != b.y || a.z != b.z); +} +static b32 +operator!=(Vec4_i8 a, Vec4_i8 b){ + return(a.x != b.x || a.y != b.y || a.z != b.z || a.w != b.w); +} +static b32 +operator!=(Vec2_i16 a, Vec2_i16 b){ + return(a.x != b.x || a.y != b.y); +} +static b32 +operator!=(Vec3_i16 a, Vec3_i16 b){ + return(a.x != b.x || a.y != b.y || a.z != b.z); +} +static b32 +operator!=(Vec4_i16 a, Vec4_i16 b){ + return(a.x != b.x || a.y != b.y || a.z != b.z || a.w != b.w); +} +static b32 +operator!=(Vec2_i32 a, Vec2_i32 b){ + return(a.x != b.x || a.y != b.y); +} +static b32 +operator!=(Vec3_i32 a, Vec3_i32 b){ + return(a.x != b.x || a.y != b.y || a.z != b.z); +} static b32 operator!=(Vec4_i32 a, Vec4_i32 b){ - return(!(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w)); + return(a.x != b.x || a.y != b.y || a.z != b.z || a.w != b.w); } - -static f32 -dot(Vec2 a, Vec2 b){ - f32 result; - result = a.x*b.x + a.y*b.y; - return(result); +static b32 +operator!=(Vec2_f32 a, Vec2_f32 b){ + return(a.x != b.x || a.y != b.y); } - -static f32 -dot(Vec3 a, Vec3 b){ - f32 result; - result = a.x*b.x + a.y*b.y + a.z*b.z; - return(result); +static b32 +operator!=(Vec3_f32 a, Vec3_f32 b){ + return(a.x != b.x || a.y != b.y || a.z != b.z); } - -static f32 -dot(Vec4 a, Vec4 b){ - f32 result; - result = a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w; - return(result); -} - -static Vec3 -cross(Vec3 a, Vec3 b){ - Vec3 result; - result.x = a.y*b.z - b.y*a.z; - result.y = a.z*b.x - b.z*a.x; - result.z = a.x*b.y - b.x*a.y; - return(result); -} - -static Vec2 -hadamard(Vec2 a, Vec2 b){ - a.x *= b.x; - a.y *= b.y; - return(a); -} - -static Vec3 -hadamard(Vec3 a, Vec3 b){ - a.x *= b.x; - a.y *= b.y; - a.z *= b.z; - return(a); -} - -static Vec4 -hadamard(Vec4 a, Vec4 b){ - a.x *= b.x; - a.y *= b.y; - a.z *= b.z; - a.w *= b.w; - return(a); -} - -static Vec2 -perp(Vec2 v){ - return(V2(-v.y, v.x)); -} - -static Vec2 -polar_to_cartesian(f32 theta_degrees, f32 length){ - return(V2(COS(theta_degrees), SIN(theta_degrees))*length); -} - -static Vec2 -rotate(Vec2 v, f32 theta_degrees){ - f32 c = COS(theta_degrees); - f32 s = SIN(theta_degrees); - return(V2(v.x*c - v.y*s, - v.x*s + v.y*c)); +static b32 +operator!=(Vec4_f32 a, Vec4_f32 b){ + return(a.x != b.x || a.y != b.y || a.z != b.z || a.w != b.w); } //////////////////////////////// @@ -700,15 +1440,13 @@ static 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); } //////////////////////////////// -// color - // TODO(allen): Convert colors to Vec4 static u32 color_blend(u32 a, f32 t, u32 b){ @@ -716,34 +1454,31 @@ color_blend(u32 a, f32 t, u32 b){ u8 byte[4]; u32 comp; } A, B, R; - A.comp = a; B.comp = b; - R.byte[0] = (u8)lerp(A.byte[0], t, B.byte[0]); R.byte[1] = (u8)lerp(A.byte[1], t, B.byte[1]); R.byte[2] = (u8)lerp(A.byte[2], t, B.byte[2]); R.byte[3] = (u8)lerp(A.byte[3], t, B.byte[3]); - return(R.comp); } static Vec3 unpack_color3(u32 color){ Vec3 result; - result.r = ((color >> 16) & 0xFF) / 255.f; - result.g = ((color >> 8) & 0xFF) / 255.f; - result.b = ((color >> 0) & 0xFF) / 255.f; + result.r = ((color >> 16) & 0xFF)/255.f; + result.g = ((color >> 8) & 0xFF)/255.f; + result.b = ((color >> 0) & 0xFF)/255.f; return(result); } static Vec4 unpack_color4(u32 color){ Vec4 result; - result.a = ((color >> 24) & 0xFF) / 255.f; - result.r = ((color >> 16) & 0xFF) / 255.f; - result.g = ((color >> 8) & 0xFF) / 255.f; - result.b = ((color >> 0) & 0xFF) / 255.f; + result.a = ((color >> 24) & 0xFF)/255.f; + result.r = ((color >> 16) & 0xFF)/255.f; + result.g = ((color >> 8) & 0xFF)/255.f; + result.b = ((color >> 0) & 0xFF)/255.f; return(result); } @@ -807,7 +1542,7 @@ rgba_to_hsla(Vec4 rgba){ }break; } hsla.x *= (1/6.f); //*60 / 360 - hsla.y = delta / (1.f - ABS(2.f*hsla.z - 1.f)); + hsla.y = delta / (1.f - abs_f32(2.f*hsla.z - 1.f)); } return(hsla); @@ -818,8 +1553,8 @@ hsla_to_rgba(Vec4 hsla){ if (hsla.h >= 1.f){ hsla.h = 0.f; } - f32 C = (1.f - ABS(2*hsla.z - 1.f))*hsla.y; - f32 X = C*(1.f-ABS(MOD(hsla.x*6.f, 2)-1.f)); + f32 C = (1.f - abs_f32(2*hsla.z - 1.f))*hsla.y; + f32 X = C*(1.f-abs_f32(mod_f32(hsla.x*6.f, 2)-1.f)); f32 m = hsla.z - C*.5f; i32 H = floor32(hsla.x*6.f); Vec4 rgba = {}; @@ -840,6 +1575,85 @@ hsla_to_rgba(Vec4 hsla){ //////////////////////////////// +static Interval_i8 +Ii8(i8 a, i8 b){ + Interval_i8 interval = {a, b}; + if (b < a){ + interval.min = b; + interval.max = a; + } + return(interval); +} +static Interval_i16 +Ii16(i16 a, i16 b){ + Interval_i16 interval = {a, b}; + if (b < a){ + interval.min = b; + interval.max = a; + } + return(interval); +} +static Interval_i32 +Ii32(i32 a, i32 b){ + Interval_i32 interval = {a, b}; + if (b < a){ + interval.min = b; + interval.max = a; + } + return(interval); +} +static Interval_f32 +If32(f32 a, f32 b){ + Interval_f32 interval = {a, b}; + if (b < a){ + interval.min = b; + interval.max = a; + } + return(interval); +} + +static Interval_i8 +range_margin(Interval_i8 range, i8 margin){ + range.min += margin; + range.max -= margin; + return(range); +} +static Interval_i16 +range_margin(Interval_i16 range, i16 margin){ + range.min += margin; + range.max -= margin; + return(range); +} +static Interval_i32 +range_margin(Interval_i32 range, i32 margin){ + range.min += margin; + range.max -= margin; + return(range); +} +static Interval_f32 +range_margin(Interval_f32 range, f32 margin){ + range.min += margin; + range.max -= margin; + return(range); +} + +static i8 +range_size(Interval_i8 range){ + return(range.max - range.min); +} +static i16 +range_size(Interval_i16 range){ + return(range.max - range.min); +} +static i32 +range_size(Interval_i32 range){ + return(range.max - range.min); +} +static f32 +range_size(Interval_f32 range){ + return(range.max - range.min); +} + static i32 get_width(Range range){ i32 result = range.end - range.start; @@ -849,9 +1663,61 @@ get_width(Range range){ return(result); } -static Range -make_range(i32 p1, i32 p2){ - Range range; +static Range_i8 +make_range_i8(i8 p1, i8 p2){ + Range_i8 range; + if (p1 < p2){ + range.min = p1; + range.max = p2; + } + else{ + range.min = p2; + range.max = p1; + } + return(range); +} +static Range_i16 +make_range_i16(i16 p1, i16 p2){ + Range_i16 range; + if (p1 < p2){ + range.min = p1; + range.max = p2; + } + else{ + range.min = p2; + range.max = p1; + } + return(range); +} +static Range_i32 +make_range_i32(i32 p1, i32 p2){ + Range_i32 range; + if (p1 < p2){ + range.min = p1; + range.max = p2; + } + else{ + range.min = p2; + range.max = p1; + } + return(range); +} +static Range_f32 +make_range_f32(f32 p1, f32 p2){ + Range_f32 range; + if (p1 < p2){ + range.min = p1; + range.max = p2; + } + else{ + range.min = p2; + range.max = p1; + } + return(range); +} +static Range_umem +make_range_umem(umem p1, umem p2){ + Range_umem range; if (p1 < p2){ range.min = p1; range.max = p2; @@ -863,11 +1729,33 @@ make_range(i32 p1, i32 p2){ return(range); } -static Range -make_range(i32 p){ - Range range = {p, p}; +static Range_i8 +make_range_i8(i8 p){ + Range_i8 range = {p, p}; return(range); } +static Range_i16 +make_range_i16(i16 p){ + Range_i16 range = {p, p}; + return(range); +} +static Range_i32 +make_range_i32(i32 p){ + Range_i32 range = {p, p}; + return(range); +} +static Range_f32 +make_range_f32(f32 p){ + Range_f32 range = {p, p}; + return(range); +} +static Range_umem +make_range_umem(umem p){ + Range_umem range = {p, p}; + return(range); +} + +#define make_range make_range_i32 static Range rectify(Range range) { @@ -1065,8 +1953,7 @@ rect_center(f32_Rect rect){ #define center_of rect_center static i32_Rect -intersection_of(i32_Rect a, i32_Rect b) -{ +intersection_of(i32_Rect a, i32_Rect b){ i32_Rect result; result.x0 = Max(a.x0, b.x0); result.y0 = Max(a.y0, b.y0); @@ -1076,8 +1963,7 @@ intersection_of(i32_Rect a, i32_Rect b) } static i32_Rect -union_of(i32_Rect a, i32_Rect b) -{ +union_of(i32_Rect a, i32_Rect b){ i32_Rect result; result.x0 = Max(a.x0, b.x0); result.y0 = Max(a.y0, b.y0); @@ -1087,8 +1973,7 @@ union_of(i32_Rect a, i32_Rect b) } static f32_Rect -intersection_of(f32_Rect a, f32_Rect b) -{ +intersection_of(f32_Rect a, f32_Rect b){ f32_Rect result; result.x0 = Max(a.x0, b.x0); result.y0 = Max(a.y0, b.y0); @@ -1098,8 +1983,7 @@ intersection_of(f32_Rect a, f32_Rect b) } static f32_Rect -union_of(f32_Rect a, f32_Rect b) -{ +union_of(f32_Rect a, f32_Rect b){ f32_Rect result; result.x0 = Max(a.x0, b.x0); result.y0 = Max(a.y0, b.y0); @@ -1108,5 +1992,3994 @@ union_of(f32_Rect a, f32_Rect b) return(result); } -// BOTTOM +//////////////////////////////// +#if defined(Migrating__Arena) + +static void* +base_reserve__noop(void *user_data, umem size, umem *size_out){ + *size_out = 0; + return(0); +} +static void +base_commit__noop(void *user_data, void *ptr, umem size){} +static void +base_uncommit__noop(void *user_data, void *ptr, umem size){} +static void +base_free__noop(void *user_data, void *ptr){} +static void +base_set_access__noop(void *user_data, void *ptr, umem size, Access_Flag flags){} + +static Base_Allocator +make_base_allocator(Base_Allocator_Reserve_Signature *func_reserve, + Base_Allocator_Commit_Signature *func_commit, + Base_Allocator_Uncommit_Signature *func_uncommit, + Base_Allocator_Free_Signature *func_free, + Base_Allocator_Set_Access_Signature *func_set_access, + void *user_data){ + if (func_reserve == 0){ + func_reserve = base_reserve__noop; + } + if (func_commit == 0){ + func_commit = base_commit__noop; + } + if (func_uncommit == 0){ + func_uncommit = base_uncommit__noop; + } + if (func_free == 0){ + func_free = base_free__noop; + } + if (func_set_access == 0){ + func_set_access = base_set_access__noop; + } + Base_Allocator base_allocator = { + func_reserve, + func_commit, + func_uncommit, + func_free, + func_set_access, + user_data, + }; + return(base_allocator); +} +static Data +base_allocate(Base_Allocator *allocator, umem size){ + umem full_size = 0; + void *memory = allocator->reserve(allocator->user_data, size, &full_size); + allocator->commit(allocator->user_data, memory, full_size); + return(make_data(memory, full_size)); +} +static void +base_free(Base_Allocator *allocator, void *ptr){ + allocator->free(allocator->user_data, ptr); +} + +//////////////////////////////// + +static Cursor +make_cursor(void *base, umem size){ + Cursor cursor = {(u8*)base, 0, size}; + return(cursor); +} +static Cursor +make_cursor(Data data){ + return(make_cursor(data.data, data.size)); +} +static Cursor +make_cursor(Base_Allocator *allocator, umem size){ + Data memory = base_allocate(allocator, size); + return(make_cursor(memory)); +} +static Data +linalloc_push(Cursor *cursor, umem size){ + Data result = {}; + if (cursor->pos + size <= cursor->cap){ + result.data = cursor->base + cursor->pos; + result.size = size; + cursor->pos += size; + } + return(result); +} +static void +linalloc_pop(Cursor *cursor, umem size){ + if (cursor->pos > size){ + cursor->pos -= size; + } + else{ + cursor->pos = 0; + } +} +static Data +linalloc_align(Cursor *cursor, umem alignment){ + umem pos = round_up_umem(cursor->pos, alignment); + umem new_size = pos - cursor->pos; + return(linalloc_push(cursor, new_size)); +} +static Temp_Memory_Cursor +linalloc_begin_temp(Cursor *cursor){ + Temp_Memory_Cursor temp = {cursor, cursor->pos}; + return(temp); +} +static void +linalloc_end_temp(Temp_Memory_Cursor temp){ + temp.cursor->pos = temp.pos; +} +static void +linalloc_clear(Cursor *cursor){ + cursor->pos = 0; +} +static Arena +make_arena(Base_Allocator *allocator, umem chunk_size, umem alignment){ + Arena arena = {allocator, 0, chunk_size, alignment}; + return(arena); +} +static Arena +make_arena(Base_Allocator *allocator, umem chunk_size){ + return(make_arena(allocator, chunk_size, 8)); +} +static Arena +make_arena(Base_Allocator *allocator){ + return(make_arena(allocator, KB(16), 8)); +} +static Cursor_Node* +arena__new_node(Arena *arena, umem min_size){ + min_size = clamp_bot(min_size, arena->chunk_size); + Data memory = base_allocate(arena->base_allocator, min_size + sizeof(Cursor_Node)); + Cursor_Node *cursor_node = (Cursor_Node*)memory.data; + cursor_node->cursor = make_cursor(cursor_node + 1, memory.size - sizeof(Cursor_Node)); + sll_stack_push(arena->cursor_node, cursor_node); + return(cursor_node); +} +static Data +linalloc_push(Arena *arena, umem size){ + Data result = {}; + if (size > 0){ + Cursor_Node *cursor_node = arena->cursor_node; + if (cursor_node == 0){ + cursor_node = arena__new_node(arena, size); + } + result = linalloc_push(&cursor_node->cursor, size); + if (result.data == 0){ + cursor_node = arena__new_node(arena, size); + result = linalloc_push(&cursor_node->cursor, size); + } + Data alignment_data = linalloc_align(&cursor_node->cursor, arena->alignment); + result.size += alignment_data.size; + } + return(result); +} +static void +linalloc_pop(Arena *arena, umem size){ + Base_Allocator *allocator = arena->base_allocator; + Cursor_Node *cursor_node = arena->cursor_node; + for (Cursor_Node *prev = 0; + cursor_node != 0 && size != 0; + cursor_node = prev){ + prev = cursor_node->prev; + if (size >= cursor_node->cursor.pos){ + size -= cursor_node->cursor.pos; + base_free(allocator, cursor_node); + } + else{ + linalloc_pop(&cursor_node->cursor, size); + break; + } + } + arena->cursor_node = cursor_node; +} +static Data +linalloc_align(Arena *arena, umem alignment){ + arena->alignment = alignment; + Data data = {}; + Cursor_Node *cursor_node = arena->cursor_node; + if (cursor_node != 0){ + data = linalloc_align(&cursor_node->cursor, arena->alignment); + } + return(data); +} +static Temp_Memory_Arena +linalloc_begin_temp(Arena *arena){ + Cursor_Node *cursor_node = arena->cursor_node; + Temp_Memory_Arena temp = {arena, cursor_node, + cursor_node == 0?0:cursor_node->cursor.pos}; + return(temp); +} +static void +linalloc_end_temp(Temp_Memory_Arena temp){ + Base_Allocator *allocator = temp.arena->base_allocator; + Cursor_Node *cursor_node = temp.arena->cursor_node; + for (Cursor_Node *prev = 0; + cursor_node != temp.cursor_node && cursor_node != 0; + cursor_node = prev){ + prev = cursor_node->prev; + base_free(allocator, cursor_node); + } + temp.arena->cursor_node = cursor_node; + if (cursor_node != 0){ + if (temp.pos > 0){ + cursor_node->cursor.pos = temp.pos; + } + else{ + temp.arena->cursor_node = cursor_node->prev; + base_free(allocator, cursor_node); + } + } +} +static void +linalloc_clear(Arena *arena){ + Temp_Memory_Arena temp = {arena, 0, 0}; + linalloc_end_temp(temp); +} +static void +arena_tap(Arena *arena){ + Cursor_Node *cursor_node = arena->cursor_node; + if (cursor_node == 0){ + arena__new_node(arena, 0); + } + else if (cursor_node->cursor.pos == cursor_node->cursor.cap){ + arena__new_node(arena, 0); + } +} +static Cursor* +arena_as_cursor(Arena *arena){ + Cursor *cursor = 0; + arena_tap(arena); + Cursor_Node *node = arena->cursor_node; + if (node != 0){ + cursor = &node->cursor; + } + return(cursor); +} +static void* +linalloc_wrap_unintialized(Data data){ + return(data.data); +} +static void* +linalloc_wrap_zero(Data data){ + block_zero(data.data, data.size); + return(data.data); +} +static void* +linalloc_wrap_write(Data data, umem size, void *src){ + block_copy(data.data, src, clamp_top(data.size, size)); + return(data.data); +} +#define push_array(a,T,c) ((T*)linalloc_wrap_unintialized(linalloc_push((a), sizeof(T)*(c)))) +#define push_array_zero(a,T,c) ((T*)linalloc_wrap_zero(linalloc_push((a), sizeof(T)*(c)))) +#define push_array_write(a,T,c,s) ((T*)linalloc_wrap_write(linalloc_push((a), sizeof(T)*(c)), sizeof(T)*(c), (s))) +#define pop_array(a,T,c) (linalloc_pop((a), sizeof(T)*(c))) +#define push_align(a,b) (linalloc_align((a), (b))) +#define push_align_zero(a,b) (linalloc_wrap_zero(linalloc_align((a), (b)))) +static Temp_Memory +begin_temp(Cursor *cursor){ + Temp_Memory temp = {LinearAllocatorKind_Cursor}; + temp.temp_memory_cursor = linalloc_begin_temp(cursor); + return(temp); +} +static Temp_Memory +begin_temp(Arena *arena){ + Temp_Memory temp = {LinearAllocatorKind_Arena}; + temp.temp_memory_arena = linalloc_begin_temp(arena); + return(temp); +} +static void +end_temp(Temp_Memory temp){ + switch (temp.kind){ + case LinearAllocatorKind_Cursor: + { + linalloc_end_temp(temp.temp_memory_cursor); + }break; + case LinearAllocatorKind_Arena: + { + linalloc_end_temp(temp.temp_memory_arena); + }break; + } +} + +//////////////////////////////// + +static Data +push_data(Arena *arena, umem size){ + Data result = {}; + result.data = push_array(arena, u8, size); + result.size = size; + return(result); +} + +static Data +push_data_copy(Arena *arena, Data data){ + Data result = {}; + result.data = push_array_write(arena, u8, data.size, data.data); + result.size = data.size; + return(result); +} + +static b32 +data_match(Data a, Data b){ + return(a.size == b.size && block_match(a.data, b.data, a.size)); +} + +//////////////////////////////// + +static b32 +character_is_slash(char c){ + return((c == '/') || (c == '\\')); +} +static b32 +character_is_slash(u8 c){ + return((c == '/') || (c == '\\')); +} +static b32 +character_is_slash(u16 c){ + return((c == '/') || (c == '\\')); +} +static b32 +character_is_slash(u32 c){ + return((c == '/') || (c == '\\')); +} + +static b32 +character_is_upper(char c){ + return(('A' <= c) && (c <= 'Z')); +} +static b32 +character_is_upper(u8 c){ + return(('A' <= c) && (c <= 'Z')); +} +static b32 +character_is_upper(u16 c){ + return(('A' <= c) && (c <= 'Z')); +} +static b32 +character_is_upper(u32 c){ + return(('A' <= c) && (c <= 'Z')); +} + +static b32 +character_is_lower(char c){ + return(('a' <= c) && (c <= 'z')); +} +static b32 +character_is_lower(u8 c){ + return(('a' <= c) && (c <= 'z')); +} +static b32 +character_is_lower(u16 c){ + return(('a' <= c) && (c <= 'z')); +} +static b32 +character_is_lower(u32 c){ + return(('a' <= c) && (c <= 'z')); +} + +static b32 +character_is_lower_unicode(u8 c){ + return((('a' <= c) && (c <= 'z')) || c >= 128); +} +static b32 +character_is_lower_unicode(u16 c){ + return((('a' <= c) && (c <= 'z')) || c >= 128); +} +static b32 +character_is_lower_unicode(u32 c){ + return((('a' <= c) && (c <= 'z')) || c >= 128); +} + +static char +character_to_upper(char c){ + if (('a' <= c) && (c <= 'z')){ + c -= 'a' - 'A'; + } + return(c); +} +static u8 +character_to_upper(u8 c){ + if (('a' <= c) && (c <= 'z')){ + c -= 'a' - 'A'; + } + return(c); +} +static u16 +character_to_upper(u16 c){ + if (('a' <= c) && (c <= 'z')){ + c -= 'a' - 'A'; + } + return(c); +} +static u32 +character_to_upper(u32 c){ + if (('a' <= c) && (c <= 'z')){ + c -= 'a' - 'A'; + } + return(c); +} +static char +character_to_lower(char c){ + if (('A' <= c) && (c <= 'Z')){ + c += 'a' - 'A'; + } + return(c); +} +static u8 +character_to_lower(u8 c){ + if (('A' <= c) && (c <= 'Z')){ + c += 'a' - 'A'; + } + return(c); +} +static u16 +character_to_lower(u16 c){ + if (('A' <= c) && (c <= 'Z')){ + c += 'a' - 'A'; + } + return(c); +} +static u32 +character_to_lower(u32 c){ + if (('A' <= c) && (c <= 'Z')){ + c += 'a' - 'A'; + } + return(c); +} + +static b32 +character_is_whitespace(char c){ + return(c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\f' || c == '\v'); +} +static b32 +character_is_whitespace(u8 c){ + return(c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\f' || c == '\v'); +} +static b32 +character_is_whitespace(u16 c){ + return(c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\f' || c == '\v'); +} +static b32 +character_is_whitespace(u32 c){ + return(c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\f' || c == '\v'); +} + +static b32 +character_is_base10(char c){ + return('0' <= c && c <= '9'); +} +static b32 +character_is_base10(u8 c){ + return('0' <= c && c <= '9'); +} +static b32 +character_is_base10(u16 c){ + return('0' <= c && c <= '9'); +} +static b32 +character_is_base10(u32 c){ + return('0' <= c && c <= '9'); +} + +static b32 +character_is_base16(char c){ + return(('0' <= c && c <= '9') || ('A' <= c && c <= 'F')); +} +static b32 +character_is_base16(u8 c){ + return(('0' <= c && c <= '9') || ('A' <= c && c <= 'F')); +} +static b32 +character_is_base16(u16 c){ + return(('0' <= c && c <= '9') || ('A' <= c && c <= 'F')); +} +static b32 +character_is_base16(u32 c){ + return(('0' <= c && c <= '9') || ('A' <= c && c <= 'F')); +} + +static b32 +character_is_base64(char c){ + return(('0' <= c && c <= '9') || + ('a' <= c && c <= 'z') || + ('A' <= c && c <= 'Z') || + c == '_' || c == '$' || c == '?'); +} +static b32 +character_is_base64(u8 c){ + return(('0' <= c && c <= '9') || + ('a' <= c && c <= 'z') || + ('A' <= c && c <= 'Z') || + c == '_' || c == '$' || c == '?'); +} +static b32 +character_is_base64(u16 c){ + return(('0' <= c && c <= '9') || + ('a' <= c && c <= 'z') || + ('A' <= c && c <= 'Z') || + c == '_' || c == '$' || c == '?'); +} +static b32 +character_is_base64(u32 c){ + return(('0' <= c && c <= '9') || + ('a' <= c && c <= 'z') || + ('A' <= c && c <= 'Z') || + c == '_' || c == '$' || c == '?'); +} + +static b32 +character_is_alpha(char c){ + return( (('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || c == '_'); +} +static b32 +character_is_alpha(u8 c){ + return( (('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || c == '_'); +} +static b32 +character_is_alpha(u16 c){ + return( (('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || c == '_'); +} +static b32 +character_is_alpha(u32 c){ + return( (('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || c == '_'); +} + +static b32 +character_is_alpha_numeric(char c){ + return((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || (('0' <= c) && (c <= '9')) || c == '_'); +} +static b32 +character_is_alpha_numeric(u8 c){ + return((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || (('0' <= c) && (c <= '9')) || c == '_'); +} +static b32 +character_is_alpha_numeric(u16 c){ + return((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || (('0' <= c) && (c <= '9')) || c == '_'); +} +static b32 +character_is_alpha_numeric(u32 c){ + return((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || (('0' <= c) && (c <= '9')) || c == '_'); +} + + +static b32 +character_is_alpha_unicode(u8 c){ + return( (('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || c == '_' || c >= 128); +} +static b32 +character_is_alpha_unicode(u16 c){ + return( (('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || c == '_' || c >= 128); +} +static b32 +character_is_alpha_unicode(u32 c){ + return( (('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || c == '_' || c >= 128); +} + +static b32 +character_is_alpha_numeric_unicode(u8 c){ + return((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || (('0' <= c) && (c <= '9')) || c == '_' || c >= 128); +} +static b32 +character_is_alpha_numeric_unicode(u16 c){ + return((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || (('0' <= c) && (c <= '9')) || c == '_' || c >= 128); +} +static b32 +character_is_alpha_numeric_unicode(u32 c){ + return((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) || (('0' <= c) && (c <= '9')) || c == '_' || c >= 128); +} + +static umem +cstring_length(char *str){ + umem length = 0; + for (;str[length] != 0; length += 1); + return(length); +} +static umem +cstring_length(u8 *str){ + umem length = 0; + for (;str[length] != 0; length += 1); + return(length); +} +static umem +cstring_length(u16 *str){ + umem length = 0; + for (;str[length] != 0; length += 1); + return(length); +} +static umem +cstring_length(u32 *str){ + umem length = 0; + for (;str[length] != 0; length += 1); + return(length); +} + +static String_char +Schar(char *str, umem size, umem cap){ + String_char string = {str, size, cap}; + return(string); +} +static String_u8 +Su8(u8 *str, umem size, umem cap){ + String_u8 string = {str, size, cap}; + return(string); +} +static String_u16 +Su16(u16 *str, umem size, umem cap){ + String_u16 string = {str, size, cap}; + return(string); +} +static String_u32 +Su32(u32 *str, umem size, umem cap){ + String_u32 string = {str, size, cap}; + return(string); +} + +static String_Any +Sany(void *str, umem size, umem cap, String_Encoding encoding){ + String_Any string = {encoding}; + switch (encoding){ + case StringEncoding_ASCII: string.s_char = Schar((char*)str, size, cap); break; + case StringEncoding_UTF8: string.s_u8 = Su8((u8*)str, size, cap); break; + case StringEncoding_UTF16: string.s_u16 = Su16((u16*)str, size, cap); break; + case StringEncoding_UTF32: string.s_u32 = Su32((u32*)str, size, cap); break; + } + return(string); +} + +static String_char +Schar(char *str, umem size){ + String_char string = {str, size, size + 1}; + return(string); +} +static String_u8 +Su8(u8 *str, umem size){ + String_u8 string = {str, size, size + 1}; + return(string); +} +static String_u16 +Su16(u16 *str, umem size){ + String_u16 string = {str, size, size + 1}; + return(string); +} +static String_u32 +Su32(u32 *str, umem size){ + String_u32 string = {str, size, size + 1}; + return(string); +} + +static String_Any +Sany(void *str, umem size, String_Encoding encoding){ + String_Any string = {encoding}; + switch (encoding){ + case StringEncoding_ASCII: string.s_char = Schar((char*)str, size); break; + case StringEncoding_UTF8: string.s_u8 = Su8((u8*)str, size); break; + case StringEncoding_UTF16: string.s_u16 = Su16((u16*)str, size); break; + case StringEncoding_UTF32: string.s_u32 = Su32((u32*)str, size); break; + } + return(string); +} + +static String_char +Schar(char *str, char *one_past_last){ + return(Schar(str, (umem)(one_past_last - str))); +} +static String_u8 +Su8(u8 *str, u8 *one_past_last){ + return(Su8(str, (umem)(one_past_last - str))); +} +static String_u16 +Su16(u16 *str, u16 *one_past_last){ + return(Su16(str, (umem)(one_past_last - str))); +} +static String_u32 +Su32(u32 *str, u32 *one_past_last){ + return(Su32(str, (umem)(one_past_last - str))); +} + +static String_Any +Sany(void *str, void *one_past_last, String_Encoding encoding){ + String_Any string = {encoding}; + switch (encoding){ + case StringEncoding_ASCII: string.s_char = Schar((char*)str, (char*)one_past_last); break; + case StringEncoding_UTF8: string.s_u8 = Su8((u8*)str, (u8*)one_past_last); break; + case StringEncoding_UTF16: string.s_u16 = Su16((u16*)str, (u16*)one_past_last); break; + case StringEncoding_UTF32: string.s_u32 = Su32((u32*)str, (u32*)one_past_last); break; + } + return(string); +} + +static String_char +Schar(char *str){ + umem size = cstring_length(str); + String_char string = {str, size, size + 1}; + return(string); +} +static String_u8 +Su8(u8 *str){ + umem size = cstring_length(str); + String_u8 string = {str, size, size + 1}; + return(string); +} +static String_u16 +Su16(u16 *str){ + umem size = cstring_length(str); + String_u16 string = {str, size, size + 1}; + return(string); +} +static String_u32 +Su32(u32 *str){ + umem size = cstring_length(str); + String_u32 string = {str, size, size + 1}; + return(string); +} + +static String_Any +Sany(void *str, String_Encoding encoding){ + String_Any string = {encoding}; + switch (encoding){ + case StringEncoding_ASCII: string.s_char = Schar((char*)str); break; + case StringEncoding_UTF8: string.s_u8 = Su8((u8*)str); break; + case StringEncoding_UTF16: string.s_u16 = Su16((u16*)str); break; + case StringEncoding_UTF32: string.s_u32 = Su32((u32*)str); break; + } + return(string); +} + +static String_char +Schar(String_Const_char str, umem cap){ + String_char string = {str.str, str.size, cap}; + return(string); +} +static String_u8 +Su8(String_Const_u8 str, umem cap){ + String_u8 string = {str.str, str.size, cap}; + return(string); +} +static String_u16 +Su16(String_Const_u16 str, umem cap){ + String_u16 string = {str.str, str.size, cap}; + return(string); +} +static String_u32 +Su32(String_Const_u32 str, umem cap){ + String_u32 string = {str.str, str.size, cap}; + return(string); +} + +static String_Any +SCany(String_char str){ + String_Any string = {StringEncoding_ASCII}; + string.s_char = str; + return(string); +} +static String_Any +SCany(String_u8 str){ + String_Any string = {StringEncoding_UTF8}; + string.s_u8 = str; + return(string); +} +static String_Any +SCany(String_u16 str){ + String_Any string = {StringEncoding_UTF16}; + string.s_u16 = str; + return(string); +} +static String_Any +SCany(String_u32 str){ + String_Any string = {StringEncoding_UTF32}; + string.s_u32 = str; + return(string); +} + +static String_Const_char +SCchar(char *str, umem size){ + String_Const_char string = {str, size}; + return(string); +} +static String_Const_u8 +SCu8(u8 *str, umem size){ + String_Const_u8 string = {str, size}; + return(string); +} +static String_Const_u16 +SCu16(u16 *str, umem size){ + String_Const_u16 string = {str, size}; + return(string); +} +static String_Const_u32 +SCu32(u32 *str, umem size){ + String_Const_u32 string = {str, size}; + return(string); +} + +static String_Const_Any +SCany(void *str, umem size, String_Encoding encoding){ + String_Const_Any string = {encoding}; + switch (encoding){ + case StringEncoding_ASCII: string.s_char = SCchar((char*)str, size); break; + case StringEncoding_UTF8: string.s_u8 = SCu8((u8*)str, size); break; + case StringEncoding_UTF16: string.s_u16 = SCu16((u16*)str, size); break; + case StringEncoding_UTF32: string.s_u32 = SCu32((u32*)str, size); break; + } + return(string); +} + +static String_Const_char +SCchar(void){ + String_Const_char string = {}; + return(string); +} +static String_Const_u8 +SCu8(void){ + String_Const_u8 string = {}; + return(string); +} +static String_Const_u16 +SCu16(void){ + String_Const_u16 string = {}; + return(string); +} +static String_Const_u32 +SCu32(void){ + String_Const_u32 string = {}; + return(string); +} + +static String_Const_char +SCchar(char *str, char *one_past_last){ + return(SCchar(str, (umem)(one_past_last - str))); +} +static String_Const_u8 +SCu8(u8 *str, u8 *one_past_last){ + return(SCu8(str, (umem)(one_past_last - str))); +} +static String_Const_u16 +SCu16(u16 *str, u16 *one_past_last){ + return(SCu16(str, (umem)(one_past_last - str))); +} +static String_Const_u32 +SCu32(u32 *str, u32 *one_past_last){ + return(SCu32(str, (umem)(one_past_last - str))); +} + +static String_Const_Any +SCany(void *str, void *one_past_last, String_Encoding encoding){ + String_Const_Any string = {encoding}; + switch (encoding){ + case StringEncoding_ASCII: string.s_char = SCchar((char*)str, (char*)one_past_last); break; + case StringEncoding_UTF8: string.s_u8 = SCu8((u8*)str, (u8*)one_past_last); break; + case StringEncoding_UTF16: string.s_u16 = SCu16((u16*)str, (u16*)one_past_last); break; + case StringEncoding_UTF32: string.s_u32 = SCu32((u32*)str, (u32*)one_past_last); break; + } + return(string); +} + +static String_Const_char +SCchar(char *str){ + umem size = cstring_length(str); + String_Const_char string = {str, size}; + return(string); +} +static String_Const_u8 +SCu8(u8 *str){ + umem size = cstring_length(str); + String_Const_u8 string = {str, size}; + return(string); +} +static String_Const_u16 +SCu16(u16 *str){ + umem size = cstring_length(str); + String_Const_u16 string = {str, size}; + return(string); +} +static String_Const_u32 +SCu32(u32 *str){ + umem size = cstring_length(str); + String_Const_u32 string = {str, size}; + return(string); +} + +static String_Const_char +SCchar(String_Const_u8 str){ + return(SCchar((char*)str.str, str.size)); +} +static String_Const_u8 +SCu8(String_Const_char str){ + return(SCu8((u8*)str.str, str.size)); +} + +static String_Const_u8 +SCu8(char *str, umem length){ + return(SCu8((u8*)str, length)); +} +static String_Const_u8 +SCu8(char *first, char *one_past_last){ + return(SCu8((u8*)first, (u8*)one_past_last)); +} +static String_Const_u8 +SCu8(char *str){ + return(SCu8((u8*)str)); +} + +static String_Const_u8 +SCu8(Data data){ + return(SCu8((u8*)data.data, data.size)); +} + +static String_Const_u16 +SCu16(wchar_t *str, umem size){ + return(SCu16((u16*)str, size)); +} +static String_Const_u16 +SCu16(wchar_t *str){ + return(SCu16((u16*)str)); +} + +static String_Const_Any +SCany(void *str, String_Encoding encoding){ + String_Const_Any string = {encoding}; + switch (encoding){ + case StringEncoding_ASCII: string.s_char = SCchar((char*)str); break; + case StringEncoding_UTF8: string.s_u8 = SCu8((u8*)str); break; + case StringEncoding_UTF16: string.s_u16 = SCu16((u16*)str); break; + case StringEncoding_UTF32: string.s_u32 = SCu32((u32*)str); break; + } + return(string); +} + +static String_Const_Any +SCany(String_Const_char str){ + String_Const_Any string = {StringEncoding_ASCII}; + string.s_char = str; + return(string); +} +static String_Const_Any +SCany(String_Const_u8 str){ + String_Const_Any string = {StringEncoding_UTF8}; + string.s_u8 = str; + return(string); +} +static String_Const_Any +SCany(String_Const_u16 str){ + String_Const_Any string = {StringEncoding_UTF16}; + string.s_u16 = str; + return(string); +} +static String_Const_Any +SCany(String_Const_u32 str){ + String_Const_Any string = {StringEncoding_UTF32}; + string.s_u32 = str; + return(string); +} + +#define string_litexpr(s) SCchar((s), sizeof(s) - 1) +#define string_litinit(s) {(s), sizeof(s) - 1} +#define string_u8_litexpr(s) SCu8((u8*)(s), sizeof(s) - 1) +#define string_u8_litinit(s) {(u8*)(s), sizeof(s) - 1} + +#define string_expand(s) (i32)(s).size, (char*)(s).str + +static char +string_get_character(String_Const_char str, umem i){ + char r = 0; + if (i < str.size){ + r = str.str[i]; + } + return(r); +} +static u8 +string_get_character(String_Const_u8 str, umem i){ + u8 r = 0; + if (i < str.size){ + r = str.str[i]; + } + return(r); +} +static u16 +string_get_character(String_Const_u16 str, umem i){ + u16 r = 0; + if (i < str.size){ + r = str.str[i]; + } + return(r); +} +static u32 +string_get_character(String_Const_u32 str, umem i){ + u32 r = 0; + if (i < str.size){ + r = str.str[i]; + } + return(r); +} + +static String_Const_char +string_prefix(String_Const_char str, umem size){ + size = clamp_top(size, str.size); + str.size = size; + return(str); +} +static String_Const_u8 +string_prefix(String_Const_u8 str, umem size){ + size = clamp_top(size, str.size); + str.size = size; + return(str); +} +static String_Const_u16 +string_prefix(String_Const_u16 str, umem size){ + size = clamp_top(size, str.size); + str.size = size; + return(str); +} +static String_Const_u32 +string_prefix(String_Const_u32 str, umem size){ + size = clamp_top(size, str.size); + str.size = size; + return(str); +} + +static String_Const_Any +string_prefix(String_Const_Any str, umem size){ + switch (str.encoding){ + case StringEncoding_ASCII: str.s_char = string_prefix(str.s_char, size); break; + case StringEncoding_UTF8: str.s_u8 = string_prefix(str.s_u8 , size); break; + case StringEncoding_UTF16: str.s_u16 = string_prefix(str.s_u16 , size); break; + case StringEncoding_UTF32: str.s_u32 = string_prefix(str.s_u32 , size); break; + } + return(str); +} + +static String_Const_char +string_postfix(String_Const_char str, umem size){ + size = clamp_top(size, str.size); + str.str += (str.size - size); + str.size = size; + return(str); +} +static String_Const_u8 +string_postfix(String_Const_u8 str, umem size){ + size = clamp_top(size, str.size); + str.str += (str.size - size); + str.size = size; + return(str); +} +static String_Const_u16 +string_postfix(String_Const_u16 str, umem size){ + size = clamp_top(size, str.size); + str.str += (str.size - size); + str.size = size; + return(str); +} +static String_Const_u32 +string_postfix(String_Const_u32 str, umem size){ + size = clamp_top(size, str.size); + str.str += (str.size - size); + str.size = size; + return(str); +} + +static String_Const_Any +string_postfix(String_Const_Any str, umem size){ + switch (str.encoding){ + case StringEncoding_ASCII: str.s_char = string_postfix(str.s_char, size); break; + case StringEncoding_UTF8: str.s_u8 = string_postfix(str.s_u8 , size); break; + case StringEncoding_UTF16: str.s_u16 = string_postfix(str.s_u16 , size); break; + case StringEncoding_UTF32: str.s_u32 = string_postfix(str.s_u32 , size); break; + } + return(str); +} + +static String_Const_char +string_skip(String_Const_char str, umem n){ + n = clamp_top(n, str.size); + str.str += n;; + str.size -= n; + return(str); +} +static String_Const_u8 +string_skip(String_Const_u8 str, umem n){ + n = clamp_top(n, str.size); + str.str += n;; + str.size -= n; + return(str); +} +static String_Const_u16 +string_skip(String_Const_u16 str, umem n){ + n = clamp_top(n, str.size); + str.str += n;; + str.size -= n; + return(str); +} +static String_Const_u32 +string_skip(String_Const_u32 str, umem n){ + n = clamp_top(n, str.size); + str.str += n;; + str.size -= n; + return(str); +} + +static String_Const_Any +string_skip(String_Const_Any str, umem n){ + switch (str.encoding){ + case StringEncoding_ASCII: str.s_char = string_skip(str.s_char, n); break; + case StringEncoding_UTF8: str.s_u8 = string_skip(str.s_u8 , n); break; + case StringEncoding_UTF16: str.s_u16 = string_skip(str.s_u16 , n); break; + case StringEncoding_UTF32: str.s_u32 = string_skip(str.s_u32 , n); break; + } + return(str); +} + +static String_Const_char +string_chop(String_Const_char str, umem n){ + n = clamp_top(n, str.size); + str.size -= n; + return(str); +} +static String_Const_u8 +string_chop(String_Const_u8 str, umem n){ + n = clamp_top(n, str.size); + str.size -= n; + return(str); +} +static String_Const_u16 +string_chop(String_Const_u16 str, umem n){ + n = clamp_top(n, str.size); + str.size -= n; + return(str); +} +static String_Const_u32 +string_chop(String_Const_u32 str, umem n){ + n = clamp_top(n, str.size); + str.size -= n; + return(str); +} + +static String_Const_Any +string_chop(String_Const_Any str, umem n){ + switch (str.encoding){ + case StringEncoding_ASCII: str.s_char = string_chop(str.s_char, n); break; + case StringEncoding_UTF8: str.s_u8 = string_chop(str.s_u8 , n); break; + case StringEncoding_UTF16: str.s_u16 = string_chop(str.s_u16 , n); break; + case StringEncoding_UTF32: str.s_u32 = string_chop(str.s_u32 , n); break; + } + return(str); +} + +static umem +string_find_first(String_Const_char str, char c){ + umem i = 0; + for (;i < str.size && c != str.str[i]; i += 1); + return(i); +} +static umem +string_find_first(String_Const_u8 str, u8 c){ + umem i = 0; + for (;i < str.size && c != str.str[i]; i += 1); + return(i); +} +static umem +string_find_first(String_Const_u16 str, u16 c){ + umem i = 0; + for (;i < str.size && c != str.str[i]; i += 1); + return(i); +} +static umem +string_find_first(String_Const_u32 str, u32 c){ + umem i = 0; + for (;i < str.size && c != str.str[i]; i += 1); + return(i); +} + +static imem +string_find_last(String_Const_char str, char c){ + imem size = (imem)str.size; + imem i = size - 1; + for (;i >= 0 && c != str.str[i]; i -= 1); + return(i); +} +static imem +string_find_last(String_Const_u8 str, u8 c){ + imem size = (imem)str.size; + imem i = size - 1; + for (;i >= 0 && c != str.str[i]; i -= 1); + return(i); +} +static imem +string_find_last(String_Const_u16 str, u16 c){ + imem size = (imem)str.size; + imem i = size - 1; + for (;i >= 0 && c != str.str[i]; i -= 1); + return(i); +} +static imem +string_find_last(String_Const_u32 str, u32 c){ + imem size = (imem)str.size; + imem i = size - 1; + for (;i >= 0 && c != str.str[i]; i -= 1); + return(i); +} + +static umem +string_find_first_non_whitespace(String_Const_char str){ + umem i = 0; + for (;i < str.size && character_is_whitespace(str.str[i]); i += 1); + return(i); +} +static umem +string_find_first_non_whitespace(String_Const_u8 str){ + umem i = 0; + for (;i < str.size && character_is_whitespace(str.str[i]); i += 1); + return(i); +} +static umem +string_find_first_non_whitespace(String_Const_u16 str){ + umem i = 0; + for (;i < str.size && character_is_whitespace(str.str[i]); i += 1); + return(i); +} +static umem +string_find_first_non_whitespace(String_Const_u32 str){ + umem i = 0; + for (;i < str.size && character_is_whitespace(str.str[i]); i += 1); + return(i); +} +static imem +string_find_last_non_whitespace(String_Const_char str){ + imem size = (imem)str.size; + imem i = size - 1; + for (;i >= 0 && character_is_whitespace(str.str[i]); i -= 1); + return(i); +} +static imem +string_find_last_non_whitespace(String_Const_u8 str){ + imem size = (imem)str.size; + imem i = size - 1; + for (;i >= 0 && character_is_whitespace(str.str[i]); i -= 1); + return(i); +} +static imem +string_find_last_non_whitespace(String_Const_u16 str){ + imem size = (imem)str.size; + imem i = size - 1; + for (;i >= 0 && character_is_whitespace(str.str[i]); i -= 1); + return(i); +} +static imem +string_find_last_non_whitespace(String_Const_u32 str){ + imem size = (imem)str.size; + imem i = size - 1; + for (;i >= 0 && character_is_whitespace(str.str[i]); i -= 1); + return(i); +} + +static umem +string_find_first_slash(String_Const_char str){ + umem i = 0; + for (;i < str.size && !character_is_slash(str.str[i]); i += 1); + return(i); +} +static umem +string_find_first_slash(String_Const_u8 str){ + umem i = 0; + for (;i < str.size && !character_is_slash(str.str[i]); i += 1); + return(i); +} +static umem +string_find_first_slash(String_Const_u16 str){ + umem i = 0; + for (;i < str.size && !character_is_slash(str.str[i]); i += 1); + return(i); +} +static umem +string_find_first_slash(String_Const_u32 str){ + umem i = 0; + for (;i < str.size && !character_is_slash(str.str[i]); i += 1); + return(i); +} +static imem +string_find_last_slash(String_Const_char str){ + imem size = (imem)str.size; + imem i = size - 1; + for (;i >= 0 && !character_is_slash(str.str[i]); i -= 1); + return(i); +} +static imem +string_find_last_slash(String_Const_u8 str){ + imem size = (imem)str.size; + imem i = size - 1; + for (;i >= 0 && !character_is_slash(str.str[i]); i -= 1); + return(i); +} +static imem +string_find_last_slash(String_Const_u16 str){ + imem size = (imem)str.size; + imem i = size - 1; + for (;i >= 0 && !character_is_slash(str.str[i]); i -= 1); + return(i); +} +static imem +string_find_last_slash(String_Const_u32 str){ + imem size = (imem)str.size; + imem i = size - 1; + for (;i >= 0 && !character_is_slash(str.str[i]); i -= 1); + return(i); +} + +static String_Const_char +string_remove_last_folder(String_Const_char str){ + if (str.size > 0){ + str.size -= 1; + } + imem slash_pos = string_find_last_slash(str); + if (slash_pos < 0){ + str.size = 0; + } + else{ + str.size = slash_pos + 1; + } + return(str); +} +static String_Const_u8 +string_remove_last_folder(String_Const_u8 str){ + if (str.size > 0){ + str.size -= 1; + } + imem slash_pos = string_find_last_slash(str); + if (slash_pos < 0){ + str.size = 0; + } + else{ + str.size = slash_pos + 1; + } + return(str); +} +static String_Const_u16 +string_remove_last_folder(String_Const_u16 str){ + if (str.size > 0){ + str.size -= 1; + } + imem slash_pos = string_find_last_slash(str); + if (slash_pos < 0){ + str.size = 0; + } + else{ + str.size = slash_pos + 1; + } + return(str); +} +static String_Const_u32 +string_remove_last_folder(String_Const_u32 str){ + if (str.size > 0){ + str.size -= 1; + } + imem slash_pos = string_find_last_slash(str); + if (slash_pos < 0){ + str.size = 0; + } + else{ + str.size = slash_pos + 1; + } + return(str); +} + +static String_Const_char +string_front_of_path(String_Const_char str){ + imem slash_pos = string_find_last_slash(str); + if (slash_pos >= 0){ + str = string_skip(str, slash_pos + 1); + } + return(str); +} +static String_Const_u8 +string_front_of_path(String_Const_u8 str){ + imem slash_pos = string_find_last_slash(str); + if (slash_pos >= 0){ + str = string_skip(str, slash_pos + 1); + } + return(str); +} +static String_Const_u16 +string_front_of_path(String_Const_u16 str){ + imem slash_pos = string_find_last_slash(str); + if (slash_pos >= 0){ + str = string_skip(str, slash_pos + 1); + } + return(str); +} +static String_Const_u32 +string_front_of_path(String_Const_u32 str){ + imem slash_pos = string_find_last_slash(str); + if (slash_pos >= 0){ + str = string_skip(str, slash_pos + 1); + } + return(str); +} + +static String_Const_char +string_file_extension(String_Const_char string){ + return(string_skip(string, string_find_last(string, '.') + 1)); +} +static String_Const_u8 +string_file_extension(String_Const_u8 string){ + return(string_skip(string, string_find_last(string, '.') + 1)); +} +static String_Const_u16 +string_file_extension(String_Const_u16 string){ + return(string_skip(string, string_find_last(string, '.') + 1)); +} +static String_Const_u32 +string_file_extension(String_Const_u32 string){ + return(string_skip(string, string_find_last(string, '.') + 1)); +} + +static String_Const_char +string_file_without_extension(String_Const_char string){ + imem pos = string_find_last(string, '.'); + if (pos > 0){ + string = string_prefix(string, pos); + } + return(string); +} +static String_Const_u8 +string_file_without_extension(String_Const_u8 string){ + imem pos = string_find_last(string, '.'); + if (pos > 0){ + string = string_prefix(string, pos); + } + return(string); +} +static String_Const_u16 +string_file_without_extension(String_Const_u16 string){ + imem pos = string_find_last(string, '.'); + if (pos > 0){ + string = string_prefix(string, pos); + } + return(string); +} +static String_Const_u32 +string_file_without_extension(String_Const_u32 string){ + imem pos = string_find_last(string, '.'); + if (pos > 0){ + string = string_prefix(string, pos); + } + return(string); +} + +static String_Const_char +string_skip_whitespace(String_Const_char str){ + umem f = string_find_first_non_whitespace(str); + str = string_skip(str, f); + return(str); +} +static String_Const_u8 +string_skip_whitespace(String_Const_u8 str){ + umem f = string_find_first_non_whitespace(str); + str = string_skip(str, f); + return(str); +} +static String_Const_u16 +string_skip_whitespace(String_Const_u16 str){ + umem f = string_find_first_non_whitespace(str); + str = string_skip(str, f); + return(str); +} +static String_Const_u32 +string_skip_whitespace(String_Const_u32 str){ + umem f = string_find_first_non_whitespace(str); + str = string_skip(str, f); + return(str); +} + +static String_Const_char +string_chop_whitespace(String_Const_char str){ + imem e = string_find_last_non_whitespace(str); + str = string_prefix(str, (umem)(e + 1)); + return(str); +} +static String_Const_u8 +string_chop_whitespace(String_Const_u8 str){ + imem e = string_find_last_non_whitespace(str); + str = string_prefix(str, (umem)(e + 1)); + return(str); +} +static String_Const_u16 +string_chop_whitespace(String_Const_u16 str){ + imem e = string_find_last_non_whitespace(str); + str = string_prefix(str, (umem)(e + 1)); + return(str); +} +static String_Const_u32 +string_chop_whitespace(String_Const_u32 str){ + imem e = string_find_last_non_whitespace(str); + str = string_prefix(str, (umem)(e + 1)); + return(str); +} + +static String_Const_char +string_skip_chop_whitespace(String_Const_char str){ + umem f = string_find_first_non_whitespace(str); + str = string_skip(str, f); + imem e = string_find_last_non_whitespace(str); + str = string_prefix(str, (umem)(e + 1)); + return(str); +} +static String_Const_u8 +string_skip_chop_whitespace(String_Const_u8 str){ + umem f = string_find_first_non_whitespace(str); + str = string_skip(str, f); + imem e = string_find_last_non_whitespace(str); + str = string_prefix(str, (umem)(e + 1)); + return(str); +} +static String_Const_u16 +string_skip_chop_whitespace(String_Const_u16 str){ + umem f = string_find_first_non_whitespace(str); + str = string_skip(str, f); + imem e = string_find_last_non_whitespace(str); + str = string_prefix(str, (umem)(e + 1)); + return(str); +} +static String_Const_u32 +string_skip_chop_whitespace(String_Const_u32 str){ + umem f = string_find_first_non_whitespace(str); + str = string_skip(str, f); + imem e = string_find_last_non_whitespace(str); + str = string_prefix(str, (umem)(e + 1)); + return(str); +} + +static b32 +string_match(String_Const_char a, String_Const_char b){ + b32 result = false; + if (a.size == b.size){ + result = true; + for (umem i = 0; i < a.size; i += 1){ + if (a.str[i] != b.str[i]){ + result = false; + break; + } + } + } + return(result); +} +static b32 +string_match(String_Const_u8 a, String_Const_u8 b){ + b32 result = false; + if (a.size == b.size){ + result = true; + for (umem i = 0; i < a.size; i += 1){ + if (a.str[i] != b.str[i]){ + result = false; + break; + } + } + } + return(result); +} +static b32 +string_match(String_Const_u16 a, String_Const_u16 b){ + b32 result = false; + if (a.size == b.size){ + result = true; + for (umem i = 0; i < a.size; i += 1){ + if (a.str[i] != b.str[i]){ + result = false; + break; + } + } + } + return(result); +} +static b32 +string_match(String_Const_u32 a, String_Const_u32 b){ + b32 result = false; + if (a.size == b.size){ + result = true; + for (umem i = 0; i < a.size; i += 1){ + if (a.str[i] != b.str[i]){ + result = false; + break; + } + } + } + return(result); +} + +static b32 +string_match(String_Const_Any a, String_Const_Any b){ + b32 result = false; + if (a.encoding == b.encoding){ + switch (a.encoding){ + case StringEncoding_ASCII: result = string_match(a.s_char, b.s_char); break; + case StringEncoding_UTF8: result = string_match(a.s_u8 , b.s_u8 ); break; + case StringEncoding_UTF16: result = string_match(a.s_u16 , b.s_u16 ); break; + case StringEncoding_UTF32: result = string_match(a.s_u32 , b.s_u32 ); break; + } + } + return(result); +} + +static b32 +string_match_insensitive(String_Const_char a, String_Const_char b){ + b32 result = false; + if (a.size == b.size){ + result = true; + for (umem i = 0; i < a.size; i += 1){ + if (character_to_upper(a.str[i]) != character_to_upper(b.str[i])){ + result = false; + break; + } + } + } + return(result); +} +static b32 +string_match_insensitive(String_Const_u8 a, String_Const_u8 b){ + b32 result = false; + if (a.size == b.size){ + result = true; + for (umem i = 0; i < a.size; i += 1){ + if (character_to_upper(a.str[i]) != character_to_upper(b.str[i])){ + result = false; + break; + } + } + } + return(result); +} +static b32 +string_match_insensitive(String_Const_u16 a, String_Const_u16 b){ + b32 result = false; + if (a.size == b.size){ + result = true; + for (umem i = 0; i < a.size; i += 1){ + if (character_to_upper(a.str[i]) != character_to_upper(b.str[i])){ + result = false; + break; + } + } + } + return(result); +} +static b32 +string_match_insensitive(String_Const_u32 a, String_Const_u32 b){ + b32 result = false; + if (a.size == b.size){ + result = true; + for (umem i = 0; i < a.size; i += 1){ + if (character_to_upper(a.str[i]) != character_to_upper(b.str[i])){ + result = false; + break; + } + } + } + return(result); +} + +static b32 +string_match(String_Const_char a, String_Const_char b, String_Match_Rule rule){ + b32 result = false; + switch (rule){ + case StringMatch_Exact: + { + result = string_match(a, b); + }break; + case StringMatch_CaseInsensitive: + { + result = string_match_insensitive(a, b); + }break; + } + return(result); +} +static b32 +string_match(String_Const_u8 a, String_Const_u8 b, String_Match_Rule rule){ + b32 result = false; + switch (rule){ + case StringMatch_Exact: + { + result = string_match(a, b); + }break; + case StringMatch_CaseInsensitive: + { + result = string_match_insensitive(a, b); + }break; + } + return(result); +} +static b32 +string_match(String_Const_u16 a, String_Const_u16 b, String_Match_Rule rule){ + b32 result = false; + switch (rule){ + case StringMatch_Exact: + { + result = string_match(a, b); + }break; + case StringMatch_CaseInsensitive: + { + result = string_match_insensitive(a, b); + }break; + } + return(result); +} +static b32 +string_match(String_Const_u32 a, String_Const_u32 b, String_Match_Rule rule){ + b32 result = false; + switch (rule){ + case StringMatch_Exact: + { + result = string_match(a, b); + }break; + case StringMatch_CaseInsensitive: + { + result = string_match_insensitive(a, b); + }break; + } + return(result); +} + +static umem +string_find_first(String_Const_char str, String_Const_char needle, String_Match_Rule rule){ + umem i = 0; + if (needle.size > 0){ + i = str.size; + if (str.size >= needle.size){ + i = 0; + umem one_past_last = str.size - needle.size + 1; + for (;i < one_past_last; i += 1){ + if (str.str[i] == needle.str[0]){ + String_Const_char source_part = string_prefix(string_skip(str, i), needle.size); + if (string_match(source_part, needle, rule)){ + break; + } + } + } + if (i == one_past_last){ + i = str.size; + } + } + } + return(i); +} +static umem +string_find_first(String_Const_u8 str, String_Const_u8 needle, String_Match_Rule rule){ + umem i = 0; + if (needle.size > 0){ + i = str.size; + if (str.size >= needle.size){ + i = 0; + umem one_past_last = str.size - needle.size + 1; + for (;i < one_past_last; i += 1){ + if (str.str[i] == needle.str[0]){ + String_Const_u8 source_part = string_prefix(string_skip(str, i), needle.size); + if (string_match(source_part, needle, rule)){ + break; + } + } + } + if (i == one_past_last){ + i = str.size; + } + } + } + return(i); +} +static umem +string_find_first(String_Const_u16 str, String_Const_u16 needle, String_Match_Rule rule){ + umem i = 0; + if (needle.size > 0){ + i = str.size; + if (str.size >= needle.size){ + i = 0; + umem one_past_last = str.size - needle.size + 1; + for (;i < one_past_last; i += 1){ + if (str.str[i] == needle.str[0]){ + String_Const_u16 source_part = string_prefix(string_skip(str, i), needle.size); + if (string_match(source_part, needle, rule)){ + break; + } + } + } + if (i == one_past_last){ + i = str.size; + } + } + } + return(i); +} +static umem +string_find_first(String_Const_u32 str, String_Const_u32 needle, String_Match_Rule rule){ + umem i = 0; + if (needle.size > 0){ + i = str.size; + if (str.size >= needle.size){ + i = 0; + umem one_past_last = str.size - needle.size + 1; + for (;i < one_past_last; i += 1){ + if (str.str[i] == needle.str[0]){ + String_Const_u32 source_part = string_prefix(string_skip(str, i), needle.size); + if (string_match(source_part, needle, rule)){ + break; + } + } + } + if (i == one_past_last){ + i = str.size; + } + } + } + return(i); +} + +static umem +string_find_first(String_Const_char str, String_Const_char needle){ + return(string_find_first(str, needle, StringMatch_Exact)); +} +static umem +string_find_first(String_Const_u8 str, String_Const_u8 needle){ + return(string_find_first(str, needle, StringMatch_Exact)); +} +static umem +string_find_first(String_Const_u16 str, String_Const_u16 needle){ + return(string_find_first(str, needle, StringMatch_Exact)); +} +static umem +string_find_first(String_Const_u32 str, String_Const_u32 needle){ + return(string_find_first(str, needle, StringMatch_Exact)); +} +static umem +string_find_first_insensitive(String_Const_char str, String_Const_char needle){ + return(string_find_first(str, needle, StringMatch_CaseInsensitive)); +} +static umem +string_find_first_insensitive(String_Const_u8 str, String_Const_u8 needle){ + return(string_find_first(str, needle, StringMatch_CaseInsensitive)); +} +static umem +string_find_first_insensitive(String_Const_u16 str, String_Const_u16 needle){ + return(string_find_first(str, needle, StringMatch_CaseInsensitive)); +} +static umem +string_find_first_insensitive(String_Const_u32 str, String_Const_u32 needle){ + return(string_find_first(str, needle, StringMatch_CaseInsensitive)); +} + +static i32 +string_compare(String_Const_char a, String_Const_char b){ + i32 result = 0; + for (umem i = 0; i < a.size || i < b.size; i += 1){ + char ca = (i < a.size)?0:a.str[i]; + char cb = (i < b.size)?0:b.str[i]; + i32 dif = (ca) != (cb); + if (dif != 0){ + result = (dif > 0)?1:-1; + break; + } + } + return(result); +} +static i32 +string_compare(String_Const_u8 a, String_Const_u8 b){ + i32 result = 0; + for (umem i = 0; i < a.size || i < b.size; i += 1){ + u8 ca = (i < a.size)?0:a.str[i]; + u8 cb = (i < b.size)?0:b.str[i]; + i32 dif = (ca) != (cb); + if (dif != 0){ + result = (dif > 0)?1:-1; + break; + } + } + return(result); +} +static i32 +string_compare(String_Const_u16 a, String_Const_u16 b){ + i32 result = 0; + for (umem i = 0; i < a.size || i < b.size; i += 1){ + u16 ca = (i < a.size)?0:a.str[i]; + u16 cb = (i < b.size)?0:b.str[i]; + i32 dif = (ca) != (cb); + if (dif != 0){ + result = (dif > 0)?1:-1; + break; + } + } + return(result); +} +static i32 +string_compare(String_Const_u32 a, String_Const_u32 b){ + i32 result = 0; + for (umem i = 0; i < a.size || i < b.size; i += 1){ + u32 ca = (i < a.size)?0:a.str[i]; + u32 cb = (i < b.size)?0:b.str[i]; + i32 dif = (ca) != (cb); + if (dif != 0){ + result = (dif > 0)?1:-1; + break; + } + } + return(result); +} + +static i32 +string_compare_insensitive(String_Const_char a, String_Const_char b){ + i32 result = 0; + for (umem i = 0; i < a.size || i < b.size; i += 1){ + char ca = (i <= a.size)?0:a.str[i]; + char cb = (i <= b.size)?0:b.str[i]; + i32 dif = character_to_upper(ca) - character_to_upper(cb); + if (dif != 0){ + result = (dif > 0)?1:-1; + break; + } + } + return(result); +} +static i32 +string_compare_insensitive(String_Const_u8 a, String_Const_u8 b){ + i32 result = 0; + for (umem i = 0; i < a.size || i < b.size; i += 1){ + u8 ca = (i <= a.size)?0:a.str[i]; + u8 cb = (i <= b.size)?0:b.str[i]; + i32 dif = character_to_upper(ca) - character_to_upper(cb); + if (dif != 0){ + result = (dif > 0)?1:-1; + break; + } + } + return(result); +} +static i32 +string_compare_insensitive(String_Const_u16 a, String_Const_u16 b){ + i32 result = 0; + for (umem i = 0; i < a.size || i < b.size; i += 1){ + u16 ca = (i <= a.size)?0:a.str[i]; + u16 cb = (i <= b.size)?0:b.str[i]; + i32 dif = character_to_upper(ca) - character_to_upper(cb); + if (dif != 0){ + result = (dif > 0)?1:-1; + break; + } + } + return(result); +} +static i32 +string_compare_insensitive(String_Const_u32 a, String_Const_u32 b){ + i32 result = 0; + for (umem i = 0; i < a.size || i < b.size; i += 1){ + u32 ca = (i <= a.size)?0:a.str[i]; + u32 cb = (i <= b.size)?0:b.str[i]; + i32 dif = character_to_upper(ca) - character_to_upper(cb); + if (dif != 0){ + result = (dif > 0)?1:-1; + break; + } + } + return(result); +} + +static String_Const_char +string_mod_upper(String_Const_char str){ + for (umem i = 0; i < str.size; i += 1){ + str.str[i] = character_to_upper(str.str[i]); + } + return(str); +} +static String_Const_u8 +string_mod_upper(String_Const_u8 str){ + for (umem i = 0; i < str.size; i += 1){ + str.str[i] = character_to_upper(str.str[i]); + } + return(str); +} +static String_Const_u16 +string_mod_upper(String_Const_u16 str){ + for (umem i = 0; i < str.size; i += 1){ + str.str[i] = character_to_upper(str.str[i]); + } + return(str); +} +static String_Const_u32 +string_mod_upper(String_Const_u32 str){ + for (umem i = 0; i < str.size; i += 1){ + str.str[i] = character_to_upper(str.str[i]); + } + return(str); +} +static String_Const_char +string_mod_lower(String_Const_char str){ + for (umem i = 0; i < str.size; i += 1){ + str.str[i] = character_to_lower(str.str[i]); + } + return(str); +} +static String_Const_u8 +string_mod_lower(String_Const_u8 str){ + for (umem i = 0; i < str.size; i += 1){ + str.str[i] = character_to_lower(str.str[i]); + } + return(str); +} +static String_Const_u16 +string_mod_lower(String_Const_u16 str){ + for (umem i = 0; i < str.size; i += 1){ + str.str[i] = character_to_lower(str.str[i]); + } + return(str); +} +static String_Const_u32 +string_mod_lower(String_Const_u32 str){ + for (umem i = 0; i < str.size; i += 1){ + str.str[i] = character_to_lower(str.str[i]); + } + return(str); +} + +static String_Const_char +string_mod_replace_character(String_Const_char str, char o, char n){ + for (umem i = 0; i < str.size; i += 1){ + char c = str.str[i]; + str.str[i] = (c == o)?(n):(c); + } + return(str); +} +static String_Const_u8 +string_mod_replace_character(String_Const_u8 str, u8 o, u8 n){ + for (umem i = 0; i < str.size; i += 1){ + u8 c = str.str[i]; + str.str[i] = (c == o)?(n):(c); + } + return(str); +} +static String_Const_u16 +string_mod_replace_character(String_Const_u16 str, u16 o, u16 n){ + for (umem i = 0; i < str.size; i += 1){ + u16 c = str.str[i]; + str.str[i] = (c == o)?(n):(c); + } + return(str); +} +static String_Const_u32 +string_mod_replace_character(String_Const_u32 str, u32 o, u32 n){ + for (umem i = 0; i < str.size; i += 1){ + u32 c = str.str[i]; + str.str[i] = (c == o)?(n):(c); + } + return(str); +} + +static b32 +string_append(String_char *dst, String_Const_char src){ + b32 result = false; + umem available = dst->cap - dst->size; + if (src.size <= available){ + result = true; + } + umem copy_size = clamp_top(src.size, available); + block_copy(dst->str + dst->size, src.str, copy_size); + dst->size += copy_size; + return(result); +} +static b32 +string_append(String_u8 *dst, String_Const_u8 src){ + b32 result = false; + umem available = dst->cap - dst->size; + if (src.size <= available){ + result = true; + } + umem copy_size = clamp_top(src.size, available); + block_copy(dst->str + dst->size, src.str, copy_size); + dst->size += copy_size; + return(result); +} +static b32 +string_append(String_u16 *dst, String_Const_u16 src){ + b32 result = false; + umem available = dst->cap - dst->size; + if (src.size <= available){ + result = true; + } + umem copy_size = clamp_top(src.size, available); + block_copy(dst->str + dst->size, src.str, copy_size); + dst->size += copy_size; + return(result); +} +static b32 +string_append(String_u32 *dst, String_Const_u32 src){ + b32 result = false; + umem available = dst->cap - dst->size; + if (src.size <= available){ + result = true; + } + umem copy_size = clamp_top(src.size, available); + block_copy(dst->str + dst->size, src.str, copy_size); + dst->size += copy_size; + return(result); +} + +static b32 +string_append_character(String_char *dst, char c){ + return(string_append(dst, SCchar(&c, 1))); +} +static b32 +string_append_character(String_u8 *dst, u8 c){ + return(string_append(dst, SCu8(&c, 1))); +} +static b32 +string_append_character(String_u16 *dst, u16 c){ + return(string_append(dst, SCu16(&c, 1))); +} +static b32 +string_append_character(String_u32 *dst, u32 c){ + return(string_append(dst, SCu32(&c, 1))); +} + +static b32 +string_null_terminate(String_char *str){ + b32 result = false; + if (str->size < str->cap){ + str->str[str->size] = 0; + } + return(result); +} +static b32 +string_null_terminate(String_u8 *str){ + b32 result = false; + if (str->size < str->cap){ + str->str[str->size] = 0; + } + return(result); +} +static b32 +string_null_terminate(String_u16 *str){ + b32 result = false; + if (str->size < str->cap){ + str->str[str->size] = 0; + } + return(result); +} +static b32 +string_null_terminate(String_u32 *str){ + b32 result = false; + if (str->size < str->cap){ + str->str[str->size] = 0; + } + return(result); +} + +static String_char +string_char_push(Arena *arena, umem size){ + String_char string = {}; + string.str = push_array(arena, char, size); + string.cap = size; + return(string); +} +static String_u8 +string_u8_push(Arena *arena, umem size){ + String_u8 string = {}; + string.str = push_array(arena, u8, size); + string.cap = size; + return(string); +} +static String_u16 +string_u16_push(Arena *arena, umem size){ + String_u16 string = {}; + string.str = push_array(arena, u16, size); + string.cap = size; + return(string); +} +static String_u32 +string_u32_push(Arena *arena, umem size){ + String_u32 string = {}; + string.str = push_array(arena, u32, size); + string.cap = size; + return(string); +} + +static String_Any +string_any_push(Arena *arena, umem size, String_Encoding encoding){ + String_Any string = {}; + switch (encoding){ + case StringEncoding_ASCII: string.s_char = string_char_push(arena, size); break; + case StringEncoding_UTF8: string.s_u8 = string_u8_push (arena, size); break; + case StringEncoding_UTF16: string.s_u16 = string_u16_push (arena, size); break; + case StringEncoding_UTF32: string.s_u32 = string_u32_push (arena, size); break; + } + return(string); +} + +static String_Const_char +string_const_char_push(Arena *arena, umem size){ + String_Const_char string = {}; + string.str = push_array(arena, char, size); + string.size = size; + return(string); +} +static String_Const_u8 +string_const_u8_push(Arena *arena, umem size){ + String_Const_u8 string = {}; + string.str = push_array(arena, u8, size); + string.size = size; + return(string); +} +static String_Const_u16 +string_const_u16_push(Arena *arena, umem size){ + String_Const_u16 string = {}; + string.str = push_array(arena, u16, size); + string.size = size; + return(string); +} +static String_Const_u32 +string_const_u32_push(Arena *arena, umem size){ + String_Const_u32 string = {}; + string.str = push_array(arena, u32, size); + string.size = size; + return(string); +} + +static String_Const_Any +string_const_any_push(Arena *arena, umem size, String_Encoding encoding){ + String_Const_Any string = {}; + switch (encoding){ + case StringEncoding_ASCII: string.s_char = string_const_char_push(arena, size); break; + case StringEncoding_UTF8: string.s_u8 = string_const_u8_push (arena, size); break; + case StringEncoding_UTF16: string.s_u16 = string_const_u16_push (arena, size); break; + case StringEncoding_UTF32: string.s_u32 = string_const_u32_push (arena, size); break; + } + return(string); +} + +static String_Const_char +string_copy(Arena *arena, String_Const_char src){ + String_Const_char string = {}; + string.str = push_array(arena, char, src.size + 1); + string.size = src.size; + block_copy_dynamic_array(string.str, src.str, src.size); + string.str[string.size] = 0; + return(string); +} +static String_Const_u8 +string_copy(Arena *arena, String_Const_u8 src){ + String_Const_u8 string = {}; + string.str = push_array(arena, u8, src.size + 1); + string.size = src.size; + block_copy_dynamic_array(string.str, src.str, src.size); + string.str[string.size] = 0; + return(string); +} +static String_Const_u16 +string_copy(Arena *arena, String_Const_u16 src){ + String_Const_u16 string = {}; + string.str = push_array(arena, u16, src.size + 1); + string.size = src.size; + block_copy_dynamic_array(string.str, src.str, src.size); + string.str[string.size] = 0; + return(string); +} +static String_Const_u32 +string_copy(Arena *arena, String_Const_u32 src){ + String_Const_u32 string = {}; + string.str = push_array(arena, u32, src.size + 1); + string.size = src.size; + block_copy_dynamic_array(string.str, src.str, src.size); + string.str[string.size] = 0; + return(string); +} + +static String_Const_Any +string_copy(Arena *arena, umem size, String_Const_Any src){ + String_Const_Any string = {}; + switch (src.encoding){ + case StringEncoding_ASCII: string.s_char = string_copy(arena, src.s_char); break; + case StringEncoding_UTF8: string.s_u8 = string_copy(arena, src.s_u8 ); break; + case StringEncoding_UTF16: string.s_u16 = string_copy(arena, src.s_u16 ); break; + case StringEncoding_UTF32: string.s_u32 = string_copy(arena, src.s_u32 ); break; + } + return(string); +} + +static void +string_list_push(Arena *arena, List_String_Const_char *list, String_Const_char string){ + Node_String_Const_char *node = push_array(arena, Node_String_Const_char, 1); + sll_queue_push(list->first, list->last, node); + node->string = string; + list->node_count += 1; + list->total_size += string.size; +} +static void +string_list_push(Arena *arena, List_String_Const_u8 *list, String_Const_u8 string){ + Node_String_Const_u8 *node = push_array(arena, Node_String_Const_u8, 1); + sll_queue_push(list->first, list->last, node); + node->string = string; + list->node_count += 1; + list->total_size += string.size; +} +static void +string_list_push(Arena *arena, List_String_Const_u16 *list, String_Const_u16 string){ + Node_String_Const_u16 *node = push_array(arena, Node_String_Const_u16, 1); + sll_queue_push(list->first, list->last, node); + node->string = string; + list->node_count += 1; + list->total_size += string.size; +} +static void +string_list_push(Arena *arena, List_String_Const_u32 *list, String_Const_u32 string){ + Node_String_Const_u32 *node = push_array(arena, Node_String_Const_u32, 1); + sll_queue_push(list->first, list->last, node); + node->string = string; + list->node_count += 1; + list->total_size += string.size; +} + +static void +string_list_push(Arena *arena, List_String_Const_Any *list, String_Const_Any string){ + Node_String_Const_Any *node = push_array(arena, Node_String_Const_Any, 1); + sll_queue_push(list->first, list->last, node); + node->string = string; + list->node_count += 1; + list->total_size += string.size; +} + +#define string_list_push_lit(a,l,s) string_list_push((a), (l), string_litexpr(s)) +#define string_list_push_u8_lit(a,l,s) string_list_push((a), (l), string_u8_litexpr(s)) + +static void +string_list_push(List_String_Const_char *list, List_String_Const_char *src_list){ + sll_queue_push_multiple(list->first, list->last, src_list->first, src_list->last); + list->node_count += src_list->node_count; + list->total_size += src_list->total_size; + block_zero_array(src_list); +} +static void +string_list_push(List_String_Const_u8 *list, List_String_Const_u8 *src_list){ + sll_queue_push_multiple(list->first, list->last, src_list->first, src_list->last); + list->node_count += src_list->node_count; + list->total_size += src_list->total_size; + block_zero_array(src_list); +} +static void +string_list_push(List_String_Const_u16 *list, List_String_Const_u16 *src_list){ + sll_queue_push_multiple(list->first, list->last, src_list->first, src_list->last); + list->node_count += src_list->node_count; + list->total_size += src_list->total_size; + block_zero_array(src_list); +} +static void +string_list_push(List_String_Const_u32 *list, List_String_Const_u32 *src_list){ + sll_queue_push_multiple(list->first, list->last, src_list->first, src_list->last); + list->node_count += src_list->node_count; + list->total_size += src_list->total_size; + block_zero_array(src_list); +} + +static void +string_list_push(List_String_Const_Any *list, List_String_Const_Any *src_list){ + sll_queue_push_multiple(list->first, list->last, src_list->first, src_list->last); + list->node_count += src_list->node_count; + list->total_size += src_list->total_size; + block_zero_array(src_list); +} + +static void +string_list_push_overlap(Arena *arena, List_String_Const_char *list, char overlap, String_Const_char string){ + b32 tail_has_overlap = false; + b32 string_has_overlap = false; + if (list->last != 0){ + String_Const_char tail = list->last->string; + if (string_get_character(tail, tail.size - 1) == overlap){ + tail_has_overlap = true; + } + } + if (string_get_character(string, 0) == overlap){ + string_has_overlap = true; + } + if (tail_has_overlap == string_has_overlap){ + if (!tail_has_overlap){ + string_list_push(arena, list, string_copy(arena, SCchar(&overlap, 1))); + } + else{ + string = string_skip(string, 1); + } + } + if (string.size > 0){ + string_list_push(arena, list, string); + } +} +static void +string_list_push_overlap(Arena *arena, List_String_Const_u8 *list, u8 overlap, String_Const_u8 string){ + b32 tail_has_overlap = false; + b32 string_has_overlap = false; + if (list->last != 0){ + String_Const_u8 tail = list->last->string; + if (string_get_character(tail, tail.size - 1) == overlap){ + tail_has_overlap = true; + } + } + if (string_get_character(string, 0) == overlap){ + string_has_overlap = true; + } + if (tail_has_overlap == string_has_overlap){ + if (!tail_has_overlap){ + string_list_push(arena, list, string_copy(arena, SCu8(&overlap, 1))); + } + else{ + string = string_skip(string, 1); + } + } + if (string.size > 0){ + string_list_push(arena, list, string); + } +} +static void +string_list_push_overlap(Arena *arena, List_String_Const_u16 *list, u16 overlap, String_Const_u16 string){ + b32 tail_has_overlap = false; + b32 string_has_overlap = false; + if (list->last != 0){ + String_Const_u16 tail = list->last->string; + if (string_get_character(tail, tail.size - 1) == overlap){ + tail_has_overlap = true; + } + } + if (string_get_character(string, 0) == overlap){ + string_has_overlap = true; + } + if (tail_has_overlap == string_has_overlap){ + if (!tail_has_overlap){ + string_list_push(arena, list, string_copy(arena, SCu16(&overlap, 1))); + } + else{ + string = string_skip(string, 1); + } + } + if (string.size > 0){ + string_list_push(arena, list, string); + } +} +static void +string_list_push_overlap(Arena *arena, List_String_Const_u32 *list, u32 overlap, String_Const_u32 string){ + b32 tail_has_overlap = false; + b32 string_has_overlap = false; + if (list->last != 0){ + String_Const_u32 tail = list->last->string; + if (string_get_character(tail, tail.size - 1) == overlap){ + tail_has_overlap = true; + } + } + if (string_get_character(string, 0) == overlap){ + string_has_overlap = true; + } + if (tail_has_overlap == string_has_overlap){ + if (!tail_has_overlap){ + string_list_push(arena, list, string_copy(arena, SCu32(&overlap, 1))); + } + else{ + string = string_skip(string, 1); + } + } + if (string.size > 0){ + string_list_push(arena, list, string); + } +} + +typedef String_Const_char String_char_Mod_Function_Type(String_Const_char string); +typedef String_Const_u8 String_u8_Mod_Function_Type(String_Const_u8 string); +typedef String_Const_u16 String_u16_Mod_Function_Type(String_Const_u16 string); +typedef String_Const_u32 String_u32_Mod_Function_Type(String_Const_u32 string); + +static String_Const_char +string_list_flatten(Arena *arena, List_String_Const_char list, String_char_Mod_Function_Type *mod, String_Const_char separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ + umem term_padding = (rule == StringFill_NullTerminate)?(1):(0);b32 before_first = HasFlag(separator_flags, StringSeparator_BeforeFirst); + b32 after_last = HasFlag(separator_flags, StringSeparator_AfterLast); + umem separator_size = separator.size*(list.node_count + before_first + after_last - 1); + String_char string = string_char_push(arena, list.total_size + separator_size + term_padding); + if (before_first){ + string_append(&string, separator); + } + for (Node_String_Const_char *node = list.first; + node != 0; + node = node->next){ + block_copy_dynamic_array(string.str + string.size, node->string.str, node->string.size); + if (mod != 0){ + mod(SCchar(string.str + string.size, node->string.size)); + } + string.size += node->string.size; + string_append(&string, separator); + } + if (after_last){ + string_append(&string, separator); + } + if (term_padding == 1){ + string_null_terminate(&string); + } + return(string.string); +} +static String_Const_u8 +string_list_flatten(Arena *arena, List_String_Const_u8 list, String_u8_Mod_Function_Type *mod, String_Const_u8 separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ + umem term_padding = (rule == StringFill_NullTerminate)?(1):(0);b32 before_first = HasFlag(separator_flags, StringSeparator_BeforeFirst); + b32 after_last = HasFlag(separator_flags, StringSeparator_AfterLast); + umem separator_size = separator.size*(list.node_count + before_first + after_last - 1); + String_u8 string = string_u8_push(arena, list.total_size + separator_size + term_padding); + if (before_first){ + string_append(&string, separator); + } + for (Node_String_Const_u8 *node = list.first; + node != 0; + node = node->next){ + block_copy_dynamic_array(string.str + string.size, node->string.str, node->string.size); + if (mod != 0){ + mod(SCu8(string.str + string.size, node->string.size)); + } + string.size += node->string.size; + string_append(&string, separator); + } + if (after_last){ + string_append(&string, separator); + } + if (term_padding == 1){ + string_null_terminate(&string); + } + return(string.string); +} +static String_Const_u16 +string_list_flatten(Arena *arena, List_String_Const_u16 list, String_u16_Mod_Function_Type *mod, String_Const_u16 separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ + umem term_padding = (rule == StringFill_NullTerminate)?(1):(0);b32 before_first = HasFlag(separator_flags, StringSeparator_BeforeFirst); + b32 after_last = HasFlag(separator_flags, StringSeparator_AfterLast); + umem separator_size = separator.size*(list.node_count + before_first + after_last - 1); + String_u16 string = string_u16_push(arena, list.total_size + separator_size + term_padding); + if (before_first){ + string_append(&string, separator); + } + for (Node_String_Const_u16 *node = list.first; + node != 0; + node = node->next){ + block_copy_dynamic_array(string.str + string.size, node->string.str, node->string.size); + if (mod != 0){ + mod(SCu16(string.str + string.size, node->string.size)); + } + string.size += node->string.size; + string_append(&string, separator); + } + if (after_last){ + string_append(&string, separator); + } + if (term_padding == 1){ + string_null_terminate(&string); + } + return(string.string); +} +static String_Const_u32 +string_list_flatten(Arena *arena, List_String_Const_u32 list, String_u32_Mod_Function_Type *mod, String_Const_u32 separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ + umem term_padding = (rule == StringFill_NullTerminate)?(1):(0);b32 before_first = HasFlag(separator_flags, StringSeparator_BeforeFirst); + b32 after_last = HasFlag(separator_flags, StringSeparator_AfterLast); + umem separator_size = separator.size*(list.node_count + before_first + after_last - 1); + String_u32 string = string_u32_push(arena, list.total_size + separator_size + term_padding); + if (before_first){ + string_append(&string, separator); + } + for (Node_String_Const_u32 *node = list.first; + node != 0; + node = node->next){ + block_copy_dynamic_array(string.str + string.size, node->string.str, node->string.size); + if (mod != 0){ + mod(SCu32(string.str + string.size, node->string.size)); + } + string.size += node->string.size; + string_append(&string, separator); + } + if (after_last){ + string_append(&string, separator); + } + if (term_padding == 1){ + string_null_terminate(&string); + } + return(string.string); +} +static String_Const_char +string_list_flatten(Arena *arena, List_String_Const_char list, String_Const_char separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ + return(string_list_flatten(arena, list, 0, separator, separator_flags, rule)); +} +static String_Const_u8 +string_list_flatten(Arena *arena, List_String_Const_u8 list, String_Const_u8 separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ + return(string_list_flatten(arena, list, 0, separator, separator_flags, rule)); +} +static String_Const_u16 +string_list_flatten(Arena *arena, List_String_Const_u16 list, String_Const_u16 separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ + return(string_list_flatten(arena, list, 0, separator, separator_flags, rule)); +} +static String_Const_u32 +string_list_flatten(Arena *arena, List_String_Const_u32 list, String_Const_u32 separator, String_Separator_Flag separator_flags, String_Fill_Terminate_Rule rule){ + return(string_list_flatten(arena, list, 0, separator, separator_flags, rule)); +} +static String_Const_char +string_list_flatten(Arena *arena, List_String_Const_char list, String_char_Mod_Function_Type *mod, String_Fill_Terminate_Rule rule){ + return(string_list_flatten(arena, list, mod, SCchar(), 0, rule)); +} +static String_Const_u8 +string_list_flatten(Arena *arena, List_String_Const_u8 list, String_u8_Mod_Function_Type *mod, String_Fill_Terminate_Rule rule){ + return(string_list_flatten(arena, list, mod, SCu8(), 0, rule)); +} +static String_Const_u16 +string_list_flatten(Arena *arena, List_String_Const_u16 list, String_u16_Mod_Function_Type *mod, String_Fill_Terminate_Rule rule){ + return(string_list_flatten(arena, list, mod, SCu16(), 0, rule)); +} +static String_Const_u32 +string_list_flatten(Arena *arena, List_String_Const_u32 list, String_u32_Mod_Function_Type *mod, String_Fill_Terminate_Rule rule){ + return(string_list_flatten(arena, list, mod, SCu32(), 0, rule)); +} +static String_Const_char +string_list_flatten(Arena *arena, List_String_Const_char string, String_Fill_Terminate_Rule rule){ + return(string_list_flatten(arena, string, 0, SCchar(), 0, rule)); +} +static String_Const_u8 +string_list_flatten(Arena *arena, List_String_Const_u8 string, String_Fill_Terminate_Rule rule){ + return(string_list_flatten(arena, string, 0, SCu8(), 0, rule)); +} +static String_Const_u16 +string_list_flatten(Arena *arena, List_String_Const_u16 string, String_Fill_Terminate_Rule rule){ + return(string_list_flatten(arena, string, 0, SCu16(), 0, rule)); +} +static String_Const_u32 +string_list_flatten(Arena *arena, List_String_Const_u32 string, String_Fill_Terminate_Rule rule){ + return(string_list_flatten(arena, string, 0, SCu32(), 0, rule)); +} +static String_Const_char +string_list_flatten(Arena *arena, List_String_Const_char string){ + return(string_list_flatten(arena, string, 0, SCchar(), 0, StringFill_NoTerminate)); +} +static String_Const_u8 +string_list_flatten(Arena *arena, List_String_Const_u8 string){ + return(string_list_flatten(arena, string, 0, SCu8(), 0, StringFill_NoTerminate)); +} +static String_Const_u16 +string_list_flatten(Arena *arena, List_String_Const_u16 string){ + return(string_list_flatten(arena, string, 0, SCu16(), 0, StringFill_NoTerminate)); +} +static String_Const_u32 +string_list_flatten(Arena *arena, List_String_Const_u32 string){ + return(string_list_flatten(arena, string, 0, SCu32(), 0, StringFill_NoTerminate)); +} + +static List_String_Const_char +string_split(Arena *arena, String_Const_char string, char *split_characters, i32 split_character_count){ + List_String_Const_char list = {}; + for (;;){ + umem i = string.size; + String_Const_char prefix = string; + for (i32 j = 0; j < split_character_count; j += 1){ + umem pos = string_find_first(prefix, split_characters[j]); + prefix = string_prefix(prefix, pos); + i = min(i, pos); + } + if (prefix.size > 0){ + string_list_push(arena, &list, prefix); + } + string = string_skip(string, i + 1); + if (string.size == 0){ + break; + } + } + return(list); +} +static List_String_Const_u8 +string_split(Arena *arena, String_Const_u8 string, u8 *split_characters, i32 split_character_count){ + List_String_Const_u8 list = {}; + for (;;){ + umem i = string.size; + String_Const_u8 prefix = string; + for (i32 j = 0; j < split_character_count; j += 1){ + umem pos = string_find_first(prefix, split_characters[j]); + prefix = string_prefix(prefix, pos); + i = min(i, pos); + } + if (prefix.size > 0){ + string_list_push(arena, &list, prefix); + } + string = string_skip(string, i + 1); + if (string.size == 0){ + break; + } + } + return(list); +} +static List_String_Const_u16 +string_split(Arena *arena, String_Const_u16 string, u16 *split_characters, i32 split_character_count){ + List_String_Const_u16 list = {}; + for (;;){ + umem i = string.size; + String_Const_u16 prefix = string; + for (i32 j = 0; j < split_character_count; j += 1){ + umem pos = string_find_first(prefix, split_characters[j]); + prefix = string_prefix(prefix, pos); + i = min(i, pos); + } + if (prefix.size > 0){ + string_list_push(arena, &list, prefix); + } + string = string_skip(string, i + 1); + if (string.size == 0){ + break; + } + } + return(list); +} +static List_String_Const_u32 +string_split(Arena *arena, String_Const_u32 string, u32 *split_characters, i32 split_character_count){ + List_String_Const_u32 list = {}; + for (;;){ + umem i = string.size; + String_Const_u32 prefix = string; + for (i32 j = 0; j < split_character_count; j += 1){ + umem pos = string_find_first(prefix, split_characters[j]); + prefix = string_prefix(prefix, pos); + i = min(i, pos); + } + if (prefix.size > 0){ + string_list_push(arena, &list, prefix); + } + string = string_skip(string, i + 1); + if (string.size == 0){ + break; + } + } + return(list); +} + +static List_String_Const_char +string_split_needle(Arena *arena, String_Const_char string, String_Const_char needle){ + List_String_Const_char list = {}; + for (;string.size > 0;){ + umem pos = string_find_first(string, needle); + String_Const_char prefix = string_prefix(string, pos); + if (pos < string.size){ + string_list_push(arena, &list, needle); + } + if (prefix.size > 0){ + string_list_push(arena, &list, prefix); + } + string = string_skip(string, prefix.size + needle.size); + } + return(list); +} +static List_String_Const_u8 +string_split_needle(Arena *arena, String_Const_u8 string, String_Const_u8 needle){ + List_String_Const_u8 list = {}; + for (;string.size > 0;){ + umem pos = string_find_first(string, needle); + String_Const_u8 prefix = string_prefix(string, pos); + if (pos < string.size){ + string_list_push(arena, &list, needle); + } + if (prefix.size > 0){ + string_list_push(arena, &list, prefix); + } + string = string_skip(string, prefix.size + needle.size); + } + return(list); +} +static List_String_Const_u16 +string_split_needle(Arena *arena, String_Const_u16 string, String_Const_u16 needle){ + List_String_Const_u16 list = {}; + for (;string.size > 0;){ + umem pos = string_find_first(string, needle); + String_Const_u16 prefix = string_prefix(string, pos); + if (pos < string.size){ + string_list_push(arena, &list, needle); + } + if (prefix.size > 0){ + string_list_push(arena, &list, prefix); + } + string = string_skip(string, prefix.size + needle.size); + } + return(list); +} +static List_String_Const_u32 +string_split_needle(Arena *arena, String_Const_u32 string, String_Const_u32 needle){ + List_String_Const_u32 list = {}; + for (;string.size > 0;){ + umem pos = string_find_first(string, needle); + String_Const_u32 prefix = string_prefix(string, pos); + if (pos < string.size){ + string_list_push(arena, &list, needle); + } + if (prefix.size > 0){ + string_list_push(arena, &list, prefix); + } + string = string_skip(string, prefix.size + needle.size); + } + return(list); +} + +static void +string_list_insert_separators(Arena *arena, List_String_Const_char *list, String_Const_char separator, String_Separator_Flag flags){ + Node_String_Const_char *last = list->last; + for (Node_String_Const_char *node = list->first, *next = 0; + node != last; + node = next){ + next = node->next; + Node_String_Const_char *new_node = push_array(arena, Node_String_Const_char, 1); + node->next = new_node; + new_node->next = next; + new_node->string = separator; + list->node_count += 1; + list->total_size += separator.size; + } + if (HasFlag(flags, StringSeparator_BeforeFirst)){ + Node_String_Const_char *new_node = push_array(arena, Node_String_Const_char, 1); + new_node->next = list->first; + list->first = new_node; + new_node->string = separator; + list->node_count += 1; + list->total_size += separator.size; + } + if (HasFlag(flags, StringSeparator_AfterLast)){ + Node_String_Const_char *new_node = push_array(arena, Node_String_Const_char, 1); + list->last->next = new_node; + list->last = new_node; + new_node->next = 0; + new_node->string = separator; + list->node_count += 1; + list->total_size += separator.size; + } +} +static void +string_list_insert_separators(Arena *arena, List_String_Const_u8 *list, String_Const_u8 separator, String_Separator_Flag flags){ + Node_String_Const_u8 *last = list->last; + for (Node_String_Const_u8 *node = list->first, *next = 0; + node != last; + node = next){ + next = node->next; + Node_String_Const_u8 *new_node = push_array(arena, Node_String_Const_u8, 1); + node->next = new_node; + new_node->next = next; + new_node->string = separator; + list->node_count += 1; + list->total_size += separator.size; + } + if (HasFlag(flags, StringSeparator_BeforeFirst)){ + Node_String_Const_u8 *new_node = push_array(arena, Node_String_Const_u8, 1); + new_node->next = list->first; + list->first = new_node; + new_node->string = separator; + list->node_count += 1; + list->total_size += separator.size; + } + if (HasFlag(flags, StringSeparator_AfterLast)){ + Node_String_Const_u8 *new_node = push_array(arena, Node_String_Const_u8, 1); + list->last->next = new_node; + list->last = new_node; + new_node->next = 0; + new_node->string = separator; + list->node_count += 1; + list->total_size += separator.size; + } +} +static void +string_list_insert_separators(Arena *arena, List_String_Const_u16 *list, String_Const_u16 separator, String_Separator_Flag flags){ + Node_String_Const_u16 *last = list->last; + for (Node_String_Const_u16 *node = list->first, *next = 0; + node != last; + node = next){ + next = node->next; + Node_String_Const_u16 *new_node = push_array(arena, Node_String_Const_u16, 1); + node->next = new_node; + new_node->next = next; + new_node->string = separator; + list->node_count += 1; + list->total_size += separator.size; + } + if (HasFlag(flags, StringSeparator_BeforeFirst)){ + Node_String_Const_u16 *new_node = push_array(arena, Node_String_Const_u16, 1); + new_node->next = list->first; + list->first = new_node; + new_node->string = separator; + list->node_count += 1; + list->total_size += separator.size; + } + if (HasFlag(flags, StringSeparator_AfterLast)){ + Node_String_Const_u16 *new_node = push_array(arena, Node_String_Const_u16, 1); + list->last->next = new_node; + list->last = new_node; + new_node->next = 0; + new_node->string = separator; + list->node_count += 1; + list->total_size += separator.size; + } +} +static void +string_list_insert_separators(Arena *arena, List_String_Const_u32 *list, String_Const_u32 separator, String_Separator_Flag flags){ + Node_String_Const_u32 *last = list->last; + for (Node_String_Const_u32 *node = list->first, *next = 0; + node != last; + node = next){ + next = node->next; + Node_String_Const_u32 *new_node = push_array(arena, Node_String_Const_u32, 1); + node->next = new_node; + new_node->next = next; + new_node->string = separator; + list->node_count += 1; + list->total_size += separator.size; + } + if (HasFlag(flags, StringSeparator_BeforeFirst)){ + Node_String_Const_u32 *new_node = push_array(arena, Node_String_Const_u32, 1); + new_node->next = list->first; + list->first = new_node; + new_node->string = separator; + list->node_count += 1; + list->total_size += separator.size; + } + if (HasFlag(flags, StringSeparator_AfterLast)){ + Node_String_Const_u32 *new_node = push_array(arena, Node_String_Const_u32, 1); + list->last->next = new_node; + list->last = new_node; + new_node->next = 0; + new_node->string = separator; + list->node_count += 1; + list->total_size += separator.size; + } +} + +static void +string_list_rewrite_nodes(Arena *arena, List_String_Const_char *list, String_Const_char needle, String_Const_char new_value){ + for (Node_String_Const_char *node = list->first; + node != 0; + node = node->next){ + if (string_match(node->string, needle)){ + node->string = new_value; + list->total_size += new_value.size; + list->total_size -= needle.size; + } + } +} +static void +string_list_rewrite_nodes(Arena *arena, List_String_Const_u8 *list, String_Const_u8 needle, String_Const_u8 new_value){ + for (Node_String_Const_u8 *node = list->first; + node != 0; + node = node->next){ + if (string_match(node->string, needle)){ + node->string = new_value; + list->total_size += new_value.size; + list->total_size -= needle.size; + } + } +} +static void +string_list_rewrite_nodes(Arena *arena, List_String_Const_u16 *list, String_Const_u16 needle, String_Const_u16 new_value){ + for (Node_String_Const_u16 *node = list->first; + node != 0; + node = node->next){ + if (string_match(node->string, needle)){ + node->string = new_value; + list->total_size += new_value.size; + list->total_size -= needle.size; + } + } +} +static void +string_list_rewrite_nodes(Arena *arena, List_String_Const_u32 *list, String_Const_u32 needle, String_Const_u32 new_value){ + for (Node_String_Const_u32 *node = list->first; + node != 0; + node = node->next){ + if (string_match(node->string, needle)){ + node->string = new_value; + list->total_size += new_value.size; + list->total_size -= needle.size; + } + } +} + +static String_Const_char +string_condense_whitespace(Arena *arena, String_Const_char string){ + char split_characters[] = { ' ', '\t', '\n', '\r', '\f', '\v', }; + List_String_Const_char list = string_split(arena, string, split_characters, ArrayCount(split_characters)); + string_list_insert_separators(arena, &list, SCchar(split_characters, 1), StringSeparator_NoFlags); + return(string_list_flatten(arena, list, StringFill_NullTerminate)); +} +static String_Const_u8 +string_condense_whitespace(Arena *arena, String_Const_u8 string){ + u8 split_characters[] = { ' ', '\t', '\n', '\r', '\f', '\v', }; + List_String_Const_u8 list = string_split(arena, string, split_characters, ArrayCount(split_characters)); + string_list_insert_separators(arena, &list, SCu8(split_characters, 1), StringSeparator_NoFlags); + return(string_list_flatten(arena, list, StringFill_NullTerminate)); +} +static String_Const_u16 +string_condense_whitespace(Arena *arena, String_Const_u16 string){ + u16 split_characters[] = { ' ', '\t', '\n', '\r', '\f', '\v', }; + List_String_Const_u16 list = string_split(arena, string, split_characters, ArrayCount(split_characters)); + string_list_insert_separators(arena, &list, SCu16(split_characters, 1), StringSeparator_NoFlags); + return(string_list_flatten(arena, list, StringFill_NullTerminate)); +} +static String_Const_u32 +string_condense_whitespace(Arena *arena, String_Const_u32 string){ + u32 split_characters[] = { ' ', '\t', '\n', '\r', '\f', '\v', }; + List_String_Const_u32 list = string_split(arena, string, split_characters, ArrayCount(split_characters)); + string_list_insert_separators(arena, &list, SCu32(split_characters, 1), StringSeparator_NoFlags); + return(string_list_flatten(arena, list, StringFill_NullTerminate)); +} + +static List_String_Const_u8 +string_split_wildcards(Arena *arena, String_Const_u8 string){ + List_String_Const_u8 list = {}; + if (string_get_character(string, 0) == '*'){ + string_list_push(arena, &list, SCu8()); + } + { + List_String_Const_u8 splits = string_split(arena, string, (u8*)"*", 1); + string_list_push(&list, &splits); + } + if (string.size > 1 && string_get_character(string, string.size - 1) == '*'){ + string_list_push(arena, &list, SCu8()); + } + return(list); +} + +static b32 +string_wildcard_match(List_String_Const_u8 list, String_Const_u8 string, String_Match_Rule rule){ + b32 success = true; + if (list.node_count > 0){ + String_Const_u8 head = list.first->string; + if (!string_match(head, string_prefix(string, head.size), rule)){ + success = false; + } + else if (list.node_count > 1){ + string = string_skip(string, head.size); + String_Const_u8 tail = list.last->string; + if (!string_match(tail, string_postfix(string, tail.size), rule)){ + success = false; + } + else if (list.node_count > 2){ + string = string_chop(string, tail.size); + Node_String_Const_u8 *one_past_last = list.last; + for (Node_String_Const_u8 *node = list.first->next; + node != one_past_last; + node = node->next){ + umem position = string_find_first(string, node->string, rule); + if (position < string.size){ + string = string_skip(string, position + node->string.size); + } + else{ + success = false; + break; + } + } + } + } + } + return(success); +} + +static b32 +string_wildcard_match(List_String_Const_u8 list, String_Const_u8 string){ + return(string_wildcard_match(list, string, StringMatch_Exact)); +} +static b32 +string_wildcard_match_insensitive(List_String_Const_u8 list, String_Const_u8 string){ + return(string_wildcard_match(list, string, StringMatch_CaseInsensitive)); +} + +//////////////////////////////// + +global_const u8 utf8_class[32] = { + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,2,2,2,2,3,3,4,5, +}; + +static Character_Consume_Result +utf8_consume(u8 *str, umem max){ + Character_Consume_Result result = {1, max_u32}; + u8 byte = str[0]; + u8 byte_class = utf8_class[byte >> 3]; + switch (byte_class){ + case 1: + { + result.codepoint = byte; + }break; + case 2: + { + if (1 < max){ + u8 cont_byte = str[1]; + if (utf8_class[cont_byte >> 3] == 0){ + result.codepoint = (byte & bitmask_5) << 6; + result.codepoint |= (cont_byte & bitmask_6); + result.inc = 2; + } + } + }break; + case 3: + { + if (2 < max){ + u8 cont_byte[2] = {str[1], str[2]}; + if (utf8_class[cont_byte[0] >> 3] == 0 && + utf8_class[cont_byte[1] >> 3] == 0){ + result.codepoint = (byte & bitmask_4) << 12; + result.codepoint |= ((cont_byte[0] & bitmask_6) << 6); + result.codepoint |= (cont_byte[1] & bitmask_6); + result.inc = 3; + } + } + }break; + case 4: + { + if (3 < max){ + u8 cont_byte[3] = {str[1], str[2], str[3]}; + if (utf8_class[cont_byte[0] >> 3] == 0 && + utf8_class[cont_byte[1] >> 3] == 0 && + utf8_class[cont_byte[2] >> 3] == 0){ + result.codepoint = (byte & bitmask_3) << 18; + result.codepoint |= ((cont_byte[0] & bitmask_6) << 12); + result.codepoint |= ((cont_byte[1] & bitmask_6) << 6); + result.codepoint |= (cont_byte[2] & bitmask_6); + result.inc = 4; + } + } + }break; + } + return(result); +} + +static Character_Consume_Result +utf16_consume(u16 *str, umem max){ + Character_Consume_Result result = {1, max_u32}; + result.codepoint = str[0]; + result.inc = 1; + if (0xD800 <= str[0] && str[0] < 0xDC00 && max > 1 && 0xDC00 <= str[1] && str[1] < 0xE000){ + result.codepoint = ((str[0] - 0xD800) << 10) | (str[1] - 0xDC00); + result.inc = 2; + } + return(result); +} + +static u32 +utf8_write(u8 *str, u32 codepoint){ + u32 inc = 0; + if (codepoint <= 0x7F){ + str[0] = (u8)codepoint; + inc = 1; + } + else if (codepoint <= 0x7FF){ + str[0] = (bitmask_2 << 6) | ((codepoint >> 6) & bitmask_5); + str[1] = bit_8 | (codepoint & bitmask_6); + inc = 2; + } + else if (codepoint <= 0xFFFF){ + str[0] = (bitmask_3 << 5) | ((codepoint >> 12) & bitmask_4); + str[1] = bit_8 | ((codepoint >> 6) & bitmask_6); + str[2] = bit_8 | ( codepoint & bitmask_6); + inc = 3; + } + else if (codepoint <= 0x10FFFF){ + str[0] = (bitmask_4 << 3) | ((codepoint >> 18) & bitmask_3); + str[1] = bit_8 | ((codepoint >> 12) & bitmask_6); + str[2] = bit_8 | ((codepoint >> 6) & bitmask_6); + str[3] = bit_8 | ( codepoint & bitmask_6); + inc = 4; + } + else{ + str[0] = '?'; + inc = 1; + } + return(inc); +} + +static u32 +utf16_write(u16 *str, u32 codepoint){ + u32 inc = 1; + if (codepoint == max_u32){ + str[0] = (u16)'?'; + } + else if (codepoint < 0x10000){ + str[0] = (u16)codepoint; + } + else{ + u32 v = codepoint - 0x10000; + str[0] = 0xD800 + (u16)(v >> 10); + str[1] = 0xDC00 + (v & bitmask_10); + inc = 2; + } + return(inc); +} + +//////////////////////////////// + +static String_u8 +string_u8_from_string_char(Arena *arena, String_Const_char string, String_Fill_Terminate_Rule rule){ + String_u8 out = {}; + out.cap = string.size; + if (rule == StringFill_NullTerminate){ + out.cap += 1; + } + out.str = push_array(arena, u8, out.cap); + for (umem i = 0; i < string.size; i += 1){ + out.str[i] = ((u8)string.str[i])&bitmask_7; + } + out.size = string.size; + if (rule == StringFill_NullTerminate){ + string_null_terminate(&out); + } + return(out); +} + +static String_u16 +string_u16_from_string_char(Arena *arena, String_Const_char string, String_Fill_Terminate_Rule rule){ + String_u16 out = {}; + out.cap = string.size; + if (rule == StringFill_NullTerminate){ + out.cap += 1; + } + out.str = push_array(arena, u16, out.cap); + for (umem i = 0; i < string.size; i += 1){ + out.str[i] = ((u16)string.str[i])&bitmask_7; + } + out.size = string.size; + if (rule == StringFill_NullTerminate){ + string_null_terminate(&out); + } + return(out); +} + +static String_u32 +string_u32_from_string_char(Arena *arena, String_Const_char string, String_Fill_Terminate_Rule rule){ + String_u32 out = {}; + out.cap = string.size; + if (rule == StringFill_NullTerminate){ + out.cap += 1; + } + out.str = push_array(arena, u32, string.size); + for (umem i = 0; i < string.size; i += 1){ + out.str[i] = ((u32)string.str[i])&bitmask_7; + } + out.size = string.size; + if (rule == StringFill_NullTerminate){ + string_null_terminate(&out); + } + return(out); +} + +static String_char +string_char_from_string_u8(Arena *arena, String_Const_u8 string, String_Fill_Terminate_Rule rule){ + String_char out = {}; + out.cap = string.size; + if (rule == StringFill_NullTerminate){ + out.cap += 1; + } + out.str = push_array(arena, char, out.cap); + u8 *ptr = string.str; + u8 *one_past_last = ptr + string.size; + umem cap = string.size; + Character_Consume_Result consume; + for (;ptr < one_past_last; ptr += consume.inc, cap -= consume.inc){ + consume = utf8_consume(ptr, cap); + out.str[out.size++] = (consume.codepoint <= 127)?((char)consume.codepoint):('?'); + } + if (rule == StringFill_NullTerminate){ + string_null_terminate(&out); + } + return(out); +} + +static String_u16 +string_u16_from_string_u8(Arena *arena, String_Const_u8 string, String_Fill_Terminate_Rule rule){ + String_u16 out = {}; + out.cap = string.size; + if (rule == StringFill_NullTerminate){ + out.cap += 1; + } + out.str = push_array(arena, u16, out.cap); + u8 *ptr = string.str; + u8 *one_past_last = ptr + string.size; + umem cap = string.size; + Character_Consume_Result consume; + for (;ptr < one_past_last; ptr += consume.inc, cap -= consume.inc){ + consume = utf8_consume(ptr, cap); + out.size += utf16_write(out.str + out.size, consume.codepoint); + } + if (rule == StringFill_NullTerminate){ + string_null_terminate(&out); + } + return(out); +} + +static String_u32 +string_u32_from_string_u8(Arena *arena, String_Const_u8 string, String_Fill_Terminate_Rule rule){ + String_u32 out = {}; + out.cap = string.size; + if (rule == StringFill_NullTerminate){ + out.cap += 1; + } + out.str = push_array(arena, u32, out.cap); + u8 *ptr = string.str; + u8 *one_past_last = ptr + string.size; + umem cap = string.size; + Character_Consume_Result consume; + for (;ptr < one_past_last; ptr += consume.inc, cap -= consume.inc){ + consume = utf8_consume(ptr, cap); + out.str[out.size++] = (consume.codepoint == max_u32)?(u64)'?':(consume.codepoint); + } + if (rule == StringFill_NullTerminate){ + string_null_terminate(&out); + } + return(out); +} + +static String_char +string_char_from_string_u16(Arena *arena, String_Const_u16 string, String_Fill_Terminate_Rule rule){ + String_char out = {}; + out.cap = string.size; + if (rule == StringFill_NullTerminate){ + out.cap += 1; + } + out.str = push_array(arena, char, out.cap); + u16 *ptr = string.str; + u16 *one_past_last = ptr + string.size; + umem cap = string.size; + Character_Consume_Result consume; + for (;ptr < one_past_last; ptr += consume.inc, cap -= consume.inc){ + consume = utf16_consume(ptr, cap); + out.str[out.size++] = (consume.codepoint <= 127)?((char)consume.codepoint):('?'); + } + if (rule == StringFill_NullTerminate){ + string_null_terminate(&out); + } + return(out); +} + +static String_u8 +string_u8_from_string_u16(Arena *arena, String_Const_u16 string, String_Fill_Terminate_Rule rule){ + String_u8 out = {}; + out.cap = string.size*3; + if (rule == StringFill_NullTerminate){ + out.cap += 1; + } + out.str = push_array(arena, u8, out.cap); + u16 *ptr = string.str; + u16 *one_past_last = ptr + string.size; + umem cap = string.size; + Character_Consume_Result consume; + for (;ptr < one_past_last; ptr += consume.inc, cap -= consume.inc){ + consume = utf16_consume(ptr, cap); + out.size += utf8_write(out.str + out.size, consume.codepoint); + } + if (rule == StringFill_NullTerminate){ + string_null_terminate(&out); + } + return(out); +} + +static String_u32 +string_u32_from_string_u16(Arena *arena, String_Const_u16 string, String_Fill_Terminate_Rule rule){ + String_u32 out = {}; + out.cap = string.size; + if (rule == StringFill_NullTerminate){ + out.cap += 1; + } + out.str = push_array(arena, u32, out.cap); + u16 *ptr = string.str; + u16 *one_past_last = ptr + string.size; + umem cap = string.size; + Character_Consume_Result consume; + for (;ptr < one_past_last; ptr += consume.inc, cap -= consume.inc){ + consume = utf16_consume(ptr, cap); + out.str[out.size++] = consume.codepoint; + } + if (rule == StringFill_NullTerminate){ + string_null_terminate(&out); + } + return(out); +} + +static String_char +string_char_from_string_u32(Arena *arena, String_Const_u32 string, String_Fill_Terminate_Rule rule){ + String_char out = {}; + out.cap = string.size; + if (rule == StringFill_NullTerminate){ + out.cap += 1; + } + out.str = push_array(arena, char, string.size); + u32 *ptr = string.str; + u32 *one_past_last = ptr + string.size; + for (;ptr < one_past_last; ptr += 1){ + u32 codepoint = *ptr; + out.str[out.size++] = (codepoint <= 127)?((char)codepoint):('?'); + } + if (rule == StringFill_NullTerminate){ + string_null_terminate(&out); + } + return(out); +} + +static String_u8 +string_u8_from_string_u32(Arena *arena, String_Const_u32 string, String_Fill_Terminate_Rule rule){ + String_u8 out = {}; + out.cap = string.size*4; + if (rule == StringFill_NullTerminate){ + out.cap += 1; + } + out.str = push_array(arena, u8, out.cap); + u32 *ptr = string.str; + u32 *one_past_last = ptr + string.size; + for (;ptr < one_past_last; ptr += 1){ + out.size += utf8_write(out.str + out.size, *ptr); + } + if (rule == StringFill_NullTerminate){ + string_null_terminate(&out); + } + return(out); +} + +static String_u16 +string_u16_from_string_u32(Arena *arena, String_Const_u32 string, String_Fill_Terminate_Rule rule){ + String_u16 out = {}; + out.cap = string.size*2; + if (rule == StringFill_NullTerminate){ + out.cap += 1; + } + out.str = push_array(arena, u16, out.cap); + u32 *ptr = string.str; + u32 *one_past_last = ptr + string.size; + for (;ptr < one_past_last; ptr += 1){ + out.size += utf16_write(out.str + out.size, *ptr); + } + if (rule == StringFill_NullTerminate){ + string_null_terminate(&out); + } + return(out); +} + +//////////////////////////////// + +static String_char +string_char_from_string_u8(Arena *arena, String_Const_u8 string){ + return(string_char_from_string_u8(arena, string, StringFill_NoTerminate)); +} +static String_char +string_char_from_string_u16(Arena *arena, String_Const_u16 string){ + return(string_char_from_string_u16(arena, string, StringFill_NoTerminate)); +} +static String_char +string_char_from_string_u32(Arena *arena, String_Const_u32 string){ + return(string_char_from_string_u32(arena, string, StringFill_NoTerminate)); +} +static String_u8 +string_u8_from_string_char(Arena *arena, String_Const_char string){ + return(string_u8_from_string_char(arena, string, StringFill_NoTerminate)); +} +static String_u8 +string_u8_from_string_u16(Arena *arena, String_Const_u16 string){ + return(string_u8_from_string_u16(arena, string, StringFill_NoTerminate)); +} +static String_u8 +string_u8_from_string_u32(Arena *arena, String_Const_u32 string){ + return(string_u8_from_string_u32(arena, string, StringFill_NoTerminate)); +} +static String_u16 +string_u16_from_string_char(Arena *arena, String_Const_char string){ + return(string_u16_from_string_char(arena, string, StringFill_NoTerminate)); +} +static String_u16 +string_u16_from_string_u8(Arena *arena, String_Const_u8 string){ + return(string_u16_from_string_u8(arena, string, StringFill_NoTerminate)); +} +static String_u16 +string_u16_from_string_u32(Arena *arena, String_Const_u32 string){ + return(string_u16_from_string_u32(arena, string, StringFill_NoTerminate)); +} +static String_u32 +string_u32_from_string_char(Arena *arena, String_Const_char string){ + return(string_u32_from_string_char(arena, string, StringFill_NoTerminate)); +} +static String_u32 +string_u32_from_string_u8(Arena *arena, String_Const_u8 string){ + return(string_u32_from_string_u8(arena, string, StringFill_NoTerminate)); +} +static String_u32 +string_u32_from_string_u16(Arena *arena, String_Const_u16 string){ + return(string_u32_from_string_u16(arena, string, StringFill_NoTerminate)); +} + +//////////////////////////////// + +static String_Const_char +string_char_from_any(Arena *arena, String_Const_Any string){ + String_Const_char result = {}; + switch (string.encoding){ + case StringEncoding_ASCII: result = string.s_char; break; + case StringEncoding_UTF8: result = string_char_from_string_u8 (arena, string.s_u8 ).string; break; + case StringEncoding_UTF16: result = string_char_from_string_u16(arena, string.s_u16).string; break; + case StringEncoding_UTF32: result = string_char_from_string_u32(arena, string.s_u32).string; break; + } + return(result); +} +static String_Const_u8 +string_u8_from_any(Arena *arena, String_Const_Any string){ + String_Const_u8 result = {}; + switch (string.encoding){ + case StringEncoding_ASCII: result = string_u8_from_string_char(arena, string.s_char).string; break; + case StringEncoding_UTF8: result = string.s_u8; break; + case StringEncoding_UTF16: result = string_u8_from_string_u16(arena, string.s_u16).string; break; + case StringEncoding_UTF32: result = string_u8_from_string_u32(arena, string.s_u32).string; break; + } + return(result); +} +static String_Const_u16 +string_u16_from_any(Arena *arena, String_Const_Any string){ + String_Const_u16 result = {}; + switch (string.encoding){ + case StringEncoding_ASCII: result = string_u16_from_string_char(arena, string.s_char).string; break; + case StringEncoding_UTF8: result = string_u16_from_string_u8 (arena, string.s_u8 ).string; break; + case StringEncoding_UTF16: result = string.s_u16; break; + case StringEncoding_UTF32: result = string_u16_from_string_u32(arena, string.s_u32).string; break; + } + return(result); +} +static String_Const_u32 +string_u32_from_any(Arena *arena, String_Const_Any string){ + String_Const_u32 result = {}; + switch (string.encoding){ + case StringEncoding_ASCII: result = string_u32_from_string_char(arena, string.s_char).string; break; + case StringEncoding_UTF8: result = string_u32_from_string_u8 (arena, string.s_u8 ).string; break; + case StringEncoding_UTF16: result = string_u32_from_string_u16 (arena, string.s_u16 ).string; break; + case StringEncoding_UTF32: result = string.s_u32; break; + } + return(result); +} + +static String_Const_Any +string_any_from_any(Arena *arena, String_Encoding encoding, String_Const_Any string){ + String_Const_Any result = {encoding}; + switch (encoding){ + case StringEncoding_ASCII: result.s_char = string_char_from_any(arena, string); break; + case StringEncoding_UTF8: result.s_u8 = string_u8_from_any (arena, string); break; + case StringEncoding_UTF16: result.s_u16 = string_u16_from_any (arena, string); break; + case StringEncoding_UTF32: result.s_u32 = string_u32_from_any (arena, string); break; + } + return(result); +} + +static List_String_Const_char +string_list_char_from_any(Arena *arena, List_String_Const_Any list){ + List_String_Const_char result = {}; + for (Node_String_Const_Any *node = list.first; + node != 0; + node = node->next){ + string_list_push(arena, &result, string_char_from_any(arena, node->string)); + } + return(result); +} +static List_String_Const_u8 +string_list_u8_from_any(Arena *arena, List_String_Const_Any list){ + List_String_Const_u8 result = {}; + for (Node_String_Const_Any *node = list.first; + node != 0; + node = node->next){ + string_list_push(arena, &result, string_u8_from_any(arena, node->string)); + } + return(result); +} +static List_String_Const_u16 +string_list_u16_from_any(Arena *arena, List_String_Const_Any list){ + List_String_Const_u16 result = {}; + for (Node_String_Const_Any *node = list.first; + node != 0; + node = node->next){ + string_list_push(arena, &result, string_u16_from_any(arena, node->string)); + } + return(result); +} +static List_String_Const_u32 +string_list_u32_from_any(Arena *arena, List_String_Const_Any list){ + List_String_Const_u32 result = {}; + for (Node_String_Const_Any *node = list.first; + node != 0; + node = node->next){ + string_list_push(arena, &result, string_u32_from_any(arena, node->string)); + } + return(result); +} + +//////////////////////////////// + +static List_String_Const_char +string_replace_list(Arena *arena, String_Const_char source, String_Const_char needle, String_Const_char replacement){ + List_String_Const_char list = {}; + for (;;){ + umem i = string_find_first(source, needle); + string_list_push(arena, &list, string_prefix(source, i)); + if (i < source.size){ + string_list_push(arena, &list, replacement); + source = string_skip(source, i + needle.size); + } + else{ + break; + } + } + return(list); +} +static List_String_Const_u8 +string_replace_list(Arena *arena, String_Const_u8 source, String_Const_u8 needle, String_Const_u8 replacement){ + List_String_Const_u8 list = {}; + for (;;){ + umem i = string_find_first(source, needle); + string_list_push(arena, &list, string_prefix(source, i)); + if (i < source.size){ + string_list_push(arena, &list, replacement); + source = string_skip(source, i + needle.size); + } + else{ + break; + } + } + return(list); +} +static List_String_Const_u16 +string_replace_list(Arena *arena, String_Const_u16 source, String_Const_u16 needle, String_Const_u16 replacement){ + List_String_Const_u16 list = {}; + for (;;){ + umem i = string_find_first(source, needle); + string_list_push(arena, &list, string_prefix(source, i)); + if (i < source.size){ + string_list_push(arena, &list, replacement); + source = string_skip(source, i + needle.size); + } + else{ + break; + } + } + return(list); +} +static List_String_Const_u32 +string_replace_list(Arena *arena, String_Const_u32 source, String_Const_u32 needle, String_Const_u32 replacement){ + List_String_Const_u32 list = {}; + for (;;){ + umem i = string_find_first(source, needle); + string_list_push(arena, &list, string_prefix(source, i)); + if (i < source.size){ + string_list_push(arena, &list, replacement); + source = string_skip(source, i + needle.size); + } + else{ + break; + } + } + return(list); +} + +static String_Const_char +string_replace(Arena *arena, String_Const_char source, String_Const_char needle, String_Const_char replacement, String_Fill_Terminate_Rule rule){ + List_String_Const_char list = string_replace_list(arena, source, needle, replacement); + return(string_list_flatten(arena, list, rule)); +} +static String_Const_u8 +string_replace(Arena *arena, String_Const_u8 source, String_Const_u8 needle, String_Const_u8 replacement, String_Fill_Terminate_Rule rule){ + List_String_Const_u8 list = string_replace_list(arena, source, needle, replacement); + return(string_list_flatten(arena, list, rule)); +} +static String_Const_u16 +string_replace(Arena *arena, String_Const_u16 source, String_Const_u16 needle, String_Const_u16 replacement, String_Fill_Terminate_Rule rule){ + List_String_Const_u16 list = string_replace_list(arena, source, needle, replacement); + return(string_list_flatten(arena, list, rule)); +} +static String_Const_u32 +string_replace(Arena *arena, String_Const_u32 source, String_Const_u32 needle, String_Const_u32 replacement, String_Fill_Terminate_Rule rule){ + List_String_Const_u32 list = string_replace_list(arena, source, needle, replacement); + return(string_list_flatten(arena, list, rule)); +} + +static String_Const_char +string_replace(Arena *arena, String_Const_char source, String_Const_char needle, String_Const_char replacement){ + return(string_replace(arena, source, needle, replacement, StringFill_NoTerminate)); +} +static String_Const_u8 +string_replace(Arena *arena, String_Const_u8 source, String_Const_u8 needle, String_Const_u8 replacement){ + return(string_replace(arena, source, needle, replacement, StringFill_NoTerminate)); +} +static String_Const_u16 +string_replace(Arena *arena, String_Const_u16 source, String_Const_u16 needle, String_Const_u16 replacement){ + return(string_replace(arena, source, needle, replacement, StringFill_NoTerminate)); +} +static String_Const_u32 +string_replace(Arena *arena, String_Const_u32 source, String_Const_u32 needle, String_Const_u32 replacement){ + return(string_replace(arena, source, needle, replacement, StringFill_NoTerminate)); +} + +//////////////////////////////// + +static b32 +byte_is_ascii(u8 byte){ + return(byte == '\r' || byte == '\n' || byte == '\t' || (' ' <= byte && byte <= '~')); +} + +static b32 +data_is_ascii(Data data){ + u8 *ptr = (u8*)data.data; + u8 *one_past_last = ptr + data.size; + b32 result = true; + for (;ptr < one_past_last; ptr += 1){ + if (!byte_is_ascii(*ptr) && !(*ptr == 0 && ptr + 1 == one_past_last)){ + result = false; + break; + } + } + return(result); +} + +//////////////////////////////// + +static String_Const_char +string_interpret_escapes(Arena *arena, String_Const_char string){ + char *space = push_array(arena, char, string.size + 1); + String_char result = Schar(space, 0, string.size); + for (;;){ + umem back_slash_pos = string_find_first(string, '\\'); + string_append(&result, string_prefix(string, back_slash_pos)); + string = string_skip(string, back_slash_pos + 1); + if (string.size == 0){ + break; + } + switch (string.str[0]){ + case '\\': + { + string_append_character(&result, '\\'); + }break; + + case 'n': + { + string_append_character(&result, '\n'); + }break; + + case 't': + { + string_append_character(&result, '\t'); + }break; + + case '"': + { + string_append_character(&result, '\"'); + }break; + + case '0': + { + string_append_character(&result, '\0'); + }break; + + default: + { + char c[2] = {'\\'}; + c[1] = string.str[0]; + string_append(&result, SCchar(c, 2)); + }break; + } + string = string_skip(string, 1); + } + result.str[result.size] = 0; + pop_array(arena, char, result.cap - result.size); + return(result.string); +} + +static String_Const_u8 +string_interpret_escapes(Arena *arena, String_Const_u8 string){ + return(SCu8(string_interpret_escapes(arena, SCchar(string)))); +} + +global_const u8 integer_symbols[] = { + '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F', +}; + +global_const u8 integer_symbol_reverse[128] = { + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + 0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, +}; + +global_const u8 base64[64] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + '_', '$', +}; + +global_const u8 base64_reverse[128] = { + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + 0xFF,0xFF,0xFF,0xFF,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0x00, + 0xFF,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32, + 0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0xFF,0xFF,0xFF,0xFF,0x3E, + 0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18, + 0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0xFF,0xFF,0xFF,0xFF,0xFF, +}; + +static umem +digit_count_from_integer(u64 x, u32 radix){ + umem result = {}; + if (radix >= 2 && radix <= 16){ + if (x == 0){ + result = 1; + } + else{ + do{ + x /= radix; + result += 1; + } while(x > 0); + } + } + return(result); +} + +static String_Const_u8 +string_from_integer(Arena *arena, u64 x, u32 radix){ + String_Const_u8 result = {}; + if (radix >= 2 && radix <= 16){ + if (x == 0){ + result = string_copy(arena, string_u8_litexpr("0")); + } + else{ + u8 string_space[64]; + umem length = 0; + for (u64 X = x; + X > 0; + X /= radix, length += 1){ + string_space[length] = integer_symbols[X%radix]; + } + for (umem j = 0, i = length - 1; + j < i; + j += 1, i -= 1){ + Swap(u8, string_space[i], string_space[j]); + } + result = string_copy(arena, SCu8(string_space, length)); + } + } + return(result); +} + +static b32 +string_is_integer(String_Const_u8 string, u32 radix){ + b32 is_integer = false; + if (radix <= 16){ + is_integer = true; + for (umem i = 0; i < string.size; i += 1){ + if (string.str[i] < 128){ + u8 x = integer_symbol_reverse[character_to_upper(string.str[i])]; + if (x >= radix){ + is_integer = false; + break; + } + } + else{ + is_integer = false; + break; + } + } + } + return(is_integer); +} + +static u64 +string_to_integer(String_Const_u8 string, u32 radix){ + u64 x = 0; + if (radix <= 16){ + for (umem i = 0; i < string.size; i += 1){ + x *= radix; + if (string.str[i] < 128){ + x += integer_symbol_reverse[character_to_upper(string.str[i])]; + } + else{ + x += 0xFF; + } + } + } + return(x); +} + +static u64 +string_to_integer(String_Const_char string, u32 radix){ + return(string_to_integer(SCu8((u8*)string.str, string.size), radix)); +} + +static String_Const_u8 +string_base64_encode_from_binary(Arena *arena, void *data, umem size){ + umem char_count = div_round_up_positive(size*8, 6); + char_count = round_up_umem(char_count, 4); + String_Const_u8 string = string_const_u8_push(arena, char_count); + u8 *s = string.str; + u8 *d = (u8*)data; + u8 *de = d + size; + for (;d < de; d += 3, s += 4){ + i32 in_byte_count = (i32)(de - d); + u8 *D = d; + b32 partial_fill = (in_byte_count < 3); + u8 D_space[3] = {}; + if (partial_fill){ + block_copy(D_space, d, clamp_top(sizeof(D_space), in_byte_count)); + D = D_space; + } + s[0] = D[0] &bitmask_6; + s[1] = ((D[0] >> 6)&bitmask_2) | ((D[1]&bitmask_4) << 2); + s[2] = ((D[1] >> 4)&bitmask_4) | ((D[2]&bitmask_2) << 4); + s[3] = (D[2] >> 2)&bitmask_6; + for (i32 j = 0; j < 4; j += 1){ + s[j] = base64[s[j]]; + } + switch (in_byte_count){ + case 1: + { + s[2] = '?'; + s[3] = '?'; + }break; + case 2: + { + s[3] = '?'; + }break; + } + } + return(string); +} + +static Data +data_decode_from_base64(Arena *arena, u8 *str, umem size){ + Data data = {}; + if (size%4 == 0){ + umem data_size = size*6/8; + if (str[size - 2] == '?'){ + data_size -= 2; + } + else if (str[size - 1] == '?'){ + data_size -= 1; + } + data = push_data(arena, data_size); + u8 *s = str; + u8 *se = s + size; + u8 *d = (u8*)data.data; + u8 *de = d + data_size; + for (;s < se; d += 3, s += 4){ + u8 *D = d; + i32 out_byte_count = (i32)(de - d); + b32 partial_fill = (out_byte_count < 3); + u8 D_space[2]; + if (partial_fill){ + D = D_space; + } + u8 S[4]; + for (i32 j = 0; j < 4; j += 1){ + if (s[j] < 128){ + S[j] = base64_reverse[s[j]]; + } + else{ + S[j] = 0xFF; + } + } + D[0] = ( S[0] &bitmask_6) | ((S[1]&bitmask_2) << 6); + D[1] = ((S[1] >> 2)&bitmask_4) | ((S[2]&bitmask_4) << 4); + D[2] = ((S[2] >> 4)&bitmask_2) | ((S[3]&bitmask_6) << 2); + if (partial_fill){ + Assert(out_byte_count <= sizeof(D_space)); + block_copy(D, D_space, out_byte_count); + } + } + } + return(data); +} + +#endif + +//////////////////////////////// + +#if defined(FSTRING_GUARD) +static String +string_old_from_new(String_Const_char string){ + return(make_string(string.str, (i32)string.size)); +} +static String +string_old_from_new(String_Const_u8 string){ + return(make_string((char*)string.str, (i32)string.size)); +} +static String_Const_char +string_new_from_old(String string){ + return(SCchar(string.str, (umem)string.size)); +} +static String_Const_u8 +string_new_u8_from_old(String string){ + return(SCu8((u8*)string.str, (umem)string.size)); +} +#endif + +#endif + +// BOTTOM diff --git a/4coder_base_types.h b/4coder_base_types.h index c914fe1e..72b39387 100644 --- a/4coder_base_types.h +++ b/4coder_base_types.h @@ -7,14 +7,119 @@ #if !defined(FCODER_BASE_TYPES) #define FCODER_BASE_TYPES -#include "4coder_os_comp_cracking.h" +#if defined(_MSC_VER) -#if defined(IS_CL) -#if (_MSC_VER == 1500) +# define COMPILER_CL 1 + +# if defined(_WIN32) +# define OS_WINDOWS 1 +# else +# error This compiler/platform combo is not supported yet +# endif + +# if defined(_M_AMD64) +# define ARCH_X64 1 +# elif defined(_M_IX86) +# define ARCH_X86 1 +# elif defined(_M_ARM64) +# define ARCH_ARM64 1 +# elif defined(_M_ARM) +# define ARCH_ARM32 1 +# else +# error architecture not supported yet +# endif + +#elif defined(__GNUC__) || defined(__GNUG__) + +# define COMPILER_GCC 1 + +# if defined(__gnu_linux__) +# define OS_LINUX 1 +# elif defined(__APPLE__) && defined(__MACH__) +# define OS_MAC 1 +# else +# error This compiler/platform combo is not supported yet +# endif + +# if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) +# define ARCH_X64 1 +# elif defined(i386) || defined(__i386) || defined(__i386__) +# define ARCH_X86 1 +# elif defined(__aarch64__) +# define ARCH_ARM64 1 +# elif defined(__arm__) +# define ARCH_ARM32 1 +# else +# error architecture not supported yet +# endif + +#else +# error This compiler is not supported yet +#endif + +#if defined(ARCH_X64) +# define ARCH_64BIT 1 +#elif defined(ARCH_X86) +# define ARCH_32BIT 1 + +#endif + +// zeroify + +#if !defined(ARCH_32BIT) +#define ARCH_32BIT 0 +#endif +#if !defined(ARCH_64BIT) +#define ARCH_64BIT 0 +#endif +#if !defined(ARCH_X64) +#define ARCH_X64 0 +#endif +#if !defined(ARCH_X86) +#define ARCH_X86 0 +#endif +#if !defined(ARCH_ARM64) +#define ARCH_ARM64 0 +#endif +#if !defined(ARCH_ARM32) +#define ARCH_ARM32 0 +#endif +#if !defined(COMPILER_CL) +#define COMPILER_CL 0 +#endif +#if !defined(COMPILER_GCC) +#define COMPILER_GCC 0 +#endif +#if !defined(OS_WINDOWS) +#define OS_WINDOWS 0 +#endif +#if !defined(OS_LINUX) +#define OS_LINUX 0 +#endif +#if !defined(OS_MAC) +#define OS_MAC 0 +#endif + +//////////////////////////////// + +#if COMPILER_CL +#if _MSC_VER <= 1800 +# define snprintf _snprintf +#endif + +#if (_MSC_VER <= 1500) #define JUST_GUESS_INTS #endif #endif +#if OS_WINDOWS +# if ARCH_32BIT +# define CALL_CONVENTION __stdcall +# else +# define CALL_CONVENTION +# endif +#endif + #if defined(JUST_GUESS_INTS) typedef signed char i8; typedef signed short i16; @@ -42,7 +147,7 @@ typedef uint64_t u64; typedef i8 b8; typedef i32 b32; -#if defined(FTECH_32_BIT) +#if ARCH_32BIT typedef u32 umem; typedef i32 imem; #else @@ -53,384 +158,848 @@ typedef i64 imem; typedef float f32; typedef double f64; -#define Swap(t,a,b) do { t x = a; a = b; b = x; } while(0) +#define glue_(a,b) a##b +#define glue(a,b) glue_(a,b) -#define Max(a,b) (((a)>(b))?(a):(b)) -#define Min(a,b) (((a)<(b))?(a):(b)) +#define stringify_(a) #a +#define stringify(a) stringify_(a) -#define clamp_top(a,b) Min(a,b) -#define clamp_bottom(a,b) Max(a,b) -#define clamp(a,x,b) (((a)>(x))?(a):(((b)<(x))?(b):(x))) - -#define HasFlag(field,flag) ((field)&(flag)) +#define internal static +#define local_persist static +#define global static +#define local_const static const +#define global_const static const +#define external extern "C" #define ArrayCount(a) ((sizeof(a))/(sizeof(*a))) #define ExpandArray(a) (a), (ArrayCount(a)) -#define AllowLocal(c) (void)(c) -#if !defined(Member) -# define Member(S,m) (((S*)0)->m) -#endif +#define FixSize(s) struct{ u8 __size_fixer__[s]; } + #define PtrDif(a,b) ((u8*)(a) - (u8*)(b)) #define PtrAsInt(a) PtrDif(a,0) -#define HandleAsU64(a) (uint64_t)(PtrAsInt(a)) +#define HandleAsU64(a) (u64)(PtrAsInt(a)) +#define Member(S,m) (((S*)0)->m) #define NullMember(S,m) (&Member(S,m)) #define OffsetOfMember(S,m) PtrAsInt(&Member(S,m)) +#define SizeAfterMember(S,m) (sizeof(S) - OffsetOfMember(S,m)) #define CastFromMember(S,m,ptr) (S*)( (u8*)(ptr) - OffsetOfMember(S,m) ) #define IntAsPtr(a) (void*)(((u8*)0) + a) #define Stmnt(s) do{ s }while(0) -#define STR__(s) #s -#define STR_(s) STR__(s) -#define LINE_STR STR_(__LINE__) -#define FNLN __FILE__ ":" LINE_STR ":" +#define AssertBreak(m) (*((i32*)0) = 0xA11E) +#define AssertAlways(c) Stmnt( if (!(c)) { AssertBreak(c); } ) +#define AssertMessageAlways(m) AssertBreak(m) +#define StaticAssertDisambiguateAlways(c,d) char glue(__ignore__, glue(__LINE__, d))[(c)?1:-1]; +#define StaticAssertAlways(c) StaticAssertDisambiguateAlways(c,__default__) -#if defined(Assert) -# undef Assert +#if !SHIP_MODE +#define Assert(c) AssertAlways(c) +#define AssertMessage(m) AssertMessageAlways(m) +#define StaticAssertDisambiguate(c,d) StaticAssertDisambiguateAlways(c,d) +#define StaticAssert(c) StaticAssertAlways(c) +#else +#define Assert(c) +#define AssertMessage(m) +#define StaticAssertDisambiguate(c,d) +#define StaticAssert(c) #endif -#define Assert(c) do { if (!(c)) *((i32*)0) = 0xA11E; } while(0) -#define TentativeAssert(c) Assert(c) -#define InvalidCodePath Assert(!"Invalid Code Path!") -#define NotImplemented Assert(!"Not Implemented!") #define AssertImplies(a,b) Assert(!(a) || (b)) +#define InvalidPath AssertMessage("invalid path") +#define NotImplemented AssertMessage("not implemented") +#define DontCompile NoSeriouslyDontCompile + +#define B(x) (x) +#define KB(x) ((x) << 10) +#define MB(x) ((x) << 20) +#define GB(x) ((x) << 30) +#define TB(x) (((u64)x) << 40) + +#define Thousand(x) ((x)*1000) +#define Million(x) ((x)*1000000) +#define Billion(x) ((x)*1000000000) + +#define HasFlag(fi,fl) (((fi)&(fl))!=0) +#define HasAllFlag(fi,fl) (((fi)&(fl))==(fl)) +#define AddFlag(fi,fl) ((fi)|=(fl)) +#define RemFlag(fi,fl) ((fi)&=(~(fl))) +#define MovFlag(fi1,fl1,fi2,fl2) ((HasFlag(fi1,fl1))?(AddFlag(fi2,fl2)):(fi2)) + +#define Swap(t,a,b) do { t glue(hidden_temp_,__LINE__) = a; a = b; b = glue(hidden_temp_,__LINE__); } while(0) + +#define div_round_up_positive_(n,d) (n + d - 1)/d +#define div_round_up_positive(n,d) (div_round_up_positive_((n),(d))) + +#define DrCase(PC) case PC: goto resumespot_##PC +#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); } + +#define Max(a,b) (((a)>(b))?(a):(b)) +#define Min(a,b) (((a)<(b))?(a):(b)) +#define max(a,b) (((a)>(b))?(a):(b)) +#define min(a,b) (((a)<(b))?(a):(b)) +#define clamp_top(a,b) Min(a,b) +#define clamp_bot(a,b) Max(a,b) +#define clamp_(a,x,b) ((a>x)?a:((bnext=(s),(s)->prev=(s) -#define dll_insert(p,n) (n)->next=(p)->next,(n)->prev=(p),(p)->next=(n),(n)->next->prev=(n) -#define dll_insert_back(p,n) (n)->prev=(p)->prev,(n)->next=(p),(p)->prev=(n),(n)->prev->next=(n) -#define dll_remove(n) (n)->next->prev=(n)->prev,(n)->prev->next=(n)->next,(n)->next=(n)->prev=0 - -#define zdll_push_back_(f,l,n) if(f==0){n->next=n->prev=0;f=l=n;}else{n->prev=l;n->next=0;l->next=n;l=n;} -#define zdll_push_front_(f,l,n) if(f==0){n->prev=n->next=0;f=l=n;}else{n->next=l;n->prev=0;l->prev=n;l=n;} -#define zdll_remove_front_(f,l,n) if(f==l){f=l=0;}else{f=f->next;f->prev=0;} -#define zdll_remove_(f,l,n) if(f==n){zdll_remove_front_(f,l,n);}else if(l==n){zdll_remove_back_(f,l,n);}else{dll_remove(n);} - -#define zdll_push_back(f,l,n) Stmnt( zdll_push_back_((f),(l),(n)) ) -#define zdll_push_front(f,l,n) Stmnt( zdll_push_front_((f),(l),(n)) ) -#define zdll_remove_back_(f,l,n) if(f==l){f=l=0;}else{l=l->prev;l->next=0;} -#define zdll_remove(f,l,n) Stmnt( zdll_remove_((f),(l),(n)) ) - -#define sll_clear(f,l) (f)=(l)=0 -#define sll_push(f,l,n) Stmnt( if((f)==0||(l)==0){(f)=(l)=(n);}else{(l)->next=(n);(l)=(n);}(n)->next=0; ) -#define sll_pop(f,l) Stmnt( if((f)!=(l)){(f)=(f)->next;}else{(f)=(l)=0;} ) - -#define sll_init_sentinel(s) Stmnt( (s)->next=(s); ) -#define sll_insert(p,v) Stmnt( (v)->next=(p)->next; (p)->next = (v); ) -#define sll_remove(p,v) Stmnt( Assert((p)->next == (v)); (p)->next = (v)->next; ) - struct Node{ Node *next; Node *prev; }; +union SNode{ + SNode *next; + SNode *prev; +}; + +#define dll_init_sentinel_NP_(s,next,prev) s->next=s,s->prev=s +#define dll_insert_NP_(p,n1,n2,next,prev) n2->next=p->next,n1->prev=p,p->next->prev=n2,p->next=n1 +#define dll_remove_NP_(n1,n2,next,prev) n2->next->prev=n1->prev,n1->prev->next=n2->next,n2->next=n1->prev=0 + +#define dll_init_sentinel_(s) dll_init_sentinel_NP_(s,next,prev) +#define dll_insert_(p,n) dll_insert_NP_(p,n,n,next,prev) +#define dll_insert_multiple_(p,n1,n2) dll_insert_NP_(p,n1,n2,next,prev) +#define dll_insert_back_(p,n) dll_insert_NP_(p,n,n,prev,next) +#define dll_insert_multiple_back_(p,n1,n2) dll_insert_NP_(p,n2,n1,prev,next) +#define dll_remove_(n) dll_remove_NP_(n,n,next,prev) +#define dll_remove_multiple_(n1,n2) dll_remove_NP_(n1,n2,next,prev) + +#define dll_init_sentinel(s) (dll_init_sentinel_((s))) +#define dll_insert(p,n) (dll_insert_((p),(n))) +#define dll_insert_multiple(p,n1,n2) (dll_insert_multiple_((p),(n1),(n2))) +#define dll_insert_back(p,n) (dll_insert_back_((p),(n))) +#define dll_insert_multiple_back(p,n1,n2) (dll_insert_multiple_back_((p),(n1),(n2))) +#define dll_remove(n) (dll_remove_((n))) +#define dll_remove_multiple(n1,n2) (dll_remove_multiple_((n1),(n2))) + +#define sll_stack_push_(h,n) n->next=h,h=n +#define sll_stack_pop_(h) h->next=0,h=h->next +#define sll_queue_push_multiple_(f,l,ff,ll) if(ll){if(f){l->next=ff;}else{f=ff;}l=ll;l->next=0;} +#define sll_queue_push_(f,l,n) sll_queue_push_multiple_(f,l,n,n) +#define sll_queue_pop_(f,l) if (f==l) { f=l=0; } else { f->next=0;f=f->next; } + +#define sll_stack_push(h,n) (sll_stack_push_((h),(n))) +#define sll_stack_pop(h) (sll_stack_pop_((h))) +#define sll_queue_push_multiple(f,l,ff,ll) Stmnt( sll_queue_push_multiple_((f),(l),(ff),(ll)) ) +#define sll_queue_push(f,l,n) Stmnt( sll_queue_push_((f),(l),(n)) ) +#define sll_queue_pop(f,l) Stmnt( sll_queue_pop_((f),(l)) ) + +#define zdll_push_back_NP_(f,l,n,next,prev) ((f==0)?(n->next=n->prev=0,f=l=n):(n->prev=l,n->next=0,l->next=n,l=n)) +#define zdll_remove_back_NP_(f,l,next,prev) ((f==l)?(f=l=0):(l->prev->next=0,l=l->prev)) +#define zdll_remove_NP_(f,l,n,next,prev) \ +((l==n)?(zdll_remove_back_NP_(f,l,next,prev)) \ +:(f==n)?(zdll_remove_back_NP_(l,f,prev,next)) \ +: (dll_remove_NP_(n,n,next,prev))) + +#define zdll_push_back(f,l,n) zdll_push_back_NP_((f),(l),(n),next,prev) +#define zdll_push_front(f,l,n) zdll_push_back_NP_((l),(f),(n),prev,next) +#define zdll_remove_back(f,l) zdll_remove_back_NP_((f),(l),next,prev) +#define zdll_remove_front(f,l) zdll_remove_back_NP_((l),(f),prev,next) +#define zdll_remove(f,l,n) zdll_remove_NP_((f),(l),(n),next,prev) //////////////////////////////// -struct Vec2_f32{ - union{ - struct{ - f32 x, y; - }; - struct{ - f32 v[2]; - }; +union Vec2_i8{ + struct{ + i8 x; + i8 y; + }; + i8 v[2]; +}; +union Vec3_i8{ + struct{ + i8 x; + i8 y; + i8 z; + }; + struct{ + i8 r; + i8 g; + i8 b; + }; + i8 v[3]; +}; +union Vec4_i8{ + struct{ + i8 x; + i8 y; + i8 z; + i8 w; + }; + struct{ + i8 r; + i8 g; + i8 b; + i8 a; + }; + i8 v[4]; +}; +union Vec2_i16{ + struct{ + i16 x; + i16 y; + }; + i16 v[2]; +}; +union Vec3_i16{ + struct{ + i16 x; + i16 y; + i16 z; + }; + struct{ + i16 r; + i16 g; + i16 b; + }; + i16 v[3]; +}; +union Vec4_i16{ + struct{ + i16 x; + i16 y; + i16 z; + i16 w; + }; + struct{ + i16 r; + i16 g; + i16 b; + i16 a; + }; + i16 v[4]; +}; +union Vec2_i32{ + struct{ + i32 x; + i32 y; + }; + i32 v[2]; +}; +union Vec3_i32{ + struct{ + i32 x; + i32 y; + i32 z; + }; + struct{ + i32 r; + i32 g; + i32 b; + }; + i32 v[3]; +}; +union Vec4_i32{ + struct{ + i32 x; + i32 y; + i32 z; + i32 w; + }; + struct{ + i32 r; + i32 g; + i32 b; + i32 a; + }; + i32 v[4]; +}; +union Vec2_f32{ + struct{ + f32 x; + f32 y; + }; + f32 v[2]; +}; +union Vec3_f32{ + struct{ + f32 x; + f32 y; + f32 z; + }; + struct{ + f32 r; + f32 g; + f32 b; + }; + f32 v[3]; +}; +union Vec4_f32{ + struct{ + f32 x; + f32 y; + f32 z; + f32 w; + }; + struct{ + f32 r; + f32 g; + f32 b; + f32 a; + }; + struct{ + f32 h; + f32 s; + f32 l; + f32 __a; + }; + f32 v[4]; +}; + +union Range_i8{ + struct{ + i8 min; + i8 max; + }; + struct{ + i8 start; + i8 end; + }; + struct{ + i8 first; + i8 one_past_last; + }; +}; +union Range_i16{ + struct{ + i16 min; + i16 max; + }; + struct{ + i16 start; + i16 end; + }; + struct{ + i16 first; + i16 one_past_last; + }; +}; +union Range_i32{ + struct{ + i32 min; + i32 max; + }; + struct{ + i32 start; + i32 end; + }; + struct{ + i32 first; + i32 one_past_last; + }; +}; +union Range_f32{ + struct{ + f32 min; + f32 max; + }; + struct{ + f32 start; + f32 end; + }; + struct{ + f32 first; + f32 one_past_last; + }; +}; +union Range_umem{ + struct{ + umem min; + umem max; + }; + struct{ + umem start; + umem end; + }; + struct{ + umem first; + umem one_past_last; }; }; -struct Vec3_f32{ - union{ - struct{ - f32 x, y, z; - }; - struct{ - f32 r, g, b; - }; - struct{ - Vec2_f32 xy; - f32 _z; - }; - struct{ - f32 _x; - Vec2_f32 yz; - }; - struct{ - f32 v[3]; - }; - }; -}; +typedef Range_i8 Interval_i8; +typedef Range_i16 Interval_i16; +typedef Range_i32 Interval_i32; +typedef Range_f32 Interval_f32; +typedef Range_umem Interval_umem; +typedef Range_i32 Range; -struct Vec4_f32{ - union{ - struct{ - f32 r, g, b, a; - }; - struct{ - f32 h, s, l, __a; - }; - struct{ - f32 x, y, z, w; - }; - struct{ - Vec3_f32 xy; - Vec3_f32 zw; - }; - struct{ - Vec3_f32 _x; - Vec3_f32 yz; - Vec3_f32 _w; - }; - struct{ - Vec3_f32 rgb; - f32 __a; - }; - struct{ - Vec3_f32 xyz; - f32 __w; - }; - struct{ - f32 __x; - Vec3_f32 yzw; - }; - struct{ - f32 v[4]; - }; +union Rect_i8{ + struct{ + i8 x0; + i8 y0; + i8 x1; + i8 y1; }; + struct{ + Vec2_i8 p0; + Vec2_i8 p1; + }; + Vec2_i8 p[2]; }; - -struct Vec2_i32{ - union{ - struct{ - i32 x, y; - }; - struct{ - i32 v[2]; - }; +union Rect_i16{ + struct{ + i16 x0; + i16 y0; + i16 x1; + i16 y1; }; + struct{ + Vec2_i16 p0; + Vec2_i16 p1; + }; + Vec2_i16 p[2]; }; - -struct Vec3_i32{ - union{ - struct{ - i32 x, y, z; - }; - struct{ - i32 r, g, b; - }; - struct{ - Vec2_i32 xy; - i32 _z; - }; - struct{ - i32 _x; - Vec2_i32 yz; - }; - struct{ - i32 v[3]; - }; +union Rect_i32{ + struct{ + i32 x0; + i32 y0; + i32 x1; + i32 y1; }; + struct{ + Vec2_i32 p0; + Vec2_i32 p1; + }; + Vec2_i32 p[2]; }; - -struct Vec4_i32{ - union{ - struct{ - i32 r, g, b, a; - }; - struct{ - i32 h, s, l, __a; - }; - struct{ - i32 x, y, z, w; - }; - struct{ - Vec3_i32 xy; - Vec3_i32 zw; - }; - struct{ - Vec3_i32 _x; - Vec3_i32 yz; - Vec3_i32 _w; - }; - struct{ - Vec3_i32 rgb; - i32 __a; - }; - struct{ - Vec3_i32 xyz; - i32 __w; - }; - struct{ - i32 __x; - Vec3_i32 yzw; - }; - struct{ - i32 v[4]; - }; +union Rect_f32{ + struct{ + f32 x0; + f32 y0; + f32 x1; + f32 y1; }; + struct{ + Vec2_f32 p0; + Vec2_f32 p1; + }; + Vec2_f32 p[2]; }; typedef Vec2_f32 Vec2; typedef Vec3_f32 Vec3; typedef Vec4_f32 Vec4; -//////////////////////////////// - -struct Rect_f32{ - union{ - struct{ - f32 x0; - f32 y0; - f32 x1; - f32 y1; - }; - struct{ - Vec2_f32 p0; - Vec2_f32 p1; - }; - }; -}; - -struct Rect_i32{ - union{ - struct{ - i32 x0; - i32 y0; - i32 x1; - i32 y1; - }; - struct{ - Vec2_i32 p0; - Vec2_i32 p1; - }; - }; -}; - typedef Rect_f32 f32_Rect; typedef Rect_i32 i32_Rect; -struct f32_Rect_Pair -{ +struct f32_Rect_Pair{ f32_Rect E[2]; }; typedef f32_Rect_Pair Rect_f32_Pair; +//////////////////////////////// + +typedef i32 String_Fill_Terminate_Rule; +enum{ + StringFill_NoTerminate = 0, + StringFill_NullTerminate = 1, +}; +typedef u32 String_Separator_Flag; +enum{ + StringSeparator_NoFlags = 0, +}; +enum{ + StringSeparator_BeforeFirst = 1, + StringSeparator_AfterLast = 2, +}; +typedef i32 String_Match_Rule; +enum{ + StringMatch_Exact = 0, + StringMatch_CaseInsensitive = 1, +}; + +struct String_Const_char{ + char *str; + umem size; +}; +struct String_Const_u8{ + union{ + void *data; + u8 *str; + }; + umem size; +}; +struct String_Const_u16{ + u16 *str; + umem size; +}; +struct String_Const_u32{ + u32 *str; + umem size; +}; + +struct String_Const_char_Array{ + union{ + String_Const_char *strings; + String_Const_char *vals; + }; + i32 count; +}; +struct String_Const_u8_Array{ + union{ + String_Const_u8 *strings; + String_Const_u8 *vals; + }; + i32 count; +}; +struct String_Const_u16_Array{ + union{ + String_Const_u16 *strings; + String_Const_u16 *vals; + }; + i32 count; +}; +struct String_Const_u32_Array{ + union{ + String_Const_u32 *strings; + String_Const_u32 *vals; + }; + i32 count; +}; + +typedef i32 String_Encoding; +enum{ + StringEncoding_ASCII = 0, + StringEncoding_UTF8 = 1, + StringEncoding_UTF16 = 2, + StringEncoding_UTF32 = 3, +}; + +struct String_Const_Any{ + String_Encoding encoding; + union{ + struct{ + void *str; + umem size; + }; + String_Const_char s_char; + String_Const_u8 s_u8; + String_Const_u16 s_u16; + String_Const_u32 s_u32; + }; +}; + +struct Node_String_Const_char{ + Node_String_Const_char *next; + String_Const_char string; +}; +struct Node_String_Const_u8{ + Node_String_Const_u8 *next; + String_Const_u8 string; +}; +struct Node_String_Const_u16{ + Node_String_Const_u16 *next; + String_Const_u16 string; +}; +struct Node_String_Const_u32{ + Node_String_Const_u32 *next; + String_Const_u32 string; +}; +struct List_String_Const_char{ + Node_String_Const_char *first; + Node_String_Const_char *last; + i32 node_count; + umem total_size; +}; +struct List_String_Const_u8{ + Node_String_Const_u8 *first; + Node_String_Const_u8 *last; + i32 node_count; + umem total_size; +}; +struct List_String_Const_u16{ + Node_String_Const_u16 *first; + Node_String_Const_u16 *last; + i32 node_count; + umem total_size; +}; +struct List_String_Const_u32{ + Node_String_Const_u32 *first; + Node_String_Const_u32 *last; + i32 node_count; + umem total_size; +}; + +struct Node_String_Const_Any{ + Node_String_Const_Any *next; + String_Const_Any string; +}; +struct List_String_Const_Any{ + Node_String_Const_Any *first; + Node_String_Const_Any *last; + i32 node_count; + umem total_size; +}; + +struct String_char{ + union{ + String_Const_char string; + struct{ + char *str; + umem size; + }; + }; + umem cap; +}; +struct String_u8{ + union{ + String_Const_u8 string; + struct{ + u8 *str; + umem size; + }; + }; + umem cap; +}; +struct String_u16{ + union{ + String_Const_u16 string; + struct{ + u16 *str; + umem size; + }; + }; + umem cap; +}; +struct String_u32{ + union{ + String_Const_u32 string; + struct{ + u32 *str; + umem size; + }; + }; + umem cap; +}; + +struct String_Any{ + String_Encoding encoding; + union{ + struct{ + void *str; + umem size; + umem cap; + }; + String_char s_char; + String_u8 s_u8; + String_u16 s_u16; + String_u32 s_u32; + }; +}; + +struct Character_Consume_Result{ + u32 inc; + u32 codepoint; +}; + +struct Data{ + u8 *data; + umem size; +}; + +//////////////////////////////// + +typedef u32 Access_Flag; +enum{ + AccessFlag_Read = 1, + AccessFlag_Write = 2, + AccessFlag_Exec = 4, +}; + +typedef i32 Dimension; +enum{ + Dimension_X = 0, + Dimension_Y = 1, + Dimension_Z = 2, + Dimension_W = 3, +}; typedef i32 Coordinate; -typedef i32 Side; - enum{ Coordinate_X = 0, Coordinate_Y = 1, @@ -438,11 +1007,83 @@ enum{ Coordinate_W = 3, }; +typedef i32 Side; enum{ Side_Min = 0, Side_Max = 1, }; +//////////////////////////////// + +#define Migrating__Arena +#if defined(Migrating__Arena) + +typedef void *Base_Allocator_Reserve_Signature(void *user_data, umem size, umem *size_out); +typedef void Base_Allocator_Commit_Signature(void *user_data, void *ptr, umem size); +typedef void Base_Allocator_Uncommit_Signature(void *user_data, void *ptr, umem size); +typedef void Base_Allocator_Free_Signature(void *user_data, void *ptr); +typedef void Base_Allocator_Set_Access_Signature(void *user_data, void *ptr, umem size, Access_Flag flags); +struct Base_Allocator{ + Base_Allocator_Reserve_Signature *reserve; + Base_Allocator_Commit_Signature *commit; + Base_Allocator_Uncommit_Signature *uncommit; + Base_Allocator_Free_Signature *free; + Base_Allocator_Set_Access_Signature *set_access; + void *user_data; +}; + +struct Cursor{ + u8 *base; + umem pos; + umem cap; +}; +struct Temp_Memory_Cursor{ + Cursor *cursor; + umem pos; +}; +struct Cursor_Node{ + union{ + Cursor_Node *next; + Cursor_Node *prev; + }; + Cursor cursor; +}; +struct Arena{ + Base_Allocator *base_allocator; + Cursor_Node *cursor_node; + umem chunk_size; + umem alignment; +}; +struct Temp_Memory_Arena{ + Arena *arena; + Cursor_Node *cursor_node; + umem pos; +}; +typedef i32 Linear_Allocator_Kind; +enum{ + LinearAllocatorKind_Cursor, + LinearAllocatorKind_Arena, +}; +struct Temp_Memory{ + Linear_Allocator_Kind kind; + union{ + Temp_Memory_Cursor temp_memory_cursor; + Temp_Memory_Arena temp_memory_arena; + }; +}; + +struct Scratch_Block{ + Scratch_Block(Temp_Memory temp); + Scratch_Block(Arena *arena); + Scratch_Block(struct Application_Links *app); + ~Scratch_Block(); + operator Arena*(); + void restore(void); + Temp_Memory temp; +}; + +#endif + #endif // BOTTOM diff --git a/4coder_build_commands.cpp b/4coder_build_commands.cpp index 191d107b..70cedab8 100644 --- a/4coder_build_commands.cpp +++ b/4coder_build_commands.cpp @@ -4,142 +4,124 @@ // TOP -// NOTE(allen|a4.0.9): This is provided to establish a default method of getting -// a "build directory". This function tries to setup the build directory in the -// directory of the given buffer, if it cannot get that information it get's the -// 4coder hot directory. -// -// There is no requirement that a custom build system in 4coder actually use the -// directory given by this function. -static i32 -get_build_directory(Application_Links *app, Buffer_ID buffer, String *dir_out){ - Arena *scratch = context_get_arena(app); - Temp_Memory_Arena temp = begin_temp_memory(scratch); - - i32 result = BuildDir_None; - - if (buffer != 0){ - String file_name = buffer_push_file_name(app, buffer, scratch); - String base_name = buffer_push_base_buffer_name(app, buffer, scratch); - if (!match(file_name, base_name)){ - remove_last_folder(&file_name); - append(dir_out, file_name); - result = BuildDir_AtFile; - } - } - - if (result == BuildDir_None){ - if (get_hot_directory(app, dir_out, 0)){ - result = BuildDir_AtHot; - } - } - - end_temp_memory(temp); - - return(result); -} - -// TODO(allen): Better names for the "standard build search" family. -static i32 -standard_build_search(Application_Links *app, View_ID view, String *dir, String *command, b32 perform_backup, b32 use_path_in_command, String filename, String command_name){ - i32 result = false; - - for(;;){ - i32 old_size = dir->size; - append_ss(dir, filename); - - if (file_exists(app, dir->str, dir->size)){ - dir->size = old_size; - - if (use_path_in_command){ - append(command, '"'); - append(command, *dir); - append(command, command_name); - append(command, '"'); - } - else{ - append_ss(command, command_name); - } - - char space[512]; - String message = make_fixed_width_string(space); - append_ss(&message, make_lit_string("Building with: ")); - append_ss(&message, *command); - append_s_char(&message, '\n'); - print_message(app, message.str, message.size); - - if (global_config.automatically_save_changes_on_build){ - save_all_dirty_buffers(app); - } - - exec_system_command(app, view, buffer_identifier(literal("*compilation*")), dir->str, dir->size, command->str, command->size, CLI_OverlapWithConflict|CLI_SendEndSignal); - result = true; - break; - } - dir->size = old_size; - - if (directory_cd(app, dir->str, &dir->size, dir->memory_size, literal("..")) == 0){ - if (perform_backup){ - dir->size = directory_get_hot(app, dir->str, dir->memory_size); - char backup_space[256]; - String backup_command = make_fixed_width_string(backup_space); - append_ss(&backup_command, make_lit_string("echo could not find ")); - append_ss(&backup_command, filename); - exec_system_command(app, view, buffer_identifier(literal("*compilation*")), dir->str, dir->size, backup_command.str, backup_command.size, CLI_OverlapWithConflict|CLI_SendEndSignal); - } - break; - } - } - - return(result); -} - -#if defined(IS_WINDOWS) - -// NOTE(allen): Build search rule for windows. -static i32 -execute_standard_build_search(Application_Links *app, View_ID view, String *dir, String *command, i32 perform_backup){ - i32 result = standard_build_search(app, view, dir, command, perform_backup, true, make_lit_string("build.bat"), make_lit_string("build")); - return(result); -} - -#elif defined(IS_LINUX) || defined(IS_MAC) - -// NOTE(allen): Build search rule for linux and mac. -static i32 -execute_standard_build_search(Application_Links *app, View_ID view, String *dir, String *command, b32 perform_backup){ - char dir_space[512]; - String dir_copy = make_fixed_width_string(dir_space); - copy(&dir_copy, *dir); - i32 result = standard_build_search(app, view, dir, command, 0, 1, make_lit_string("build.sh"), make_lit_string("build.sh")); - if (!result){ - result = standard_build_search(app, view, &dir_copy, command, perform_backup, 0, make_lit_string("Makefile"), make_lit_string("make")); +static String_Const_u8 +push_build_directory_at_file(Application_Links *app, Arena *arena, Buffer_ID buffer){ + String_Const_u8 result = {}; + String_Const_u8 file_name = buffer_push_file_name(app, buffer, arena); + Temp_Memory restore_point = begin_temp(arena); + String_Const_u8 base_name = buffer_push_base_buffer_name(app, buffer, arena); + b32 is_match = string_match(file_name, base_name); + end_temp(restore_point); + if (!is_match){ + result = string_copy(arena, string_remove_last_folder(file_name)); } return(result); } +#if OS_WINDOWS + +global String_Const_u8 standard_build_file_name_array[] = { + string_u8_litinit("build.bat"), +}; +global String_Const_u8 standard_build_cmd_string_array[] = { + string_u8_litinit("build"), +}; + +#elif OS_LINUX || OS_MAC + +global String_Const_u8 standard_build_file_name_array[] = { + string_u8_litinit("build.sh"), + string_u8_litinit("Makefile"), +}; +global String_Const_u8 standard_build_cmd_string_array[] = { + string_u8_litinit("build.sh"), + string_u8_litinit("make"), +}; + #else -# error No build search rule for this platform. +#error OS needs standard search and build rules #endif +static String_Const_u8 +push_fallback_command(Arena *arena, String_Const_u8 file_name){ + return(string_u8_pushf(arena, "echo could not find %.*s", string_expand(file_name))); +} + +static String_Const_u8 +push_fallback_command(Arena *arena){ + return(push_fallback_command(arena, standard_build_file_name_array[0])); +} + +global_const Buffer_Identifier standard_build_build_buffer_identifier = buffer_identifier(string_u8_litexpr("*compilation*")); + +global_const u32 standard_build_exec_flags = CLI_OverlapWithConflict|CLI_SendEndSignal; + +static void +standard_build_exec_command(Application_Links *app, View_ID view, String_Const_u8 dir, String_Const_u8 cmd){ + exec_system_command(app, view, standard_build_build_buffer_identifier, + dir, cmd, + standard_build_exec_flags); +} + +static b32 +standard_search_and_build_from_dir(Application_Links *app, View_ID view, String_Const_u8 start_dir){ + Scratch_Block scratch(app); + + // NOTE(allen): Search + String_Const_u8 full_file_path = {}; + String_Const_u8 cmd_string = {}; + for (i32 i = 0; i < ArrayCount(standard_build_file_name_array); i += 1){ + full_file_path = push_file_search_up_path(app, scratch, start_dir, standard_build_file_name_array[i]); + if (full_file_path.size > 0){ + cmd_string = standard_build_cmd_string_array[i]; + break; + } + } + + b32 result = (full_file_path.size > 0); + if (result){ + // NOTE(allen): Build + String_Const_u8 path = string_remove_last_folder(full_file_path); +#if OS_WINDOWS + String_Const_u8 command = string_u8_pushf(scratch, "%.*s/%.*s", + string_expand(path), + string_expand(cmd_string)); +#elif OS_LINUX || OS_MAC + String_Const_u8 command = cmd_string; +#else +#error OS needs standard search and build rules +#endif + if (global_config.automatically_save_changes_on_build){ + save_all_dirty_buffers(app); + } + standard_build_exec_command(app, view, path, command); + print_message(app, string_u8_pushf(scratch, "Building with: %.*s\n", + string_expand(full_file_path))); + } + + return(result); +} + // NOTE(allen): This searches first using the active file's directory, // then if no build script is found, it searches from 4coders hot directory. static void -execute_standard_build(Application_Links *app, View_ID view, Buffer_ID active_buffer){ - char dir_space[512]; - String dir = make_fixed_width_string(dir_space); - char command_str_space[512]; - String command = make_fixed_width_string(command_str_space); - i32 build_dir_type = get_build_directory(app, active_buffer, &dir); - if (build_dir_type == BuildDir_AtFile){ - if (!execute_standard_build_search(app, view, &dir, &command, false)){ - dir.size = 0; - command.size = 0; - build_dir_type = get_build_directory(app, 0, &dir); +standard_search_and_build(Application_Links *app, View_ID view, Buffer_ID active_buffer){ + Scratch_Block scratch(app); + b32 did_build = false; + String_Const_u8 build_dir = push_build_directory_at_file(app, scratch, active_buffer); + if (build_dir.size > 0){ + did_build = standard_search_and_build_from_dir(app, view, build_dir); + } + if (!did_build){ + build_dir = push_hot_directory(app, scratch); + if (build_dir.size > 0){ + did_build = standard_search_and_build_from_dir(app, view, build_dir); } } - if (build_dir_type == BuildDir_AtHot){ - execute_standard_build_search(app, view, &dir, &command, true); + if (!did_build){ + standard_build_exec_command(app, view, + push_hot_directory(app, scratch), + push_fallback_command(scratch)); } } @@ -150,18 +132,21 @@ CUSTOM_DOC("Looks for a build.bat, build.sh, or makefile in the current and pare get_active_view(app, AccessAll, &view); Buffer_ID buffer = 0; view_get_buffer(app, view, AccessAll, &buffer); - execute_standard_build(app, view, buffer); + standard_search_and_build(app, view, buffer); memset(&prev_location, 0, sizeof(prev_location)); - lock_jump_buffer(make_lit_string("*compilation*")); + lock_jump_buffer(string_u8_litexpr("*compilation*")); } -#define GET_COMP_BUFFER(app,id) get_buffer_by_name(app, make_lit_string("*compilation*"), AccessAll, (id)) +static b32 +get_comp_buffer(Application_Links *app, Buffer_ID *id_out){ + return(get_buffer_by_name(app, string_u8_litexpr("*compilation*"), AccessAll, id_out)); +} static View_ID get_or_open_build_panel(Application_Links *app){ View_ID view = 0; Buffer_ID buffer = 0; - GET_COMP_BUFFER(app, &buffer); + get_comp_buffer(app, &buffer); if (buffer != 0){ view = get_first_view_with_buffer(app, buffer); } @@ -174,8 +159,8 @@ get_or_open_build_panel(Application_Links *app){ static void set_fancy_compilation_buffer_font(Application_Links *app){ Buffer_ID buffer = 0; - GET_COMP_BUFFER(app, &buffer); - set_buffer_face_by_name(app, buffer, literal("Inconsolata")); + get_comp_buffer(app, &buffer); + set_buffer_face_by_name(app, buffer, string_u8_litexpr("Inconsolata")); } CUSTOM_COMMAND_SIG(build_in_build_panel) @@ -188,11 +173,11 @@ CUSTOM_DOC("Looks for a build.bat, build.sh, or makefile in the current and pare View_ID build_view = get_or_open_build_panel(app); - execute_standard_build(app, build_view, buffer); + standard_search_and_build(app, build_view, buffer); set_fancy_compilation_buffer_font(app); memset(&prev_location, 0, sizeof(prev_location)); - lock_jump_buffer(make_lit_string("*compilation*")); + lock_jump_buffer(string_u8_litexpr("*compilation*")); } CUSTOM_COMMAND_SIG(close_build_panel) diff --git a/4coder_build_commands.h b/4coder_build_commands.h index e556fd7b..223a596d 100644 --- a/4coder_build_commands.h +++ b/4coder_build_commands.h @@ -7,12 +7,6 @@ #if !defined(FCODER_BUILD_COMMANDS_H) #define FCODER_BUILD_COMMANDS_H -enum Get_Build_Directory_Result{ - BuildDir_None, - BuildDir_AtFile, - BuildDir_AtHot -}; - #endif // BOTTOM \ No newline at end of file diff --git a/4coder_clipboard.cpp b/4coder_clipboard.cpp index 77708c3f..66b17bf3 100644 --- a/4coder_clipboard.cpp +++ b/4coder_clipboard.cpp @@ -5,20 +5,18 @@ // TOP static b32 -post_buffer_range_to_clipboard(Application_Links *app, Partition *scratch, i32 clipboard_index, Buffer_ID buffer, i32 first, i32 one_past_last){ +post_buffer_range_to_clipboard(Application_Links *app, i32 clipboard_index, Buffer_ID buffer, i32 first, i32 one_past_last){ b32 success = false; i32 buffer_size = 0; buffer_get_size(app, buffer, &buffer_size); if (buffer != 0 && 0 <= first && first < one_past_last && one_past_last <= buffer_size){ - Temp_Memory temp = begin_temp_memory(scratch); - i32 size = one_past_last - first; - char *str = push_array(scratch, char, size); - if (str != 0){ - buffer_read_range(app, buffer, first, one_past_last, str); - clipboard_post(app, clipboard_index, str, size); + Scratch_Block scratch(app); + Range range = make_range(first, one_past_last); + String_Const_u8 string = scratch_read(app, scratch, buffer, range); + if (string.size > 0){ + clipboard_post(app, clipboard_index, string); success = true; } - end_temp_memory(temp); } return(success); } @@ -31,7 +29,7 @@ CUSTOM_DOC("Copy the text in the range from the cursor to the mark onto the clip Buffer_ID buffer = 0; view_get_buffer(app, view, AccessProtected, &buffer); Range range = get_view_range(app, view); - post_buffer_range_to_clipboard(app, &global_part, 0, buffer, range.min, range.max); + post_buffer_range_to_clipboard(app, 0, buffer, range.min, range.max); } CUSTOM_COMMAND_SIG(cut) @@ -42,48 +40,46 @@ CUSTOM_DOC("Cut the text in the range from the cursor to the mark onto the clipb Buffer_ID buffer = 0; view_get_buffer(app, view, AccessOpen, &buffer); Range range = get_view_range(app, view); - if (post_buffer_range_to_clipboard(app, &global_part, 0, buffer, range.min, range.max)){ - buffer_replace_range(app, buffer, range, make_lit_string("")); + if (post_buffer_range_to_clipboard(app, 0, buffer, range.min, range.max)){ + buffer_replace_range(app, buffer, range, string_u8_litexpr("")); } } CUSTOM_COMMAND_SIG(paste) CUSTOM_DOC("At the cursor, insert the text at the top of the clipboard.") { - i32 count = clipboard_count(app, 0); + i32 count = 0; + clipboard_count(app, 0, &count); if (count > 0){ View_ID view = 0; get_active_view(app, AccessOpen, &view); if_view_has_highlighted_range_delete_range(app, view); - Managed_Scope scope = view_get_managed_scope(app, view); + Managed_Scope scope = 0; + view_get_managed_scope(app, view, &scope); managed_variable_set(app, scope, view_next_rewrite_loc, RewritePaste); i32 paste_index = 0; managed_variable_set(app, scope, view_paste_index_loc, paste_index); - i32 len = clipboard_index(app, 0, paste_index, 0, 0); - char *str = 0; - if (len <= app->memory_size){ - str = (char*)app->memory; - } + Scratch_Block scratch(app); - if (str != 0){ - clipboard_index(app, 0, paste_index, str, len); - + String_Const_u8 string = {}; + clipboard_index(app, 0, paste_index, scratch, &string); + if (string.size > 0){ Buffer_ID buffer = 0; view_get_buffer(app, view, AccessOpen, &buffer); i32 pos = 0; view_get_cursor_pos(app, view, &pos); - buffer_replace_range(app, buffer, make_range(pos), make_string(str, len)); + buffer_replace_range(app, buffer, make_range(pos), string); view_set_mark(app, view, seek_pos(pos)); - view_set_cursor(app, view, seek_pos(pos + len), true); + view_set_cursor(app, view, seek_pos(pos + (i32)string.size), true); // TODO(allen): Send this to all views. Theme_Color paste = {}; paste.tag = Stag_Paste; get_theme_colors(app, &paste, 1); - view_post_fade(app, view, 0.667f, pos, pos + len, paste.color); + view_post_fade(app, view, 0.667f, pos, pos + (i32)string.size, paste.color); } } } @@ -91,11 +87,15 @@ CUSTOM_DOC("At the cursor, insert the text at the top of the clipboard.") CUSTOM_COMMAND_SIG(paste_next) CUSTOM_DOC("If the previous command was paste or paste_next, replaces the paste range with the next text down on the clipboard, otherwise operates as the paste command.") { - i32 count = clipboard_count(app, 0); + Scratch_Block scratch(app); + + i32 count = 0; + clipboard_count(app, 0, &count); if (count > 0){ View_ID view = 0; get_active_view(app, AccessOpen, &view); - Managed_Scope scope = view_get_managed_scope(app, view); + Managed_Scope scope = 0; + view_get_managed_scope(app, view, &scope); no_mark_snap_to_cursor(app, scope); u64 rewrite = 0; @@ -107,31 +107,24 @@ CUSTOM_DOC("If the previous command was paste or paste_next, replaces the paste i32 paste_index = (i32)prev_paste_index + 1; managed_variable_set(app, scope, view_paste_index_loc, paste_index); - i32 len = clipboard_index(app, 0, paste_index, 0, 0); - char *str = 0; + String_Const_u8 string = {}; + clipboard_index(app, 0, paste_index, scratch, &string); - if (len <= app->memory_size){ - str = (char*)app->memory; - } + Buffer_ID buffer = 0; + view_get_buffer(app, view, AccessOpen, &buffer); + + Range range = get_view_range(app, view); + i32 pos = range.min; + + buffer_replace_range(app, buffer, range, string); + view_set_cursor(app, view, seek_pos(pos + (i32)string.size), true); + + // TODO(allen): Send this to all views. + Theme_Color paste = {}; + paste.tag = Stag_Paste; + get_theme_colors(app, &paste, 1); + view_post_fade(app, view, 0.667f, pos, pos + (i32)string.size, paste.color); - if (str != 0){ - clipboard_index(app, 0, paste_index, str, len); - - Buffer_ID buffer = 0; - view_get_buffer(app, view, AccessOpen, &buffer); - - Range range = get_view_range(app, view); - i32 pos = range.min; - - buffer_replace_range(app, buffer, range, make_string(str, len)); - view_set_cursor(app, view, seek_pos(pos + len), true); - - // TODO(allen): Send this to all views. - Theme_Color paste = {}; - paste.tag = Stag_Paste; - get_theme_colors(app, &paste, 1); - view_post_fade(app, view, 0.667f, pos, pos + len, paste.color); - } } else{ exec_command(app, paste); diff --git a/4coder_combined_write_commands.cpp b/4coder_combined_write_commands.cpp index 015f6c27..644f8ace 100644 --- a/4coder_combined_write_commands.cpp +++ b/4coder_combined_write_commands.cpp @@ -5,15 +5,15 @@ // TOP static void -write_string(Application_Links *app, View_ID view, Buffer_ID buffer, String string){ +write_string(Application_Links *app, View_ID view, Buffer_ID buffer, String_Const_u8 string){ i32 pos = 0; view_get_cursor_pos(app, view, &pos); buffer_replace_range(app, buffer, make_range(pos), string); - view_set_cursor(app, view, seek_pos(pos + string.size), 1); + view_set_cursor(app, view, seek_pos(pos + (i32)string.size), 1); } static void -write_string(Application_Links *app, String string){ +write_string(Application_Links *app, String_Const_u8 string){ View_ID view = 0; get_active_view(app, AccessOpen, &view); Buffer_ID buffer = 0; @@ -23,23 +23,15 @@ write_string(Application_Links *app, String string){ static void write_named_comment_string(Application_Links *app, char *type_string){ - char space[512]; - String str = make_fixed_width_string(space); - - String name = global_config.user_name; + Scratch_Block scratch(app); + String_Const_u8 name = global_config.user_name; + String_Const_u8 str = {}; if (name.size > 0){ - append(&str, "// "); - append(&str, type_string); - append(&str, "("); - append(&str, name); - append(&str, "): "); + str = string_u8_pushf(scratch, "// %s(%.*s): ", type_string, string_expand(name)); } else{ - append(&str, "// "); - append(&str, type_string); - append(&str, ": "); + str = string_u8_pushf(scratch, "// %s: ", type_string); } - write_string(app, str); } @@ -51,9 +43,9 @@ long_braces(Application_Links *app, char *text, i32 size){ view_get_buffer(app, view, AccessOpen, &buffer); i32 pos = 0; view_get_cursor_pos(app, view, &pos); - buffer_replace_range(app, buffer, make_range(pos), make_string(text, size)); + buffer_replace_range(app, buffer, make_range(pos), SCu8(text, size)); view_set_cursor(app, view, seek_pos(pos + 2), true); - buffer_auto_indent(app, &global_part, buffer, pos, pos + size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); + buffer_auto_indent(app, buffer, pos, pos + size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); move_past_lead_whitespace(app, view, buffer); } @@ -84,7 +76,7 @@ CUSTOM_DOC("At the cursor, insert a '{' and '}break;' separated by a blank line. CUSTOM_COMMAND_SIG(if0_off) CUSTOM_DOC("Surround the range between the cursor and mark with an '#if 0' and an '#endif'") { - place_begin_and_end_on_own_lines(app, &global_part, "#if 0", "#endif"); + place_begin_and_end_on_own_lines(app, "#if 0", "#endif"); } CUSTOM_COMMAND_SIG(write_todo) @@ -108,13 +100,13 @@ CUSTOM_DOC("At the cursor, insert a '// NOTE' comment, includes user name if it CUSTOM_COMMAND_SIG(write_block) CUSTOM_DOC("At the cursor, insert a block comment.") { - write_string(app, make_lit_string("/* */")); + write_string(app, string_u8_litexpr("/* */")); } CUSTOM_COMMAND_SIG(write_zero_struct) CUSTOM_DOC("At the cursor, insert a ' = {};'.") { - write_string(app, make_lit_string(" = {};")); + write_string(app, string_u8_litexpr(" = {};")); } static i32 @@ -150,7 +142,7 @@ CUSTOM_DOC("Insert '//' at the beginning of the line after leading whitespace.") i32 pos = get_start_of_line_at_cursor(app, view, buffer); b32 alread_has_comment = c_line_comment_starts_at_position(app, buffer, pos); if (!alread_has_comment){ - buffer_replace_range(app, buffer, make_range(pos), make_lit_string("//")); + buffer_replace_range(app, buffer, make_range(pos), string_u8_litexpr("//")); } } @@ -164,7 +156,7 @@ CUSTOM_DOC("If present, delete '//' at the beginning of the line after leading w i32 pos = get_start_of_line_at_cursor(app, view, buffer); b32 alread_has_comment = c_line_comment_starts_at_position(app, buffer, pos); if (alread_has_comment){ - buffer_replace_range(app, buffer, make_range(pos, pos + 2), make_lit_string("")); + buffer_replace_range(app, buffer, make_range(pos, pos + 2), string_u8_litexpr("")); } } @@ -178,10 +170,10 @@ CUSTOM_DOC("Turns uncommented lines into commented lines and vice versa for comm i32 pos = get_start_of_line_at_cursor(app, view, buffer); b32 alread_has_comment = c_line_comment_starts_at_position(app, buffer, pos); if (alread_has_comment){ - buffer_replace_range(app, buffer, make_range(pos, pos + 2), make_lit_string("")); + buffer_replace_range(app, buffer, make_range(pos, pos + 2), string_u8_litexpr("")); } else{ - buffer_replace_range(app, buffer, make_range(pos), make_lit_string("//")); + buffer_replace_range(app, buffer, make_range(pos), string_u8_litexpr("//")); } } @@ -218,43 +210,43 @@ static Snippet default_snippets[] = { }; static void -activate_snippet(Application_Links *app, Partition *scratch, Heap *heap, View_ID view, struct Lister_State *state, String text_field, void *user_data, b32 activated_by_mouse){ +activate_snippet(Application_Links *app, Heap *heap, View_ID view, struct Lister_State *state, String_Const_u8 text_field, void *user_data, b32 activated_by_mouse){ i32 index = (i32)PtrAsInt(user_data); Snippet_Array snippets = *(Snippet_Array*)state->lister.data.user_data; if (0 <= index && index < snippets.count){ Snippet snippet = snippets.snippets[index]; - lister_default(app, scratch, heap, view, state, ListerActivation_Finished); + lister_default(app, heap, view, state, ListerActivation_Finished); Buffer_ID buffer = 0; view_get_buffer(app, view, AccessOpen, &buffer); i32 pos = 0; view_get_cursor_pos(app, view, &pos); - buffer_replace_range(app, buffer, make_range(pos), make_string_slowly(snippet.text)); + buffer_replace_range(app, buffer, make_range(pos), SCu8(snippet.text)); view_set_cursor(app, view, seek_pos(pos + snippet.cursor_offset), true); view_set_mark(app, view, seek_pos(pos + snippet.mark_offset)); } else{ - lister_default(app, scratch, heap, view, state, ListerActivation_Finished); + lister_default(app, heap, view, state, ListerActivation_Finished); } } static void snippet_lister__parameterized(Application_Links *app, Snippet_Array snippet_array){ - Partition *arena = &global_part; View_ID view = 0; get_active_view(app, AccessAll, &view); view_end_ui_mode(app, view); - Temp_Memory temp = begin_temp_memory(arena); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); i32 option_count = snippet_array.count; - Lister_Option *options = push_array(arena, Lister_Option, option_count); + Lister_Option *options = push_array(scratch, Lister_Option, option_count); for (i32 i = 0; i < snippet_array.count; i += 1){ - options[i].string = make_string_slowly(snippet_array.snippets[i].name); - options[i].status = make_string_slowly(snippet_array.snippets[i].text); + options[i].string = SCu8(snippet_array.snippets[i].name); + options[i].status = SCu8(snippet_array.snippets[i].text); options[i].user_data = IntAsPtr(i); } begin_integrated_lister__basic_list(app, "Snippet:", activate_snippet, &snippet_array, sizeof(snippet_array), options, option_count, 0, view); - end_temp_memory(temp); + end_temp(temp); } CUSTOM_COMMAND_SIG(snippet_lister) diff --git a/4coder_config.cpp b/4coder_config.cpp index d0e6a05c..c0ee9b3f 100644 --- a/4coder_config.cpp +++ b/4coder_config.cpp @@ -4,56 +4,40 @@ // TOP -static CString_Array -get_code_extensions(Extension_List *list){ - CString_Array array = {}; - array.strings = default_extensions; - array.count = ArrayCount(default_extensions); - if (list->count != 0){ - array.strings = list->exts; - array.count = list->count; - } - return(array); -} - -static void -parse_extension_line_to_extension_list(String str, Extension_List *list){ - i32 mode = 0; - i32 j = 0, k = 0; - for (i32 i = 0; i < str.size; ++i){ - switch (mode){ - case 0: - { - if (str.str[i] == '.'){ - mode = 1; - list->exts[k++] = &list->space[j]; - } - }break; - - case 1: - { - if (str.str[i] == '.'){ - list->space[j++] = 0; - list->exts[k++] = &list->space[j]; - } - else{ - list->space[j++] = str.str[i]; - } - }break; +static String_Const_u8_Array +parse_extension_line_to_extension_list(Arena *arena, String_Const_u8 str){ + i32 count = 0; + for (umem i = 0; i < str.size; i += 1){ + if (str.str[i] == '.'){ + count += 1; } } - list->space[j++] = 0; - list->count = k; + + String_Const_u8_Array array = {}; + array.count = count; + array.strings = push_array(arena, String_Const_u8, count); + + push_align(arena, 1); + str = string_skip(str, string_find_first(str, '.') + 1); + for (i32 i = 0; i < count; i += 1){ + umem next_period = string_find_first(str, '.'); + String_Const_u8 extension = string_prefix(str, next_period); + str = string_skip(str, next_period + 1); + array.strings[i] = string_copy(arena, extension); + } + push_align(arena, 8); + + return(array); } //////////////////////////////// static Error_Location -get_error_location(char *base, char *pos){ +get_error_location(u8 *base, u8 *pos){ Error_Location location = {}; location.line_number = 1; location.column_number = 1; - for (char *ptr = base; + for (u8 *ptr = base; ptr < pos; ptr += 1){ if (*ptr == '\n'){ @@ -67,27 +51,19 @@ get_error_location(char *base, char *pos){ return(location); } -static String -config_stringize_errors(Partition *arena, Config *parsed){ - String result = {}; +static String_Const_u8 +config_stringize_errors(Arena *arena, Config *parsed){ + String_Const_u8 result = {}; if (parsed->errors.first != 0){ - result.str = push_array(arena, char, 0); - result.memory_size = part_remaining(arena); + List_String_Const_u8 list = {}; for (Config_Error *error = parsed->errors.first; error != 0; error = error->next){ Error_Location location = get_error_location(parsed->data.str, error->pos); - append(&result, error->file_name); - append(&result, ":"); - append_int_to_str(&result, location.line_number); - append(&result, ":"); - append_int_to_str(&result, location.column_number); - append(&result, ": "); - append(&result, error->text); - append(&result, "\n"); + string_list_pushf(arena, &list, "%.*s:%d:%d: %.*s\n", + string_expand(error->file_name), location.line_number, location.column_number, string_expand(error->text)); } - result.memory_size = result.size; - push_array(arena, char, result.size); + result = string_list_flatten(arena, list); } return(result); } @@ -103,7 +79,7 @@ config_parser__advance_to_next(Config_Parser *ctx){ } static Config_Parser -make_config_parser(Partition *arena, String file_name, String data, Cpp_Token_Array array){ +make_config_parser(Arena *arena, String_Const_u8 file_name, String_Const_u8 data, Cpp_Token_Array array){ Config_Parser ctx = {}; ctx.start = array.tokens; ctx.token = ctx.start - 1; @@ -139,11 +115,11 @@ config_parser__recognize_token_category(Config_Parser *ctx, Cpp_Token_Category c return(result); } -static String +static String_Const_u8 config_parser__get_lexeme(Config_Parser *ctx){ - String lexeme = {}; + String_Const_u8 lexeme = {}; if (ctx->start <= ctx->token && ctx->token < ctx->end){ - lexeme = make_string(ctx->data.str + ctx->token->start, ctx->token->size); + lexeme = SCu8(ctx->data.str + ctx->token->start, ctx->token->size); } return(lexeme); } @@ -151,32 +127,35 @@ config_parser__get_lexeme(Config_Parser *ctx){ static Config_Integer config_parser__get_int(Config_Parser *ctx){ Config_Integer config_integer = {}; - String str = config_parser__get_lexeme(ctx); - if (match(substr(str, 0, 2), "0x")){ + String_Const_u8 str = config_parser__get_lexeme(ctx); + if (string_match(string_prefix(str, 2), string_u8_litexpr("0x"))){ config_integer.is_signed = false; - config_integer.uinteger = hexstr_to_int(substr_tail(str, 2)); + config_integer.uinteger = (u32)(string_to_integer(string_skip(str, 2), 16)); } else{ + b32 is_negative = (string_get_character(str, 0) == '-'); + if (is_negative){ + str = string_skip(str, 1); + } config_integer.is_signed = true; - config_integer.integer = str_to_int(str); + config_integer.integer = (i32)(string_to_integer(str, 10)); + if (is_negative){ + config_integer.integer *= -1; + } } return(config_integer); } static b32 config_parser__get_boolean(Config_Parser *ctx){ - String str = config_parser__get_lexeme(ctx); - return(match(str, "true")); + String_Const_u8 str = config_parser__get_lexeme(ctx); + return(string_match(str, string_u8_litexpr("true"))); } static b32 -config_parser__recognize_text(Config_Parser *ctx, String text){ - b32 result = false; - String lexeme = config_parser__get_lexeme(ctx); - if (lexeme.str != 0 && match(lexeme, text)){ - result = true; - } - return(result); +config_parser__recognize_text(Config_Parser *ctx, String_Const_u8 text){ + String_Const_u8 lexeme = config_parser__get_lexeme(ctx); + return(lexeme.str != 0 && string_match(lexeme, text)); } static b32 @@ -189,7 +168,7 @@ config_parser__match_token(Config_Parser *ctx, Cpp_Token_Type type){ } static b32 -config_parser__match_text(Config_Parser *ctx, String text){ +config_parser__match_text(Config_Parser *ctx, String_Const_u8 text){ b32 result = config_parser__recognize_text(ctx, text); if (result){ config_parser__advance_to_next(ctx); @@ -197,6 +176,8 @@ config_parser__match_text(Config_Parser *ctx, String text){ return(result); } +#define config_parser__match_text_lit(c,s) config_parser__match_text((c), string_u8_litexpr(s)) + static Config *config_parser__config (Config_Parser *ctx); static i32 *config_parser__version (Config_Parser *ctx); static Config_Assignment *config_parser__assignment(Config_Parser *ctx); @@ -206,52 +187,35 @@ static Config_Compound *config_parser__compound (Config_Parser *ctx); static Config_Compound_Element *config_parser__element (Config_Parser *ctx); static Config* -text_data_and_token_array_to_parse_data(Partition *arena, String file_name, String data, Cpp_Token_Array array){ - Temp_Memory restore_point = begin_temp_memory(arena); +text_data_and_token_array_to_parse_data(Arena *arena, String_Const_u8 file_name, String_Const_u8 data, Cpp_Token_Array array){ + Temp_Memory restore_point = begin_temp(arena); Config_Parser ctx = make_config_parser(arena, file_name, data, array); Config *config = config_parser__config(&ctx); if (config == 0){ - end_temp_memory(restore_point); + end_temp(restore_point); } return(config); } // TODO(allen): Move to string library -static String -config_begin_string(Partition *arena){ - String str; - str.str = push_array(arena, char, 0); - str.size = 0; - str.memory_size = arena->max - arena->pos; - return(str); -} - -static void -config_end_string(Partition *arena, String *str){ - str->memory_size = str->size; - push_array(arena, char, str->size); -} - static Config_Error* -config_error_push(Partition *arena, Config_Error_List *list, String file_name, char *pos, char *error_text){ +config_error_push(Arena *arena, Config_Error_List *list, String_Const_u8 file_name, u8 *pos, char *error_text){ Config_Error *error = push_array(arena, Config_Error, 1); zdll_push_back(list->first, list->last, error); list->count += 1; error->file_name = file_name; error->pos = pos; - error->text = config_begin_string(arena); - append(&error->text, error_text); - config_end_string(arena, &error->text); + error->text = string_copy(arena, SCu8(error_text)); return(error); } -static char* +static u8* config_parser__get_pos(Config_Parser *ctx){ return(ctx->data.str + ctx->token->start); } static void -config_parser__log_error_pos(Config_Parser *ctx, char *pos, char *error_text){ +config_parser__log_error_pos(Config_Parser *ctx, u8 *pos, char *error_text){ config_error_push(ctx->arena, &ctx->errors, ctx->file_name, pos, error_text); } @@ -302,7 +266,7 @@ config_parser__recover_parse(Config_Parser *ctx){ static i32* config_parser__version(Config_Parser *ctx){ - require(config_parser__match_text(ctx, make_lit_string("version"))); + require(config_parser__match_text_lit(ctx, "version")); if (!config_parser__match_token(ctx, CPP_TOKEN_PARENTHESE_OPEN)){ config_parser__log_error(ctx, "expected token '(' for version specifier: 'version(#)'"); @@ -338,7 +302,7 @@ config_parser__version(Config_Parser *ctx){ static Config_Assignment* config_parser__assignment(Config_Parser *ctx){ - char *pos = config_parser__get_pos(ctx); + u8 *pos = config_parser__get_pos(ctx); Config_LValue *l = config_parser__lvalue(ctx); if (l == 0){ @@ -371,8 +335,7 @@ config_parser__assignment(Config_Parser *ctx){ return(0); } - Config_Assignment *assignment = push_array(ctx->arena, Config_Assignment, 1); - memset(assignment, 0, sizeof(*assignment)); + Config_Assignment *assignment = push_array_zero(ctx->arena, Config_Assignment, 1); assignment->pos = pos; assignment->l = l; assignment->r = r; @@ -382,7 +345,7 @@ config_parser__assignment(Config_Parser *ctx){ static Config_LValue* config_parser__lvalue(Config_Parser *ctx){ require(config_parser__recognize_token(ctx, CPP_TOKEN_IDENTIFIER)); - String identifier = config_parser__get_lexeme(ctx); + String_Const_u8 identifier = config_parser__get_lexeme(ctx); config_parser__advance_to_next(ctx); i32 index = 0; @@ -394,8 +357,7 @@ config_parser__lvalue(Config_Parser *ctx){ require(config_parser__match_token(ctx, CPP_TOKEN_BRACKET_CLOSE)); } - Config_LValue *lvalue = push_array(ctx->arena, Config_LValue, 1); - memset(lvalue, 0, sizeof(*lvalue)); + Config_LValue *lvalue = push_array_zero(ctx->arena, Config_LValue, 1); lvalue->identifier = identifier; lvalue->index = index; return(lvalue); @@ -403,39 +365,33 @@ config_parser__lvalue(Config_Parser *ctx){ static Config_RValue* config_parser__rvalue(Config_Parser *ctx){ + Config_RValue *rvalue = 0; if (config_parser__recognize_token(ctx, CPP_TOKEN_IDENTIFIER)){ Config_LValue *l = config_parser__lvalue(ctx); require(l != 0); - Config_RValue *rvalue = push_array(ctx->arena, Config_RValue, 1); - memset(rvalue, 0, sizeof(*rvalue)); + rvalue = push_array_zero(ctx->arena, Config_RValue, 1); rvalue->type = ConfigRValueType_LValue; rvalue->lvalue = l; - return(rvalue); } else if (config_parser__recognize_token(ctx, CPP_TOKEN_BRACE_OPEN)){ config_parser__advance_to_next(ctx); Config_Compound *compound = config_parser__compound(ctx); require(compound != 0); - Config_RValue *rvalue = push_array(ctx->arena, Config_RValue, 1); - memset(rvalue, 0, sizeof(*rvalue)); + rvalue = push_array_zero(ctx->arena, Config_RValue, 1); rvalue->type = ConfigRValueType_Compound; rvalue->compound = compound; - return(rvalue); } else if (config_parser__recognize_token_category(ctx, CPP_TOKEN_CAT_BOOLEAN_CONSTANT)){ b32 b = config_parser__get_boolean(ctx); config_parser__advance_to_next(ctx); - Config_RValue *rvalue = push_array(ctx->arena, Config_RValue, 1); - memset(rvalue, 0, sizeof(*rvalue)); + rvalue = push_array_zero(ctx->arena, Config_RValue, 1); rvalue->type = ConfigRValueType_Boolean; rvalue->boolean = b; - return(rvalue); } else if (config_parser__recognize_token(ctx, CPP_TOKEN_INTEGER_CONSTANT)){ Config_Integer value = config_parser__get_int(ctx); config_parser__advance_to_next(ctx); - Config_RValue *rvalue = push_array(ctx->arena, Config_RValue, 1); - memset(rvalue, 0, sizeof(*rvalue)); + rvalue = push_array_zero(ctx->arena, Config_RValue, 1); rvalue->type = ConfigRValueType_Integer; if (value.is_signed){ rvalue->integer = value.integer; @@ -443,35 +399,26 @@ config_parser__rvalue(Config_Parser *ctx){ else{ rvalue->uinteger = value.uinteger; } - return(rvalue); } else if (config_parser__recognize_token(ctx, CPP_TOKEN_STRING_CONSTANT)){ - String s = config_parser__get_lexeme(ctx); + String_Const_u8 s = config_parser__get_lexeme(ctx); config_parser__advance_to_next(ctx); - char *space = push_array(ctx->arena, char, s.size + 1); - push_align(ctx->arena, 8); - s = substr(s, 1, s.size - 2); - string_interpret_escapes(s, space); - Config_RValue *rvalue = push_array(ctx->arena, Config_RValue, 1); - memset(rvalue, 0, sizeof(*rvalue)); + s = string_chop(string_skip(s, 1), 1); + String_Const_u8 interpreted = string_interpret_escapes(ctx->arena, s); + rvalue = push_array_zero(ctx->arena, Config_RValue, 1); rvalue->type = ConfigRValueType_String; - rvalue->string = make_string_slowly(space); - return(rvalue); + rvalue->string = interpreted; } else if (config_parser__recognize_token(ctx, CPP_TOKEN_CHARACTER_CONSTANT)){ - String s = config_parser__get_lexeme(ctx); + String_Const_u8 s = config_parser__get_lexeme(ctx); config_parser__advance_to_next(ctx); - char *space = push_array(ctx->arena, char, s.size + 1); - push_align(ctx->arena, 8); - s = substr(s, 1, s.size - 2); - string_interpret_escapes(s, space); - Config_RValue *rvalue = push_array(ctx->arena, Config_RValue, 1); - memset(rvalue, 0, sizeof(*rvalue)); + s = string_chop(string_skip(s, 1), 1); + String_Const_u8 interpreted = string_interpret_escapes(ctx->arena, s); + rvalue = push_array_zero(ctx->arena, Config_RValue, 1); rvalue->type = ConfigRValueType_Character; - rvalue->character = space[0]; - return(rvalue); + rvalue->character = string_get_character(interpreted, 0); } - return(0); + return(rvalue); } static void @@ -555,20 +502,20 @@ config_parser__element(Config_Parser *ctx){ //////////////////////////////// static Config_Error* -config_add_error(Partition *arena, Config *config, char *pos, char *error_text){ +config_add_error(Arena *arena, Config *config, u8 *pos, char *error_text){ return(config_error_push(arena, &config->errors, config->file_name, pos, error_text)); } //////////////////////////////// static Config_Assignment* -config_lookup_assignment(Config *config, String var_name, i32 subscript){ - Config_Assignment *assignment; +config_lookup_assignment(Config *config, String_Const_u8 var_name, i32 subscript){ + Config_Assignment *assignment = 0; for (assignment = config->first; assignment != 0; assignment = assignment->next){ Config_LValue *l = assignment->l; - if (l != 0 && match(l->identifier, var_name) && l->index == subscript){ + if (l != 0 && string_match(l->identifier, var_name) && l->index == subscript){ break; } } @@ -576,7 +523,7 @@ config_lookup_assignment(Config *config, String var_name, i32 subscript){ } static Config_Get_Result -config_var(Config *config, String var_name, i32 subscript); +config_var(Config *config, String_Const_u8 var_name, i32 subscript); static Config_Get_Result config_evaluate_rvalue(Config *config, Config_Assignment *assignment, Config_RValue *r){ @@ -624,7 +571,7 @@ config_evaluate_rvalue(Config *config, Config_Assignment *assignment, Config_RVa } static Config_Get_Result -config_var(Config *config, String var_name, i32 subscript){ +config_var(Config *config, String_Const_u8 var_name, i32 subscript){ Config_Get_Result result = {}; Config_Assignment *assignment = config_lookup_assignment(config, var_name, subscript); if (assignment != 0){ @@ -634,7 +581,7 @@ config_var(Config *config, String var_name, i32 subscript){ } static Config_Get_Result -config_compound_member(Config *config, Config_Compound *compound, String var_name, i32 index){ +config_compound_member(Config *config, Config_Compound *compound, String_Const_u8 var_name, i32 index){ Config_Get_Result result = {}; i32 implicit_index = 0; b32 implicit_index_is_valid = true; @@ -653,7 +600,7 @@ config_compound_member(Config *config, Config_Compound *compound, String var_nam case ConfigLayoutType_Identifier: { implicit_index_is_valid = false; - if (match(element->l.identifier, var_name)){ + if (string_match(element->l.identifier, var_name)){ element_matches_query = true; } }break; @@ -683,29 +630,25 @@ static i32 typed_array_get_count(Config *parsed, Config_Compound *compound, Config_RValue_Type type); static Config_Get_Result_List -typed_array_reference_list(Partition *arena, Config *parsed, Config_Compound *compound, Config_RValue_Type type); +typed_array_reference_list(Arena *arena, Config *parsed, Config_Compound *compound, Config_RValue_Type type); #define config_fixed_string_var(c,v,s,o,a) config_placed_string_var((c),(v),(s),(o),(a),sizeof(a)) //////////////////////////////// static b32 -config_has_var(Config *config, String var_name, i32 subscript){ +config_has_var(Config *config, String_Const_u8 var_name, i32 subscript){ Config_Get_Result result = config_var(config, var_name, subscript); - b32 success = result.success && result.type == ConfigRValueType_NoType; - return(success); + return(result.success && result.type == ConfigRValueType_NoType); } static b32 config_has_var(Config *config, char *var_name, i32 subscript){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_var(config, var_name_str, subscript); - b32 success = result.success && result.type == ConfigRValueType_NoType; - return(success); + return(config_has_var(config, SCu8(var_name), subscript)); } static b32 -config_bool_var(Config *config, String var_name, i32 subscript, b32* var_out){ +config_bool_var(Config *config, String_Const_u8 var_name, i32 subscript, b32* var_out){ Config_Get_Result result = config_var(config, var_name, subscript); b32 success = result.success && result.type == ConfigRValueType_Boolean; if (success){ @@ -716,17 +659,11 @@ config_bool_var(Config *config, String var_name, i32 subscript, b32* var_out){ static b32 config_bool_var(Config *config, char *var_name, i32 subscript, b32* var_out){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_var(config, var_name_str, subscript); - b32 success = result.success && result.type == ConfigRValueType_Boolean; - if (success){ - *var_out = result.boolean; - } - return(success); + return(config_bool_var(config, SCu8(var_name), subscript, var_out)); } static b32 -config_int_var(Config *config, String var_name, i32 subscript, i32* var_out){ +config_int_var(Config *config, String_Const_u8 var_name, i32 subscript, i32* var_out){ Config_Get_Result result = config_var(config, var_name, subscript); b32 success = result.success && result.type == ConfigRValueType_Integer; if (success){ @@ -737,17 +674,11 @@ config_int_var(Config *config, String var_name, i32 subscript, i32* var_out){ static b32 config_int_var(Config *config, char *var_name, i32 subscript, i32* var_out){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_var(config, var_name_str, subscript); - b32 success = result.success && result.type == ConfigRValueType_Integer; - if (success){ - *var_out = result.integer; - } - return(success); + return(config_int_var(config, SCu8(var_name), subscript, var_out)); } static b32 -config_uint_var(Config *config, String var_name, i32 subscript, u32* var_out){ +config_uint_var(Config *config, String_Const_u8 var_name, i32 subscript, u32* var_out){ Config_Get_Result result = config_var(config, var_name, subscript); b32 success = result.success && result.type == ConfigRValueType_Integer; if (success){ @@ -758,17 +689,11 @@ config_uint_var(Config *config, String var_name, i32 subscript, u32* var_out){ static b32 config_uint_var(Config *config, char *var_name, i32 subscript, u32* var_out){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_var(config, var_name_str, subscript); - b32 success = result.success && result.type == ConfigRValueType_Integer; - if (success){ - *var_out = result.uinteger; - } - return(success); + return(config_uint_var(config, SCu8(var_name), subscript, var_out)); } static b32 -config_string_var(Config *config, String var_name, i32 subscript, String* var_out){ +config_string_var(Config *config, String_Const_u8 var_name, i32 subscript, String_Const_u8* var_out){ Config_Get_Result result = config_var(config, var_name, subscript); b32 success = result.success && result.type == ConfigRValueType_String; if (success){ @@ -778,49 +703,30 @@ config_string_var(Config *config, String var_name, i32 subscript, String* var_ou } static b32 -config_string_var(Config *config, char *var_name, i32 subscript, String* var_out){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_var(config, var_name_str, subscript); - b32 success = result.success && result.type == ConfigRValueType_String; - if (success){ - *var_out = result.string; - } - return(success); +config_string_var(Config *config, char *var_name, i32 subscript, String_Const_u8* var_out){ + return(config_string_var(config, SCu8(var_name), subscript, var_out)); } static b32 -config_placed_string_var(Config *config, String var_name, i32 subscript, String* var_out, char *space, i32 space_size){ +config_placed_string_var(Config *config, String_Const_u8 var_name, i32 subscript, String_Const_u8* var_out, u8 *space, umem space_size){ Config_Get_Result result = config_var(config, var_name, subscript); - b32 success = result.success && result.type == ConfigRValueType_String; + b32 success = (result.success && result.type == ConfigRValueType_String); if (success){ - *var_out = result.string; - } - if (success){ - String str = *var_out; - *var_out = make_string_cap(space, 0, space_size); - copy(var_out, str); + umem size = result.string.size; + size = clamp_top(size, space_size); + block_copy(space, result.string.str, size); + *var_out = SCu8(space, size); } return(success); } static b32 -config_placed_string_var(Config *config, char *var_name, i32 subscript, String* var_out, char *space, i32 space_size){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_var(config, var_name_str, subscript); - b32 success = result.success && result.type == ConfigRValueType_String; - if (success){ - *var_out = result.string; - } - if (success){ - String str = *var_out; - *var_out = make_string_cap(space, 0, space_size); - copy(var_out, str); - } - return(success); +config_placed_string_var(Config *config, char *var_name, i32 subscript, String_Const_u8* var_out, u8 *space, umem space_size){ + return(config_placed_string_var(config, SCu8(var_name), subscript, var_out, space, space_size)); } static b32 -config_char_var(Config *config, String var_name, i32 subscript, char* var_out){ +config_char_var(Config *config, String_Const_u8 var_name, i32 subscript, char* var_out){ Config_Get_Result result = config_var(config, var_name, subscript); b32 success = result.success && result.type == ConfigRValueType_Character; if (success){ @@ -831,17 +737,11 @@ config_char_var(Config *config, String var_name, i32 subscript, char* var_out){ static b32 config_char_var(Config *config, char *var_name, i32 subscript, char* var_out){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_var(config, var_name_str, subscript); - b32 success = result.success && result.type == ConfigRValueType_Character; - if (success){ - *var_out = result.character; - } - return(success); + return(config_char_var(config, SCu8(var_name), subscript, var_out)); } static b32 -config_compound_var(Config *config, String var_name, i32 subscript, Config_Compound** var_out){ +config_compound_var(Config *config, String_Const_u8 var_name, i32 subscript, Config_Compound** var_out){ Config_Get_Result result = config_var(config, var_name, subscript); b32 success = result.success && result.type == ConfigRValueType_Compound; if (success){ @@ -852,18 +752,12 @@ config_compound_var(Config *config, String var_name, i32 subscript, Config_Compo static b32 config_compound_var(Config *config, char *var_name, i32 subscript, Config_Compound** var_out){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_var(config, var_name_str, subscript); - b32 success = result.success && result.type == ConfigRValueType_Compound; - if (success){ - *var_out = result.compound; - } - return(success); + return(config_compound_var(config, SCu8(var_name), subscript, var_out)); } static b32 config_compound_has_member(Config *config, Config_Compound *compound, - String var_name, i32 index){ + String_Const_u8 var_name, i32 index){ Config_Get_Result result = config_compound_member(config, compound, var_name, index); b32 success = result.success && result.type == ConfigRValueType_NoType; return(success); @@ -872,15 +766,12 @@ config_compound_has_member(Config *config, Config_Compound *compound, static b32 config_compound_has_member(Config *config, Config_Compound *compound, char *var_name, i32 index){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_compound_member(config, compound, var_name_str, index); - b32 success = result.success && result.type == ConfigRValueType_NoType; - return(success); + return(config_compound_has_member(config, compound, SCu8(var_name), index)); } static b32 config_compound_bool_member(Config *config, Config_Compound *compound, - String var_name, i32 index, b32* var_out){ + String_Const_u8 var_name, i32 index, b32* var_out){ Config_Get_Result result = config_compound_member(config, compound, var_name, index); b32 success = result.success && result.type == ConfigRValueType_Boolean; if (success){ @@ -892,18 +783,12 @@ config_compound_bool_member(Config *config, Config_Compound *compound, static b32 config_compound_bool_member(Config *config, Config_Compound *compound, char *var_name, i32 index, b32* var_out){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_compound_member(config, compound, var_name_str, index); - b32 success = result.success && result.type == ConfigRValueType_Boolean; - if (success){ - *var_out = result.boolean; - } - return(success); + return(config_compound_bool_member(config, compound, SCu8(var_name), index, var_out)); } static b32 config_compound_int_member(Config *config, Config_Compound *compound, - String var_name, i32 index, i32* var_out){ + String_Const_u8 var_name, i32 index, i32* var_out){ Config_Get_Result result = config_compound_member(config, compound, var_name, index); b32 success = result.success && result.type == ConfigRValueType_Integer; if (success){ @@ -915,18 +800,12 @@ config_compound_int_member(Config *config, Config_Compound *compound, static b32 config_compound_int_member(Config *config, Config_Compound *compound, char *var_name, i32 index, i32* var_out){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_compound_member(config, compound, var_name_str, index); - b32 success = result.success && result.type == ConfigRValueType_Integer; - if (success){ - *var_out = result.integer; - } - return(success); + return(config_compound_int_member(config, compound, SCu8(var_name), index, var_out)); } static b32 config_compound_uint_member(Config *config, Config_Compound *compound, - String var_name, i32 index, u32* var_out){ + String_Const_u8 var_name, i32 index, u32* var_out){ Config_Get_Result result = config_compound_member(config, compound, var_name, index); b32 success = result.success && result.type == ConfigRValueType_Integer; if (success){ @@ -938,20 +817,14 @@ config_compound_uint_member(Config *config, Config_Compound *compound, static b32 config_compound_uint_member(Config *config, Config_Compound *compound, char *var_name, i32 index, u32* var_out){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_compound_member(config, compound, var_name_str, index); - b32 success = result.success && result.type == ConfigRValueType_Integer; - if (success){ - *var_out = result.uinteger; - } - return(success); + return(config_compound_uint_member(config, compound, SCu8(var_name), index, var_out)); } static b32 config_compound_string_member(Config *config, Config_Compound *compound, - String var_name, i32 index, String* var_out){ + String_Const_u8 var_name, i32 index, String_Const_u8* var_out){ Config_Get_Result result = config_compound_member(config, compound, var_name, index); - b32 success = result.success && result.type == ConfigRValueType_String; + b32 success = (result.success && result.type == ConfigRValueType_String); if (success){ *var_out = result.string; } @@ -960,52 +833,33 @@ config_compound_string_member(Config *config, Config_Compound *compound, static b32 config_compound_string_member(Config *config, Config_Compound *compound, - char *var_name, i32 index, String* var_out){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_compound_member(config, compound, var_name_str, index); - b32 success = result.success && result.type == ConfigRValueType_String; - if (success){ - *var_out = result.string; - } - return(success); + char *var_name, i32 index, String_Const_u8* var_out){ + return(config_compound_string_member(config, compound, SCu8(var_name), index, var_out)); } static b32 config_compound_placed_string_member(Config *config, Config_Compound *compound, - String var_name, i32 index, String* var_out, char *space, i32 space_size){ + String_Const_u8 var_name, i32 index, String_Const_u8* var_out, u8 *space, umem space_size){ Config_Get_Result result = config_compound_member(config, compound, var_name, index); - b32 success = result.success && result.type == ConfigRValueType_String; + b32 success = (result.success && result.type == ConfigRValueType_String); if (success){ - *var_out = result.string; - } - if (success){ - String str = *var_out; - *var_out = make_string_cap(space, 0, space_size); - copy(var_out, str); + umem size = result.string.size; + size = clamp_top(size, space_size); + block_copy(space, result.string.str, size); + *var_out = SCu8(space, size); } return(success); } static b32 config_compound_placed_string_member(Config *config, Config_Compound *compound, - char *var_name, i32 index, String* var_out, char *space, i32 space_size){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_compound_member(config, compound, var_name_str, index); - b32 success = result.success && result.type == ConfigRValueType_String; - if (success){ - *var_out = result.string; - } - if (success){ - String str = *var_out; - *var_out = make_string_cap(space, 0, space_size); - copy(var_out, str); - } - return(success); + char *var_name, i32 index, String_Const_u8* var_out, u8 *space, umem space_size){ + return(config_compound_placed_string_member(config, compound, SCu8(var_name), index, var_out, space, space_size)); } static b32 config_compound_char_member(Config *config, Config_Compound *compound, - String var_name, i32 index, char* var_out){ + String_Const_u8 var_name, i32 index, char* var_out){ Config_Get_Result result = config_compound_member(config, compound, var_name, index); b32 success = result.success && result.type == ConfigRValueType_Character; if (success){ @@ -1017,18 +871,12 @@ config_compound_char_member(Config *config, Config_Compound *compound, static b32 config_compound_char_member(Config *config, Config_Compound *compound, char *var_name, i32 index, char* var_out){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_compound_member(config, compound, var_name_str, index); - b32 success = result.success && result.type == ConfigRValueType_Character; - if (success){ - *var_out = result.character; - } - return(success); + return(config_compound_char_member(config, compound, SCu8(var_name), index, var_out)); } static b32 config_compound_compound_member(Config *config, Config_Compound *compound, - String var_name, i32 index, Config_Compound** var_out){ + String_Const_u8 var_name, i32 index, Config_Compound** var_out){ Config_Get_Result result = config_compound_member(config, compound, var_name, index); b32 success = result.success && result.type == ConfigRValueType_Compound; if (success){ @@ -1040,13 +888,7 @@ config_compound_compound_member(Config *config, Config_Compound *compound, static b32 config_compound_compound_member(Config *config, Config_Compound *compound, char *var_name, i32 index, Config_Compound** var_out){ - String var_name_str = make_string_slowly(var_name); - Config_Get_Result result = config_compound_member(config, compound, var_name_str, index); - b32 success = result.success && result.type == ConfigRValueType_Compound; - if (success){ - *var_out = result.compound; - } - return(success); + return(config_compound_compound_member(config, compound, SCu8(var_name), index, var_out)); } static Iteration_Step_Result @@ -1086,7 +928,7 @@ typed_uint_array_iteration_step(Config *config, Config_Compound *compound, i32 i } static Iteration_Step_Result -typed_string_array_iteration_step(Config *config, Config_Compound *compound, i32 index, String* var_out){ +typed_string_array_iteration_step(Config *config, Config_Compound *compound, i32 index, String_Const_u8* var_out){ Config_Iteration_Step_Result result = typed_array_iteration_step(config, compound, ConfigRValueType_String, index); b32 success = (result.step == Iteration_Good); if (success){ @@ -1096,17 +938,14 @@ typed_string_array_iteration_step(Config *config, Config_Compound *compound, i32 } static Iteration_Step_Result -typed_placed_string_array_iteration_step(Config *config, Config_Compound *compound, i32 index, String* var_out - , char *space, i32 space_size){ +typed_placed_string_array_iteration_step(Config *config, Config_Compound *compound, i32 index, String_Const_u8* var_out, u8 *space, umem space_size){ Config_Iteration_Step_Result result = typed_array_iteration_step(config, compound, ConfigRValueType_String, index); b32 success = (result.step == Iteration_Good); if (success){ - *var_out = result.get.string; - } - if (success){ - String str = *var_out; - *var_out = make_string_cap(space, 0, space_size); - copy(var_out, str); + umem size = result.get.string.size; + size = clamp_top(size, space_size); + block_copy(space, result.get.string.str, size); + *var_out = SCu8(space, size); } return(result.step); } @@ -1174,43 +1013,43 @@ typed_no_type_array_get_count(Config *config, Config_Compound *compound){ } static Config_Get_Result_List -typed_bool_array_reference_list(Partition *arena, Config *config, Config_Compound *compound){ +typed_bool_array_reference_list(Arena *arena, Config *config, Config_Compound *compound){ Config_Get_Result_List list = typed_array_reference_list(arena, config, compound, ConfigRValueType_Boolean); return(list); } static Config_Get_Result_List -typed_int_array_reference_list(Partition *arena, Config *config, Config_Compound *compound){ +typed_int_array_reference_list(Arena *arena, Config *config, Config_Compound *compound){ Config_Get_Result_List list = typed_array_reference_list(arena, config, compound, ConfigRValueType_Integer); return(list); } static Config_Get_Result_List -typed_float_array_reference_list(Partition *arena, Config *config, Config_Compound *compound){ +typed_float_array_reference_list(Arena *arena, Config *config, Config_Compound *compound){ Config_Get_Result_List list = typed_array_reference_list(arena, config, compound, ConfigRValueType_Float); return(list); } static Config_Get_Result_List -typed_string_array_reference_list(Partition *arena, Config *config, Config_Compound *compound){ +typed_string_array_reference_list(Arena *arena, Config *config, Config_Compound *compound){ Config_Get_Result_List list = typed_array_reference_list(arena, config, compound, ConfigRValueType_String); return(list); } static Config_Get_Result_List -typed_character_array_reference_list(Partition *arena, Config *config, Config_Compound *compound){ +typed_character_array_reference_list(Arena *arena, Config *config, Config_Compound *compound){ Config_Get_Result_List list = typed_array_reference_list(arena, config, compound, ConfigRValueType_Character); return(list); } static Config_Get_Result_List -typed_compound_array_reference_list(Partition *arena, Config *config, Config_Compound *compound){ +typed_compound_array_reference_list(Arena *arena, Config *config, Config_Compound *compound){ Config_Get_Result_List list = typed_array_reference_list(arena, config, compound, ConfigRValueType_Compound); return(list); } static Config_Get_Result_List -typed_no_type_array_reference_list(Partition *arena, Config *config, Config_Compound *compound){ +typed_no_type_array_reference_list(Arena *arena, Config *config, Config_Compound *compound){ Config_Get_Result_List list = typed_array_reference_list(arena, config, compound, ConfigRValueType_NoType); return(list); } @@ -1221,7 +1060,7 @@ static Config_Iteration_Step_Result typed_array_iteration_step(Config *parsed, Config_Compound *compound, Config_RValue_Type type, i32 index){ Config_Iteration_Step_Result result = {}; result.step = Iteration_Quit; - Config_Get_Result get_result = config_compound_member(parsed, compound, make_lit_string("~"), index); + Config_Get_Result get_result = config_compound_member(parsed, compound, string_u8_litexpr("~"), index); if (get_result.success){ if (get_result.type == type || type == ConfigRValueType_NoType){ result.step = Iteration_Good; @@ -1251,7 +1090,7 @@ typed_array_get_count(Config *parsed, Config_Compound *compound, Config_RValue_T } static Config_Get_Result_List -typed_array_reference_list(Partition *arena, Config *parsed, Config_Compound *compound, Config_RValue_Type type){ +typed_array_reference_list(Arena *arena, Config *parsed, Config_Compound *compound, Config_RValue_Type type){ Config_Get_Result_List list = {}; for (i32 i = 0;; ++i){ Config_Iteration_Step_Result result = typed_array_iteration_step(parsed, compound, type, i); @@ -1272,71 +1111,70 @@ typed_array_reference_list(Partition *arena, Config *parsed, Config_Compound *co //////////////////////////////// static void -change_mapping(Application_Links *app, String mapping){ +change_mapping(Application_Links *app, String_Const_u8 mapping){ b32 did_remap = false; for (i32 i = 0; i < named_map_count; ++i){ - if (match(mapping, named_maps[i].name)){ + if (string_match(mapping, named_maps[i].name)){ did_remap = true; - exec_command(app, named_maps[i].remap_command); + named_maps[i].remap_command(app); break; } } if (!did_remap){ - print_message(app, literal("Leaving bindings unaltered.\n")); + print_message(app, string_u8_litexpr("Leaving bindings unaltered.\n")); } } static void -change_mode(Application_Links *app, String mode){ +change_mode(Application_Links *app, String_Const_u8 mode){ fcoder_mode = FCoderMode_Original; - if (match(mode, "4coder")){ + if (string_match(mode, string_u8_litexpr("4coder"))){ fcoder_mode = FCoderMode_Original; } - else if (match(mode, "notepad-like")){ + else if (string_match(mode, string_u8_litexpr("notepad-like"))){ begin_notepad_mode(app); } else{ - print_message(app, literal("Unknown mode.\n")); + print_message(app, string_u8_litexpr("Unknown mode.\n")); } } //////////////////////////////// +// TODO(allen): rewrite! static Cpp_Token_Array -text_data_to_token_array(Partition *arena, String data){ +text_data_to_token_array(Arena *arena, String_Const_u8 data){ b32 success = false; - i32 max_count = (1 << 20)/sizeof(Cpp_Token); - Temp_Memory restore_point = begin_temp_memory(arena); + Temp_Memory restore_point = begin_temp(arena); Cpp_Token_Array array = {}; + i32 max_count = (1 << 20)/sizeof(Cpp_Token); array.tokens = push_array(arena, Cpp_Token, max_count); - if (array.tokens != 0){ - array.max_count = max_count; - Cpp_Keyword_Table kw_table = {}; - Cpp_Keyword_Table pp_table = {}; - if (lexer_keywords_default_init(arena, &kw_table, &pp_table)){ - Cpp_Lex_Data S = cpp_lex_data_init(false, kw_table, pp_table); - Cpp_Lex_Result result = cpp_lex_step(&S, data.str, data.size + 1, HAS_NULL_TERM, &array, NO_OUT_LIMIT); - if (result == LexResult_Finished){ - success = true; - } + array.max_count = max_count; + Cpp_Keyword_Table kw_table = {}; + Cpp_Keyword_Table pp_table = {}; + if (lexer_keywords_default_init(arena, &kw_table, &pp_table)){ + Cpp_Lex_Data S = cpp_lex_data_init(false, kw_table, pp_table); + Cpp_Lex_Result result = cpp_lex_step(&S, (char*)data.str, (i32)(data.size + 1), HAS_NULL_TERM, &array, NO_OUT_LIMIT); + if (result == LexResult_Finished){ + success = true; } } if (!success){ - memset(&array, 0, sizeof(array)); - end_temp_memory(restore_point); + block_zero_struct(&array); + end_temp(restore_point); } return(array); } static Config* -text_data_to_parsed_data(Partition *arena, String file_name, String data){ +text_data_to_parsed_data(Arena *arena, String_Const_u8 file_name, String_Const_u8 data){ Config *parsed = 0; - Temp_Memory restore_point = begin_temp_memory(arena); + Temp_Memory restore_point = begin_temp(arena); Cpp_Token_Array array = text_data_to_token_array(arena, data); if (array.tokens != 0){ parsed = text_data_and_token_array_to_parse_data(arena, file_name, data, array); if (parsed == 0){ - end_temp_memory(restore_point); + end_temp(restore_point); } } return(parsed); @@ -1346,16 +1184,12 @@ text_data_to_parsed_data(Partition *arena, String file_name, String data){ static void config_init_default(Config_Data *config){ - config->user_name = make_fixed_width_string(config->user_name_space); - copy(&config->user_name, ""); + config->user_name = SCu8(config->user_name_space, (umem)0); - memset(&config->code_exts, 0, sizeof(config->code_exts)); + block_zero_struct(&config->code_exts); - config->current_mapping = make_fixed_width_string(config->current_mapping_space); - copy(&config->current_mapping, ""); - - config->mode = make_fixed_width_string(config->mode_space); - copy(&config->mode, "4coder"); + config->current_mapping = SCu8(config->current_mapping_space, (umem)0); + config->mode = SCu8(config->mode_space, (umem)0); config->use_scroll_bars = false; config->use_file_bars = true; @@ -1379,32 +1213,29 @@ config_init_default(Config_Data *config){ config->default_wrap_width = 672; config->default_min_base_width = 550; - config->default_theme_name = make_fixed_width_string(config->default_theme_name_space); - copy(&config->default_theme_name, "4coder"); + config->default_theme_name = SCu8(config->default_theme_name_space, sizeof("4coder") - 1); + block_copy(config->default_theme_name.str, "4coder", config->default_theme_name.size); config->highlight_line_at_cursor = true; - config->default_font_name = make_fixed_width_string(config->default_font_name_space); - copy(&config->default_font_name, ""); + config->default_font_name = SCu8(config->default_font_name_space, (umem)0); config->default_font_size = 16; config->default_font_hinting = false; - config->default_compiler_bat = make_fixed_width_string(config->default_compiler_bat_space); - copy(&config->default_compiler_bat, "cl"); + config->default_compiler_bat = SCu8(config->default_compiler_bat_space, 2); + block_copy(config->default_compiler_bat.str, "cl", 2); - config->default_flags_bat = make_fixed_width_string(config->default_flags_bat_space); - copy(&config->default_flags_bat, ""); + config->default_flags_bat = SCu8(config->default_flags_bat_space, (umem)0); - config->default_compiler_sh = make_fixed_width_string(config->default_compiler_sh_space); - copy(&config->default_compiler_sh, "g++"); + config->default_compiler_sh = SCu8(config->default_compiler_sh_space, 3); + block_copy(config->default_compiler_sh.str, "g++", 3); - config->default_flags_sh = make_fixed_width_string(config->default_flags_sh_space); - copy(&config->default_flags_sh, ""); + config->default_flags_sh = SCu8(config->default_flags_sh_space, (umem)0); config->lalt_lctrl_is_altgr = false; } static Config* -config_parse__data(Partition *arena, String file_name, String data, Config_Data *config){ +config_parse__data(Arena *arena, String_Const_u8 file_name, String_Const_u8 data, Config_Data *config){ config_init_default(config); b32 success = false; @@ -1416,9 +1247,9 @@ config_parse__data(Partition *arena, String file_name, String data, Config_Data config_fixed_string_var(parsed, "user_name", 0, &config->user_name, config->user_name_space); - String str; + String_Const_u8 str = {}; if (config_string_var(parsed, "treat_as_code", 0, &str)){ - parse_extension_line_to_extension_list(str, &config->code_exts); + config->code_exts = parse_extension_line_to_extension_list(arena, str); } config_fixed_string_var(parsed, "mapping", 0, @@ -1479,12 +1310,11 @@ config_parse__data(Partition *arena, String file_name, String data, Config_Data } static Config* -config_parse__file_handle(Partition *arena, - String file_name, FILE *file, Config_Data *config){ +config_parse__file_handle(Arena *arena, String_Const_u8 file_name, FILE *file, Config_Data *config){ Config *parsed = 0; - String data = dump_file_handle(arena, file); - if (data.str != 0){ - parsed = config_parse__data(arena, file_name, data, config); + Data data = dump_file_handle(arena, file); + if (data.data != 0){ + parsed = config_parse__data(arena, file_name, SCu8(data), config); } else{ config_init_default(config); @@ -1493,16 +1323,15 @@ config_parse__file_handle(Partition *arena, } static Config* -config_parse__file_name(Application_Links *app, Partition *arena, - char *file_name, Config_Data *config){ +config_parse__file_name(Application_Links *app, Arena *arena, char *file_name, Config_Data *config){ Config *parsed = 0; b32 success = false; FILE *file = open_file_try_current_path_then_binary_path(app, file_name); if (file != 0){ - String data = dump_file_handle(arena, file); + Data data = dump_file_handle(arena, file); fclose(file); - if (data.str != 0){ - parsed = config_parse__data(arena, make_string_slowly(file_name), data, config); + if (data.data != 0){ + parsed = config_parse__data(arena, SCu8(file_name), SCu8(data), config); success = true; } } @@ -1578,118 +1407,109 @@ theme_parse__file_name(Application_Links *app, Partition *arena, //////////////////////////////// static void -config_feedback_bool(String *space, char *name, b32 val){ - append(space, name); - append(space, " = "); - append(space, (char*)(val?"true":"false")); - append(space, ";\n"); +config_feedback_bool(Arena *arena, List_String_Const_u8 *list, char *name, b32 val){ + string_list_pushf(arena, list, "%s = %s;\n", name, (char*)(val?"true":"false")); } static void -config_feedback_string(String *space, char *name, String val){ - if (val.size > 0){ - append(space, name); - append(space, " = \""); - append(space, val); - append(space, "\";\n"); +config_feedback_string(Arena *arena, List_String_Const_u8 *list, char *name, String_Const_u8 val){ + val.size = clamp_bot(0, val.size); + string_list_pushf(arena, list, "%s = \"%.*s\";\n", name, string_expand(val)); +} + +static void +config_feedback_string(Arena *arena, List_String_Const_u8 *list, char *name, char *val){ + string_list_pushf(arena, list, "%s = \"%s\";\n", name, val); +} + +static void +config_feedback_extension_list(Arena *arena, List_String_Const_u8 *list, char *name, String_Const_u8_Array *extensions){ + string_list_pushf(arena, list, "%s = \"", name); + for (i32 i = 0; i < extensions->count; ++i){ + String_Const_u8 ext = extensions->strings[i]; + string_list_pushf(arena, list, ".%.*s", string_expand(ext)); } + string_list_push_u8_lit(arena, list, "\";\n"); } static void -config_feedback_string(String *space, char *name, char *val){ - config_feedback_string(space, name, make_string_slowly(val)); -} - -static void -config_feedback_extension_list(String *space, char *name, Extension_List *list){ - if (list->count > 0){ - append(space, name); - append(space, " = \""); - for (i32 i = 0; i < list->count; ++i){ - append(space, "."); - append(space, list->exts[i]); - } - append(space, "\";\n"); - } -} - -static void -config_feedback_int(String *space, char *name, i32 val){ - append(space, name); - append(space, " = "); - append_int_to_str(space, val); - append(space, ";\n"); +config_feedback_int(Arena *arena, List_String_Const_u8 *list, char *name, i32 val){ + string_list_pushf(arena, list, "%s = %d;\n", name, val); } //////////////////////////////// static void -load_config_and_apply(Application_Links *app, Partition *scratch, Config_Data *config, - i32 override_font_size, b32 override_hinting){ - Temp_Memory temp = begin_temp_memory(scratch); - Config *parsed = config_parse__file_name(app, scratch, "config.4coder", config); +load_config_and_apply(Application_Links *app, Arena *out_arena, Config_Data *config, i32 override_font_size, b32 override_hinting){ + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); + + linalloc_clear(out_arena); + Config *parsed = config_parse__file_name(app, out_arena, "config.4coder", config); if (parsed != 0){ // Top - print_message(app, literal("Loaded config file:\n")); + print_message(app, string_u8_litexpr("Loaded config file:\n")); // Errors - String error_text = config_stringize_errors(scratch, parsed); + String_Const_u8 error_text = config_stringize_errors(scratch, parsed); if (error_text.str != 0){ - print_message(app, error_text.str, error_text.size); + print_message(app, error_text); } // Values - Temp_Memory temp2 = begin_temp_memory(scratch); - String space = string_push(scratch, part_remaining(scratch)); + Temp_Memory temp2 = begin_temp(scratch); + // TODO(allen): switch to List_String_Const_u8 for the whole config system + List_String_Const_u8 list = {}; { - config_feedback_string(&space, "user_name", config->user_name); - config_feedback_extension_list(&space, "treat_as_code", &config->code_exts); - config_feedback_string(&space, "current_mapping", config->current_mapping); + config_feedback_string(scratch, &list, "user_name", config->user_name); + config_feedback_extension_list(scratch, &list, "treat_as_code", &config->code_exts); + config_feedback_string(scratch, &list, "current_mapping", config->current_mapping); - config_feedback_string(&space, "mode", config->mode); + config_feedback_string(scratch, &list, "mode", config->mode); - config_feedback_bool(&space, "use_scroll_bars", config->use_scroll_bars); - config_feedback_bool(&space, "use_file_bars", config->use_file_bars); - config_feedback_bool(&space, "use_line_highlight", config->use_line_highlight); - config_feedback_bool(&space, "use_scope_highlight", config->use_scope_highlight); - config_feedback_bool(&space, "use_paren_helper", config->use_paren_helper); - config_feedback_bool(&space, "use_comment_keyword", config->use_comment_keyword); - config_feedback_bool(&space, "file_lister_per_character_backspace", config->file_lister_per_character_backspace); - config_feedback_bool(&space, "show_line_number_margins", config->show_line_number_margins); + config_feedback_bool(scratch, &list, "use_scroll_bars", config->use_scroll_bars); + config_feedback_bool(scratch, &list, "use_file_bars", config->use_file_bars); + config_feedback_bool(scratch, &list, "use_line_highlight", config->use_line_highlight); + config_feedback_bool(scratch, &list, "use_scope_highlight", config->use_scope_highlight); + config_feedback_bool(scratch, &list, "use_paren_helper", config->use_paren_helper); + config_feedback_bool(scratch, &list, "use_comment_keyword", config->use_comment_keyword); + config_feedback_bool(scratch, &list, "file_lister_per_character_backspace", config->file_lister_per_character_backspace); + config_feedback_bool(scratch, &list, "show_line_number_margins", config->show_line_number_margins); - config_feedback_bool(&space, "enable_virtual_whitespace", config->enable_virtual_whitespace); - config_feedback_bool(&space, "enable_code_wrapping", config->enable_code_wrapping); - config_feedback_bool(&space, "automatically_indent_text_on_save", config->automatically_indent_text_on_save); - config_feedback_bool(&space, "automatically_save_changes_on_build", config->automatically_save_changes_on_build); - config_feedback_bool(&space, "automatically_adjust_wrapping", config->automatically_adjust_wrapping); - config_feedback_bool(&space, "automatically_load_project", config->automatically_load_project); + config_feedback_bool(scratch, &list, "enable_virtual_whitespace", config->enable_virtual_whitespace); + config_feedback_bool(scratch, &list, "enable_code_wrapping", config->enable_code_wrapping); + config_feedback_bool(scratch, &list, "automatically_indent_text_on_save", config->automatically_indent_text_on_save); + config_feedback_bool(scratch, &list, "automatically_save_changes_on_build", config->automatically_save_changes_on_build); + config_feedback_bool(scratch, &list, "automatically_adjust_wrapping", config->automatically_adjust_wrapping); + config_feedback_bool(scratch, &list, "automatically_load_project", config->automatically_load_project); - config_feedback_bool(&space, "indent_with_tabs", config->indent_with_tabs); - config_feedback_int(&space, "indent_width", config->indent_width); + config_feedback_bool(scratch, &list, "indent_with_tabs", config->indent_with_tabs); + config_feedback_int(scratch, &list, "indent_width", config->indent_width); - config_feedback_int(&space, "default_wrap_width", config->default_wrap_width); - config_feedback_int(&space, "default_min_base_width", config->default_min_base_width); + config_feedback_int(scratch, &list, "default_wrap_width", config->default_wrap_width); + config_feedback_int(scratch, &list, "default_min_base_width", config->default_min_base_width); - config_feedback_string(&space, "default_theme_name", config->default_theme_name); - config_feedback_bool(&space, "highlight_line_at_cursor", config->highlight_line_at_cursor); + config_feedback_string(scratch, &list, "default_theme_name", config->default_theme_name); + config_feedback_bool(scratch, &list, "highlight_line_at_cursor", config->highlight_line_at_cursor); - config_feedback_string(&space, "default_font_name", config->default_font_name); - config_feedback_int(&space, "default_font_size", config->default_font_size); - config_feedback_bool(&space, "default_font_hinting", config->default_font_hinting); + config_feedback_string(scratch, &list, "default_font_name", config->default_font_name); + config_feedback_int(scratch, &list, "default_font_size", config->default_font_size); + config_feedback_bool(scratch, &list, "default_font_hinting", config->default_font_hinting); - config_feedback_string(&space, "default_compiler_bat", config->default_compiler_bat); - config_feedback_string(&space, "default_flags_bat", config->default_flags_bat); - config_feedback_string(&space, "default_compiler_sh", config->default_compiler_sh); - config_feedback_string(&space, "default_flags_sh", config->default_flags_sh); + config_feedback_string(scratch, &list, "default_compiler_bat", config->default_compiler_bat); + config_feedback_string(scratch, &list, "default_flags_bat", config->default_flags_bat); + config_feedback_string(scratch, &list, "default_compiler_sh", config->default_compiler_sh); + config_feedback_string(scratch, &list, "default_flags_sh", config->default_flags_sh); - config_feedback_bool(&space, "lalt_lctrl_is_altgr", config->lalt_lctrl_is_altgr); + config_feedback_bool(scratch, &list, "lalt_lctrl_is_altgr", config->lalt_lctrl_is_altgr); } - append(&space, "\n"); - print_message(app, space.str, space.size); - end_temp_memory(temp2); + string_list_push_u8_lit(scratch, &list, "\n"); + String_Const_u8 message = string_list_flatten(scratch, list); + print_message(app, message); + end_temp(temp2); // Apply config change_mapping(app, config->current_mapping); @@ -1705,11 +1525,9 @@ load_config_and_apply(Application_Links *app, Partition *scratch, Config_Data *c highlight_line_at_cursor = config->highlight_line_at_cursor; Face_Description description = {}; - i32 len = config->default_font_name.size; - char *name_ptr = config->default_font_name.str; - if (len > sizeof(description.font.name) - 1){ - len = sizeof(description.font.name) - 1; - } + umem len = config->default_font_name.size; + len = clamp_top(len, sizeof(description.font.name) - 1); + u8 *name_ptr = config->default_font_name.str; memcpy(description.font.name, name_ptr, len); description.font.name[len] = 0; if (override_font_size != 0){ @@ -1722,7 +1540,7 @@ load_config_and_apply(Application_Links *app, Partition *scratch, Config_Data *c change_global_face_by_description(app, description, true); } - end_temp_memory(temp); + end_temp(temp); } #if 0 diff --git a/4coder_config.h b/4coder_config.h index 6f2b91a2..cf82b743 100644 --- a/4coder_config.h +++ b/4coder_config.h @@ -19,9 +19,9 @@ struct Error_Location{ struct Config_Error{ Config_Error *next; Config_Error *prev; - String file_name; - char *pos; - String text; + String_Const_u8 file_name; + u8 *pos; + String_Const_u8 text; }; struct Config_Error_List{ @@ -35,16 +35,16 @@ struct Config_Parser{ Cpp_Token *token; Cpp_Token *end; - String file_name; - String data; + String_Const_u8 file_name; + String_Const_u8 data; - Partition *arena; + Arena *arena; Config_Error_List errors; }; struct Config_LValue{ - String identifier; + String_Const_u8 identifier; i32 index; }; @@ -76,7 +76,7 @@ struct Config_RValue{ b32 boolean; i32 integer; u32 uinteger; - String string; + String_Const_u8 string; char character; Config_Compound *compound; }; @@ -99,9 +99,9 @@ enum{ }; struct Config_Layout{ Config_Layout_Type type; - char *pos; + u8 *pos; union{ - String identifier; + String_Const_u8 identifier; i32 integer; }; }; @@ -118,7 +118,7 @@ struct Config_Assignment{ Config_Assignment *next; Config_Assignment *prev; - char *pos; + u8 *pos; Config_LValue *l; Config_RValue *r; @@ -133,8 +133,8 @@ struct Config{ Config_Error_List errors; - String file_name; - String data; + String_Const_u8 file_name; + String_Const_u8 data; }; //////////////////////////////// @@ -149,12 +149,12 @@ enum{ struct Config_Get_Result{ b32 success; Config_RValue_Type type; - char *pos; + u8 *pos; union{ b32 boolean; i32 integer; u32 uinteger; - String string; + String_Const_u8 string; char character; Config_Compound *compound; }; @@ -179,28 +179,17 @@ struct Config_Get_Result_List{ //////////////////////////////// -struct Extension_List{ - char space[256]; - char *exts[94]; - i32 count; -}; - -struct CString_Array{ - char **strings; - i32 count; -}; - struct Config_Data{ - char user_name_space[256]; - String user_name; + u8 user_name_space[256]; + String_Const_u8 user_name; - Extension_List code_exts; + String_Const_u8_Array code_exts; - char current_mapping_space[256]; - String current_mapping; + u8 current_mapping_space[256]; + String_Const_u8 current_mapping; - char mode_space[64]; - String mode; + u8 mode_space[64]; + String_Const_u8 mode; b32 use_scroll_bars; b32 use_file_bars; @@ -224,27 +213,27 @@ struct Config_Data{ i32 default_wrap_width; i32 default_min_base_width; - char default_theme_name_space[256]; - String default_theme_name; + u8 default_theme_name_space[256]; + String_Const_u8 default_theme_name; b32 highlight_line_at_cursor; - char default_font_name_space[256]; - String default_font_name; + u8 default_font_name_space[256]; + String_Const_u8 default_font_name; i32 default_font_size; b32 default_font_hinting; - char default_compiler_bat_space[256]; - String default_compiler_bat; + u8 default_compiler_bat_space[256]; + String_Const_u8 default_compiler_bat; - char default_flags_bat_space[1024]; - String default_flags_bat; + u8 default_flags_bat_space[1024]; + String_Const_u8 default_flags_bat; - char default_compiler_sh_space[256]; - String default_compiler_sh; + u8 default_compiler_sh_space[256]; + String_Const_u8 default_compiler_sh; - char default_flags_sh_space[1024]; - String default_flags_sh; + u8 default_flags_sh_space[1024]; + String_Const_u8 default_flags_sh; b32 lalt_lctrl_is_altgr; }; diff --git a/4coder_default_framework.cpp b/4coder_default_framework.cpp index 918ed963..c356ce69 100644 --- a/4coder_default_framework.cpp +++ b/4coder_default_framework.cpp @@ -11,24 +11,25 @@ unlock_jump_buffer(void){ } static void -lock_jump_buffer(String name){ - if (name.size < locked_buffer.memory_size){ - copy(&locked_buffer, name); +lock_jump_buffer(String_Const_u8 name){ + if (name.size < sizeof(locked_buffer_space)){ + block_copy(locked_buffer_space, name.str, name.size); + locked_buffer = SCu8(locked_buffer_space, name.size); } } static void lock_jump_buffer(char *name, i32 size){ - lock_jump_buffer(make_string(name, size)); + lock_jump_buffer(SCu8(name, size)); } static void lock_jump_buffer(Application_Links *app, Buffer_ID buffer_id){ Arena *scratch = context_get_arena(app); - Temp_Memory_Arena temp = begin_temp_memory(scratch); - String buffer_name = buffer_push_unique_buffer_name(app, buffer_id, scratch); + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 buffer_name = buffer_push_unique_buffer_name(app, buffer_id, scratch); lock_jump_buffer(buffer_name); - end_temp_memory(temp); + end_temp(temp); } static View_ID @@ -63,13 +64,15 @@ new_view_settings(Application_Links *app, View_ID view){ static void view_set_passive(Application_Links *app, View_ID view_id, b32 value){ - Managed_Scope scope = view_get_managed_scope(app, view_id); + Managed_Scope scope = 0; + view_get_managed_scope(app, view_id, &scope); managed_variable_set(app, scope, view_is_passive_loc, (u64)value); } static b32 view_get_is_passive(Application_Links *app, View_ID view_id){ - Managed_Scope scope = view_get_managed_scope(app, view_id); + Managed_Scope scope = 0; + view_get_managed_scope(app, view_id, &scope); u64 is_passive = 0; managed_variable_get(app, scope, view_is_passive_loc, &is_passive); return(is_passive != 0); @@ -149,7 +152,7 @@ static void view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32 count){ if (count > 0){ Arena *arena = context_get_arena(app); - Temp_Memory_Arena temp = begin_temp_memory(arena); + Temp_Memory temp = begin_temp(arena); struct View_Node{ View_Node *next; @@ -194,7 +197,7 @@ view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32 } } - end_temp_memory(temp); + end_temp(temp); } } @@ -251,7 +254,7 @@ CUSTOM_DOC("Create a new panel by horizontally splitting the active panel.") // NOTE(allen): Credits to nj/FlyingSolomon for authoring the original version of this helper. static Buffer_ID -create_or_switch_to_buffer_by_name(Application_Links *app, String name_string, View_ID default_target_view){ +create_or_switch_to_buffer_and_clear_by_name(Application_Links *app, String_Const_u8 name_string, View_ID default_target_view){ Buffer_ID search_buffer = 0; get_buffer_by_name(app, name_string, AccessAll, &search_buffer); if (search_buffer != 0){ @@ -273,7 +276,7 @@ create_or_switch_to_buffer_by_name(Application_Links *app, String name_string, V buffer_get_size(app, search_buffer, &buffer_size); buffer_send_end_signal(app, search_buffer); - buffer_replace_range(app, search_buffer, make_range(0, buffer_size), make_lit_string("")); + buffer_replace_range(app, search_buffer, make_range(0, buffer_size), string_u8_litexpr("")); } else{ create_buffer(app, name_string, BufferCreate_AlwaysNew, &search_buffer); @@ -361,9 +364,10 @@ CUSTOM_COMMAND_SIG(remap_interactive) CUSTOM_DOC("Switch to a named key binding map.") { Query_Bar bar = {}; - char space[1024]; - bar.prompt = make_lit_string("Map Name: "); - bar.string = make_fixed_width_string(space); + u8 space[1024]; + bar.prompt = string_u8_litexpr("Map Name: "); + bar.string = SCu8(space, (umem)0); + bar.string_capacity = sizeof(space); if (!query_user_string(app, &bar)) return; change_mapping(app, bar.string); } @@ -372,28 +376,26 @@ CUSTOM_DOC("Switch to a named key binding map.") static void default_4coder_initialize(Application_Links *app, char **command_line_files, i32 file_count, i32 override_font_size, b32 override_hinting){ - i32 part_size = (32 << 20); - void *part_mem = memory_allocate(app, part_size); - global_part = make_part(part_mem, part_size); - i32 heap_size = (4 << 20); void *heap_mem = memory_allocate(app, heap_size); heap_init(&global_heap); heap_extend(&global_heap, heap_mem, heap_size); - static char message[] = - "Welcome to " VERSION "\n" - "If you're new to 4coder there are some tutorials at http://4coder.net/tutorials.html\n" - "Direct bug reports and feature requests to https://github.com/4coder-editor/4coder/issues\n" - "Other questions and discussion can be directed to editor@4coder.net or 4coder.handmade.network\n" - "The change log can be found in CHANGES.txt\n" - "\n"; - print_message(app, message, sizeof(message) - 1); +#define M \ + "Welcome to " VERSION "\n" \ + "If you're new to 4coder there are some tutorials at http://4coder.net/tutorials.html\n" \ + "Direct bug reports and feature requests to https://github.com/4coder-editor/4coder/issues\n" \ + "Other questions and discussion can be directed to editor@4coder.net or 4coder.handmade.network\n" \ + "The change log can be found in CHANGES.txt\n" \ + "\n" + print_message(app, string_u8_litexpr(M)); +#undef M #if 0 load_folder_of_themes_into_live_set(app, &global_part, "themes"); #endif - load_config_and_apply(app, &global_part, &global_config, override_font_size, override_hinting); + global_config_arena = make_arena_app_links(app); + load_config_and_apply(app, &global_config_arena, &global_config, override_font_size, override_hinting); view_rewrite_loc = managed_variable_create_or_get_id(app, "DEFAULT.rewrite" , 0); view_next_rewrite_loc = managed_variable_create_or_get_id(app, "DEFAULT.next_rewrite" , 0); @@ -403,23 +405,20 @@ default_4coder_initialize(Application_Links *app, char **command_line_files, i32 view_ui_data = managed_variable_create_or_get_id(app, "DEFAULT.ui_data" , 0); // open command line files - Temp_Memory temp = begin_temp_memory(&global_part); - char *space = push_array(&global_part, char, (32 << 10)); - String file_name = make_string_cap(space, 0, (32 << 10)); - i32 hot_directory_length = 0; - if (get_hot_directory(app, &file_name, &hot_directory_length)){ - for (i32 i = 0; i < file_count; i += 1){ - String input_name = make_string_slowly(command_line_files[i]); - file_name.size = hot_directory_length; - append(&file_name, input_name); - Buffer_ID ignore = 0; - if (!create_buffer(app, file_name, BufferCreate_NeverNew|BufferCreate_MustAttachToFile, &ignore)){ - create_buffer(app, input_name, 0, &ignore); - } + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 hot_directory = push_hot_directory(app, scratch); + for (i32 i = 0; i < file_count; i += 1){ + Temp_Memory temp2 = begin_temp(scratch); + String_Const_u8 input_name = SCu8(command_line_files[i]); + String_Const_u8 file_name = string_u8_pushf(scratch, "%.*s/%.*s", string_expand(hot_directory), string_expand(input_name)); + Buffer_ID ignore = 0; + if (!create_buffer(app, file_name, BufferCreate_NeverNew|BufferCreate_MustAttachToFile, &ignore)){ + create_buffer(app, input_name, 0, &ignore); } + end_temp(temp2); } - - end_temp_memory(temp); + end_temp(temp); } static void @@ -461,25 +460,23 @@ default_4coder_side_by_side_panels(Application_Links *app, Buffer_Identifier lef } static void -default_4coder_side_by_side_panels(Application_Links *app, char **command_line_files, i32 file_count){ - Buffer_Identifier left = buffer_identifier(literal("*scratch*")); - Buffer_Identifier right = buffer_identifier(literal("*messages*")); - +default_4coder_side_by_side_panels(Application_Links *app, Buffer_Identifier left, Buffer_Identifier right, char **command_line_files, i32 file_count){ if (file_count > 0){ - char *left_name = command_line_files[0]; - i32 left_len = str_size(left_name); - left = buffer_identifier(left_name, left_len); - + left = buffer_identifier(SCu8(command_line_files[0])); if (file_count > 1){ - char *right_name = command_line_files[1]; - i32 right_len = str_size(right_name); - right = buffer_identifier(right_name, right_len); + right = buffer_identifier(SCu8(command_line_files[1])); } } - default_4coder_side_by_side_panels(app, left, right); } +static void +default_4coder_side_by_side_panels(Application_Links *app, char **command_line_files, i32 file_count){ + Buffer_Identifier left = buffer_identifier(string_u8_litexpr("*scratch*")); + Buffer_Identifier right = buffer_identifier(string_u8_litexpr("*messages*")); + default_4coder_side_by_side_panels(app, left, right, command_line_files, file_count); +} + static void default_4coder_side_by_side_panels(Application_Links *app){ default_4coder_side_by_side_panels(app, 0, 0); @@ -496,14 +493,10 @@ default_4coder_one_panel(Application_Links *app, Buffer_Identifier buffer){ static void default_4coder_one_panel(Application_Links *app, char **command_line_files, i32 file_count){ - Buffer_Identifier buffer = buffer_identifier(literal("*messages*")); - + Buffer_Identifier buffer = buffer_identifier(string_u8_litexpr("*messages*")); if (file_count > 0){ - char *name = command_line_files[0]; - i32 len = str_size(name); - buffer = buffer_identifier(name, len); + buffer = buffer_identifier(SCu8(command_line_files[0])); } - default_4coder_one_panel(app, buffer); } diff --git a/4coder_default_framework.h b/4coder_default_framework.h index 7b87b277..375f41dc 100644 --- a/4coder_default_framework.h +++ b/4coder_default_framework.h @@ -36,7 +36,7 @@ struct ID_Pos_Jump_Location{ }; struct Name_Line_Column_Location{ - String file; + String_Const_u8 file; i32 line; i32 column; }; @@ -60,7 +60,7 @@ struct ID_Pos_Jump_Location_Array{ //////////////////////////////// struct Named_Mapping{ - String name; + String_Const_u8 name; Custom_Command_Function *remap_command; }; diff --git a/4coder_default_framework_variables.cpp b/4coder_default_framework_variables.cpp index 06f6251b..72744bc8 100644 --- a/4coder_default_framework_variables.cpp +++ b/4coder_default_framework_variables.cpp @@ -27,8 +27,8 @@ static char *default_extensions[] = { #define AUTO_CENTER_AFTER_JUMPS true #endif static b32 auto_center_after_jumps = AUTO_CENTER_AFTER_JUMPS; -static char locked_buffer_space[256]; -static String locked_buffer = make_fixed_width_string(locked_buffer_space); +static u8 locked_buffer_space[256]; +static String_Const_u8 locked_buffer = {}; static View_ID build_footer_panel_view_id = 0; @@ -41,8 +41,8 @@ static Managed_Variable_ID view_is_passive_loc = 0; static Managed_Variable_ID view_snap_mark_to_cursor = 0; static Managed_Variable_ID view_ui_data = 0; -static char out_buffer_space[1024]; -static char command_space[1024]; +static u8 out_buffer_space[1024]; +static u8 command_space[1024]; static char hot_directory_space[1024]; @@ -56,7 +56,6 @@ static b32 cursor_is_hidden = false; static b32 show_fps_hud = false; -static Partition global_part; static Heap global_heap; enum{ @@ -68,6 +67,7 @@ static i32 fcoder_mode = FCoderMode_Original; static ID_Line_Column_Jump_Location prev_location = {}; +static Arena global_config_arena = {}; static Config_Data global_config = {}; static char previous_isearch_query[256] = {}; diff --git a/4coder_default_hooks.cpp b/4coder_default_hooks.cpp index 58bf8a64..cffa032f 100644 --- a/4coder_default_hooks.cpp +++ b/4coder_default_hooks.cpp @@ -14,9 +14,9 @@ CUSTOM_COMMAND_SIG(set_bindings_default); CUSTOM_COMMAND_SIG(set_bindings_mac_default); static Named_Mapping named_maps_values[] = { - {make_lit_string("mac-default") , set_bindings_mac_default }, - {make_lit_string("choose") , set_bindings_choose }, - {make_lit_string("default") , set_bindings_default }, + {string_u8_litexpr("mac-default") , set_bindings_mac_default }, + {string_u8_litexpr("choose") , set_bindings_choose }, + {string_u8_litexpr("default") , set_bindings_default }, }; START_HOOK_SIG(default_start){ @@ -82,14 +82,16 @@ START_HOOK_SIG(default_start){ COMMAND_CALLER_HOOK(default_command_caller){ View_ID view = 0; get_active_view(app, AccessAll, &view); - Managed_Scope scope = view_get_managed_scope(app, view); + Managed_Scope scope = 0; + view_get_managed_scope(app, view, &scope); managed_variable_set(app, scope, view_next_rewrite_loc, 0); if (fcoder_mode == FCoderMode_NotepadLike){ View_ID view_it = 0; for (get_view_next(app, 0, AccessAll, &view_it); view_it != 0; get_view_next(app, view_it, AccessAll, &view_it)){ - Managed_Scope scope_it = view_get_managed_scope(app, view_it); + Managed_Scope scope_it = 0; + view_get_managed_scope(app, view_it, &scope_it); managed_variable_set(app, scope_it, view_snap_mark_to_cursor, true); } } @@ -104,7 +106,8 @@ COMMAND_CALLER_HOOK(default_command_caller){ for (get_view_next(app, 0, AccessAll, &view_it); view_it != 0; get_view_next(app, view_it, AccessAll, &view_it)){ - Managed_Scope scope_it = view_get_managed_scope(app, view_it); + Managed_Scope scope_it = 0; + view_get_managed_scope(app, view_it, &scope_it); u64 val = 0; if (managed_variable_get(app, scope_it, view_snap_mark_to_cursor, &val)){ if (val != 0){ @@ -120,8 +123,8 @@ COMMAND_CALLER_HOOK(default_command_caller){ } struct Highlight_Record{ - i32 first; - i32 one_past_last; + Highlight_Record *next; + Range range; int_color color; }; @@ -147,28 +150,32 @@ sort_highlight_record(Highlight_Record *records, i32 first, i32 one_past_last){ } static Range_Array -get_enclosure_ranges(Application_Links *app, Partition *part, Buffer_ID buffer, i32 pos, u32 flags){ +get_enclosure_ranges(Application_Links *app, Arena *arena, Buffer_ID buffer, i32 pos, u32 flags){ Range_Array array = {}; - array.ranges = push_array(part, Range, 0); + i32 max = 100; + array.ranges = push_array(arena, Range, max); for (;;){ Range range = {}; if (find_scope_range(app, buffer, pos, &range, flags)){ - Range *r = push_array(part, Range, 1); - *r = range; + array.ranges[array.count] = range; + array.count += 1; pos = range.first; + if (array.count >= max){ + break; + } } else{ break; } } - array.count = (i32)(push_array(part, Range, 0) - array.ranges); return(array); } static void -mark_enclosures(Application_Links *app, Partition *scratch, Managed_Scope render_scope, Buffer_ID buffer, i32 pos, u32 flags, +mark_enclosures(Application_Links *app, Managed_Scope render_scope, Buffer_ID buffer, i32 pos, u32 flags, Marker_Visual_Type type, int_color *back_colors, int_color *fore_colors, i32 color_count){ - Temp_Memory temp = begin_temp_memory(scratch); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); Range_Array ranges = get_enclosure_ranges(app, scratch, buffer, pos, flags); if (ranges.count > 0){ @@ -212,7 +219,7 @@ mark_enclosures(Application_Links *app, Partition *scratch, Managed_Scope render } } - end_temp_memory(temp); + end_temp(temp); } static argb_color default_colors[Stag_COUNT] = {}; @@ -311,7 +318,7 @@ GET_VIEW_BUFFER_REGION_SIG(default_view_buffer_region){ if (global_config.show_line_number_margins){ i32 line_count = 0; buffer_get_line_count(app, buffer, &line_count); - i32 line_count_digit_count = int_to_str_size(line_count); + i32 line_count_digit_count = (i32)digit_count_from_integer(line_count, 10); i32 margin_width = ceil32((f32)line_count_digit_count*metrics.typical_character_width); sub_region.x0 += margin_width + 2; } @@ -376,8 +383,8 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View get_active_view(app, AccessAll, &active_view); b32 is_active_view = (active_view == view_id); - Arena *arena = context_get_arena(app); - Temp_Memory_Arena major_temp = begin_temp_memory(arena); + Arena *scratch = context_get_arena(app); + Temp_Memory major_temp = begin_temp(scratch); static Managed_Scope render_scope = 0; if (render_scope == 0){ @@ -404,7 +411,7 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View Fancy_Color base_color = fancy_id(Stag_Base); Fancy_Color pop2_color = fancy_id(Stag_Pop2); - Temp_Memory_Arena temp = begin_temp_memory(arena); + Temp_Memory temp = begin_temp(scratch); i32 cursor_position = 0; view_get_cursor_pos(app, view_id, &cursor_position); @@ -412,43 +419,44 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View view_compute_cursor(app, view_id, seek_pos(cursor_position), &cursor); Fancy_String_List list = {}; - push_fancy_string(arena, &list, base_color, buffer_push_unique_buffer_name(app, buffer_id, arena)); - push_fancy_stringf(arena, &list, base_color, " - Row: %3.d Col: %3.d -", cursor.line, cursor.character); + String_Const_u8 unique_name = buffer_push_unique_buffer_name(app, buffer_id, scratch); + push_fancy_string(scratch, &list, base_color, unique_name); + push_fancy_stringf(scratch, &list, base_color, " - Row: %3.d Col: %3.d -", cursor.line, cursor.character); b32 is_dos_mode = false; if (buffer_get_setting(app, buffer_id, BufferSetting_Eol, &is_dos_mode)){ if (is_dos_mode){ - push_fancy_string(arena, &list, base_color, make_lit_string(" dos")); + push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" dos")); } else{ - push_fancy_string(arena, &list, base_color, make_lit_string(" nix")); + push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" nix")); } } else{ - push_fancy_string(arena, &list, base_color, make_lit_string(" ???")); + push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" ???")); } { Dirty_State dirty = 0; buffer_get_dirty_state(app, buffer_id, &dirty); - char space[3]; - String str = make_fixed_width_string(space); + u8 space[3]; + String_u8 str = Su8(space, 0, 3); if (dirty != 0){ - append(&str, " "); + string_append(&str, string_u8_litexpr(" ")); } if (HasFlag(dirty, DirtyState_UnsavedChanges)){ - append(&str, "*"); + string_append(&str, string_u8_litexpr("*")); } if (HasFlag(dirty, DirtyState_UnloadedChanges)){ - append(&str, "!"); + string_append(&str, string_u8_litexpr("!")); } - push_fancy_string(arena, &list, pop2_color, str); + push_fancy_string(scratch, &list, pop2_color, str.string); } Vec2 p = bar.p0 + V2(0.f, 2.f); draw_fancy_string(app, face_id, list.first, p, Stag_Default, 0); - end_temp_memory(temp); + end_temp(temp); } } } @@ -466,19 +474,19 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View bar.y1 = bar.y0 + line_height + 2.f; r_cursor.y0 = bar.y1; - Temp_Memory_Arena temp = begin_temp_memory(arena); + Temp_Memory temp = begin_temp(scratch); Fancy_String_List list = {}; Fancy_Color default_color = fancy_id(Stag_Default); Fancy_Color pop1_color = fancy_id(Stag_Pop1); - push_fancy_string(arena, &list, pop1_color , query_bar->prompt); - push_fancy_string(arena, &list, default_color, query_bar->string); + push_fancy_string(scratch, &list, pop1_color , query_bar->prompt); + push_fancy_string(scratch, &list, default_color, query_bar->string); Vec2 p = bar.p0 + V2(0.f, 2.f); draw_fancy_string(app, face_id, list.first, p, Stag_Default, 0); - end_temp_memory(temp); + end_temp(temp); } } } @@ -487,9 +495,9 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View if (global_config.show_line_number_margins){ i32 line_count = 0; buffer_get_line_count(app, buffer_id, &line_count); - i32 line_count_digit_count = int_to_str_size(line_count); + i32 line_count_digit_count = (i32)digit_count_from_integer(line_count, 10); // TODO(allen): I need a "digit width" - f32 zero = get_string_advance(app, face_id, make_lit_string("0")); + f32 zero = get_string_advance(app, face_id, string_u8_litexpr("0")); f32 margin_width = (f32)line_count_digit_count*zero; Rect_f32 left_margin = r_cursor; @@ -509,10 +517,10 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View Vec2 p = panel_space_from_view_space(cursor.wrapped_p, scroll_vars.scroll_p); p += V2(buffer_rect.p0); p.x = left_margin.x0; - Temp_Memory_Arena temp = begin_temp_memory(arena); - Fancy_String *line_string = push_fancy_stringf(arena, line_color, "%*d", line_count_digit_count, cursor.line); + Temp_Memory temp = begin_temp(scratch); + Fancy_String *line_string = push_fancy_stringf(scratch, line_color, "%*d", line_count_digit_count, cursor.line); draw_fancy_string(app, face_id, line_string, p, Stag_Margin_Active, 0); - end_temp_memory(temp); + end_temp(temp); i32 next_line = cursor.line + 1; view_compute_cursor(app, view_id, seek_line_char(next_line, 1), &cursor); if (cursor.line < next_line){ @@ -524,70 +532,82 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View } } - // TODO(allen): eliminate scratch partition usage - Partition *scratch = &global_part; // NOTE(allen): Scan for TODOs and NOTEs { - Temp_Memory temp = begin_temp_memory(scratch); - i32 text_size = on_screen_range.one_past_last - on_screen_range.first; - char *text = push_array(scratch, char, text_size); - buffer_read_range(app, buffer_id, on_screen_range.first, on_screen_range.one_past_last, text); + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 tail = scratch_read(app, scratch, buffer_id, on_screen_range); - Highlight_Record *records = push_array(scratch, Highlight_Record, 0); - String tail = make_string(text, text_size); - for (i32 i = 0; i < text_size; tail.str += 1, tail.size -= 1, i += 1){ - if (match_part(tail, make_lit_string("NOTE"))){ + Highlight_Record *record_first = 0; + Highlight_Record *record_last = 0; + i32 record_count = 0; + i32 index = 0; + + for (;tail.size > 0; tail = string_skip(tail, 1), index += 1){ + if (string_match(string_prefix(tail, 4), string_u8_litexpr("NOTE"))){ Highlight_Record *record = push_array(scratch, Highlight_Record, 1); - record->first = i + on_screen_range.first; - record->one_past_last = record->first + 4; + sll_queue_push(record_first, record_last, record); + record_count += 1; + record->range.first = on_screen_range.first + index; + record->range.one_past_last = record->range.first + 4; record->color = Stag_Text_Cycle_2; - tail.str += 3; - tail.size -= 3; - i += 3; + tail = string_skip(tail, 3); + index += 3; } - else if (match_part(tail, make_lit_string("TODO"))){ + else if (string_match(string_prefix(tail, 4), string_u8_litexpr("TODO"))){ Highlight_Record *record = push_array(scratch, Highlight_Record, 1); - record->first = i + on_screen_range.first; - record->one_past_last = record->first + 4; + sll_queue_push(record_first, record_last, record); + record_count += 1; + record->range.first = on_screen_range.first + index; + record->range.one_past_last = record->range.first + 4; record->color = Stag_Text_Cycle_1; - tail.str += 3; - tail.size -= 3; - i += 3; + tail = string_skip(tail, 3); + index += 3; } } - i32 record_count = (i32)(push_array(scratch, Highlight_Record, 0) - records); - push_array(scratch, Highlight_Record, 1); + + Highlight_Record *records = push_array(scratch, Highlight_Record, record_count); + i32 record_index = 0; + for (Highlight_Record *node = record_first; + node != 0; + node = node->next){ + records[record_index] = *node; + record_index += 1; + } if (record_count > 0){ sort_highlight_record(records, 0, record_count); - Temp_Memory marker_temp = begin_temp_memory(scratch); - Marker *markers = push_array(scratch, Marker, 0); + Marker *markers = push_array_zero(scratch, Marker, 2*record_count); + i32 marker_index_first = 0; + i32 marker_index = 0; int_color current_color = records[0].color; { - Marker *marker = push_array(scratch, Marker, 2); - marker[0].pos = records[0].first; - marker[1].pos = records[0].one_past_last; + Marker *marker = &markers[marker_index]; + marker[0].pos = records[0].range.first; + marker[1].pos = records[0].range.one_past_last; + marker_index += 2; } for (i32 i = 1; i <= record_count; i += 1){ - b32 do_emit = i == record_count || (records[i].color != current_color); + b32 do_emit = (i == record_count || records[i].color != current_color); if (do_emit){ - i32 marker_count = (i32)(push_array(scratch, Marker, 0) - markers); + i32 marker_count = marker_index - marker_index_first; Managed_Object o = alloc_buffer_markers_on_buffer(app, buffer_id, marker_count, &render_scope); - managed_object_store_data(app, o, 0, marker_count, markers); + managed_object_store_data(app, o, 0, marker_count, markers + marker_index_first); Marker_Visual v = create_marker_visual(app, o); marker_visual_set_effect(app, v, VisualType_CharacterHighlightRanges, SymbolicColor_Default, current_color, 0); marker_visual_set_priority(app, v, VisualPriority_Lowest); - end_temp_memory(marker_temp); current_color = records[i].color; + marker_index_first = marker_index; + } + if (i < record_count){ + Marker *marker = &markers[marker_index]; + marker[0].pos = records[i].range.first; + marker[1].pos = records[i].range.one_past_last; + marker_index += 2; } - - Marker *marker = push_array(scratch, Marker, 2); - marker[0].pos = records[i].first; - marker[1].pos = records[i].one_past_last; } } - end_temp_memory(temp); + end_temp(temp); } // NOTE(allen): Cursor and mark @@ -700,7 +720,7 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View for (u16 i = 0; i < color_count; i += 1){ colors[i] = Stag_Back_Cycle_1 + i; } - mark_enclosures(app, scratch, render_scope, buffer_id, cursor_pos, FindScope_Brace, VisualType_LineHighlightRanges, colors, 0, color_count); + mark_enclosures(app, render_scope, buffer_id, cursor_pos, FindScope_Brace, VisualType_LineHighlightRanges, colors, 0, color_count); } if (do_matching_paren_highlight){ i32 pos = cursor_pos; @@ -716,7 +736,7 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View for (u16 i = 0; i < color_count; i += 1){ colors[i] = Stag_Text_Cycle_1 + i; } - mark_enclosures(app, scratch, render_scope, buffer_id, pos, FindScope_Paren, VisualType_CharacterBlocks, 0, colors, color_count); + mark_enclosures(app, render_scope, buffer_id, pos, FindScope_Paren, VisualType_CharacterBlocks, 0, colors, color_count); } draw_clip_push(app, buffer_rect); @@ -758,28 +778,24 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View dts[1] = history_animation_dt[j]; i32 frame_index = history_frame_index[j]; - char space[256]; - String str = make_fixed_width_string(space); - Fancy_Color white = fancy_rgba(1.f, 1.f, 1.f, 1.f); Fancy_Color pink = fancy_rgba(1.f, 0.f, 1.f, 1.f); Fancy_Color green = fancy_rgba(0.f, 1.f, 0.f, 1.f); Fancy_String_List list = {}; - push_fancy_stringf(arena, &list, pink , "FPS: "); - push_fancy_stringf(arena, &list, green, "["); - push_fancy_stringf(arena, &list, white, "%5d", frame_index); - push_fancy_stringf(arena, &list, green, "]: "); + push_fancy_stringf(scratch, &list, pink , "FPS: "); + push_fancy_stringf(scratch, &list, green, "["); + push_fancy_stringf(scratch, &list, white, "%5d", frame_index); + push_fancy_stringf(scratch, &list, green, "]: "); for (i32 k = 0; k < 2; k += 1){ f32 dt = dts[k]; - str.size = 0; if (dt == 0.f){ - push_fancy_stringf(arena, &list, white, "----------"); + push_fancy_stringf(scratch, &list, white, "----------"); } else{ - push_fancy_stringf(arena, &list, white, "%10.6f", dt); + push_fancy_stringf(scratch, &list, white, "%10.6f", dt); } - push_fancy_stringf(arena, &list, green, " | "); + push_fancy_stringf(scratch, &list, green, " | "); } draw_fancy_string(app, face_id, list.first, p, Stag_Default, 0, 0, V2(1.f, 0.f)); @@ -789,7 +805,7 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View animate_in_n_milliseconds(app, 1000); } - end_temp_memory(major_temp); + end_temp(major_temp); managed_scope_clear_self_all_dependent_scopes(app, render_scope); } @@ -962,7 +978,7 @@ HOOK_SIG(default_view_adjust){ Face_ID face_id = 0; get_face_id(app, buffer, &face_id); - f32 em = get_string_advance(app, face_id, make_lit_string("m")); + f32 em = get_string_advance(app, face_id, string_u8_litexpr("m")); f32 wrap_width = view_width - 2.0f*em; f32 min_width = 40.0f*em; @@ -980,12 +996,9 @@ HOOK_SIG(default_view_adjust){ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){ if (conflict_count > 1){ // List of unresolved conflicts - Partition *part = &global_part; - Temp_Memory temp = begin_temp_memory(part); - - i32 *unresolved = push_array(part, i32, conflict_count); - if (unresolved == 0) return; + Scratch_Block scratch(app); + i32 *unresolved = push_array(scratch, i32, conflict_count); i32 unresolved_count = conflict_count; for (i32 i = 0; i < conflict_count; ++i){ unresolved[i] = i; @@ -1000,57 +1013,50 @@ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){ i32 conflict_index = unresolved[i]; Buffer_Name_Conflict_Entry *conflict = &conflicts[conflict_index]; - i32 len = conflict->base_name_len; - if (len < 0){ - len = 0; - } - if (len > conflict->unique_name_capacity){ - len = conflict->unique_name_capacity; - } - conflict->unique_name_len_in_out = len; - memcpy(conflict->unique_name_in_out, conflict->base_name, len); + umem size = conflict->base_name.size; + size = clamp_top(size, conflict->unique_name_capacity); + conflict->unique_name_len_in_out = size; + memcpy(conflict->unique_name_in_out, conflict->base_name.str, size); - if (conflict->file_name != 0){ - char uniqueifier_space[256]; - String uniqueifier = make_fixed_width_string(uniqueifier_space); + if (conflict->file_name.str != 0){ + Scratch_Block per_file_closer(scratch); + String_Const_u8 uniqueifier = {}; - String s_file_name = make_string(conflict->file_name, conflict->file_name_len); - s_file_name = path_of_directory(s_file_name); - if (s_file_name.size > 0){ - s_file_name.size -= 1; - char *end = s_file_name.str + s_file_name.size; + String_Const_u8 file_name = string_remove_last_folder(conflict->file_name); + if (file_name.size > 0){ + file_name = string_chop(file_name, 1); + u8 *end = file_name.str + file_name.size; b32 past_the_end = false; for (i32 j = 0; j < x; ++j){ - s_file_name = path_of_directory(s_file_name); + file_name = string_remove_last_folder(file_name); if (j + 1 < x){ - s_file_name.size -= 1; + file_name = string_chop(file_name, 1); } - if (s_file_name.size <= 0){ + if (file_name.size == 0){ if (j + 1 < x){ past_the_end = true; } - s_file_name.size = 0; break; } } - char *start = s_file_name.str + s_file_name.size; + u8 *start = file_name.str + file_name.size; - append(&uniqueifier, make_string(start, (i32)(end - start))); + uniqueifier = SCu8(start, end); if (past_the_end){ - append(&uniqueifier, "~"); - append_int_to_str(&uniqueifier, i); + uniqueifier = string_u8_pushf(scratch, "%.*s~%d", + string_expand(uniqueifier), i); } } else{ - append_int_to_str(&uniqueifier, i); + uniqueifier = string_u8_pushf(scratch, "%d", i); } - String builder = make_string_cap(conflict->unique_name_in_out, - conflict->unique_name_len_in_out, - conflict->unique_name_capacity); - append(&builder, " <"); - append(&builder, uniqueifier); - append(&builder, ">"); + String_u8 builder = Su8(conflict->unique_name_in_out, + conflict->unique_name_len_in_out, + conflict->unique_name_capacity); + string_append(&builder, string_u8_litexpr(" <")); + string_append(&builder, uniqueifier); + string_append(&builder, string_u8_litexpr(">")); conflict->unique_name_len_in_out = builder.size; } } @@ -1060,19 +1066,21 @@ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){ for (i32 i = 0; i < unresolved_count; ++i){ i32 conflict_index = unresolved[i]; Buffer_Name_Conflict_Entry *conflict = &conflicts[conflict_index]; - String conflict_name = make_string(conflict->unique_name_in_out, - conflict->unique_name_len_in_out); + String_Const_u8 conflict_name = SCu8(conflict->unique_name_in_out, + conflict->unique_name_len_in_out); b32 hit_conflict = false; - if (conflict->file_name != 0){ + if (conflict->file_name.str != 0){ for (i32 j = 0; j < unresolved_count; ++j){ if (i == j) continue; i32 conflict_j_index = unresolved[j]; Buffer_Name_Conflict_Entry *conflict_j = &conflicts[conflict_j_index]; - if (match(conflict_name, make_string(conflict_j->unique_name_in_out, - conflict_j->unique_name_len_in_out))){ + String_Const_u8 conflict_name_j = SCu8(conflict_j->unique_name_in_out, + conflict_j->unique_name_len_in_out); + + if (string_match(conflict_name, conflict_name_j)){ hit_conflict = true; break; } @@ -1093,8 +1101,6 @@ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){ break; } } - - end_temp_memory(temp); } } @@ -1103,38 +1109,38 @@ OPEN_FILE_HOOK_SIG(default_file_settings){ b32 treat_as_todo = false; b32 lex_without_strings = false; - CString_Array extensions = get_code_extensions(&global_config.code_exts); + String_Const_u8_Array extensions = global_config.code_exts; Parse_Context_ID parse_context_id = 0; Arena *scratch = context_get_arena(app); - Temp_Memory_Arena temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); - String file_name = buffer_push_file_name(app, buffer_id, scratch); + String_Const_u8 file_name = buffer_push_file_name(app, buffer_id, scratch); i32 buffer_size = 0; buffer_get_size(app, buffer_id, &buffer_size); - if (file_name.size > 0 && buffer_size < (32 << 20)){ - String ext = file_extension(file_name); + if (file_name.size > 0 && buffer_size < MB(32)){ + String_Const_u8 ext = string_file_extension(file_name); for (i32 i = 0; i < extensions.count; ++i){ - if (match(ext, extensions.strings[i])){ + if (string_match(ext, extensions.strings[i])){ treat_as_code = true; - if (match(ext, "cs")){ + if (string_match(ext, string_u8_litexpr("cs"))){ if (parse_context_language_cs == 0){ init_language_cs(app); } parse_context_id = parse_context_language_cs; } - if (match(ext, "java")){ + if (string_match(ext, string_u8_litexpr("java"))){ if (parse_context_language_java == 0){ init_language_java(app); } parse_context_id = parse_context_language_java; } - if (match(ext, "rs")){ + if (string_match(ext, string_u8_litexpr("rs"))){ if (parse_context_language_rust == 0){ init_language_rust(app); } @@ -1142,7 +1148,11 @@ OPEN_FILE_HOOK_SIG(default_file_settings){ lex_without_strings = true; } - if (match(ext, "cpp") || match(ext, "h") || match(ext, "c") || match(ext, "hpp") || match(ext, "cc")){ + if (string_match(ext, string_u8_litexpr("cpp")) || + string_match(ext, string_u8_litexpr("h")) || + string_match(ext, string_u8_litexpr("c")) || + string_match(ext, string_u8_litexpr("hpp")) || + string_match(ext, string_u8_litexpr("cc"))){ if (parse_context_language_cpp == 0){ init_language_cpp(app); } @@ -1150,7 +1160,7 @@ OPEN_FILE_HOOK_SIG(default_file_settings){ } // TODO(NAME): Real GLSL highlighting - if (match(ext, "glsl")){ + if (string_match(ext, string_u8_litexpr("glsl"))){ if (parse_context_language_cpp == 0){ init_language_cpp(app); } @@ -1158,7 +1168,7 @@ OPEN_FILE_HOOK_SIG(default_file_settings){ } // TODO(NAME): Real Objective-C highlighting - if (match(ext, "m")){ + if (string_match(ext, string_u8_litexpr("m"))){ if (parse_context_language_cpp == 0){ init_language_cpp(app); } @@ -1170,7 +1180,8 @@ OPEN_FILE_HOOK_SIG(default_file_settings){ } if (!treat_as_code){ - treat_as_todo = match_insensitive(front_of_directory(file_name), "todo.txt"); + treat_as_todo = string_match_insensitive(string_front_of_path(file_name), + string_u8_litexpr("todo.txt")); } } @@ -1204,8 +1215,8 @@ OPEN_FILE_HOOK_SIG(default_file_settings){ use_lexer = true; } - String buffer_name = buffer_push_base_buffer_name(app, buffer_id, scratch); - if (match(buffer_name, "*compilation*")){ + String_Const_u8 buffer_name = buffer_push_base_buffer_name(app, buffer_id, scratch); + if (string_match(buffer_name, string_u8_litexpr("*compilation*"))){ wrap_lines = false; } if (buffer_size >= (1 << 20)){ @@ -1224,7 +1235,7 @@ OPEN_FILE_HOOK_SIG(default_file_settings){ buffer_set_setting(app, buffer_id, BufferSetting_VirtualWhitespace, use_virtual_whitespace); buffer_set_setting(app, buffer_id, BufferSetting_Lex, use_lexer); - end_temp_memory(temp); + end_temp(temp); // no meaning for return return(0); @@ -1243,7 +1254,7 @@ OPEN_FILE_HOOK_SIG(default_file_save){ if (is_virtual){ i32 buffer_size = 0; buffer_get_size(app, buffer_id, &buffer_size); - buffer_auto_indent(app, &global_part, buffer_id, 0, buffer_size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); + buffer_auto_indent(app, buffer_id, 0, buffer_size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens); } } // no meaning for return @@ -1268,16 +1279,11 @@ FILE_EDIT_FINISHED_SIG(default_file_edit_finished){ } OPEN_FILE_HOOK_SIG(default_end_file){ - Arena *scratch = context_get_arena(app); - Temp_Memory_Arena temp = begin_temp_memory(scratch); - char space[1024]; - String buffer_name = buffer_push_unique_buffer_name(app, buffer_id, scratch); - String str = make_fixed_width_string(space); - append(&str, "Ending file: "); - append(&str, buffer_name); - append(&str, "\n"); - print_message(app, str.str, str.size); - end_temp_memory(temp); + Scratch_Block scratch(app); + String_Const_u8 buffer_name = buffer_push_unique_buffer_name(app, buffer_id, scratch); + String_Const_u8 str = string_u8_pushf(scratch, "Ending file: %.*s\n", + string_expand(buffer_name)); + print_message(app, str); // no meaning for return return(0); } diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index bd866a9e..2224b8c3 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -10,11 +10,17 @@ // NOTE(allen): Define USE_OLD_STYLE_JUMPS before 4coder_default_include.cpp to get // the direct jumps (instead of sticky jumps). +#define REMOVE_OLD_STRING +#define REMOVE_TRANSITION_HELPER_31 + #include "4coder_API/4coder_custom.h" -#include "4coder_os_comp_cracking.h" #include "4coder_generated/command_metadata.h" +#include "4coder_base_types.cpp" +#include "4coder_stringf.cpp" +#include "4coder_app_links_allocator.cpp" + #include "4coder_lib/4coder_arena.cpp" #include "4coder_lib/4coder_heap.cpp" @@ -36,6 +42,7 @@ #include "4coder_auto_indent.h" #include "4coder_search.h" #include "4coder_build_commands.h" +#include "4coder_jumping.h" #include "4coder_jump_sticky.h" #include "4coder_jump_lister.h" #include "4coder_project_commands.h" diff --git a/4coder_experiments.cpp b/4coder_experiments.cpp index 2ffc7d9b..8439eec2 100644 --- a/4coder_experiments.cpp +++ b/4coder_experiments.cpp @@ -64,14 +64,14 @@ CUSTOM_DOC("Delete characters in a rectangular region. Range testing is done by i32 start = cursor.pos; if (view_compute_cursor(app, view, seek_wrapped_xy((float)rect.x1, y, 0), &cursor)){ i32 end = cursor.pos; - buffer_replace_range(app, buffer, make_range(start, end), make_lit_string("")); + buffer_replace_range(app, buffer, make_range(start, end), string_u8_litexpr("")); } } } } static void -pad_buffer_line(Application_Links *app, Partition *part, Buffer_ID buffer, i32 line, char padchar, i32 target){ +pad_buffer_line(Application_Links *app, Buffer_ID buffer, i32 line, char padchar, i32 target){ Partial_Cursor start = {}; Partial_Cursor end = {}; @@ -79,12 +79,13 @@ pad_buffer_line(Application_Links *app, Partition *part, Buffer_ID buffer, i32 l if (buffer_compute_cursor(app, buffer, seek_line_char(line, 65536), &end)){ if (start.line == line){ if (end.character-1 < target){ - Temp_Memory temp = begin_temp_memory(part); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); i32 size = target - (end.character - 1); - char *str = push_array(part, char, size); - memset(str, ' ', size); - buffer_replace_range(app, buffer, make_range(end.pos), make_string(str, size)); - end_temp_memory(temp); + char *str = push_array(scratch, char, size); + block_fill_u8(str, size, ' '); + buffer_replace_range(app, buffer, make_range(end.pos), SCu8(str, size)); + end_temp(temp); } } } @@ -136,8 +137,6 @@ struct Buffer_Rect{ CUSTOM_COMMAND_SIG(multi_line_edit) CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted at every line between the mark and cursor. All characters are inserted at the same character offset into the line. This mode uses line_char coordinates.") { - Partition *part = &global_part; - View_ID view = 0; get_active_view(app, AccessOpen, &view); Buffer_ID buffer = 0; @@ -167,7 +166,7 @@ CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted a i32 pos = cursor.character - 1; for (i32 i = rect.line0; i <= rect.line1; ++i){ - pad_buffer_line(app, &global_part, buffer, i, ' ', pos); + pad_buffer_line(app, buffer, i, ' ', pos); } i32 line_count = rect.line1 - rect.line0 + 1; @@ -179,8 +178,9 @@ CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted a if (in.key.character && key_is_unmodified(&in.key)){ char str = (char)in.key.character; - Temp_Memory temp = begin_temp_memory(part); - Buffer_Edit *edit = push_array(part, Buffer_Edit, line_count); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); + Buffer_Edit *edit = push_array(scratch, Buffer_Edit, line_count); Buffer_Edit *edits = edit; for (i32 i = rect.line0; i <= rect.line1; ++i){ @@ -197,7 +197,7 @@ CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted a i32 edit_count = (int)(edit - edits); buffer_batch_edit(app, buffer, &str, edits, edit_count); - end_temp_memory(temp); + end_temp(temp); ++pos; @@ -205,8 +205,9 @@ CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted a } else if (in.key.keycode == key_back){ if (pos > 0){ - Temp_Memory temp = begin_temp_memory(part); - Buffer_Edit *edit = push_array(part, Buffer_Edit, line_count); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); + Buffer_Edit *edit = push_array(scratch, Buffer_Edit, line_count); Buffer_Edit *edits = edit; for (i32 i = rect.line0; i <= rect.line1; ++i){ @@ -223,7 +224,7 @@ CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted a i32 edit_count = (int)(edit - edits); buffer_batch_edit(app, buffer, 0, edits, edit_count); - end_temp_memory(temp); + end_temp(temp); --pos; } @@ -237,11 +238,15 @@ CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted a // NOTE(allen): An experimental mutli-pasting thing CUSTOM_COMMAND_SIG(multi_paste){ - i32 count = clipboard_count(app, 0); + Scratch_Block scratch(app); + + i32 count = 0; + clipboard_count(app, 0, &count); if (count > 0){ View_ID view = 0; get_active_view(app, AccessOpen, &view); - Managed_Scope scope = view_get_managed_scope(app, view); + Managed_Scope scope = 0; + view_get_managed_scope(app, view, &scope); u64 rewrite = 0; managed_variable_get(app, scope, view_rewrite_loc, &rewrite); @@ -252,35 +257,34 @@ CUSTOM_COMMAND_SIG(multi_paste){ i32 paste_index = (i32)prev_paste_index + 1; managed_variable_set(app, scope, view_paste_index_loc, paste_index); - i32 len = clipboard_index(app, 0, paste_index, 0, 0); + String_Const_u8 string = {}; + clipboard_index(app, 0, paste_index, scratch, &string); - if (len + 1 <= app->memory_size){ - char *str = (char*)app->memory; - str[0] = '\n'; - clipboard_index(app, 0, paste_index, str + 1, len); - - Buffer_ID buffer = 0; - view_get_buffer(app, view, AccessOpen, &buffer); - Range range = get_view_range(app, view); - buffer_replace_range(app, buffer, make_range(range.max), make_string(str, len + 1)); - view_set_mark(app, view, seek_pos(range.max + 1)); - view_set_cursor(app, view, seek_pos(range.max + len + 1), true); - - // TODO(allen): Send this to all views. - Theme_Color paste; - paste.tag = Stag_Paste; - get_theme_colors(app, &paste, 1); - view_post_fade(app, view, 0.667f, range.max + 1, range.max + len + 1, paste.color); - } + String_Const_u8 insert_string = string_u8_pushf(scratch, "\n%.*s", string_expand(string)); + + Buffer_ID buffer = 0; + view_get_buffer(app, view, AccessOpen, &buffer); + Range range = get_view_range(app, view); + buffer_replace_range(app, buffer, make_range(range.max), insert_string); + view_set_mark(app, view, seek_pos(range.max + 1)); + view_set_cursor(app, view, seek_pos((i32)(range.max + insert_string.size)), true); + + // TODO(allen): Send this to all views. + Theme_Color paste = {}; + paste.tag = Stag_Paste; + get_theme_colors(app, &paste, 1); + view_post_fade(app, view, 0.667f, range.max + 1, (i32)(range.max + insert_string.size), paste.color); } else{ - exec_command(app, paste); + paste(app); } } } static Range multi_paste_range(Application_Links *app, View_ID view, Range range, i32 paste_count, b32 old_to_new){ + Scratch_Block scratch(app); + Range finish_range = range; if (paste_count >= 1){ Buffer_ID buffer = 0; @@ -292,31 +296,31 @@ multi_paste_range(Application_Links *app, View_ID view, Range range, i32 paste_c total_size -= 1; if (total_size <= app->memory_size){ - char *str = (char*)app->memory; - i32 position = 0; - i32 first = paste_count - 1; i32 one_past_last = -1; i32 step = -1; - if (!old_to_new){ first = 0; one_past_last = paste_count; step = 1; } + List_String_Const_u8 list = {}; + for (i32 paste_index = first; paste_index != one_past_last; paste_index += step){ if (paste_index != first){ - str[position] = '\n'; - ++position; + string_list_push(scratch, &list, SCu8("\n", 1)); + } + String_Const_u8 string = {}; + if (clipboard_index(app, 0, paste_index, scratch, &string)){ + string_list_push(scratch, &list, string); } - - i32 len = clipboard_index(app, 0, paste_index, str + position, total_size - position); - position += len; } + String_Const_u8 flattened = string_list_flatten(scratch, list); + i32 pos = range.min; - buffer_replace_range(app, buffer, range, make_string(str, total_size)); + buffer_replace_range(app, buffer, range, flattened); finish_range.min = pos; finish_range.max = pos + total_size; view_set_mark(app, view, seek_pos(finish_range.min)); @@ -347,7 +351,7 @@ multi_paste_interactive_up_down(Application_Links *app, i32 paste_count, i32 cli range = multi_paste_range(app, view, range, paste_count, old_to_new); Query_Bar bar = {}; - bar.prompt = make_lit_string("Up and Down to condense and expand paste stages; R to reverse order; Return to finish; Escape to abort."); + bar.prompt = string_u8_litexpr("Up and Down to condense and expand paste stages; R to reverse order; Return to finish; Escape to abort."); if (start_query_bar(app, &bar, 0) == 0) return; User_Input in = {}; @@ -384,34 +388,31 @@ multi_paste_interactive_up_down(Application_Links *app, i32 paste_count, i32 cli if (in.abort){ Buffer_ID buffer = 0; view_get_buffer(app, view, AccessOpen, &buffer); - buffer_replace_range(app, buffer, range, make_lit_string("")); + buffer_replace_range(app, buffer, range, SCu8("")); } } CUSTOM_COMMAND_SIG(multi_paste_interactive){ - i32 clip_count = clipboard_count(app, 0); + i32 clip_count = 0; + clipboard_count(app, 0, &clip_count); if (clip_count > 0){ multi_paste_interactive_up_down(app, 1, clip_count); } } CUSTOM_COMMAND_SIG(multi_paste_interactive_quick){ - i32 clip_count = clipboard_count(app, 0); + i32 clip_count = 0; + clipboard_count(app, 0, &clip_count); if (clip_count > 0){ - char string_space[256]; + u8 string_space[256]; Query_Bar bar = {}; - bar.prompt = make_lit_string("How Many Slots To Paste: "); - bar.string = make_fixed_width_string(string_space); + bar.prompt = string_u8_litexpr("How Many Slots To Paste: "); + bar.string = SCu8(string_space, (umem)0); + bar.string_capacity = sizeof(string_space); query_user_number(app, &bar); - i32 initial_paste_count = str_to_int_s(bar.string); - if (initial_paste_count > clip_count){ - initial_paste_count = clip_count; - } - if (initial_paste_count < 1){ - initial_paste_count = 1; - } - + i32 initial_paste_count = (i32)string_to_integer(bar.string, 10); + initial_paste_count = clamp(1, initial_paste_count, clip_count); end_query_bar(app, &bar, 0); multi_paste_interactive_up_down(app, initial_paste_count, clip_count); @@ -430,9 +431,8 @@ CUSTOM_DOC("If the cursor is found to be on the name of a function parameter in i32 cursor_pos = 0; view_get_cursor_pos(app, view, &cursor_pos); - Partition *part = &global_part; - - Temp_Memory temp = begin_temp_memory(part); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); Cpp_Get_Token_Result result; if (buffer_get_token_index(app, buffer, cursor_pos, &result)){ @@ -446,123 +446,113 @@ CUSTOM_DOC("If the cursor is found to be on the name of a function parameter in Cpp_Token token = stream.tokens[token_index]; if (token.type == CPP_TOKEN_IDENTIFIER){ + Cpp_Token original_token = token; + String_Const_u8 old_lexeme = scratch_read(app, scratch, buffer, token); - char old_lexeme_base[128]; - String old_lexeme = make_fixed_width_string(old_lexeme_base); + i32 proc_body_found = 0; + b32 still_looping = 0; - if (token.size < sizeof(old_lexeme_base)){ - Cpp_Token original_token = token; - old_lexeme.size = token.size; - buffer_read_range(app, buffer, token.start, token.start+token.size, old_lexeme.str); + ++token_index; + do{ + for (; token_index < stream.end; ++token_index){ + Cpp_Token *token_ptr = stream.tokens + token_index; + switch (token_ptr->type){ + case CPP_TOKEN_BRACE_OPEN: + { + proc_body_found = 1; + goto doublebreak; + }break; + + case CPP_TOKEN_BRACE_CLOSE: + case CPP_TOKEN_PARENTHESE_OPEN: + { + goto doublebreak; + }break; + } + } + still_looping = forward_stream_tokens(&stream); + }while(still_looping); + doublebreak:; + + if (proc_body_found){ - i32 proc_body_found = 0; - b32 still_looping = 0; + u8 with_space[1024]; + Query_Bar with = {}; + with.prompt = string_u8_litexpr("New Name: "); + with.string = SCu8(with_space, (umem)0); + with.string_capacity = sizeof(with_space); + if (!query_user_string(app, &with)) return; + String_Const_u8 replace_string = with.string; + + // TODO(allen): fix this up to work with arena better + i32 edit_max = Thousand(100); + Buffer_Edit *edits = push_array(scratch, Buffer_Edit, edit_max); + i32 edit_count = 0; + + if (edit_max >= 1){ + Buffer_Edit edit = {}; + edit.str_start = 0; + edit.len = (i32)replace_string.size; + edit.start = original_token.start; + edit.end = original_token.start + original_token.size; + + edits[edit_count] = edit; + edit_count += 1; + } + + i32 nesting_level = 0; + i32 closed_correctly = 0; ++token_index; + still_looping = 0; do{ for (; token_index < stream.end; ++token_index){ Cpp_Token *token_ptr = stream.tokens + token_index; switch (token_ptr->type){ + case CPP_TOKEN_IDENTIFIER: + { + if (token_ptr->size == old_lexeme.size){ + String_Const_u8 other_lexeme = scratch_read(app, scratch, buffer, *token_ptr); + if (string_match(old_lexeme, other_lexeme)){ + Buffer_Edit edit = {}; + edit.str_start = 0; + edit.len = (i32)replace_string.size; + edit.start = token_ptr->start; + edit.end = token_ptr->start + token_ptr->size; + if (edit_count < edit_max){ + edits[edit_count] = edit; + edit_count += 1; + } + else{ + goto doublebreak2; + } + } + } + }break; + case CPP_TOKEN_BRACE_OPEN: { - proc_body_found = 1; - goto doublebreak; + ++nesting_level; }break; case CPP_TOKEN_BRACE_CLOSE: - case CPP_TOKEN_PARENTHESE_OPEN: { - goto doublebreak; + if (nesting_level == 0){ + closed_correctly = 1; + goto doublebreak2; + } + else{ + --nesting_level; + } }break; } } still_looping = forward_stream_tokens(&stream); }while(still_looping); - doublebreak:; + doublebreak2:; - if (proc_body_found){ - - Query_Bar with; - char with_space[1024]; - with.prompt = make_lit_string("New Name: "); - with.string = make_fixed_width_string(with_space); - if (!query_user_string(app, &with)) return; - - String replace_string = with.string; - - Buffer_Edit *edits = push_array(part, Buffer_Edit, 0); - i32 edit_max = (part_remaining(part))/sizeof(Buffer_Edit); - i32 edit_count = 0; - - if (edit_max >= 1){ - Buffer_Edit edit; - edit.str_start = 0; - edit.len = replace_string.size; - edit.start = original_token.start; - edit.end = original_token.start + original_token.size; - - edits[edit_count] = edit; - ++edit_count; - } - - i32 nesting_level = 0; - i32 closed_correctly = 0; - ++token_index; - still_looping = 0; - do{ - for (; token_index < stream.end; ++token_index){ - Cpp_Token *token_ptr = stream.tokens + token_index; - switch (token_ptr->type){ - case CPP_TOKEN_IDENTIFIER: - { - if (token_ptr->size == old_lexeme.size){ - char other_lexeme_base[128]; - String other_lexeme = make_fixed_width_string(other_lexeme_base); - other_lexeme.size = old_lexeme.size; - buffer_read_range(app, buffer, token_ptr->start, token_ptr->start+token_ptr->size, other_lexeme.str); - - if (match(old_lexeme, other_lexeme)){ - Buffer_Edit edit; - edit.str_start = 0; - edit.len = replace_string.size; - edit.start = token_ptr->start; - edit.end = token_ptr->start + token_ptr->size; - - if (edit_count < edit_max){ - edits[edit_count] = edit; - ++edit_count; - } - else{ - goto doublebreak2; - } - } - } - }break; - - case CPP_TOKEN_BRACE_OPEN: - { - ++nesting_level; - }break; - - case CPP_TOKEN_BRACE_CLOSE: - { - if (nesting_level == 0){ - closed_correctly = 1; - goto doublebreak2; - } - else{ - --nesting_level; - } - }break; - } - } - still_looping = forward_stream_tokens(&stream); - }while(still_looping); - doublebreak2:; - - if (closed_correctly){ - buffer_batch_edit(app, buffer, replace_string.str, edits, edit_count); - } + if (closed_correctly){ + buffer_batch_edit(app, buffer, (char*)replace_string.str, edits, edit_count); } } } @@ -570,7 +560,7 @@ CUSTOM_DOC("If the cursor is found to be on the name of a function parameter in } } - end_temp_memory(temp); + end_temp(temp); } typedef u32 Write_Explicit_Enum_Values_Mode; @@ -589,9 +579,8 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu i32 pos = 0; view_get_cursor_pos(app, view, &pos); - Partition *part = &global_part; - - Temp_Memory temp = begin_temp_memory(part); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); Cpp_Get_Token_Result result; if (buffer_get_token_index(app, buffer, pos, &result)){ @@ -632,10 +621,9 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu i32 count_estimate = 1 + (seeker_index - token_index)/2; i32 edit_count = 0; - Buffer_Edit *edits = push_array(part, Buffer_Edit, count_estimate); + Buffer_Edit *edits = push_array(scratch, Buffer_Edit, count_estimate); - char *string_base = push_array(part, char, 0); - String string = make_string(string_base, 0, part_remaining(part)); + List_String_Const_char list = {}; closed_correctly = false; still_looping = false; @@ -680,24 +668,27 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu good_edit:; if (edit_is_good){ - i32 str_pos = string.size; + i32 str_pos = (i32)(list.total_size); - append(&string, " = "); - append_int_to_str(&string, value); + string_list_pushf(scratch, &list, " = %d", value); if (closed_correctly){ - append(&string, "\n"); + string_list_push_lit(scratch, &list, "\n"); } - if (mode == WriteExplicitEnumValues_Integers){ - ++value; - } - else if (mode == WriteExplicitEnumValues_Flags){ - if (value < (1 << 31)){ - value <<= 1; - } + switch (mode){ + case WriteExplicitEnumValues_Integers: + { + ++value; + }break; + case WriteExplicitEnumValues_Flags: + { + if (value < (1 << 31)){ + value <<= 1; + } + }break; } - i32 str_size = string.size - str_pos; + i32 str_size = (i32)(list.total_size) - str_pos; Buffer_Edit edit; edit.str_start = str_pos; @@ -727,7 +718,8 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu finished:; if (closed_correctly){ - buffer_batch_edit(app, buffer, string_base, edits, edit_count); + String_Const_char text = string_list_flatten(scratch, list); + buffer_batch_edit(app, buffer, text.str, edits, edit_count); } } } @@ -735,7 +727,7 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu } } - end_temp_memory(temp); + end_temp(temp); } CUSTOM_COMMAND_SIG(write_explicit_enum_values) @@ -755,91 +747,85 @@ CUSTOM_DOC("If the cursor is found to be on the '{' of an enum definition, the v // struct Replace_Target{ + Replace_Target *next; Buffer_ID buffer_id; i32 start_pos; }; static void -replace_all_occurrences_parameters(Application_Links *app, Heap *heap, Partition *part, String target_string, String new_string){ - if (target_string.size <= 0) return; - - global_history_edit_group_begin(app); - for (b32 got_all_occurrences = false; - !got_all_occurrences;){ +replace_all_occurrences_parameters(Application_Links *app, Heap *heap, String_Const_u8 target_string, String_Const_u8 new_string){ + if (target_string.size > 0){ + global_history_edit_group_begin(app); + // Initialize a generic search all buffers Search_Set set = {}; Search_Iter iter = {}; initialize_generic_search_all_buffers(app, heap, &target_string, 1, SearchFlag_MatchSubstring, 0, 0, &set, &iter); // Visit all locations and create replacement list - Temp_Memory temp = begin_temp_memory(part); - Replace_Target *targets = push_array(part, Replace_Target, 0); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); + + Replace_Target *target_first = 0; + Replace_Target *target_last = 0; i32 target_count = 0; - got_all_occurrences = true; for (Search_Match match = search_next_match(app, &set, &iter); match.found_match; match = search_next_match(app, &set, &iter)){ - Replace_Target *new_target = push_array(part, Replace_Target, 1); - if (new_target != 0){ - new_target->buffer_id = match.buffer; - new_target->start_pos = match.start; - ++target_count; - } - else{ - if (!has_substr(new_string, target_string)){ - got_all_occurrences = false; - } - else{ - print_message(app, literal("Could not replace all occurrences, ran out of memory\n")); - } - break; - } + Replace_Target *new_target = push_array(scratch, Replace_Target, 1); + sll_queue_push(target_first, target_last, new_target); + ++target_count; + new_target->buffer_id = match.buffer; + new_target->start_pos = match.start; } // Use replacement list to do replacements - i32 shift_per_replacement = new_string.size - target_string.size; - i32 current_offset = 0; - i32 current_buffer_id = 0; - Replace_Target *target = targets; - for (i32 i = 0; i < target_count; ++i, ++target){ + imem shift_per_replacement = new_string.size - target_string.size; + imem current_offset = 0; + Buffer_ID current_buffer_id = 0; + for (Replace_Target *target = target_first; + target != 0; + target = target->next){ if (target->buffer_id != current_buffer_id){ current_buffer_id = target->buffer_id; current_offset = 0; } - i32 pos = target->start_pos + current_offset; - buffer_replace_range(app, target->buffer_id, make_range(pos, pos + target_string.size), new_string); + i32 pos = target->start_pos + (i32)current_offset; + buffer_replace_range(app, target->buffer_id, make_range(pos, pos + (i32)target_string.size), new_string); current_offset += shift_per_replacement; } - end_temp_memory(temp); + end_temp(temp); + + global_history_edit_group_end(app); } - global_history_edit_group_end(app); } CUSTOM_COMMAND_SIG(replace_all_occurrences) CUSTOM_DOC("Queries the user for two strings, and replaces all occurrences of the first string with the second string in all open buffers.") { - Query_Bar replace; - char replace_space[1024]; - replace.prompt = make_lit_string("Replace (In All Buffers): "); - replace.string = make_fixed_width_string(replace_space); + u8 replace_space[1024]; + Query_Bar replace = {}; + replace.prompt = string_u8_litexpr("Replace (In All Buffers): "); + replace.string = SCu8(replace_space, (umem)0); + replace.string_capacity = sizeof(replace_space); - Query_Bar with; - char with_space[1024]; - with.prompt = make_lit_string("With: "); - with.string = make_fixed_width_string(with_space); + u8 with_space[1024]; + Query_Bar with = {}; + with.prompt = string_u8_litexpr("With: "); + with.string = SCu8(with_space, (umem)0); + with.string_capacity = sizeof(with_space); if (!query_user_string(app, &replace)) return; if (replace.string.size == 0) return; if (!query_user_string(app, &with)) return; - String r = replace.string; - String w = with.string; - - replace_all_occurrences_parameters(app, &global_heap, &global_part, r, w); + String_Const_u8 r = replace.string; + String_Const_u8 w = with.string; + replace_all_occurrences_parameters(app, &global_heap, r, w); } extern "C" i32 diff --git a/4coder_fancy.cpp b/4coder_fancy.cpp index f1d05a8c..d26350db 100644 --- a/4coder_fancy.cpp +++ b/4coder_fancy.cpp @@ -90,49 +90,45 @@ fancy_string_list_push(Fancy_String_List *list, Fancy_String *string){ } static Fancy_String * -push_fancy_string(Arena *arena, Fancy_String_List *list, Fancy_Color fore, Fancy_Color back, String value){ - Fancy_String *result = push_array(arena, Fancy_String, 1); - memset(result, 0, sizeof(*result)); - - result->value = string_push_copy(arena, value); +push_fancy_string(Arena *arena, Fancy_String_List *list, Fancy_Color fore, Fancy_Color back, String_Const_u8 value){ + Fancy_String *result = push_array_zero(arena, Fancy_String, 1); + result->value = string_copy(arena, value); result->fore = fore; result->back = back; - if (list != 0){ fancy_string_list_push(list, result); } - return(result); } static Fancy_String * -push_fancy_string(Arena *arena, Fancy_Color fore, Fancy_Color back, String value){ +push_fancy_string(Arena *arena, Fancy_Color fore, Fancy_Color back, String_Const_u8 value){ return(push_fancy_string(arena, 0, fore, back, value)); } static Fancy_String * -push_fancy_string(Arena *arena, Fancy_String_List *list, Fancy_Color fore, String value){ +push_fancy_string(Arena *arena, Fancy_String_List *list, Fancy_Color fore, String_Const_u8 value){ return(push_fancy_string(arena, list, fore, fancy_pass_through(), value)); } static Fancy_String * -push_fancy_string(Arena *arena, Fancy_Color fore, String value){ +push_fancy_string(Arena *arena, Fancy_Color fore, String_Const_u8 value){ return(push_fancy_string(arena, 0, fore, fancy_pass_through(), value)); } static Fancy_String * -push_fancy_string(Arena *arena, Fancy_String_List *list, String value){ +push_fancy_string(Arena *arena, Fancy_String_List *list, String_Const_u8 value){ return(push_fancy_string(arena, list, fancy_pass_through(), fancy_pass_through(), value)); } static Fancy_String * -push_fancy_string(Arena *arena, String value){ +push_fancy_string(Arena *arena, String_Const_u8 value){ return(push_fancy_string(arena, 0, fancy_pass_through(), fancy_pass_through(), value)); } static Fancy_String* push_fancy_stringfv(Arena *arena, Fancy_String_List *list, Fancy_Color fore, Fancy_Color back, char *format, va_list args){ - String str = string_push_fv(arena, format, args); + String_Const_u8 str = string_u8_pushfv(arena, format, args); Fancy_String *result = 0; if (str.size > 0){ result = push_fancy_string(arena, list, fore, back, str); diff --git a/4coder_fancy.h b/4coder_fancy.h index 793181dd..1cfa6e4e 100644 --- a/4coder_fancy.h +++ b/4coder_fancy.h @@ -38,7 +38,7 @@ struct Fancy_Color{ struct Fancy_String{ Fancy_String *next; - String value; + String_Const_u8 value; Face_ID font_id; Fancy_Color fore; diff --git a/4coder_file.h b/4coder_file.h index 72ce6db8..f0e11eb9 100644 --- a/4coder_file.h +++ b/4coder_file.h @@ -10,7 +10,7 @@ #include "4coder_lib/4coder_arena.h" #include "4coder_lib/4coder_arena.cpp" -#include "4coder_os_comp_cracking.h" +#include "4coder_base_types.h" #define FSTRING_IMPLEMENTATION #include "4coder_lib/4coder_string.h" @@ -18,9 +18,7 @@ #include #include -typedef int32_t bool32; - -#if defined(IS_WINDOWS) +#if OS_WINDOWS //// WINDOWS BEGIN //// #define UNICODE @@ -29,7 +27,7 @@ typedef TCHAR Filename_Character; #define SLASH '\\' //// WINDOWS END //// -#elif defined(IS_LINUX) || defined(IS_MAC) +#elif OS_LINUX || OS_MAC //// UNIX BEGIN //// #include @@ -47,7 +45,7 @@ typedef char Filename_Character; struct Cross_Platform_File_Info{ Filename_Character *name; int32_t len; - bool32 is_folder; + b32 is_folder; }; struct Cross_Platform_File_List{ @@ -57,18 +55,17 @@ struct Cross_Platform_File_List{ Filename_Character path_name[4096]; }; -typedef bool32 File_Filter(Filename_Character *name, int32_t len); +typedef b32 File_Filter(Filename_Character *name, int32_t len); static Cross_Platform_File_List -get_file_list(Partition *part, Filename_Character *dir, File_Filter *filter); +get_file_list(Arena *arena, Filename_Character *dir, File_Filter *filter); static Filename_Character* -encode(Partition *part, char *str){ +encode(Arena *arena, char *str){ int32_t size = 0; for (;str[size]!=0;++size); - Filename_Character *out = push_array(part, Filename_Character, size + 1); - push_align(part, 8); + Filename_Character *out = push_array(arena, Filename_Character, size + 1); if (out == 0){ fprintf(stdout, "fatal error: ran out of memory encoding string to filename\n"); @@ -86,10 +83,9 @@ encode(Partition *part, char *str){ } static char* -unencode(Partition *part, Filename_Character *str, int32_t len){ - Temp_Memory temp = begin_temp_memory(part); - char *out = push_array(part, char, len + 1); - push_align(part, 8); +unencode(Arena *arena, Filename_Character *str, int32_t len){ + Temp_Memory temp = begin_temp(arena); + char *out = push_array(arena, char, len + 1); if (out == 0){ fprintf(stdout, "fatal error: ran out of memory unencoding string to filename\n"); @@ -102,7 +98,7 @@ unencode(Partition *part, Filename_Character *str, int32_t len){ } else{ out = 0; - end_temp_memory(temp); + end_temp(temp); break; } } @@ -110,14 +106,14 @@ unencode(Partition *part, Filename_Character *str, int32_t len){ return(out); } -static bool32 +static b32 filter_all(Filename_Character *name, int32_t len){ return(true); } -static bool32 +static b32 filter_is_code_file(Filename_Character *name, int32_t len){ - bool32 is_code = false; + b32 is_code = false; if (len >= 5){ Filename_Character *ext = &name[len - 4]; if (ext[0] == '.' && ext[1] == 'c' && ext[2] == 'p' && ext[3] == 'p'){ @@ -145,12 +141,12 @@ filter_is_code_file(Filename_Character *name, int32_t len){ return(is_code); } -#if defined(IS_WINDOWS) +#if OS_WINDOWS //// WINDOWS BEGIN //// static Cross_Platform_File_List -get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter){ - if (part == 0){ +get_file_list(Arena *arena, Filename_Character *pattern, File_Filter *filter){ + if (arena == 0){ fprintf(stdout, "fatal error: NULL part passed to %s\n", __FUNCTION__); exit(1); } @@ -217,8 +213,8 @@ get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter) for(;name[size];++size); uint32_t attribs = find_data.dwFileAttributes; - bool32 is_folder = ((attribs & FILE_ATTRIBUTE_DIRECTORY) != 0); - bool32 is_hidden = ((attribs & FILE_ATTRIBUTE_HIDDEN) != 0); + b32 is_folder = ((attribs & FILE_ATTRIBUTE_DIRECTORY) != 0); + b32 is_hidden = ((attribs & FILE_ATTRIBUTE_HIDDEN) != 0); if (!is_hidden){ if (name[0] != '.' && (is_folder || filter(name, size))){ @@ -232,11 +228,11 @@ get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter) FindClose(search); Cross_Platform_File_List list = {}; - Temp_Memory part_reset = begin_temp_memory(part); + Temp_Memory part_reset = begin_temp(arena); int32_t rounded_char_size = (character_count*sizeof(Filename_Character) + 7)&(~7); int32_t memsize = rounded_char_size + file_count*sizeof(Cross_Platform_File_Info); - void *mem = push_array(part, uint8_t, memsize); + void *mem = push_array(arena, u8, memsize); if (mem == 0){ fprintf(stdout, "fatal error: not enough memory on the partition for a file list.\n"); exit(1); @@ -265,14 +261,14 @@ get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter) for(;name[size]!=0;++size); uint32_t attribs = find_data.dwFileAttributes; - bool32 is_folder = ((attribs & FILE_ATTRIBUTE_DIRECTORY) != 0); - bool32 is_hidden = ((attribs & FILE_ATTRIBUTE_HIDDEN) != 0); + b32 is_folder = ((attribs & FILE_ATTRIBUTE_DIRECTORY) != 0); + b32 is_hidden = ((attribs & FILE_ATTRIBUTE_HIDDEN) != 0); if (!is_hidden){ if (name[0] != '.' && (is_folder || filter(name, size))){ if (info_ptr + 1 > info_ptr_end || char_ptr + size + 1 > char_ptr_end){ memset(&list, 0, sizeof(list)); - end_temp_memory(part_reset); + end_temp(part_reset); FindClose(search); return(list); } @@ -304,12 +300,12 @@ get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter) } //// WINDOWS END //// -#elif defined(IS_LINUX) || defined(IS_MAC) +#elif OS_LINUX || OS_MAC //// UNIX BEGIN //// -static bool32 +static b32 match_pattern(Filename_Character *name, Filename_Character *pattern){ - bool32 match = false; + b32 match = false; if (sizeof(*name) == 1){ Absolutes absolutes = {}; String pattern_str = make_string_slowly(pattern); @@ -380,7 +376,7 @@ get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter) int32_t size = 0; for(;name[size];++size); - bool32 is_folder = false; + b32 is_folder = false; if (entry->d_type == DT_LNK){ struct stat st; if (stat(entry->d_name, &st) != -1){ @@ -430,7 +426,7 @@ get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter) int32_t size = 0; for(;name[size];++size); - bool32 is_folder = false; + b32 is_folder = false; if (entry->d_type == DT_LNK){ struct stat st; if (stat(entry->d_name, &st) != -1){ @@ -477,27 +473,23 @@ get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter) # error metdata generator not supported on this platform #endif -static String -file_dump(Partition *part, char *name){ - String text = {}; - +static String_Const_char +file_dump(Arena *arena, char *name){ + String_Const_char text = {}; FILE *file = fopen(name, "rb"); if (file != 0){ fseek(file, 0, SEEK_END); text.size = ftell(file); fseek(file, 0, SEEK_SET); - text.memory_size = text.size + 1; - text.str = push_array(part, char, text.memory_size); - push_align(part, 8); + text.str = push_array(arena, char, text.size + 1); if (text.str == 0){ fprintf(stdout, "fatal error: not enough memory in partition for file dumping"); exit(1); } fread(text.str, 1, text.size, file); - terminate_with_null(&text); + text.str[text.size] = 0; fclose(file); } - return(text); } diff --git a/4coder_font_helper.cpp b/4coder_font_helper.cpp index 8f28bdc5..4a882e85 100644 --- a/4coder_font_helper.cpp +++ b/4coder_font_helper.cpp @@ -4,6 +4,7 @@ // TOP +// TODO(allen): transition wrappers static Face_Description get_buffer_face_description(Application_Links *app, Buffer_ID buffer){ Face_ID current_id = 0; @@ -17,7 +18,8 @@ get_buffer_face_description(Application_Links *app, Buffer_ID buffer){ static Face_Description get_global_face_description(Application_Links *app){ - Face_ID current_id = get_face_id(app, 0); + Face_ID current_id = 0; + get_face_id(app, 0, ¤t_id); Face_Description description = get_face_description(app, current_id); return(description); } @@ -25,7 +27,7 @@ get_global_face_description(Application_Links *app){ static b32 descriptions_match(Face_Description *a, Face_Description *b){ b32 result = false; - if (match(a->font.name, b->font.name) && a->font.in_local_font_folder == b->font.in_local_font_folder){ + if (string_match(SCchar(a->font.name), SCchar(b->font.name)) && a->font.in_local_font_folder == b->font.in_local_font_folder){ if (memcmp((&a->pt_size), (&b->pt_size), sizeof(*a) - sizeof(a->font)) == 0){ result = true; } @@ -34,13 +36,12 @@ descriptions_match(Face_Description *a, Face_Description *b){ } static Face_ID -get_existing_face_id_matching_name(Application_Links *app, char *name, i32 len){ - String name_str = make_string(name, len); +get_existing_face_id_matching_name(Application_Links *app, String_Const_u8 name){ Face_ID largest_id = get_largest_face_id(app); Face_ID result = 0; for (Face_ID id = 1; id <= largest_id; ++id){ Face_Description compare = get_face_description(app, id); - if (match(compare.font.name, name_str)){ + if (string_match(SCu8(compare.font.name), name)){ result = id; break; } @@ -63,15 +64,15 @@ get_existing_face_id_matching_description(Application_Links *app, Face_Descripti } static Face_ID -get_face_id_by_name(Application_Links *app, char *name, i32 len, Face_Description *base_description){ +get_face_id_by_name(Application_Links *app, String_Const_u8 name, Face_Description *base_description){ Face_ID new_id = 0; - String str = make_string(name, len); - if (!match(str, base_description->font.name)){ - new_id = get_existing_face_id_matching_name(app, name, len); + name.size = clamp_top(name.size, sizeof(base_description->font.name) - 1); + if (!string_match(name, SCu8(base_description->font.name))){ + new_id = get_existing_face_id_matching_name(app, name); if (new_id == 0){ Face_Description description = *base_description; - copy_fast_unsafe_cs(description.font.name, str); - description.font.name[str.size] = 0; + block_copy(description.font.name, name.str, name.size); + description.font.name[name.size] = 0; description.font.in_local_font_folder = false; new_id = try_create_new_face(app, &description); if (new_id == 0){ @@ -96,10 +97,11 @@ get_face_id_by_description(Application_Links *app, Face_Description *description } static void -set_global_face_by_name(Application_Links *app, char *name, i32 len, b32 apply_to_all_buffers){ - Face_ID global_face_id = get_face_id(app, 0); +set_global_face_by_name(Application_Links *app, String_Const_u8 name, b32 apply_to_all_buffers){ + Face_ID global_face_id = 0; + get_face_id(app, 0, &global_face_id); Face_Description description = get_face_description(app, global_face_id); - Face_ID new_id = get_face_id_by_name(app, name, len, &description); + Face_ID new_id = get_face_id_by_name(app, name, &description); if (new_id != 0){ set_global_face(app, new_id, apply_to_all_buffers); } @@ -107,7 +109,8 @@ set_global_face_by_name(Application_Links *app, char *name, i32 len, b32 apply_t static void change_global_face_by_description(Application_Links *app, Face_Description description, b32 apply_to_all_buffers){ - Face_ID face_id = get_face_id(app, 0); + Face_ID face_id = 0; + get_face_id(app, 0, &face_id); if (!try_modify_face(app, face_id, &description)){ description.font.in_local_font_folder = !description.font.in_local_font_folder; try_modify_face(app, face_id, &description); @@ -115,12 +118,12 @@ change_global_face_by_description(Application_Links *app, Face_Description descr } static void -set_buffer_face_by_name(Application_Links *app, Buffer_ID buffer, char *name, i32 len){ +set_buffer_face_by_name(Application_Links *app, Buffer_ID buffer, String_Const_u8 name){ Face_ID current_id = 0; get_face_id(app, buffer, ¤t_id); if (current_id != 0){ Face_Description description = get_face_description(app, current_id); - Face_ID new_id = get_face_id_by_name(app, name, len, &description); + Face_ID new_id = get_face_id_by_name(app, name, &description); if (new_id != 0){ buffer_set_face(app, buffer, new_id); } diff --git a/4coder_function_list.cpp b/4coder_function_list.cpp index ac401e15..92f2e794 100644 --- a/4coder_function_list.cpp +++ b/4coder_function_list.cpp @@ -10,53 +10,6 @@ // iterating tokens is now. // -static Buffered_Write_Stream -make_buffered_write_stream(Buffer_ID output_buffer_id, Partition *buffering_arena){ - Buffered_Write_Stream stream = {}; - stream.output_buffer_id = output_buffer_id; - stream.buffering_arena = buffering_arena; - stream.buffer = push_array(buffering_arena, char, 0); - return(stream); -} - -static void -buffered_write_stream_flush(Application_Links *app, Buffered_Write_Stream *stream){ - Buffer_ID buffer = stream->output_buffer_id; - i32 buffer_size = 0; - buffer_get_size(app, buffer, &buffer_size); - i32 stream_size = (i32)(push_array(stream->buffering_arena, char, 0) - stream->buffer); - buffer_replace_range(app, buffer, make_range(buffer_size), make_string(stream->buffer, stream_size)); - stream->buffering_arena->pos -= stream_size; -} - -static void -buffered_write_stream_write(Application_Links *app, Buffered_Write_Stream *stream, String text){ - for (;text.size > 0;){ - char *buffered = push_array(stream->buffering_arena, char, text.size); - if (buffered != 0){ - memcpy(buffered, text.str, text.size); - text.size = 0; - } - else{ - i32 partial_size = part_remaining(stream->buffering_arena); - buffered = push_array(stream->buffering_arena, char, partial_size); - Assert(partial_size < text.size); - memcpy(buffered, text.str, partial_size); - text.size -= partial_size; - text.str += partial_size; - buffered_write_stream_flush(app, stream); - } - } -} - -static void -buffered_write_stream_write_int(Application_Links *app, Buffered_Write_Stream *stream, i32 x){ - char space[128]; - String integer_string = make_fixed_width_string(space); - append_int_to_str(&integer_string, x); - buffered_write_stream_write(app, stream, integer_string); -} - static Get_Positions_Results get_function_positions(Application_Links *app, Buffer_ID buffer, i32 first_token_index, Function_Positions *positions_array, i32 positions_max){ Get_Positions_Results result = {}; @@ -188,11 +141,13 @@ get_function_positions(Application_Links *app, Buffer_ID buffer, i32 first_token } static void -print_positions_buffered(Application_Links *app, Buffer_ID buffer, Function_Positions *positions_array, i32 positions_count, Buffered_Write_Stream *stream){ +print_positions_buffered(Application_Links *app, Buffer_Insertion *out, Function_Positions *positions_array, i32 positions_count){ Arena *scratch = context_get_arena(app); - Temp_Memory_Arena temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); - String buffer_name = buffer_push_unique_buffer_name(app, buffer, scratch); + Buffer_ID buffer = out->buffer; + + String_Const_u8 buffer_name = buffer_push_unique_buffer_name(app, buffer, scratch); for (i32 i = 0; i < positions_count; ++i){ Function_Positions *positions = &positions_array[i]; @@ -206,10 +161,7 @@ print_positions_buffered(Application_Links *app, Buffer_ID buffer, Function_Posi Token_Range token_range = buffer_get_token_range(app, buffer); if (token_range.first != 0){ - buffered_write_stream_write(app, stream, buffer_name); - buffered_write_stream_write(app, stream, make_lit_string(":")); - buffered_write_stream_write_int(app, stream, line_number); - buffered_write_stream_write(app, stream, make_lit_string(": ")); + insertf(out, "%.*s:%d: ", string_expand(buffer_name), line_number); Cpp_Token prev_token = {}; Token_Iterator token_it = make_token_iterator(token_range, start_index); @@ -217,13 +169,6 @@ print_positions_buffered(Application_Links *app, Buffer_ID buffer, Function_Posi token != 0 && token_iterator_current_index(&token_it) <= end_index; token = token_iterator_goto_next_raw(&token_it)){ if ((token->flags & CPP_TFLAG_PP_BODY) == 0 && token->type != CPP_TOKEN_COMMENT){ - char space[2 << 10]; - i32 token_size = token->size; - if (token_size > sizeof(space)){ - token_size = sizeof(space); - } - buffer_read_range(app, buffer, token->start, token->start + token_size, space); - if ((prev_token.type == CPP_TOKEN_IDENTIFIER || prev_token.type == CPP_TOKEN_STAR || prev_token.type == CPP_TOKEN_COMMA || @@ -234,24 +179,29 @@ print_positions_buffered(Application_Links *app, Buffer_ID buffer, Function_Posi token->type == CPP_TOKEN_COMMA ) ){ - buffered_write_stream_write(app, stream, make_lit_string(" ")); + insertc(out, ' '); } - buffered_write_stream_write(app, stream, make_string(space, token_size)); + + Temp_Memory token_temp = begin_temp(scratch); + String_Const_u8 lexeme = get_token_lexeme(app, scratch, buffer, *token); + insert_string(out, lexeme); + end_temp(token_temp); prev_token = *token; } } - buffered_write_stream_write(app, stream, make_lit_string("\n")); + insertc(out, '\n'); } } - end_temp_memory(temp); + end_temp(temp); } static void -list_all_functions(Application_Links *app, Partition *part, Buffer_ID optional_target_buffer){ - String decls_name = make_lit_string("*decls*"); +list_all_functions(Application_Links *app, Buffer_ID optional_target_buffer){ + // TODO(allen): Use create or switch to buffer and clear here? + String_Const_u8 decls_name = string_u8_litexpr("*decls*"); Buffer_ID decls_buffer = 0; get_buffer_by_name(app, decls_name, AccessAll, &decls_buffer); if (!buffer_exists(app, decls_buffer)){ @@ -264,15 +214,18 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_ID optional_t buffer_send_end_signal(app, decls_buffer); i32 size = 0; buffer_get_size(app, decls_buffer, &size); - buffer_replace_range(app, decls_buffer, make_range(0, size), make_lit_string("")); + buffer_replace_range(app, decls_buffer, make_range(0, size), string_u8_litexpr("")); } - Temp_Memory temp = begin_temp_memory(part); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); + // TODO(allen): rewrite get_function_positions to allocate on arena i32 positions_max = (4<<10)/sizeof(Function_Positions); - Function_Positions *positions_array = push_array(part, Function_Positions, positions_max); + Function_Positions *positions_array = push_array(scratch, Function_Positions, positions_max); - Buffered_Write_Stream buffered_write_stream = make_buffered_write_stream(decls_buffer, part); + Cursor insertion_cursor = make_cursor(push_array(scratch, u8, KB(256)), KB(256)); + Buffer_Insertion out = begin_buffer_insertion_at_buffered(app, decls_buffer, 0, &insertion_cursor); Buffer_ID buffer_it = 0; for (get_buffer_next(app, 0, AccessAll, &buffer_it); @@ -293,8 +246,7 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_ID optional_t token_index = get_positions_results.next_token_index; still_looping = get_positions_results.still_looping; - print_positions_buffered(app, buffer, positions_array, positions_count, &buffered_write_stream); - //print_positions(app, &buffer, positions_array, positions_count, &decls_buffer, part); + print_positions_buffered(app, &out, positions_array, positions_count); }while(still_looping); if (optional_target_buffer != 0){ @@ -306,15 +258,15 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_ID optional_t } } - buffered_write_stream_flush(app, &buffered_write_stream); + end_buffer_insertion(&out); View_ID view = 0; get_active_view(app, AccessAll, &view); view_set_buffer(app, view, decls_buffer, 0); - lock_jump_buffer(decls_name.str, decls_name.size); + lock_jump_buffer(decls_name); - end_temp_memory(temp); + end_temp(temp); } @@ -326,7 +278,7 @@ CUSTOM_DOC("Creates a jump list of lines of the current buffer that appear to de Buffer_ID buffer = 0; view_get_buffer(app, view, AccessProtected, &buffer); if (buffer_exists(app, buffer)){ - list_all_functions(app, &global_part, buffer); + list_all_functions(app, buffer); } } @@ -338,27 +290,27 @@ CUSTOM_DOC("Creates a lister of locations that look like function definitions an Buffer_ID buffer = 0; view_get_buffer(app, view, AccessProtected, &buffer); if (buffer_exists(app, buffer)){ - list_all_functions(app, &global_part, buffer); + list_all_functions(app, buffer); get_active_view(app, AccessAll, &view); - open_jump_lister(app, &global_part, &global_heap, view, buffer, JumpListerActivation_OpenInUIView, 0); + open_jump_lister(app, &global_heap, view, buffer, JumpListerActivation_OpenInUIView, 0); } } CUSTOM_COMMAND_SIG(list_all_functions_all_buffers) CUSTOM_DOC("Creates a jump list of lines from all buffers that appear to define or declare functions.") { - list_all_functions(app, &global_part, 0); + list_all_functions(app, 0); } CUSTOM_COMMAND_SIG(list_all_functions_all_buffers_lister) CUSTOM_DOC("Creates a lister of locations that look like function definitions and declarations all buffers.") { - list_all_functions(app, &global_part, 0); + list_all_functions(app, 0); View_ID view = 0; get_active_view(app, AccessAll, &view); Buffer_ID buffer = 0; view_get_buffer(app, view, AccessAll, &buffer); - open_jump_lister(app, &global_part, &global_heap, view, buffer, JumpListerActivation_OpenInUIView, 0); + open_jump_lister(app, &global_heap, view, buffer, JumpListerActivation_OpenInUIView, 0); } // BOTTOM diff --git a/4coder_function_list.h b/4coder_function_list.h index a45d13b5..95c698e7 100644 --- a/4coder_function_list.h +++ b/4coder_function_list.h @@ -19,12 +19,6 @@ struct Get_Positions_Results{ b32 still_looping; }; -struct Buffered_Write_Stream{ - Buffer_ID output_buffer_id; - Partition *buffering_arena; - char *buffer; -}; - #endif // BOTTOM diff --git a/4coder_generated/app_functions.h b/4coder_generated/app_functions.h index fd8e1b9b..8ed76c67 100644 --- a/4coder_generated/app_functions.h +++ b/4coder_generated/app_functions.h @@ -3,21 +3,22 @@ struct Application_Links; #define GLOBAL_SET_MAPPING_SIG(n) b32 n(Application_Links *app, void *data, i32 size) #define GLOBAL_GET_SCREEN_RECTANGLE_SIG(n) b32 n(Application_Links *app, Rect_f32 *rect_out) #define CONTEXT_GET_ARENA_SIG(n) Arena* n(Application_Links *app) -#define CREATE_CHILD_PROCESS_SIG(n) b32 n(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out) +#define CONTEXT_GET_BASE_ALLOCATOR_SIG(n) Base_Allocator* n(Application_Links *app) +#define CREATE_CHILD_PROCESS_SIG(n) b32 n(Application_Links *app, String_Const_u8 path, String_Const_u8 command, Child_Process_ID *child_process_id_out) #define CHILD_PROCESS_SET_TARGET_BUFFER_SIG(n) b32 n(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags) #define BUFFER_GET_ATTACHED_CHILD_PROCESS_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Child_Process_ID *child_process_id_out) #define CHILD_PROCESS_GET_ATTACHED_BUFFER_SIG(n) b32 n(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID *buffer_id_out) #define CHILD_PROCESS_GET_STATE_SIG(n) b32 n(Application_Links *app, Child_Process_ID child_process_id, Process_State *process_state_out) -#define CLIPBOARD_POST_SIG(n) b32 n(Application_Links *app, i32 clipboard_id, String string) +#define CLIPBOARD_POST_SIG(n) b32 n(Application_Links *app, i32 clipboard_id, String_Const_u8 string) #define CLIPBOARD_COUNT_SIG(n) b32 n(Application_Links *app, i32 clipboard_id, i32 *count_out) -#define CLIPBOARD_INDEX_SIG(n) b32 n(Application_Links *app, i32 clipboard_id, i32 item_index, String *string_out, i32 *required_size_out) +#define CLIPBOARD_INDEX_SIG(n) b32 n(Application_Links *app, i32 clipboard_id, i32 item_index, Arena *out, String_Const_u8 *string_out) #define CREATE_PARSE_CONTEXT_SIG(n) Parse_Context_ID n(Application_Links *app, Parser_String_And_Type *kw, u32 kw_count, Parser_String_And_Type *pp, u32 pp_count) #define GET_BUFFER_COUNT_SIG(n) i32 n(Application_Links *app) #define GET_BUFFER_NEXT_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_ID *buffer_id_out) -#define GET_BUFFER_BY_NAME_SIG(n) b32 n(Application_Links *app, String name, Access_Flag access, Buffer_ID *buffer_id_out) -#define GET_BUFFER_BY_FILE_NAME_SIG(n) b32 n(Application_Links *app, String file_name, Access_Flag access, Buffer_ID *buffer_id_out) +#define GET_BUFFER_BY_NAME_SIG(n) b32 n(Application_Links *app, String_Const_u8 name, Access_Flag access, Buffer_ID *buffer_id_out) +#define GET_BUFFER_BY_FILE_NAME_SIG(n) b32 n(Application_Links *app, String_Const_u8 file_name, Access_Flag access, Buffer_ID *buffer_id_out) #define BUFFER_READ_RANGE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 one_past_last, char *out) -#define BUFFER_REPLACE_RANGE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Range range, String string) +#define BUFFER_REPLACE_RANGE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Range range, String_Const_u8 string) #define BUFFER_BATCH_EDIT_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, char *str, Buffer_Edit *edits, i32 edit_count) #define BUFFER_COMPUTE_CURSOR_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Buffer_Seek seek, Partial_Cursor *cursor_out) #define BUFFER_EXISTS_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id) @@ -25,9 +26,9 @@ struct Application_Links; #define BUFFER_GET_ACCESS_FLAGS_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Access_Flag *access_flags_out) #define BUFFER_GET_SIZE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, i32 *size_out) #define BUFFER_GET_LINE_COUNT_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, i32 *line_count_out) -#define BUFFER_GET_BASE_BUFFER_NAME_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out) -#define BUFFER_GET_UNIQUE_BUFFER_NAME_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out) -#define BUFFER_GET_FILE_NAME_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out) +#define BUFFER_GET_BASE_BUFFER_NAME_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out) +#define BUFFER_GET_UNIQUE_BUFFER_NAME_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out) +#define BUFFER_GET_FILE_NAME_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out) #define BUFFER_GET_DIRTY_STATE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Dirty_State *dirty_state_out) #define BUFFER_DIRECTLY_SET_DIRTY_STATE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Dirty_State dirty_state) #define BUFFER_TOKENS_ARE_READY_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id) @@ -39,8 +40,8 @@ struct Application_Links; #define BUFFER_GET_TOKEN_RANGE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Cpp_Token **first_token_out, Cpp_Token **one_past_last_token_out) #define BUFFER_GET_TOKEN_INDEX_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, i32 pos, Cpp_Get_Token_Result *get_result) #define BUFFER_SEND_END_SIGNAL_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id) -#define CREATE_BUFFER_SIG(n) b32 n(Application_Links *app, String file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out) -#define BUFFER_SAVE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, String file_name, u32 flags) +#define CREATE_BUFFER_SIG(n) b32 n(Application_Links *app, String_Const_u8 file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out) +#define BUFFER_SAVE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, String_Const_u8 file_name, u32 flags) #define BUFFER_KILL_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Buffer_Kill_Flag flags, Buffer_Kill_Result *result_out) #define BUFFER_REOPEN_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag flags, Buffer_Reopen_Result *result_out) #define BUFFER_GET_FILE_ATTRIBUTES_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, File_Attributes *attributes_out) @@ -105,7 +106,7 @@ struct Application_Links; #define MARKER_VISUAL_SET_VIEW_KEY_SIG(n) b32 n(Application_Links *app, Marker_Visual visual, View_ID key_view_id) #define DESTROY_MARKER_VISUAL_SIG(n) b32 n(Application_Links *app, Marker_Visual visual) #define BUFFER_MARKERS_GET_ATTACHED_VISUAL_COUNT_SIG(n) i32 n(Application_Links *app, Managed_Object object) -#define BUFFER_MARKERS_GET_ATTACHED_VISUAL_SIG(n) Marker_Visual* n(Application_Links *app, Partition *part, Managed_Object object) +#define BUFFER_MARKERS_GET_ATTACHED_VISUAL_SIG(n) Marker_Visual* n(Application_Links *app, Arena *arena, Managed_Object object) #define MANAGED_OBJECT_GET_ITEM_SIZE_SIG(n) u32 n(Application_Links *app, Managed_Object object) #define MANAGED_OBJECT_GET_ITEM_COUNT_SIG(n) u32 n(Application_Links *app, Managed_Object object) #define MANAGED_OBJECT_GET_TYPE_SIG(n) Managed_Object_Type n(Application_Links *app, Managed_Object object) @@ -120,7 +121,7 @@ struct Application_Links; #define GET_ACTIVE_QUERY_BARS_SIG(n) b32 n(Application_Links *app, View_ID view_id, i32 max_result_count, Query_Bar_Ptr_Array *array_out) #define START_QUERY_BAR_SIG(n) b32 n(Application_Links *app, Query_Bar *bar, u32 flags) #define END_QUERY_BAR_SIG(n) void n(Application_Links *app, Query_Bar *bar, u32 flags) -#define PRINT_MESSAGE_SIG(n) b32 n(Application_Links *app, String message) +#define PRINT_MESSAGE_SIG(n) b32 n(Application_Links *app, String_Const_u8 message) #define GET_LARGEST_FACE_ID_SIG(n) Face_ID n(Application_Links *app) #define SET_GLOBAL_FACE_SIG(n) b32 n(Application_Links *app, Face_ID id, b32 apply_to_all_buffers) #define BUFFER_HISTORY_GET_MAX_RECORD_INDEX_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, History_Record_Index *index_out) @@ -144,26 +145,26 @@ struct Application_Links; #define SET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, i32 count) #define GET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, i32 count) #define FINALIZE_COLOR_SIG(n) argb_color n(Application_Links *app, int_color color) -#define GET_HOT_DIRECTORY_SIG(n) b32 n(Application_Links *app, String *out, i32 *required_size_out) -#define SET_HOT_DIRECTORY_SIG(n) b32 n(Application_Links *app, String string) -#define GET_FILE_LIST_SIG(n) b32 n(Application_Links *app, String directory, File_List *list_out) +#define GET_HOT_DIRECTORY_SIG(n) b32 n(Application_Links *app, Arena *out, String_Const_u8 *out_directory) +#define SET_HOT_DIRECTORY_SIG(n) b32 n(Application_Links *app, String_Const_u8 string) +#define GET_FILE_LIST_SIG(n) b32 n(Application_Links *app, String_Const_u8 directory, File_List *list_out) #define FREE_FILE_LIST_SIG(n) void n(Application_Links *app, File_List list) #define SET_GUI_UP_DOWN_KEYS_SIG(n) void n(Application_Links *app, Key_Code up_key, Key_Modifier up_key_modifier, Key_Code down_key, Key_Modifier down_key_modifier) #define MEMORY_ALLOCATE_SIG(n) void* n(Application_Links *app, i32 size) #define MEMORY_SET_PROTECTION_SIG(n) b32 n(Application_Links *app, void *ptr, i32 size, Memory_Protect_Flags flags) #define MEMORY_FREE_SIG(n) void n(Application_Links *app, void *ptr, i32 size) -#define FILE_GET_ATTRIBUTES_SIG(n) b32 n(Application_Links *app, String file_name, File_Attributes *attributes_out) -#define DIRECTORY_CD_SIG(n) b32 n(Application_Links *app, String *directory, String relative_path) -#define GET_4ED_PATH_SIG(n) b32 n(Application_Links *app, String *path_out, i32 *required_size_out) +#define FILE_GET_ATTRIBUTES_SIG(n) b32 n(Application_Links *app, String_Const_u8 file_name, File_Attributes *attributes_out) +#define DIRECTORY_CD_SIG(n) b32 n(Application_Links *app, String_Const_u8 directory, String_Const_u8 relative_path, Arena *out, String_Const_u8 *directory_out) +#define GET_4ED_PATH_SIG(n) b32 n(Application_Links *app, Arena *out, String_Const_u8 *path_out) #define SHOW_MOUSE_CURSOR_SIG(n) void n(Application_Links *app, Mouse_Cursor_Show_Type show) #define SET_EDIT_FINISHED_HOOK_REPEAT_SPEED_SIG(n) b32 n(Application_Links *app, u32 milliseconds) #define SET_FULLSCREEN_SIG(n) b32 n(Application_Links *app, b32 full_screen) #define IS_FULLSCREEN_SIG(n) b32 n(Application_Links *app) #define SEND_EXIT_SIGNAL_SIG(n) void n(Application_Links *app) -#define SET_WINDOW_TITLE_SIG(n) b32 n(Application_Links *app, String title) +#define SET_WINDOW_TITLE_SIG(n) b32 n(Application_Links *app, String_Const_u8 title) #define GET_MICROSECONDS_TIMESTAMP_SIG(n) Microsecond_Time_Stamp n(Application_Links *app) -#define DRAW_STRING_SIG(n) Vec2 n(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta) -#define GET_STRING_ADVANCE_SIG(n) f32 n(Application_Links *app, Face_ID font_id, String str) +#define DRAW_STRING_SIG(n) Vec2 n(Application_Links *app, Face_ID font_id, String_Const_u8 str, Vec2 point, int_color color, u32 flags, Vec2 delta) +#define GET_STRING_ADVANCE_SIG(n) f32 n(Application_Links *app, Face_ID font_id, String_Const_u8 str) #define DRAW_RECTANGLE_SIG(n) void n(Application_Links *app, Rect_f32 rect, int_color color) #define DRAW_RECTANGLE_OUTLINE_SIG(n) void n(Application_Links *app, f32_Rect rect, int_color color) #define DRAW_CLIP_PUSH_SIG(n) void n(Application_Links *app, f32_Rect clip_box) @@ -180,12 +181,13 @@ struct Application_Links; #define DRAW_RENDER_LAYOUT_SIG(n) void n(Application_Links *app, View_ID view_id) #define OPEN_COLOR_PICKER_SIG(n) void n(Application_Links *app, color_picker *picker) #define ANIMATE_IN_N_MILLISECONDS_SIG(n) void n(Application_Links *app, u32 n) -#define FIND_ALL_IN_RANGE_INSENSITIVE_SIG(n) Found_String_List n(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String key, Partition *memory) +#define FIND_ALL_IN_RANGE_INSENSITIVE_SIG(n) Found_String_List n(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String_Const_u8 key, Arena *arena) #define GET_VIEW_VISIBLE_RANGE_SIG(n) Range n(Application_Links *app, View_ID view_id) typedef GLOBAL_SET_SETTING_SIG(Global_Set_Setting_Function); typedef GLOBAL_SET_MAPPING_SIG(Global_Set_Mapping_Function); typedef GLOBAL_GET_SCREEN_RECTANGLE_SIG(Global_Get_Screen_Rectangle_Function); typedef CONTEXT_GET_ARENA_SIG(Context_Get_Arena_Function); +typedef CONTEXT_GET_BASE_ALLOCATOR_SIG(Context_Get_Base_Allocator_Function); typedef CREATE_CHILD_PROCESS_SIG(Create_Child_Process_Function); typedef CHILD_PROCESS_SET_TARGET_BUFFER_SIG(Child_Process_Set_Target_Buffer_Function); typedef BUFFER_GET_ATTACHED_CHILD_PROCESS_SIG(Buffer_Get_Attached_Child_Process_Function); @@ -371,6 +373,7 @@ Global_Set_Setting_Function *global_set_setting; Global_Set_Mapping_Function *global_set_mapping; Global_Get_Screen_Rectangle_Function *global_get_screen_rectangle; Context_Get_Arena_Function *context_get_arena; +Context_Get_Base_Allocator_Function *context_get_base_allocator; Create_Child_Process_Function *create_child_process; Child_Process_Set_Target_Buffer_Function *child_process_set_target_buffer; Buffer_Get_Attached_Child_Process_Function *buffer_get_attached_child_process; @@ -555,6 +558,7 @@ Global_Set_Setting_Function *global_set_setting_; Global_Set_Mapping_Function *global_set_mapping_; Global_Get_Screen_Rectangle_Function *global_get_screen_rectangle_; Context_Get_Arena_Function *context_get_arena_; +Context_Get_Base_Allocator_Function *context_get_base_allocator_; Create_Child_Process_Function *create_child_process_; Child_Process_Set_Target_Buffer_Function *child_process_set_target_buffer_; Buffer_Get_Attached_Child_Process_Function *buffer_get_attached_child_process_; @@ -747,6 +751,7 @@ app_links->global_set_setting_ = Global_Set_Setting;\ app_links->global_set_mapping_ = Global_Set_Mapping;\ app_links->global_get_screen_rectangle_ = Global_Get_Screen_Rectangle;\ app_links->context_get_arena_ = Context_Get_Arena;\ +app_links->context_get_base_allocator_ = Context_Get_Base_Allocator;\ app_links->create_child_process_ = Create_Child_Process;\ app_links->child_process_set_target_buffer_ = Child_Process_Set_Target_Buffer;\ app_links->buffer_get_attached_child_process_ = Buffer_Get_Attached_Child_Process;\ @@ -931,21 +936,22 @@ static b32 global_set_setting(Application_Links *app, Global_Setting_ID setting, static b32 global_set_mapping(Application_Links *app, void *data, i32 size){return(app->global_set_mapping(app, data, size));} static b32 global_get_screen_rectangle(Application_Links *app, Rect_f32 *rect_out){return(app->global_get_screen_rectangle(app, rect_out));} static Arena* context_get_arena(Application_Links *app){return(app->context_get_arena(app));} -static b32 create_child_process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){return(app->create_child_process(app, path, command, child_process_id_out));} +static Base_Allocator* context_get_base_allocator(Application_Links *app){return(app->context_get_base_allocator(app));} +static b32 create_child_process(Application_Links *app, String_Const_u8 path, String_Const_u8 command, Child_Process_ID *child_process_id_out){return(app->create_child_process(app, path, command, child_process_id_out));} static b32 child_process_set_target_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags){return(app->child_process_set_target_buffer(app, child_process_id, buffer_id, flags));} static b32 buffer_get_attached_child_process(Application_Links *app, Buffer_ID buffer_id, Child_Process_ID *child_process_id_out){return(app->buffer_get_attached_child_process(app, buffer_id, child_process_id_out));} static b32 child_process_get_attached_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID *buffer_id_out){return(app->child_process_get_attached_buffer(app, child_process_id, buffer_id_out));} static b32 child_process_get_state(Application_Links *app, Child_Process_ID child_process_id, Process_State *process_state_out){return(app->child_process_get_state(app, child_process_id, process_state_out));} -static b32 clipboard_post(Application_Links *app, i32 clipboard_id, String string){return(app->clipboard_post(app, clipboard_id, string));} +static b32 clipboard_post(Application_Links *app, i32 clipboard_id, String_Const_u8 string){return(app->clipboard_post(app, clipboard_id, string));} static b32 clipboard_count(Application_Links *app, i32 clipboard_id, i32 *count_out){return(app->clipboard_count(app, clipboard_id, count_out));} -static b32 clipboard_index(Application_Links *app, i32 clipboard_id, i32 item_index, String *string_out, i32 *required_size_out){return(app->clipboard_index(app, clipboard_id, item_index, string_out, required_size_out));} +static b32 clipboard_index(Application_Links *app, i32 clipboard_id, i32 item_index, Arena *out, String_Const_u8 *string_out){return(app->clipboard_index(app, clipboard_id, item_index, out, string_out));} static Parse_Context_ID create_parse_context(Application_Links *app, Parser_String_And_Type *kw, u32 kw_count, Parser_String_And_Type *pp, u32 pp_count){return(app->create_parse_context(app, kw, kw_count, pp, pp_count));} static i32 get_buffer_count(Application_Links *app){return(app->get_buffer_count(app));} static b32 get_buffer_next(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_next(app, buffer_id, access, buffer_id_out));} -static b32 get_buffer_by_name(Application_Links *app, String name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_name(app, name, access, buffer_id_out));} -static b32 get_buffer_by_file_name(Application_Links *app, String file_name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_file_name(app, file_name, access, buffer_id_out));} +static b32 get_buffer_by_name(Application_Links *app, String_Const_u8 name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_name(app, name, access, buffer_id_out));} +static b32 get_buffer_by_file_name(Application_Links *app, String_Const_u8 file_name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_file_name(app, file_name, access, buffer_id_out));} static b32 buffer_read_range(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 one_past_last, char *out){return(app->buffer_read_range(app, buffer_id, start, one_past_last, out));} -static b32 buffer_replace_range(Application_Links *app, Buffer_ID buffer_id, Range range, String string){return(app->buffer_replace_range(app, buffer_id, range, string));} +static b32 buffer_replace_range(Application_Links *app, Buffer_ID buffer_id, Range range, String_Const_u8 string){return(app->buffer_replace_range(app, buffer_id, range, string));} static b32 buffer_batch_edit(Application_Links *app, Buffer_ID buffer_id, char *str, Buffer_Edit *edits, i32 edit_count){return(app->buffer_batch_edit(app, buffer_id, str, edits, edit_count));} static b32 buffer_compute_cursor(Application_Links *app, Buffer_ID buffer_id, Buffer_Seek seek, Partial_Cursor *cursor_out){return(app->buffer_compute_cursor(app, buffer_id, seek, cursor_out));} static b32 buffer_exists(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_exists(app, buffer_id));} @@ -953,9 +959,9 @@ static b32 buffer_ready(Application_Links *app, Buffer_ID buffer_id){return(app- static b32 buffer_get_access_flags(Application_Links *app, Buffer_ID buffer_id, Access_Flag *access_flags_out){return(app->buffer_get_access_flags(app, buffer_id, access_flags_out));} static b32 buffer_get_size(Application_Links *app, Buffer_ID buffer_id, i32 *size_out){return(app->buffer_get_size(app, buffer_id, size_out));} static b32 buffer_get_line_count(Application_Links *app, Buffer_ID buffer_id, i32 *line_count_out){return(app->buffer_get_line_count(app, buffer_id, line_count_out));} -static b32 buffer_get_base_buffer_name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){return(app->buffer_get_base_buffer_name(app, buffer_id, name_out, required_size_out));} -static b32 buffer_get_unique_buffer_name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){return(app->buffer_get_unique_buffer_name(app, buffer_id, name_out, required_size_out));} -static b32 buffer_get_file_name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){return(app->buffer_get_file_name(app, buffer_id, name_out, required_size_out));} +static b32 buffer_get_base_buffer_name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){return(app->buffer_get_base_buffer_name(app, buffer_id, out, name_out));} +static b32 buffer_get_unique_buffer_name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){return(app->buffer_get_unique_buffer_name(app, buffer_id, out, name_out));} +static b32 buffer_get_file_name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){return(app->buffer_get_file_name(app, buffer_id, out, name_out));} static b32 buffer_get_dirty_state(Application_Links *app, Buffer_ID buffer_id, Dirty_State *dirty_state_out){return(app->buffer_get_dirty_state(app, buffer_id, dirty_state_out));} static b32 buffer_directly_set_dirty_state(Application_Links *app, Buffer_ID buffer_id, Dirty_State dirty_state){return(app->buffer_directly_set_dirty_state(app, buffer_id, dirty_state));} static b32 buffer_tokens_are_ready(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_tokens_are_ready(app, buffer_id));} @@ -967,8 +973,8 @@ static b32 buffer_read_tokens(Application_Links *app, Buffer_ID buffer_id, i32 s static b32 buffer_get_token_range(Application_Links *app, Buffer_ID buffer_id, Cpp_Token **first_token_out, Cpp_Token **one_past_last_token_out){return(app->buffer_get_token_range(app, buffer_id, first_token_out, one_past_last_token_out));} static b32 buffer_get_token_index(Application_Links *app, Buffer_ID buffer_id, i32 pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index(app, buffer_id, pos, get_result));} static b32 buffer_send_end_signal(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_send_end_signal(app, buffer_id));} -static b32 create_buffer(Application_Links *app, String file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out){return(app->create_buffer(app, file_name, flags, new_buffer_id_out));} -static b32 buffer_save(Application_Links *app, Buffer_ID buffer_id, String file_name, u32 flags){return(app->buffer_save(app, buffer_id, file_name, flags));} +static b32 create_buffer(Application_Links *app, String_Const_u8 file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out){return(app->create_buffer(app, file_name, flags, new_buffer_id_out));} +static b32 buffer_save(Application_Links *app, Buffer_ID buffer_id, String_Const_u8 file_name, u32 flags){return(app->buffer_save(app, buffer_id, file_name, flags));} static b32 buffer_kill(Application_Links *app, Buffer_ID buffer_id, Buffer_Kill_Flag flags, Buffer_Kill_Result *result_out){return(app->buffer_kill(app, buffer_id, flags, result_out));} static b32 buffer_reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag flags, Buffer_Reopen_Result *result_out){return(app->buffer_reopen(app, buffer_id, flags, result_out));} static b32 buffer_get_file_attributes(Application_Links *app, Buffer_ID buffer_id, File_Attributes *attributes_out){return(app->buffer_get_file_attributes(app, buffer_id, attributes_out));} @@ -1033,7 +1039,7 @@ static b32 marker_visual_set_priority(Application_Links *app, Marker_Visual visu static b32 marker_visual_set_view_key(Application_Links *app, Marker_Visual visual, View_ID key_view_id){return(app->marker_visual_set_view_key(app, visual, key_view_id));} static b32 destroy_marker_visual(Application_Links *app, Marker_Visual visual){return(app->destroy_marker_visual(app, visual));} static i32 buffer_markers_get_attached_visual_count(Application_Links *app, Managed_Object object){return(app->buffer_markers_get_attached_visual_count(app, object));} -static Marker_Visual* buffer_markers_get_attached_visual(Application_Links *app, Partition *part, Managed_Object object){return(app->buffer_markers_get_attached_visual(app, part, object));} +static Marker_Visual* buffer_markers_get_attached_visual(Application_Links *app, Arena *arena, Managed_Object object){return(app->buffer_markers_get_attached_visual(app, arena, object));} static u32 managed_object_get_item_size(Application_Links *app, Managed_Object object){return(app->managed_object_get_item_size(app, object));} static u32 managed_object_get_item_count(Application_Links *app, Managed_Object object){return(app->managed_object_get_item_count(app, object));} static Managed_Object_Type managed_object_get_type(Application_Links *app, Managed_Object object){return(app->managed_object_get_type(app, object));} @@ -1048,7 +1054,7 @@ static Mouse_State get_mouse_state(Application_Links *app){return(app->get_mouse static b32 get_active_query_bars(Application_Links *app, View_ID view_id, i32 max_result_count, Query_Bar_Ptr_Array *array_out){return(app->get_active_query_bars(app, view_id, max_result_count, array_out));} static b32 start_query_bar(Application_Links *app, Query_Bar *bar, u32 flags){return(app->start_query_bar(app, bar, flags));} static void end_query_bar(Application_Links *app, Query_Bar *bar, u32 flags){(app->end_query_bar(app, bar, flags));} -static b32 print_message(Application_Links *app, String message){return(app->print_message(app, message));} +static b32 print_message(Application_Links *app, String_Const_u8 message){return(app->print_message(app, message));} static Face_ID get_largest_face_id(Application_Links *app){return(app->get_largest_face_id(app));} static b32 set_global_face(Application_Links *app, Face_ID id, b32 apply_to_all_buffers){return(app->set_global_face(app, id, apply_to_all_buffers));} static b32 buffer_history_get_max_record_index(Application_Links *app, Buffer_ID buffer_id, History_Record_Index *index_out){return(app->buffer_history_get_max_record_index(app, buffer_id, index_out));} @@ -1072,26 +1078,26 @@ static Available_Font get_available_font(Application_Links *app, i32 index){retu static void set_theme_colors(Application_Links *app, Theme_Color *colors, i32 count){(app->set_theme_colors(app, colors, count));} static void get_theme_colors(Application_Links *app, Theme_Color *colors, i32 count){(app->get_theme_colors(app, colors, count));} static argb_color finalize_color(Application_Links *app, int_color color){return(app->finalize_color(app, color));} -static b32 get_hot_directory(Application_Links *app, String *out, i32 *required_size_out){return(app->get_hot_directory(app, out, required_size_out));} -static b32 set_hot_directory(Application_Links *app, String string){return(app->set_hot_directory(app, string));} -static b32 get_file_list(Application_Links *app, String directory, File_List *list_out){return(app->get_file_list(app, directory, list_out));} +static b32 get_hot_directory(Application_Links *app, Arena *out, String_Const_u8 *out_directory){return(app->get_hot_directory(app, out, out_directory));} +static b32 set_hot_directory(Application_Links *app, String_Const_u8 string){return(app->set_hot_directory(app, string));} +static b32 get_file_list(Application_Links *app, String_Const_u8 directory, File_List *list_out){return(app->get_file_list(app, directory, list_out));} static void free_file_list(Application_Links *app, File_List list){(app->free_file_list(app, list));} static void set_gui_up_down_keys(Application_Links *app, Key_Code up_key, Key_Modifier up_key_modifier, Key_Code down_key, Key_Modifier down_key_modifier){(app->set_gui_up_down_keys(app, up_key, up_key_modifier, down_key, down_key_modifier));} static void* memory_allocate(Application_Links *app, i32 size){return(app->memory_allocate(app, size));} static b32 memory_set_protection(Application_Links *app, void *ptr, i32 size, Memory_Protect_Flags flags){return(app->memory_set_protection(app, ptr, size, flags));} static void memory_free(Application_Links *app, void *ptr, i32 size){(app->memory_free(app, ptr, size));} -static b32 file_get_attributes(Application_Links *app, String file_name, File_Attributes *attributes_out){return(app->file_get_attributes(app, file_name, attributes_out));} -static b32 directory_cd(Application_Links *app, String *directory, String relative_path){return(app->directory_cd(app, directory, relative_path));} -static b32 get_4ed_path(Application_Links *app, String *path_out, i32 *required_size_out){return(app->get_4ed_path(app, path_out, required_size_out));} +static b32 file_get_attributes(Application_Links *app, String_Const_u8 file_name, File_Attributes *attributes_out){return(app->file_get_attributes(app, file_name, attributes_out));} +static b32 directory_cd(Application_Links *app, String_Const_u8 directory, String_Const_u8 relative_path, Arena *out, String_Const_u8 *directory_out){return(app->directory_cd(app, directory, relative_path, out, directory_out));} +static b32 get_4ed_path(Application_Links *app, Arena *out, String_Const_u8 *path_out){return(app->get_4ed_path(app, out, path_out));} static void show_mouse_cursor(Application_Links *app, Mouse_Cursor_Show_Type show){(app->show_mouse_cursor(app, show));} static b32 set_edit_finished_hook_repeat_speed(Application_Links *app, u32 milliseconds){return(app->set_edit_finished_hook_repeat_speed(app, milliseconds));} static b32 set_fullscreen(Application_Links *app, b32 full_screen){return(app->set_fullscreen(app, full_screen));} static b32 is_fullscreen(Application_Links *app){return(app->is_fullscreen(app));} static void send_exit_signal(Application_Links *app){(app->send_exit_signal(app));} -static b32 set_window_title(Application_Links *app, String title){return(app->set_window_title(app, title));} +static b32 set_window_title(Application_Links *app, String_Const_u8 title){return(app->set_window_title(app, title));} static Microsecond_Time_Stamp get_microseconds_timestamp(Application_Links *app){return(app->get_microseconds_timestamp(app));} -static Vec2 draw_string(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta){return(app->draw_string(app, font_id, str, point, color, flags, delta));} -static f32 get_string_advance(Application_Links *app, Face_ID font_id, String str){return(app->get_string_advance(app, font_id, str));} +static Vec2 draw_string(Application_Links *app, Face_ID font_id, String_Const_u8 str, Vec2 point, int_color color, u32 flags, Vec2 delta){return(app->draw_string(app, font_id, str, point, color, flags, delta));} +static f32 get_string_advance(Application_Links *app, Face_ID font_id, String_Const_u8 str){return(app->get_string_advance(app, font_id, str));} static void draw_rectangle(Application_Links *app, Rect_f32 rect, int_color color){(app->draw_rectangle(app, rect, color));} static void draw_rectangle_outline(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle_outline(app, rect, color));} static void draw_clip_push(Application_Links *app, f32_Rect clip_box){(app->draw_clip_push(app, clip_box));} @@ -1108,28 +1114,29 @@ static b32 compute_render_layout(Application_Links *app, View_ID view_id, Buffer static void draw_render_layout(Application_Links *app, View_ID view_id){(app->draw_render_layout(app, view_id));} static void open_color_picker(Application_Links *app, color_picker *picker){(app->open_color_picker(app, picker));} static void animate_in_n_milliseconds(Application_Links *app, u32 n){(app->animate_in_n_milliseconds(app, n));} -static Found_String_List find_all_in_range_insensitive(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String key, Partition *memory){return(app->find_all_in_range_insensitive(app, buffer_id, start, end, key, memory));} +static Found_String_List find_all_in_range_insensitive(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String_Const_u8 key, Arena *arena){return(app->find_all_in_range_insensitive(app, buffer_id, start, end, key, arena));} static Range get_view_visible_range(Application_Links *app, View_ID view_id){return(app->get_view_visible_range(app, view_id));} #else static b32 global_set_setting(Application_Links *app, Global_Setting_ID setting, i32 value){return(app->global_set_setting_(app, setting, value));} static b32 global_set_mapping(Application_Links *app, void *data, i32 size){return(app->global_set_mapping_(app, data, size));} static b32 global_get_screen_rectangle(Application_Links *app, Rect_f32 *rect_out){return(app->global_get_screen_rectangle_(app, rect_out));} static Arena* context_get_arena(Application_Links *app){return(app->context_get_arena_(app));} -static b32 create_child_process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){return(app->create_child_process_(app, path, command, child_process_id_out));} +static Base_Allocator* context_get_base_allocator(Application_Links *app){return(app->context_get_base_allocator_(app));} +static b32 create_child_process(Application_Links *app, String_Const_u8 path, String_Const_u8 command, Child_Process_ID *child_process_id_out){return(app->create_child_process_(app, path, command, child_process_id_out));} static b32 child_process_set_target_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags){return(app->child_process_set_target_buffer_(app, child_process_id, buffer_id, flags));} static b32 buffer_get_attached_child_process(Application_Links *app, Buffer_ID buffer_id, Child_Process_ID *child_process_id_out){return(app->buffer_get_attached_child_process_(app, buffer_id, child_process_id_out));} static b32 child_process_get_attached_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID *buffer_id_out){return(app->child_process_get_attached_buffer_(app, child_process_id, buffer_id_out));} static b32 child_process_get_state(Application_Links *app, Child_Process_ID child_process_id, Process_State *process_state_out){return(app->child_process_get_state_(app, child_process_id, process_state_out));} -static b32 clipboard_post(Application_Links *app, i32 clipboard_id, String string){return(app->clipboard_post_(app, clipboard_id, string));} +static b32 clipboard_post(Application_Links *app, i32 clipboard_id, String_Const_u8 string){return(app->clipboard_post_(app, clipboard_id, string));} static b32 clipboard_count(Application_Links *app, i32 clipboard_id, i32 *count_out){return(app->clipboard_count_(app, clipboard_id, count_out));} -static b32 clipboard_index(Application_Links *app, i32 clipboard_id, i32 item_index, String *string_out, i32 *required_size_out){return(app->clipboard_index_(app, clipboard_id, item_index, string_out, required_size_out));} +static b32 clipboard_index(Application_Links *app, i32 clipboard_id, i32 item_index, Arena *out, String_Const_u8 *string_out){return(app->clipboard_index_(app, clipboard_id, item_index, out, string_out));} static Parse_Context_ID create_parse_context(Application_Links *app, Parser_String_And_Type *kw, u32 kw_count, Parser_String_And_Type *pp, u32 pp_count){return(app->create_parse_context_(app, kw, kw_count, pp, pp_count));} static i32 get_buffer_count(Application_Links *app){return(app->get_buffer_count_(app));} static b32 get_buffer_next(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_next_(app, buffer_id, access, buffer_id_out));} -static b32 get_buffer_by_name(Application_Links *app, String name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_name_(app, name, access, buffer_id_out));} -static b32 get_buffer_by_file_name(Application_Links *app, String file_name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_file_name_(app, file_name, access, buffer_id_out));} +static b32 get_buffer_by_name(Application_Links *app, String_Const_u8 name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_name_(app, name, access, buffer_id_out));} +static b32 get_buffer_by_file_name(Application_Links *app, String_Const_u8 file_name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_file_name_(app, file_name, access, buffer_id_out));} static b32 buffer_read_range(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 one_past_last, char *out){return(app->buffer_read_range_(app, buffer_id, start, one_past_last, out));} -static b32 buffer_replace_range(Application_Links *app, Buffer_ID buffer_id, Range range, String string){return(app->buffer_replace_range_(app, buffer_id, range, string));} +static b32 buffer_replace_range(Application_Links *app, Buffer_ID buffer_id, Range range, String_Const_u8 string){return(app->buffer_replace_range_(app, buffer_id, range, string));} static b32 buffer_batch_edit(Application_Links *app, Buffer_ID buffer_id, char *str, Buffer_Edit *edits, i32 edit_count){return(app->buffer_batch_edit_(app, buffer_id, str, edits, edit_count));} static b32 buffer_compute_cursor(Application_Links *app, Buffer_ID buffer_id, Buffer_Seek seek, Partial_Cursor *cursor_out){return(app->buffer_compute_cursor_(app, buffer_id, seek, cursor_out));} static b32 buffer_exists(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_exists_(app, buffer_id));} @@ -1137,9 +1144,9 @@ static b32 buffer_ready(Application_Links *app, Buffer_ID buffer_id){return(app- static b32 buffer_get_access_flags(Application_Links *app, Buffer_ID buffer_id, Access_Flag *access_flags_out){return(app->buffer_get_access_flags_(app, buffer_id, access_flags_out));} static b32 buffer_get_size(Application_Links *app, Buffer_ID buffer_id, i32 *size_out){return(app->buffer_get_size_(app, buffer_id, size_out));} static b32 buffer_get_line_count(Application_Links *app, Buffer_ID buffer_id, i32 *line_count_out){return(app->buffer_get_line_count_(app, buffer_id, line_count_out));} -static b32 buffer_get_base_buffer_name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){return(app->buffer_get_base_buffer_name_(app, buffer_id, name_out, required_size_out));} -static b32 buffer_get_unique_buffer_name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){return(app->buffer_get_unique_buffer_name_(app, buffer_id, name_out, required_size_out));} -static b32 buffer_get_file_name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){return(app->buffer_get_file_name_(app, buffer_id, name_out, required_size_out));} +static b32 buffer_get_base_buffer_name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){return(app->buffer_get_base_buffer_name_(app, buffer_id, out, name_out));} +static b32 buffer_get_unique_buffer_name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){return(app->buffer_get_unique_buffer_name_(app, buffer_id, out, name_out));} +static b32 buffer_get_file_name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){return(app->buffer_get_file_name_(app, buffer_id, out, name_out));} static b32 buffer_get_dirty_state(Application_Links *app, Buffer_ID buffer_id, Dirty_State *dirty_state_out){return(app->buffer_get_dirty_state_(app, buffer_id, dirty_state_out));} static b32 buffer_directly_set_dirty_state(Application_Links *app, Buffer_ID buffer_id, Dirty_State dirty_state){return(app->buffer_directly_set_dirty_state_(app, buffer_id, dirty_state));} static b32 buffer_tokens_are_ready(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_tokens_are_ready_(app, buffer_id));} @@ -1151,8 +1158,8 @@ static b32 buffer_read_tokens(Application_Links *app, Buffer_ID buffer_id, i32 s static b32 buffer_get_token_range(Application_Links *app, Buffer_ID buffer_id, Cpp_Token **first_token_out, Cpp_Token **one_past_last_token_out){return(app->buffer_get_token_range_(app, buffer_id, first_token_out, one_past_last_token_out));} static b32 buffer_get_token_index(Application_Links *app, Buffer_ID buffer_id, i32 pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index_(app, buffer_id, pos, get_result));} static b32 buffer_send_end_signal(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_send_end_signal_(app, buffer_id));} -static b32 create_buffer(Application_Links *app, String file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out){return(app->create_buffer_(app, file_name, flags, new_buffer_id_out));} -static b32 buffer_save(Application_Links *app, Buffer_ID buffer_id, String file_name, u32 flags){return(app->buffer_save_(app, buffer_id, file_name, flags));} +static b32 create_buffer(Application_Links *app, String_Const_u8 file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out){return(app->create_buffer_(app, file_name, flags, new_buffer_id_out));} +static b32 buffer_save(Application_Links *app, Buffer_ID buffer_id, String_Const_u8 file_name, u32 flags){return(app->buffer_save_(app, buffer_id, file_name, flags));} static b32 buffer_kill(Application_Links *app, Buffer_ID buffer_id, Buffer_Kill_Flag flags, Buffer_Kill_Result *result_out){return(app->buffer_kill_(app, buffer_id, flags, result_out));} static b32 buffer_reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag flags, Buffer_Reopen_Result *result_out){return(app->buffer_reopen_(app, buffer_id, flags, result_out));} static b32 buffer_get_file_attributes(Application_Links *app, Buffer_ID buffer_id, File_Attributes *attributes_out){return(app->buffer_get_file_attributes_(app, buffer_id, attributes_out));} @@ -1217,7 +1224,7 @@ static b32 marker_visual_set_priority(Application_Links *app, Marker_Visual visu static b32 marker_visual_set_view_key(Application_Links *app, Marker_Visual visual, View_ID key_view_id){return(app->marker_visual_set_view_key_(app, visual, key_view_id));} static b32 destroy_marker_visual(Application_Links *app, Marker_Visual visual){return(app->destroy_marker_visual_(app, visual));} static i32 buffer_markers_get_attached_visual_count(Application_Links *app, Managed_Object object){return(app->buffer_markers_get_attached_visual_count_(app, object));} -static Marker_Visual* buffer_markers_get_attached_visual(Application_Links *app, Partition *part, Managed_Object object){return(app->buffer_markers_get_attached_visual_(app, part, object));} +static Marker_Visual* buffer_markers_get_attached_visual(Application_Links *app, Arena *arena, Managed_Object object){return(app->buffer_markers_get_attached_visual_(app, arena, object));} static u32 managed_object_get_item_size(Application_Links *app, Managed_Object object){return(app->managed_object_get_item_size_(app, object));} static u32 managed_object_get_item_count(Application_Links *app, Managed_Object object){return(app->managed_object_get_item_count_(app, object));} static Managed_Object_Type managed_object_get_type(Application_Links *app, Managed_Object object){return(app->managed_object_get_type_(app, object));} @@ -1232,7 +1239,7 @@ static Mouse_State get_mouse_state(Application_Links *app){return(app->get_mouse static b32 get_active_query_bars(Application_Links *app, View_ID view_id, i32 max_result_count, Query_Bar_Ptr_Array *array_out){return(app->get_active_query_bars_(app, view_id, max_result_count, array_out));} static b32 start_query_bar(Application_Links *app, Query_Bar *bar, u32 flags){return(app->start_query_bar_(app, bar, flags));} static void end_query_bar(Application_Links *app, Query_Bar *bar, u32 flags){(app->end_query_bar_(app, bar, flags));} -static b32 print_message(Application_Links *app, String message){return(app->print_message_(app, message));} +static b32 print_message(Application_Links *app, String_Const_u8 message){return(app->print_message_(app, message));} static Face_ID get_largest_face_id(Application_Links *app){return(app->get_largest_face_id_(app));} static b32 set_global_face(Application_Links *app, Face_ID id, b32 apply_to_all_buffers){return(app->set_global_face_(app, id, apply_to_all_buffers));} static b32 buffer_history_get_max_record_index(Application_Links *app, Buffer_ID buffer_id, History_Record_Index *index_out){return(app->buffer_history_get_max_record_index_(app, buffer_id, index_out));} @@ -1256,26 +1263,26 @@ static Available_Font get_available_font(Application_Links *app, i32 index){retu static void set_theme_colors(Application_Links *app, Theme_Color *colors, i32 count){(app->set_theme_colors_(app, colors, count));} static void get_theme_colors(Application_Links *app, Theme_Color *colors, i32 count){(app->get_theme_colors_(app, colors, count));} static argb_color finalize_color(Application_Links *app, int_color color){return(app->finalize_color_(app, color));} -static b32 get_hot_directory(Application_Links *app, String *out, i32 *required_size_out){return(app->get_hot_directory_(app, out, required_size_out));} -static b32 set_hot_directory(Application_Links *app, String string){return(app->set_hot_directory_(app, string));} -static b32 get_file_list(Application_Links *app, String directory, File_List *list_out){return(app->get_file_list_(app, directory, list_out));} +static b32 get_hot_directory(Application_Links *app, Arena *out, String_Const_u8 *out_directory){return(app->get_hot_directory_(app, out, out_directory));} +static b32 set_hot_directory(Application_Links *app, String_Const_u8 string){return(app->set_hot_directory_(app, string));} +static b32 get_file_list(Application_Links *app, String_Const_u8 directory, File_List *list_out){return(app->get_file_list_(app, directory, list_out));} static void free_file_list(Application_Links *app, File_List list){(app->free_file_list_(app, list));} static void set_gui_up_down_keys(Application_Links *app, Key_Code up_key, Key_Modifier up_key_modifier, Key_Code down_key, Key_Modifier down_key_modifier){(app->set_gui_up_down_keys_(app, up_key, up_key_modifier, down_key, down_key_modifier));} static void* memory_allocate(Application_Links *app, i32 size){return(app->memory_allocate_(app, size));} static b32 memory_set_protection(Application_Links *app, void *ptr, i32 size, Memory_Protect_Flags flags){return(app->memory_set_protection_(app, ptr, size, flags));} static void memory_free(Application_Links *app, void *ptr, i32 size){(app->memory_free_(app, ptr, size));} -static b32 file_get_attributes(Application_Links *app, String file_name, File_Attributes *attributes_out){return(app->file_get_attributes_(app, file_name, attributes_out));} -static b32 directory_cd(Application_Links *app, String *directory, String relative_path){return(app->directory_cd_(app, directory, relative_path));} -static b32 get_4ed_path(Application_Links *app, String *path_out, i32 *required_size_out){return(app->get_4ed_path_(app, path_out, required_size_out));} +static b32 file_get_attributes(Application_Links *app, String_Const_u8 file_name, File_Attributes *attributes_out){return(app->file_get_attributes_(app, file_name, attributes_out));} +static b32 directory_cd(Application_Links *app, String_Const_u8 directory, String_Const_u8 relative_path, Arena *out, String_Const_u8 *directory_out){return(app->directory_cd_(app, directory, relative_path, out, directory_out));} +static b32 get_4ed_path(Application_Links *app, Arena *out, String_Const_u8 *path_out){return(app->get_4ed_path_(app, out, path_out));} static void show_mouse_cursor(Application_Links *app, Mouse_Cursor_Show_Type show){(app->show_mouse_cursor_(app, show));} static b32 set_edit_finished_hook_repeat_speed(Application_Links *app, u32 milliseconds){return(app->set_edit_finished_hook_repeat_speed_(app, milliseconds));} static b32 set_fullscreen(Application_Links *app, b32 full_screen){return(app->set_fullscreen_(app, full_screen));} static b32 is_fullscreen(Application_Links *app){return(app->is_fullscreen_(app));} static void send_exit_signal(Application_Links *app){(app->send_exit_signal_(app));} -static b32 set_window_title(Application_Links *app, String title){return(app->set_window_title_(app, title));} +static b32 set_window_title(Application_Links *app, String_Const_u8 title){return(app->set_window_title_(app, title));} static Microsecond_Time_Stamp get_microseconds_timestamp(Application_Links *app){return(app->get_microseconds_timestamp_(app));} -static Vec2 draw_string(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta){return(app->draw_string_(app, font_id, str, point, color, flags, delta));} -static f32 get_string_advance(Application_Links *app, Face_ID font_id, String str){return(app->get_string_advance_(app, font_id, str));} +static Vec2 draw_string(Application_Links *app, Face_ID font_id, String_Const_u8 str, Vec2 point, int_color color, u32 flags, Vec2 delta){return(app->draw_string_(app, font_id, str, point, color, flags, delta));} +static f32 get_string_advance(Application_Links *app, Face_ID font_id, String_Const_u8 str){return(app->get_string_advance_(app, font_id, str));} static void draw_rectangle(Application_Links *app, Rect_f32 rect, int_color color){(app->draw_rectangle_(app, rect, color));} static void draw_rectangle_outline(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle_outline_(app, rect, color));} static void draw_clip_push(Application_Links *app, f32_Rect clip_box){(app->draw_clip_push_(app, clip_box));} @@ -1292,6 +1299,6 @@ static b32 compute_render_layout(Application_Links *app, View_ID view_id, Buffer static void draw_render_layout(Application_Links *app, View_ID view_id){(app->draw_render_layout_(app, view_id));} static void open_color_picker(Application_Links *app, color_picker *picker){(app->open_color_picker_(app, picker));} static void animate_in_n_milliseconds(Application_Links *app, u32 n){(app->animate_in_n_milliseconds_(app, n));} -static Found_String_List find_all_in_range_insensitive(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String key, Partition *memory){return(app->find_all_in_range_insensitive_(app, buffer_id, start, end, key, memory));} +static Found_String_List find_all_in_range_insensitive(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String_Const_u8 key, Arena *arena){return(app->find_all_in_range_insensitive_(app, buffer_id, start, end, key, arena));} static Range get_view_visible_range(Application_Links *app, View_ID view_id){return(app->get_view_visible_range_(app, view_id));} #endif diff --git a/4coder_generated/command_metadata.h b/4coder_generated/command_metadata.h index e96419e8..bc28bfa3 100644 --- a/4coder_generated/command_metadata.h +++ b/4coder_generated/command_metadata.h @@ -9,240 +9,240 @@ #define PROC_LINKS(x,y) y #endif #if defined(CUSTOM_COMMAND_SIG) -CUSTOM_COMMAND_SIG(allow_mouse); -CUSTOM_COMMAND_SIG(auto_tab_line_at_cursor); -CUSTOM_COMMAND_SIG(auto_tab_range); -CUSTOM_COMMAND_SIG(auto_tab_whole_file); -CUSTOM_COMMAND_SIG(backspace_char); -CUSTOM_COMMAND_SIG(backspace_word); -CUSTOM_COMMAND_SIG(basic_change_active_panel); -CUSTOM_COMMAND_SIG(build_in_build_panel); -CUSTOM_COMMAND_SIG(build_search); -CUSTOM_COMMAND_SIG(center_view); +CUSTOM_COMMAND_SIG(replace_all_occurrences); CUSTOM_COMMAND_SIG(change_active_panel); CUSTOM_COMMAND_SIG(change_active_panel_backwards); -CUSTOM_COMMAND_SIG(change_to_build_panel); -CUSTOM_COMMAND_SIG(clean_all_lines); -CUSTOM_COMMAND_SIG(click_set_cursor); -CUSTOM_COMMAND_SIG(click_set_cursor_and_mark); -CUSTOM_COMMAND_SIG(click_set_cursor_if_lbutton); -CUSTOM_COMMAND_SIG(click_set_mark); -CUSTOM_COMMAND_SIG(close_all_code); -CUSTOM_COMMAND_SIG(close_build_panel); -CUSTOM_COMMAND_SIG(close_panel); -CUSTOM_COMMAND_SIG(command_lister); -CUSTOM_COMMAND_SIG(comment_line); -CUSTOM_COMMAND_SIG(comment_line_toggle); -CUSTOM_COMMAND_SIG(copy); -CUSTOM_COMMAND_SIG(cursor_mark_swap); -CUSTOM_COMMAND_SIG(cut); -CUSTOM_COMMAND_SIG(decrease_face_size); -CUSTOM_COMMAND_SIG(decrease_line_wrap); -CUSTOM_COMMAND_SIG(delete_char); -CUSTOM_COMMAND_SIG(delete_current_scope); -CUSTOM_COMMAND_SIG(delete_file_query); -CUSTOM_COMMAND_SIG(delete_line); -CUSTOM_COMMAND_SIG(delete_range); -CUSTOM_COMMAND_SIG(delete_word); -CUSTOM_COMMAND_SIG(duplicate_line); -CUSTOM_COMMAND_SIG(eol_dosify); -CUSTOM_COMMAND_SIG(eol_nixify); -CUSTOM_COMMAND_SIG(execute_any_cli); -CUSTOM_COMMAND_SIG(execute_previous_cli); -CUSTOM_COMMAND_SIG(exit_4coder); +CUSTOM_COMMAND_SIG(open_panel_vsplit); +CUSTOM_COMMAND_SIG(open_panel_hsplit); +CUSTOM_COMMAND_SIG(suppress_mouse); +CUSTOM_COMMAND_SIG(allow_mouse); +CUSTOM_COMMAND_SIG(toggle_mouse); +CUSTOM_COMMAND_SIG(set_mode_to_original); +CUSTOM_COMMAND_SIG(set_mode_to_notepad_like); +CUSTOM_COMMAND_SIG(toggle_highlight_line_at_cursor); +CUSTOM_COMMAND_SIG(toggle_highlight_enclosing_scopes); +CUSTOM_COMMAND_SIG(toggle_paren_matching_helper); +CUSTOM_COMMAND_SIG(toggle_fullscreen); +CUSTOM_COMMAND_SIG(remap_interactive); +CUSTOM_COMMAND_SIG(seek_whitespace_up); +CUSTOM_COMMAND_SIG(seek_whitespace_down); +CUSTOM_COMMAND_SIG(seek_beginning_of_textual_line); +CUSTOM_COMMAND_SIG(seek_end_of_textual_line); +CUSTOM_COMMAND_SIG(seek_beginning_of_line); +CUSTOM_COMMAND_SIG(seek_end_of_line); +CUSTOM_COMMAND_SIG(seek_whitespace_up_end_line); +CUSTOM_COMMAND_SIG(seek_whitespace_down_end_line); CUSTOM_COMMAND_SIG(goto_beginning_of_file); CUSTOM_COMMAND_SIG(goto_end_of_file); -CUSTOM_COMMAND_SIG(goto_first_jump_direct); -CUSTOM_COMMAND_SIG(goto_first_jump_same_panel_sticky); -CUSTOM_COMMAND_SIG(goto_first_jump_sticky); -CUSTOM_COMMAND_SIG(goto_jump_at_cursor_direct); -CUSTOM_COMMAND_SIG(goto_jump_at_cursor_same_panel_direct); -CUSTOM_COMMAND_SIG(goto_jump_at_cursor_same_panel_sticky); -CUSTOM_COMMAND_SIG(goto_jump_at_cursor_sticky); -CUSTOM_COMMAND_SIG(goto_line); -CUSTOM_COMMAND_SIG(goto_next_jump_direct); -CUSTOM_COMMAND_SIG(goto_next_jump_no_skips_direct); -CUSTOM_COMMAND_SIG(goto_next_jump_no_skips_sticky); -CUSTOM_COMMAND_SIG(goto_next_jump_sticky); -CUSTOM_COMMAND_SIG(goto_prev_jump_direct); -CUSTOM_COMMAND_SIG(goto_prev_jump_no_skips_direct); -CUSTOM_COMMAND_SIG(goto_prev_jump_no_skips_sticky); -CUSTOM_COMMAND_SIG(goto_prev_jump_sticky); -CUSTOM_COMMAND_SIG(hide_filebar); +CUSTOM_COMMAND_SIG(seek_whitespace_right); +CUSTOM_COMMAND_SIG(seek_whitespace_left); +CUSTOM_COMMAND_SIG(seek_token_right); +CUSTOM_COMMAND_SIG(seek_token_left); +CUSTOM_COMMAND_SIG(seek_white_or_token_right); +CUSTOM_COMMAND_SIG(seek_white_or_token_left); +CUSTOM_COMMAND_SIG(seek_alphanumeric_right); +CUSTOM_COMMAND_SIG(seek_alphanumeric_left); +CUSTOM_COMMAND_SIG(seek_alphanumeric_or_camel_right); +CUSTOM_COMMAND_SIG(seek_alphanumeric_or_camel_left); +CUSTOM_COMMAND_SIG(backspace_word); +CUSTOM_COMMAND_SIG(delete_word); +CUSTOM_COMMAND_SIG(snipe_token_or_word); +CUSTOM_COMMAND_SIG(snipe_token_or_word_right); +CUSTOM_COMMAND_SIG(write_character); +CUSTOM_COMMAND_SIG(write_underscore); +CUSTOM_COMMAND_SIG(delete_char); +CUSTOM_COMMAND_SIG(backspace_char); +CUSTOM_COMMAND_SIG(set_mark); +CUSTOM_COMMAND_SIG(cursor_mark_swap); +CUSTOM_COMMAND_SIG(delete_range); +CUSTOM_COMMAND_SIG(center_view); +CUSTOM_COMMAND_SIG(left_adjust_view); +CUSTOM_COMMAND_SIG(click_set_cursor_and_mark); +CUSTOM_COMMAND_SIG(click_set_cursor); +CUSTOM_COMMAND_SIG(click_set_cursor_if_lbutton); +CUSTOM_COMMAND_SIG(click_set_mark); +CUSTOM_COMMAND_SIG(mouse_wheel_scroll); +CUSTOM_COMMAND_SIG(move_up); +CUSTOM_COMMAND_SIG(move_down); +CUSTOM_COMMAND_SIG(move_up_10); +CUSTOM_COMMAND_SIG(move_down_10); +CUSTOM_COMMAND_SIG(move_down_textual); +CUSTOM_COMMAND_SIG(page_up); +CUSTOM_COMMAND_SIG(page_down); +CUSTOM_COMMAND_SIG(move_left); +CUSTOM_COMMAND_SIG(move_right); +CUSTOM_COMMAND_SIG(select_all); +CUSTOM_COMMAND_SIG(to_uppercase); +CUSTOM_COMMAND_SIG(to_lowercase); +CUSTOM_COMMAND_SIG(clean_all_lines); +CUSTOM_COMMAND_SIG(basic_change_active_panel); +CUSTOM_COMMAND_SIG(close_panel); +CUSTOM_COMMAND_SIG(show_scrollbar); CUSTOM_COMMAND_SIG(hide_scrollbar); -CUSTOM_COMMAND_SIG(if0_off); -CUSTOM_COMMAND_SIG(increase_face_size); +CUSTOM_COMMAND_SIG(show_filebar); +CUSTOM_COMMAND_SIG(hide_filebar); +CUSTOM_COMMAND_SIG(toggle_filebar); +CUSTOM_COMMAND_SIG(toggle_line_wrap); +CUSTOM_COMMAND_SIG(toggle_fps_meter); CUSTOM_COMMAND_SIG(increase_line_wrap); +CUSTOM_COMMAND_SIG(decrease_line_wrap); +CUSTOM_COMMAND_SIG(increase_face_size); +CUSTOM_COMMAND_SIG(decrease_face_size); +CUSTOM_COMMAND_SIG(mouse_wheel_change_face_size); +CUSTOM_COMMAND_SIG(toggle_virtual_whitespace); +CUSTOM_COMMAND_SIG(toggle_show_whitespace); +CUSTOM_COMMAND_SIG(toggle_line_numbers); +CUSTOM_COMMAND_SIG(eol_dosify); +CUSTOM_COMMAND_SIG(eol_nixify); +CUSTOM_COMMAND_SIG(exit_4coder); +CUSTOM_COMMAND_SIG(goto_line); +CUSTOM_COMMAND_SIG(search); +CUSTOM_COMMAND_SIG(reverse_search); +CUSTOM_COMMAND_SIG(search_identifier); +CUSTOM_COMMAND_SIG(reverse_search_identifier); +CUSTOM_COMMAND_SIG(replace_in_range); +CUSTOM_COMMAND_SIG(query_replace); +CUSTOM_COMMAND_SIG(query_replace_identifier); +CUSTOM_COMMAND_SIG(query_replace_selection); +CUSTOM_COMMAND_SIG(save_all_dirty_buffers); +CUSTOM_COMMAND_SIG(delete_file_query); +CUSTOM_COMMAND_SIG(save_to_query); +CUSTOM_COMMAND_SIG(rename_file_query); +CUSTOM_COMMAND_SIG(make_directory_query); +CUSTOM_COMMAND_SIG(move_line_up); +CUSTOM_COMMAND_SIG(move_line_down); +CUSTOM_COMMAND_SIG(duplicate_line); +CUSTOM_COMMAND_SIG(delete_line); +CUSTOM_COMMAND_SIG(open_file_in_quotes); +CUSTOM_COMMAND_SIG(open_matching_file_cpp); +CUSTOM_COMMAND_SIG(view_buffer_other_panel); +CUSTOM_COMMAND_SIG(swap_buffers_between_panels); +CUSTOM_COMMAND_SIG(kill_buffer); +CUSTOM_COMMAND_SIG(save); +CUSTOM_COMMAND_SIG(reopen); +CUSTOM_COMMAND_SIG(undo); +CUSTOM_COMMAND_SIG(redo); +CUSTOM_COMMAND_SIG(undo_all_buffers); +CUSTOM_COMMAND_SIG(redo_all_buffers); +CUSTOM_COMMAND_SIG(open_in_other); +CUSTOM_COMMAND_SIG(lister__quit); +CUSTOM_COMMAND_SIG(lister__activate); +CUSTOM_COMMAND_SIG(lister__write_character); +CUSTOM_COMMAND_SIG(lister__backspace_text_field); +CUSTOM_COMMAND_SIG(lister__move_up); +CUSTOM_COMMAND_SIG(lister__move_down); +CUSTOM_COMMAND_SIG(lister__wheel_scroll); +CUSTOM_COMMAND_SIG(lister__mouse_press); +CUSTOM_COMMAND_SIG(lister__mouse_release); +CUSTOM_COMMAND_SIG(lister__repaint); +CUSTOM_COMMAND_SIG(lister__write_character__default); +CUSTOM_COMMAND_SIG(lister__backspace_text_field__default); +CUSTOM_COMMAND_SIG(lister__move_up__default); +CUSTOM_COMMAND_SIG(lister__move_down__default); +CUSTOM_COMMAND_SIG(lister__write_character__file_path); +CUSTOM_COMMAND_SIG(lister__backspace_text_field__file_path); +CUSTOM_COMMAND_SIG(lister__write_character__fixed_list); +CUSTOM_COMMAND_SIG(interactive_switch_buffer); CUSTOM_COMMAND_SIG(interactive_kill_buffer); +CUSTOM_COMMAND_SIG(interactive_open_or_new); CUSTOM_COMMAND_SIG(interactive_new); CUSTOM_COMMAND_SIG(interactive_open); -CUSTOM_COMMAND_SIG(interactive_open_or_new); -CUSTOM_COMMAND_SIG(interactive_switch_buffer); -CUSTOM_COMMAND_SIG(kill_buffer); -CUSTOM_COMMAND_SIG(kill_rect); -CUSTOM_COMMAND_SIG(left_adjust_view); -CUSTOM_COMMAND_SIG(list_all_functions_all_buffers); -CUSTOM_COMMAND_SIG(list_all_functions_all_buffers_lister); -CUSTOM_COMMAND_SIG(list_all_functions_current_buffer); -CUSTOM_COMMAND_SIG(list_all_functions_current_buffer_lister); +CUSTOM_COMMAND_SIG(command_lister); +CUSTOM_COMMAND_SIG(auto_tab_whole_file); +CUSTOM_COMMAND_SIG(auto_tab_line_at_cursor); +CUSTOM_COMMAND_SIG(auto_tab_range); +CUSTOM_COMMAND_SIG(write_and_auto_tab); CUSTOM_COMMAND_SIG(list_all_locations); +CUSTOM_COMMAND_SIG(list_all_substring_locations); CUSTOM_COMMAND_SIG(list_all_locations_case_insensitive); +CUSTOM_COMMAND_SIG(list_all_substring_locations_case_insensitive); CUSTOM_COMMAND_SIG(list_all_locations_of_identifier); CUSTOM_COMMAND_SIG(list_all_locations_of_identifier_case_insensitive); CUSTOM_COMMAND_SIG(list_all_locations_of_selection); CUSTOM_COMMAND_SIG(list_all_locations_of_selection_case_insensitive); CUSTOM_COMMAND_SIG(list_all_locations_of_type_definition); CUSTOM_COMMAND_SIG(list_all_locations_of_type_definition_of_identifier); -CUSTOM_COMMAND_SIG(list_all_substring_locations); -CUSTOM_COMMAND_SIG(list_all_substring_locations_case_insensitive); -CUSTOM_COMMAND_SIG(lister__activate); -CUSTOM_COMMAND_SIG(lister__backspace_text_field); -CUSTOM_COMMAND_SIG(lister__backspace_text_field__default); -CUSTOM_COMMAND_SIG(lister__backspace_text_field__file_path); -CUSTOM_COMMAND_SIG(lister__mouse_press); -CUSTOM_COMMAND_SIG(lister__mouse_release); -CUSTOM_COMMAND_SIG(lister__move_down); -CUSTOM_COMMAND_SIG(lister__move_down__default); -CUSTOM_COMMAND_SIG(lister__move_up); -CUSTOM_COMMAND_SIG(lister__move_up__default); -CUSTOM_COMMAND_SIG(lister__quit); -CUSTOM_COMMAND_SIG(lister__repaint); -CUSTOM_COMMAND_SIG(lister__wheel_scroll); -CUSTOM_COMMAND_SIG(lister__write_character); -CUSTOM_COMMAND_SIG(lister__write_character__default); -CUSTOM_COMMAND_SIG(lister__write_character__file_path); -CUSTOM_COMMAND_SIG(lister__write_character__fixed_list); -CUSTOM_COMMAND_SIG(load_project); -CUSTOM_COMMAND_SIG(make_directory_query); -CUSTOM_COMMAND_SIG(miblo_decrement_basic); -CUSTOM_COMMAND_SIG(miblo_decrement_time_stamp); -CUSTOM_COMMAND_SIG(miblo_decrement_time_stamp_minute); -CUSTOM_COMMAND_SIG(miblo_increment_basic); -CUSTOM_COMMAND_SIG(miblo_increment_time_stamp); -CUSTOM_COMMAND_SIG(miblo_increment_time_stamp_minute); -CUSTOM_COMMAND_SIG(mouse_wheel_change_face_size); -CUSTOM_COMMAND_SIG(mouse_wheel_scroll); -CUSTOM_COMMAND_SIG(move_down); -CUSTOM_COMMAND_SIG(move_down_10); -CUSTOM_COMMAND_SIG(move_down_textual); -CUSTOM_COMMAND_SIG(move_left); -CUSTOM_COMMAND_SIG(move_line_down); -CUSTOM_COMMAND_SIG(move_line_up); -CUSTOM_COMMAND_SIG(move_right); -CUSTOM_COMMAND_SIG(move_up); -CUSTOM_COMMAND_SIG(move_up_10); -CUSTOM_COMMAND_SIG(multi_line_edit); +CUSTOM_COMMAND_SIG(word_complete); +CUSTOM_COMMAND_SIG(goto_jump_at_cursor_direct); +CUSTOM_COMMAND_SIG(goto_jump_at_cursor_same_panel_direct); +CUSTOM_COMMAND_SIG(goto_next_jump_direct); +CUSTOM_COMMAND_SIG(goto_prev_jump_direct); +CUSTOM_COMMAND_SIG(goto_next_jump_no_skips_direct); +CUSTOM_COMMAND_SIG(goto_prev_jump_no_skips_direct); +CUSTOM_COMMAND_SIG(goto_first_jump_direct); CUSTOM_COMMAND_SIG(newline_or_goto_position_direct); CUSTOM_COMMAND_SIG(newline_or_goto_position_same_panel_direct); -CUSTOM_COMMAND_SIG(newline_or_goto_position_same_panel_sticky); +CUSTOM_COMMAND_SIG(goto_jump_at_cursor_sticky); +CUSTOM_COMMAND_SIG(goto_jump_at_cursor_same_panel_sticky); +CUSTOM_COMMAND_SIG(goto_next_jump_sticky); +CUSTOM_COMMAND_SIG(goto_prev_jump_sticky); +CUSTOM_COMMAND_SIG(goto_next_jump_no_skips_sticky); +CUSTOM_COMMAND_SIG(goto_prev_jump_no_skips_sticky); +CUSTOM_COMMAND_SIG(goto_first_jump_sticky); +CUSTOM_COMMAND_SIG(goto_first_jump_same_panel_sticky); CUSTOM_COMMAND_SIG(newline_or_goto_position_sticky); +CUSTOM_COMMAND_SIG(newline_or_goto_position_same_panel_sticky); +CUSTOM_COMMAND_SIG(view_jump_list_with_lister); +CUSTOM_COMMAND_SIG(copy); +CUSTOM_COMMAND_SIG(cut); +CUSTOM_COMMAND_SIG(paste); +CUSTOM_COMMAND_SIG(paste_next); +CUSTOM_COMMAND_SIG(paste_and_indent); +CUSTOM_COMMAND_SIG(paste_next_and_indent); +CUSTOM_COMMAND_SIG(execute_previous_cli); +CUSTOM_COMMAND_SIG(execute_any_cli); +CUSTOM_COMMAND_SIG(build_search); +CUSTOM_COMMAND_SIG(build_in_build_panel); +CUSTOM_COMMAND_SIG(close_build_panel); +CUSTOM_COMMAND_SIG(change_to_build_panel); +CUSTOM_COMMAND_SIG(close_all_code); CUSTOM_COMMAND_SIG(open_all_code); CUSTOM_COMMAND_SIG(open_all_code_recursive); -CUSTOM_COMMAND_SIG(open_file_in_quotes); -CUSTOM_COMMAND_SIG(open_in_other); -CUSTOM_COMMAND_SIG(open_long_braces); -CUSTOM_COMMAND_SIG(open_long_braces_break); -CUSTOM_COMMAND_SIG(open_long_braces_semicolon); -CUSTOM_COMMAND_SIG(open_matching_file_cpp); -CUSTOM_COMMAND_SIG(open_panel_hsplit); -CUSTOM_COMMAND_SIG(open_panel_vsplit); -CUSTOM_COMMAND_SIG(page_down); -CUSTOM_COMMAND_SIG(page_up); -CUSTOM_COMMAND_SIG(paste); -CUSTOM_COMMAND_SIG(paste_and_indent); -CUSTOM_COMMAND_SIG(paste_next); -CUSTOM_COMMAND_SIG(paste_next_and_indent); -CUSTOM_COMMAND_SIG(place_in_scope); -CUSTOM_COMMAND_SIG(project_command_lister); +CUSTOM_COMMAND_SIG(load_project); CUSTOM_COMMAND_SIG(project_fkey_command); CUSTOM_COMMAND_SIG(project_go_to_root_directory); -CUSTOM_COMMAND_SIG(query_replace); -CUSTOM_COMMAND_SIG(query_replace_identifier); -CUSTOM_COMMAND_SIG(query_replace_selection); -CUSTOM_COMMAND_SIG(redo); -CUSTOM_COMMAND_SIG(redo_all_buffers); -CUSTOM_COMMAND_SIG(remap_interactive); -CUSTOM_COMMAND_SIG(rename_file_query); -CUSTOM_COMMAND_SIG(rename_parameter); -CUSTOM_COMMAND_SIG(reopen); -CUSTOM_COMMAND_SIG(replace_all_occurrences); -CUSTOM_COMMAND_SIG(replace_in_range); -CUSTOM_COMMAND_SIG(reverse_search); -CUSTOM_COMMAND_SIG(reverse_search_identifier); -CUSTOM_COMMAND_SIG(save); -CUSTOM_COMMAND_SIG(save_all_dirty_buffers); -CUSTOM_COMMAND_SIG(save_to_query); -CUSTOM_COMMAND_SIG(scope_absorb_down); -CUSTOM_COMMAND_SIG(search); -CUSTOM_COMMAND_SIG(search_identifier); -CUSTOM_COMMAND_SIG(seek_alphanumeric_left); -CUSTOM_COMMAND_SIG(seek_alphanumeric_or_camel_left); -CUSTOM_COMMAND_SIG(seek_alphanumeric_or_camel_right); -CUSTOM_COMMAND_SIG(seek_alphanumeric_right); -CUSTOM_COMMAND_SIG(seek_beginning_of_line); -CUSTOM_COMMAND_SIG(seek_beginning_of_textual_line); -CUSTOM_COMMAND_SIG(seek_end_of_line); -CUSTOM_COMMAND_SIG(seek_end_of_textual_line); -CUSTOM_COMMAND_SIG(seek_token_left); -CUSTOM_COMMAND_SIG(seek_token_right); -CUSTOM_COMMAND_SIG(seek_white_or_token_left); -CUSTOM_COMMAND_SIG(seek_white_or_token_right); -CUSTOM_COMMAND_SIG(seek_whitespace_down); -CUSTOM_COMMAND_SIG(seek_whitespace_down_end_line); -CUSTOM_COMMAND_SIG(seek_whitespace_left); -CUSTOM_COMMAND_SIG(seek_whitespace_right); -CUSTOM_COMMAND_SIG(seek_whitespace_up); -CUSTOM_COMMAND_SIG(seek_whitespace_up_end_line); -CUSTOM_COMMAND_SIG(select_all); +CUSTOM_COMMAND_SIG(setup_new_project); +CUSTOM_COMMAND_SIG(setup_build_bat); +CUSTOM_COMMAND_SIG(setup_build_sh); +CUSTOM_COMMAND_SIG(setup_build_bat_and_sh); +CUSTOM_COMMAND_SIG(project_command_lister); +CUSTOM_COMMAND_SIG(list_all_functions_current_buffer); +CUSTOM_COMMAND_SIG(list_all_functions_current_buffer_lister); +CUSTOM_COMMAND_SIG(list_all_functions_all_buffers); +CUSTOM_COMMAND_SIG(list_all_functions_all_buffers_lister); +CUSTOM_COMMAND_SIG(select_surrounding_scope); CUSTOM_COMMAND_SIG(select_next_scope_absolute); CUSTOM_COMMAND_SIG(select_prev_scope_absolute); -CUSTOM_COMMAND_SIG(select_surrounding_scope); +CUSTOM_COMMAND_SIG(place_in_scope); +CUSTOM_COMMAND_SIG(delete_current_scope); +CUSTOM_COMMAND_SIG(scope_absorb_down); +CUSTOM_COMMAND_SIG(open_long_braces); +CUSTOM_COMMAND_SIG(open_long_braces_semicolon); +CUSTOM_COMMAND_SIG(open_long_braces_break); +CUSTOM_COMMAND_SIG(if0_off); +CUSTOM_COMMAND_SIG(write_todo); +CUSTOM_COMMAND_SIG(write_hack); +CUSTOM_COMMAND_SIG(write_note); +CUSTOM_COMMAND_SIG(write_block); +CUSTOM_COMMAND_SIG(write_zero_struct); +CUSTOM_COMMAND_SIG(comment_line); +CUSTOM_COMMAND_SIG(uncomment_line); +CUSTOM_COMMAND_SIG(comment_line_toggle); +CUSTOM_COMMAND_SIG(snippet_lister); CUSTOM_COMMAND_SIG(set_bindings_choose); CUSTOM_COMMAND_SIG(set_bindings_default); CUSTOM_COMMAND_SIG(set_bindings_mac_default); -CUSTOM_COMMAND_SIG(set_mark); -CUSTOM_COMMAND_SIG(set_mode_to_notepad_like); -CUSTOM_COMMAND_SIG(set_mode_to_original); -CUSTOM_COMMAND_SIG(setup_build_bat); -CUSTOM_COMMAND_SIG(setup_build_bat_and_sh); -CUSTOM_COMMAND_SIG(setup_build_sh); -CUSTOM_COMMAND_SIG(setup_new_project); -CUSTOM_COMMAND_SIG(show_filebar); -CUSTOM_COMMAND_SIG(show_scrollbar); -CUSTOM_COMMAND_SIG(snipe_token_or_word); -CUSTOM_COMMAND_SIG(snipe_token_or_word_right); -CUSTOM_COMMAND_SIG(snippet_lister); -CUSTOM_COMMAND_SIG(suppress_mouse); -CUSTOM_COMMAND_SIG(swap_buffers_between_panels); -CUSTOM_COMMAND_SIG(to_lowercase); -CUSTOM_COMMAND_SIG(to_uppercase); -CUSTOM_COMMAND_SIG(toggle_filebar); -CUSTOM_COMMAND_SIG(toggle_fps_meter); -CUSTOM_COMMAND_SIG(toggle_fullscreen); -CUSTOM_COMMAND_SIG(toggle_highlight_enclosing_scopes); -CUSTOM_COMMAND_SIG(toggle_highlight_line_at_cursor); -CUSTOM_COMMAND_SIG(toggle_line_numbers); -CUSTOM_COMMAND_SIG(toggle_line_wrap); -CUSTOM_COMMAND_SIG(toggle_mouse); -CUSTOM_COMMAND_SIG(toggle_paren_matching_helper); -CUSTOM_COMMAND_SIG(toggle_show_whitespace); -CUSTOM_COMMAND_SIG(toggle_virtual_whitespace); -CUSTOM_COMMAND_SIG(uncomment_line); -CUSTOM_COMMAND_SIG(undo); -CUSTOM_COMMAND_SIG(undo_all_buffers); -CUSTOM_COMMAND_SIG(view_buffer_other_panel); -CUSTOM_COMMAND_SIG(view_jump_list_with_lister); -CUSTOM_COMMAND_SIG(word_complete); -CUSTOM_COMMAND_SIG(write_and_auto_tab); -CUSTOM_COMMAND_SIG(write_block); -CUSTOM_COMMAND_SIG(write_character); -CUSTOM_COMMAND_SIG(write_explicit_enum_flags); +CUSTOM_COMMAND_SIG(miblo_increment_basic); +CUSTOM_COMMAND_SIG(miblo_decrement_basic); +CUSTOM_COMMAND_SIG(miblo_increment_time_stamp); +CUSTOM_COMMAND_SIG(miblo_decrement_time_stamp); +CUSTOM_COMMAND_SIG(miblo_increment_time_stamp_minute); +CUSTOM_COMMAND_SIG(miblo_decrement_time_stamp_minute); +CUSTOM_COMMAND_SIG(kill_rect); +CUSTOM_COMMAND_SIG(multi_line_edit); +CUSTOM_COMMAND_SIG(rename_parameter); CUSTOM_COMMAND_SIG(write_explicit_enum_values); -CUSTOM_COMMAND_SIG(write_hack); -CUSTOM_COMMAND_SIG(write_note); -CUSTOM_COMMAND_SIG(write_todo); -CUSTOM_COMMAND_SIG(write_underscore); -CUSTOM_COMMAND_SIG(write_zero_struct); +CUSTOM_COMMAND_SIG(write_explicit_enum_flags); #endif struct Command_Metadata{ PROC_LINKS(Custom_Command_Function, void) *proc; @@ -255,473 +255,473 @@ int32_t source_name_len; int32_t line_number; }; static Command_Metadata fcoder_metacmd_table[234] = { -{ PROC_LINKS(allow_mouse, 0), "allow_mouse", 11, "Shows the mouse and causes all mouse input to be processed normally.", 68, "c:\\4ed\\code\\4coder_default_framework.cpp", 40, 310 }, -{ PROC_LINKS(auto_tab_line_at_cursor, 0), "auto_tab_line_at_cursor", 23, "Auto-indents the line on which the cursor sits.", 47, "c:\\4ed\\code\\4coder_auto_indent.cpp", 34, 624 }, -{ PROC_LINKS(auto_tab_range, 0), "auto_tab_range", 14, "Auto-indents the range between the cursor and the mark.", 55, "c:\\4ed\\code\\4coder_auto_indent.cpp", 34, 637 }, -{ PROC_LINKS(auto_tab_whole_file, 0), "auto_tab_whole_file", 19, "Audo-indents the entire current buffer.", 39, "c:\\4ed\\code\\4coder_auto_indent.cpp", 34, 612 }, -{ PROC_LINKS(backspace_char, 0), "backspace_char", 14, "Deletes the character to the left of the cursor.", 48, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 109 }, -{ PROC_LINKS(backspace_word, 0), "backspace_word", 14, "Delete characters between the cursor position and the first alphanumeric boundary to the left.", 94, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1241 }, -{ PROC_LINKS(basic_change_active_panel, 0), "basic_change_active_panel", 25, "Change the currently active panel, moving to the panel with the next highest view_id. Will not skipe the build panel if it is open.", 132, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 573 }, -{ PROC_LINKS(build_in_build_panel, 0), "build_in_build_panel", 20, "Looks for a build.bat, build.sh, or makefile in the current and parent directories. Runs the first that it finds and prints the output to *compilation*. Puts the *compilation* buffer in a panel at the footer of the current view.", 230, "c:\\4ed\\code\\4coder_build_commands.cpp", 37, 181 }, -{ PROC_LINKS(build_search, 0), "build_search", 12, "Looks for a build.bat, build.sh, or makefile in the current and parent directories. Runs the first that it finds and prints the output to *compilation*.", 153, "c:\\4ed\\code\\4coder_build_commands.cpp", 37, 146 }, -{ PROC_LINKS(center_view, 0), "center_view", 11, "Centers the view vertically on the line on which the cursor sits.", 65, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 170 }, -{ PROC_LINKS(change_active_panel, 0), "change_active_panel", 19, "Change the currently active panel, moving to the panel with the next highest view_id.", 85, "c:\\4ed\\code\\4coder_default_framework.cpp", 40, 203 }, -{ PROC_LINKS(change_active_panel_backwards, 0), "change_active_panel_backwards", 29, "Change the currently active panel, moving to the panel with the next lowest view_id.", 84, "c:\\4ed\\code\\4coder_default_framework.cpp", 40, 214 }, -{ PROC_LINKS(change_to_build_panel, 0), "change_to_build_panel", 21, "If the special build panel is open, makes the build panel the active panel.", 75, "c:\\4ed\\code\\4coder_build_commands.cpp", 37, 204 }, -{ PROC_LINKS(clean_all_lines, 0), "clean_all_lines", 15, "Removes trailing whitespace from all lines in the current buffer.", 65, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 503 }, -{ PROC_LINKS(click_set_cursor, 0), "click_set_cursor", 16, "Sets the cursor position to the mouse position.", 47, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 232 }, -{ PROC_LINKS(click_set_cursor_and_mark, 0), "click_set_cursor_and_mark", 25, "Sets the cursor position and mark to the mouse position.", 56, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 213 }, -{ PROC_LINKS(click_set_cursor_if_lbutton, 0), "click_set_cursor_if_lbutton", 27, "If the mouse left button is pressed, sets the cursor position to the mouse position.", 84, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 249 }, -{ PROC_LINKS(click_set_mark, 0), "click_set_mark", 14, "Sets the mark position to the mouse position.", 45, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 268 }, -{ PROC_LINKS(close_all_code, 0), "close_all_code", 14, "Closes any buffer with a filename ending with an extension configured to be recognized as a code file type.", 107, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1064 }, -{ PROC_LINKS(close_build_panel, 0), "close_build_panel", 17, "If the special build panel is open, closes it.", 46, "c:\\4ed\\code\\4coder_build_commands.cpp", 37, 198 }, -{ PROC_LINKS(close_panel, 0), "close_panel", 11, "Closes the currently active panel if it is not the only panel open.", 67, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 582 }, -{ PROC_LINKS(command_lister, 0), "command_lister", 14, "Opens an interactive list of all registered commands.", 53, "c:\\4ed\\code\\4coder_lists.cpp", 28, 1047 }, -{ PROC_LINKS(comment_line, 0), "comment_line", 12, "Insert '//' at the beginning of the line after leading whitespace.", 66, "c:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 143 }, -{ PROC_LINKS(comment_line_toggle, 0), "comment_line_toggle", 19, "Turns uncommented lines into commented lines and vice versa for comments starting with '//'.", 92, "c:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 171 }, -{ PROC_LINKS(copy, 0), "copy", 4, "Copy the text in the range from the cursor to the mark onto the clipboard.", 74, "c:\\4ed\\code\\4coder_clipboard.cpp", 32, 26 }, -{ PROC_LINKS(cursor_mark_swap, 0), "cursor_mark_swap", 16, "Swaps the position of the cursor and the mark.", 46, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 144 }, -{ PROC_LINKS(cut, 0), "cut", 3, "Cut the text in the range from the cursor to the mark onto the clipboard.", 73, "c:\\4ed\\code\\4coder_clipboard.cpp", 32, 37 }, -{ PROC_LINKS(decrease_face_size, 0), "decrease_face_size", 18, "Decrease the size of the face used by the current buffer.", 57, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 690 }, -{ PROC_LINKS(decrease_line_wrap, 0), "decrease_line_wrap", 18, "Decrases the current buffer's width for line wrapping.", 54, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 664 }, -{ PROC_LINKS(delete_char, 0), "delete_char", 11, "Deletes the character to the right of the cursor.", 49, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 87 }, -{ PROC_LINKS(delete_current_scope, 0), "delete_current_scope", 20, "Deletes the braces surrounding the currently selected scope. Leaves the contents within the scope.", 99, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 493 }, -{ PROC_LINKS(delete_file_query, 0), "delete_file_query", 17, "Deletes the file of the current buffer if 4coder has the appropriate access rights. Will ask the user for confirmation first.", 125, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1271 }, -{ PROC_LINKS(delete_line, 0), "delete_line", 11, "Delete the line the on which the cursor sits.", 45, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1541 }, -{ PROC_LINKS(delete_range, 0), "delete_range", 12, "Deletes the text in the range between the cursor and the mark.", 62, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 157 }, -{ PROC_LINKS(delete_word, 0), "delete_word", 11, "Delete characters between the cursor position and the first alphanumeric boundary to the right.", 95, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1247 }, -{ PROC_LINKS(duplicate_line, 0), "duplicate_line", 14, "Create a copy of the line on which the cursor sits.", 51, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1516 }, -{ PROC_LINKS(eol_dosify, 0), "eol_dosify", 10, "Puts the buffer in DOS line ending mode.", 40, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 749 }, -{ PROC_LINKS(eol_nixify, 0), "eol_nixify", 10, "Puts the buffer in NIX line ending mode.", 40, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 759 }, -{ PROC_LINKS(execute_any_cli, 0), "execute_any_cli", 15, "Queries for an output buffer name and system command, runs the system command as a CLI and prints the output to the specified buffer.", 133, "c:\\4ed\\code\\4coder_system_command.cpp", 37, 22 }, -{ PROC_LINKS(execute_previous_cli, 0), "execute_previous_cli", 20, "If the command execute_any_cli has already been used, this will execute a CLI reusing the most recent buffer name and command.", 126, "c:\\4ed\\code\\4coder_system_command.cpp", 37, 7 }, -{ PROC_LINKS(exit_4coder, 0), "exit_4coder", 11, "Attempts to close 4coder.", 25, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 769 }, -{ PROC_LINKS(goto_beginning_of_file, 0), "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1155 }, -{ PROC_LINKS(goto_end_of_file, 0), "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1164 }, -{ PROC_LINKS(goto_first_jump_direct, 0), "goto_first_jump_direct", 22, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 95 }, -{ PROC_LINKS(goto_first_jump_same_panel_sticky, 0), "goto_first_jump_same_panel_sticky", 33, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer and views the buffer in the panel where the jump list was.", 153, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 580 }, -{ PROC_LINKS(goto_first_jump_sticky, 0), "goto_first_jump_sticky", 22, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 562 }, -{ PROC_LINKS(goto_jump_at_cursor_direct, 0), "goto_jump_at_cursor_direct", 26, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.", 187, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 8 }, -{ PROC_LINKS(goto_jump_at_cursor_same_panel_direct, 0), "goto_jump_at_cursor_same_panel_direct", 37, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list..", 168, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 35 }, -{ PROC_LINKS(goto_jump_at_cursor_same_panel_sticky, 0), "goto_jump_at_cursor_same_panel_sticky", 37, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list.", 167, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 382 }, -{ PROC_LINKS(goto_jump_at_cursor_sticky, 0), "goto_jump_at_cursor_sticky", 26, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.", 187, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 346 }, -{ PROC_LINKS(goto_line, 0), "goto_line", 9, "Queries the user for a number, and jumps the cursor to the corresponding line.", 78, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 777 }, -{ PROC_LINKS(goto_next_jump_direct, 0), "goto_next_jump_direct", 21, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.", 123, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 59 }, -{ PROC_LINKS(goto_next_jump_no_skips_direct, 0), "goto_next_jump_no_skips_direct", 30, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, and does not skip sub jump locations.", 132, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 77 }, -{ PROC_LINKS(goto_next_jump_no_skips_sticky, 0), "goto_next_jump_no_skips_sticky", 30, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, and does not skip sub jump locations.", 132, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 527 }, -{ PROC_LINKS(goto_next_jump_sticky, 0), "goto_next_jump_sticky", 21, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.", 123, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 493 }, -{ PROC_LINKS(goto_prev_jump_direct, 0), "goto_prev_jump_direct", 21, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations.", 127, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 68 }, -{ PROC_LINKS(goto_prev_jump_no_skips_direct, 0), "goto_prev_jump_no_skips_direct", 30, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.", 136, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 86 }, -{ PROC_LINKS(goto_prev_jump_no_skips_sticky, 0), "goto_prev_jump_no_skips_sticky", 30, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.", 136, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 547 }, -{ PROC_LINKS(goto_prev_jump_sticky, 0), "goto_prev_jump_sticky", 21, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations.", 127, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 513 }, -{ PROC_LINKS(hide_filebar, 0), "hide_filebar", 12, "Sets the current view to hide it's filebar.", 43, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 616 }, -{ PROC_LINKS(hide_scrollbar, 0), "hide_scrollbar", 14, "Sets the current view to hide it's scrollbar.", 45, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 600 }, -{ PROC_LINKS(if0_off, 0), "if0_off", 7, "Surround the range between the cursor and mark with an '#if 0' and an '#endif'", 78, "c:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 84 }, -{ PROC_LINKS(increase_face_size, 0), "increase_face_size", 18, "Increase the size of the face used by the current buffer.", 57, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 676 }, -{ PROC_LINKS(increase_line_wrap, 0), "increase_line_wrap", 18, "Increases the current buffer's width for line wrapping.", 55, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 652 }, -{ PROC_LINKS(interactive_kill_buffer, 0), "interactive_kill_buffer", 23, "Interactively kill an open buffer.", 34, "c:\\4ed\\code\\4coder_lists.cpp", 28, 816 }, -{ PROC_LINKS(interactive_new, 0), "interactive_new", 15, "Interactively creates a new file.", 33, "c:\\4ed\\code\\4coder_lists.cpp", 28, 929 }, -{ PROC_LINKS(interactive_open, 0), "interactive_open", 16, "Interactively opens a file.", 27, "c:\\4ed\\code\\4coder_lists.cpp", 28, 962 }, -{ PROC_LINKS(interactive_open_or_new, 0), "interactive_open_or_new", 23, "Interactively open a file out of the file system.", 49, "c:\\4ed\\code\\4coder_lists.cpp", 28, 890 }, -{ PROC_LINKS(interactive_switch_buffer, 0), "interactive_switch_buffer", 25, "Interactively switch to an open buffer.", 39, "c:\\4ed\\code\\4coder_lists.cpp", 28, 796 }, -{ PROC_LINKS(kill_buffer, 0), "kill_buffer", 11, "Kills the current buffer.", 25, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1749 }, -{ PROC_LINKS(kill_rect, 0), "kill_rect", 9, "Delete characters in a rectangular region. Range testing is done by unwrapped-xy coordinates.", 93, "c:\\4ed\\code\\4coder_experiments.cpp", 34, 50 }, -{ PROC_LINKS(left_adjust_view, 0), "left_adjust_view", 16, "Sets the left size of the view near the x position of the cursor.", 65, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 188 }, -{ PROC_LINKS(list_all_functions_all_buffers, 0), "list_all_functions_all_buffers", 30, "Creates a jump list of lines from all buffers that appear to define or declare functions.", 89, "c:\\4ed\\code\\4coder_function_list.cpp", 36, 347 }, -{ PROC_LINKS(list_all_functions_all_buffers_lister, 0), "list_all_functions_all_buffers_lister", 37, "Creates a lister of locations that look like function definitions and declarations all buffers.", 95, "c:\\4ed\\code\\4coder_function_list.cpp", 36, 353 }, -{ PROC_LINKS(list_all_functions_current_buffer, 0), "list_all_functions_current_buffer", 33, "Creates a jump list of lines of the current buffer that appear to define or declare functions.", 94, "c:\\4ed\\code\\4coder_function_list.cpp", 36, 321 }, -{ PROC_LINKS(list_all_functions_current_buffer_lister, 0), "list_all_functions_current_buffer_lister", 40, "Creates a lister of locations that look like function definitions and declarations in the buffer.", 97, "c:\\4ed\\code\\4coder_function_list.cpp", 36, 333 }, -{ PROC_LINKS(list_all_locations, 0), "list_all_locations", 18, "Queries the user for a string and lists all exact case-sensitive matches found in all open buffers.", 99, "c:\\4ed\\code\\4coder_search.cpp", 29, 792 }, -{ PROC_LINKS(list_all_locations_case_insensitive, 0), "list_all_locations_case_insensitive", 35, "Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.", 101, "c:\\4ed\\code\\4coder_search.cpp", 29, 806 }, -{ PROC_LINKS(list_all_locations_of_identifier, 0), "list_all_locations_of_identifier", 32, "Reads a token or word under the cursor and lists all exact case-sensitive mathces in all open buffers.", 102, "c:\\4ed\\code\\4coder_search.cpp", 29, 820 }, -{ PROC_LINKS(list_all_locations_of_identifier_case_insensitive, 0), "list_all_locations_of_identifier_case_insensitive", 49, "Reads a token or word under the cursor and lists all exact case-insensitive mathces in all open buffers.", 104, "c:\\4ed\\code\\4coder_search.cpp", 29, 827 }, -{ PROC_LINKS(list_all_locations_of_selection, 0), "list_all_locations_of_selection", 31, "Reads the string in the selected range and lists all exact case-sensitive mathces in all open buffers.", 102, "c:\\4ed\\code\\4coder_search.cpp", 29, 834 }, -{ PROC_LINKS(list_all_locations_of_selection_case_insensitive, 0), "list_all_locations_of_selection_case_insensitive", 48, "Reads the string in the selected range and lists all exact case-insensitive mathces in all open buffers.", 104, "c:\\4ed\\code\\4coder_search.cpp", 29, 841 }, -{ PROC_LINKS(list_all_locations_of_type_definition, 0), "list_all_locations_of_type_definition", 37, "Queries user for string, lists all locations of strings that appear to define a type whose name matches the input string.", 121, "c:\\4ed\\code\\4coder_search.cpp", 29, 848 }, -{ PROC_LINKS(list_all_locations_of_type_definition_of_identifier, 0), "list_all_locations_of_type_definition_of_identifier", 51, "Reads a token or word under the cursor and lists all locations of strings that appear to define a type whose name matches it.", 125, "c:\\4ed\\code\\4coder_search.cpp", 29, 859 }, -{ PROC_LINKS(list_all_substring_locations, 0), "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "c:\\4ed\\code\\4coder_search.cpp", 29, 799 }, -{ PROC_LINKS(list_all_substring_locations_case_insensitive, 0), "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "c:\\4ed\\code\\4coder_search.cpp", 29, 813 }, -{ PROC_LINKS(lister__activate, 0), "lister__activate", 16, "A lister mode command that activates the list's action on the highlighted item.", 79, "c:\\4ed\\code\\4coder_lists.cpp", 28, 16 }, -{ PROC_LINKS(lister__backspace_text_field, 0), "lister__backspace_text_field", 28, "A lister mode command that dispatches to the lister's backspace text field handler.", 83, "c:\\4ed\\code\\4coder_lists.cpp", 28, 44 }, -{ PROC_LINKS(lister__backspace_text_field__default, 0), "lister__backspace_text_field__default", 37, "A lister mode command that backspaces one character from the text field.", 72, "c:\\4ed\\code\\4coder_lists.cpp", 28, 157 }, -{ PROC_LINKS(lister__backspace_text_field__file_path, 0), "lister__backspace_text_field__file_path", 39, "A lister mode command that backspaces one character from the text field of a file system list.", 94, "c:\\4ed\\code\\4coder_lists.cpp", 28, 233 }, -{ PROC_LINKS(lister__mouse_press, 0), "lister__mouse_press", 19, "A lister mode command that beings a click interaction with a list item under the mouse.", 87, "c:\\4ed\\code\\4coder_lists.cpp", 28, 94 }, -{ PROC_LINKS(lister__mouse_release, 0), "lister__mouse_release", 21, "A lister mode command that ends a click interaction with a list item under the mouse, possibly activating it.", 109, "c:\\4ed\\code\\4coder_lists.cpp", 28, 107 }, -{ PROC_LINKS(lister__move_down, 0), "lister__move_down", 17, "A lister mode command that dispatches to the lister's navigate down handler.", 76, "c:\\4ed\\code\\4coder_lists.cpp", 28, 66 }, -{ PROC_LINKS(lister__move_down__default, 0), "lister__move_down__default", 26, "A lister mode command that moves the highlighted item one down in the list.", 75, "c:\\4ed\\code\\4coder_lists.cpp", 28, 190 }, -{ PROC_LINKS(lister__move_up, 0), "lister__move_up", 15, "A lister mode command that dispatches to the lister's navigate up handler.", 74, "c:\\4ed\\code\\4coder_lists.cpp", 28, 55 }, -{ PROC_LINKS(lister__move_up__default, 0), "lister__move_up__default", 24, "A lister mode command that moves the highlighted item one up in the list.", 73, "c:\\4ed\\code\\4coder_lists.cpp", 28, 173 }, -{ PROC_LINKS(lister__quit, 0), "lister__quit", 12, "A lister mode command that quits the list without executing any actions.", 72, "c:\\4ed\\code\\4coder_lists.cpp", 28, 8 }, -{ PROC_LINKS(lister__repaint, 0), "lister__repaint", 15, "A lister mode command that updates the lists UI data.", 53, "c:\\4ed\\code\\4coder_lists.cpp", 28, 124 }, -{ PROC_LINKS(lister__wheel_scroll, 0), "lister__wheel_scroll", 20, "A lister mode command that scrolls the list in response to the mouse wheel.", 75, "c:\\4ed\\code\\4coder_lists.cpp", 28, 77 }, -{ PROC_LINKS(lister__write_character, 0), "lister__write_character", 23, "A lister mode command that dispatches to the lister's write character handler.", 78, "c:\\4ed\\code\\4coder_lists.cpp", 28, 33 }, -{ PROC_LINKS(lister__write_character__default, 0), "lister__write_character__default", 32, "A lister mode command that inserts a new character to the text field.", 69, "c:\\4ed\\code\\4coder_lists.cpp", 28, 136 }, -{ PROC_LINKS(lister__write_character__file_path, 0), "lister__write_character__file_path", 34, "A lister mode command that inserts a character into the text field of a file system list.", 89, "c:\\4ed\\code\\4coder_lists.cpp", 28, 207 }, -{ PROC_LINKS(lister__write_character__fixed_list, 0), "lister__write_character__fixed_list", 35, "A lister mode command that handles input for the fixed sure to kill list.", 73, "c:\\4ed\\code\\4coder_lists.cpp", 28, 273 }, -{ PROC_LINKS(load_project, 0), "load_project", 12, "Looks for a project.4coder file in the current directory and tries to load it. Looks in parent directories until a project file is found or there are no more parents.", 167, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1087 }, -{ PROC_LINKS(make_directory_query, 0), "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1396 }, -{ PROC_LINKS(miblo_decrement_basic, 0), "miblo_decrement_basic", 21, "Decrement an integer under the cursor by one.", 45, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 116 }, -{ PROC_LINKS(miblo_decrement_time_stamp, 0), "miblo_decrement_time_stamp", 26, "Decrement a time stamp under the cursor by one second. (format [m]m:ss or h:mm:ss", 81, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 400 }, -{ PROC_LINKS(miblo_decrement_time_stamp_minute, 0), "miblo_decrement_time_stamp_minute", 33, "Decrement a time stamp under the cursor by one minute. (format [m]m:ss or h:mm:ss", 81, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 412 }, -{ PROC_LINKS(miblo_increment_basic, 0), "miblo_increment_basic", 21, "Increment an integer under the cursor by one.", 45, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 97 }, -{ PROC_LINKS(miblo_increment_time_stamp, 0), "miblo_increment_time_stamp", 26, "Increment a time stamp under the cursor by one second. (format [m]m:ss or h:mm:ss", 81, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 394 }, -{ PROC_LINKS(miblo_increment_time_stamp_minute, 0), "miblo_increment_time_stamp_minute", 33, "Increment a time stamp under the cursor by one minute. (format [m]m:ss or h:mm:ss", 81, "c:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 406 }, -{ PROC_LINKS(mouse_wheel_change_face_size, 0), "mouse_wheel_change_face_size", 28, "Reads the state of the mouse wheel and uses it to either increase or decrease the face size.", 92, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 704 }, -{ PROC_LINKS(mouse_wheel_scroll, 0), "mouse_wheel_scroll", 18, "Reads the scroll wheel value from the mouse state and scrolls accordingly.", 74, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 285 }, -{ PROC_LINKS(move_down, 0), "move_down", 9, "Moves the cursor down one line.", 31, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 367 }, -{ PROC_LINKS(move_down_10, 0), "move_down_10", 12, "Moves the cursor down ten lines.", 32, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 379 }, -{ PROC_LINKS(move_down_textual, 0), "move_down_textual", 17, "Moves down to the next line of actual text, regardless of line wrapping.", 72, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 385 }, -{ PROC_LINKS(move_left, 0), "move_left", 9, "Moves the cursor one character to the left.", 43, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 419 }, -{ PROC_LINKS(move_line_down, 0), "move_line_down", 14, "Swaps the line under the cursor with the line below it, and moves the cursor down with it.", 90, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1494 }, -{ PROC_LINKS(move_line_up, 0), "move_line_up", 12, "Swaps the line under the cursor with the line above it, and moves the cursor up with it.", 88, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1429 }, -{ PROC_LINKS(move_right, 0), "move_right", 10, "Moves the cursor one character to the right.", 44, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 433 }, -{ PROC_LINKS(move_up, 0), "move_up", 7, "Moves the cursor up one line.", 29, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 361 }, -{ PROC_LINKS(move_up_10, 0), "move_up_10", 10, "Moves the cursor up ten lines.", 30, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 373 }, -{ PROC_LINKS(multi_line_edit, 0), "multi_line_edit", 15, "Begin multi-line mode. In multi-line mode characters are inserted at every line between the mark and cursor. All characters are inserted at the same character offset into the line. This mode uses line_char coordinates.", 221, "c:\\4ed\\code\\4coder_experiments.cpp", 34, 136 }, -{ PROC_LINKS(newline_or_goto_position_direct, 0), "newline_or_goto_position_direct", 31, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 112 }, -{ PROC_LINKS(newline_or_goto_position_same_panel_direct, 0), "newline_or_goto_position_same_panel_direct", 42, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "c:\\4ed\\code\\4coder_jump_direct.cpp", 34, 127 }, -{ PROC_LINKS(newline_or_goto_position_same_panel_sticky, 0), "newline_or_goto_position_same_panel_sticky", 42, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 618 }, -{ PROC_LINKS(newline_or_goto_position_sticky, 0), "newline_or_goto_position_sticky", 31, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "c:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 603 }, -{ PROC_LINKS(open_all_code, 0), "open_all_code", 13, "Open all code in the current directory. File types are determined by extensions. An extension is considered code based on the extensions specified in 4coder.config.", 164, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1071 }, -{ PROC_LINKS(open_all_code_recursive, 0), "open_all_code_recursive", 23, "Works as open_all_code but also runs in all subdirectories.", 59, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1078 }, -{ PROC_LINKS(open_file_in_quotes, 0), "open_file_in_quotes", 19, "Reads a filename from surrounding '\"' characters and attempts to open the corresponding file.", 94, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1630 }, -{ PROC_LINKS(open_in_other, 0), "open_in_other", 13, "Interactively opens a file in the other panel.", 46, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 2060 }, -{ PROC_LINKS(open_long_braces, 0), "open_long_braces", 16, "At the cursor, insert a '{' and '}' separated by a blank line.", 62, "c:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 60 }, -{ PROC_LINKS(open_long_braces_break, 0), "open_long_braces_break", 22, "At the cursor, insert a '{' and '}break;' separated by a blank line.", 68, "c:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 76 }, -{ PROC_LINKS(open_long_braces_semicolon, 0), "open_long_braces_semicolon", 26, "At the cursor, insert a '{' and '};' separated by a blank line.", 63, "c:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 68 }, -{ PROC_LINKS(open_matching_file_cpp, 0), "open_matching_file_cpp", 22, "If the current file is a *.cpp or *.h, attempts to open the corresponding *.h or *.cpp file in the other view.", 110, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1674 }, -{ PROC_LINKS(open_panel_hsplit, 0), "open_panel_hsplit", 17, "Create a new panel by horizontally splitting the active panel.", 62, "c:\\4ed\\code\\4coder_default_framework.cpp", 40, 237 }, -{ PROC_LINKS(open_panel_vsplit, 0), "open_panel_vsplit", 17, "Create a new panel by vertically splitting the active panel.", 60, "c:\\4ed\\code\\4coder_default_framework.cpp", 40, 225 }, -{ PROC_LINKS(page_down, 0), "page_down", 9, "Scrolls the view down one view height and moves the cursor down one view height.", 80, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 408 }, -{ PROC_LINKS(page_up, 0), "page_up", 7, "Scrolls the view up one view height and moves the cursor up one view height.", 76, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 399 }, -{ PROC_LINKS(paste, 0), "paste", 5, "At the cursor, insert the text at the top of the clipboard.", 59, "c:\\4ed\\code\\4coder_clipboard.cpp", 32, 50 }, -{ PROC_LINKS(paste_and_indent, 0), "paste_and_indent", 16, "Paste from the top of clipboard and run auto-indent on the newly pasted text.", 77, "c:\\4ed\\code\\4coder_clipboard.cpp", 32, 142 }, -{ PROC_LINKS(paste_next, 0), "paste_next", 10, "If the previous command was paste or paste_next, replaces the paste range with the next text down on the clipboard, otherwise operates as the paste command.", 156, "c:\\4ed\\code\\4coder_clipboard.cpp", 32, 91 }, -{ PROC_LINKS(paste_next_and_indent, 0), "paste_next_and_indent", 21, "Paste the next item on the clipboard and run auto-indent on the newly pasted text.", 82, "c:\\4ed\\code\\4coder_clipboard.cpp", 32, 149 }, -{ PROC_LINKS(place_in_scope, 0), "place_in_scope", 14, "Wraps the code contained in the range between cursor and mark with a new curly brace scope.", 91, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 487 }, -{ PROC_LINKS(project_command_lister, 0), "project_command_lister", 22, "Open a lister of all commands in the currently loaded project.", 62, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1529 }, -{ PROC_LINKS(project_fkey_command, 0), "project_fkey_command", 20, "Run an 'fkey command' configured in a project.4coder file. Determines the index of the 'fkey command' by which function key or numeric key was pressed to trigger the command.", 175, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1094 }, -{ PROC_LINKS(project_go_to_root_directory, 0), "project_go_to_root_directory", 28, "Changes 4coder's hot directory to the root directory of the currently loaded project. With no loaded project nothing hapepns.", 125, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1117 }, -{ PROC_LINKS(query_replace, 0), "query_replace", 13, "Queries the user for two strings, and incrementally replaces every occurence of the first string with the second string.", 120, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1156 }, -{ PROC_LINKS(query_replace_identifier, 0), "query_replace_identifier", 24, "Queries the user for a string, and incrementally replace every occurence of the word or token found at the cursor with the specified string.", 140, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1178 }, -{ PROC_LINKS(query_replace_selection, 0), "query_replace_selection", 23, "Queries the user for a string, and incrementally replace every occurence of the string found in the selected range with the specified string.", 141, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1197 }, -{ PROC_LINKS(redo, 0), "redo", 4, "Advances forwards through the undo history of the current buffer.", 65, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1853 }, -{ PROC_LINKS(redo_all_buffers, 0), "redo_all_buffers", 16, "Advances forward through the undo history in the buffer containing the most recent regular edit.", 96, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1950 }, -{ PROC_LINKS(remap_interactive, 0), "remap_interactive", 17, "Switch to a named key binding map.", 34, "c:\\4ed\\code\\4coder_default_framework.cpp", 40, 360 }, -{ PROC_LINKS(rename_file_query, 0), "rename_file_query", 17, "Queries the user for a new name and renames the file of the current buffer, altering the buffer's name too.", 107, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1345 }, -{ PROC_LINKS(rename_parameter, 0), "rename_parameter", 16, "If the cursor is found to be on the name of a function parameter in the signature of a function definition, all occurences within the scope of the function will be replaced with a new provided string.", 200, "c:\\4ed\\code\\4coder_experiments.cpp", 34, 423 }, -{ PROC_LINKS(reopen, 0), "reopen", 6, "Reopen the current buffer from the hard drive.", 46, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1773 }, -{ PROC_LINKS(replace_all_occurrences, 0), "replace_all_occurrences", 23, "Queries the user for two strings, and replaces all occurrences of the first string with the second string in all open buffers.", 126, "c:\\4ed\\code\\4coder_experiments.cpp", 34, 821 }, -{ PROC_LINKS(replace_in_range, 0), "replace_in_range", 16, "Queries the user for two strings, and replaces all occurences of the first string in the range between the cursor and the mark with the second string.", 150, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1038 }, -{ PROC_LINKS(reverse_search, 0), "reverse_search", 14, "Begins an incremental search up through the current buffer for a user specified string.", 87, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1003 }, -{ PROC_LINKS(reverse_search_identifier, 0), "reverse_search_identifier", 25, "Begins an incremental search up through the current buffer for the word or token under the cursor.", 98, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1024 }, -{ PROC_LINKS(save, 0), "save", 4, "Saves the current buffer.", 25, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1759 }, -{ PROC_LINKS(save_all_dirty_buffers, 0), "save_all_dirty_buffers", 22, "Saves all buffers marked dirty (showing the '*' indicator).", 59, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1245 }, -{ PROC_LINKS(save_to_query, 0), "save_to_query", 13, "Queries the user for a file name and saves the contents of the current buffer, altering the buffer's name too.", 110, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1299 }, -{ PROC_LINKS(scope_absorb_down, 0), "scope_absorb_down", 17, "If a scope is currently selected, and a statement or block statement is present below the current scope, the statement is moved into the scope.", 143, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 734 }, -{ PROC_LINKS(search, 0), "search", 6, "Begins an incremental search down through the current buffer for a user specified string.", 89, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 996 }, -{ PROC_LINKS(search_identifier, 0), "search_identifier", 17, "Begins an incremental search down through the current buffer for the word or token under the cursor.", 100, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1010 }, -{ PROC_LINKS(seek_alphanumeric_left, 0), "seek_alphanumeric_left", 22, "Seek left for boundary between alphanumeric characters and non-alphanumeric characters.", 87, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1221 }, -{ PROC_LINKS(seek_alphanumeric_or_camel_left, 0), "seek_alphanumeric_or_camel_left", 31, "Seek left for boundary between alphanumeric characters or camel case word and non-alphanumeric characters.", 106, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1233 }, -{ PROC_LINKS(seek_alphanumeric_or_camel_right, 0), "seek_alphanumeric_or_camel_right", 32, "Seek right for boundary between alphanumeric characters or camel case word and non-alphanumeric characters.", 107, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1227 }, -{ PROC_LINKS(seek_alphanumeric_right, 0), "seek_alphanumeric_right", 23, "Seek right for boundary between alphanumeric characters and non-alphanumeric characters.", 88, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1215 }, -{ PROC_LINKS(seek_beginning_of_line, 0), "seek_beginning_of_line", 22, "Seeks the cursor to the beginning of the visual line.", 53, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1097 }, -{ PROC_LINKS(seek_beginning_of_textual_line, 0), "seek_beginning_of_textual_line", 30, "Seeks the cursor to the beginning of the line across all text.", 62, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1069 }, -{ PROC_LINKS(seek_end_of_line, 0), "seek_end_of_line", 16, "Seeks the cursor to the end of the visual line.", 47, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1111 }, -{ PROC_LINKS(seek_end_of_textual_line, 0), "seek_end_of_textual_line", 24, "Seeks the cursor to the end of the line across all text.", 56, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1083 }, -{ PROC_LINKS(seek_token_left, 0), "seek_token_left", 15, "Seek left for the next beginning of a token.", 44, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1197 }, -{ PROC_LINKS(seek_token_right, 0), "seek_token_right", 16, "Seek right for the next end of a token.", 39, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1191 }, -{ PROC_LINKS(seek_white_or_token_left, 0), "seek_white_or_token_left", 24, "Seek left for the next end of a token or boundary between whitespace and non-whitespace.", 88, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1209 }, -{ PROC_LINKS(seek_white_or_token_right, 0), "seek_white_or_token_right", 25, "Seek right for the next end of a token or boundary between whitespace and non-whitespace.", 89, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1203 }, -{ PROC_LINKS(seek_whitespace_down, 0), "seek_whitespace_down", 20, "Seeks the cursor down to the next blank line.", 45, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1055 }, -{ PROC_LINKS(seek_whitespace_down_end_line, 0), "seek_whitespace_down_end_line", 29, "Seeks the cursor down to the next blank line and places it at the end of the line.", 82, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1140 }, -{ PROC_LINKS(seek_whitespace_left, 0), "seek_whitespace_left", 20, "Seek left for the next boundary between whitespace and non-whitespace.", 70, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1185 }, -{ PROC_LINKS(seek_whitespace_right, 0), "seek_whitespace_right", 21, "Seek right for the next boundary between whitespace and non-whitespace.", 71, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1179 }, -{ PROC_LINKS(seek_whitespace_up, 0), "seek_whitespace_up", 18, "Seeks the cursor up to the next blank line.", 43, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1041 }, -{ PROC_LINKS(seek_whitespace_up_end_line, 0), "seek_whitespace_up_end_line", 27, "Seeks the cursor up to the next blank line and places it at the end of the line.", 80, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1125 }, -{ PROC_LINKS(select_all, 0), "select_all", 10, "Puts the cursor at the top of the file, and the mark at the bottom of the file.", 79, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 447 }, -{ PROC_LINKS(select_next_scope_absolute, 0), "select_next_scope_absolute", 26, "Finds the first scope started by '{' after the cursor and puts the cursor and mark on the '{' and '}'.", 102, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 357 }, -{ PROC_LINKS(select_prev_scope_absolute, 0), "select_prev_scope_absolute", 26, "Finds the first scope started by '{' before the cursor and puts the cursor and mark on the '{' and '}'.", 103, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 379 }, -{ PROC_LINKS(select_surrounding_scope, 0), "select_surrounding_scope", 24, "Finds the scope enclosed by '{' '}' surrounding the cursor and puts the cursor and mark on the '{' and '}'.", 107, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 339 }, -{ PROC_LINKS(set_bindings_choose, 0), "set_bindings_choose", 19, "Remap keybindings using the 'choose' mapping rule.", 50, "c:\\4ed\\code\\4coder_remapping_commands.cpp", 41, 47 }, -{ PROC_LINKS(set_bindings_default, 0), "set_bindings_default", 20, "Remap keybindings using the 'default' mapping rule.", 51, "c:\\4ed\\code\\4coder_remapping_commands.cpp", 41, 61 }, -{ PROC_LINKS(set_bindings_mac_default, 0), "set_bindings_mac_default", 24, "Remap keybindings using the 'mac-default' mapping rule.", 55, "c:\\4ed\\code\\4coder_remapping_commands.cpp", 41, 75 }, -{ PROC_LINKS(set_mark, 0), "set_mark", 8, "Sets the mark to the current position of the cursor.", 52, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 133 }, -{ PROC_LINKS(set_mode_to_notepad_like, 0), "set_mode_to_notepad_like", 24, "Sets the edit mode to Notepad like.", 35, "c:\\4ed\\code\\4coder_default_framework.cpp", 40, 328 }, -{ PROC_LINKS(set_mode_to_original, 0), "set_mode_to_original", 20, "Sets the edit mode to 4coder original.", 38, "c:\\4ed\\code\\4coder_default_framework.cpp", 40, 322 }, -{ PROC_LINKS(setup_build_bat, 0), "setup_build_bat", 15, "Queries the user for several configuration options and initializes a new build batch script.", 92, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1502 }, -{ PROC_LINKS(setup_build_bat_and_sh, 0), "setup_build_bat_and_sh", 22, "Queries the user for several configuration options and initializes a new build batch script.", 92, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1514 }, -{ PROC_LINKS(setup_build_sh, 0), "setup_build_sh", 14, "Queries the user for several configuration options and initializes a new build shell script.", 92, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1508 }, -{ PROC_LINKS(setup_new_project, 0), "setup_new_project", 17, "Queries the user for several configuration options and initializes a new 4coder project with build scripts for every OS.", 120, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1495 }, -{ PROC_LINKS(show_filebar, 0), "show_filebar", 12, "Sets the current view to show it's filebar.", 43, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 608 }, -{ PROC_LINKS(show_scrollbar, 0), "show_scrollbar", 14, "Sets the current view to show it's scrollbar.", 45, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 592 }, -{ PROC_LINKS(snipe_token_or_word, 0), "snipe_token_or_word", 19, "Delete a single, whole token on or to the left of the cursor and post it to the clipboard.", 90, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1253 }, -{ PROC_LINKS(snipe_token_or_word_right, 0), "snipe_token_or_word_right", 25, "Delete a single, whole token on or to the right of the cursor and post it to the clipboard.", 91, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1259 }, -{ PROC_LINKS(snippet_lister, 0), "snippet_lister", 14, "Opens a snippet lister for inserting whole pre-written snippets of text.", 72, "c:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 260 }, -{ PROC_LINKS(suppress_mouse, 0), "suppress_mouse", 14, "Hides the mouse and causes all mosue input (clicks, position, wheel) to be ignored.", 83, "c:\\4ed\\code\\4coder_default_framework.cpp", 40, 304 }, -{ PROC_LINKS(swap_buffers_between_panels, 0), "swap_buffers_between_panels", 27, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1704 }, -{ PROC_LINKS(to_lowercase, 0), "to_lowercase", 12, "Converts all ascii text in the range between the cursor and the mark to lowercase.", 82, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 483 }, -{ PROC_LINKS(to_uppercase, 0), "to_uppercase", 12, "Converts all ascii text in the range between the cursor and the mark to uppercase.", 82, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 463 }, -{ PROC_LINKS(toggle_filebar, 0), "toggle_filebar", 14, "Toggles the visibility status of the current view's filebar.", 60, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 624 }, -{ PROC_LINKS(toggle_fps_meter, 0), "toggle_fps_meter", 16, "Toggles the visibility of the FPS performance meter", 51, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 646 }, -{ PROC_LINKS(toggle_fullscreen, 0), "toggle_fullscreen", 17, "Toggle fullscreen mode on or off. The change(s) do not take effect until the next frame.", 89, "c:\\4ed\\code\\4coder_default_framework.cpp", 40, 352 }, -{ PROC_LINKS(toggle_highlight_enclosing_scopes, 0), "toggle_highlight_enclosing_scopes", 33, "In code files scopes surrounding the cursor are highlighted with distinguishing colors.", 87, "c:\\4ed\\code\\4coder_default_framework.cpp", 40, 340 }, -{ PROC_LINKS(toggle_highlight_line_at_cursor, 0), "toggle_highlight_line_at_cursor", 31, "Toggles the line highlight at the cursor.", 41, "c:\\4ed\\code\\4coder_default_framework.cpp", 40, 334 }, -{ PROC_LINKS(toggle_line_numbers, 0), "toggle_line_numbers", 19, "Toggles the left margin line numbers.", 37, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 743 }, -{ PROC_LINKS(toggle_line_wrap, 0), "toggle_line_wrap", 16, "Toggles the current buffer's line wrapping status.", 50, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 634 }, -{ PROC_LINKS(toggle_mouse, 0), "toggle_mouse", 12, "Toggles the mouse suppression mode, see suppress_mouse and allow_mouse.", 71, "c:\\4ed\\code\\4coder_default_framework.cpp", 40, 316 }, -{ PROC_LINKS(toggle_paren_matching_helper, 0), "toggle_paren_matching_helper", 28, "In code files matching parentheses pairs are colored with distinguishing colors.", 80, "c:\\4ed\\code\\4coder_default_framework.cpp", 40, 346 }, -{ PROC_LINKS(toggle_show_whitespace, 0), "toggle_show_whitespace", 22, "Toggles the current buffer's whitespace visibility status.", 58, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 733 }, -{ PROC_LINKS(toggle_virtual_whitespace, 0), "toggle_virtual_whitespace", 25, "Toggles the current buffer's virtual whitespace status.", 55, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 721 }, -{ PROC_LINKS(uncomment_line, 0), "uncomment_line", 14, "If present, delete '//' at the beginning of the line after leading whitespace.", 78, "c:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 157 }, -{ PROC_LINKS(undo, 0), "undo", 4, "Advances backwards through the undo history of the current buffer.", 66, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1837 }, -{ PROC_LINKS(undo_all_buffers, 0), "undo_all_buffers", 16, "Advances backward through the undo history in the buffer containing the most recent regular edit.", 97, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1871 }, -{ PROC_LINKS(view_buffer_other_panel, 0), "view_buffer_other_panel", 23, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1689 }, -{ PROC_LINKS(view_jump_list_with_lister, 0), "view_jump_list_with_lister", 26, "When executed on a buffer with jumps, creates a persistent lister for all the jumps", 83, "c:\\4ed\\code\\4coder_jump_lister.cpp", 34, 104 }, -{ PROC_LINKS(word_complete, 0), "word_complete", 13, "Iteratively tries completing the word to the left of the cursor with other words in open buffers that have the same prefix string.", 130, "c:\\4ed\\code\\4coder_search.cpp", 29, 883 }, -{ PROC_LINKS(write_and_auto_tab, 0), "write_and_auto_tab", 18, "Inserts a character and auto-indents the line on which the cursor sits.", 71, "c:\\4ed\\code\\4coder_auto_indent.cpp", 34, 649 }, -{ PROC_LINKS(write_block, 0), "write_block", 11, "At the cursor, insert a block comment.", 38, "c:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 108 }, -{ PROC_LINKS(write_character, 0), "write_character", 15, "Inserts whatever character was used to trigger this command.", 60, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 71 }, -{ PROC_LINKS(write_explicit_enum_flags, 0), "write_explicit_enum_flags", 25, "If the cursor is found to be on the '{' of an enum definition, the values of the enum will be filled in to give each a unique power of 2 value, starting from 1. Existing values are overwritten.", 194, "c:\\4ed\\code\\4coder_experiments.cpp", 34, 747 }, -{ PROC_LINKS(write_explicit_enum_values, 0), "write_explicit_enum_values", 26, "If the cursor is found to be on the '{' of an enum definition, the values of the enum will be filled in sequentially starting from zero. Existing values are overwritten.", 170, "c:\\4ed\\code\\4coder_experiments.cpp", 34, 741 }, -{ PROC_LINKS(write_hack, 0), "write_hack", 10, "At the cursor, insert a '// HACK' comment, includes user name if it was specified in config.4coder.", 99, "c:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 96 }, -{ PROC_LINKS(write_note, 0), "write_note", 10, "At the cursor, insert a '// NOTE' comment, includes user name if it was specified in config.4coder.", 99, "c:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 102 }, -{ PROC_LINKS(write_todo, 0), "write_todo", 10, "At the cursor, insert a '// TODO' comment, includes user name if it was specified in config.4coder.", 99, "c:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 90 }, -{ PROC_LINKS(write_underscore, 0), "write_underscore", 16, "Inserts an underscore.", 22, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 80 }, -{ PROC_LINKS(write_zero_struct, 0), "write_zero_struct", 17, "At the cursor, insert a ' = {};'.", 33, "c:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 114 }, +{ PROC_LINKS(replace_all_occurrences, 0), "replace_all_occurrences", 23, "Queries the user for two strings, and replaces all occurrences of the first string with the second string in all open buffers.", 126, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 806 }, +{ PROC_LINKS(change_active_panel, 0), "change_active_panel", 19, "Change the currently active panel, moving to the panel with the next highest view_id.", 85, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 206 }, +{ PROC_LINKS(change_active_panel_backwards, 0), "change_active_panel_backwards", 29, "Change the currently active panel, moving to the panel with the next lowest view_id.", 84, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 217 }, +{ PROC_LINKS(open_panel_vsplit, 0), "open_panel_vsplit", 17, "Create a new panel by vertically splitting the active panel.", 60, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 228 }, +{ PROC_LINKS(open_panel_hsplit, 0), "open_panel_hsplit", 17, "Create a new panel by horizontally splitting the active panel.", 62, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 240 }, +{ PROC_LINKS(suppress_mouse, 0), "suppress_mouse", 14, "Hides the mouse and causes all mosue input (clicks, position, wheel) to be ignored.", 83, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 307 }, +{ PROC_LINKS(allow_mouse, 0), "allow_mouse", 11, "Shows the mouse and causes all mouse input to be processed normally.", 68, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 313 }, +{ PROC_LINKS(toggle_mouse, 0), "toggle_mouse", 12, "Toggles the mouse suppression mode, see suppress_mouse and allow_mouse.", 71, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 319 }, +{ PROC_LINKS(set_mode_to_original, 0), "set_mode_to_original", 20, "Sets the edit mode to 4coder original.", 38, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 325 }, +{ PROC_LINKS(set_mode_to_notepad_like, 0), "set_mode_to_notepad_like", 24, "Sets the edit mode to Notepad like.", 35, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 331 }, +{ PROC_LINKS(toggle_highlight_line_at_cursor, 0), "toggle_highlight_line_at_cursor", 31, "Toggles the line highlight at the cursor.", 41, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 337 }, +{ PROC_LINKS(toggle_highlight_enclosing_scopes, 0), "toggle_highlight_enclosing_scopes", 33, "In code files scopes surrounding the cursor are highlighted with distinguishing colors.", 87, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 343 }, +{ PROC_LINKS(toggle_paren_matching_helper, 0), "toggle_paren_matching_helper", 28, "In code files matching parentheses pairs are colored with distinguishing colors.", 80, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 349 }, +{ PROC_LINKS(toggle_fullscreen, 0), "toggle_fullscreen", 17, "Toggle fullscreen mode on or off. The change(s) do not take effect until the next frame.", 89, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 355 }, +{ PROC_LINKS(remap_interactive, 0), "remap_interactive", 17, "Switch to a named key binding map.", 34, "w:\\4ed\\code\\4coder_default_framework.cpp", 40, 363 }, +{ PROC_LINKS(seek_whitespace_up, 0), "seek_whitespace_up", 18, "Seeks the cursor up to the next blank line.", 43, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1041 }, +{ PROC_LINKS(seek_whitespace_down, 0), "seek_whitespace_down", 20, "Seeks the cursor down to the next blank line.", 45, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1055 }, +{ PROC_LINKS(seek_beginning_of_textual_line, 0), "seek_beginning_of_textual_line", 30, "Seeks the cursor to the beginning of the line across all text.", 62, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1069 }, +{ PROC_LINKS(seek_end_of_textual_line, 0), "seek_end_of_textual_line", 24, "Seeks the cursor to the end of the line across all text.", 56, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1083 }, +{ PROC_LINKS(seek_beginning_of_line, 0), "seek_beginning_of_line", 22, "Seeks the cursor to the beginning of the visual line.", 53, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1097 }, +{ PROC_LINKS(seek_end_of_line, 0), "seek_end_of_line", 16, "Seeks the cursor to the end of the visual line.", 47, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1111 }, +{ PROC_LINKS(seek_whitespace_up_end_line, 0), "seek_whitespace_up_end_line", 27, "Seeks the cursor up to the next blank line and places it at the end of the line.", 80, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1125 }, +{ PROC_LINKS(seek_whitespace_down_end_line, 0), "seek_whitespace_down_end_line", 29, "Seeks the cursor down to the next blank line and places it at the end of the line.", 82, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1140 }, +{ PROC_LINKS(goto_beginning_of_file, 0), "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1155 }, +{ PROC_LINKS(goto_end_of_file, 0), "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1164 }, +{ PROC_LINKS(seek_whitespace_right, 0), "seek_whitespace_right", 21, "Seek right for the next boundary between whitespace and non-whitespace.", 71, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1179 }, +{ PROC_LINKS(seek_whitespace_left, 0), "seek_whitespace_left", 20, "Seek left for the next boundary between whitespace and non-whitespace.", 70, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1185 }, +{ PROC_LINKS(seek_token_right, 0), "seek_token_right", 16, "Seek right for the next end of a token.", 39, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1191 }, +{ PROC_LINKS(seek_token_left, 0), "seek_token_left", 15, "Seek left for the next beginning of a token.", 44, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1197 }, +{ PROC_LINKS(seek_white_or_token_right, 0), "seek_white_or_token_right", 25, "Seek right for the next end of a token or boundary between whitespace and non-whitespace.", 89, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1203 }, +{ PROC_LINKS(seek_white_or_token_left, 0), "seek_white_or_token_left", 24, "Seek left for the next end of a token or boundary between whitespace and non-whitespace.", 88, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1209 }, +{ PROC_LINKS(seek_alphanumeric_right, 0), "seek_alphanumeric_right", 23, "Seek right for boundary between alphanumeric characters and non-alphanumeric characters.", 88, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1215 }, +{ PROC_LINKS(seek_alphanumeric_left, 0), "seek_alphanumeric_left", 22, "Seek left for boundary between alphanumeric characters and non-alphanumeric characters.", 87, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1221 }, +{ PROC_LINKS(seek_alphanumeric_or_camel_right, 0), "seek_alphanumeric_or_camel_right", 32, "Seek right for boundary between alphanumeric characters or camel case word and non-alphanumeric characters.", 107, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1227 }, +{ PROC_LINKS(seek_alphanumeric_or_camel_left, 0), "seek_alphanumeric_or_camel_left", 31, "Seek left for boundary between alphanumeric characters or camel case word and non-alphanumeric characters.", 106, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1233 }, +{ PROC_LINKS(backspace_word, 0), "backspace_word", 14, "Delete characters between the cursor position and the first alphanumeric boundary to the left.", 94, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1241 }, +{ PROC_LINKS(delete_word, 0), "delete_word", 11, "Delete characters between the cursor position and the first alphanumeric boundary to the right.", 95, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1247 }, +{ PROC_LINKS(snipe_token_or_word, 0), "snipe_token_or_word", 19, "Delete a single, whole token on or to the left of the cursor and post it to the clipboard.", 90, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1253 }, +{ PROC_LINKS(snipe_token_or_word_right, 0), "snipe_token_or_word_right", 25, "Delete a single, whole token on or to the right of the cursor and post it to the clipboard.", 91, "w:\\4ed\\code\\4coder_seek.cpp", 27, 1259 }, +{ PROC_LINKS(write_character, 0), "write_character", 15, "Inserts whatever character was used to trigger this command.", 60, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 71 }, +{ PROC_LINKS(write_underscore, 0), "write_underscore", 16, "Inserts an underscore.", 22, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 80 }, +{ PROC_LINKS(delete_char, 0), "delete_char", 11, "Deletes the character to the right of the cursor.", 49, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 87 }, +{ PROC_LINKS(backspace_char, 0), "backspace_char", 14, "Deletes the character to the left of the cursor.", 48, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 109 }, +{ PROC_LINKS(set_mark, 0), "set_mark", 8, "Sets the mark to the current position of the cursor.", 52, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 133 }, +{ PROC_LINKS(cursor_mark_swap, 0), "cursor_mark_swap", 16, "Swaps the position of the cursor and the mark.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 144 }, +{ PROC_LINKS(delete_range, 0), "delete_range", 12, "Deletes the text in the range between the cursor and the mark.", 62, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 157 }, +{ PROC_LINKS(center_view, 0), "center_view", 11, "Centers the view vertically on the line on which the cursor sits.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 170 }, +{ PROC_LINKS(left_adjust_view, 0), "left_adjust_view", 16, "Sets the left size of the view near the x position of the cursor.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 188 }, +{ PROC_LINKS(click_set_cursor_and_mark, 0), "click_set_cursor_and_mark", 25, "Sets the cursor position and mark to the mouse position.", 56, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 213 }, +{ PROC_LINKS(click_set_cursor, 0), "click_set_cursor", 16, "Sets the cursor position to the mouse position.", 47, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 232 }, +{ PROC_LINKS(click_set_cursor_if_lbutton, 0), "click_set_cursor_if_lbutton", 27, "If the mouse left button is pressed, sets the cursor position to the mouse position.", 84, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 249 }, +{ PROC_LINKS(click_set_mark, 0), "click_set_mark", 14, "Sets the mark position to the mouse position.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 268 }, +{ PROC_LINKS(mouse_wheel_scroll, 0), "mouse_wheel_scroll", 18, "Reads the scroll wheel value from the mouse state and scrolls accordingly.", 74, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 285 }, +{ PROC_LINKS(move_up, 0), "move_up", 7, "Moves the cursor up one line.", 29, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 361 }, +{ PROC_LINKS(move_down, 0), "move_down", 9, "Moves the cursor down one line.", 31, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 367 }, +{ PROC_LINKS(move_up_10, 0), "move_up_10", 10, "Moves the cursor up ten lines.", 30, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 373 }, +{ PROC_LINKS(move_down_10, 0), "move_down_10", 12, "Moves the cursor down ten lines.", 32, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 379 }, +{ PROC_LINKS(move_down_textual, 0), "move_down_textual", 17, "Moves down to the next line of actual text, regardless of line wrapping.", 72, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 385 }, +{ PROC_LINKS(page_up, 0), "page_up", 7, "Scrolls the view up one view height and moves the cursor up one view height.", 76, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 399 }, +{ PROC_LINKS(page_down, 0), "page_down", 9, "Scrolls the view down one view height and moves the cursor down one view height.", 80, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 408 }, +{ PROC_LINKS(move_left, 0), "move_left", 9, "Moves the cursor one character to the left.", 43, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 419 }, +{ PROC_LINKS(move_right, 0), "move_right", 10, "Moves the cursor one character to the right.", 44, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 433 }, +{ PROC_LINKS(select_all, 0), "select_all", 10, "Puts the cursor at the top of the file, and the mark at the bottom of the file.", 79, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 447 }, +{ PROC_LINKS(to_uppercase, 0), "to_uppercase", 12, "Converts all ascii text in the range between the cursor and the mark to uppercase.", 82, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 463 }, +{ PROC_LINKS(to_lowercase, 0), "to_lowercase", 12, "Converts all ascii text in the range between the cursor and the mark to lowercase.", 82, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 483 }, +{ PROC_LINKS(clean_all_lines, 0), "clean_all_lines", 15, "Removes trailing whitespace from all lines in the current buffer.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 503 }, +{ PROC_LINKS(basic_change_active_panel, 0), "basic_change_active_panel", 25, "Change the currently active panel, moving to the panel with the next highest view_id. Will not skipe the build panel if it is open.", 132, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 573 }, +{ PROC_LINKS(close_panel, 0), "close_panel", 11, "Closes the currently active panel if it is not the only panel open.", 67, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 582 }, +{ PROC_LINKS(show_scrollbar, 0), "show_scrollbar", 14, "Sets the current view to show it's scrollbar.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 592 }, +{ PROC_LINKS(hide_scrollbar, 0), "hide_scrollbar", 14, "Sets the current view to hide it's scrollbar.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 600 }, +{ PROC_LINKS(show_filebar, 0), "show_filebar", 12, "Sets the current view to show it's filebar.", 43, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 608 }, +{ PROC_LINKS(hide_filebar, 0), "hide_filebar", 12, "Sets the current view to hide it's filebar.", 43, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 616 }, +{ PROC_LINKS(toggle_filebar, 0), "toggle_filebar", 14, "Toggles the visibility status of the current view's filebar.", 60, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 624 }, +{ PROC_LINKS(toggle_line_wrap, 0), "toggle_line_wrap", 16, "Toggles the current buffer's line wrapping status.", 50, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 634 }, +{ PROC_LINKS(toggle_fps_meter, 0), "toggle_fps_meter", 16, "Toggles the visibility of the FPS performance meter", 51, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 646 }, +{ PROC_LINKS(increase_line_wrap, 0), "increase_line_wrap", 18, "Increases the current buffer's width for line wrapping.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 652 }, +{ PROC_LINKS(decrease_line_wrap, 0), "decrease_line_wrap", 18, "Decrases the current buffer's width for line wrapping.", 54, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 664 }, +{ PROC_LINKS(increase_face_size, 0), "increase_face_size", 18, "Increase the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 676 }, +{ PROC_LINKS(decrease_face_size, 0), "decrease_face_size", 18, "Decrease the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 690 }, +{ PROC_LINKS(mouse_wheel_change_face_size, 0), "mouse_wheel_change_face_size", 28, "Reads the state of the mouse wheel and uses it to either increase or decrease the face size.", 92, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 704 }, +{ PROC_LINKS(toggle_virtual_whitespace, 0), "toggle_virtual_whitespace", 25, "Toggles the current buffer's virtual whitespace status.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 721 }, +{ PROC_LINKS(toggle_show_whitespace, 0), "toggle_show_whitespace", 22, "Toggles the current buffer's whitespace visibility status.", 58, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 733 }, +{ PROC_LINKS(toggle_line_numbers, 0), "toggle_line_numbers", 19, "Toggles the left margin line numbers.", 37, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 743 }, +{ PROC_LINKS(eol_dosify, 0), "eol_dosify", 10, "Puts the buffer in DOS line ending mode.", 40, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 749 }, +{ PROC_LINKS(eol_nixify, 0), "eol_nixify", 10, "Puts the buffer in NIX line ending mode.", 40, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 759 }, +{ PROC_LINKS(exit_4coder, 0), "exit_4coder", 11, "Attempts to close 4coder.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 769 }, +{ PROC_LINKS(goto_line, 0), "goto_line", 9, "Queries the user for a number, and jumps the cursor to the corresponding line.", 78, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 777 }, +{ PROC_LINKS(search, 0), "search", 6, "Begins an incremental search down through the current buffer for a user specified string.", 89, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1005 }, +{ PROC_LINKS(reverse_search, 0), "reverse_search", 14, "Begins an incremental search up through the current buffer for a user specified string.", 87, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1011 }, +{ PROC_LINKS(search_identifier, 0), "search_identifier", 17, "Begins an incremental search down through the current buffer for the word or token under the cursor.", 100, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1017 }, +{ PROC_LINKS(reverse_search_identifier, 0), "reverse_search_identifier", 25, "Begins an incremental search up through the current buffer for the word or token under the cursor.", 98, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1031 }, +{ PROC_LINKS(replace_in_range, 0), "replace_in_range", 16, "Queries the user for two strings, and replaces all occurences of the first string in the range between the cursor and the mark with the second string.", 150, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1045 }, +{ PROC_LINKS(query_replace, 0), "query_replace", 13, "Queries the user for two strings, and incrementally replaces every occurence of the first string with the second string.", 120, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1166 }, +{ PROC_LINKS(query_replace_identifier, 0), "query_replace_identifier", 24, "Queries the user for a string, and incrementally replace every occurence of the word or token found at the cursor with the specified string.", 140, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1189 }, +{ PROC_LINKS(query_replace_selection, 0), "query_replace_selection", 23, "Queries the user for a string, and incrementally replace every occurence of the string found in the selected range with the specified string.", 141, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1208 }, +{ PROC_LINKS(save_all_dirty_buffers, 0), "save_all_dirty_buffers", 22, "Saves all buffers marked dirty (showing the '*' indicator).", 59, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1252 }, +{ PROC_LINKS(delete_file_query, 0), "delete_file_query", 17, "Deletes the file of the current buffer if 4coder has the appropriate access rights. Will ask the user for confirmation first.", 125, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1277 }, +{ PROC_LINKS(save_to_query, 0), "save_to_query", 13, "Queries the user for a file name and saves the contents of the current buffer, altering the buffer's name too.", 110, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1316 }, +{ PROC_LINKS(rename_file_query, 0), "rename_file_query", 17, "Queries the user for a new name and renames the file of the current buffer, altering the buffer's name too.", 107, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1354 }, +{ PROC_LINKS(make_directory_query, 0), "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1397 }, +{ PROC_LINKS(move_line_up, 0), "move_line_up", 12, "Swaps the line under the cursor with the line above it, and moves the cursor up with it.", 88, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1420 }, +{ PROC_LINKS(move_line_down, 0), "move_line_down", 14, "Swaps the line under the cursor with the line below it, and moves the cursor down with it.", 90, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1485 }, +{ PROC_LINKS(duplicate_line, 0), "duplicate_line", 14, "Create a copy of the line on which the cursor sits.", 51, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1507 }, +{ PROC_LINKS(delete_line, 0), "delete_line", 11, "Delete the line the on which the cursor sits.", 45, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1525 }, +{ PROC_LINKS(open_file_in_quotes, 0), "open_file_in_quotes", 19, "Reads a filename from surrounding '\"' characters and attempts to open the corresponding file.", 94, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1621 }, +{ PROC_LINKS(open_matching_file_cpp, 0), "open_matching_file_cpp", 22, "If the current file is a *.cpp or *.h, attempts to open the corresponding *.h or *.cpp file in the other view.", 110, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1659 }, +{ PROC_LINKS(view_buffer_other_panel, 0), "view_buffer_other_panel", 23, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1674 }, +{ PROC_LINKS(swap_buffers_between_panels, 0), "swap_buffers_between_panels", 27, "Set the other non-active panel to view the buffer that the active panel views, and switch to that panel.", 104, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1689 }, +{ PROC_LINKS(kill_buffer, 0), "kill_buffer", 11, "Kills the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1734 }, +{ PROC_LINKS(save, 0), "save", 4, "Saves the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1744 }, +{ PROC_LINKS(reopen, 0), "reopen", 6, "Reopen the current buffer from the hard drive.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1758 }, +{ PROC_LINKS(undo, 0), "undo", 4, "Advances backwards through the undo history of the current buffer.", 66, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1822 }, +{ PROC_LINKS(redo, 0), "redo", 4, "Advances forwards through the undo history of the current buffer.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1838 }, +{ PROC_LINKS(undo_all_buffers, 0), "undo_all_buffers", 16, "Advances backward through the undo history in the buffer containing the most recent regular edit.", 97, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1856 }, +{ PROC_LINKS(redo_all_buffers, 0), "redo_all_buffers", 16, "Advances forward through the undo history in the buffer containing the most recent regular edit.", 96, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1935 }, +{ PROC_LINKS(open_in_other, 0), "open_in_other", 13, "Interactively opens a file in the other panel.", 46, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 2045 }, +{ PROC_LINKS(lister__quit, 0), "lister__quit", 12, "A lister mode command that quits the list without executing any actions.", 72, "w:\\4ed\\code\\4coder_lists.cpp", 28, 8 }, +{ PROC_LINKS(lister__activate, 0), "lister__activate", 16, "A lister mode command that activates the list's action on the highlighted item.", 79, "w:\\4ed\\code\\4coder_lists.cpp", 28, 16 }, +{ PROC_LINKS(lister__write_character, 0), "lister__write_character", 23, "A lister mode command that dispatches to the lister's write character handler.", 78, "w:\\4ed\\code\\4coder_lists.cpp", 28, 32 }, +{ PROC_LINKS(lister__backspace_text_field, 0), "lister__backspace_text_field", 28, "A lister mode command that dispatches to the lister's backspace text field handler.", 83, "w:\\4ed\\code\\4coder_lists.cpp", 28, 43 }, +{ PROC_LINKS(lister__move_up, 0), "lister__move_up", 15, "A lister mode command that dispatches to the lister's navigate up handler.", 74, "w:\\4ed\\code\\4coder_lists.cpp", 28, 54 }, +{ PROC_LINKS(lister__move_down, 0), "lister__move_down", 17, "A lister mode command that dispatches to the lister's navigate down handler.", 76, "w:\\4ed\\code\\4coder_lists.cpp", 28, 65 }, +{ PROC_LINKS(lister__wheel_scroll, 0), "lister__wheel_scroll", 20, "A lister mode command that scrolls the list in response to the mouse wheel.", 75, "w:\\4ed\\code\\4coder_lists.cpp", 28, 76 }, +{ PROC_LINKS(lister__mouse_press, 0), "lister__mouse_press", 19, "A lister mode command that beings a click interaction with a list item under the mouse.", 87, "w:\\4ed\\code\\4coder_lists.cpp", 28, 92 }, +{ PROC_LINKS(lister__mouse_release, 0), "lister__mouse_release", 21, "A lister mode command that ends a click interaction with a list item under the mouse, possibly activating it.", 109, "w:\\4ed\\code\\4coder_lists.cpp", 28, 104 }, +{ PROC_LINKS(lister__repaint, 0), "lister__repaint", 15, "A lister mode command that updates the lists UI data.", 53, "w:\\4ed\\code\\4coder_lists.cpp", 28, 120 }, +{ PROC_LINKS(lister__write_character__default, 0), "lister__write_character__default", 32, "A lister mode command that inserts a new character to the text field.", 69, "w:\\4ed\\code\\4coder_lists.cpp", 28, 131 }, +{ PROC_LINKS(lister__backspace_text_field__default, 0), "lister__backspace_text_field__default", 37, "A lister mode command that backspaces one character from the text field.", 72, "w:\\4ed\\code\\4coder_lists.cpp", 28, 151 }, +{ PROC_LINKS(lister__move_up__default, 0), "lister__move_up__default", 24, "A lister mode command that moves the highlighted item one up in the list.", 73, "w:\\4ed\\code\\4coder_lists.cpp", 28, 166 }, +{ PROC_LINKS(lister__move_down__default, 0), "lister__move_down__default", 26, "A lister mode command that moves the highlighted item one down in the list.", 75, "w:\\4ed\\code\\4coder_lists.cpp", 28, 182 }, +{ PROC_LINKS(lister__write_character__file_path, 0), "lister__write_character__file_path", 34, "A lister mode command that inserts a character into the text field of a file system list.", 89, "w:\\4ed\\code\\4coder_lists.cpp", 28, 198 }, +{ PROC_LINKS(lister__backspace_text_field__file_path, 0), "lister__backspace_text_field__file_path", 39, "A lister mode command that backspaces one character from the text field of a file system list.", 94, "w:\\4ed\\code\\4coder_lists.cpp", 28, 224 }, +{ PROC_LINKS(lister__write_character__fixed_list, 0), "lister__write_character__fixed_list", 35, "A lister mode command that handles input for the fixed sure to kill list.", 73, "w:\\4ed\\code\\4coder_lists.cpp", 28, 266 }, +{ PROC_LINKS(interactive_switch_buffer, 0), "interactive_switch_buffer", 25, "Interactively switch to an open buffer.", 39, "w:\\4ed\\code\\4coder_lists.cpp", 28, 750 }, +{ PROC_LINKS(interactive_kill_buffer, 0), "interactive_kill_buffer", 23, "Interactively kill an open buffer.", 34, "w:\\4ed\\code\\4coder_lists.cpp", 28, 770 }, +{ PROC_LINKS(interactive_open_or_new, 0), "interactive_open_or_new", 23, "Interactively open a file out of the file system.", 49, "w:\\4ed\\code\\4coder_lists.cpp", 28, 845 }, +{ PROC_LINKS(interactive_new, 0), "interactive_new", 15, "Interactively creates a new file.", 33, "w:\\4ed\\code\\4coder_lists.cpp", 28, 885 }, +{ PROC_LINKS(interactive_open, 0), "interactive_open", 16, "Interactively opens a file.", 27, "w:\\4ed\\code\\4coder_lists.cpp", 28, 919 }, +{ PROC_LINKS(command_lister, 0), "command_lister", 14, "Opens an interactive list of all registered commands.", 53, "w:\\4ed\\code\\4coder_lists.cpp", 28, 1004 }, +{ PROC_LINKS(auto_tab_whole_file, 0), "auto_tab_whole_file", 19, "Audo-indents the entire current buffer.", 39, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 610 }, +{ PROC_LINKS(auto_tab_line_at_cursor, 0), "auto_tab_line_at_cursor", 23, "Auto-indents the line on which the cursor sits.", 47, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 623 }, +{ PROC_LINKS(auto_tab_range, 0), "auto_tab_range", 14, "Auto-indents the range between the cursor and the mark.", 55, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 637 }, +{ PROC_LINKS(write_and_auto_tab, 0), "write_and_auto_tab", 18, "Inserts a character and auto-indents the line on which the cursor sits.", 71, "w:\\4ed\\code\\4coder_auto_indent.cpp", 34, 650 }, +{ PROC_LINKS(list_all_locations, 0), "list_all_locations", 18, "Queries the user for a string and lists all exact case-sensitive matches found in all open buffers.", 99, "w:\\4ed\\code\\4coder_search.cpp", 29, 724 }, +{ PROC_LINKS(list_all_substring_locations, 0), "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "w:\\4ed\\code\\4coder_search.cpp", 29, 731 }, +{ PROC_LINKS(list_all_locations_case_insensitive, 0), "list_all_locations_case_insensitive", 35, "Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.", 101, "w:\\4ed\\code\\4coder_search.cpp", 29, 738 }, +{ PROC_LINKS(list_all_substring_locations_case_insensitive, 0), "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "w:\\4ed\\code\\4coder_search.cpp", 29, 745 }, +{ PROC_LINKS(list_all_locations_of_identifier, 0), "list_all_locations_of_identifier", 32, "Reads a token or word under the cursor and lists all exact case-sensitive mathces in all open buffers.", 102, "w:\\4ed\\code\\4coder_search.cpp", 29, 752 }, +{ PROC_LINKS(list_all_locations_of_identifier_case_insensitive, 0), "list_all_locations_of_identifier_case_insensitive", 49, "Reads a token or word under the cursor and lists all exact case-insensitive mathces in all open buffers.", 104, "w:\\4ed\\code\\4coder_search.cpp", 29, 759 }, +{ PROC_LINKS(list_all_locations_of_selection, 0), "list_all_locations_of_selection", 31, "Reads the string in the selected range and lists all exact case-sensitive mathces in all open buffers.", 102, "w:\\4ed\\code\\4coder_search.cpp", 29, 766 }, +{ PROC_LINKS(list_all_locations_of_selection_case_insensitive, 0), "list_all_locations_of_selection_case_insensitive", 48, "Reads the string in the selected range and lists all exact case-insensitive mathces in all open buffers.", 104, "w:\\4ed\\code\\4coder_search.cpp", 29, 773 }, +{ PROC_LINKS(list_all_locations_of_type_definition, 0), "list_all_locations_of_type_definition", 37, "Queries user for string, lists all locations of strings that appear to define a type whose name matches the input string.", 121, "w:\\4ed\\code\\4coder_search.cpp", 29, 780 }, +{ PROC_LINKS(list_all_locations_of_type_definition_of_identifier, 0), "list_all_locations_of_type_definition_of_identifier", 51, "Reads a token or word under the cursor and lists all locations of strings that appear to define a type whose name matches it.", 125, "w:\\4ed\\code\\4coder_search.cpp", 29, 791 }, +{ PROC_LINKS(word_complete, 0), "word_complete", 13, "Iteratively tries completing the word to the left of the cursor with other words in open buffers that have the same prefix string.", 130, "w:\\4ed\\code\\4coder_search.cpp", 29, 815 }, +{ PROC_LINKS(goto_jump_at_cursor_direct, 0), "goto_jump_at_cursor_direct", 26, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.", 187, "w:\\4ed\\code\\4coder_jump_direct.cpp", 34, 8 }, +{ PROC_LINKS(goto_jump_at_cursor_same_panel_direct, 0), "goto_jump_at_cursor_same_panel_direct", 37, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list..", 168, "w:\\4ed\\code\\4coder_jump_direct.cpp", 34, 36 }, +{ PROC_LINKS(goto_next_jump_direct, 0), "goto_next_jump_direct", 21, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.", 123, "w:\\4ed\\code\\4coder_jump_direct.cpp", 34, 61 }, +{ PROC_LINKS(goto_prev_jump_direct, 0), "goto_prev_jump_direct", 21, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations.", 127, "w:\\4ed\\code\\4coder_jump_direct.cpp", 34, 70 }, +{ PROC_LINKS(goto_next_jump_no_skips_direct, 0), "goto_next_jump_no_skips_direct", 30, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, and does not skip sub jump locations.", 132, "w:\\4ed\\code\\4coder_jump_direct.cpp", 34, 79 }, +{ PROC_LINKS(goto_prev_jump_no_skips_direct, 0), "goto_prev_jump_no_skips_direct", 30, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.", 136, "w:\\4ed\\code\\4coder_jump_direct.cpp", 34, 88 }, +{ PROC_LINKS(goto_first_jump_direct, 0), "goto_first_jump_direct", 22, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "w:\\4ed\\code\\4coder_jump_direct.cpp", 34, 97 }, +{ PROC_LINKS(newline_or_goto_position_direct, 0), "newline_or_goto_position_direct", 31, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "w:\\4ed\\code\\4coder_jump_direct.cpp", 34, 112 }, +{ PROC_LINKS(newline_or_goto_position_same_panel_direct, 0), "newline_or_goto_position_same_panel_direct", 42, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "w:\\4ed\\code\\4coder_jump_direct.cpp", 34, 127 }, +{ PROC_LINKS(goto_jump_at_cursor_sticky, 0), "goto_jump_at_cursor_sticky", 26, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.", 187, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 366 }, +{ PROC_LINKS(goto_jump_at_cursor_same_panel_sticky, 0), "goto_jump_at_cursor_same_panel_sticky", 37, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list.", 167, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 398 }, +{ PROC_LINKS(goto_next_jump_sticky, 0), "goto_next_jump_sticky", 21, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.", 123, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 505 }, +{ PROC_LINKS(goto_prev_jump_sticky, 0), "goto_prev_jump_sticky", 21, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations.", 127, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 524 }, +{ PROC_LINKS(goto_next_jump_no_skips_sticky, 0), "goto_next_jump_no_skips_sticky", 30, "If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, and does not skip sub jump locations.", 132, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 537 }, +{ PROC_LINKS(goto_prev_jump_no_skips_sticky, 0), "goto_prev_jump_no_skips_sticky", 30, "If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.", 136, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 556 }, +{ PROC_LINKS(goto_first_jump_sticky, 0), "goto_first_jump_sticky", 22, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 570 }, +{ PROC_LINKS(goto_first_jump_same_panel_sticky, 0), "goto_first_jump_same_panel_sticky", 33, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer and views the buffer in the panel where the jump list was.", 153, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 587 }, +{ PROC_LINKS(newline_or_goto_position_sticky, 0), "newline_or_goto_position_sticky", 31, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 609 }, +{ PROC_LINKS(newline_or_goto_position_same_panel_sticky, 0), "newline_or_goto_position_same_panel_sticky", 42, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "w:\\4ed\\code\\4coder_jump_sticky.cpp", 34, 624 }, +{ PROC_LINKS(view_jump_list_with_lister, 0), "view_jump_list_with_lister", 26, "When executed on a buffer with jumps, creates a persistent lister for all the jumps", 83, "w:\\4ed\\code\\4coder_jump_lister.cpp", 34, 104 }, +{ PROC_LINKS(copy, 0), "copy", 4, "Copy the text in the range from the cursor to the mark onto the clipboard.", 74, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 24 }, +{ PROC_LINKS(cut, 0), "cut", 3, "Cut the text in the range from the cursor to the mark onto the clipboard.", 73, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 35 }, +{ PROC_LINKS(paste, 0), "paste", 5, "At the cursor, insert the text at the top of the clipboard.", 59, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 48 }, +{ PROC_LINKS(paste_next, 0), "paste_next", 10, "If the previous command was paste or paste_next, replaces the paste range with the next text down on the clipboard, otherwise operates as the paste command.", 156, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 87 }, +{ PROC_LINKS(paste_and_indent, 0), "paste_and_indent", 16, "Paste from the top of clipboard and run auto-indent on the newly pasted text.", 77, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 135 }, +{ PROC_LINKS(paste_next_and_indent, 0), "paste_next_and_indent", 21, "Paste the next item on the clipboard and run auto-indent on the newly pasted text.", 82, "w:\\4ed\\code\\4coder_clipboard.cpp", 32, 142 }, +{ PROC_LINKS(execute_previous_cli, 0), "execute_previous_cli", 20, "If the command execute_any_cli has already been used, this will execute a CLI reusing the most recent buffer name and command.", 126, "w:\\4ed\\code\\4coder_system_command.cpp", 37, 7 }, +{ PROC_LINKS(execute_any_cli, 0), "execute_any_cli", 15, "Queries for an output buffer name and system command, runs the system command as a CLI and prints the output to the specified buffer.", 133, "w:\\4ed\\code\\4coder_system_command.cpp", 37, 23 }, +{ PROC_LINKS(build_search, 0), "build_search", 12, "Looks for a build.bat, build.sh, or makefile in the current and parent directories. Runs the first that it finds and prints the output to *compilation*.", 153, "w:\\4ed\\code\\4coder_build_commands.cpp", 37, 128 }, +{ PROC_LINKS(build_in_build_panel, 0), "build_in_build_panel", 20, "Looks for a build.bat, build.sh, or makefile in the current and parent directories. Runs the first that it finds and prints the output to *compilation*. Puts the *compilation* buffer in a panel at the footer of the current view.", 230, "w:\\4ed\\code\\4coder_build_commands.cpp", 37, 166 }, +{ PROC_LINKS(close_build_panel, 0), "close_build_panel", 17, "If the special build panel is open, closes it.", 46, "w:\\4ed\\code\\4coder_build_commands.cpp", 37, 183 }, +{ PROC_LINKS(change_to_build_panel, 0), "change_to_build_panel", 21, "If the special build panel is open, makes the build panel the active panel.", 75, "w:\\4ed\\code\\4coder_build_commands.cpp", 37, 189 }, +{ PROC_LINKS(close_all_code, 0), "close_all_code", 14, "Closes any buffer with a filename ending with an extension configured to be recognized as a code file type.", 107, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 931 }, +{ PROC_LINKS(open_all_code, 0), "open_all_code", 13, "Open all code in the current directory. File types are determined by extensions. An extension is considered code based on the extensions specified in 4coder.config.", 164, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 937 }, +{ PROC_LINKS(open_all_code_recursive, 0), "open_all_code_recursive", 23, "Works as open_all_code but also runs in all subdirectories.", 59, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 943 }, +{ PROC_LINKS(load_project, 0), "load_project", 12, "Looks for a project.4coder file in the current directory and tries to load it. Looks in parent directories until a project file is found or there are no more parents.", 167, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 951 }, +{ PROC_LINKS(project_fkey_command, 0), "project_fkey_command", 20, "Run an 'fkey command' configured in a project.4coder file. Determines the index of the 'fkey command' by which function key or numeric key was pressed to trigger the command.", 175, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 958 }, +{ PROC_LINKS(project_go_to_root_directory, 0), "project_go_to_root_directory", 28, "Changes 4coder's hot directory to the root directory of the currently loaded project. With no loaded project nothing hapepns.", 125, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 981 }, +{ PROC_LINKS(setup_new_project, 0), "setup_new_project", 17, "Queries the user for several configuration options and initializes a new 4coder project with build scripts for every OS.", 120, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1322 }, +{ PROC_LINKS(setup_build_bat, 0), "setup_build_bat", 15, "Queries the user for several configuration options and initializes a new build batch script.", 92, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1329 }, +{ PROC_LINKS(setup_build_sh, 0), "setup_build_sh", 14, "Queries the user for several configuration options and initializes a new build shell script.", 92, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1335 }, +{ PROC_LINKS(setup_build_bat_and_sh, 0), "setup_build_bat_and_sh", 22, "Queries the user for several configuration options and initializes a new build batch script.", 92, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1341 }, +{ PROC_LINKS(project_command_lister, 0), "project_command_lister", 22, "Open a lister of all commands in the currently loaded project.", 62, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1356 }, +{ PROC_LINKS(list_all_functions_current_buffer, 0), "list_all_functions_current_buffer", 33, "Creates a jump list of lines of the current buffer that appear to define or declare functions.", 94, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 273 }, +{ PROC_LINKS(list_all_functions_current_buffer_lister, 0), "list_all_functions_current_buffer_lister", 40, "Creates a lister of locations that look like function definitions and declarations in the buffer.", 97, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 285 }, +{ PROC_LINKS(list_all_functions_all_buffers, 0), "list_all_functions_all_buffers", 30, "Creates a jump list of lines from all buffers that appear to define or declare functions.", 89, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 299 }, +{ PROC_LINKS(list_all_functions_all_buffers_lister, 0), "list_all_functions_all_buffers_lister", 37, "Creates a lister of locations that look like function definitions and declarations all buffers.", 95, "w:\\4ed\\code\\4coder_function_list.cpp", 36, 305 }, +{ PROC_LINKS(select_surrounding_scope, 0), "select_surrounding_scope", 24, "Finds the scope enclosed by '{' '}' surrounding the cursor and puts the cursor and mark on the '{' and '}'.", 107, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 339 }, +{ PROC_LINKS(select_next_scope_absolute, 0), "select_next_scope_absolute", 26, "Finds the first scope started by '{' after the cursor and puts the cursor and mark on the '{' and '}'.", 102, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 357 }, +{ PROC_LINKS(select_prev_scope_absolute, 0), "select_prev_scope_absolute", 26, "Finds the first scope started by '{' before the cursor and puts the cursor and mark on the '{' and '}'.", 103, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 379 }, +{ PROC_LINKS(place_in_scope, 0), "place_in_scope", 14, "Wraps the code contained in the range between cursor and mark with a new curly brace scope.", 91, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 478 }, +{ PROC_LINKS(delete_current_scope, 0), "delete_current_scope", 20, "Deletes the braces surrounding the currently selected scope. Leaves the contents within the scope.", 99, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 484 }, +{ PROC_LINKS(scope_absorb_down, 0), "scope_absorb_down", 17, "If a scope is currently selected, and a statement or block statement is present below the current scope, the statement is moved into the scope.", 143, "w:\\4ed\\code\\4coder_scope_commands.cpp", 37, 718 }, +{ PROC_LINKS(open_long_braces, 0), "open_long_braces", 16, "At the cursor, insert a '{' and '}' separated by a blank line.", 62, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 52 }, +{ PROC_LINKS(open_long_braces_semicolon, 0), "open_long_braces_semicolon", 26, "At the cursor, insert a '{' and '};' separated by a blank line.", 63, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 60 }, +{ PROC_LINKS(open_long_braces_break, 0), "open_long_braces_break", 22, "At the cursor, insert a '{' and '}break;' separated by a blank line.", 68, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 68 }, +{ PROC_LINKS(if0_off, 0), "if0_off", 7, "Surround the range between the cursor and mark with an '#if 0' and an '#endif'", 78, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 76 }, +{ PROC_LINKS(write_todo, 0), "write_todo", 10, "At the cursor, insert a '// TODO' comment, includes user name if it was specified in config.4coder.", 99, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 82 }, +{ PROC_LINKS(write_hack, 0), "write_hack", 10, "At the cursor, insert a '// HACK' comment, includes user name if it was specified in config.4coder.", 99, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 88 }, +{ PROC_LINKS(write_note, 0), "write_note", 10, "At the cursor, insert a '// NOTE' comment, includes user name if it was specified in config.4coder.", 99, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 94 }, +{ PROC_LINKS(write_block, 0), "write_block", 11, "At the cursor, insert a block comment.", 38, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 100 }, +{ PROC_LINKS(write_zero_struct, 0), "write_zero_struct", 17, "At the cursor, insert a ' = {};'.", 33, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 106 }, +{ PROC_LINKS(comment_line, 0), "comment_line", 12, "Insert '//' at the beginning of the line after leading whitespace.", 66, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 135 }, +{ PROC_LINKS(uncomment_line, 0), "uncomment_line", 14, "If present, delete '//' at the beginning of the line after leading whitespace.", 78, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 149 }, +{ PROC_LINKS(comment_line_toggle, 0), "comment_line_toggle", 19, "Turns uncommented lines into commented lines and vice versa for comments starting with '//'.", 92, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 163 }, +{ PROC_LINKS(snippet_lister, 0), "snippet_lister", 14, "Opens a snippet lister for inserting whole pre-written snippets of text.", 72, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 252 }, +{ PROC_LINKS(set_bindings_choose, 0), "set_bindings_choose", 19, "Remap keybindings using the 'choose' mapping rule.", 50, "w:\\4ed\\code\\4coder_remapping_commands.cpp", 41, 39 }, +{ PROC_LINKS(set_bindings_default, 0), "set_bindings_default", 20, "Remap keybindings using the 'default' mapping rule.", 51, "w:\\4ed\\code\\4coder_remapping_commands.cpp", 41, 49 }, +{ PROC_LINKS(set_bindings_mac_default, 0), "set_bindings_mac_default", 24, "Remap keybindings using the 'mac-default' mapping rule.", 55, "w:\\4ed\\code\\4coder_remapping_commands.cpp", 41, 64 }, +{ PROC_LINKS(miblo_increment_basic, 0), "miblo_increment_basic", 21, "Increment an integer under the cursor by one.", 45, "w:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 95 }, +{ PROC_LINKS(miblo_decrement_basic, 0), "miblo_decrement_basic", 21, "Decrement an integer under the cursor by one.", 45, "w:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 113 }, +{ PROC_LINKS(miblo_increment_time_stamp, 0), "miblo_increment_time_stamp", 26, "Increment a time stamp under the cursor by one second. (format [m]m:ss or h:mm:ss", 81, "w:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 383 }, +{ PROC_LINKS(miblo_decrement_time_stamp, 0), "miblo_decrement_time_stamp", 26, "Decrement a time stamp under the cursor by one second. (format [m]m:ss or h:mm:ss", 81, "w:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 389 }, +{ PROC_LINKS(miblo_increment_time_stamp_minute, 0), "miblo_increment_time_stamp_minute", 33, "Increment a time stamp under the cursor by one minute. (format [m]m:ss or h:mm:ss", 81, "w:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 395 }, +{ PROC_LINKS(miblo_decrement_time_stamp_minute, 0), "miblo_decrement_time_stamp_minute", 33, "Decrement a time stamp under the cursor by one minute. (format [m]m:ss or h:mm:ss", 81, "w:\\4ed\\code\\4coder_miblo_numbers.cpp", 36, 401 }, +{ PROC_LINKS(kill_rect, 0), "kill_rect", 9, "Delete characters in a rectangular region. Range testing is done by unwrapped-xy coordinates.", 93, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 50 }, +{ PROC_LINKS(multi_line_edit, 0), "multi_line_edit", 15, "Begin multi-line mode. In multi-line mode characters are inserted at every line between the mark and cursor. All characters are inserted at the same character offset into the line. This mode uses line_char coordinates.", 221, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 137 }, +{ PROC_LINKS(rename_parameter, 0), "rename_parameter", 16, "If the cursor is found to be on the name of a function parameter in the signature of a function definition, all occurences within the scope of the function will be replaced with a new provided string.", 200, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 424 }, +{ PROC_LINKS(write_explicit_enum_values, 0), "write_explicit_enum_values", 26, "If the cursor is found to be on the '{' of an enum definition, the values of the enum will be filled in sequentially starting from zero. Existing values are overwritten.", 170, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 733 }, +{ PROC_LINKS(write_explicit_enum_flags, 0), "write_explicit_enum_flags", 25, "If the cursor is found to be on the '{' of an enum definition, the values of the enum will be filled in to give each a unique power of 2 value, starting from 1. Existing values are overwritten.", 194, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 739 }, }; -static int32_t fcoder_metacmd_ID_allow_mouse = 0; -static int32_t fcoder_metacmd_ID_auto_tab_line_at_cursor = 1; -static int32_t fcoder_metacmd_ID_auto_tab_range = 2; -static int32_t fcoder_metacmd_ID_auto_tab_whole_file = 3; -static int32_t fcoder_metacmd_ID_backspace_char = 4; -static int32_t fcoder_metacmd_ID_backspace_word = 5; -static int32_t fcoder_metacmd_ID_basic_change_active_panel = 6; -static int32_t fcoder_metacmd_ID_build_in_build_panel = 7; -static int32_t fcoder_metacmd_ID_build_search = 8; -static int32_t fcoder_metacmd_ID_center_view = 9; -static int32_t fcoder_metacmd_ID_change_active_panel = 10; -static int32_t fcoder_metacmd_ID_change_active_panel_backwards = 11; -static int32_t fcoder_metacmd_ID_change_to_build_panel = 12; -static int32_t fcoder_metacmd_ID_clean_all_lines = 13; -static int32_t fcoder_metacmd_ID_click_set_cursor = 14; -static int32_t fcoder_metacmd_ID_click_set_cursor_and_mark = 15; -static int32_t fcoder_metacmd_ID_click_set_cursor_if_lbutton = 16; -static int32_t fcoder_metacmd_ID_click_set_mark = 17; -static int32_t fcoder_metacmd_ID_close_all_code = 18; -static int32_t fcoder_metacmd_ID_close_build_panel = 19; -static int32_t fcoder_metacmd_ID_close_panel = 20; -static int32_t fcoder_metacmd_ID_command_lister = 21; -static int32_t fcoder_metacmd_ID_comment_line = 22; -static int32_t fcoder_metacmd_ID_comment_line_toggle = 23; -static int32_t fcoder_metacmd_ID_copy = 24; -static int32_t fcoder_metacmd_ID_cursor_mark_swap = 25; -static int32_t fcoder_metacmd_ID_cut = 26; -static int32_t fcoder_metacmd_ID_decrease_face_size = 27; -static int32_t fcoder_metacmd_ID_decrease_line_wrap = 28; -static int32_t fcoder_metacmd_ID_delete_char = 29; -static int32_t fcoder_metacmd_ID_delete_current_scope = 30; -static int32_t fcoder_metacmd_ID_delete_file_query = 31; -static int32_t fcoder_metacmd_ID_delete_line = 32; -static int32_t fcoder_metacmd_ID_delete_range = 33; -static int32_t fcoder_metacmd_ID_delete_word = 34; -static int32_t fcoder_metacmd_ID_duplicate_line = 35; -static int32_t fcoder_metacmd_ID_eol_dosify = 36; -static int32_t fcoder_metacmd_ID_eol_nixify = 37; -static int32_t fcoder_metacmd_ID_execute_any_cli = 38; -static int32_t fcoder_metacmd_ID_execute_previous_cli = 39; -static int32_t fcoder_metacmd_ID_exit_4coder = 40; -static int32_t fcoder_metacmd_ID_goto_beginning_of_file = 41; -static int32_t fcoder_metacmd_ID_goto_end_of_file = 42; -static int32_t fcoder_metacmd_ID_goto_first_jump_direct = 43; -static int32_t fcoder_metacmd_ID_goto_first_jump_same_panel_sticky = 44; -static int32_t fcoder_metacmd_ID_goto_first_jump_sticky = 45; -static int32_t fcoder_metacmd_ID_goto_jump_at_cursor_direct = 46; -static int32_t fcoder_metacmd_ID_goto_jump_at_cursor_same_panel_direct = 47; -static int32_t fcoder_metacmd_ID_goto_jump_at_cursor_same_panel_sticky = 48; -static int32_t fcoder_metacmd_ID_goto_jump_at_cursor_sticky = 49; -static int32_t fcoder_metacmd_ID_goto_line = 50; -static int32_t fcoder_metacmd_ID_goto_next_jump_direct = 51; -static int32_t fcoder_metacmd_ID_goto_next_jump_no_skips_direct = 52; -static int32_t fcoder_metacmd_ID_goto_next_jump_no_skips_sticky = 53; -static int32_t fcoder_metacmd_ID_goto_next_jump_sticky = 54; -static int32_t fcoder_metacmd_ID_goto_prev_jump_direct = 55; -static int32_t fcoder_metacmd_ID_goto_prev_jump_no_skips_direct = 56; -static int32_t fcoder_metacmd_ID_goto_prev_jump_no_skips_sticky = 57; -static int32_t fcoder_metacmd_ID_goto_prev_jump_sticky = 58; -static int32_t fcoder_metacmd_ID_hide_filebar = 59; -static int32_t fcoder_metacmd_ID_hide_scrollbar = 60; -static int32_t fcoder_metacmd_ID_if0_off = 61; -static int32_t fcoder_metacmd_ID_increase_face_size = 62; -static int32_t fcoder_metacmd_ID_increase_line_wrap = 63; -static int32_t fcoder_metacmd_ID_interactive_kill_buffer = 64; -static int32_t fcoder_metacmd_ID_interactive_new = 65; -static int32_t fcoder_metacmd_ID_interactive_open = 66; -static int32_t fcoder_metacmd_ID_interactive_open_or_new = 67; -static int32_t fcoder_metacmd_ID_interactive_switch_buffer = 68; -static int32_t fcoder_metacmd_ID_kill_buffer = 69; -static int32_t fcoder_metacmd_ID_kill_rect = 70; -static int32_t fcoder_metacmd_ID_left_adjust_view = 71; -static int32_t fcoder_metacmd_ID_list_all_functions_all_buffers = 72; -static int32_t fcoder_metacmd_ID_list_all_functions_all_buffers_lister = 73; -static int32_t fcoder_metacmd_ID_list_all_functions_current_buffer = 74; -static int32_t fcoder_metacmd_ID_list_all_functions_current_buffer_lister = 75; -static int32_t fcoder_metacmd_ID_list_all_locations = 76; -static int32_t fcoder_metacmd_ID_list_all_locations_case_insensitive = 77; -static int32_t fcoder_metacmd_ID_list_all_locations_of_identifier = 78; -static int32_t fcoder_metacmd_ID_list_all_locations_of_identifier_case_insensitive = 79; -static int32_t fcoder_metacmd_ID_list_all_locations_of_selection = 80; -static int32_t fcoder_metacmd_ID_list_all_locations_of_selection_case_insensitive = 81; -static int32_t fcoder_metacmd_ID_list_all_locations_of_type_definition = 82; -static int32_t fcoder_metacmd_ID_list_all_locations_of_type_definition_of_identifier = 83; -static int32_t fcoder_metacmd_ID_list_all_substring_locations = 84; -static int32_t fcoder_metacmd_ID_list_all_substring_locations_case_insensitive = 85; -static int32_t fcoder_metacmd_ID_lister__activate = 86; -static int32_t fcoder_metacmd_ID_lister__backspace_text_field = 87; -static int32_t fcoder_metacmd_ID_lister__backspace_text_field__default = 88; -static int32_t fcoder_metacmd_ID_lister__backspace_text_field__file_path = 89; -static int32_t fcoder_metacmd_ID_lister__mouse_press = 90; -static int32_t fcoder_metacmd_ID_lister__mouse_release = 91; -static int32_t fcoder_metacmd_ID_lister__move_down = 92; -static int32_t fcoder_metacmd_ID_lister__move_down__default = 93; -static int32_t fcoder_metacmd_ID_lister__move_up = 94; -static int32_t fcoder_metacmd_ID_lister__move_up__default = 95; -static int32_t fcoder_metacmd_ID_lister__quit = 96; -static int32_t fcoder_metacmd_ID_lister__repaint = 97; -static int32_t fcoder_metacmd_ID_lister__wheel_scroll = 98; -static int32_t fcoder_metacmd_ID_lister__write_character = 99; -static int32_t fcoder_metacmd_ID_lister__write_character__default = 100; -static int32_t fcoder_metacmd_ID_lister__write_character__file_path = 101; -static int32_t fcoder_metacmd_ID_lister__write_character__fixed_list = 102; -static int32_t fcoder_metacmd_ID_load_project = 103; -static int32_t fcoder_metacmd_ID_make_directory_query = 104; -static int32_t fcoder_metacmd_ID_miblo_decrement_basic = 105; -static int32_t fcoder_metacmd_ID_miblo_decrement_time_stamp = 106; -static int32_t fcoder_metacmd_ID_miblo_decrement_time_stamp_minute = 107; -static int32_t fcoder_metacmd_ID_miblo_increment_basic = 108; -static int32_t fcoder_metacmd_ID_miblo_increment_time_stamp = 109; -static int32_t fcoder_metacmd_ID_miblo_increment_time_stamp_minute = 110; -static int32_t fcoder_metacmd_ID_mouse_wheel_change_face_size = 111; -static int32_t fcoder_metacmd_ID_mouse_wheel_scroll = 112; -static int32_t fcoder_metacmd_ID_move_down = 113; -static int32_t fcoder_metacmd_ID_move_down_10 = 114; -static int32_t fcoder_metacmd_ID_move_down_textual = 115; -static int32_t fcoder_metacmd_ID_move_left = 116; -static int32_t fcoder_metacmd_ID_move_line_down = 117; -static int32_t fcoder_metacmd_ID_move_line_up = 118; -static int32_t fcoder_metacmd_ID_move_right = 119; -static int32_t fcoder_metacmd_ID_move_up = 120; -static int32_t fcoder_metacmd_ID_move_up_10 = 121; -static int32_t fcoder_metacmd_ID_multi_line_edit = 122; -static int32_t fcoder_metacmd_ID_newline_or_goto_position_direct = 123; -static int32_t fcoder_metacmd_ID_newline_or_goto_position_same_panel_direct = 124; -static int32_t fcoder_metacmd_ID_newline_or_goto_position_same_panel_sticky = 125; -static int32_t fcoder_metacmd_ID_newline_or_goto_position_sticky = 126; -static int32_t fcoder_metacmd_ID_open_all_code = 127; -static int32_t fcoder_metacmd_ID_open_all_code_recursive = 128; -static int32_t fcoder_metacmd_ID_open_file_in_quotes = 129; -static int32_t fcoder_metacmd_ID_open_in_other = 130; -static int32_t fcoder_metacmd_ID_open_long_braces = 131; -static int32_t fcoder_metacmd_ID_open_long_braces_break = 132; -static int32_t fcoder_metacmd_ID_open_long_braces_semicolon = 133; -static int32_t fcoder_metacmd_ID_open_matching_file_cpp = 134; -static int32_t fcoder_metacmd_ID_open_panel_hsplit = 135; -static int32_t fcoder_metacmd_ID_open_panel_vsplit = 136; -static int32_t fcoder_metacmd_ID_page_down = 137; -static int32_t fcoder_metacmd_ID_page_up = 138; -static int32_t fcoder_metacmd_ID_paste = 139; -static int32_t fcoder_metacmd_ID_paste_and_indent = 140; -static int32_t fcoder_metacmd_ID_paste_next = 141; -static int32_t fcoder_metacmd_ID_paste_next_and_indent = 142; -static int32_t fcoder_metacmd_ID_place_in_scope = 143; -static int32_t fcoder_metacmd_ID_project_command_lister = 144; -static int32_t fcoder_metacmd_ID_project_fkey_command = 145; -static int32_t fcoder_metacmd_ID_project_go_to_root_directory = 146; -static int32_t fcoder_metacmd_ID_query_replace = 147; -static int32_t fcoder_metacmd_ID_query_replace_identifier = 148; -static int32_t fcoder_metacmd_ID_query_replace_selection = 149; -static int32_t fcoder_metacmd_ID_redo = 150; -static int32_t fcoder_metacmd_ID_redo_all_buffers = 151; -static int32_t fcoder_metacmd_ID_remap_interactive = 152; -static int32_t fcoder_metacmd_ID_rename_file_query = 153; -static int32_t fcoder_metacmd_ID_rename_parameter = 154; -static int32_t fcoder_metacmd_ID_reopen = 155; -static int32_t fcoder_metacmd_ID_replace_all_occurrences = 156; -static int32_t fcoder_metacmd_ID_replace_in_range = 157; -static int32_t fcoder_metacmd_ID_reverse_search = 158; -static int32_t fcoder_metacmd_ID_reverse_search_identifier = 159; -static int32_t fcoder_metacmd_ID_save = 160; -static int32_t fcoder_metacmd_ID_save_all_dirty_buffers = 161; -static int32_t fcoder_metacmd_ID_save_to_query = 162; -static int32_t fcoder_metacmd_ID_scope_absorb_down = 163; -static int32_t fcoder_metacmd_ID_search = 164; -static int32_t fcoder_metacmd_ID_search_identifier = 165; -static int32_t fcoder_metacmd_ID_seek_alphanumeric_left = 166; -static int32_t fcoder_metacmd_ID_seek_alphanumeric_or_camel_left = 167; -static int32_t fcoder_metacmd_ID_seek_alphanumeric_or_camel_right = 168; -static int32_t fcoder_metacmd_ID_seek_alphanumeric_right = 169; -static int32_t fcoder_metacmd_ID_seek_beginning_of_line = 170; -static int32_t fcoder_metacmd_ID_seek_beginning_of_textual_line = 171; -static int32_t fcoder_metacmd_ID_seek_end_of_line = 172; -static int32_t fcoder_metacmd_ID_seek_end_of_textual_line = 173; -static int32_t fcoder_metacmd_ID_seek_token_left = 174; -static int32_t fcoder_metacmd_ID_seek_token_right = 175; -static int32_t fcoder_metacmd_ID_seek_white_or_token_left = 176; -static int32_t fcoder_metacmd_ID_seek_white_or_token_right = 177; -static int32_t fcoder_metacmd_ID_seek_whitespace_down = 178; -static int32_t fcoder_metacmd_ID_seek_whitespace_down_end_line = 179; -static int32_t fcoder_metacmd_ID_seek_whitespace_left = 180; -static int32_t fcoder_metacmd_ID_seek_whitespace_right = 181; -static int32_t fcoder_metacmd_ID_seek_whitespace_up = 182; -static int32_t fcoder_metacmd_ID_seek_whitespace_up_end_line = 183; -static int32_t fcoder_metacmd_ID_select_all = 184; -static int32_t fcoder_metacmd_ID_select_next_scope_absolute = 185; -static int32_t fcoder_metacmd_ID_select_prev_scope_absolute = 186; -static int32_t fcoder_metacmd_ID_select_surrounding_scope = 187; -static int32_t fcoder_metacmd_ID_set_bindings_choose = 188; -static int32_t fcoder_metacmd_ID_set_bindings_default = 189; -static int32_t fcoder_metacmd_ID_set_bindings_mac_default = 190; -static int32_t fcoder_metacmd_ID_set_mark = 191; -static int32_t fcoder_metacmd_ID_set_mode_to_notepad_like = 192; -static int32_t fcoder_metacmd_ID_set_mode_to_original = 193; -static int32_t fcoder_metacmd_ID_setup_build_bat = 194; +static int32_t fcoder_metacmd_ID_replace_all_occurrences = 0; +static int32_t fcoder_metacmd_ID_change_active_panel = 1; +static int32_t fcoder_metacmd_ID_change_active_panel_backwards = 2; +static int32_t fcoder_metacmd_ID_open_panel_vsplit = 3; +static int32_t fcoder_metacmd_ID_open_panel_hsplit = 4; +static int32_t fcoder_metacmd_ID_suppress_mouse = 5; +static int32_t fcoder_metacmd_ID_allow_mouse = 6; +static int32_t fcoder_metacmd_ID_toggle_mouse = 7; +static int32_t fcoder_metacmd_ID_set_mode_to_original = 8; +static int32_t fcoder_metacmd_ID_set_mode_to_notepad_like = 9; +static int32_t fcoder_metacmd_ID_toggle_highlight_line_at_cursor = 10; +static int32_t fcoder_metacmd_ID_toggle_highlight_enclosing_scopes = 11; +static int32_t fcoder_metacmd_ID_toggle_paren_matching_helper = 12; +static int32_t fcoder_metacmd_ID_toggle_fullscreen = 13; +static int32_t fcoder_metacmd_ID_remap_interactive = 14; +static int32_t fcoder_metacmd_ID_seek_whitespace_up = 15; +static int32_t fcoder_metacmd_ID_seek_whitespace_down = 16; +static int32_t fcoder_metacmd_ID_seek_beginning_of_textual_line = 17; +static int32_t fcoder_metacmd_ID_seek_end_of_textual_line = 18; +static int32_t fcoder_metacmd_ID_seek_beginning_of_line = 19; +static int32_t fcoder_metacmd_ID_seek_end_of_line = 20; +static int32_t fcoder_metacmd_ID_seek_whitespace_up_end_line = 21; +static int32_t fcoder_metacmd_ID_seek_whitespace_down_end_line = 22; +static int32_t fcoder_metacmd_ID_goto_beginning_of_file = 23; +static int32_t fcoder_metacmd_ID_goto_end_of_file = 24; +static int32_t fcoder_metacmd_ID_seek_whitespace_right = 25; +static int32_t fcoder_metacmd_ID_seek_whitespace_left = 26; +static int32_t fcoder_metacmd_ID_seek_token_right = 27; +static int32_t fcoder_metacmd_ID_seek_token_left = 28; +static int32_t fcoder_metacmd_ID_seek_white_or_token_right = 29; +static int32_t fcoder_metacmd_ID_seek_white_or_token_left = 30; +static int32_t fcoder_metacmd_ID_seek_alphanumeric_right = 31; +static int32_t fcoder_metacmd_ID_seek_alphanumeric_left = 32; +static int32_t fcoder_metacmd_ID_seek_alphanumeric_or_camel_right = 33; +static int32_t fcoder_metacmd_ID_seek_alphanumeric_or_camel_left = 34; +static int32_t fcoder_metacmd_ID_backspace_word = 35; +static int32_t fcoder_metacmd_ID_delete_word = 36; +static int32_t fcoder_metacmd_ID_snipe_token_or_word = 37; +static int32_t fcoder_metacmd_ID_snipe_token_or_word_right = 38; +static int32_t fcoder_metacmd_ID_write_character = 39; +static int32_t fcoder_metacmd_ID_write_underscore = 40; +static int32_t fcoder_metacmd_ID_delete_char = 41; +static int32_t fcoder_metacmd_ID_backspace_char = 42; +static int32_t fcoder_metacmd_ID_set_mark = 43; +static int32_t fcoder_metacmd_ID_cursor_mark_swap = 44; +static int32_t fcoder_metacmd_ID_delete_range = 45; +static int32_t fcoder_metacmd_ID_center_view = 46; +static int32_t fcoder_metacmd_ID_left_adjust_view = 47; +static int32_t fcoder_metacmd_ID_click_set_cursor_and_mark = 48; +static int32_t fcoder_metacmd_ID_click_set_cursor = 49; +static int32_t fcoder_metacmd_ID_click_set_cursor_if_lbutton = 50; +static int32_t fcoder_metacmd_ID_click_set_mark = 51; +static int32_t fcoder_metacmd_ID_mouse_wheel_scroll = 52; +static int32_t fcoder_metacmd_ID_move_up = 53; +static int32_t fcoder_metacmd_ID_move_down = 54; +static int32_t fcoder_metacmd_ID_move_up_10 = 55; +static int32_t fcoder_metacmd_ID_move_down_10 = 56; +static int32_t fcoder_metacmd_ID_move_down_textual = 57; +static int32_t fcoder_metacmd_ID_page_up = 58; +static int32_t fcoder_metacmd_ID_page_down = 59; +static int32_t fcoder_metacmd_ID_move_left = 60; +static int32_t fcoder_metacmd_ID_move_right = 61; +static int32_t fcoder_metacmd_ID_select_all = 62; +static int32_t fcoder_metacmd_ID_to_uppercase = 63; +static int32_t fcoder_metacmd_ID_to_lowercase = 64; +static int32_t fcoder_metacmd_ID_clean_all_lines = 65; +static int32_t fcoder_metacmd_ID_basic_change_active_panel = 66; +static int32_t fcoder_metacmd_ID_close_panel = 67; +static int32_t fcoder_metacmd_ID_show_scrollbar = 68; +static int32_t fcoder_metacmd_ID_hide_scrollbar = 69; +static int32_t fcoder_metacmd_ID_show_filebar = 70; +static int32_t fcoder_metacmd_ID_hide_filebar = 71; +static int32_t fcoder_metacmd_ID_toggle_filebar = 72; +static int32_t fcoder_metacmd_ID_toggle_line_wrap = 73; +static int32_t fcoder_metacmd_ID_toggle_fps_meter = 74; +static int32_t fcoder_metacmd_ID_increase_line_wrap = 75; +static int32_t fcoder_metacmd_ID_decrease_line_wrap = 76; +static int32_t fcoder_metacmd_ID_increase_face_size = 77; +static int32_t fcoder_metacmd_ID_decrease_face_size = 78; +static int32_t fcoder_metacmd_ID_mouse_wheel_change_face_size = 79; +static int32_t fcoder_metacmd_ID_toggle_virtual_whitespace = 80; +static int32_t fcoder_metacmd_ID_toggle_show_whitespace = 81; +static int32_t fcoder_metacmd_ID_toggle_line_numbers = 82; +static int32_t fcoder_metacmd_ID_eol_dosify = 83; +static int32_t fcoder_metacmd_ID_eol_nixify = 84; +static int32_t fcoder_metacmd_ID_exit_4coder = 85; +static int32_t fcoder_metacmd_ID_goto_line = 86; +static int32_t fcoder_metacmd_ID_search = 87; +static int32_t fcoder_metacmd_ID_reverse_search = 88; +static int32_t fcoder_metacmd_ID_search_identifier = 89; +static int32_t fcoder_metacmd_ID_reverse_search_identifier = 90; +static int32_t fcoder_metacmd_ID_replace_in_range = 91; +static int32_t fcoder_metacmd_ID_query_replace = 92; +static int32_t fcoder_metacmd_ID_query_replace_identifier = 93; +static int32_t fcoder_metacmd_ID_query_replace_selection = 94; +static int32_t fcoder_metacmd_ID_save_all_dirty_buffers = 95; +static int32_t fcoder_metacmd_ID_delete_file_query = 96; +static int32_t fcoder_metacmd_ID_save_to_query = 97; +static int32_t fcoder_metacmd_ID_rename_file_query = 98; +static int32_t fcoder_metacmd_ID_make_directory_query = 99; +static int32_t fcoder_metacmd_ID_move_line_up = 100; +static int32_t fcoder_metacmd_ID_move_line_down = 101; +static int32_t fcoder_metacmd_ID_duplicate_line = 102; +static int32_t fcoder_metacmd_ID_delete_line = 103; +static int32_t fcoder_metacmd_ID_open_file_in_quotes = 104; +static int32_t fcoder_metacmd_ID_open_matching_file_cpp = 105; +static int32_t fcoder_metacmd_ID_view_buffer_other_panel = 106; +static int32_t fcoder_metacmd_ID_swap_buffers_between_panels = 107; +static int32_t fcoder_metacmd_ID_kill_buffer = 108; +static int32_t fcoder_metacmd_ID_save = 109; +static int32_t fcoder_metacmd_ID_reopen = 110; +static int32_t fcoder_metacmd_ID_undo = 111; +static int32_t fcoder_metacmd_ID_redo = 112; +static int32_t fcoder_metacmd_ID_undo_all_buffers = 113; +static int32_t fcoder_metacmd_ID_redo_all_buffers = 114; +static int32_t fcoder_metacmd_ID_open_in_other = 115; +static int32_t fcoder_metacmd_ID_lister__quit = 116; +static int32_t fcoder_metacmd_ID_lister__activate = 117; +static int32_t fcoder_metacmd_ID_lister__write_character = 118; +static int32_t fcoder_metacmd_ID_lister__backspace_text_field = 119; +static int32_t fcoder_metacmd_ID_lister__move_up = 120; +static int32_t fcoder_metacmd_ID_lister__move_down = 121; +static int32_t fcoder_metacmd_ID_lister__wheel_scroll = 122; +static int32_t fcoder_metacmd_ID_lister__mouse_press = 123; +static int32_t fcoder_metacmd_ID_lister__mouse_release = 124; +static int32_t fcoder_metacmd_ID_lister__repaint = 125; +static int32_t fcoder_metacmd_ID_lister__write_character__default = 126; +static int32_t fcoder_metacmd_ID_lister__backspace_text_field__default = 127; +static int32_t fcoder_metacmd_ID_lister__move_up__default = 128; +static int32_t fcoder_metacmd_ID_lister__move_down__default = 129; +static int32_t fcoder_metacmd_ID_lister__write_character__file_path = 130; +static int32_t fcoder_metacmd_ID_lister__backspace_text_field__file_path = 131; +static int32_t fcoder_metacmd_ID_lister__write_character__fixed_list = 132; +static int32_t fcoder_metacmd_ID_interactive_switch_buffer = 133; +static int32_t fcoder_metacmd_ID_interactive_kill_buffer = 134; +static int32_t fcoder_metacmd_ID_interactive_open_or_new = 135; +static int32_t fcoder_metacmd_ID_interactive_new = 136; +static int32_t fcoder_metacmd_ID_interactive_open = 137; +static int32_t fcoder_metacmd_ID_command_lister = 138; +static int32_t fcoder_metacmd_ID_auto_tab_whole_file = 139; +static int32_t fcoder_metacmd_ID_auto_tab_line_at_cursor = 140; +static int32_t fcoder_metacmd_ID_auto_tab_range = 141; +static int32_t fcoder_metacmd_ID_write_and_auto_tab = 142; +static int32_t fcoder_metacmd_ID_list_all_locations = 143; +static int32_t fcoder_metacmd_ID_list_all_substring_locations = 144; +static int32_t fcoder_metacmd_ID_list_all_locations_case_insensitive = 145; +static int32_t fcoder_metacmd_ID_list_all_substring_locations_case_insensitive = 146; +static int32_t fcoder_metacmd_ID_list_all_locations_of_identifier = 147; +static int32_t fcoder_metacmd_ID_list_all_locations_of_identifier_case_insensitive = 148; +static int32_t fcoder_metacmd_ID_list_all_locations_of_selection = 149; +static int32_t fcoder_metacmd_ID_list_all_locations_of_selection_case_insensitive = 150; +static int32_t fcoder_metacmd_ID_list_all_locations_of_type_definition = 151; +static int32_t fcoder_metacmd_ID_list_all_locations_of_type_definition_of_identifier = 152; +static int32_t fcoder_metacmd_ID_word_complete = 153; +static int32_t fcoder_metacmd_ID_goto_jump_at_cursor_direct = 154; +static int32_t fcoder_metacmd_ID_goto_jump_at_cursor_same_panel_direct = 155; +static int32_t fcoder_metacmd_ID_goto_next_jump_direct = 156; +static int32_t fcoder_metacmd_ID_goto_prev_jump_direct = 157; +static int32_t fcoder_metacmd_ID_goto_next_jump_no_skips_direct = 158; +static int32_t fcoder_metacmd_ID_goto_prev_jump_no_skips_direct = 159; +static int32_t fcoder_metacmd_ID_goto_first_jump_direct = 160; +static int32_t fcoder_metacmd_ID_newline_or_goto_position_direct = 161; +static int32_t fcoder_metacmd_ID_newline_or_goto_position_same_panel_direct = 162; +static int32_t fcoder_metacmd_ID_goto_jump_at_cursor_sticky = 163; +static int32_t fcoder_metacmd_ID_goto_jump_at_cursor_same_panel_sticky = 164; +static int32_t fcoder_metacmd_ID_goto_next_jump_sticky = 165; +static int32_t fcoder_metacmd_ID_goto_prev_jump_sticky = 166; +static int32_t fcoder_metacmd_ID_goto_next_jump_no_skips_sticky = 167; +static int32_t fcoder_metacmd_ID_goto_prev_jump_no_skips_sticky = 168; +static int32_t fcoder_metacmd_ID_goto_first_jump_sticky = 169; +static int32_t fcoder_metacmd_ID_goto_first_jump_same_panel_sticky = 170; +static int32_t fcoder_metacmd_ID_newline_or_goto_position_sticky = 171; +static int32_t fcoder_metacmd_ID_newline_or_goto_position_same_panel_sticky = 172; +static int32_t fcoder_metacmd_ID_view_jump_list_with_lister = 173; +static int32_t fcoder_metacmd_ID_copy = 174; +static int32_t fcoder_metacmd_ID_cut = 175; +static int32_t fcoder_metacmd_ID_paste = 176; +static int32_t fcoder_metacmd_ID_paste_next = 177; +static int32_t fcoder_metacmd_ID_paste_and_indent = 178; +static int32_t fcoder_metacmd_ID_paste_next_and_indent = 179; +static int32_t fcoder_metacmd_ID_execute_previous_cli = 180; +static int32_t fcoder_metacmd_ID_execute_any_cli = 181; +static int32_t fcoder_metacmd_ID_build_search = 182; +static int32_t fcoder_metacmd_ID_build_in_build_panel = 183; +static int32_t fcoder_metacmd_ID_close_build_panel = 184; +static int32_t fcoder_metacmd_ID_change_to_build_panel = 185; +static int32_t fcoder_metacmd_ID_close_all_code = 186; +static int32_t fcoder_metacmd_ID_open_all_code = 187; +static int32_t fcoder_metacmd_ID_open_all_code_recursive = 188; +static int32_t fcoder_metacmd_ID_load_project = 189; +static int32_t fcoder_metacmd_ID_project_fkey_command = 190; +static int32_t fcoder_metacmd_ID_project_go_to_root_directory = 191; +static int32_t fcoder_metacmd_ID_setup_new_project = 192; +static int32_t fcoder_metacmd_ID_setup_build_bat = 193; +static int32_t fcoder_metacmd_ID_setup_build_sh = 194; static int32_t fcoder_metacmd_ID_setup_build_bat_and_sh = 195; -static int32_t fcoder_metacmd_ID_setup_build_sh = 196; -static int32_t fcoder_metacmd_ID_setup_new_project = 197; -static int32_t fcoder_metacmd_ID_show_filebar = 198; -static int32_t fcoder_metacmd_ID_show_scrollbar = 199; -static int32_t fcoder_metacmd_ID_snipe_token_or_word = 200; -static int32_t fcoder_metacmd_ID_snipe_token_or_word_right = 201; -static int32_t fcoder_metacmd_ID_snippet_lister = 202; -static int32_t fcoder_metacmd_ID_suppress_mouse = 203; -static int32_t fcoder_metacmd_ID_swap_buffers_between_panels = 204; -static int32_t fcoder_metacmd_ID_to_lowercase = 205; -static int32_t fcoder_metacmd_ID_to_uppercase = 206; -static int32_t fcoder_metacmd_ID_toggle_filebar = 207; -static int32_t fcoder_metacmd_ID_toggle_fps_meter = 208; -static int32_t fcoder_metacmd_ID_toggle_fullscreen = 209; -static int32_t fcoder_metacmd_ID_toggle_highlight_enclosing_scopes = 210; -static int32_t fcoder_metacmd_ID_toggle_highlight_line_at_cursor = 211; -static int32_t fcoder_metacmd_ID_toggle_line_numbers = 212; -static int32_t fcoder_metacmd_ID_toggle_line_wrap = 213; -static int32_t fcoder_metacmd_ID_toggle_mouse = 214; -static int32_t fcoder_metacmd_ID_toggle_paren_matching_helper = 215; -static int32_t fcoder_metacmd_ID_toggle_show_whitespace = 216; -static int32_t fcoder_metacmd_ID_toggle_virtual_whitespace = 217; -static int32_t fcoder_metacmd_ID_uncomment_line = 218; -static int32_t fcoder_metacmd_ID_undo = 219; -static int32_t fcoder_metacmd_ID_undo_all_buffers = 220; -static int32_t fcoder_metacmd_ID_view_buffer_other_panel = 221; -static int32_t fcoder_metacmd_ID_view_jump_list_with_lister = 222; -static int32_t fcoder_metacmd_ID_word_complete = 223; -static int32_t fcoder_metacmd_ID_write_and_auto_tab = 224; -static int32_t fcoder_metacmd_ID_write_block = 225; -static int32_t fcoder_metacmd_ID_write_character = 226; -static int32_t fcoder_metacmd_ID_write_explicit_enum_flags = 227; -static int32_t fcoder_metacmd_ID_write_explicit_enum_values = 228; -static int32_t fcoder_metacmd_ID_write_hack = 229; -static int32_t fcoder_metacmd_ID_write_note = 230; -static int32_t fcoder_metacmd_ID_write_todo = 231; -static int32_t fcoder_metacmd_ID_write_underscore = 232; -static int32_t fcoder_metacmd_ID_write_zero_struct = 233; +static int32_t fcoder_metacmd_ID_project_command_lister = 196; +static int32_t fcoder_metacmd_ID_list_all_functions_current_buffer = 197; +static int32_t fcoder_metacmd_ID_list_all_functions_current_buffer_lister = 198; +static int32_t fcoder_metacmd_ID_list_all_functions_all_buffers = 199; +static int32_t fcoder_metacmd_ID_list_all_functions_all_buffers_lister = 200; +static int32_t fcoder_metacmd_ID_select_surrounding_scope = 201; +static int32_t fcoder_metacmd_ID_select_next_scope_absolute = 202; +static int32_t fcoder_metacmd_ID_select_prev_scope_absolute = 203; +static int32_t fcoder_metacmd_ID_place_in_scope = 204; +static int32_t fcoder_metacmd_ID_delete_current_scope = 205; +static int32_t fcoder_metacmd_ID_scope_absorb_down = 206; +static int32_t fcoder_metacmd_ID_open_long_braces = 207; +static int32_t fcoder_metacmd_ID_open_long_braces_semicolon = 208; +static int32_t fcoder_metacmd_ID_open_long_braces_break = 209; +static int32_t fcoder_metacmd_ID_if0_off = 210; +static int32_t fcoder_metacmd_ID_write_todo = 211; +static int32_t fcoder_metacmd_ID_write_hack = 212; +static int32_t fcoder_metacmd_ID_write_note = 213; +static int32_t fcoder_metacmd_ID_write_block = 214; +static int32_t fcoder_metacmd_ID_write_zero_struct = 215; +static int32_t fcoder_metacmd_ID_comment_line = 216; +static int32_t fcoder_metacmd_ID_uncomment_line = 217; +static int32_t fcoder_metacmd_ID_comment_line_toggle = 218; +static int32_t fcoder_metacmd_ID_snippet_lister = 219; +static int32_t fcoder_metacmd_ID_set_bindings_choose = 220; +static int32_t fcoder_metacmd_ID_set_bindings_default = 221; +static int32_t fcoder_metacmd_ID_set_bindings_mac_default = 222; +static int32_t fcoder_metacmd_ID_miblo_increment_basic = 223; +static int32_t fcoder_metacmd_ID_miblo_decrement_basic = 224; +static int32_t fcoder_metacmd_ID_miblo_increment_time_stamp = 225; +static int32_t fcoder_metacmd_ID_miblo_decrement_time_stamp = 226; +static int32_t fcoder_metacmd_ID_miblo_increment_time_stamp_minute = 227; +static int32_t fcoder_metacmd_ID_miblo_decrement_time_stamp_minute = 228; +static int32_t fcoder_metacmd_ID_kill_rect = 229; +static int32_t fcoder_metacmd_ID_multi_line_edit = 230; +static int32_t fcoder_metacmd_ID_rename_parameter = 231; +static int32_t fcoder_metacmd_ID_write_explicit_enum_values = 232; +static int32_t fcoder_metacmd_ID_write_explicit_enum_flags = 233; #endif diff --git a/4coder_helper.cpp b/4coder_helper.cpp index 33f13a30..7537a1ea 100644 --- a/4coder_helper.cpp +++ b/4coder_helper.cpp @@ -4,69 +4,17 @@ // TOP -static String -string_push(Arena *arena, i32 size){ - String result = {}; - if (size != 0){ - result.str = push_array(arena, char, size); - if (result.str != 0){ - result.memory_size = size; - } - } +static String_Const_u8 +push_hot_directory(Application_Links *app, Arena *arena){ + String_Const_u8 result = {}; + get_hot_directory(app, arena, &result); return(result); } -static String -string_push_copy(Arena *arena, String str){ - String result = {}; - if (str.str != 0){ - result.str = push_array(arena, char, str.size + 1); - if (result.str != 0){ - result.memory_size = str.size + 1; - copy(&result, str); - result.str[result.size] = 0; - } - } - return(result); -} - -static String -string_push_fv(Arena *arena, char *format, va_list args){ - char temp[KB(4)]; - i32 n = vsnprintf(temp, sizeof(temp), format, args); - String result = {}; - if (0 <= n && n < sizeof(temp)){ - result = string_push_copy(arena, make_string(temp, n)); - } - return(result); -} - -static String -string_push_fv(Partition *part, char *format, va_list args){ - char temp[KB(4)]; - i32 n = vsnprintf(temp, sizeof(temp), format, args); - String result = {}; - if (0 <= n && n < sizeof(temp)){ - result = string_push_copy(part, make_string(temp, n)); - } - return(result); -} - -static String -string_push_f(Arena *arena, char *format, ...){ - va_list args; - va_start(args, format); - String result = string_push_fv(arena, format, args); - va_end(args); - return(result); -} - -static String -string_push_f(Partition *part, char *format, ...){ - va_list args; - va_start(args, format); - String result = string_push_fv(part, format, args); - va_end(args); +static String_Const_u8 +push_4ed_path(Application_Links *app, Arena *arena){ + String_Const_u8 result = {}; + get_4ed_path(app, arena, &result); return(result); } @@ -338,10 +286,10 @@ end_bind_helper_get_buffer(Bind_Helper *helper){ return(result); } -static u32_4tech +static u32 get_key_code(char *buffer){ - u32_4tech ignore; - u32_4tech result = utf8_to_u32_length_unchecked((u8_4tech*)buffer, &ignore); + u32 ignore; + u32 result = utf8_to_u32_length_unchecked((u8*)buffer, &ignore); return(result); } @@ -400,21 +348,18 @@ to_writable_character(Key_Event_Data key, uint8_t *character){ return(result); } -static b32 -backspace_utf8(String *str){ - b32 result = false; - uint8_t *s = (uint8_t*)str->str; - if (str->size > 0){ - u32 i = str->size-1; +static String_Const_u8 +backspace_utf8(String_Const_u8 string){ + if (string.size > 0){ + umem i = string.size - 1; for (; i > 0; --i){ - if (s[i] <= 0x7F || s[i] >= 0xC0){ + if (string.str[i] <= 0x7F || string.str[i] >= 0xC0){ break; } } - str->size = i; - result = true; + string.size = i; } - return(result); + return(string); } static b32 @@ -469,15 +414,15 @@ query_user_general(Application_Links *app, Query_Bar *bar, b32 force_number){ break; } else if (in.key.keycode == key_back){ - backspace_utf8(&bar->string); + bar->string = backspace_utf8(bar->string); } else if (good_character){ - append(&bar->string, make_string(character, length)); + String_u8 string = Su8(bar->string.str, bar->string.size, bar->string_capacity); + string_append(&string, SCu8(character, length)); + bar->string = string.string; } } - terminate_with_null(&bar->string); - return(success); } @@ -511,6 +456,11 @@ buffer_identifier(char *str, i32 len){ return(identifier); } +static Buffer_Identifier +buffer_identifier(String_Const_u8 str){ + return(buffer_identifier((char*)str.str, (i32)str.size)); +} + static Buffer_Identifier buffer_identifier(Buffer_ID id){ Buffer_Identifier identifier; @@ -531,6 +481,28 @@ adjust_all_buffer_wrap_widths(Application_Links *app, i32 wrap_width, i32 min_ba } } +static View_ID +open_view(Application_Links *app, View_ID view_location, View_Split_Position position){ + View_ID result = 0; + if (view_location != 0 && view_exists(app, view_location)){ + Panel_ID panel_id = 0; + if (view_get_panel(app, view_location, &panel_id)){ + b32 vertical = (position == ViewSplit_Left || position == ViewSplit_Right); + if (panel_split(app, panel_id, vertical?PanelSplit_LeftAndRight:PanelSplit_TopAndBottom)){ + Panel_ID new_panel_id = 0; + Panel_Child child = (position == ViewSplit_Left || position == ViewSplit_Top)?PanelChild_Min:PanelChild_Max; + if (panel_get_child(app, panel_id, child, &new_panel_id)){ + View_ID new_view_id = 0; + if (panel_get_view(app, new_panel_id, &new_view_id)){ + result = new_view_id; + } + } + } + } + } + return(result); +} + static View_ID get_first_view_with_buffer(Application_Links *app, Buffer_ID buffer_id){ View_ID result = {}; @@ -551,10 +523,10 @@ get_first_view_with_buffer(Application_Links *app, Buffer_ID buffer_id){ } static b32 -open_file(Application_Links *app, Buffer_ID *buffer_out, char *filename, i32 filename_len, b32 background, b32 never_new){ +open_file(Application_Links *app, Buffer_ID *buffer_out, String_Const_u8 file_name, b32 background, b32 never_new){ b32 result = false; Buffer_ID buffer = 0; - get_buffer_by_name(app, filename, filename_len, AccessProtected); + get_buffer_by_name(app, file_name, AccessProtected, &buffer); b32 exists = buffer_exists(app, buffer); if (!exists){ Buffer_Create_Flag flags = 0; @@ -564,7 +536,7 @@ open_file(Application_Links *app, Buffer_ID *buffer_out, char *filename, i32 fil if (never_new){ flags |= BufferCreate_NeverNew; } - create_buffer(app, make_string(filename, filename_len), flags, &buffer); + create_buffer(app, file_name, flags, &buffer); exists = buffer_exists(app, buffer); } if (exists){ @@ -583,7 +555,7 @@ buffer_identifier_to_id(Application_Links *app, Buffer_Identifier identifier){ id = identifier.id; } else{ - String name = make_string(identifier.name, identifier.name_len); + String_Const_u8 name = SCu8(identifier.name, identifier.name_len); get_buffer_by_name(app, name, AccessAll, &id); if (id == 0){ get_buffer_by_file_name(app, name, AccessAll, &id); @@ -592,12 +564,35 @@ buffer_identifier_to_id(Application_Links *app, Buffer_Identifier identifier){ return(id); } +static Buffer_ID +buffer_identifier_to_id_create_out_buffer(Application_Links *app, Buffer_Identifier buffer_id){ + Buffer_ID result = 0; + if (buffer_id.name != 0 && buffer_id.name_len > 0){ + String_Const_u8 buffer_name = SCu8(buffer_id.name, buffer_id.name_len); + Buffer_ID buffer_attach_id = 0; + if (get_buffer_by_name(app, buffer_name, AccessAll, &buffer_attach_id)){ + result = buffer_attach_id; + } + else{ + if (create_buffer(app, buffer_name, BufferCreate_AlwaysNew|BufferCreate_NeverAttachToFile, &buffer_attach_id)){ + buffer_set_setting(app, buffer_attach_id, BufferSetting_ReadOnly, true); + buffer_set_setting(app, buffer_attach_id, BufferSetting_Unimportant, true); + result = buffer_attach_id; + } + } + } + else{ + result = buffer_id.id; + } + return(result); +} + static b32 -view_open_file(Application_Links *app, View_ID view, char *filename, i32 filename_len, b32 never_new){ +view_open_file(Application_Links *app, View_ID view, String_Const_u8 file_name, b32 never_new){ b32 result = false; if (view != 0){ Buffer_ID buffer = 0; - if (open_file(app, &buffer, filename, filename_len, false, never_new)){ + if (open_file(app, &buffer, file_name, false, never_new)){ view_set_buffer(app, view, buffer, 0); result = true; } @@ -631,7 +626,9 @@ get_prev_view_looped_all_panels(Application_Links *app, View_ID view_id, Access_ static Buffer_Kill_Result kill_buffer(Application_Links *app, Buffer_Identifier identifier, View_ID gui_view_id, Buffer_Kill_Flag flags){ - Buffer_Kill_Result result = kill_buffer(app, identifier, flags); + Buffer_ID buffer = buffer_identifier_to_id(app, identifier); + Buffer_Kill_Result result = 0; + buffer_kill(app, buffer, flags, &result); if (result == BufferKillResult_Dirty){ Buffer_ID buffer = buffer_identifier_to_id(app, identifier); do_gui_sure_to_kill(app, buffer, gui_view_id); @@ -675,106 +672,94 @@ get_view_range(Application_Links *app, View_ID view){ return(rectify(range)); } -static String -buffer_read_string(Application_Links *app, Buffer_ID buffer, Range range, void *dest) { - String result = {}; - if (dest != 0 && buffer_read_range(app, buffer, range.start, range.end, (char *)dest)){ - result = make_string((char *)dest, get_width(range)); +static String_Const_u8 +buffer_read_string(Application_Links *app, Buffer_ID buffer, Range range, void *dest){ + String_Const_u8 result = {}; + if (dest != 0 && buffer_read_range(app, buffer, range.start, range.end, (char*)dest)){ + result = SCu8((u8*)dest, get_width(range)); } return(result); } static b32 -read_line(Application_Links *app, Partition *part, Buffer_ID buffer_id, i32 line, String *str, - Partial_Cursor *start_out, Partial_Cursor *one_past_last_out){ - Partial_Cursor begin = {}; - Partial_Cursor end = {}; - - b32 success = false; - if (buffer_compute_cursor(app, buffer_id, seek_line_char(line, 1), &begin) && - buffer_compute_cursor(app, buffer_id, seek_line_char(line, -1), &end) && - begin.line == line){ - i32 buffer_size = 0; - buffer_get_size(app, buffer_id, &buffer_size); - if (0 <= begin.pos && begin.pos <= end.pos && end.pos <= buffer_size){ - i32 size = (end.pos - begin.pos); - i32 alloc_size = size + 1; - char *memory = push_array(part, char, alloc_size); - if (memory != 0){ - *str = make_string(memory, 0, alloc_size); - buffer_read_range(app, buffer_id, begin.pos, end.pos, str->str); - str->size = size; - terminate_with_null(str); - - *start_out = begin; - *one_past_last_out = end; - success = true; - } - } +is_valid_line(Application_Links *app, Buffer_ID buffer_id, i32 line){ + i32 max_line = 0; + buffer_get_line_count(app, buffer_id, &max_line); + return(1 <= line && line <= max_line); +} + +static Range_Partial_Cursor +get_line_range(Application_Links *app, Buffer_ID buffer_id, i32 line){ + Range_Partial_Cursor result = {}; + b32 success = (buffer_compute_cursor(app, buffer_id, seek_line_char(line, 1), &result.begin) && + buffer_compute_cursor(app, buffer_id, seek_line_char(line, -1), &result.end) && + result.begin.line == line); + if (!success){ + block_zero_struct(&result); } - - return(success); + return(result); } -static b32 -read_line(Application_Links *app, Partition *part, Buffer_ID buffer_id, i32 line, String *str){ - Partial_Cursor ignore = {}; - return(read_line(app, part, buffer_id, line, str, &ignore, &ignore)); +static Range_umem +make_range_from_cursors(Range_Partial_Cursor range){ + return(make_range_umem(range.begin.pos, range.end.pos)); } -static String -scratch_read(Application_Links *app, Partition *scratch, Buffer_ID buffer, i32 start, i32 end){ - String result = {}; +static String_Const_u8 +scratch_read(Application_Links *app, Arena *arena, Buffer_ID buffer, umem start, umem end){ + String_Const_u8 result = {}; if (start <= end){ - i32 len = end - start; - result = string_push(scratch, len); - if (buffer_read_range(app, buffer, start, end, result.str)){ - result.size = len; + umem length = end - start; + u8 *memory = push_array(arena, u8, length); + if (buffer_read_range(app, buffer, (i32)start, (i32)end, (char*)memory)){ + result = SCu8(memory, length); } } return(result); } -static String -scratch_read(Application_Links *app, Partition *scratch, Buffer_ID buffer, Range range){ - return(scratch_read(app, scratch, buffer, range.first, range.one_past_last)); +static String_Const_u8 +scratch_read(Application_Links *app, Arena *arena, Buffer_ID buffer, Range range){ + return(scratch_read(app, arena, buffer, range.first, range.one_past_last)); } -static String -scratch_read(Application_Links *app, Arena *scratch, Buffer_ID buffer, i32 start, i32 end){ - String result = {}; - if (start <= end){ - i32 len = end - start; - result = string_push(scratch, len); - if (buffer_read_range(app, buffer, start, end, result.str)){ - result.size = len; - } - } - return(result); +static String_Const_u8 +scratch_read(Application_Links *app, Arena *arena, Buffer_ID buffer, Range_umem range){ + return(scratch_read(app, arena, buffer, range.first, range.one_past_last)); } -static String -scratch_read(Application_Links *app, Arena *scratch, Buffer_ID buffer, Range range){ - return(scratch_read(app, scratch, buffer, range.first, range.one_past_last)); +static String_Const_u8 +scratch_read(Application_Links *app, Arena *arena, Buffer_ID buffer, Cpp_Token token){ + return(scratch_read(app, arena, buffer, token.start, token.start + token.size)); } -static String -scratch_read(Application_Links *app, Partition *scratch, Buffer_ID buffer, Cpp_Token token){ - String result = scratch_read(app, scratch, buffer, token.start, token.start + token.size); - return(result); +static String_Const_u8 +scratch_read_line(Application_Links *app, Arena *arena, Buffer_ID buffer, i32 line){ + Range_umem range = make_range_from_cursors(get_line_range(app, buffer, line)); + return(scratch_read(app, arena, buffer, range)); +} + +static String_Const_u8 +token_get_lexeme(Application_Links *app, Arena *arena, Buffer_ID buffer, Cpp_Token token){ + return(scratch_read(app, arena, buffer, token.start, token.start + token.size)); +} + +static String_Const_u8 +get_token_lexeme(Application_Links *app, Arena *arena, Buffer_ID buffer, Cpp_Token token){ + return(scratch_read(app, arena, buffer, token.start, token.start + token.size)); } static b32 -token_match(Application_Links *app, Buffer_ID buffer, Cpp_Token token, String b){ +token_match(Application_Links *app, Buffer_ID buffer, Cpp_Token token, String_Const_u8 b){ Arena *scratch = context_get_arena(app); - Temp_Memory_Arena temp = begin_temp_memory(scratch); - String a = scratch_read(app, scratch, buffer, make_range(token.start, token.start + token.size)); - b32 result = match(a, b); - end_temp_memory(temp); + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 a = scratch_read(app, scratch, buffer, token.start, token.start + token.size); + b32 result = string_match(a, b); + end_temp(temp); return(result); } -static String +static String_Const_u8 read_entire_buffer(Application_Links *app, Buffer_ID buffer_id, Arena *scratch){ i32 size = 0; buffer_get_size(app, buffer_id, &size); @@ -846,7 +831,7 @@ static void clear_buffer(Application_Links *app, Buffer_ID buffer_id){ i32 buffer_size = 0; buffer_get_size(app, buffer_id, &buffer_size); - buffer_replace_range(app, buffer_id, make_range(0, buffer_size), make_lit_string("")); + buffer_replace_range(app, buffer_id, make_range(0, buffer_size), string_u8_litexpr("")); } //////////////////////////////// @@ -1147,101 +1132,56 @@ token_iterator_goto_prev_raw(Token_Iterator *iterator){ return(result); } -static String -token_get_lexeme(Application_Links *app, Buffer_ID buffer, Cpp_Token *token, char *out_buffer, i32 out_buffer_size){ - String result = {}; - if (out_buffer_size > 1){ - i32 read_size = token->size; - if (read_size >= out_buffer_size){ - read_size = out_buffer_size - 1; - } - if (buffer_read_range(app, buffer, token->start, token->start + read_size, out_buffer)){ - result = make_string(out_buffer, read_size, out_buffer_size); - out_buffer[read_size] = 0; - } - } - return(result); -} - -static String -token_get_lexeme(Application_Links *app, Partition *part, Buffer_ID buffer, Cpp_Token *token){ - String result = {}; - Temp_Memory restore_point = begin_temp_memory(part); - char *s = push_array(part, char, token->size); - if (s != 0){ - result = token_get_lexeme(app, buffer, token, s, token->size); - } - else{ - end_temp_memory(restore_point); - } - return(result); -} - //////////////////////////////// -static String +static String_Const_u8 get_query_string(Application_Links *app, char *query_str, char *string_space, i32 space_size){ Query_Bar bar; - bar.prompt = make_string_slowly(query_str); - bar.string = make_string_cap(string_space, 0, space_size); + bar.prompt = SCu8((u8*)query_str); + bar.string = SCu8((u8*)string_space, (umem)0); + bar.string_capacity = space_size; if (!query_user_string(app, &bar)){ bar.string.size = 0; } return(bar.string); } -static String -get_string_in_view_range(Application_Links *app, Partition *arena, View_ID view){ - String str = {}; +static String_Const_u8 +get_string_in_view_range(Application_Links *app, Arena *arena, View_ID view){ + String_Const_u8 result = {}; Buffer_ID buffer = 0; view_get_buffer(app, view, AccessProtected, &buffer); if (buffer_exists(app, buffer)){ Range range = get_view_range(app, view); - i32 query_length = range.max - range.min; - if (query_length != 0){ - char *query_space = push_array(arena, char, query_length); - if (buffer_read_range(app, buffer, range.min, range.max, query_space)){ - str = make_string(query_space, query_length); - } - } - } - return(str); -} - -static String -get_token_or_word_under_pos(Application_Links *app, Buffer_ID buffer, i32 pos, char *space, i32 capacity){ - String result = {}; - Cpp_Get_Token_Result get_result = {}; - b32 success = buffer_get_token_index(app, buffer, pos, &get_result); - if (success && !get_result.in_whitespace_after_token){ - i32 size = get_result.token_one_past_last - get_result.token_start; - if (size > 0 && size <= capacity){ - success = buffer_read_range(app, buffer, get_result.token_start, get_result.token_one_past_last, space); - if (success){ - result = make_string(space, size); - } + umem query_length = range.max - range.min; + if (query_length > 0){ + result = scratch_read(app, arena, buffer, range.first, range.one_past_last); } } return(result); } -static void -append_int_to_str_left_pad(String *str, i32 x, i32 minimum_width, char pad_char){ - i32 length = int_to_str_size(x); - i32 left_over = minimum_width - length; - if (left_over > 0){ - append_padding(str, pad_char, str->size + left_over); +static String_Const_u8 +get_token_or_word_under_pos(Application_Links *app, Arena *arena, Buffer_ID buffer, umem pos){ + String_Const_u8 result = {}; + Cpp_Get_Token_Result get_result = {}; + b32 success = buffer_get_token_index(app, buffer, (i32)pos, &get_result); + if (success && !get_result.in_whitespace_after_token){ + umem size = get_result.token_one_past_last - get_result.token_start; + if (0 < size){ + result = scratch_read(app, arena, buffer, get_result.token_start, get_result.token_one_past_last); + } } - append_int_to_str(str, x); + return(result); } static b32 -lexer_keywords_default_init(Partition *arena, Cpp_Keyword_Table *kw_out, Cpp_Keyword_Table *pp_out){ +lexer_keywords_default_init(Arena *arena, Cpp_Keyword_Table *kw_out, Cpp_Keyword_Table *pp_out){ b32 success = false; - umem_4tech kw_size = cpp_get_table_memory_size_default(CPP_TABLE_KEYWORDS); - umem_4tech pp_size = cpp_get_table_memory_size_default(CPP_TABLE_PREPROCESSOR_DIRECTIVES); - void *kw_mem = push_array(arena, char, (i32_4tech)kw_size); - void *pp_mem = push_array(arena, char, (i32_4tech)pp_size); + umem kw_size = cpp_get_table_memory_size_default(CPP_TABLE_KEYWORDS); + umem pp_size = cpp_get_table_memory_size_default(CPP_TABLE_PREPROCESSOR_DIRECTIVES); + void *kw_mem = push_array(arena, char, kw_size); + void *pp_mem = push_array(arena, char, pp_size); if (kw_mem != 0 && pp_mem != 0){ *kw_out = cpp_make_table_default(CPP_TABLE_KEYWORDS, kw_mem, kw_size); *pp_out = cpp_make_table_default(CPP_TABLE_PREPROCESSOR_DIRECTIVES, pp_mem, pp_size); @@ -1252,78 +1192,48 @@ lexer_keywords_default_init(Partition *arena, Cpp_Keyword_Table *kw_out, Cpp_Key //////////////////////////////// -static String -get_hot_directory(Application_Links *app, Partition *part){ - Temp_Memory temp = begin_temp_memory(part); - i32 space_cap = part_remaining(part); - char *space = push_array(part, char, space_cap); - String hot_dir = make_string_cap(space, 0, space_cap); - hot_dir.size = directory_get_hot(app, hot_dir.str, hot_dir.memory_size); - end_temp_memory(temp); - push_array(part, char, hot_dir.size); - hot_dir.memory_size = hot_dir.size; - return(hot_dir); +static b32 +file_exists(Application_Links *app, String_Const_u8 file_name){ + File_Attributes attributes = {}; + file_get_attributes(app, file_name, &attributes); + return(attributes.last_write_time > 0); } -static String -get_hot_directory(Application_Links *app, Arena *arena){ - i32 space_required = directory_get_hot(app, 0, 0); - char *space = push_array(arena, char, space_required); - String hot_dir = make_string_cap(space, 0, space_required); - hot_dir.size = directory_get_hot(app, hot_dir.str, hot_dir.memory_size); - return(hot_dir); -} - -//////////////////////////////// - -static String -dump_file_handle(Partition *arena, FILE *file){ - String str = {}; +static Data +dump_file_handle(Arena *arena, FILE *file){ + Data result = {}; if (file != 0){ fseek(file, 0, SEEK_END); - i32 size = ftell(file); - char *mem = push_array(arena, char, size + 1); - push_align(arena, 8); + umem size = ftell(file); + char *mem = push_array(arena, char, size); if (mem != 0){ fseek(file, 0, SEEK_SET); fread(mem, 1, size, file); - mem[size] = 0; - str = make_string_cap(mem, size, size + 1); + result = make_data(mem, size); } } - return(str); + return(result); } -static File_Handle_Path -open_file_search_up_path(Partition *arena, String path, String file_name){ - File_Handle_Path result = {}; - - i32 cap = path.size + file_name.size + 2; - char *space = push_array(arena, char, cap); - push_align(arena, 8); - String name_str = make_string_cap(space, 0, cap); - append(&name_str, path); - if (name_str.size == 0 || !char_is_slash(name_str.str[name_str.size - 1])){ - append(&name_str, "/"); - } - - for (;;){ - i32 base_size = name_str.size; - append(&name_str, file_name); - terminate_with_null(&name_str); - result.file = fopen(name_str.str, "rb"); - if (result.file != 0){ - result.path = name_str; - break; - } - - name_str.size = base_size; - remove_last_folder(&name_str); - if (name_str.size >= base_size){ +static String_Const_u8 +push_file_search_up_path(Application_Links *app, Arena *arena, String_Const_u8 start_path, String_Const_u8 file_name){ + String_Const_u8 result = {}; + String_Const_u8 path = start_path; + for (;path.size > 0;){ + Temp_Memory temp = begin_temp(arena); + if (character_is_slash(string_get_character(path, path.size - 1))){ + path = string_chop(path, 1); + } + String_Const_u8 full_path = string_u8_pushf(arena, "%.*s/%.*s", + string_expand(path), + string_expand(file_name)); + if (file_exists(app, full_path)){ + result = full_path; break; } + path = string_remove_last_folder(path); + end_temp(temp); } - return(result); } @@ -1331,49 +1241,27 @@ static FILE* open_file_try_current_path_then_binary_path(Application_Links *app, char *file_name){ FILE *file = fopen(file_name, "rb"); if (file == 0){ - char space[256]; - i32 size = get_4ed_path(app, space, sizeof(space)); - String str = make_string_cap(space, size, sizeof(space)); - append(&str, "/"); - append(&str, file_name); - if (terminate_with_null(&str)){ - file = fopen(str.str, "rb"); - } + Scratch_Block scratch(app); + List_String_Const_u8 list = {}; + string_list_push(scratch, &list, push_4ed_path(app, scratch)); + string_list_push_overlap(scratch, &list, '/', SCu8(file_name)); + String_Const_u8 str = string_list_flatten(scratch, list, StringFill_NullTerminate); + file = fopen((char*)str.str, "rb"); } return(file); } -static char* -get_null_terminated(Partition *scratch, String name){ - char *name_terminated = 0; - if (name.size < name.memory_size){ - terminate_with_null(&name); - name_terminated = name.str; - } - else{ - name_terminated = push_array(scratch, char, name.size + 1); - if (name_terminated != 0){ - memcpy(name_terminated, name.str, name.size); - name_terminated[name.size] = 0; - } - } - return(name_terminated); -} - static FILE* -open_file(Partition *scratch, String name){ - FILE *file = 0; - Temp_Memory temp = begin_temp_memory(scratch); - char *name_terminated = get_null_terminated(scratch, name); - if (name_terminated != 0){ - file = fopen(name_terminated, "rb"); - } - end_temp_memory(temp); +open_file(Arena *scratch, String_Const_u8 name){ + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 name_copy = string_copy(scratch, name); + FILE *file = fopen((char*)name_copy.str, "rb"); + end_temp(temp); return(file); } static File_Name_Data -dump_file(Partition *arena, String file_name){ +dump_file(Arena *arena, String_Const_u8 file_name){ File_Name_Data result = {}; FILE *file = open_file(arena, file_name); if (file != 0){ @@ -1384,15 +1272,12 @@ dump_file(Partition *arena, String file_name){ return(result); } -static File_Name_Path_Data -dump_file_search_up_path(Partition *arena, String path, String file_name){ - File_Name_Path_Data result = {}; - File_Handle_Path file = open_file_search_up_path(arena, path, file_name); - if (file.file != 0){ - result.file_name = file_name; - result.path = file.path; - result.data = dump_file_handle(arena, file.file); - fclose(file.file); +static File_Name_Data +dump_file_search_up_path(Application_Links *app, Arena *arena, String_Const_u8 path, String_Const_u8 file_name){ + File_Name_Data result = {}; + String_Const_u8 full_path = push_file_search_up_path(app, arena, path, file_name); + if (full_path.size > 0){ + result = dump_file(arena, full_path); } return(result); } @@ -1434,10 +1319,10 @@ sort_pairs_by_key(Sort_Pair_i32 *pairs, i32 count){ } static Range_Array -get_ranges_of_duplicate_keys(Partition *arena, i32 *keys, i32 stride, i32 count){ +get_ranges_of_duplicate_keys(Arena *arena, i32 *keys, i32 stride, i32 count){ Range_Array result = {}; - result.ranges = push_array(arena, Range, 0); - uint8_t *ptr = (uint8_t*)keys; + result.ranges = push_array(arena, Range, count); + u8 *ptr = (u8*)keys; i32 start_i = 0; for (i32 i = 1; i <= count; i += 1){ b32 is_end = false; @@ -1448,13 +1333,13 @@ get_ranges_of_duplicate_keys(Partition *arena, i32 *keys, i32 stride, i32 count) is_end = true; } if (is_end){ - Range *new_range = push_array(arena, Range, 1); + Range *new_range = &result.ranges[result.count++]; new_range->first = start_i; new_range->one_past_last = i; start_i = i; } } - result.count = (i32)(push_array(arena, Range, 0) - result.ranges); + pop_array(arena, Range, count - result.count); return(result); } @@ -1465,7 +1350,8 @@ no_mark_snap_to_cursor(Application_Links *app, Managed_Scope view_scope){ static void no_mark_snap_to_cursor(Application_Links *app, View_ID view_id){ - Managed_Scope scope = view_get_managed_scope(app, view_id); + Managed_Scope scope = 0; + view_get_managed_scope(app, view_id, &scope); no_mark_snap_to_cursor(app, scope); } @@ -1497,7 +1383,7 @@ if_view_has_highlighted_range_delete_range(Application_Links *app, View_ID view_ Range range = get_view_range(app, view_id); Buffer_ID buffer = 0; view_get_buffer(app, view_id, AccessOpen, &buffer); - buffer_replace_range(app, buffer, range, make_lit_string("")); + buffer_replace_range(app, buffer, range, string_u8_litexpr("")); result = true; } return(result); @@ -1518,6 +1404,12 @@ begin_notepad_mode(Application_Links *app){ //////////////////////////////// +typedef i32 View_Split_Kind; +enum{ + ViewSplitKind_Ratio, + ViewSplitKind_FixedPixels, +}; + static b32 view_set_split(Application_Links *app, View_ID view, View_Split_Kind kind, f32 t){ b32 result = false; @@ -1557,37 +1449,15 @@ get_single_record(Application_Links *app, Buffer_ID buffer_id, History_Record_In Record_Info record = {}; buffer_history_get_record_info(app, buffer_id, index, &record); if (record.error == RecordError_NoError && record.kind == RecordKind_Group){ - buffer_history_get_group_sub_record(app, buffer_id, index, record.group.count, &record); + buffer_history_get_group_sub_record(app, buffer_id, index, record.group.count - 1, &record); } return(record); } //////////////////////////////// -static void -condense_whitespace(String *a) -{ - *a = skip_chop_whitespace(*a); - int size = a->size; - a->size = 0; - int i = 0; - for (;i < size;){ - if (char_is_whitespace(a->str[i])){ - a->str[a->size++] = ' '; - for (;(i < size) && char_is_whitespace(a->str[i]);){ - ++i; - } - } - else{ - a->str[a->size++] = a->str[i++]; - } - } -} - -//////////////////////////////// - static Vec2 -draw_string(Application_Links *app, Face_ID font_id, String string, Vec2 p, int_color color){ +draw_string(Application_Links *app, Face_ID font_id, String_Const_u8 string, Vec2 p, int_color color){ return(draw_string(app, font_id, string, p, color, 0, V2(1.f, 0.f))); } @@ -1635,58 +1505,55 @@ split_rect(f32_Rect rect, View_Split_Kind kind, Coordinate coord, Side from_side //////////////////////////////// -static String +static String_Const_u8 buffer_push_base_buffer_name(Application_Links *app, Buffer_ID buffer, Arena *arena){ - String result = {}; - buffer_get_base_buffer_name(app, buffer, 0, &result.memory_size); - result.str = push_array(arena, char, result.memory_size); - buffer_get_base_buffer_name(app, buffer, &result, 0); + String_Const_u8 result = {}; + buffer_get_base_buffer_name(app, buffer, arena, &result); return(result); } -static String +static String_Const_u8 buffer_push_unique_buffer_name(Application_Links *app, Buffer_ID buffer, Arena *arena){ - String result = {}; - buffer_get_unique_buffer_name(app, buffer, 0, &result.memory_size); - result.str = push_array(arena, char, result.memory_size); - buffer_get_unique_buffer_name(app, buffer, &result, 0); + String_Const_u8 result = {}; + buffer_get_unique_buffer_name(app, buffer, arena, &result); return(result); } -static String +static String_Const_u8 buffer_push_file_name(Application_Links *app, Buffer_ID buffer, Arena *arena){ - String result = {}; - buffer_get_file_name(app, buffer, 0, &result.memory_size); - result.str = push_array(arena, char, result.memory_size); - buffer_get_file_name(app, buffer, &result, 0); + String_Const_u8 result = {}; + buffer_get_file_name(app, buffer, arena, &result); return(result); } -static String +static String_Const_u8 buffer_limited_base_buffer_name(Application_Links *app, Buffer_ID buffer, char *memory, i32 max){ - String result = {}; - result.str = memory; - result.memory_size = max; - buffer_get_base_buffer_name(app, buffer, &result, 0); - return(result); + Scratch_Block scratch(app); + String_Const_u8 full = {}; + buffer_get_base_buffer_name(app, buffer, scratch, &full); + i32 length = clamp_top((i32)full.size, max); + block_copy(memory, full.str, length); + return(SCu8(memory, length)); } -static String +static String_Const_u8 buffer_limited_unique_buffer_name(Application_Links *app, Buffer_ID buffer, char *memory, i32 max){ - String result = {}; - result.str = memory; - result.memory_size = max; - buffer_get_unique_buffer_name(app, buffer, &result, 0); - return(result); + Scratch_Block scratch(app); + String_Const_u8 full = {}; + buffer_get_unique_buffer_name(app, buffer, scratch, &full); + i32 length = clamp_top((i32)full.size, max); + block_copy(memory, full.str, length); + return(SCu8(memory, length)); } -static String +static String_Const_u8 buffer_limited_file_name(Application_Links *app, Buffer_ID buffer, char *memory, i32 max){ - String result = {}; - result.str = memory; - result.memory_size = max; - buffer_get_file_name(app, buffer, &result, 0); - return(result); + Scratch_Block scratch(app); + String_Const_u8 full = {}; + buffer_get_file_name(app, buffer, scratch, &full); + i32 length = clamp_top((i32)full.size, max); + block_copy(memory, full.str, length); + return(SCu8(memory, length)); } //////////////////////////////// @@ -1694,20 +1561,93 @@ buffer_limited_file_name(Application_Links *app, Buffer_ID buffer, char *memory, static b32 buffer_has_name_with_star(Application_Links *app, Buffer_ID buffer){ char first = 0; - String str = buffer_limited_unique_buffer_name(app, buffer, &first, 1); + String_Const_u8 str = buffer_limited_unique_buffer_name(app, buffer, &first, 1); return(str.size == 0 || first == '*'); } //////////////////////////////// static f32 -get_dpi_scaling_value(Application_Links *app) -{ +get_dpi_scaling_value(Application_Links *app){ // TODO(casey): Allen, this should return the multiplier for the display relative to whatever 4coder // gets tuned to. f32 result = 2.0f; return(result); } +//////////////////////////////// + +static History_Group +begin_history_group(Application_Links *app, Buffer_ID buffer){ + History_Group group = {}; + group.app = app; + group.buffer = buffer; + buffer_history_get_current_state_index(app, buffer, &group.first); + group.first += 1; + return(group); +} + +static void +end_history_group(History_Group group){ + History_Record_Index last = 0; + buffer_history_get_current_state_index(group.app, group.buffer, &last); + if (group.first < last){ + buffer_history_merge_record_range(group.app, group.buffer, group.first, last, RecordMergeFlag_StateInRange_MoveStateForward); + } +} + +//////////////////////////////// + +// TODO(allen): REWRITE THIS EXACTLY HOW YOU WANT IT --- start --- + +static Child_Process_Set_Target_Flags +flags_system_command(Command_Line_Interface_Flag flags){ + Child_Process_Set_Target_Flags set_buffer_flags = 0; + if (!HasFlag(flags, CLI_OverlapWithConflict)){ + set_buffer_flags |= ChildProcessSet_FailIfBufferAlreadyAttachedToAProcess; + } + if (HasFlag(flags, CLI_CursorAtEnd)){ + set_buffer_flags |= ChildProcessSet_CursorAtEnd; + } + return(set_buffer_flags); +} + +static b32 +set_buffer_system_command(Application_Links *app, Child_Process_ID process, Buffer_ID buffer, Command_Line_Interface_Flag flags){ + b32 result = false; + Child_Process_Set_Target_Flags set_buffer_flags = flags_system_command(flags); + if (child_process_set_target_buffer(app, process, buffer, set_buffer_flags)){ + i32 buffer_size = 0; + buffer_get_size(app, buffer, &buffer_size); + buffer_replace_range(app, buffer, make_range(0, buffer_size), string_u8_litexpr("")); + if (HasFlag(flags, CLI_SendEndSignal)){ + buffer_send_end_signal(app, buffer); + } + result = true; + } + return(result); +} + +static b32 +exec_system_command(Application_Links *app, View_ID view, Buffer_Identifier buffer_id, + String_Const_u8 path, String_Const_u8 command, Command_Line_Interface_Flag flags){ + b32 result = false; + Child_Process_ID child_process_id = 0; + if (create_child_process(app, path, command, &child_process_id)){ + result = true; + Buffer_ID buffer_attach_id = buffer_identifier_to_id_create_out_buffer(app, buffer_id); + if (buffer_attach_id != 0){ + if (set_buffer_system_command(app, child_process_id, buffer_attach_id, flags)){ + if (view != 0){ + view_set_buffer(app, view, buffer_attach_id, 0); + } + } + } + } + return(result); +} + +// TODO(allen): --- end --- + // BOTTOM diff --git a/4coder_helper.h b/4coder_helper.h index 9541116c..1c88547d 100644 --- a/4coder_helper.h +++ b/4coder_helper.h @@ -26,20 +26,9 @@ struct Bind_Buffer{ //////////////////////////////// -struct File_Handle_Path{ - FILE *file; - String path; -}; - struct File_Name_Data{ - String file_name; - String data; -}; - -struct File_Name_Path_Data{ - String file_name; - String path; - String data; + String_Const_u8 file_name; + Data data; }; //////////////////////////////// @@ -93,6 +82,14 @@ struct Sort_Pair_i32{ i32 key; }; +//////////////////////////////// + +struct History_Group{ + Application_Links *app; + Buffer_ID buffer; + History_Record_Index first; +}; + #endif // BOTTOM diff --git a/4coder_insertion.cpp b/4coder_insertion.cpp index 6c97e713..681c4056 100644 --- a/4coder_insertion.cpp +++ b/4coder_insertion.cpp @@ -14,11 +14,11 @@ begin_buffer_insertion_at(Application_Links *app, Buffer_ID buffer_id, i32 at){ } static Buffer_Insertion -begin_buffer_insertion_at_buffered(Application_Links *app, Buffer_ID buffer_id, i32 at, Partition *part){ +begin_buffer_insertion_at_buffered(Application_Links *app, Buffer_ID buffer_id, i32 at, Cursor *cursor){ Buffer_Insertion result = begin_buffer_insertion_at(app, buffer_id, at); result.buffering = true; - result.part = part; - result.temp = begin_temp_memory(part); + result.cursor = cursor; + result.temp = begin_temp(cursor); return(result); } @@ -35,32 +35,39 @@ begin_buffer_insertion(Application_Links *app){ } static void -insert_string__no_buffering(Buffer_Insertion *insertion, String string){ - buffer_replace_range(insertion->app, insertion->buffer, make_range(insertion->at), string); +insert_string__no_buffering(Buffer_Insertion *insertion, String_Const_u8 string){ + buffer_replace_range(insertion->app, insertion->buffer, make_range((i32)insertion->at), string); insertion->at += string.size; } static void insert__flush(Buffer_Insertion *insertion){ - Partition *part = insertion->part; - i32 pos = insertion->temp.pos; - String string = make_string(part->base + pos, part->pos - pos); + Cursor *cursor = insertion->cursor; + umem pos = insertion->temp.temp_memory_cursor.pos; + String_Const_u8 string = SCu8(cursor->base + pos, cursor->pos - pos); insert_string__no_buffering(insertion, string); - end_temp_memory(insertion->temp); + end_temp(insertion->temp); } static char* -insert__reserve(Buffer_Insertion *insertion, i32 size){ - char *space = push_array(insertion->part, char, size); +insert__reserve(Buffer_Insertion *insertion, umem size){ + char *space = push_array(insertion->cursor, char, size); if (space == 0){ insert__flush(insertion); - space = push_array(insertion->part, char, size); + space = push_array(insertion->cursor, char, size); } return(space); } static void -insert_string(Buffer_Insertion *insertion, String string){ +end_buffer_insertion(Buffer_Insertion *insertion){ + if (insertion->buffering){ + insert__flush(insertion); + } +} + +static void +insert_string(Buffer_Insertion *insertion, String_Const_u8 string){ if (!insertion->buffering){ insert_string__no_buffering(insertion, string); } @@ -75,28 +82,27 @@ insert_string(Buffer_Insertion *insertion, String string){ } } -static i32 +static umem insertf(Buffer_Insertion *insertion, char *format, ...){ - Arena *arena = context_get_arena(insertion->app); - Temp_Memory_Arena temp = begin_temp_memory(arena); + Arena *scratch = context_get_arena(insertion->app); + Temp_Memory temp = begin_temp(scratch); va_list args; va_start(args, format); - String string = string_push_fv(arena, format, args); + String_Const_u8 string = string_u8_pushfv(scratch, format, args); va_end(args); insert_string(insertion, string); - end_temp_memory(temp); + end_temp(temp); return(string.size); } static void insertc(Buffer_Insertion *insertion, char C){ - insert_string(insertion, make_string(&C, 1)); + insert_string(insertion, SCu8(&C, 1)); } static b32 insert_line_from_buffer(Buffer_Insertion *insertion, Buffer_ID buffer_id, i32 line, i32 truncate_at){ - Partition *part = &global_part; - Temp_Memory temp = begin_temp_memory(part); + Scratch_Block scratch(insertion->app); Partial_Cursor begin = {}; Partial_Cursor end = {}; @@ -109,25 +115,18 @@ insert_line_from_buffer(Buffer_Insertion *insertion, Buffer_ID buffer_id, i32 li buffer_get_size(insertion->app, buffer_id, &buffer_size); if (0 <= begin.pos && begin.pos <= end.pos && end.pos <= buffer_size){ i32 size = (end.pos - begin.pos); - if(truncate_at && (size > truncate_at)) - { + if (truncate_at && (size > truncate_at)){ size = truncate_at; } - char *memory = push_array(part, char, size); - if (memory != 0){ - String str = make_string(memory, 0, size); - success = true; - buffer_read_range(insertion->app, buffer_id, begin.pos, end.pos, str.str); - str.size = size; - insert_string(insertion, str); - } + String_Const_u8 string = scratch_read(insertion->app, scratch, buffer_id, begin.pos, end.pos); + insert_string(insertion, string); + success = true; } } } } - end_temp_memory(temp); return(success); } diff --git a/4coder_insertion.h b/4coder_insertion.h index ec8b9cf6..9d7207f7 100644 --- a/4coder_insertion.h +++ b/4coder_insertion.h @@ -10,9 +10,9 @@ struct Buffer_Insertion{ Application_Links *app; Buffer_ID buffer; - i32 at; + umem at; b32 buffering; - Partition *part; + Cursor *cursor; Temp_Memory temp; }; diff --git a/4coder_jump_direct.cpp b/4coder_jump_direct.cpp index 2fe692b7..78fc4647 100644 --- a/4coder_jump_direct.cpp +++ b/4coder_jump_direct.cpp @@ -8,7 +8,8 @@ compiler errors and jumping to them in the corresponding buffer. CUSTOM_COMMAND_SIG(goto_jump_at_cursor_direct) CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.") { - Temp_Memory temp = begin_temp_memory(&global_part); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); View_ID view = 0; get_active_view(app, AccessProtected, &view); Buffer_ID buffer = 0; @@ -18,7 +19,7 @@ CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump loc Full_Cursor cursor = {}; view_compute_cursor(app, view, seek_pos(pos), &cursor); - Parsed_Jump jump = parse_jump_from_buffer_line(app, &global_part, buffer, cursor.line, false); + Parsed_Jump jump = parse_jump_from_buffer_line(app, scratch, buffer, cursor.line, false); if (jump.success){ change_active_panel(app); View_ID target_view = 0; @@ -29,13 +30,14 @@ CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump loc } } - end_temp_memory(temp); + end_temp(temp); } CUSTOM_COMMAND_SIG(goto_jump_at_cursor_same_panel_direct) CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list..") { - Temp_Memory temp = begin_temp_memory(&global_part); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); View_ID view = 0; get_active_view(app, AccessProtected, &view); Buffer_ID buffer = 0; @@ -45,7 +47,7 @@ CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump loc Full_Cursor cursor = {}; view_compute_cursor(app, view, seek_pos(pos), &cursor); - Parsed_Jump jump = parse_jump_from_buffer_line(app, &global_part, buffer, cursor.line, false); + Parsed_Jump jump = parse_jump_from_buffer_line(app, scratch, buffer, cursor.line, false); if (jump.success){ View_ID target_view = view; if (get_jump_buffer(app, &buffer, &jump.location)){ @@ -53,7 +55,7 @@ CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump loc } } - end_temp_memory(temp); + end_temp(temp); } CUSTOM_COMMAND_SIG(goto_next_jump_direct) @@ -62,7 +64,7 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th b32 skip_repeats = true; b32 skip_sub_errors = true; i32 dir = 1; - seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir); + seek_jump(app, skip_repeats, skip_sub_errors, dir); } CUSTOM_COMMAND_SIG(goto_prev_jump_direct) @@ -71,7 +73,7 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th b32 skip_repeats = true; b32 skip_sub_errors = true; i32 dir = -1; - seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir); + seek_jump(app, skip_repeats, skip_sub_errors, dir); } CUSTOM_COMMAND_SIG(goto_next_jump_no_skips_direct) @@ -80,7 +82,7 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th b32 skip_repeats = false; b32 skip_sub_errors = true; i32 dir = 1; - seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir); + seek_jump(app, skip_repeats, skip_sub_errors, dir); } CUSTOM_COMMAND_SIG(goto_prev_jump_no_skips_direct) @@ -89,20 +91,18 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th b32 skip_repeats = false; b32 skip_sub_errors = true; i32 dir = -1; - seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir); + seek_jump(app, skip_repeats, skip_sub_errors, dir); } CUSTOM_COMMAND_SIG(goto_first_jump_direct) CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.") { - Temp_Memory temp = begin_temp_memory(&global_part); View_ID view = get_view_for_locked_jump_buffer(app); if (view != 0){ view_set_cursor(app, view, seek_pos(0), true); memset(&prev_location, 0, sizeof(prev_location)); - seek_jump(app, &global_part, false, true, 1); + seek_jump(app, false, true, 1); } - end_temp_memory(temp); } // diff --git a/4coder_jump_lister.cpp b/4coder_jump_lister.cpp index 267c5f2a..8ac1c8e1 100644 --- a/4coder_jump_lister.cpp +++ b/4coder_jump_lister.cpp @@ -5,9 +5,9 @@ // TOP static void -activate_jump(Application_Links *app, Partition *scratch, Heap *heap, +activate_jump(Application_Links *app, Heap *heap, View_ID view, struct Lister_State *state, - String text_field, void *user_data, b32 activated_by_mouse){ + String_Const_u8 text_field, void *user_data, b32 activated_by_mouse){ Lister_Activation_Code result_code = ListerActivation_Finished; i32 list_index = (i32)PtrAsInt(user_data); Jump_Lister_Parameters *params = (Jump_Lister_Parameters*)state->lister.data.user_data; @@ -58,29 +58,29 @@ activate_jump(Application_Links *app, Partition *scratch, Heap *heap, } } - lister_default(app, scratch, heap, view, state, result_code); + lister_default(app, heap, view, state, result_code); } static void -open_jump_lister(Application_Links *app, Partition *scratch, Heap *heap, View_ID ui_view, Buffer_ID list_buffer_id, Jump_Lister_Activation_Rule activation_rule, View_ID optional_target_view){ +open_jump_lister(Application_Links *app, Heap *heap, View_ID ui_view, Buffer_ID list_buffer_id, Jump_Lister_Activation_Rule activation_rule, View_ID optional_target_view){ - Marker_List *list = get_or_make_list_for_buffer(app, scratch, heap, list_buffer_id); + Marker_List *list = get_or_make_list_for_buffer(app, heap, list_buffer_id); if (list != 0){ i32 estimated_string_space_size = 0; view_end_ui_mode(app, ui_view); - Temp_Memory temp = begin_temp_memory(scratch); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); i32 option_count = list->jump_count; Lister_Option *options = push_array(scratch, Lister_Option, option_count); Managed_Object stored_jumps = list->jump_array; for (i32 i = 0; i < option_count; i += 1){ Sticky_Jump_Stored stored = {}; managed_object_load_data(app, stored_jumps, i, 1, &stored); - String line = {}; - read_line(app, scratch, list_buffer_id, stored.list_line, &line); + String_Const_u8 line = scratch_read_line(app, scratch, list_buffer_id, stored.list_line); options[i].string = line; memset(&options[i].status, 0, sizeof(options[i].status)); options[i].user_data = IntAsPtr(i); - i32 aligned_size = line.size + 1 + 7; + i32 aligned_size = ((i32)line.size) + 1 + 7; aligned_size = aligned_size - aligned_size%8; estimated_string_space_size += aligned_size; } @@ -97,7 +97,7 @@ open_jump_lister(Application_Links *app, Partition *scratch, Heap *heap, View_ID options, option_count, estimated_string_space_size, ui_view); - end_temp_memory(temp); + end_temp(temp); } } @@ -108,7 +108,7 @@ CUSTOM_DOC("When executed on a buffer with jumps, creates a persistent lister fo get_active_view(app, AccessAll, &view); Buffer_ID buffer = 0; view_get_buffer(app, view, AccessAll, &buffer); - open_jump_lister(app, &global_part, &global_heap, view, buffer, JumpListerActivation_OpenInNextViewKeepUI, 0); + open_jump_lister(app, &global_heap, view, buffer, JumpListerActivation_OpenInNextViewKeepUI, 0); } // BOTTOM diff --git a/4coder_jump_sticky.cpp b/4coder_jump_sticky.cpp index 52254602..af7a5706 100644 --- a/4coder_jump_sticky.cpp +++ b/4coder_jump_sticky.cpp @@ -39,9 +39,10 @@ binary_search(u32 *array, i32 stride, i32 count, u32 x){ } static Sticky_Jump_Array -parse_buffer_to_jump_array(Application_Links *app, Partition *arena, Buffer_ID buffer){ - Sticky_Jump_Array result = {}; - result.jumps = push_array(arena, Sticky_Jump, 0); +parse_buffer_to_jump_array(Application_Links *app, Arena *arena, Buffer_ID buffer){ + Sticky_Jump_Node *jump_first = 0;; + Sticky_Jump_Node *jump_last = 0; + i32 jump_count = 0; for (i32 line = 1;; line += 1){ b32 output_jump = false; @@ -50,41 +51,53 @@ parse_buffer_to_jump_array(Application_Links *app, Partition *arena, Buffer_ID b Buffer_ID out_buffer_id = 0; i32 out_pos = 0; - Temp_Memory temp = begin_temp_memory(arena); - String line_str = {}; - if (read_line(app, arena, buffer, line, &line_str)){ - Parsed_Jump parsed_jump = parse_jump_location(line_str); - if (parsed_jump.success){ - Buffer_ID jump_buffer = {}; - if (open_file(app, &jump_buffer, parsed_jump.location.file.str, parsed_jump.location.file.size, false, true)){ - if (buffer_exists(app, jump_buffer)){ - Partial_Cursor cursor = {}; - if (buffer_compute_cursor(app, jump_buffer, seek_line_char(parsed_jump.location.line, parsed_jump.location.column), &cursor)){ - out_buffer_id = jump_buffer; - out_pos = cursor.pos; - output_jump = true; + { + Scratch_Block line_auto_closer(arena); + if (is_valid_line(app, buffer, line)){ + String_Const_u8 line_str = scratch_read_line(app, arena, buffer, line); + Parsed_Jump parsed_jump = parse_jump_location(line_str); + if (parsed_jump.success){ + Buffer_ID jump_buffer = {}; + if (open_file(app, &jump_buffer, parsed_jump.location.file, false, true)){ + if (buffer_exists(app, jump_buffer)){ + Partial_Cursor cursor = {}; + if (buffer_compute_cursor(app, jump_buffer, seek_line_char(parsed_jump.location.line, parsed_jump.location.column), &cursor)){ + out_buffer_id = jump_buffer; + out_pos = cursor.pos; + output_jump = true; + } } } } } + else{ + break; + } } - else{ - end_temp_memory(temp); - break; - } - end_temp_memory(temp); if (output_jump){ - Sticky_Jump *jump = push_array(arena, Sticky_Jump, 1); - jump->list_line = line; - jump->list_colon_index = colon_index; - jump->is_sub_error = is_sub_error; - jump->jump_buffer_id = out_buffer_id; - jump->jump_pos = out_pos; + Sticky_Jump_Node *jump = push_array(arena, Sticky_Jump_Node, 1); + sll_queue_push(jump_first, jump_last, jump); + jump_count += 1; + jump->jump.list_line = line; + jump->jump.list_colon_index = colon_index; + jump->jump.is_sub_error = is_sub_error; + jump->jump.jump_buffer_id = out_buffer_id; + jump->jump.jump_pos = out_pos; } } - result.count = (i32)(push_array(arena, Sticky_Jump, 0) - result.jumps); + Sticky_Jump_Array result = {}; + result.count = jump_count; + result.jumps = push_array(arena, Sticky_Jump, result.count); + i32 index = 0; + for (Sticky_Jump_Node *node = jump_first; + node != 0; + node = node->next){ + result.jumps[index] = node->jump; + index += 1; + } + return(result); } @@ -92,14 +105,13 @@ static char sticky_jump_marker_handle_var[] = "DEFAULT.sticky_jump_marker_han static i32 sticky_jump_marker_handle_loc; static void -init_marker_list(Application_Links *app, Partition *scratch, Heap *heap, Buffer_ID buffer, Marker_List *list){ - Arena *scratch_arena = context_get_arena(app); - Temp_Memory_Arena temp_arena = begin_temp_memory(scratch_arena); +init_marker_list(Application_Links *app, Heap *heap, Buffer_ID buffer, Marker_List *list){ + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); - String buffer_name = buffer_push_base_buffer_name(app, buffer, scratch_arena); - b32 is_compilation_buffer = match(buffer_name, "*compilation*"); + String_Const_u8 buffer_name = buffer_push_base_buffer_name(app, buffer, scratch); + b32 is_compilation_buffer = string_match(buffer_name, string_u8_litexpr("*compilation*")); - Temp_Memory temp = begin_temp_memory(scratch); Sticky_Jump_Array jumps = parse_buffer_to_jump_array(app, scratch, buffer); Range_Array buffer_ranges = get_ranges_of_duplicate_keys(scratch, &jumps.jumps->jump_buffer_id, sizeof(*jumps.jumps), jumps.count); Sort_Pair_i32 *range_index_buffer_id_pairs = push_array(scratch, Sort_Pair_i32, buffer_ranges.count); @@ -116,15 +128,24 @@ init_marker_list(Application_Links *app, Partition *scratch, Heap *heap, Buffer_ Sticky_Jump_Stored *stored = push_array(scratch, Sticky_Jump_Stored, jumps.count); Managed_Scope scope_array[2] = {}; - scope_array[0] = buffer_get_managed_scope(app, buffer); + buffer_get_managed_scope(app, buffer, &scope_array[0]); for (i32 i = 0; i < scoped_buffer_ranges.count; i += 1){ Range buffer_range_indices = scoped_buffer_ranges.ranges[i]; - Temp_Memory marker_temp = begin_temp_memory(scratch); - Marker *markers = push_array(scratch, Marker, 0); u32 total_jump_count = 0; + for (i32 j = buffer_range_indices.first; + j < buffer_range_indices.one_past_last; + j += 1){ + i32 range_index = range_index_buffer_id_pairs[j].index; + Range range = buffer_ranges.ranges[range_index]; + total_jump_count += range_size(range); + } + + Temp_Memory marker_temp = begin_temp(scratch); + Marker *markers = push_array(scratch, Marker, total_jump_count); Buffer_ID target_buffer_id = 0; + u32 marker_index = 0; for (i32 j = buffer_range_indices.first; j < buffer_range_indices.one_past_last; j += 1){ @@ -134,19 +155,18 @@ init_marker_list(Application_Links *app, Partition *scratch, Heap *heap, Buffer_ target_buffer_id = jumps.jumps[range.first].jump_buffer_id; } for (i32 k = range.first; k < range.one_past_last; k += 1){ - Marker *new_marker = push_array(scratch, Marker, 1); - new_marker->pos = jumps.jumps[k].jump_pos; - new_marker->lean_right = false; + markers[marker_index].pos = jumps.jumps[k].jump_pos; + markers[marker_index].lean_right = false; stored[k].list_line = jumps.jumps[k].list_line; stored[k].list_colon_index = jumps.jumps[k].list_colon_index; stored[k].is_sub_error = jumps.jumps[k].is_sub_error; stored[k].jump_buffer_id = jumps.jumps[k].jump_buffer_id; - stored[k].index_into_marker_array = total_jump_count; - total_jump_count += 1; + stored[k].index_into_marker_array = marker_index; + marker_index += 1; } } - scope_array[1] = buffer_get_managed_scope(app, target_buffer_id); + buffer_get_managed_scope(app, target_buffer_id, &scope_array[1]); Managed_Scope scope = get_managed_scope_with_multiple_dependencies(app, scope_array, ArrayCount(scope_array)); Managed_Object marker_handle = alloc_buffer_markers_on_buffer(app, target_buffer_id, total_jump_count, &scope); managed_object_store_data(app, marker_handle, 0, total_jump_count, markers); @@ -156,7 +176,7 @@ init_marker_list(Application_Links *app, Partition *scratch, Heap *heap, Buffer_ marker_visual_set_effect(app, visual, VisualType_LineHighlights, Stag_Highlight_Junk, 0, 0); } - end_temp_memory(marker_temp); + end_temp(marker_temp); Assert(managed_object_get_item_size(app, marker_handle) == sizeof(Marker)); Assert(managed_object_get_item_count(app, marker_handle) == total_jump_count); @@ -169,14 +189,12 @@ init_marker_list(Application_Links *app, Partition *scratch, Heap *heap, Buffer_ Managed_Object stored_jump_array = alloc_managed_memory_in_scope(app, scope_array[0], sizeof(Sticky_Jump_Stored), jumps.count); managed_object_store_data(app, stored_jump_array, 0, jumps.count, stored); - end_temp_memory(temp); - list->jump_array = stored_jump_array; list->jump_count = jumps.count; buffer_get_size(app, buffer, &list->previous_size); list->buffer_id = buffer; - end_temp_memory(temp_arena); + end_temp(temp); } static void @@ -212,7 +230,7 @@ get_marker_list_for_buffer(Buffer_ID buffer_id){ } static Marker_List* -get_or_make_list_for_buffer(Application_Links *app, Partition *scratch, Heap *heap, Buffer_ID buffer_id){ +get_or_make_list_for_buffer(Application_Links *app, Heap *heap, Buffer_ID buffer_id){ Marker_List *result = get_marker_list_for_buffer(buffer_id); if (result != 0){ i32 buffer_size = 0; @@ -225,7 +243,7 @@ get_or_make_list_for_buffer(Application_Links *app, Partition *scratch, Heap *he } if (result == 0){ result = make_new_marker_list_for_buffer(heap, buffer_id); - init_marker_list(app, scratch, heap, buffer_id, result); + init_marker_list(app, heap, buffer_id, result); if (result->jump_count == 0){ delete_marker_list(result); result = 0; @@ -248,15 +266,15 @@ get_stored_jump_from_list(Application_Links *app, Marker_List *list, i32 index, } static Sticky_Jump_Stored* -get_all_stored_jumps_from_list(Application_Links *app, Partition *arena, Marker_List *list){ +get_all_stored_jumps_from_list(Application_Links *app, Arena *arena, Marker_List *list){ Sticky_Jump_Stored *stored = 0; if (list != 0){ - Temp_Memory restore_point = begin_temp_memory(arena); + Temp_Memory restore_point = begin_temp(arena); stored = push_array(arena, Sticky_Jump_Stored, list->jump_count); if (stored != 0){ if (!managed_object_load_data(app, list->jump_array, 0, list->jump_count, stored)){ stored = 0; - end_temp_memory(restore_point); + end_temp(restore_point); } } } @@ -271,8 +289,8 @@ get_jump_from_list(Application_Links *app, Marker_List *list, i32 index, ID_Pos_ Buffer_ID target_buffer_id = stored.jump_buffer_id; Managed_Scope scope_array[2] = {}; - scope_array[0] = buffer_get_managed_scope(app, list->buffer_id); - scope_array[1] = buffer_get_managed_scope(app, target_buffer_id); + buffer_get_managed_scope(app, list->buffer_id, &scope_array[0]); + buffer_get_managed_scope(app, target_buffer_id, &scope_array[1]); Managed_Scope scope = get_managed_scope_with_multiple_dependencies(app, scope_array, ArrayCount(scope_array)); sticky_jump_marker_handle_loc = managed_variable_create_or_get_id(app, sticky_jump_marker_handle_var, 0); @@ -313,24 +331,26 @@ get_is_sub_error_from_list(Application_Links *app, Marker_List *list, i32 index) } static i32 -get_index_nearest_from_list(Application_Links *app, Partition *scratch, Marker_List *list, i32 line){ +get_index_nearest_from_list(Application_Links *app, Marker_List *list, i32 line){ i32 result = -1; if (list != 0){ - Temp_Memory temp = begin_temp_memory(scratch); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); Sticky_Jump_Stored *stored = get_all_stored_jumps_from_list(app, scratch, list); if (stored != 0){ result = binary_search((u32*)&stored->list_line, sizeof(*stored), list->jump_count, line); } - end_temp_memory(temp); + end_temp(temp); } return(result); } static i32 -get_index_exact_from_list(Application_Links *app, Partition *scratch, Marker_List *list, i32 line){ +get_index_exact_from_list(Application_Links *app, Marker_List *list, i32 line){ i32 result = -1; if (list != 0){ - Temp_Memory temp = begin_temp_memory(scratch); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); Sticky_Jump_Stored *stored = get_all_stored_jumps_from_list(app, scratch, list); if (stored != 0){ i32 index = binary_search((u32*)&stored->list_line, sizeof(*stored), list->jump_count, line); @@ -338,7 +358,7 @@ get_index_exact_from_list(Application_Links *app, Partition *scratch, Marker_Lis result = index; } } - end_temp_memory(temp); + end_temp(temp); } return(result); } @@ -347,21 +367,19 @@ CUSTOM_COMMAND_SIG(goto_jump_at_cursor_sticky) CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.") { Heap *heap = &global_heap; - Partition *part = &global_part; - Temp_Memory temp = begin_temp_memory(part); View_ID view = 0; get_active_view(app, AccessProtected, &view); Buffer_ID buffer = 0; view_get_buffer(app, view, AccessProtected, &buffer); - Marker_List *list = get_or_make_list_for_buffer(app, part, heap, buffer); + Marker_List *list = get_or_make_list_for_buffer(app, heap, buffer); i32 pos = 0; view_get_cursor_pos(app, view, &pos); Full_Cursor cursor = {}; view_compute_cursor(app, view, seek_pos(pos), &cursor); - i32 list_index = get_index_exact_from_list(app, part, list, cursor.line); + i32 list_index = get_index_exact_from_list(app, list, cursor.line); if (list_index >= 0){ ID_Pos_Jump_Location location = {}; @@ -375,30 +393,26 @@ CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump loc } } } - - end_temp_memory(temp); } CUSTOM_COMMAND_SIG(goto_jump_at_cursor_same_panel_sticky) CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list.") { Heap *heap = &global_heap; - Partition *part = &global_part; - Temp_Memory temp = begin_temp_memory(part); View_ID view = 0; get_active_view(app, AccessProtected, &view); Buffer_ID buffer = 0; view_get_buffer(app, view, AccessProtected, &buffer); - Marker_List *list = get_or_make_list_for_buffer(app, part, heap, buffer); + Marker_List *list = get_or_make_list_for_buffer(app, heap, buffer); i32 pos = 0; view_get_cursor_pos(app, view, &pos); Full_Cursor cursor = {}; view_compute_cursor(app, view, seek_pos(pos), &cursor); - i32 list_index = get_index_exact_from_list(app, part, list, cursor.line); + i32 list_index = get_index_exact_from_list(app, list, cursor.line); if (list_index >= 0){ ID_Pos_Jump_Location location = {}; @@ -408,8 +422,6 @@ CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump loc } } } - - end_temp_memory(temp); } static void @@ -473,19 +485,19 @@ goto_next_filtered_jump(Application_Links *app, Marker_List *list, View_ID jump_ } static Locked_Jump_State -get_locked_jump_state(Application_Links *app, Partition *part, Heap *heap){ +get_locked_jump_state(Application_Links *app, Heap *heap){ Locked_Jump_State result = {}; result.view = get_view_for_locked_jump_buffer(app); if (result.view != 0){ Buffer_ID buffer = 0; view_get_buffer(app, result.view, AccessAll, &buffer); - result.list = get_or_make_list_for_buffer(app, part, heap, buffer); + result.list = get_or_make_list_for_buffer(app, heap, buffer); i32 cursor_position = 0; view_get_cursor_pos(app, result.view, &cursor_position); Full_Cursor cursor = {}; view_compute_cursor(app, result.view, seek_pos(cursor_position), &cursor); - result.list_index = get_index_nearest_from_list(app, part, result.list, cursor.line); + result.list_index = get_index_nearest_from_list(app, result.list, cursor.line); } return(result); } @@ -494,9 +506,8 @@ CUSTOM_COMMAND_SIG(goto_next_jump_sticky) CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.") { Heap *heap = &global_heap; - Partition *part = &global_part; - Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap); + Locked_Jump_State jump_state = get_locked_jump_state(app, heap); if (jump_state.view != 0){ i32 cursor_position = 0; view_get_cursor_pos(app, jump_state.view, &cursor_position); @@ -513,9 +524,8 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th CUSTOM_COMMAND_SIG(goto_prev_jump_sticky) CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations."){ Heap *heap = &global_heap; - Partition *part = &global_part; - Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap); + Locked_Jump_State jump_state = get_locked_jump_state(app, heap); if (jump_state.view != 0){ if (jump_state.list_index > 0){ --jump_state.list_index; @@ -528,9 +538,8 @@ CUSTOM_COMMAND_SIG(goto_next_jump_no_skips_sticky) CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, and does not skip sub jump locations.") { Heap *heap = &global_heap; - Partition *part = &global_part; - Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap); + Locked_Jump_State jump_state = get_locked_jump_state(app, heap); if (jump_state.view != 0){ i32 cursor_position = 0; view_get_cursor_pos(app, jump_state.view, &cursor_position); @@ -548,9 +557,8 @@ CUSTOM_COMMAND_SIG(goto_prev_jump_no_skips_sticky) CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.") { Heap *heap = &global_heap; - Partition *part = &global_part; - Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap); + Locked_Jump_State jump_state = get_locked_jump_state(app, heap); if (jump_state.view != 0){ if (jump_state.list_index > 0){ --jump_state.list_index; @@ -563,9 +571,8 @@ CUSTOM_COMMAND_SIG(goto_first_jump_sticky) CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.") { Heap *heap = &global_heap; - Partition *part = &global_part; - Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap); + Locked_Jump_State jump_state = get_locked_jump_state(app, heap); if (jump_state.view != 0){ i32 list_index = 0; ID_Pos_Jump_Location location = {}; @@ -581,9 +588,8 @@ CUSTOM_COMMAND_SIG(goto_first_jump_same_panel_sticky) CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the first jump in the buffer and views the buffer in the panel where the jump list was.") { Heap *heap = &global_heap; - Partition *part = &global_part; - Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap); + Locked_Jump_State jump_state = get_locked_jump_state(app, heap); if (jump_state.view != 0){ i32 list_index = 0; ID_Pos_Jump_Location location = {}; diff --git a/4coder_jump_sticky.h b/4coder_jump_sticky.h index 12754a12..87bc3e2a 100644 --- a/4coder_jump_sticky.h +++ b/4coder_jump_sticky.h @@ -23,6 +23,11 @@ struct Sticky_Jump_Stored{ i32 index_into_marker_array; }; +struct Sticky_Jump_Node{ + Sticky_Jump_Node *next; + Sticky_Jump jump; +}; + struct Sticky_Jump_Array{ Sticky_Jump *jumps; i32 count; diff --git a/4coder_jumping.cpp b/4coder_jumping.cpp index 4fb650c4..b3e98b54 100644 --- a/4coder_jumping.cpp +++ b/4coder_jumping.cpp @@ -5,24 +5,24 @@ // TOP static b32 -ms_style_verify(String line, i32 left_paren_pos, i32 right_paren_pos){ +ms_style_verify(String_Const_u8 line, umem left_paren_pos, umem right_paren_pos){ i32 result = false; - String line_part = substr_tail(line, right_paren_pos); - if (match_part_sc(line_part, ") : ")){ + String_Const_u8 line_part = string_skip(line, right_paren_pos); + if (string_match(string_prefix(line_part, 4), string_u8_litexpr(") : "))){ result = true; } - else if (match_part_sc(line_part, "): ")){ + else if (string_match(string_prefix(line_part, 3), string_u8_litexpr("): "))){ result = true; } if (result){ - String number = substr(line, left_paren_pos + 1, right_paren_pos - left_paren_pos - 2); - if (!str_is_int_s(number)){ + String_Const_u8 number = string_skip(string_prefix(line, right_paren_pos - 1), left_paren_pos + 1); + if (!string_is_integer(number, 10)){ result = false; - i32 comma_pos = find_s_char(number, 0, ','); + umem comma_pos = string_find_first(number, ','); if (comma_pos < number.size){ - String sub_number0 = substr(number, 0, comma_pos); - String sub_number1 = substr(number, comma_pos + 1, number.size - comma_pos - 1); - if (str_is_int_s(sub_number0) && str_is_int_s(sub_number1)){ + String_Const_u8 sub_number0 = string_prefix(number, comma_pos); + String_Const_u8 sub_number1 = string_skip(number, comma_pos + 1); + if (string_is_integer(sub_number0, 10) && string_is_integer(sub_number1, 10)){ result = true; } } @@ -31,25 +31,25 @@ ms_style_verify(String line, i32 left_paren_pos, i32 right_paren_pos){ return(result); } -static i32 -try_skip_rust_arrow(String line){ - i32 pos = 0; - if (match_part(line, "-->")){ - String sub = substr_tail(line, 3); - sub = skip_chop_whitespace(sub); - pos = (i32)(sub.str - line.str); +static umem +try_skip_rust_arrow(String_Const_u8 line){ + umem pos = 0; + if (string_match(string_prefix(line, 3), string_u8_litexpr("-->"))){ + String_Const_u8 sub = string_skip(line, 3); + sub = string_skip_chop_whitespace(sub); + pos = (umem)(sub.str - line.str); } return(pos); } static b32 -check_is_note(String line, i32 colon_pos){ +check_is_note(String_Const_u8 line, umem colon_pos){ b32 is_note = false; - i32 note_pos = find_substr(line, colon_pos, make_lit_string("note")); + umem note_pos = colon_pos + string_find_first(string_skip(line, colon_pos), string_u8_litexpr("note")); if (note_pos < line.size){ b32 is_all_whitespace = true; - for (i32 i = colon_pos + 1; i < note_pos; i += 1){ - if (!char_is_whitespace(line.str[i])){ + for (umem i = colon_pos + 1; i < note_pos; i += 1){ + if (!character_is_whitespace(line.str[i])){ is_all_whitespace = false; break; } @@ -62,54 +62,53 @@ check_is_note(String line, i32 colon_pos){ } static Parsed_Jump -parse_jump_location(String line){ +parse_jump_location(String_Const_u8 line){ Parsed_Jump jump = {}; - jump.sub_jump_indented = (line.str[0] == ' '); + jump.sub_jump_indented = (string_get_character(line, 0) == ' '); - i32 whitespace_length = 0; - line = skip_chop_whitespace(line, &whitespace_length); + String_Const_u8 reduced_line = string_skip_chop_whitespace(line); + umem whitespace_length = (umem)(reduced_line.str - line.str); + line = reduced_line; - i32 left_paren_pos = find_s_char(line, 0, '('); - i32 right_paren_pos = find_s_char(line, left_paren_pos, ')'); + umem left_paren_pos = string_find_first(line, '('); + umem right_paren_pos = left_paren_pos + string_find_first(string_skip(line, left_paren_pos), ')'); for (;!jump.is_ms_style && right_paren_pos < line.size;){ if (ms_style_verify(line, left_paren_pos, right_paren_pos)){ jump.is_ms_style = true; - jump.colon_position = find_s_char(line, right_paren_pos, ':'); + jump.colon_position = (i32)(right_paren_pos + string_find_first(string_skip(line, right_paren_pos), ':')); if (jump.colon_position < line.size){ if (check_is_note(line, jump.colon_position)){ jump.sub_jump_note = true; } - String location_str = substr(line, 0, jump.colon_position); + String_Const_u8 location_str = string_prefix(line, jump.colon_position); + location_str = string_skip_chop_whitespace(location_str); - location_str = skip_chop_whitespace(location_str); - - i32 close_pos = right_paren_pos; - i32 open_pos = left_paren_pos; + i32 close_pos = (i32)right_paren_pos; + i32 open_pos = (i32)left_paren_pos; if (0 < open_pos && open_pos < location_str.size){ - String file = substr(location_str, 0, open_pos); - file = skip_chop_whitespace(file); + String_Const_u8 file = SCu8(location_str.str, open_pos); + file = string_skip_chop_whitespace(file); if (file.size > 0){ - String line_number = substr(location_str, open_pos + 1, close_pos-open_pos - 1); - line_number = skip_chop_whitespace(line_number); + String_Const_u8 line_number = string_skip(string_prefix(location_str, close_pos), open_pos + 1); + line_number = string_skip_chop_whitespace(line_number); if (line_number.size > 0){ - i32 comma_pos = find_s_char(line_number, 0, ','); + umem comma_pos = string_find_first(line_number, ','); if (comma_pos < line_number.size){ - i32 start = comma_pos + 1; - String column_number = substr(line_number, start, line_number.size-start); - line_number = substr(line_number, 0, comma_pos); - jump.location.line = str_to_int_s(line_number); - jump.location.column = str_to_int_s(column_number); + String_Const_u8 column_number = string_skip(line_number, comma_pos + 1); + line_number = string_prefix(line_number, comma_pos); + jump.location.line = (i32)string_to_integer(line_number, 10); + jump.location.column = (i32)string_to_integer(column_number, 10); } else{ - jump.location.line = str_to_int_s(line_number); + jump.location.line = (i32)string_to_integer(line_number, 10); jump.location.column = 0; } jump.location.file = file; - jump.colon_position = jump.colon_position + whitespace_length; + jump.colon_position = jump.colon_position + (i32)whitespace_length; jump.success = true; } } @@ -117,43 +116,41 @@ parse_jump_location(String line){ } } else{ - left_paren_pos = find_s_char(line, left_paren_pos + 1, '('); - right_paren_pos = find_s_char(line, left_paren_pos, ')'); + left_paren_pos = string_find_first(string_skip(line, left_paren_pos + 1), '(') + left_paren_pos + 1; + right_paren_pos = string_find_first(string_skip(line, left_paren_pos), ')') + left_paren_pos; } } if (!jump.is_ms_style){ - i32 start = try_skip_rust_arrow(line); + i32 start = (i32)try_skip_rust_arrow(line); if (start != 0){ jump.has_rust_arrow = true; } - i32 colon_pos1 = find_s_char(line, start, ':'); + umem colon_pos1 = string_find_first(string_skip(line, start), ':') + start; if (line.size > colon_pos1 + 1){ - if (char_is_slash(line.str[colon_pos1 + 1])){ - colon_pos1 = find_s_char(line, colon_pos1 + 1, ':'); + if (character_is_slash(string_get_character(line, colon_pos1 + 1))){ + colon_pos1 = string_find_first(string_skip(line, colon_pos1 + 1), ':') + colon_pos1 + 1; } } - i32 colon_pos2 = find_s_char(line, colon_pos1 + 1, ':'); - i32 colon_pos3 = find_s_char(line, colon_pos2 + 1, ':'); + umem colon_pos2 = string_find_first(string_skip(line, colon_pos1 + 1), ':') + colon_pos1 + 1; + umem colon_pos3 = string_find_first(string_skip(line, colon_pos2 + 1), ':') + colon_pos2 + 1; if (colon_pos3 < line.size){ if (check_is_note(line, colon_pos3)){ jump.sub_jump_note = true; } - String filename = substr(line, start, colon_pos1 - start); - String line_number = substr(line, colon_pos1 + 1, colon_pos2 - colon_pos1 - 1); - String column_number = substr(line, colon_pos2 + 1, colon_pos3 - colon_pos2 - 1); + String_Const_u8 file_name = string_skip(string_prefix(line, colon_pos1), start); + String_Const_u8 line_number = string_skip(string_prefix(line, colon_pos2), colon_pos1 + 1); + String_Const_u8 column_number = string_skip(string_prefix(line, colon_pos3), colon_pos2 + 1); - if (filename.size > 0 && - line_number.size > 0 && - column_number.size > 0){ - jump.location.file = filename; - jump.location.line = str_to_int_s(line_number); - jump.location.column = str_to_int_s(column_number); - jump.colon_position = colon_pos3 + whitespace_length; + if (file_name.size > 0 && line_number.size > 0 && column_number.size > 0){ + jump.location.file = file_name; + jump.location.line = (i32)string_to_integer(line_number, 10); + jump.location.column = (i32)string_to_integer(column_number, 10); + jump.colon_position = (i32)(colon_pos3 + whitespace_length); jump.success = true; } } @@ -163,15 +160,15 @@ parse_jump_location(String line){ jump.sub_jump_note = true; } - String filename = substr(line, 0, colon_pos1); - String line_number = substr(line, colon_pos1 + 1, colon_pos2 - colon_pos1 - 1); + String_Const_u8 file_name = string_prefix(line, colon_pos1); + String_Const_u8 line_number = string_skip(string_prefix(line, colon_pos2), colon_pos1 + 1); - if (str_is_int_s(line_number)){ - if (filename.size > 0 && line_number.size > 0){ - jump.location.file = filename; - jump.location.line = str_to_int_s(line_number); + if (string_is_integer(line_number, 10)){ + if (file_name.size > 0 && line_number.size > 0){ + jump.location.file = file_name; + jump.location.line = (i32)string_to_integer(line_number, 10); jump.location.column = 0; - jump.colon_position = colon_pos3 + whitespace_length; + jump.colon_position = (i32)(colon_pos3 + whitespace_length); jump.success = true; } } @@ -189,20 +186,20 @@ parse_jump_location(String line){ } static Parsed_Jump -parse_jump_location(String line, b32 skip_sub_jump){ +parse_jump_location(String_Const_u8 line, Jump_Flag flags){ Parsed_Jump jump = parse_jump_location(line); - if (jump.is_sub_jump && skip_sub_jump){ - memset(&jump, 0, sizeof(jump)); + if (HasFlag(flags, JumpFlag_SkipSubs) && jump.is_sub_jump){ + block_zero_struct(&jump); } return(jump); } static Parsed_Jump -parse_jump_from_buffer_line(Application_Links *app, Partition *arena, Buffer_ID buffer_id, i32 line, b32 skip_sub_errors){ +parse_jump_from_buffer_line(Application_Links *app, Arena *arena, Buffer_ID buffer_id, i32 line, Jump_Flag flags){ Parsed_Jump jump = {}; - String line_str = {}; - if (read_line(app, arena, buffer_id, line, &line_str)){ - jump = parse_jump_location(line_str, skip_sub_errors); + String_Const_u8 line_str = scratch_read_line(app, arena, buffer_id, line); + if (line_str.size > 0){ + jump = parse_jump_location(line_str, flags); } return(jump); } @@ -211,7 +208,7 @@ parse_jump_from_buffer_line(Application_Links *app, Partition *arena, Buffer_ID static b32 get_jump_buffer(Application_Links *app, Buffer_ID *buffer, Name_Line_Column_Location *location){ - return(open_file(app, buffer, location->file.str, location->file.size, false, true)); + return(open_file(app, buffer, location->file, false, true)); } static b32 @@ -269,16 +266,16 @@ jump_to_location(Application_Links *app, View_ID view, Buffer_ID buffer, ID_Pos_ //////////////////////////////// static Parsed_Jump -seek_next_jump_in_buffer(Application_Links *app, Partition *part, - i32 buffer_id, i32 first_line, b32 skip_sub_errors, i32 direction, +seek_next_jump_in_buffer(Application_Links *app, Arena *arena, + i32 buffer_id, i32 first_line, Jump_Flag flags, i32 direction, i32 *line_out){ Assert(direction == 1 || direction == -1); Parsed_Jump jump = {}; i32 line = first_line; - String line_str = {}; for (;;){ - if (read_line(app, part, buffer_id, line, &line_str)){ - jump = parse_jump_location(line_str, skip_sub_errors); + if (is_valid_line(app, buffer_id, line)){ + String_Const_u8 line_str = scratch_read_line(app, arena, buffer_id, line); + jump = parse_jump_location(line_str, flags); if (jump.success){ break; } @@ -288,11 +285,8 @@ seek_next_jump_in_buffer(Application_Links *app, Partition *part, break; } } - if (line < 0){ - line = 0; - } if (jump.success){ - *line_out = line; + *line_out = clamp_bot(line, 0); } return(jump); } @@ -311,7 +305,7 @@ convert_name_based_to_id_based(Application_Links *app, Name_Line_Column_Location } static Parsed_Jump -seek_next_jump_in_view(Application_Links *app, Partition *part, View_ID view, i32 skip_sub_errors, i32 direction, i32 *line_out){ +seek_next_jump_in_view(Application_Links *app, Arena *arena, View_ID view, i32 skip_sub_errors, i32 direction, i32 *line_out){ i32 cursor_position = 0; view_get_cursor_pos(app, view, &cursor_position); Full_Cursor cursor = {}; @@ -319,7 +313,7 @@ seek_next_jump_in_view(Application_Links *app, Partition *part, View_ID view, i3 i32 line = cursor.line; Buffer_ID buffer = 0; view_get_buffer(app, view, AccessAll, &buffer); - Parsed_Jump jump = seek_next_jump_in_buffer(app, part, buffer, line + direction, skip_sub_errors, direction, &line); + Parsed_Jump jump = seek_next_jump_in_buffer(app, arena, buffer, line + direction, skip_sub_errors, direction, &line); if (jump.success){ *line_out = line; } @@ -336,7 +330,7 @@ skip_this_jump(ID_Line_Column_Jump_Location prev, ID_Line_Column_Jump_Location j } static b32 -advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_ID view, i32 skip_repeats, i32 skip_sub_error, i32 direction, Name_Line_Column_Location *location_out){ +advance_cursor_in_jump_view(Application_Links *app, View_ID view, i32 skip_repeats, i32 skip_sub_error, i32 direction, Name_Line_Column_Location *location_out){ b32 result = true; Name_Line_Column_Location location = {}; @@ -345,8 +339,9 @@ advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_ID vie i32 colon_index = 0; do{ - Temp_Memory temp = begin_temp_memory(part); - Parsed_Jump parsed_jump = seek_next_jump_in_view(app, part, view, skip_sub_error, direction, &line); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); + Parsed_Jump parsed_jump = seek_next_jump_in_view(app, scratch, view, skip_sub_error, direction, &line); if (parsed_jump.success){ jump = convert_name_based_to_id_based(app, parsed_jump.location); view_set_cursor(app, view, seek_line_char(line, parsed_jump.colon_position + 1), true); @@ -356,7 +351,7 @@ advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_ID vie jump.buffer_id = 0; result = false; } - end_temp_memory(temp); + end_temp(temp); }while(skip_repeats && skip_this_jump(prev_location, jump)); if (result){ @@ -370,13 +365,13 @@ advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_ID vie } static b32 -seek_jump(Application_Links *app, Partition *part, b32 skip_repeats, b32 skip_sub_errors, i32 direction){ +seek_jump(Application_Links *app, b32 skip_repeats, b32 skip_sub_errors, i32 direction){ b32 result = false; View_ID view = get_view_for_locked_jump_buffer(app); if (view != 0){ Name_Line_Column_Location location = {}; - if (advance_cursor_in_jump_view(app, &global_part, view, skip_repeats, skip_sub_errors, direction, &location)){ + if (advance_cursor_in_jump_view(app, view, skip_repeats, skip_sub_errors, direction, &location)){ Buffer_ID buffer = {}; if (get_jump_buffer(app, &buffer, &location)){ View_ID target_view = 0; diff --git a/4coder_jumping.h b/4coder_jumping.h new file mode 100644 index 00000000..06427188 --- /dev/null +++ b/4coder_jumping.h @@ -0,0 +1,17 @@ +/* +4coder_jumping.h - Typesused when writing code to jump to locations and seek through jump lists. +*/ + +// TOP + +#if !defined(FCODER_JUMPING_H) +#define FCODER_JUMPING_H + +typedef u32 Jump_Flag; +enum{ + JumpFlag_SkipSubs = 1, +}; + +#endif + +// BOTTOM \ No newline at end of file diff --git a/4coder_lib/4coder_arena.cpp b/4coder_lib/4coder_arena.cpp index 0efd564e..3efdd226 100644 --- a/4coder_lib/4coder_arena.cpp +++ b/4coder_lib/4coder_arena.cpp @@ -9,8 +9,9 @@ distribute, and modify this file as you see fit. // TOP +#if !defined(Migrating__Arena) static Partition -make_part(void *memory, i32_4tech size){ +make_part(void *memory, i32 size){ Partition part = {}; part.base = (char*)memory; part.pos = 0; @@ -19,7 +20,7 @@ make_part(void *memory, i32_4tech size){ } static void* -part_allocate(Partition *data, i32_4tech size){ +part_allocate(Partition *data, i32 size){ void *ret = 0; if (size < 0){ size = 0; @@ -32,15 +33,15 @@ part_allocate(Partition *data, i32_4tech size){ } static void -part_reduce(Partition *data, i32_4tech size){ +part_reduce(Partition *data, i32 size){ if (size > 0 && size <= data->pos){ data->pos -= size; } } static void -part_align(Partition *data, i32_4tech boundary){ - i32_4tech p = data->pos; +part_align(Partition *data, i32 boundary){ + i32 p = data->pos; p += boundary - 1; data->pos = p - p%boundary; } @@ -50,13 +51,13 @@ part_current(Partition *data){ return(data->base + data->pos); } -static i32_4tech +static i32 part_remaining(Partition *data){ return(data->max - data->pos); } static Partition -part_sub_part(Partition *data, i32_4tech size){ +part_sub_part(Partition *data, i32 size){ Partition result = {}; void *d = part_allocate(data, size); if (d != 0){ @@ -79,12 +80,12 @@ end_temp_memory(Temp_Memory temp){ } static void* -push_allocator_allocate(Partition *part, i32_4tech size){ +push_allocator_allocate(Partition *part, i32 size){ return(part_allocate(part, size)); } static void -push_allocator_align(Partition *part, i32_4tech b){ +push_allocator_align(Partition *part, i32 b){ part_align(part, b); } @@ -93,7 +94,7 @@ push_allocator_align(Partition *part, i32_4tech b){ #if defined(FCODER_CUSTOM_H) static Arena -make_arena(Application_Links *app, i32_4tech chunk_size, i32_4tech initial_align){ +make_arena(Application_Links *app, i32 chunk_size, i32 initial_align){ Arena arena = {}; arena.app = app; arena.chunk_size = chunk_size; @@ -102,7 +103,7 @@ make_arena(Application_Links *app, i32_4tech chunk_size, i32_4tech initial_align } static Arena -make_arena(Application_Links *app, i32_4tech chunk_size){ +make_arena(Application_Links *app, i32 chunk_size){ return(make_arena(app, chunk_size, 1)); } @@ -124,15 +125,15 @@ arena_release_all(Arena *arena){ } static void -arena_change_chunk_size(Arena *arena, i32_4tech chunk_size){ +arena_change_chunk_size(Arena *arena, i32 chunk_size){ arena->chunk_size = chunk_size; } static Partition_Chained* -arena__new_part(Arena *arena, i32_4tech new_chunk_size){ +arena__new_part(Arena *arena, i32 new_chunk_size){ Application_Links *app = arena->app; - i32_4tech memory_size = new_chunk_size + sizeof(Partition_Chained); - i32_4tech boundardy = 4096; + i32 memory_size = new_chunk_size + sizeof(Partition_Chained); + i32 boundardy = 4096; if (memory_size < boundardy){ memory_size = boundardy; } @@ -155,7 +156,7 @@ arena__new_part(Arena *arena){ } static void -arena__align_inner(Arena *arena, i32_4tech b){ +arena__align_inner(Arena *arena, i32 b){ if (arena->align != 1){ Partition_Chained *part = arena->part; if (part == 0){ @@ -166,7 +167,7 @@ arena__align_inner(Arena *arena, i32_4tech b){ } static void* -arena_allocate(Arena *arena, i32_4tech size){ +arena_allocate(Arena *arena, i32 size){ void *result = 0; Partition_Chained *part = arena->part; if (part == 0){ @@ -175,7 +176,7 @@ arena_allocate(Arena *arena, i32_4tech size){ arena__align_inner(arena, arena->align); result = part_allocate(&part->part, size); if (result == 0){ - i32_4tech new_chunk_size = arena->chunk_size; + i32 new_chunk_size = arena->chunk_size; if (size > new_chunk_size){ new_chunk_size = size; } @@ -188,13 +189,13 @@ arena_allocate(Arena *arena, i32_4tech size){ } static void -arena_align(Arena *arena, i32_4tech b){ +arena_align(Arena *arena, i32 b){ arena__align_inner(arena, b); arena->align = b; } static Partition* -arena_use_as_part(Arena *arena, i32_4tech minimum_part_size){ +arena_use_as_part(Arena *arena, i32 minimum_part_size){ if (minimum_part_size < arena->chunk_size){ minimum_part_size = arena->chunk_size; } @@ -254,12 +255,12 @@ end_temp_memory(Arena *arena, Temp_Memory_Arena_Light temp){ } static void* -push_allocator_allocate(Arena *arena, i32_4tech size){ +push_allocator_allocate(Arena *arena, i32 size){ return(arena_allocate(arena, size)); } static void -push_allocator_align(Arena *arena, i32_4tech b){ +push_allocator_align(Arena *arena, i32 b){ arena_align(arena, b); } @@ -285,6 +286,7 @@ Scratch_Block::operator Arena*(){ #define push_array(A, T, size) (T*)push_allocator_allocate((A), sizeof(T)*(size)) #define push_align(A, b) push_allocator_align((A), (b)) #define reset_temp_memory end_temp_memory +#endif // BOTTOM diff --git a/4coder_lib/4coder_arena.h b/4coder_lib/4coder_arena.h index f16ba58f..77b14b65 100644 --- a/4coder_lib/4coder_arena.h +++ b/4coder_lib/4coder_arena.h @@ -12,47 +12,16 @@ distribute, and modify this file as you see fit. #if !defined(FCODER_ARENA_H) #define FCODER_ARENA_H -// 4tech_standard_preamble.h -#if !defined(FTECH_INTEGERS) -#define FTECH_INTEGERS -#include -typedef int8_t i8_4tech; -typedef int16_t i16_4tech; -typedef int32_t i32_4tech; -typedef int64_t i64_4tech; - -typedef uint8_t u8_4tech; -typedef uint16_t u16_4tech; -typedef uint32_t u32_4tech; -typedef uint64_t u64_4tech; - -#if defined(FTECH_32_BIT) -typedef u32_4tech umem_4tech; -#else -typedef u64_4tech umem_4tech; -#endif - -typedef float f32_4tech; -typedef double f64_4tech; - -typedef int8_t b8_4tech; -typedef int32_t b32_4tech; -#endif - -#if !defined(Assert) -# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0) -#endif -// standard preamble end - +#if !defined(Migrating__Arena) struct Partition{ char *base; - i32_4tech pos; - i32_4tech max; + i32 pos; + i32 max; }; struct Temp_Memory{ Partition *part; - i32_4tech pos; + i32 pos; }; #if defined(FCODER_CUSTOM_H) @@ -65,19 +34,19 @@ struct Partition_Chained{ struct Arena{ struct Application_Links *app; Partition_Chained *part; - i32_4tech chunk_size; - i32_4tech align; + i32 chunk_size; + i32 align; }; struct Temp_Memory_Arena{ Arena *arena; Partition_Chained *part; - i32_4tech pos; + i32 pos; }; struct Temp_Memory_Arena_Light{ Partition_Chained *part; - i32_4tech pos; + i32 pos; }; struct Scratch_Block{ @@ -93,5 +62,7 @@ struct Scratch_Block{ #endif +#endif + // BOTTOM diff --git a/4coder_lib/4coder_heap.cpp b/4coder_lib/4coder_heap.cpp index f610375b..1e40cfd1 100644 --- a/4coder_lib/4coder_heap.cpp +++ b/4coder_lib/4coder_heap.cpp @@ -52,24 +52,24 @@ heap_init(Heap *heap){ } static void -heap_extend(Heap *heap, void *memory, i32_4tech size){ +heap_extend(Heap *heap, void *memory, i32 size){ heap_assert_good(heap); if (size >= sizeof(Heap_Node)){ Heap_Node *new_node = (Heap_Node*)memory; heap__insert_prev(&heap->in_order, &new_node->order); heap__insert_next(&heap->free_nodes, &new_node->alloc); new_node->size = size - sizeof(*new_node); - heap->total_space += (umem_4tech)size; + heap->total_space += (umem)size; } heap_assert_good(heap); } static void* -heap__reserve_chunk(Heap *heap, Heap_Node *node, i32_4tech size){ - u8_4tech *ptr = (u8_4tech*)(node + 1); - i32_4tech left_over_size = node->size - size; +heap__reserve_chunk(Heap *heap, Heap_Node *node, i32 size){ + u8 *ptr = (u8*)(node + 1); + i32 left_over_size = node->size - size; if (left_over_size > sizeof(*node)){ - i32_4tech new_node_size = left_over_size - sizeof(*node); + i32 new_node_size = left_over_size - sizeof(*node); Heap_Node *new_node = (Heap_Node*)(ptr + size); heap__insert_next(&node->order, &new_node->order); heap__insert_next(&node->alloc, &new_node->alloc); @@ -84,10 +84,10 @@ heap__reserve_chunk(Heap *heap, Heap_Node *node, i32_4tech size){ } static void* -heap_allocate(Heap *heap, i32_4tech size){ +heap_allocate(Heap *heap, i32 size){ if (heap->in_order.next != 0){ heap_assert_good(heap); - i32_4tech aligned_size = (size + sizeof(Heap_Node) - 1); + i32 aligned_size = (size + sizeof(Heap_Node) - 1); aligned_size = aligned_size - (aligned_size%sizeof(Heap_Node)); for (Heap_Basic_Node *n = heap->free_nodes.next; n != &heap->free_nodes; @@ -109,7 +109,7 @@ heap__merge(Heap *heap, Heap_Node *l, Heap_Node *r){ if (&l->order != &heap->in_order && &r->order != &heap->in_order && l->alloc.next != 0 && l->alloc.prev != 0 && r->alloc.next != 0 && r->alloc.prev != 0){ - u8_4tech *ptr = (u8_4tech*)(l + 1) + l->size; + u8 *ptr = (u8*)(l + 1) + l->size; if (PtrDif(ptr, r) == 0){ heap__remove(&r->order); heap__remove(&r->alloc); diff --git a/4coder_lib/4coder_heap.h b/4coder_lib/4coder_heap.h index e5f85e46..451d625d 100644 --- a/4coder_lib/4coder_heap.h +++ b/4coder_lib/4coder_heap.h @@ -12,58 +12,6 @@ distribute, and modify this file as you see fit. #if !defined(FCODER_HEAP_H) #define FCODER_HEAP_H -// 4tech_standard_preamble.h -#if !defined(FTECH_INTEGERS) -#define FTECH_INTEGERS -#include -typedef int8_t i8_4tech; -typedef int16_t i16_4tech; -typedef int32_t i32_4tech; -typedef int64_t i64_4tech; - -typedef uint8_t u8_4tech; -typedef uint16_t u16_4tech; -typedef uint32_t u32_4tech; -typedef uint64_t u64_4tech; - -#if defined(FTECH_32_BIT) -typedef u32_4tech umem_4tech; -#else -typedef u64_4tech umem_4tech; -#endif - -typedef float f32_4tech; -typedef double f64_4tech; - -typedef int8_t b8_4tech; -typedef int32_t b32_4tech; -#endif - -#if !defined(Assert) -# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0) -#endif - -#if !defined(Member) -# define Member(T, m) (((T*)0)->m) -#endif - -#if !defined(PtrDif) -#define PtrDif(a,b) ((uint8_t*)(a) - (uint8_t*)(b)) -#endif - -#if !defined(PtrAsInt) -#define PtrAsInt(a) PtrDif(a,0) -#endif - -#if !defined(OffsetOfMember) -#define OffsetOfMember(S,m) PtrAsInt(&Member(S,m)) -#endif - -#if !defined(CastFromMember) -#define CastFromMember(S,m,ptr) (S*)( (uint8_t*)(ptr) - OffsetOfMember(S,m) ) -#endif -// standard preamble end - struct Heap_Basic_Node{ Heap_Basic_Node *next; Heap_Basic_Node *prev; @@ -74,17 +22,17 @@ struct Heap_Node{ struct{ Heap_Basic_Node order; Heap_Basic_Node alloc; - i32_4tech size; + i32 size; }; - u8_4tech force_size__[64]; + u8 force_size__[64]; }; }; struct Heap{ Heap_Basic_Node in_order; Heap_Basic_Node free_nodes; - i32_4tech used_space; - i32_4tech total_space; + i32 used_space; + i32 total_space; }; //#define DO_HEAP_CHECKS diff --git a/4coder_lib/4coder_string.h b/4coder_lib/4coder_string.h index 8e08d734..d2b3e572 100644 --- a/4coder_lib/4coder_string.h +++ b/4coder_lib/4coder_string.h @@ -12,37 +12,7 @@ To use in C mode: #define FSTRING_C // TOP -// 4tech_standard_preamble.h -#if !defined(FTECH_INTEGERS) -#define FTECH_INTEGERS -#include -typedef int8_t i8_4tech; -typedef int16_t i16_4tech; -typedef int32_t i32_4tech; -typedef int64_t i64_4tech; - -typedef uint8_t u8_4tech; -typedef uint16_t u16_4tech; -typedef uint32_t u32_4tech; -typedef uint64_t u64_4tech; - -#if defined(FTECH_32_BIT) -typedef u32_4tech umem_4tech; -#else -typedef u64_4tech umem_4tech; -#endif - -typedef float f32_4tech; -typedef double f64_4tech; - -typedef int8_t b8_4tech; -typedef int32_t b32_4tech; -#endif - -#if !defined(Assert) -# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0) -#endif -// standard preamble end +#if !defined(REMOVE_OLD_STRING) #if !defined(FSTRING_LINK) # define FSTRING_LINK static @@ -55,10 +25,15 @@ typedef int32_t b32_4tech; #if !defined(FSTRING_GUARD) #define literal(s) (s), (sizeof(s) - 1) +struct CString_Array{ + char **strings; + i32 count; +}; + typedef struct String{ char *str; - i32_4tech size; - i32_4tech memory_size; + i32 size; + i32 memory_size; } String; static String null_string = {}; @@ -67,28 +42,28 @@ static String null_string = {}; #if !defined(FCODER_STRING_H) #define FCODER_STRING_H -FSTRING_INLINE b32_4tech char_is_slash(char c); -FSTRING_INLINE b32_4tech char_is_upper(char c); -FSTRING_INLINE b32_4tech char_is_upper_utf8(char c); -FSTRING_INLINE b32_4tech char_is_lower(char c); -FSTRING_INLINE b32_4tech char_is_lower_utf8(u8_4tech c); +FSTRING_INLINE b32 char_is_slash(char c); +FSTRING_INLINE b32 char_is_upper(char c); +FSTRING_INLINE b32 char_is_upper_utf8(char c); +FSTRING_INLINE b32 char_is_lower(char c); +FSTRING_INLINE b32 char_is_lower_utf8(u8 c); FSTRING_INLINE char char_to_upper(char c); FSTRING_INLINE char char_to_lower(char c); -FSTRING_INLINE b32_4tech char_is_whitespace(char c); -FSTRING_INLINE b32_4tech char_is_alpha_numeric(char c); -FSTRING_INLINE b32_4tech char_is_alpha_numeric_utf8(u8_4tech c); -FSTRING_INLINE b32_4tech char_is_alpha_numeric_true(char c); -FSTRING_INLINE b32_4tech char_is_alpha_numeric_true_utf8(u8_4tech c); -FSTRING_INLINE b32_4tech char_is_alpha(char c); -FSTRING_INLINE b32_4tech char_is_alpha_utf8(u8_4tech c); -FSTRING_INLINE b32_4tech char_is_alpha_true(char c); -FSTRING_INLINE b32_4tech char_is_alpha_true_utf8(u8_4tech c); -FSTRING_INLINE b32_4tech char_is_hex(char c); -FSTRING_INLINE b32_4tech char_is_hex_utf8(u8_4tech c); -FSTRING_INLINE b32_4tech char_is_numeric(char c); -FSTRING_INLINE b32_4tech char_is_numeric_utf8(u8_4tech c); -FSTRING_INLINE String make_string_cap(void *str, i32_4tech size, i32_4tech mem_size); -FSTRING_INLINE String make_string(void *str, i32_4tech size); +FSTRING_INLINE b32 char_is_whitespace(char c); +FSTRING_INLINE b32 char_is_alpha_numeric(char c); +FSTRING_INLINE b32 char_is_alpha_numeric_utf8(u8 c); +FSTRING_INLINE b32 char_is_alpha_numeric_true(char c); +FSTRING_INLINE b32 char_is_alpha_numeric_true_utf8(u8 c); +FSTRING_INLINE b32 char_is_alpha(char c); +FSTRING_INLINE b32 char_is_alpha_utf8(u8 c); +FSTRING_INLINE b32 char_is_alpha_true(char c); +FSTRING_INLINE b32 char_is_alpha_true_utf8(u8 c); +FSTRING_INLINE b32 char_is_hex(char c); +FSTRING_INLINE b32 char_is_hex_utf8(u8 c); +FSTRING_INLINE b32 char_is_numeric(char c); +FSTRING_INLINE b32 char_is_numeric_utf8(u8 c); +FSTRING_INLINE String make_string_cap(void *str, i32 size, i32 mem_size); +FSTRING_INLINE String make_string(void *str, i32 size); #ifndef make_lit_string # define make_lit_string(s) (make_string_cap((char*)(s), sizeof(s)-1, sizeof(s))) #endif @@ -101,72 +76,72 @@ FSTRING_INLINE String make_string(void *str, i32_4tech size); #ifndef expand_str # define expand_str(s) ((s).str), ((s).size) #endif -FSTRING_LINK i32_4tech str_size(char *str); +FSTRING_LINK i32 str_size(char *str); FSTRING_INLINE String make_string_slowly(void *str); -FSTRING_INLINE String substr_tail(String str, i32_4tech start); -FSTRING_INLINE String substr(String str, i32_4tech start, i32_4tech size); +FSTRING_INLINE String substr_tail(String str, i32 start); +FSTRING_INLINE String substr(String str, i32 start, i32 size); FSTRING_LINK String skip_whitespace(String str); -FSTRING_LINK String skip_whitespace_measure(String str, i32_4tech *skip_length); +FSTRING_LINK String skip_whitespace_measure(String str, i32 *skip_length); FSTRING_LINK String chop_whitespace(String str); FSTRING_LINK String skip_chop_whitespace(String str); -FSTRING_LINK String skip_chop_whitespace_measure(String str, i32_4tech *skip_length); +FSTRING_LINK String skip_chop_whitespace_measure(String str, i32 *skip_length); FSTRING_INLINE String tailstr(String str); -FSTRING_LINK b32_4tech match_cc(char *a, char *b); -FSTRING_LINK b32_4tech match_sc(String a, char *b); -FSTRING_INLINE b32_4tech match_cs(char *a, String b); -FSTRING_LINK b32_4tech match_ss(String a, String b); -FSTRING_LINK b32_4tech match_part_ccl(char *a, char *b, i32_4tech *len); -FSTRING_LINK b32_4tech match_part_scl(String a, char *b, i32_4tech *len); -FSTRING_INLINE b32_4tech match_part_cc(char *a, char *b); -FSTRING_INLINE b32_4tech match_part_sc(String a, char *b); -FSTRING_LINK b32_4tech match_part_cs(char *a, String b); -FSTRING_LINK b32_4tech match_part_ss(String a, String b); -FSTRING_LINK b32_4tech match_insensitive_cc(char *a, char *b); -FSTRING_LINK b32_4tech match_insensitive_sc(String a, char *b); -FSTRING_INLINE b32_4tech match_insensitive_cs(char *a, String b); -FSTRING_LINK b32_4tech match_insensitive_ss(String a, String b); -FSTRING_LINK b32_4tech match_part_insensitive_ccl(char *a, char *b, i32_4tech *len); -FSTRING_LINK b32_4tech match_part_insensitive_scl(String a, char *b, i32_4tech *len); -FSTRING_INLINE b32_4tech match_part_insensitive_cc(char *a, char *b); -FSTRING_INLINE b32_4tech match_part_insensitive_sc(String a, char *b); -FSTRING_LINK b32_4tech match_part_insensitive_cs(char *a, String b); -FSTRING_LINK b32_4tech match_part_insensitive_ss(String a, String b); -FSTRING_LINK i32_4tech compare_cc(char *a, char *b); -FSTRING_LINK i32_4tech compare_sc(String a, char *b); -FSTRING_INLINE i32_4tech compare_cs(char *a, String b); -FSTRING_LINK i32_4tech compare_ss(String a, String b); -FSTRING_LINK i32_4tech find_c_char(char *str, i32_4tech start, char character); -FSTRING_LINK i32_4tech find_s_char(String str, i32_4tech start, char character); -FSTRING_LINK i32_4tech rfind_s_char(String str, i32_4tech start, char character); -FSTRING_LINK i32_4tech find_c_chars(char *str, i32_4tech start, char *characters); -FSTRING_LINK i32_4tech find_s_chars(String str, i32_4tech start, char *characters); -FSTRING_LINK i32_4tech find_substr_c(char *str, i32_4tech start, String seek); -FSTRING_LINK i32_4tech find_substr_s(String str, i32_4tech start, String seek); -FSTRING_LINK i32_4tech rfind_substr_s(String str, i32_4tech start, String seek); -FSTRING_LINK i32_4tech find_substr_insensitive_c(char *str, i32_4tech start, String seek); -FSTRING_LINK i32_4tech find_substr_insensitive_s(String str, i32_4tech start, String seek); -FSTRING_INLINE b32_4tech has_substr_c(char *s, String seek); -FSTRING_INLINE b32_4tech has_substr_s(String s, String seek); -FSTRING_INLINE b32_4tech has_substr_insensitive_c(char *s, String seek); -FSTRING_INLINE b32_4tech has_substr_insensitive_s(String s, String seek); -FSTRING_LINK i32_4tech copy_fast_unsafe_cc(char *dest, char *src); -FSTRING_LINK i32_4tech copy_fast_unsafe_cs(char *dest, String src); -FSTRING_LINK b32_4tech copy_checked_ss(String *dest, String src); -FSTRING_LINK b32_4tech copy_checked_cs(char *dest, i32_4tech dest_cap, String src); -FSTRING_LINK b32_4tech copy_partial_sc(String *dest, char *src); -FSTRING_LINK b32_4tech copy_partial_ss(String *dest, String src); -FSTRING_LINK b32_4tech copy_partial_cs(char *dest, i32_4tech dest_cap, String src); -FSTRING_INLINE i32_4tech copy_cc(char *dest, char *src); +FSTRING_LINK b32 match_cc(char *a, char *b); +FSTRING_LINK b32 match_sc(String a, char *b); +FSTRING_INLINE b32 match_cs(char *a, String b); +FSTRING_LINK b32 match_ss(String a, String b); +FSTRING_LINK b32 match_part_ccl(char *a, char *b, i32 *len); +FSTRING_LINK b32 match_part_scl(String a, char *b, i32 *len); +FSTRING_INLINE b32 match_part_cc(char *a, char *b); +FSTRING_INLINE b32 match_part_sc(String a, char *b); +FSTRING_LINK b32 match_part_cs(char *a, String b); +FSTRING_LINK b32 match_part_ss(String a, String b); +FSTRING_LINK b32 match_insensitive_cc(char *a, char *b); +FSTRING_LINK b32 match_insensitive_sc(String a, char *b); +FSTRING_INLINE b32 match_insensitive_cs(char *a, String b); +FSTRING_LINK b32 match_insensitive_ss(String a, String b); +FSTRING_LINK b32 match_part_insensitive_ccl(char *a, char *b, i32 *len); +FSTRING_LINK b32 match_part_insensitive_scl(String a, char *b, i32 *len); +FSTRING_INLINE b32 match_part_insensitive_cc(char *a, char *b); +FSTRING_INLINE b32 match_part_insensitive_sc(String a, char *b); +FSTRING_LINK b32 match_part_insensitive_cs(char *a, String b); +FSTRING_LINK b32 match_part_insensitive_ss(String a, String b); +FSTRING_LINK i32 compare_cc(char *a, char *b); +FSTRING_LINK i32 compare_sc(String a, char *b); +FSTRING_INLINE i32 compare_cs(char *a, String b); +FSTRING_LINK i32 compare_ss(String a, String b); +FSTRING_LINK i32 find_c_char(char *str, i32 start, char character); +FSTRING_LINK i32 find_s_char(String str, i32 start, char character); +FSTRING_LINK i32 rfind_s_char(String str, i32 start, char character); +FSTRING_LINK i32 find_c_chars(char *str, i32 start, char *characters); +FSTRING_LINK i32 find_s_chars(String str, i32 start, char *characters); +FSTRING_LINK i32 find_substr_c(char *str, i32 start, String seek); +FSTRING_LINK i32 find_substr_s(String str, i32 start, String seek); +FSTRING_LINK i32 rfind_substr_s(String str, i32 start, String seek); +FSTRING_LINK i32 find_substr_insensitive_c(char *str, i32 start, String seek); +FSTRING_LINK i32 find_substr_insensitive_s(String str, i32 start, String seek); +FSTRING_INLINE b32 has_substr_c(char *s, String seek); +FSTRING_INLINE b32 has_substr_s(String s, String seek); +FSTRING_INLINE b32 has_substr_insensitive_c(char *s, String seek); +FSTRING_INLINE b32 has_substr_insensitive_s(String s, String seek); +FSTRING_LINK i32 copy_fast_unsafe_cc(char *dest, char *src); +FSTRING_LINK i32 copy_fast_unsafe_cs(char *dest, String src); +FSTRING_LINK b32 copy_checked_ss(String *dest, String src); +FSTRING_LINK b32 copy_checked_cs(char *dest, i32 dest_cap, String src); +FSTRING_LINK b32 copy_partial_sc(String *dest, char *src); +FSTRING_LINK b32 copy_partial_ss(String *dest, String src); +FSTRING_LINK b32 copy_partial_cs(char *dest, i32 dest_cap, String src); +FSTRING_INLINE i32 copy_cc(char *dest, char *src); FSTRING_INLINE void copy_ss(String *dest, String src); FSTRING_INLINE void copy_sc(String *dest, char *src); -FSTRING_LINK b32_4tech append_checked_ss(String *dest, String src); -FSTRING_LINK b32_4tech append_partial_sc(String *dest, char *src); -FSTRING_LINK b32_4tech append_partial_ss(String *dest, String src); -FSTRING_LINK b32_4tech append_s_char(String *dest, char c); -FSTRING_INLINE b32_4tech append_ss(String *dest, String src); -FSTRING_INLINE b32_4tech append_sc(String *dest, char *src); -FSTRING_LINK b32_4tech terminate_with_null(String *str); -FSTRING_LINK b32_4tech append_padding(String *dest, char c, i32_4tech target_size); +FSTRING_LINK b32 append_checked_ss(String *dest, String src); +FSTRING_LINK b32 append_partial_sc(String *dest, char *src); +FSTRING_LINK b32 append_partial_ss(String *dest, String src); +FSTRING_LINK b32 append_s_char(String *dest, char c); +FSTRING_INLINE b32 append_ss(String *dest, String src); +FSTRING_INLINE b32 append_sc(String *dest, char *src); +FSTRING_LINK b32 terminate_with_null(String *str); +FSTRING_LINK b32 append_padding(String *dest, char c, i32 target_size); FSTRING_LINK void string_interpret_escapes(String src, char *dst); FSTRING_LINK void replace_char(String *str, char replace, char with); FSTRING_LINK void replace_str_ss(String *str, String replace, String with); @@ -180,104 +155,107 @@ FSTRING_LINK void to_upper_cc(char *src, char *dst); FSTRING_LINK void to_upper_ss(String *dst, String src); FSTRING_LINK void to_upper_s(String *str); FSTRING_LINK void to_camel_cc(char *src, char *dst); -FSTRING_LINK i32_4tech int_to_str_size(i32_4tech x); -FSTRING_LINK b32_4tech int_to_str(String *dest, i32_4tech x); -FSTRING_LINK b32_4tech append_int_to_str(String *dest, i32_4tech x); -FSTRING_LINK i32_4tech u64_to_str_size(uint64_t x); -FSTRING_LINK b32_4tech u64_to_str(String *dest, uint64_t x); -FSTRING_LINK b32_4tech append_u64_to_str(String *dest, uint64_t x); -FSTRING_LINK i32_4tech float_to_str_size(float x); -FSTRING_LINK b32_4tech append_float_to_str(String *dest, float x); -FSTRING_LINK b32_4tech float_to_str(String *dest, float x); -FSTRING_LINK i32_4tech str_is_int_c(char *str); -FSTRING_LINK b32_4tech str_is_int_s(String str); -FSTRING_LINK i32_4tech str_to_int_c(char *str); -FSTRING_LINK i32_4tech str_to_int_s(String str); -FSTRING_LINK i32_4tech hexchar_to_int(char c); -FSTRING_LINK char int_to_hexchar(i32_4tech x); -FSTRING_LINK u32_4tech hexstr_to_int(String str); -FSTRING_LINK b32_4tech color_to_hexstr(String *s, u32_4tech color); -FSTRING_LINK b32_4tech hexstr_to_color(String s, u32_4tech *out); -FSTRING_LINK i32_4tech reverse_seek_slash_pos(String str, i32_4tech pos); -FSTRING_INLINE i32_4tech reverse_seek_slash(String str); +FSTRING_LINK i32 int_to_str_size(i32 x); +FSTRING_LINK b32 int_to_str(String *dest, i32 x); +FSTRING_LINK b32 append_int_to_str(String *dest, i32 x); +FSTRING_LINK i32 u64_to_str_size(uint64_t x); +FSTRING_LINK b32 u64_to_str(String *dest, uint64_t x); +FSTRING_LINK b32 append_u64_to_str(String *dest, uint64_t x); +FSTRING_LINK i32 float_to_str_size(float x); +FSTRING_LINK b32 append_float_to_str(String *dest, float x); +FSTRING_LINK b32 float_to_str(String *dest, float x); +FSTRING_LINK i32 str_is_int_c(char *str); +FSTRING_LINK b32 str_is_int_s(String str); +FSTRING_LINK i32 str_to_int_c(char *str); +FSTRING_LINK i32 str_to_int_s(String str); +FSTRING_LINK i32 hexchar_to_int(char c); +FSTRING_LINK char int_to_hexchar(i32 x); +FSTRING_LINK u32 hexstr_to_int(String str); +FSTRING_LINK b32 color_to_hexstr(String *s, u32 color); +FSTRING_LINK b32 hexstr_to_color(String s, u32 *out); +FSTRING_LINK i32 reverse_seek_slash_pos(String str, i32 pos); +FSTRING_INLINE i32 reverse_seek_slash(String str); FSTRING_INLINE String front_of_directory(String dir); FSTRING_INLINE String path_of_directory(String dir); -FSTRING_LINK b32_4tech set_last_folder_sc(String *dir, char *folder_name, char slash); -FSTRING_LINK b32_4tech set_last_folder_ss(String *dir, String folder_name, char slash); +FSTRING_LINK b32 set_last_folder_sc(String *dir, char *folder_name, char slash); +FSTRING_LINK b32 set_last_folder_ss(String *dir, String folder_name, char slash); FSTRING_LINK String file_extension(String str); -FSTRING_LINK b32_4tech remove_extension(String *str); -FSTRING_LINK b32_4tech remove_last_folder(String *str); -FSTRING_LINK b32_4tech string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index); -FSTRING_LINK b32_4tech string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_index); +FSTRING_LINK b32 remove_extension(String *str); +FSTRING_LINK b32 remove_last_folder(String *str); +FSTRING_LINK b32 string_set_match_table(void *str_set, i32 item_size, i32 count, String str, i32 *match_index); +FSTRING_LINK b32 string_set_match(String *str_set, i32 count, String str, i32 *match_index); FSTRING_LINK String get_first_double_line(String source); FSTRING_LINK String get_next_double_line(String source, String line); FSTRING_LINK String get_next_word(String source, String prev_word); FSTRING_LINK String get_first_word(String source); -FSTRING_LINK String string_push(Partition *part, i32_4tech size); -FSTRING_LINK String string_push_copy(Partition *part, String str); +FSTRING_LINK String string_push(Cursor *cursor, i32 size); +FSTRING_LINK String string_push_copy(Cursor *cursor, String str); +FSTRING_LINK String string_push(Arena *arena, i32 size); +FSTRING_LINK String string_push_copy(Arena *arena, String str); +FSTRING_LINK char* get_null_terminated(Arena *arena, String str); #endif #if !defined(FSTRING_C) && !defined(FSTRING_GUARD) -FSTRING_INLINE String make_string(void *str, i32_4tech size, i32_4tech mem_size){return(make_string_cap(str,size,mem_size));} -FSTRING_INLINE String substr(String str, i32_4tech start){return(substr_tail(str,start));} -FSTRING_LINK String skip_whitespace(String str, i32_4tech *skip_length){return(skip_whitespace_measure(str,skip_length));} -FSTRING_LINK String skip_chop_whitespace(String str, i32_4tech *skip_length){return(skip_chop_whitespace_measure(str,skip_length));} -FSTRING_LINK b32_4tech match(char *a, char *b){return(match_cc(a,b));} -FSTRING_LINK b32_4tech match(String a, char *b){return(match_sc(a,b));} -FSTRING_INLINE b32_4tech match(char *a, String b){return(match_cs(a,b));} -FSTRING_LINK b32_4tech match(String a, String b){return(match_ss(a,b));} -FSTRING_LINK b32_4tech match_part(char *a, char *b, i32_4tech *len){return(match_part_ccl(a,b,len));} -FSTRING_LINK b32_4tech match_part(String a, char *b, i32_4tech *len){return(match_part_scl(a,b,len));} -FSTRING_INLINE b32_4tech match_part(char *a, char *b){return(match_part_cc(a,b));} -FSTRING_INLINE b32_4tech match_part(String a, char *b){return(match_part_sc(a,b));} -FSTRING_LINK b32_4tech match_part(char *a, String b){return(match_part_cs(a,b));} -FSTRING_LINK b32_4tech match_part(String a, String b){return(match_part_ss(a,b));} -FSTRING_LINK b32_4tech match_insensitive(char *a, char *b){return(match_insensitive_cc(a,b));} -FSTRING_LINK b32_4tech match_insensitive(String a, char *b){return(match_insensitive_sc(a,b));} -FSTRING_INLINE b32_4tech match_insensitive(char *a, String b){return(match_insensitive_cs(a,b));} -FSTRING_LINK b32_4tech match_insensitive(String a, String b){return(match_insensitive_ss(a,b));} -FSTRING_LINK b32_4tech match_part_insensitive(char *a, char *b, i32_4tech *len){return(match_part_insensitive_ccl(a,b,len));} -FSTRING_LINK b32_4tech match_part_insensitive(String a, char *b, i32_4tech *len){return(match_part_insensitive_scl(a,b,len));} -FSTRING_INLINE b32_4tech match_part_insensitive(char *a, char *b){return(match_part_insensitive_cc(a,b));} -FSTRING_INLINE b32_4tech match_part_insensitive(String a, char *b){return(match_part_insensitive_sc(a,b));} -FSTRING_LINK b32_4tech match_part_insensitive(char *a, String b){return(match_part_insensitive_cs(a,b));} -FSTRING_LINK b32_4tech match_part_insensitive(String a, String b){return(match_part_insensitive_ss(a,b));} -FSTRING_LINK i32_4tech compare(char *a, char *b){return(compare_cc(a,b));} -FSTRING_LINK i32_4tech compare(String a, char *b){return(compare_sc(a,b));} -FSTRING_INLINE i32_4tech compare(char *a, String b){return(compare_cs(a,b));} -FSTRING_LINK i32_4tech compare(String a, String b){return(compare_ss(a,b));} -FSTRING_LINK i32_4tech find(char *str, i32_4tech start, char character){return(find_c_char(str,start,character));} -FSTRING_LINK i32_4tech find(String str, i32_4tech start, char character){return(find_s_char(str,start,character));} -FSTRING_LINK i32_4tech rfind(String str, i32_4tech start, char character){return(rfind_s_char(str,start,character));} -FSTRING_LINK i32_4tech find(char *str, i32_4tech start, char *characters){return(find_c_chars(str,start,characters));} -FSTRING_LINK i32_4tech find(String str, i32_4tech start, char *characters){return(find_s_chars(str,start,characters));} -FSTRING_LINK i32_4tech find_substr(char *str, i32_4tech start, String seek){return(find_substr_c(str,start,seek));} -FSTRING_LINK i32_4tech find_substr(String str, i32_4tech start, String seek){return(find_substr_s(str,start,seek));} -FSTRING_LINK i32_4tech rfind_substr(String str, i32_4tech start, String seek){return(rfind_substr_s(str,start,seek));} -FSTRING_LINK i32_4tech find_substr_insensitive(char *str, i32_4tech start, String seek){return(find_substr_insensitive_c(str,start,seek));} -FSTRING_LINK i32_4tech find_substr_insensitive(String str, i32_4tech start, String seek){return(find_substr_insensitive_s(str,start,seek));} -FSTRING_INLINE b32_4tech has_substr(char *s, String seek){return(has_substr_c(s,seek));} -FSTRING_INLINE b32_4tech has_substr(String s, String seek){return(has_substr_s(s,seek));} -FSTRING_INLINE b32_4tech has_substr_insensitive(char *s, String seek){return(has_substr_insensitive_c(s,seek));} -FSTRING_INLINE b32_4tech has_substr_insensitive(String s, String seek){return(has_substr_insensitive_s(s,seek));} -FSTRING_LINK i32_4tech copy_fast_unsafe(char *dest, char *src){return(copy_fast_unsafe_cc(dest,src));} -FSTRING_LINK i32_4tech copy_fast_unsafe(char *dest, String src){return(copy_fast_unsafe_cs(dest,src));} -FSTRING_LINK b32_4tech copy_checked(String *dest, String src){return(copy_checked_ss(dest,src));} -FSTRING_LINK b32_4tech copy_checked(char *dest, i32_4tech dest_cap, String src){return(copy_checked_cs(dest,dest_cap,src));} -FSTRING_LINK b32_4tech copy_partial(String *dest, char *src){return(copy_partial_sc(dest,src));} -FSTRING_LINK b32_4tech copy_partial(String *dest, String src){return(copy_partial_ss(dest,src));} -FSTRING_LINK b32_4tech copy_partial(char *dest, i32_4tech dest_cap, String src){return(copy_partial_cs(dest,dest_cap,src));} -FSTRING_INLINE i32_4tech copy(char *dest, char *src){return(copy_cc(dest,src));} +FSTRING_INLINE String make_string(void *str, i32 size, i32 mem_size){return(make_string_cap(str,size,mem_size));} +FSTRING_INLINE String substr(String str, i32 start){return(substr_tail(str,start));} +FSTRING_LINK String skip_whitespace(String str, i32 *skip_length){return(skip_whitespace_measure(str,skip_length));} +FSTRING_LINK String skip_chop_whitespace(String str, i32 *skip_length){return(skip_chop_whitespace_measure(str,skip_length));} +FSTRING_LINK b32 match(char *a, char *b){return(match_cc(a,b));} +FSTRING_LINK b32 match(String a, char *b){return(match_sc(a,b));} +FSTRING_INLINE b32 match(char *a, String b){return(match_cs(a,b));} +FSTRING_LINK b32 match(String a, String b){return(match_ss(a,b));} +FSTRING_LINK b32 match_part(char *a, char *b, i32 *len){return(match_part_ccl(a,b,len));} +FSTRING_LINK b32 match_part(String a, char *b, i32 *len){return(match_part_scl(a,b,len));} +FSTRING_INLINE b32 match_part(char *a, char *b){return(match_part_cc(a,b));} +FSTRING_INLINE b32 match_part(String a, char *b){return(match_part_sc(a,b));} +FSTRING_LINK b32 match_part(char *a, String b){return(match_part_cs(a,b));} +FSTRING_LINK b32 match_part(String a, String b){return(match_part_ss(a,b));} +FSTRING_LINK b32 match_insensitive(char *a, char *b){return(match_insensitive_cc(a,b));} +FSTRING_LINK b32 match_insensitive(String a, char *b){return(match_insensitive_sc(a,b));} +FSTRING_INLINE b32 match_insensitive(char *a, String b){return(match_insensitive_cs(a,b));} +FSTRING_LINK b32 match_insensitive(String a, String b){return(match_insensitive_ss(a,b));} +FSTRING_LINK b32 match_part_insensitive(char *a, char *b, i32 *len){return(match_part_insensitive_ccl(a,b,len));} +FSTRING_LINK b32 match_part_insensitive(String a, char *b, i32 *len){return(match_part_insensitive_scl(a,b,len));} +FSTRING_INLINE b32 match_part_insensitive(char *a, char *b){return(match_part_insensitive_cc(a,b));} +FSTRING_INLINE b32 match_part_insensitive(String a, char *b){return(match_part_insensitive_sc(a,b));} +FSTRING_LINK b32 match_part_insensitive(char *a, String b){return(match_part_insensitive_cs(a,b));} +FSTRING_LINK b32 match_part_insensitive(String a, String b){return(match_part_insensitive_ss(a,b));} +FSTRING_LINK i32 compare(char *a, char *b){return(compare_cc(a,b));} +FSTRING_LINK i32 compare(String a, char *b){return(compare_sc(a,b));} +FSTRING_INLINE i32 compare(char *a, String b){return(compare_cs(a,b));} +FSTRING_LINK i32 compare(String a, String b){return(compare_ss(a,b));} +FSTRING_LINK i32 find(char *str, i32 start, char character){return(find_c_char(str,start,character));} +FSTRING_LINK i32 find(String str, i32 start, char character){return(find_s_char(str,start,character));} +FSTRING_LINK i32 rfind(String str, i32 start, char character){return(rfind_s_char(str,start,character));} +FSTRING_LINK i32 find(char *str, i32 start, char *characters){return(find_c_chars(str,start,characters));} +FSTRING_LINK i32 find(String str, i32 start, char *characters){return(find_s_chars(str,start,characters));} +FSTRING_LINK i32 find_substr(char *str, i32 start, String seek){return(find_substr_c(str,start,seek));} +FSTRING_LINK i32 find_substr(String str, i32 start, String seek){return(find_substr_s(str,start,seek));} +FSTRING_LINK i32 rfind_substr(String str, i32 start, String seek){return(rfind_substr_s(str,start,seek));} +FSTRING_LINK i32 find_substr_insensitive(char *str, i32 start, String seek){return(find_substr_insensitive_c(str,start,seek));} +FSTRING_LINK i32 find_substr_insensitive(String str, i32 start, String seek){return(find_substr_insensitive_s(str,start,seek));} +FSTRING_INLINE b32 has_substr(char *s, String seek){return(has_substr_c(s,seek));} +FSTRING_INLINE b32 has_substr(String s, String seek){return(has_substr_s(s,seek));} +FSTRING_INLINE b32 has_substr_insensitive(char *s, String seek){return(has_substr_insensitive_c(s,seek));} +FSTRING_INLINE b32 has_substr_insensitive(String s, String seek){return(has_substr_insensitive_s(s,seek));} +FSTRING_LINK i32 copy_fast_unsafe(char *dest, char *src){return(copy_fast_unsafe_cc(dest,src));} +FSTRING_LINK i32 copy_fast_unsafe(char *dest, String src){return(copy_fast_unsafe_cs(dest,src));} +FSTRING_LINK b32 copy_checked(String *dest, String src){return(copy_checked_ss(dest,src));} +FSTRING_LINK b32 copy_checked(char *dest, i32 dest_cap, String src){return(copy_checked_cs(dest,dest_cap,src));} +FSTRING_LINK b32 copy_partial(String *dest, char *src){return(copy_partial_sc(dest,src));} +FSTRING_LINK b32 copy_partial(String *dest, String src){return(copy_partial_ss(dest,src));} +FSTRING_LINK b32 copy_partial(char *dest, i32 dest_cap, String src){return(copy_partial_cs(dest,dest_cap,src));} +FSTRING_INLINE i32 copy(char *dest, char *src){return(copy_cc(dest,src));} FSTRING_INLINE void copy(String *dest, String src){return(copy_ss(dest,src));} FSTRING_INLINE void copy(String *dest, char *src){return(copy_sc(dest,src));} -FSTRING_LINK b32_4tech append_checked(String *dest, String src){return(append_checked_ss(dest,src));} -FSTRING_LINK b32_4tech append_partial(String *dest, char *src){return(append_partial_sc(dest,src));} -FSTRING_LINK b32_4tech append_partial(String *dest, String src){return(append_partial_ss(dest,src));} -FSTRING_LINK b32_4tech append(String *dest, char c){return(append_s_char(dest,c));} -FSTRING_INLINE b32_4tech append(String *dest, String src){return(append_ss(dest,src));} -FSTRING_INLINE b32_4tech append(String *dest, char *src){return(append_sc(dest,src));} +FSTRING_LINK b32 append_checked(String *dest, String src){return(append_checked_ss(dest,src));} +FSTRING_LINK b32 append_partial(String *dest, char *src){return(append_partial_sc(dest,src));} +FSTRING_LINK b32 append_partial(String *dest, String src){return(append_partial_ss(dest,src));} +FSTRING_LINK b32 append(String *dest, char c){return(append_s_char(dest,c));} +FSTRING_INLINE b32 append(String *dest, String src){return(append_ss(dest,src));} +FSTRING_INLINE b32 append(String *dest, char *src){return(append_sc(dest,src));} FSTRING_LINK void replace_str(String *str, String replace, String with){return(replace_str_ss(str,replace,with));} FSTRING_LINK void replace_str(String *str, String replace, char *with){return(replace_str_sc(str,replace,with));} FSTRING_LINK void replace_str(String *str, char *replace, String with){return(replace_str_cs(str,replace,with));} @@ -289,14 +267,14 @@ FSTRING_LINK void to_upper(char *src, char *dst){return(to_uppe FSTRING_LINK void to_upper(String *dst, String src){return(to_upper_ss(dst,src));} FSTRING_LINK void to_upper(String *str){return(to_upper_s(str));} FSTRING_LINK void to_camel(char *src, char *dst){return(to_camel_cc(src,dst));} -FSTRING_LINK i32_4tech str_is_int(char *str){return(str_is_int_c(str));} -FSTRING_LINK b32_4tech str_is_int(String str){return(str_is_int_s(str));} -FSTRING_LINK i32_4tech str_to_int(char *str){return(str_to_int_c(str));} -FSTRING_LINK i32_4tech str_to_int(String str){return(str_to_int_s(str));} -FSTRING_LINK i32_4tech reverse_seek_slash(String str, i32_4tech pos){return(reverse_seek_slash_pos(str,pos));} -FSTRING_LINK b32_4tech set_last_folder(String *dir, char *folder_name, char slash){return(set_last_folder_sc(dir,folder_name,slash));} -FSTRING_LINK b32_4tech set_last_folder(String *dir, String folder_name, char slash){return(set_last_folder_ss(dir,folder_name,slash));} -FSTRING_LINK b32_4tech string_set_match(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index){return(string_set_match_table(str_set,item_size,count,str,match_index));} +FSTRING_LINK i32 str_is_int(char *str){return(str_is_int_c(str));} +FSTRING_LINK b32 str_is_int(String str){return(str_is_int_s(str));} +FSTRING_LINK i32 str_to_int(char *str){return(str_to_int_c(str));} +FSTRING_LINK i32 str_to_int(String str){return(str_to_int_s(str));} +FSTRING_LINK i32 reverse_seek_slash(String str, i32 pos){return(reverse_seek_slash_pos(str,pos));} +FSTRING_LINK b32 set_last_folder(String *dir, char *folder_name, char slash){return(set_last_folder_sc(dir,folder_name,slash));} +FSTRING_LINK b32 set_last_folder(String *dir, String folder_name, char slash){return(set_last_folder_ss(dir,folder_name,slash));} +FSTRING_LINK b32 string_set_match(void *str_set, i32 item_size, i32 count, String str, i32 *match_index){return(string_set_match_table(str_set,item_size,count,str,match_index));} #endif @@ -306,7 +284,7 @@ FSTRING_LINK b32_4tech string_set_match(void *str_set, i32_4tech ite // #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 char_is_slash(char c) { return (c == '\\' || c == '/'); @@ -314,7 +292,7 @@ char_is_slash(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 char_is_upper(char c) { return (c >= 'A' && c <= 'Z'); @@ -322,7 +300,7 @@ char_is_upper(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 char_is_upper_utf8(char c) { return ((c >= 'A' && c <= 'Z') || (unsigned char)c >= 128); @@ -330,7 +308,7 @@ char_is_upper_utf8(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 char_is_lower(char c) { return (c >= 'a' && c <= 'z'); @@ -338,8 +316,8 @@ char_is_lower(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech -char_is_lower_utf8(u8_4tech c) +FSTRING_INLINE b32 +char_is_lower_utf8(u8 c) { return ((c >= 'a' && c <= 'z') || (unsigned char)c >= 128); } @@ -362,7 +340,7 @@ char_to_lower(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 char_is_whitespace(char c) { return (c == ' ' || c == '\n' || c == '\r' || c == '\t'); @@ -370,7 +348,7 @@ char_is_whitespace(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 char_is_alpha_numeric(char c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'); @@ -378,15 +356,15 @@ char_is_alpha_numeric(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech -char_is_alpha_numeric_utf8(u8_4tech c) +FSTRING_INLINE b32 +char_is_alpha_numeric_utf8(u8 c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || (unsigned char)c >= 128); } #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 char_is_alpha_numeric_true(char c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')); @@ -394,15 +372,15 @@ char_is_alpha_numeric_true(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech -char_is_alpha_numeric_true_utf8(u8_4tech c) +FSTRING_INLINE b32 +char_is_alpha_numeric_true_utf8(u8 c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (unsigned char)c >= 128); } #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 char_is_alpha(char c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'); @@ -410,15 +388,15 @@ char_is_alpha(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech -char_is_alpha_utf8(u8_4tech c) +FSTRING_INLINE b32 +char_is_alpha_utf8(u8 c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (unsigned char)c >= 128); } #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 char_is_alpha_true(char c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); @@ -426,15 +404,15 @@ char_is_alpha_true(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech -char_is_alpha_true_utf8(u8_4tech c) +FSTRING_INLINE b32 +char_is_alpha_true_utf8(u8 c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (unsigned char)c >= 128); } #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 char_is_hex(char c) { return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); @@ -442,15 +420,15 @@ char_is_hex(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech -char_is_hex_utf8(u8_4tech c) +FSTRING_INLINE b32 +char_is_hex_utf8(u8 c) { return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (unsigned char)c >= 128); } #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 char_is_numeric(char c) { return (c >= '0' && c <= '9'); @@ -458,8 +436,8 @@ char_is_numeric(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech -char_is_numeric_utf8(u8_4tech c) +FSTRING_INLINE b32 +char_is_numeric_utf8(u8 c) { return ((c >= '0' && c <= '9') || (unsigned char)c >= 128); } @@ -473,7 +451,7 @@ char_is_numeric_utf8(u8_4tech c) #if !defined(FSTRING_GUARD) FSTRING_INLINE String -make_string_cap(void *str, i32_4tech size, i32_4tech mem_size){ +make_string_cap(void *str, i32 size, i32 mem_size){ String result; result.str = (char*)str; result.size = size; @@ -484,16 +462,16 @@ make_string_cap(void *str, i32_4tech size, i32_4tech mem_size){ #if !defined(FSTRING_GUARD) FSTRING_INLINE String -make_string(void *str, i32_4tech size){ +make_string(void *str, i32 size){ return(make_string(str, size, size)); } #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech +FSTRING_LINK i32 str_size(char *str) { - i32_4tech i = 0; + i32 i = 0; if (str != 0){ for (;str[i];++i); } @@ -516,7 +494,7 @@ make_string_slowly(void *str) #if !defined(FSTRING_GUARD) FSTRING_INLINE String -substr_tail(String str, i32_4tech start) +substr_tail(String str, i32 start) { String result; result.str = str.str + start; @@ -528,7 +506,7 @@ substr_tail(String str, i32_4tech start) #if !defined(FSTRING_GUARD) FSTRING_INLINE String -substr(String str, i32_4tech start, i32_4tech size) +substr(String str, i32 start, i32 size) { String result; result.str = str.str + start; @@ -546,7 +524,7 @@ FSTRING_LINK String skip_whitespace(String str) { String result = {}; - i32_4tech i = 0; + i32 i = 0; for (; i < str.size && char_is_whitespace(str.str[i]); ++i); result = substr(str, i, str.size - i); return(result); @@ -556,10 +534,10 @@ skip_whitespace(String str) #if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK String -skip_whitespace_measure(String str, i32_4tech *skip_length) +skip_whitespace_measure(String str, i32 *skip_length) { String result = {}; - i32_4tech i = 0; + i32 i = 0; for (; i < str.size && char_is_whitespace(str.str[i]); ++i); result = substr(str, i, str.size - i); *skip_length = i; @@ -572,7 +550,7 @@ FSTRING_LINK String chop_whitespace(String str) { String result = {}; - i32_4tech i = str.size; + i32 i = str.size; for (; i > 0 && char_is_whitespace(str.str[i-1]); --i); result = substr(str, 0, i); return(result); @@ -592,7 +570,7 @@ skip_chop_whitespace(String str) #if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK String -skip_chop_whitespace_measure(String str, i32_4tech *skip_length) +skip_chop_whitespace_measure(String str, i32 *skip_length) { str = skip_whitespace_measure(str, skip_length); str = chop_whitespace(str); @@ -619,9 +597,9 @@ tailstr(String str) #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 match_cc(char *a, char *b){ - for (i32_4tech i = 0;; ++i){ + for (i32 i = 0;; ++i){ if (a[i] != b[i]){ return 0; } @@ -634,9 +612,9 @@ match_cc(char *a, char *b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 match_sc(String a, char *b){ - i32_4tech i = 0; + i32 i = 0; for (; i < a.size; ++i){ if (a.str[i] != b[i]){ return 0; @@ -651,7 +629,7 @@ match_sc(String a, char *b){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 match_cs(char *a, String b){ return(match_sc(b,a)); } @@ -659,12 +637,12 @@ match_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 match_ss(String a, String b){ if (a.size != b.size){ return 0; } - for (i32_4tech i = 0; i < b.size; ++i){ + for (i32 i = 0; i < b.size; ++i){ if (a.str[i] != b.str[i]){ return 0; } @@ -675,8 +653,8 @@ match_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech -match_part_ccl(char *a, char *b, i32_4tech *len){ +FSTRING_LINK b32 +match_part_ccl(char *a, char *b, i32 *len){ if (a == 0){ a = ""; } @@ -684,7 +662,7 @@ match_part_ccl(char *a, char *b, i32_4tech *len){ b = ""; } - i32_4tech i; + i32 i; for (i = 0; b[i] != 0; ++i){ if (a[i] != b[i]){ return(0); @@ -697,12 +675,12 @@ match_part_ccl(char *a, char *b, i32_4tech *len){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech -match_part_scl(String a, char *b, i32_4tech *len){ +FSTRING_LINK b32 +match_part_scl(String a, char *b, i32 *len){ if (b == 0){ b = ""; } - i32_4tech i; + i32 i; for (i = 0; b[i] != 0; ++i){ if (i == a.size || a.str[i] != b[i]){ return(0); @@ -715,27 +693,27 @@ match_part_scl(String a, char *b, i32_4tech *len){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 match_part_cc(char *a, char *b){ - i32_4tech x; + i32 x; return match_part_ccl(a,b,&x); } #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 match_part_sc(String a, char *b){ - i32_4tech x; + i32 x; return match_part_scl(a,b,&x); } #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 match_part_cs(char *a, String b){ - for (i32_4tech i = 0; i != b.size; ++i){ + for (i32 i = 0; i != b.size; ++i){ if (a[i] != b.str[i]){ return 0; } @@ -746,12 +724,12 @@ match_part_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 match_part_ss(String a, String b){ if (a.size < b.size){ return(0); } - for (i32_4tech i = 0; i < b.size; ++i){ + for (i32 i = 0; i < b.size; ++i){ if (a.str[i] != b.str[i]){ return(0); } @@ -762,9 +740,9 @@ match_part_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 match_insensitive_cc(char *a, char *b){ - for (i32_4tech i = 0;; ++i){ + for (i32 i = 0;; ++i){ if (char_to_upper(a[i]) != char_to_upper(b[i])){ return 0; @@ -778,9 +756,9 @@ match_insensitive_cc(char *a, char *b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 match_insensitive_sc(String a, char *b){ - i32_4tech i = 0; + i32 i = 0; for (; i < a.size; ++i){ if (char_to_upper(a.str[i]) != char_to_upper(b[i])){ @@ -796,7 +774,7 @@ match_insensitive_sc(String a, char *b){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 match_insensitive_cs(char *a, String b){ return match_insensitive_sc(b,a); } @@ -804,12 +782,12 @@ match_insensitive_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 match_insensitive_ss(String a, String b){ if (a.size != b.size){ return 0; } - for (i32_4tech i = 0; i < b.size; ++i){ + for (i32 i = 0; i < b.size; ++i){ if (char_to_upper(a.str[i]) != char_to_upper(b.str[i])){ return 0; @@ -821,9 +799,9 @@ match_insensitive_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech -match_part_insensitive_ccl(char *a, char *b, i32_4tech *len){ - i32_4tech i; +FSTRING_LINK b32 +match_part_insensitive_ccl(char *a, char *b, i32 *len){ + i32 i; for (i = 0; b[i] != 0; ++i){ if (char_to_upper(a[i]) != char_to_upper(b[i])){ return 0; @@ -836,9 +814,9 @@ match_part_insensitive_ccl(char *a, char *b, i32_4tech *len){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech -match_part_insensitive_scl(String a, char *b, i32_4tech *len){ - i32_4tech i; +FSTRING_LINK b32 +match_part_insensitive_scl(String a, char *b, i32 *len){ + i32 i; for (i = 0; b[i] != 0; ++i){ if (char_to_upper(a.str[i]) != char_to_upper(b[i]) || i == a.size){ @@ -852,27 +830,27 @@ match_part_insensitive_scl(String a, char *b, i32_4tech *len){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 match_part_insensitive_cc(char *a, char *b){ - i32_4tech x; + i32 x; return match_part_insensitive_ccl(a,b,&x); } #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 match_part_insensitive_sc(String a, char *b){ - i32_4tech x; + i32 x; return match_part_insensitive_scl(a,b,&x); } #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 match_part_insensitive_cs(char *a, String b){ - for (i32_4tech i = 0; i != b.size; ++i){ + for (i32 i = 0; i != b.size; ++i){ if (char_to_upper(a[i]) != char_to_upper(b.str[i])){ return(0); } @@ -883,12 +861,12 @@ match_part_insensitive_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 match_part_insensitive_ss(String a, String b){ if (a.size < b.size){ return(0); } - for (i32_4tech i = 0; i < b.size; ++i){ + for (i32 i = 0; i < b.size; ++i){ if (char_to_upper(a.str[i]) != char_to_upper(b.str[i])){ return(0); } @@ -899,9 +877,9 @@ match_part_insensitive_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech +FSTRING_LINK i32 compare_cc(char *a, char *b){ - i32_4tech i = 0, r = 0; + i32 i = 0, r = 0; while (a[i] == b[i] && a[i] != 0){ ++i; } @@ -912,9 +890,9 @@ compare_cc(char *a, char *b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech +FSTRING_LINK i32 compare_sc(String a, char *b){ - i32_4tech i = 0, r = 0; + i32 i = 0, r = 0; while (i < a.size && a.str[i] == b[i]){ ++i; } @@ -935,19 +913,19 @@ compare_sc(String a, char *b){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE i32_4tech +FSTRING_INLINE i32 compare_cs(char *a, String b){ - i32_4tech r = -compare_sc(b,a); + i32 r = -compare_sc(b,a); return(r); } #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech +FSTRING_LINK i32 compare_ss(String a, String b){ - i32_4tech i = 0, r = 0; - i32_4tech m = a.size; + i32 i = 0, r = 0; + i32 m = a.size; if (b.size < m){ m = b.size; } @@ -972,9 +950,9 @@ compare_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech -find_c_char(char *str, i32_4tech start, char character){ - i32_4tech i = start; +FSTRING_LINK i32 +find_c_char(char *str, i32 start, char character){ + i32 i = start; while (str[i] != character && str[i] != 0) ++i; return(i); } @@ -982,9 +960,9 @@ find_c_char(char *str, i32_4tech start, char character){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech -find_s_char(String str, i32_4tech start, char character){ - i32_4tech i = start; +FSTRING_LINK i32 +find_s_char(String str, i32 start, char character){ + i32 i = start; while (i < str.size && str.str[i] != character) ++i; return(i); } @@ -992,9 +970,9 @@ find_s_char(String str, i32_4tech start, char character){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech -rfind_s_char(String str, i32_4tech start, char character){ - i32_4tech i = start; +FSTRING_LINK i32 +rfind_s_char(String str, i32 start, char character){ + i32 i = start; while (i >= 0 && str.str[i] != character) --i; return(i); } @@ -1002,9 +980,9 @@ rfind_s_char(String str, i32_4tech start, char character){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech -find_c_chars(char *str, i32_4tech start, char *characters){ - i32_4tech i = start, j; +FSTRING_LINK i32 +find_c_chars(char *str, i32 start, char *characters){ + i32 i = start, j; while (str[i] != 0){ for (j = 0; characters[j]; ++j){ if (str[i] == characters[j]){ @@ -1019,9 +997,9 @@ find_c_chars(char *str, i32_4tech start, char *characters){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech -find_s_chars(String str, i32_4tech start, char *characters){ - i32_4tech i = start, j; +FSTRING_LINK i32 +find_s_chars(String str, i32 start, char *characters){ + i32 i = start, j; while (i < str.size){ for (j = 0; characters[j]; ++j){ if (str.str[i] == characters[j]){ @@ -1036,10 +1014,10 @@ find_s_chars(String str, i32_4tech start, char *characters){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech -find_substr_c(char *str, i32_4tech start, String seek){ - i32_4tech i, j, k; - b32_4tech hit; +FSTRING_LINK i32 +find_substr_c(char *str, i32 start, String seek){ + i32 i, j, k; + b32 hit; if (seek.size == 0){ i = str_size(str); @@ -1065,10 +1043,10 @@ find_substr_c(char *str, i32_4tech start, String seek){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech -find_substr_s(String str, i32_4tech start, String seek){ - i32_4tech stop_at, i, j, k; - b32_4tech hit; +FSTRING_LINK i32 +find_substr_s(String str, i32 start, String seek){ + i32 stop_at, i, j, k; + b32 hit; if (seek.size == 0){ return str.size; @@ -1094,10 +1072,10 @@ find_substr_s(String str, i32_4tech start, String seek){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech -rfind_substr_s(String str, i32_4tech start, String seek){ - i32_4tech i, j, k; - b32_4tech hit; +FSTRING_LINK i32 +rfind_substr_s(String str, i32 start, String seek){ + i32 i, j, k; + b32 hit; if (seek.size == 0){ return -1; @@ -1125,10 +1103,10 @@ rfind_substr_s(String str, i32_4tech start, String seek){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech -find_substr_insensitive_c(char *str, i32_4tech start, String seek){ - i32_4tech i, j, k; - b32_4tech hit; +FSTRING_LINK i32 +find_substr_insensitive_c(char *str, i32 start, String seek){ + i32 i, j, k; + b32 hit; char a_upper, b_upper; char first_test_char; @@ -1159,11 +1137,11 @@ find_substr_insensitive_c(char *str, i32_4tech start, String seek){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech -find_substr_insensitive_s(String str, i32_4tech start, String seek){ - i32_4tech i, j, k; - i32_4tech stop_at; - b32_4tech hit; +FSTRING_LINK i32 +find_substr_insensitive_s(String str, i32 start, String seek){ + i32 i, j, k; + i32 stop_at; + b32 hit; char a_upper, b_upper; char first_test_char; @@ -1195,7 +1173,7 @@ find_substr_insensitive_s(String str, i32_4tech start, String seek){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 has_substr_c(char *s, String seek){ return (s[find_substr_c(s, 0, seek)] != 0); } @@ -1203,7 +1181,7 @@ has_substr_c(char *s, String seek){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 has_substr_s(String s, String seek){ return (find_substr_s(s, 0, seek) < s.size); } @@ -1211,7 +1189,7 @@ has_substr_s(String s, String seek){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 has_substr_insensitive_c(char *s, String seek){ return (s[find_substr_insensitive_c(s, 0, seek)] != 0); } @@ -1219,7 +1197,7 @@ has_substr_insensitive_c(char *s, String seek){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 has_substr_insensitive_s(String s, String seek){ return (find_substr_insensitive_s(s, 0, seek) < s.size); } @@ -1231,7 +1209,7 @@ has_substr_insensitive_s(String s, String seek){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech +FSTRING_LINK i32 copy_fast_unsafe_cc(char *dest, char *src){ char *start = dest; while (*src != 0){ @@ -1239,15 +1217,15 @@ copy_fast_unsafe_cc(char *dest, char *src){ ++dest; ++src; } - return (i32_4tech)(dest - start); + return (i32)(dest - start); } #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech +FSTRING_LINK i32 copy_fast_unsafe_cs(char *dest, String src){ - i32_4tech i = 0; + i32 i = 0; while (i != src.size){ dest[i] = src.str[i]; ++i; @@ -1258,10 +1236,10 @@ copy_fast_unsafe_cs(char *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 copy_checked_ss(String *dest, String src){ char *dest_str; - i32_4tech i; + i32 i; if (dest->memory_size < src.size){ return 0; } @@ -1276,9 +1254,9 @@ copy_checked_ss(String *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech -copy_checked_cs(char *dest, i32_4tech dest_cap, String src){ - i32_4tech i; +FSTRING_LINK b32 +copy_checked_cs(char *dest, i32 dest_cap, String src){ + i32 i; if (dest_cap < src.size){ return 0; } @@ -1291,10 +1269,10 @@ copy_checked_cs(char *dest, i32_4tech dest_cap, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 copy_partial_sc(String *dest, char *src){ - i32_4tech i = 0; - i32_4tech memory_size = dest->memory_size; + i32 i = 0; + i32 memory_size = dest->memory_size; char *dest_str = dest->str; while (src[i] != 0){ if (i >= memory_size){ @@ -1310,16 +1288,16 @@ copy_partial_sc(String *dest, char *src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 copy_partial_ss(String *dest, String src){ char *dest_str = dest->str; - i32_4tech memory_size = dest->memory_size; - b32_4tech result = 0; + i32 memory_size = dest->memory_size; + b32 result = 0; if (memory_size >= src.size){ result = 1; memory_size = src.size; } - for (i32_4tech i = 0; i < memory_size; ++i){ + for (i32 i = 0; i < memory_size; ++i){ dest_str[i] = src.str[i]; } dest->size = memory_size; @@ -1329,11 +1307,11 @@ copy_partial_ss(String *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech -copy_partial_cs(char *dest, i32_4tech dest_cap, String src){ - b32_4tech result = 0; - i32_4tech copy_size = dest_cap; - i32_4tech i; +FSTRING_LINK b32 +copy_partial_cs(char *dest, i32 dest_cap, String src){ + b32 result = 0; + i32 copy_size = dest_cap; + i32 i; if (dest_cap >= src.size){ result = 1; copy_size = src.size; @@ -1347,7 +1325,7 @@ copy_partial_cs(char *dest, i32_4tech dest_cap, String src){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE i32_4tech +FSTRING_INLINE i32 copy_cc(char *dest, char *src){ return copy_fast_unsafe_cc(dest, src); } @@ -1371,11 +1349,11 @@ copy_sc(String *dest, char *src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 append_checked_ss(String *dest, String src){ String end; end = tailstr(*dest); - b32_4tech result = copy_checked_ss(&end, src); + b32 result = copy_checked_ss(&end, src); // NOTE(allen): This depends on end.size still being 0 if // the check failed and no coppy occurred. dest->size += end.size; @@ -1385,10 +1363,10 @@ append_checked_ss(String *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 append_partial_sc(String *dest, char *src){ String end = tailstr(*dest); - b32_4tech result = copy_partial_sc(&end, src); + b32 result = copy_partial_sc(&end, src); dest->size += end.size; return result; } @@ -1396,10 +1374,10 @@ append_partial_sc(String *dest, char *src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 append_partial_ss(String *dest, String src){ String end = tailstr(*dest); - b32_4tech result = copy_partial_ss(&end, src); + b32 result = copy_partial_ss(&end, src); dest->size += end.size; return result; } @@ -1407,9 +1385,9 @@ append_partial_ss(String *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 append_s_char(String *dest, char c){ - b32_4tech result = 0; + b32 result = 0; if (dest->size < dest->memory_size){ dest->str[dest->size++] = c; result = 1; @@ -1420,7 +1398,7 @@ append_s_char(String *dest, char c){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 append_ss(String *dest, String src){ return append_partial_ss(dest, src); } @@ -1428,16 +1406,16 @@ append_ss(String *dest, String src){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech +FSTRING_INLINE b32 append_sc(String *dest, char *src){ return append_partial_sc(dest, src); } #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 terminate_with_null(String *str){ - b32_4tech result = 0; + b32 result = 0; if (str->size < str->memory_size){ str->str[str->size] = 0; result = 1; @@ -1447,11 +1425,11 @@ terminate_with_null(String *str){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech -append_padding(String *dest, char c, i32_4tech target_size){ - b32_4tech result = 1; - i32_4tech offset = target_size - dest->size; - i32_4tech r = 0; +FSTRING_LINK b32 +append_padding(String *dest, char c, i32 target_size){ + b32 result = 1; + i32 offset = target_size - dest->size; + i32 r = 0; if (offset > 0){ for (r = 0; r < offset; ++r){ if (append_s_char(dest, c) == 0){ @@ -1473,9 +1451,9 @@ append_padding(String *dest, char c, i32_4tech target_size){ FSTRING_LINK void string_interpret_escapes(String src, char *dst) { - i32_4tech mode = 0; - i32_4tech j = 0; - for (i32_4tech i = 0; i < src.size; ++i){ + i32 mode = 0; + i32 j = 0; + for (i32 i = 0; i < src.size; ++i){ switch (mode){ case 0: { @@ -1510,7 +1488,7 @@ string_interpret_escapes(String src, char *dst) FSTRING_LINK void replace_char(String *str, char replace, char with){ char *s = str->str; - i32_4tech i = 0; + i32 i = 0; for (i = 0; i < str->size; ++i, ++s){ if (*s == replace) *s = with; } @@ -1519,27 +1497,27 @@ replace_char(String *str, char replace, char with){ #if !defined(FSTRING_GUARD) void -block_move(void *a_ptr, void *b_ptr, i32_4tech s){ - u8_4tech *a = (u8_4tech*)a_ptr; - u8_4tech *b = (u8_4tech*)b_ptr; +block_move(void *a_ptr, void *b_ptr, i32 s){ + u8 *a = (u8*)a_ptr; + u8 *b = (u8*)b_ptr; if (a < b){ - for (i32_4tech i = 0; i < s; ++i, ++a, ++b){ + for (i32 i = 0; i < s; ++i, ++a, ++b){ *a = *b; } } else if (a > b){ a = a + s - 1; b = b + s - 1; - for (i32_4tech i = 0; i < s; ++i, --a, --b){ + for (i32 i = 0; i < s; ++i, --a, --b){ *a = *b; } } } void -replace_range_str(String *str, i32_4tech first, i32_4tech one_past_last, String with){ - i32_4tech shift = with.size - (one_past_last - first); - i32_4tech new_size = str->size + shift; +replace_range_str(String *str, i32 first, i32 one_past_last, String with){ + i32 shift = with.size - (one_past_last - first); + i32 new_size = str->size + shift; if (new_size <= str->memory_size){ if (shift != 0){ char *tail = str->str + one_past_last; @@ -1556,7 +1534,7 @@ replace_range_str(String *str, i32_4tech first, i32_4tech one_past_last, String #if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK void replace_str_ss(String *str, String replace, String with){ - i32_4tech i = 0; + i32 i = 0; for (;;){ i = find_substr_s(*str, i, replace); if (i >= str->size){ @@ -1611,8 +1589,8 @@ to_lower_cc(char *src, char *dst){ #if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK void to_lower_ss(String *dst, String src){ - i32_4tech i = 0; - i32_4tech size = src.size; + i32 i = 0; + i32 size = src.size; char *c = src.str; char *d = dst->str; @@ -1629,8 +1607,8 @@ to_lower_ss(String *dst, String src){ #if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK void to_lower_s(String *str){ - i32_4tech i = 0; - i32_4tech size = str->size; + i32 i = 0; + i32 size = str->size; char *c = str->str; for (; i < size; ++c, ++i){ *c = char_to_lower(*c); @@ -1653,8 +1631,8 @@ to_upper_cc(char *src, char *dst){ #if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK void to_upper_ss(String *dst, String src){ - i32_4tech i = 0; - i32_4tech size = src.size; + i32 i = 0; + i32 size = src.size; char *c = src.str; char *d = dst->str; @@ -1671,8 +1649,8 @@ to_upper_ss(String *dst, String src){ #if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK void to_upper_s(String *str){ - i32_4tech i = 0; - i32_4tech size = str->size; + i32 i = 0; + i32 size = str->size; char *c = str->str; for (; i < size; ++c, ++i){ *c = char_to_upper(*c); @@ -1685,7 +1663,7 @@ to_upper_s(String *str){ FSTRING_LINK void to_camel_cc(char *src, char *dst){ char *c, ch; - i32_4tech is_first = 1; + i32 is_first = 1; for (c = src; *c != 0; ++c){ ch = *c; if (char_is_alpha_numeric_true(ch)){ @@ -1712,9 +1690,9 @@ to_camel_cc(char *src, char *dst){ // #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech -int_to_str_size(i32_4tech x){ - i32_4tech size = 1; +FSTRING_LINK i32 +int_to_str_size(i32 x){ + i32 size = 1; if (x < 0){ size = 2; } @@ -1728,13 +1706,13 @@ int_to_str_size(i32_4tech x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech -int_to_str(String *dest, i32_4tech x){ - b32_4tech result = 1; +FSTRING_LINK b32 +int_to_str(String *dest, i32 x){ + b32 result = 1; char *str = dest->str; - i32_4tech memory_size = dest->memory_size; - i32_4tech size, i, j; - b32_4tech negative; + i32 memory_size = dest->memory_size; + i32 size, i, j; + b32 negative; if (x == 0){ str[0] = '0'; @@ -1775,10 +1753,10 @@ int_to_str(String *dest, i32_4tech x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech -append_int_to_str(String *dest, i32_4tech x){ +FSTRING_LINK b32 +append_int_to_str(String *dest, i32 x){ String last_part = tailstr(*dest); - b32_4tech result = int_to_str(&last_part, x); + b32 result = int_to_str(&last_part, x); if (result){ dest->size += last_part.size; } @@ -1787,9 +1765,9 @@ append_int_to_str(String *dest, i32_4tech x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech +FSTRING_LINK i32 u64_to_str_size(uint64_t x){ - i32_4tech size = 1; + i32 size = 1; x /= 10; while (x != 0){ x /= 10; @@ -1800,12 +1778,12 @@ u64_to_str_size(uint64_t x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 u64_to_str(String *dest, uint64_t x){ - b32_4tech result = 1; + b32 result = 1; char *str = dest->str; - i32_4tech memory_size = dest->memory_size; - i32_4tech size, i, j; + i32 memory_size = dest->memory_size; + i32 size, i, j; if (x == 0){ str[0] = '0'; @@ -1839,10 +1817,10 @@ u64_to_str(String *dest, uint64_t x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 append_u64_to_str(String *dest, uint64_t x){ String last_part = tailstr(*dest); - b32_4tech result = u64_to_str(&last_part, x); + b32 result = u64_to_str(&last_part, x); if (result){ dest->size += last_part.size; } @@ -1852,9 +1830,9 @@ append_u64_to_str(String *dest, uint64_t x){ #if !defined(FSTRING_GUARD) typedef struct Float_To_Str_Variables{ - b32_4tech negative; - i32_4tech int_part; - i32_4tech dec_part; + b32 negative; + i32 int_part; + i32 dec_part; } Float_To_Str_Variables; static Float_To_Str_Variables @@ -1866,26 +1844,26 @@ get_float_vars(float x){ x = -x; } - vars.int_part = (i32_4tech)(x); - vars.dec_part = (i32_4tech)((x - vars.int_part) * 1000); + vars.int_part = (i32)(x); + vars.dec_part = (i32)((x - vars.int_part) * 1000); return(vars); } #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech +FSTRING_LINK i32 float_to_str_size(float x){ Float_To_Str_Variables vars = get_float_vars(x); - i32_4tech size = vars.negative + int_to_str_size(vars.int_part) + 1 + int_to_str_size(vars.dec_part); + i32 size = vars.negative + int_to_str_size(vars.int_part) + 1 + int_to_str_size(vars.dec_part); return(size); } #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 append_float_to_str(String *dest, float x){ - b32_4tech result = 1; + b32 result = 1; Float_To_Str_Variables vars = get_float_vars(x); if (vars.negative){ @@ -1901,9 +1879,9 @@ append_float_to_str(String *dest, float x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 float_to_str(String *dest, float x){ - b32_4tech result = 1; + b32 result = 1; dest->size = 0; append_float_to_str(dest, x); return(result); @@ -1912,9 +1890,9 @@ float_to_str(String *dest, float x){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech +FSTRING_LINK i32 str_is_int_c(char *str){ - b32_4tech result = 1; + b32 result = 1; for (; *str; ++str){ if (!char_is_numeric(*str)){ result = 0; @@ -1927,10 +1905,10 @@ str_is_int_c(char *str){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 str_is_int_s(String str){ - b32_4tech result = 1; - for (i32_4tech i = 0; i < str.size; ++i){ + b32 result = 1; + for (i32 i = 0; i < str.size; ++i){ if (!char_is_numeric(str.str[i])){ result = 0; break; @@ -1942,9 +1920,9 @@ str_is_int_s(String str){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech +FSTRING_LINK i32 str_to_int_c(char *str){ - i32_4tech x = 0; + i32 x = 0; for (; *str; ++str){ if (*str >= '0' && *str <= '9'){ x *= 10; @@ -1961,9 +1939,9 @@ str_to_int_c(char *str){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech +FSTRING_LINK i32 str_to_int_s(String str){ - i32_4tech x, i; + i32 x, i; if (str.size == 0){ x = 0; } @@ -1979,9 +1957,9 @@ str_to_int_s(String str){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech +FSTRING_LINK i32 hexchar_to_int(char c){ - i32_4tech x = 0; + i32 x = 0; if (c >= '0' && c <= '9'){ x = c-'0'; } @@ -1997,16 +1975,16 @@ hexchar_to_int(char c){ #if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK char -int_to_hexchar(i32_4tech x){ +int_to_hexchar(i32 x){ return (x<10)?((char)x+'0'):((char)x+'a'-10); } #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK u32_4tech +FSTRING_LINK u32 hexstr_to_int(String str){ - u32_4tech x; - i32_4tech i; + u32 x; + i32 i; if (str.size == 0){ x = 0; } @@ -2022,10 +2000,10 @@ hexstr_to_int(String str){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech -color_to_hexstr(String *s, u32_4tech color){ - b32_4tech result = 0; - i32_4tech i; +FSTRING_LINK b32 +color_to_hexstr(String *s, u32 color){ + b32 result = 0; + i32 i; if (s->memory_size == 7 || s->memory_size == 8){ result = 1; @@ -2051,19 +2029,19 @@ color_to_hexstr(String *s, u32_4tech color){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech -hexstr_to_color(String s, u32_4tech *out){ - b32_4tech result = 0; - u32_4tech color = 0; +FSTRING_LINK b32 +hexstr_to_color(String s, u32 *out){ + b32 result = 0; + u32 color = 0; if (s.size == 6){ result = 1; - color = (u32_4tech)hexstr_to_int(s); + color = (u32)hexstr_to_int(s); color |= (0xFF << 24); *out = color; } else if (s.size == 8){ result = 1; - color = (u32_4tech)hexstr_to_int(s); + color = (u32)hexstr_to_int(s); *out = color; } return(result); @@ -2076,9 +2054,9 @@ hexstr_to_color(String s, u32_4tech *out){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech -reverse_seek_slash_pos(String str, i32_4tech pos){ - i32_4tech i = str.size - 1 - pos; +FSTRING_LINK i32 +reverse_seek_slash_pos(String str, i32 pos){ + i32 i = str.size - 1 - pos; while (i >= 0 && !char_is_slash(str.str[i])){ --i; } @@ -2087,7 +2065,7 @@ reverse_seek_slash_pos(String str, i32_4tech pos){ #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE i32_4tech +FSTRING_INLINE i32 reverse_seek_slash(String str){ return(reverse_seek_slash_pos(str, 0)); } @@ -2109,10 +2087,10 @@ path_of_directory(String dir){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 set_last_folder_sc(String *dir, char *folder_name, char slash){ - b32_4tech result = 0; - i32_4tech size = reverse_seek_slash(*dir) + 1; + b32 result = 0; + i32 size = reverse_seek_slash(*dir) + 1; dir->size = size; if (append_sc(dir, folder_name)){ if (append_s_char(dir, slash)){ @@ -2128,10 +2106,10 @@ set_last_folder_sc(String *dir, char *folder_name, char slash){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 set_last_folder_ss(String *dir, String folder_name, char slash){ - b32_4tech result = 0; - i32_4tech size = reverse_seek_slash(*dir) + 1; + b32 result = 0; + i32 size = reverse_seek_slash(*dir) + 1; dir->size = size; if (append_ss(dir, folder_name)){ if (append_s_char(dir, slash)){ @@ -2148,7 +2126,7 @@ set_last_folder_ss(String *dir, String folder_name, char slash){ #if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK String file_extension(String str){ - i32_4tech i; + i32 i; for (i = str.size - 1; i >= 0; --i){ if (str.str[i] == '.') break; } @@ -2158,10 +2136,10 @@ file_extension(String str){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 remove_extension(String *str){ - b32_4tech result = 0; - i32_4tech i; + b32 result = 0; + i32 i; for (i = str->size - 1; i >= 0; --i){ if (str->str[i] == '.') break; } @@ -2174,10 +2152,10 @@ remove_extension(String *str){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech +FSTRING_LINK b32 remove_last_folder(String *str){ - b32_4tech result = 0; - i32_4tech end = reverse_seek_slash_pos(*str, 1); + b32 result = 0; + i32 end = reverse_seek_slash_pos(*str, 1); if (end >= 0){ result = 1; str->size = end + 1; @@ -2188,10 +2166,10 @@ remove_last_folder(String *str){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech -string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index){ - b32_4tech result = 0; - i32_4tech i = 0; +FSTRING_LINK b32 +string_set_match_table(void *str_set, i32 item_size, i32 count, String str, i32 *match_index){ + b32 result = 0; + i32 i = 0; uint8_t *ptr = (uint8_t*)str_set; for (; i < count; ++i, ptr += item_size){ if (match_ss(*(String*)ptr, str)){ @@ -2205,9 +2183,9 @@ string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, Stri #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech -string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_index){ - b32_4tech result = string_set_match_table(str_set, sizeof(String), count, str, match_index); +FSTRING_LINK b32 +string_set_match(String *str_set, i32 count, String str, i32 *match_index){ + b32 result = string_set_match_table(str_set, sizeof(String), count, str, match_index); return(result); } #endif @@ -2216,8 +2194,8 @@ string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_ FSTRING_LINK String get_first_double_line(String source){ String line = {}; - i32_4tech pos0 = find_substr_s(source, 0, make_lit_string("\n\n")); - i32_4tech pos1 = find_substr_s(source, 0, make_lit_string("\r\n\r\n")); + i32 pos0 = find_substr_s(source, 0, make_lit_string("\n\n")); + i32 pos1 = find_substr_s(source, 0, make_lit_string("\r\n\r\n")); if (pos1 < pos0){ pos0 = pos1; } @@ -2230,8 +2208,8 @@ get_first_double_line(String source){ FSTRING_LINK String get_next_double_line(String source, String line){ String next = {}; - i32_4tech pos = (i32_4tech)(line.str - source.str) + line.size; - i32_4tech start = 0, pos0 = 0, pos1 = 0; + i32 pos = (i32)(line.str - source.str) + line.size; + i32 start = 0, pos0 = 0, pos1 = 0; if (pos < source.size){ //Assert(source.str[pos] == '\n' || source.str[pos] == '\r'); @@ -2256,8 +2234,8 @@ FSTRING_LINK String get_next_word(String source, String prev_word){ String word = {}; - i32_4tech pos0 = (i32_4tech)(prev_word.str - source.str) + prev_word.size; - i32_4tech pos1 = 0; + i32 pos0 = (i32)(prev_word.str - source.str) + prev_word.size; + i32 pos1 = 0; char c = 0; for (; pos0 < source.size; ++pos0){ @@ -2293,10 +2271,10 @@ get_first_word(String source){ #if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK String -string_push(Partition *part, i32_4tech size){ +string_push(Cursor *cursor, i32 size){ String result = {}; if (size > 0){ - result.str = push_array(part, char, size); + result.str = push_array(cursor, char, size); if (result.str != 0){ result.memory_size = size; } @@ -2307,10 +2285,10 @@ string_push(Partition *part, i32_4tech size){ #if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK String -string_push_copy(Partition *part, String str){ +string_push_copy(Cursor *cursor, String str){ String result = {}; if (str.str != 0){ - result.str = push_array(part, char, str.size + 1); + result.str = push_array(cursor, char, str.size + 1); if (result.str != 0){ result.memory_size = str.size + 1; copy(&result, str); @@ -2321,6 +2299,58 @@ string_push_copy(Partition *part, String str){ } #endif +#if defined(FSTRING_IMPLEMENTATION) +FSTRING_LINK String +string_push(Arena *arena, i32 size){ + String result = {}; + if (size > 0){ + result.str = push_array(arena, char, size); + if (result.str != 0){ + result.memory_size = size; + } + } + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) +FSTRING_LINK String +string_push_copy(Arena *arena, String str){ + String result = {}; + if (str.str != 0){ + result.str = push_array(arena, char, str.size + 1); + if (result.str != 0){ + result.memory_size = str.size + 1; + copy(&result, str); + result.str[result.size] = 0; + } + } + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) +FSTRING_LINK char* +get_null_terminated(Arena *arena, String str){ + char *str_terminated = 0; + if (str.size < str.memory_size){ + if (str.str[str.size] != 0){ + str.str[str.size] = 0; + } + str_terminated = str.str; + } + else{ + str_terminated = push_array(arena, char, str.size + 1); + if (str_terminated != 0){ + String builder = make_string_cap(str_terminated, 0, str.size + 1); + append(&builder, str); + str_terminated[str.size] = 0; + } + } + return(str_terminated); +} +#endif + // TODO(allen): eliminate this. #ifndef FSTRING_EXPERIMENTAL #define FSTRING_EXPERIMENTAL @@ -2330,28 +2360,28 @@ string_push_copy(Partition *part, String str){ typedef struct Absolutes{ String a[8]; - i32_4tech count; + i32 count; } Absolutes; static void -get_absolutes(String name, Absolutes *absolutes, b32_4tech implicit_first, b32_4tech implicit_last){ +get_absolutes(String name, Absolutes *absolutes, b32 implicit_first, b32 implicit_last){ if (name.size != 0){ - i32_4tech count = 0; - i32_4tech max = (sizeof(absolutes->a)/sizeof(*absolutes->a)) - 1; + i32 count = 0; + i32 max = (sizeof(absolutes->a)/sizeof(*absolutes->a)) - 1; if (implicit_last) --max; String str; str.str = name.str; str.size = 0; str.memory_size = 0; - b32_4tech prev_was_wild = 0; + b32 prev_was_wild = 0; if (implicit_first){ absolutes->a[count++] = str; prev_was_wild = 1; } - i32_4tech i; + i32 i; for (i = 0; i < name.size; ++i){ if (name.str[i] == '*' && count < max){ if (!prev_was_wild){ @@ -2384,15 +2414,15 @@ get_absolutes(String name, Absolutes *absolutes, b32_4tech implicit_first, b32_4 } } -static b32_4tech -wildcard_match_c(Absolutes *absolutes, char *x, i32_4tech case_sensitive){ - b32_4tech r = 1; +static b32 +wildcard_match_c(Absolutes *absolutes, char *x, i32 case_sensitive){ + b32 r = 1; if (absolutes->count > 0){ String *a = absolutes->a; - b32_4tech (*match_func)(char*, String); - b32_4tech (*match_part_func)(char*, String); + b32 (*match_func)(char*, String); + b32 (*match_part_func)(char*, String); if (case_sensitive){ match_func = match_cs; @@ -2445,8 +2475,8 @@ wildcard_match_c(Absolutes *absolutes, char *x, i32_4tech case_sensitive){ return(r); } -static b32_4tech -wildcard_match_s(Absolutes *absolutes, String x, i32_4tech case_sensitive){ +static b32 +wildcard_match_s(Absolutes *absolutes, String x, i32 case_sensitive){ terminate_with_null(&x); return(wildcard_match_c(absolutes, x.str, case_sensitive)); } @@ -2462,5 +2492,7 @@ wildcard_match_s(Absolutes *absolutes, String x, i32_4tech case_sensitive){ #define FSTRING_GUARD #endif +#endif + // BOTTOM diff --git a/4coder_lib/4coder_table.h b/4coder_lib/4coder_table.h index 97930bc8..5ea7bef6 100644 --- a/4coder_lib/4coder_table.h +++ b/4coder_lib/4coder_table.h @@ -12,67 +12,35 @@ distribute, and modify this file as you see fit. #if !defined(FCODER_TABLE_H) #define FCODER_TABLE_H -// 4tech_standard_preamble.h -#if !defined(FTECH_INTEGERS) -#define FTECH_INTEGERS -#include -typedef int8_t i8_4tech; -typedef int16_t i16_4tech; -typedef int32_t i32_4tech; -typedef int64_t i64_4tech; - -typedef uint8_t u8_4tech; -typedef uint16_t u16_4tech; -typedef uint32_t u32_4tech; -typedef uint64_t u64_4tech; - -#if defined(FTECH_32_BIT) -typedef u32_4tech umem_4tech; -#else -typedef u64_4tech umem_4tech; -#endif - -typedef float f32_4tech; -typedef double f64_4tech; - -typedef int8_t b8_4tech; -typedef int32_t b32_4tech; -#endif - -#if !defined(Assert) -# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0) -#endif -// standard preamble end - #define TableHashEmpty 0 #define TableHashDeleted 1 #define TableHashMin 0x10000000 #include -typedef u32_4tech Hash_Function(void *item, void *arg); -typedef i32_4tech Compare_Function(void *key, void *item, void *arg); +typedef u32 Hash_Function(void *item, void *arg); +typedef i32 Compare_Function(void *key, void *item, void *arg); struct Table{ - u32_4tech *hash_array; + u32 *hash_array; char *data_array; - i32_4tech count, max; - i32_4tech item_size; + i32 count, max; + i32 item_size; }; -static i32_4tech -table_required_mem_size(i32_4tech table_size, i32_4tech item_size){ - i32_4tech hash_size = ((table_size*sizeof(u32_4tech)) + 7) & ~7; - i32_4tech mem_size = hash_size + table_size*item_size; +static i32 +table_required_mem_size(i32 table_size, i32 item_size){ + i32 hash_size = ((table_size*sizeof(u32)) + 7) & ~7; + i32 mem_size = hash_size + table_size*item_size; return(mem_size); } static void -table_init_memory(Table *table, void *memory, i32_4tech table_size, i32_4tech item_size){ - i32_4tech hash_size = table_size * sizeof(u32_4tech); +table_init_memory(Table *table, void *memory, i32 table_size, i32 item_size){ + i32 hash_size = table_size * sizeof(u32); hash_size = (hash_size + 7) & ~7; - table->hash_array = (u32_4tech*)memory; + table->hash_array = (u32*)memory; table->data_array = (char*)(table->hash_array) + hash_size; table->count = 0; @@ -80,23 +48,23 @@ table_init_memory(Table *table, void *memory, i32_4tech table_size, i32_4tech it table->item_size = item_size; } -static i32_4tech +static i32 table_at_capacity(Table *table){ - i32_4tech result = true; + i32 result = true; if (table->count * 8 < table->max * 7){ result = false; } return(result); } -static i32_4tech +static i32 table_add(Table *table, void *item, void *arg, Hash_Function *hash_func, Compare_Function *comp_func){ Assert(table->count * 8 < table->max * 7); - u32_4tech hash = (hash_func(item, arg) | TableHashMin); - i32_4tech i = hash % table->max; - i32_4tech start = i; - u32_4tech *inspect = table->hash_array + i; + u32 hash = (hash_func(item, arg) | TableHashMin); + i32 i = hash % table->max; + i32 start = i; + u32 *inspect = table->hash_array + i; while (*inspect >= TableHashMin){ if (*inspect == hash){ @@ -119,14 +87,14 @@ table_add(Table *table, void *item, void *arg, Hash_Function *hash_func, Compare return(0); } -static i32_4tech -table_find_pos(Table *table, void *search_key, void *arg, i32_4tech *pos, i32_4tech *index, Hash_Function *hash_func, Compare_Function *comp_func){ +static i32 +table_find_pos(Table *table, void *search_key, void *arg, i32 *pos, i32 *index, Hash_Function *hash_func, Compare_Function *comp_func){ Assert((table->count - 1) * 8 < table->max * 7); - u32_4tech hash = (hash_func(search_key, arg) | TableHashMin); - i32_4tech i = hash % table->max; - i32_4tech start = i; - u32_4tech *inspect = table->hash_array + i; + u32 hash = (hash_func(search_key, arg) | TableHashMin); + i32 i = hash % table->max; + i32 start = i; + u32 *inspect = table->hash_array + i; while (*inspect != TableHashEmpty){ if (*inspect == hash){ @@ -151,7 +119,7 @@ table_find_pos(Table *table, void *search_key, void *arg, i32_4tech *pos, i32_4t static void* table_find_item(Table *table, void *search_key, void *arg, Hash_Function *hash_func, Compare_Function *comp_func){ void *result = 0; - i32_4tech pos; + i32 pos; if (table_find_pos(table, search_key, arg, &pos, 0, hash_func, comp_func)){ result = table->data_array + pos; } @@ -159,15 +127,15 @@ table_find_item(Table *table, void *search_key, void *arg, Hash_Function *hash_f } static void -table_remove_index(Table *table, i32_4tech index){ +table_remove_index(Table *table, i32 index){ table->hash_array[index] = TableHashDeleted; --table->count; } -static i32_4tech +static i32 table_remove_match(Table *table, void *search_key, void *arg, Hash_Function *hash_func, Compare_Function *comp_func){ - i32_4tech result = false; - i32_4tech index; + i32 result = false; + i32 index; if (table_find_pos(table, search_key, arg, 0, &index, hash_func, comp_func)){ table_remove_index(table, index); result = true; @@ -186,11 +154,11 @@ table_rehash(Table *src, Table *dst, void *arg, Hash_Function *hash_func, Compar Assert((dst->count + src->count - 1) * 7 < dst->max * 8); Assert(dst->item_size == src->item_size); - i32_4tech count = src->count; - i32_4tech item_size = src->item_size; - u32_4tech *hash_item = src->hash_array; + i32 count = src->count; + i32 item_size = src->item_size; + u32 *hash_item = src->hash_array; char *data_item = src->data_array; - for (i32_4tech i = 0, c = 0; + for (i32 i = 0, c = 0; c < count; ++i, ++hash_item, data_item += item_size){ if (*hash_item >= TableHashMin){ @@ -200,71 +168,65 @@ table_rehash(Table *src, Table *dst, void *arg, Hash_Function *hash_func, Compar } } -static u32_4tech +static u32 tbl_string_hash(void *item, void *arg){ - String *string = (String*)item; - u32_4tech x = 5381; + String_Const_u8 *string = (String_Const_u8*)item; + u32 x = 5381; (void)arg; - - char *str = string->str; - i32_4tech len = string->size; - i32_4tech i = 0; - while (i < len){ - char c = str[i++]; + u8 *str = string->str; + umem len = string->size; + for (umem i = 0; i < len; i += 1){ + u8 c = str[i]; x = ((x << 5) + x) + c; } - return(x); } -static i32_4tech +static i32 tbl_string_compare(void *a, void *b, void *arg){ - String *stra = (String*)a; - String *strb = (String*)b; - i32_4tech result = !match_ss(*stra, *strb); + String_Const_u8 *stra = (String_Const_u8*)a; + String_Const_u8 *strb = (String_Const_u8*)b; + i32 result = (!string_match(*stra, *strb)); return(result); } struct Offset_String{ - i32_4tech offset; - i32_4tech size; + umem offset; + umem size; }; -static u32_4tech +static u32 tbl_offset_string_hash(void *item, void *arg){ Offset_String *string = (Offset_String*)item; - u32_4tech x = 5381; - - char *str = ((char*)arg) + string->offset; - i32_4tech len = string->size; - i32_4tech i = 0; - while (i < len){ - char c = str[i++]; + u32 x = 5381; + u8 *str = ((u8*)arg) + string->offset; + umem size = string->size; + for (umem i = 0; i < size; i += 1){ + u8 c = str[i]; x = ((x << 5) + x) + c; } - return(x); } -static i32_4tech +static i32 tbl_offset_string_compare(void *a, void *b, void *arg){ Offset_String *ostra = (Offset_String*)a; Offset_String *ostrb = (Offset_String*)b; - String stra = make_string((char*)arg + ostra->offset, ostra->size); - String strb = make_string((char*)arg + ostrb->offset, ostrb->size); - i32_4tech result = !match_ss(stra, strb); + String_Const_u8 stra = SCu8((u8*)arg + ostra->offset, ostra->size); + String_Const_u8 strb = SCu8((u8*)arg + ostrb->offset, ostrb->size); + i32 result = (!string_match(stra, strb)); return(result); } struct String_Space{ char *space; - i32_4tech pos; - i32_4tech new_pos; - i32_4tech max; + i32 pos; + i32 new_pos; + i32 max; }; static Offset_String -strspace_append(String_Space *space, char *str, i32_4tech len){ +strspace_append(String_Space *space, char *str, i32 len){ Offset_String result = {}; if (space->new_pos + len <= space->max){ result.offset = space->new_pos; diff --git a/4coder_lib/4coder_utf8.h b/4coder_lib/4coder_utf8.h index 4a18eded..b509fbbb 100644 --- a/4coder_lib/4coder_utf8.h +++ b/4coder_lib/4coder_utf8.h @@ -12,39 +12,7 @@ #if !defined(FED_UTF8_CONVERSION_H) #define FED_UTF8_CONVERSION_H -// 4tech_standard_preamble.h -#if !defined(FTECH_INTEGERS) -#define FTECH_INTEGERS -#include -typedef int8_t i8_4tech; -typedef int16_t i16_4tech; -typedef int32_t i32_4tech; -typedef int64_t i64_4tech; - -typedef uint8_t u8_4tech; -typedef uint16_t u16_4tech; -typedef uint32_t u32_4tech; -typedef uint64_t u64_4tech; - -#if defined(FTECH_32_BIT) -typedef u32_4tech umem_4tech; -#else -typedef u64_4tech umem_4tech; -#endif - -typedef float f32_4tech; -typedef double f64_4tech; - -typedef int8_t b8_4tech; -typedef int32_t b32_4tech; -#endif - -#if !defined(Assert) -# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0) -#endif -// standard preamble end - -static u32_4tech cp_min_by_utf8_length[] = { +static u32 cp_min_by_utf8_length[] = { 0x0, 0x0, 0x80, @@ -52,45 +20,45 @@ static u32_4tech cp_min_by_utf8_length[] = { 0x10000, }; -static u32_4tech surrogate_min = 0xD800; -static u32_4tech surrogate_max = 0xDFFF; +static u32 surrogate_min = 0xD800; +static u32 surrogate_max = 0xDFFF; -static u32_4tech nonchar_min = 0xFDD0; -static u32_4tech nonchar_max = 0xFDEF; +static u32 nonchar_min = 0xFDD0; +static u32 nonchar_max = 0xFDEF; -static b32_4tech -codepoint_is_whitespace(u32_4tech codepoint){ - b32_4tech result = false; +static b32 +codepoint_is_whitespace(u32 codepoint){ + b32 result = false; if (codepoint == ' ' || codepoint == '\r' || codepoint == '\n' || codepoint == '\t'){ result = true; } return(result); } -static u32_4tech -utf8_to_u32_length_unchecked(u8_4tech *buffer, u32_4tech *length_out){ - u32_4tech result = 0; +static u32 +utf8_to_u32_length_unchecked(u8 *buffer, u32 *length_out){ + u32 result = 0; if (buffer[0] < 0x80){ - result = (u32_4tech)buffer[0]; + result = (u32)buffer[0]; *length_out = 1; } else if (buffer[0] < 0xE0){ - result = ((u32_4tech)((buffer[0])&0x1F)) << 6; - result |= ((u32_4tech)((buffer[1])&0x3F)); + result = ((u32)((buffer[0])&0x1F)) << 6; + result |= ((u32)((buffer[1])&0x3F)); *length_out = 2; } else if (buffer[0] < 0xF0){ - result = ((u32_4tech)((buffer[0])&0x0F)) << 12; - result |= ((u32_4tech)((buffer[1])&0x3F)) << 6; - result |= ((u32_4tech)((buffer[2])&0x3F)); + result = ((u32)((buffer[0])&0x0F)) << 12; + result |= ((u32)((buffer[1])&0x3F)) << 6; + result |= ((u32)((buffer[2])&0x3F)); *length_out = 3; } else{ - result = ((u32_4tech)((buffer[0])&0x07)) << 18; - result |= ((u32_4tech)((buffer[1])&0x3F)) << 12; - result |= ((u32_4tech)((buffer[2])&0x3F)) << 6; - result |= ((u32_4tech)((buffer[3])&0x3F)); + result = ((u32)((buffer[0])&0x07)) << 18; + result |= ((u32)((buffer[1])&0x3F)) << 12; + result |= ((u32)((buffer[2])&0x3F)) << 6; + result |= ((u32)((buffer[3])&0x3F)); *length_out = 4; } @@ -102,19 +70,19 @@ utf8_to_u32_length_unchecked(u8_4tech *buffer, u32_4tech *length_out){ return(result); } -static u32_4tech -utf8_to_u32_unchecked(u8_4tech *buffer){ - u32_4tech ignore; - u32_4tech result = utf8_to_u32_length_unchecked(buffer, &ignore); +static u32 +utf8_to_u32_unchecked(u8 *buffer){ + u32 ignore; + u32 result = utf8_to_u32_length_unchecked(buffer, &ignore); return(result); } -static u32_4tech -utf8_to_u32(u8_4tech **buffer_ptr, u8_4tech *end){ - u8_4tech *buffer = *buffer_ptr; - u32_4tech limit = (u32_4tech)(end - buffer); +static u32 +utf8_to_u32(u8 **buffer_ptr, u8 *end){ + u8 *buffer = *buffer_ptr; + u32 limit = (u32)(end - buffer); - u32_4tech length = 0; + u32 length = 0; if (buffer[0] < 0x80){ length = 1; } @@ -134,40 +102,40 @@ utf8_to_u32(u8_4tech **buffer_ptr, u8_4tech *end){ length = 0; } - for (u32_4tech i = 1; i < length; ++i){ + for (u32 i = 1; i < length; ++i){ if ((buffer[i] & 0xC0) != 0x80){ length = 0; break; } } - u32_4tech result = 0; + u32 result = 0; if (length != 0 && length <= limit){ switch (length){ case 1: { - result = (u32_4tech)buffer[0]; + result = (u32)buffer[0]; }break; case 2: { - result = ((u32_4tech)((buffer[0])&0x1F)) << 6; - result |= ((u32_4tech)((buffer[1])&0x3F)); + result = ((u32)((buffer[0])&0x1F)) << 6; + result |= ((u32)((buffer[1])&0x3F)); }break; case 3: { - result = ((u32_4tech)((buffer[0])&0x0F)) << 12; - result |= ((u32_4tech)((buffer[1])&0x3F)) << 6; - result |= ((u32_4tech)((buffer[2])&0x3F)); + result = ((u32)((buffer[0])&0x0F)) << 12; + result |= ((u32)((buffer[1])&0x3F)) << 6; + result |= ((u32)((buffer[2])&0x3F)); }break; case 4: { - result = ((u32_4tech)((buffer[0])&0x07)) << 18; - result |= ((u32_4tech)((buffer[1])&0x3F)) << 12; - result |= ((u32_4tech)((buffer[2])&0x3F)) << 6; - result |= ((u32_4tech)((buffer[3])&0x3F)); + result = ((u32)((buffer[0])&0x07)) << 18; + result |= ((u32)((buffer[1])&0x3F)) << 12; + result |= ((u32)((buffer[2])&0x3F)) << 6; + result |= ((u32)((buffer[3])&0x3F)); }break; } @@ -186,28 +154,28 @@ utf8_to_u32(u8_4tech **buffer_ptr, u8_4tech *end){ } static void -u32_to_utf8_unchecked(u32_4tech codepoint, u8_4tech *buffer, u32_4tech *length_out){ +u32_to_utf8_unchecked(u32 codepoint, u8 *buffer, u32 *length_out){ if (codepoint <= 0x7F){ - buffer[0] = (u8_4tech)codepoint; + buffer[0] = (u8)codepoint; *length_out = 1; } else if (codepoint <= 0x7FF){ - buffer[0] = (u8_4tech)(0xC0 | (codepoint >> 6)); - buffer[1] = (u8_4tech)(0x80 | (codepoint & 0x3F)); + buffer[0] = (u8)(0xC0 | (codepoint >> 6)); + buffer[1] = (u8)(0x80 | (codepoint & 0x3F)); *length_out = 2; } else if (codepoint <= 0xFFFF){ - buffer[0] = (u8_4tech)(0xE0 | (codepoint >> 12)); - buffer[1] = (u8_4tech)(0x80 | ((codepoint >> 6) & 0x3F)); - buffer[2] = (u8_4tech)(0x80 | (codepoint & 0x3F)); + buffer[0] = (u8)(0xE0 | (codepoint >> 12)); + buffer[1] = (u8)(0x80 | ((codepoint >> 6) & 0x3F)); + buffer[2] = (u8)(0x80 | (codepoint & 0x3F)); *length_out = 3; } else if (codepoint <= 0x10FFFF){ codepoint &= 0x001FFFFF; - buffer[0] = (u8_4tech)(0xF0 | (codepoint >> 18)); - buffer[1] = (u8_4tech)(0x80 | ((codepoint >> 12) & 0x3F)); - buffer[2] = (u8_4tech)(0x80 | ((codepoint >> 6) & 0x3F)); - buffer[3] = (u8_4tech)(0x80 | (codepoint & 0x3F)); + buffer[0] = (u8)(0xF0 | (codepoint >> 18)); + buffer[1] = (u8)(0x80 | ((codepoint >> 12) & 0x3F)); + buffer[2] = (u8)(0x80 | ((codepoint >> 6) & 0x3F)); + buffer[3] = (u8)(0x80 | (codepoint & 0x3F)); *length_out = 4; } else{ @@ -215,25 +183,25 @@ u32_to_utf8_unchecked(u32_4tech codepoint, u8_4tech *buffer, u32_4tech *length_o } } -static umem_4tech -utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech *src, umem_4tech length, b32_4tech *error){ - u8_4tech *s = src; - u8_4tech *s_end = s + length; +static umem +utf8_to_utf16_minimal_checking(u16 *dst, umem max_wchars, u8 *src, umem length, b32 *error){ + u8 *s = src; + u8 *s_end = s + length; - u16_4tech *d = dst; - u16_4tech *d_end = d + max_wchars; - umem_4tech limit = length; + u16 *d = dst; + u16 *d_end = d + max_wchars; + umem limit = length; - umem_4tech needed_max = 0; - u32_4tech advance = 1; + umem needed_max = 0; + u32 advance = 1; *error = false; for(; s < s_end;){ - u32_4tech codepoint = 0; - u32_4tech utf8_size = 0; + u32 codepoint = 0; + u32 utf8_size = 0; if (s[0] < 0x80){ - codepoint = (u32_4tech)s[0]; + codepoint = (u32)s[0]; utf8_size = 1; } else if (s[0] < 0xE0){ @@ -242,8 +210,8 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * break; } - codepoint = ((u32_4tech)((s[0])&0x1F)) << 6; - codepoint |= ((u32_4tech)((s[1])&0x3F)); + codepoint = ((u32)((s[0])&0x1F)) << 6; + codepoint |= ((u32)((s[1])&0x3F)); utf8_size = 2; } else if (s[0] < 0xF0){ @@ -252,9 +220,9 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * break; } - codepoint = ((u32_4tech)((s[0])&0x0F)) << 12; - codepoint |= ((u32_4tech)((s[1])&0x3F)) << 6; - codepoint |= ((u32_4tech)((s[2])&0x3F)); + codepoint = ((u32)((s[0])&0x0F)) << 12; + codepoint |= ((u32)((s[1])&0x3F)) << 6; + codepoint |= ((u32)((s[2])&0x3F)); utf8_size = 3; } else if (s[0] < 0xF8){ @@ -263,10 +231,10 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * break; } - codepoint = ((u32_4tech)((s[0])&0x07)) << 18; - codepoint |= ((u32_4tech)((s[1])&0x3F)) << 12; - codepoint |= ((u32_4tech)((s[2])&0x3F)) << 6; - codepoint |= ((u32_4tech)((s[3])&0x3F)); + codepoint = ((u32)((s[0])&0x07)) << 18; + codepoint |= ((u32)((s[1])&0x3F)) << 12; + codepoint |= ((u32)((s[2])&0x3F)) << 6; + codepoint |= ((u32)((s[3])&0x3F)); utf8_size = 4; } else{ @@ -283,23 +251,23 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * limit -= utf8_size; if (codepoint <= 0xD7FF || (codepoint >= 0xE000 && codepoint <= 0xFFFF)){ - *d = (u16_4tech)(codepoint); + *d = (u16)(codepoint); d += advance; needed_max += 1; } else if (codepoint >= 0x10000 && codepoint <= 0x10FFFF){ codepoint -= 0x10000; - u32_4tech high = (codepoint >> 10) & 0x03FF; - u32_4tech low = (codepoint) & 0x03FF; + u32 high = (codepoint >> 10) & 0x03FF; + u32 low = (codepoint) & 0x03FF; high += 0xD800; low += 0xDC00; if (d + advance < d_end){ - *d = (u16_4tech)high; + *d = (u16)high; d += advance; - *d = (u16_4tech)low; + *d = (u16)low; d += advance; } else{ @@ -321,22 +289,22 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * return(needed_max); } -static umem_4tech -utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *src, umem_4tech length, b32_4tech *error){ - u16_4tech *s = src; - u16_4tech *s_end = s + length; +static umem +utf16_to_utf8_minimal_checking(u8 *dst, umem max_chars, u16 *src, umem length, b32 *error){ + u16 *s = src; + u16 *s_end = s + length; - u8_4tech *d = dst; - u8_4tech *d_end = d + max_chars; - umem_4tech limit = length; + u8 *d = dst; + u8 *d_end = d + max_chars; + umem limit = length; - umem_4tech needed_max = 0; + umem needed_max = 0; *error = false; for (; s < s_end;){ - u32_4tech codepoint = 0; - u32_4tech utf16_size = 0; + u32 codepoint = 0; + u32 utf16_size = 0; if (s[0] <= 0xD7FF || (s[0] >= 0xE000 && s[0] <= 0xFFFF)){ codepoint = s[0]; @@ -349,8 +317,8 @@ utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *s break; } - u32_4tech high = s[0] - 0xD800; - u32_4tech low = s[1] - 0xDC00; + u32 high = s[0] - 0xD800; + u32 low = s[1] - 0xDC00; codepoint = ((high << 10) | (low)) + 0x10000; utf16_size = 2; } @@ -363,29 +331,29 @@ utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *s s += utf16_size; limit -= utf16_size; - u8_4tech d_fill[4]; - u32_4tech d_fill_count = 0; + u8 d_fill[4]; + u32 d_fill_count = 0; if (codepoint <= 0x7F){ - d_fill[0] = (u8_4tech)codepoint; + d_fill[0] = (u8)codepoint; d_fill_count = 1; } else if (codepoint <= 0x7FF){ - d_fill[0] = (u8_4tech)(0xC0 | (codepoint >> 6)); - d_fill[1] = (u8_4tech)(0x80 | (codepoint & 0x3F)); + d_fill[0] = (u8)(0xC0 | (codepoint >> 6)); + d_fill[1] = (u8)(0x80 | (codepoint & 0x3F)); d_fill_count = 2; } else if (codepoint <= 0xFFFF){ - d_fill[0] = (u8_4tech)(0xE0 | (codepoint >> 12)); - d_fill[1] = (u8_4tech)(0x80 | ((codepoint >> 6) & 0x3F)); - d_fill[2] = (u8_4tech)(0x80 | (codepoint & 0x3F)); + d_fill[0] = (u8)(0xE0 | (codepoint >> 12)); + d_fill[1] = (u8)(0x80 | ((codepoint >> 6) & 0x3F)); + d_fill[2] = (u8)(0x80 | (codepoint & 0x3F)); d_fill_count = 3; } else if (codepoint <= 0x10FFFF){ - d_fill[0] = (u8_4tech)(0xF0 | (codepoint >> 18)); - d_fill[1] = (u8_4tech)(0x80 | ((codepoint >> 12) & 0x3F)); - d_fill[2] = (u8_4tech)(0x80 | ((codepoint >> 6) & 0x3F)); - d_fill[3] = (u8_4tech)(0x80 | (codepoint & 0x3F)); + d_fill[0] = (u8)(0xF0 | (codepoint >> 18)); + d_fill[1] = (u8)(0x80 | ((codepoint >> 12) & 0x3F)); + d_fill[2] = (u8)(0x80 | ((codepoint >> 6) & 0x3F)); + d_fill[3] = (u8)(0x80 | (codepoint & 0x3F)); d_fill_count = 4; } else{ @@ -394,7 +362,7 @@ utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *s } if (d + d_fill_count <= d_end){ - for (u32_4tech i = 0; i < d_fill_count; ++i){ + for (u32 i = 0; i < d_fill_count; ++i){ *d = d_fill[i]; ++d; } @@ -406,8 +374,8 @@ utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *s } static void -byte_to_ascii(u8_4tech n, u8_4tech *out){ - u8_4tech C = '0' + (n / 0x10); +byte_to_ascii(u8 n, u8 *out){ + u8 C = '0' + (n / 0x10); if ((n / 0x10) > 0x9){ C = ('A' - 0xA) + (n / 0x10); } diff --git a/4coder_lib/4cpp_default_keywords.h b/4coder_lib/4cpp_default_keywords.h index 536c031c..58fffbdf 100644 --- a/4coder_lib/4cpp_default_keywords.h +++ b/4coder_lib/4cpp_default_keywords.h @@ -15,8 +15,8 @@ struct String_And_Flag{ char *str; - u32_4tech length; - u32_4tech flags; + u32 length; + u32 flags; }; static String_And_Flag default_preprops[] = { @@ -55,7 +55,7 @@ static String_And_Flag default_preprops[] = { #include FCPP_LEXER_EXTRA_PREPROPS #endif }; -static i32_4tech default_preprops_count = sizeof(default_preprops)/sizeof(default_preprops[0]); +static i32 default_preprops_count = sizeof(default_preprops)/sizeof(default_preprops[0]); static String_And_Flag default_keywords[] = { // CPP_TOKEN_BOOLEAN_CONSTANT @@ -162,7 +162,7 @@ static String_And_Flag default_keywords[] = { #include FCPP_LEXER_EXTRA_KEYWORDS #endif }; -static i32_4tech default_keywords_count = sizeof(default_keywords)/sizeof(default_keywords[0]); +static i32 default_keywords_count = sizeof(default_keywords)/sizeof(default_keywords[0]); #endif diff --git a/4coder_lib/4cpp_lexer.h b/4coder_lib/4cpp_lexer.h index 83d47941..59435589 100644 --- a/4coder_lib/4cpp_lexer.h +++ b/4coder_lib/4cpp_lexer.h @@ -9,110 +9,59 @@ distribute, and modify this file as you see fit. // TOP -#ifndef FCPP_NEW_LEXER_INC -#define FCPP_NEW_LEXER_INC - -// 4tech_standard_preamble.h -#if !defined(FTECH_INTEGERS) -#define FTECH_INTEGERS -#include -typedef int8_t i8_4tech; -typedef int16_t i16_4tech; -typedef int32_t i32_4tech; -typedef int64_t i64_4tech; - -typedef uint8_t u8_4tech; -typedef uint16_t u16_4tech; -typedef uint32_t u32_4tech; -typedef uint64_t u64_4tech; - -#if defined(FTECH_32_BIT) -typedef u32_4tech umem_4tech; -#else -typedef u64_4tech umem_4tech; -#endif - -typedef float f32_4tech; -typedef double f64_4tech; - -typedef int8_t b8_4tech; -typedef int32_t b32_4tech; -#endif - -#if !defined(Assert) -# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0) -#endif - -#if !defined(Member) -# define Member(T, m) (((T*)0)->m) -#endif - -#if !defined(API_EXPORT) -# define API_EXPORT -#endif -// standard preamble end - -// duff-routine defines -#define DfrCase(PC) case PC: goto resumespot_##PC -#define DfrYield(PC, n) { *S_ptr = S; S_ptr->__pc__ = PC; return(n); resumespot_##PC:; } -#define DfrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); } - -#ifndef FCPP_LINK -# define FCPP_LINK static -#endif +#ifndef FCPP_NEW_LEXER_H +#define FCPP_NEW_LEXER_H #include "4cpp_lexer_types.h" #include "4cpp_lexer_tables.c" #include "4cpp_default_keywords.h" -//////////////// - -API_EXPORT FCPP_LINK umem_4tech -cpp_get_table_memory_size_null_terminated(char **str_array, u32_4tech str_count) +API_EXPORT internal umem +cpp_get_table_memory_size_null_terminated(char **str_array, u32 str_count) /* DOC_PARAM(str_array, An array of null terminated strings that specifies every string that will be put in the table.) DOC_PARAM(str_count, The number of strings in str_array.) DOC_RETURN(Returns the memory size, in bytes, needed to allocate a table for the given strings.) */{ - umem_4tech memsize = 0; - for (u32_4tech i = 0; i < str_count; ++i){ + umem memsize = 0; + for (u32 i = 0; i < str_count; ++i){ char *str = str_array[i]; - u32_4tech len = 0; + u32 len = 0; for (; str[len]; ++len); memsize += 8 + (len+3)&(~3); } - u32_4tech table_count = (str_count * 3) / 2; - memsize += table_count*sizeof(*Member(Cpp_Keyword_Table, keywords)); + u32 table_count = (str_count * 3) / 2; + memsize += table_count*sizeof(Member(Cpp_Keyword_Table, keywords)); return(memsize); } -API_EXPORT FCPP_LINK umem_4tech -cpp_get_table_memory_size_string_lengths(u32_4tech *str_len, u32_4tech byte_stride, u32_4tech str_count) +API_EXPORT internal umem +cpp_get_table_memory_size_string_lengths(u32 *str_len, u32 byte_stride, u32 str_count) /* DOC_PARAM(str_len, An array specifying the length of every string that will be put in the table.) DOC_PARAM(byte_stride, The distance in bytes between each length element.) DOC_PARAM(str_count, The number of length elements in the array.) DOC_RETURN(Returns the memory size, in bytes, needed to allocate a table for the given strings.) */{ - umem_4tech memsize = 0; - u8_4tech *length_data = (u8_4tech*)str_len; - for (u32_4tech i = 0; i < str_count; ++i, length_data += byte_stride){ - u32_4tech len = *(u32_4tech*)(length_data); + umem memsize = 0; + u8 *length_data = (u8*)str_len; + for (u32 i = 0; i < str_count; ++i, length_data += byte_stride){ + u32 len = *(u32*)(length_data); memsize += 8 + (len+3)&(~3); } - u32_4tech table_count = (str_count * 3)/2; + u32 table_count = (str_count * 3)/2; memsize += table_count*sizeof(*Member(Cpp_Keyword_Table, keywords)); return(memsize); } -FCPP_LINK void -cpp__write_word_data(char **out_ptr, u32_4tech len, u32_4tech type, char *str){ +internal void +cpp__write_word_data(char **out_ptr, u32 len, u32 type, char *str){ char *out = *out_ptr; - *(u32_4tech*)out = len; + *(u32*)out = len; out += 4; - *(u32_4tech*)out = type; + *(u32*)out = type; out += 4; - for (u32_4tech j = 0; str[j]; ++j){ + for (u32 j = 0; str[j]; ++j){ out[j] = str[j]; } len = (len+3)&(~3); @@ -120,9 +69,9 @@ cpp__write_word_data(char **out_ptr, u32_4tech len, u32_4tech type, char *str){ *out_ptr = out; } -FCPP_LINK b32_4tech -cpp__match(char *a, i32_4tech a_len, char *b, i32_4tech b_len){ - b32_4tech result = false; +internal b32 +cpp__match(char *a, i32 a_len, char *b, i32 b_len){ + b32 result = false; if (a_len == b_len){ char *a_end = a + a_len; result = true; @@ -136,31 +85,31 @@ cpp__match(char *a, i32_4tech a_len, char *b, i32_4tech b_len){ return(result); } -FCPP_LINK void -cpp__fill_table(Cpp_Keyword_Table *table, char *str, u32_4tech str_count){ - u64_4tech *keywords = table->keywords; - u8_4tech *base = (u8_4tech*)keywords; - u32_4tech max = table->max; +internal void +cpp__fill_table(Cpp_Keyword_Table *table, char *str, u32 str_count){ + u64 *keywords = table->keywords; + u8 *base = (u8*)keywords; + u32 max = table->max; - for (u32_4tech i = 0; i < str_count; ++i){ - u32_4tech str_len = *(u32_4tech*)str; + for (u32 i = 0; i < str_count; ++i){ + u32 str_len = *(u32*)str; str += 8; - u32_4tech hash = 0; - for (u32_4tech j = 0; j < str_len; ++j){ - hash = (hash << 5) + (u32_4tech)(str[j]); + u32 hash = 0; + for (u32 j = 0; j < str_len; ++j){ + hash = (hash << 5) + (u32)(str[j]); } - u32_4tech first_index = hash % max; - u32_4tech index = first_index; + u32 first_index = hash % max; + u32 index = first_index; for (;;){ - u64_4tech *keyword_ptr = keywords + index; + u64 *keyword_ptr = keywords + index; if (*keyword_ptr == 0){ - *keyword_ptr = (u64_4tech)((str - 8) - (char*)base); + *keyword_ptr = (u64)((str - 8) - (char*)base); break; } else{ - u32_4tech *table_str_len = (u32_4tech*)(*keyword_ptr + base); + u32 *table_str_len = (u32*)(*keyword_ptr + base); char *table_str = (char*)(table_str_len + 2); if (cpp__match(table_str, *table_str_len, str, str_len)){ break; @@ -181,8 +130,8 @@ cpp__fill_table(Cpp_Keyword_Table *table, char *str, u32_4tech str_count){ } } -API_EXPORT FCPP_LINK Cpp_Keyword_Table -cpp_make_table(char **str_array, u32_4tech str_stride, u32_4tech *len_array, u32_4tech len_stride, u32_4tech *type_array, u32_4tech type_stride, u32_4tech str_count, void *memory, umem_4tech memsize) +API_EXPORT internal Cpp_Keyword_Table +cpp_make_table(char **str_array, u32 str_stride, u32 *len_array, u32 len_stride, u32 *type_array, u32 type_stride, u32 str_count, void *memory, umem memsize) /* DOC_PARAM(str_array, An array of strings to be put in the new table.) DOC_PARAM(str_stride, The number of bytes separating each string pointer in the array.) @@ -204,13 +153,13 @@ DOC_SEE(cpp_get_table_memory_size_string_lengths) Cpp_Keyword_Table table = {}; table.mem = memory; table.memsize = memsize; - table.keywords = (u64_4tech*)memory; + table.keywords = (u64*)memory; table.max = (str_count * 3)/2; - umem_4tech size_of_table = sizeof(*table.keywords)*table.max; + umem size_of_table = sizeof(*table.keywords)*table.max; { - u8_4tech *ptr = (u8_4tech*)memory; - for (umem_4tech i = memsize; i > 0; --i, ++ptr){ + u8 *ptr = (u8*)memory; + for (umem i = memsize; i > 0; --i, ++ptr){ *ptr = 0; } } @@ -218,48 +167,48 @@ DOC_SEE(cpp_get_table_memory_size_string_lengths) char *out_base = ((char*)memory) + size_of_table; char *out_ptr = out_base; - u8_4tech *str_ptr = (u8_4tech*)str_array; - u8_4tech *len_ptr = (u8_4tech*)len_array; - u8_4tech *type_ptr = (u8_4tech*)type_array; + u8 *str_ptr = (u8*)str_array; + u8 *len_ptr = (u8*)len_array; + u8 *type_ptr = (u8*)type_array; if (len_ptr == 0){ if (type_ptr == 0){ - for (u32_4tech i = 0; i < str_count; ++i){ + for (u32 i = 0; i < str_count; ++i){ char *str_item = *(char**)str_ptr; str_ptr += str_stride; - u32_4tech len = 0; + u32 len = 0; for (; str_item[len]; ++len); cpp__write_word_data(&out_ptr, len, CPP_TOKEN_KEY_OTHER, str_item); } } else{ - for (u32_4tech i = 0; i < str_count; ++i){ + for (u32 i = 0; i < str_count; ++i){ char *str_item = *(char**)str_ptr; str_ptr += str_stride; - u32_4tech len = 0; + u32 len = 0; for (; str_item[len]; ++len); - u32_4tech type = *(u32_4tech*)(type_ptr); + u32 type = *(u32*)(type_ptr); cpp__write_word_data(&out_ptr, len, type, str_item); } } } else{ if (type_ptr == 0){ - for (u32_4tech i = 0; i < str_count; ++i){ + for (u32 i = 0; i < str_count; ++i){ char *str_item = *(char**)str_ptr; str_ptr += str_stride; - u32_4tech len = *(u32_4tech*)(len_ptr); + u32 len = *(u32*)(len_ptr); len_ptr += len_stride; cpp__write_word_data(&out_ptr, len, CPP_TOKEN_KEY_OTHER, str_item); } } else{ - for (u32_4tech i = 0; i < str_count; ++i){ + for (u32 i = 0; i < str_count; ++i){ char *str_item = *(char**)str_ptr; str_ptr += str_stride; - u32_4tech len = *(u32_4tech*)(len_ptr); + u32 len = *(u32*)(len_ptr); len_ptr += len_stride; - u32_4tech type = *(u32_4tech*)(type_ptr); + u32 type = *(u32*)(type_ptr); type_ptr += type_stride; cpp__write_word_data(&out_ptr, len, type, str_item); } @@ -271,31 +220,31 @@ DOC_SEE(cpp_get_table_memory_size_string_lengths) return(table); } -FCPP_LINK b32_4tech -cpp__table_match(Cpp_Keyword_Table *table, char *s, u32_4tech s_len, u32_4tech **item_ptr_out){ - u32_4tech hash = 0; - for (u32_4tech i = 0; i < s_len; ++i){ - hash = (hash << 5) + (u32_4tech)(s[i]); +internal b32 +cpp__table_match(Cpp_Keyword_Table *table, char *s, u32 s_len, u32 **item_ptr_out){ + u32 hash = 0; + for (u32 i = 0; i < s_len; ++i){ + hash = (hash << 5) + (u32)(s[i]); } - u64_4tech *keywords = table->keywords; - u8_4tech *base = (u8_4tech*)keywords; + u64 *keywords = table->keywords; + u8 *base = (u8*)keywords; - b32_4tech result = false; - u32_4tech max = table->max; + b32 result = false; + u32 max = table->max; if (max > 0){ - u32_4tech first_index = hash % max; - u32_4tech index = first_index; + u32 first_index = hash % max; + u32 index = first_index; for (;;){ - u64_4tech *keyword_ptr = keywords + index; + u64 *keyword_ptr = keywords + index; if (*keyword_ptr == 0){ break; } - u32_4tech *str_len = (u32_4tech*)(*keyword_ptr + base); + u32 *str_len = (u32*)(*keyword_ptr + base); char *str = (char*)(str_len + 2); if (cpp__match(str, *str_len, s, s_len)){ - *item_ptr_out = (u32_4tech*)(*keyword_ptr + base); + *item_ptr_out = (u32*)(*keyword_ptr + base); result = true; break; } @@ -313,15 +262,15 @@ cpp__table_match(Cpp_Keyword_Table *table, char *s, u32_4tech s_len, u32_4tech * return(result); } -API_EXPORT FCPP_LINK umem_4tech +API_EXPORT internal umem cpp_get_table_memory_size_default(Cpp_Word_Table_Type type) /* DOC_PARAM(type, Specifies for which slot of the parser context to get a default result.) DOC_RETURN(Returns the memory size, in bytes, needed to allocate a table for the given default slot.) DOC_SEE(Cpp_Word_Table_Type) */{ - u32_4tech *ptr = 0; - u32_4tech count = 0; + u32 *ptr = 0; + u32 count = 0; switch (type){ case CPP_TABLE_KEYWORDS: @@ -337,13 +286,13 @@ DOC_SEE(Cpp_Word_Table_Type) }break; } - u32_4tech stride = sizeof(String_And_Flag); - umem_4tech size = cpp_get_table_memory_size_string_lengths(ptr, stride, count); + u32 stride = sizeof(String_And_Flag); + umem size = cpp_get_table_memory_size_string_lengths(ptr, stride, count); return(size); } -API_EXPORT FCPP_LINK Cpp_Keyword_Table -cpp_make_table_default(Cpp_Word_Table_Type type, void *memory, umem_4tech memsize) +API_EXPORT internal Cpp_Keyword_Table +cpp_make_table_default(Cpp_Word_Table_Type type, void *memory, umem memsize) /* DOC_PARAM(type, Specifies for which slot of the parser context to get a default result.) DOC_PARAM(memory, A chunk of memory set aside for this table. This should have at least as much memory as returned by one of the cpp_get_table_memory_size functions.) @@ -357,9 +306,9 @@ DOC_SEE(Cpp_Word_Table_Type) DOC_SEE(cpp_make_table) */{ char **str_ptr = 0; - u32_4tech *len_ptr = 0; - u32_4tech *type_ptr = 0; - u32_4tech count = 0; + u32 *len_ptr = 0; + u32 *type_ptr = 0; + u32 count = 0; switch (type){ case CPP_TABLE_KEYWORDS: @@ -379,14 +328,14 @@ DOC_SEE(cpp_make_table) }break; } - u32_4tech stride = sizeof(String_And_Flag); + u32 stride = sizeof(String_And_Flag); Cpp_Keyword_Table table = cpp_make_table(str_ptr, stride, len_ptr, stride, type_ptr, stride, count, memory, memsize); return(table); } //////////////// -API_EXPORT FCPP_LINK Cpp_Token_Category +API_EXPORT internal Cpp_Token_Category cpp_token_category_from_type(Cpp_Token_Type type){ Cpp_Token_Category cat = 0; switch (type){ @@ -521,8 +470,8 @@ cpp_token_category_from_type(Cpp_Token_Type type){ return(cat); } -API_EXPORT FCPP_LINK Cpp_Get_Token_Result -cpp_get_token(Cpp_Token_Array array, i32_4tech pos)/* +API_EXPORT internal Cpp_Get_Token_Result +cpp_get_token(Cpp_Token_Array array, i32 pos)/* DOC_PARAM(array, The array of tokens from which to get a token.) DOC_PARAM(pos, The position, measured in bytes, to get the token for.) DOC_RETURN(A Cpp_Get_Token_Result struct is returned containing the index of a token and a flag indicating whether the pos is contained in the token or in whitespace after the token.) @@ -533,10 +482,10 @@ DOC_SEE(Cpp_Get_Token_Result) */{ Cpp_Get_Token_Result result = {}; Cpp_Token *tokens = array.tokens; - i32_4tech count = array.count; + i32 count = array.count; - i32_4tech first_index = 0; - i32_4tech one_past_last_index = count; + i32 first_index = 0; + i32 one_past_last_index = count; for (;;){ if (first_index == one_past_last_index){ result.token_index = -1; @@ -544,18 +493,18 @@ DOC_SEE(Cpp_Get_Token_Result) break; } - i32_4tech mid_index = (first_index + one_past_last_index)/2; + i32 mid_index = (first_index + one_past_last_index)/2; Cpp_Token *token = tokens + mid_index; - i32_4tech range_first = token->start; - i32_4tech range_one_past_last = 0x7FFFFFFF; + i32 range_first = token->start; + i32 range_one_past_last = 0x7FFFFFFF; if (mid_index + 1 < count){ range_one_past_last = tokens[mid_index + 1].start; } if (range_first <= pos && pos < range_one_past_last){ result.token_index = mid_index; - i32_4tech token_one_past_last = range_first + token->size; + i32 token_one_past_last = range_first + token->size; if (token_one_past_last <= pos){ result.in_whitespace_after_token = 1; } @@ -577,11 +526,11 @@ DOC_SEE(Cpp_Get_Token_Result) Cpp_Get_Token_Result result = {}; Cpp_Token *token_array = array.tokens; Cpp_Token *token = 0; - i32_4tech first = 0; - i32_4tech count = array.count; - i32_4tech last = count; - i32_4tech this_start = 0; - i32_4tech next_start = 0; + i32 first = 0; + i32 count = array.count; + i32 last = count; + i32 this_start = 0; + i32 next_start = 0; if (count > 0){ for (;;){ @@ -637,7 +586,7 @@ DOC_SEE(Cpp_Get_Token_Result) } // TODO(allen): eliminate this and just make a table. -FCPP_LINK Cpp_Lex_PP_State +internal Cpp_Lex_PP_State cpp__pp_directive_to_state(Cpp_Token_Type type){ Cpp_Lex_PP_State result = LSPP_default; switch (type){ @@ -686,30 +635,30 @@ cpp__pp_directive_to_state(Cpp_Token_Type type){ #define LEXER_TB(n) ((n) & (sizeof(S.tb)-1)) -FCPP_LINK Cpp_Lex_Result -cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech size, Cpp_Token_Array *token_array_out){ +internal Cpp_Lex_Result +cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32 size, Cpp_Token_Array *token_array_out){ Cpp_Lex_Data S = *S_ptr; Cpp_Token *out_tokens = token_array_out->tokens; - i32_4tech token_i = token_array_out->count; - i32_4tech max_token_i = token_array_out->max_count; + i32 token_i = token_array_out->count; + i32 max_token_i = token_array_out->max_count; - u8_4tech c = 0; + u8 c = 0; - i32_4tech end_pos = size + S.chunk_pos; + i32 end_pos = size + S.chunk_pos; chunk -= S.chunk_pos; switch (S.__pc__){ - DfrCase(1); - DfrCase(2); - DfrCase(3); - DfrCase(4); - DfrCase(5); - DfrCase(6); - DfrCase(7); - DfrCase(8); - DfrCase(9); - DfrCase(10); + DrCase(1); + DrCase(2); + DrCase(3); + DrCase(4); + DrCase(5); + DrCase(6); + DrCase(7); + DrCase(8); + DrCase(9); + DrCase(10); } Assert(S.keyword_table.keywords != 0); @@ -719,8 +668,8 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s S.white_done = 0; for(;;){ for (; S.pp_state < LSPP_count && S.pos < end_pos;){ - c = (u8_4tech)chunk[S.pos++]; - i32_4tech i = S.pp_state + whitespace_fsm_eq_classes[c]; + c = (u8)chunk[S.pos++]; + i32 i = S.pp_state + whitespace_fsm_eq_classes[c]; S.pp_state = whitespace_fsm_table[i]; } S.white_done = (S.pp_state >= LSPP_count); @@ -728,7 +677,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s if (S.white_done == 0){ S.chunk_pos += size; token_array_out->count = token_i; - DfrYield(4, LexResult_NeedChunk); + DrYield(4, LexResult_NeedChunk); } else{ break; @@ -749,14 +698,14 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s S.fsm = null_lex_fsm; for(;;){ { - u16_4tech *eq_classes = get_eq_classes[S.pp_state]; - u8_4tech *fsm_table = get_table[S.pp_state]; + u16 *eq_classes = get_eq_classes[S.pp_state]; + u8 *fsm_table = get_table[S.pp_state]; for (; S.fsm.state < LS_count && S.pos < end_pos;){ c = chunk[S.pos++]; S.tb[LEXER_TB(S.tb_pos++)] = c; - i32_4tech i = S.fsm.state + eq_classes[c]; + i32 i = S.fsm.state + eq_classes[c]; S.fsm.state = fsm_table[i]; } S.fsm.emit_token = (S.fsm.state >= LS_count); @@ -765,7 +714,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s if (S.fsm.emit_token == 0){ S.chunk_pos += size; token_array_out->count = token_i; - DfrYield(3, LexResult_NeedChunk); + DrYield(3, LexResult_NeedChunk); } else{ break; @@ -824,7 +773,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s if (!S.white_done){ S.chunk_pos += size; token_array_out->count = token_i; - DfrYield(1, LexResult_NeedChunk); + DrYield(1, LexResult_NeedChunk); } else{ break; @@ -851,7 +800,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s { --S.pos; - i32_4tech word_size = S.pos - S.token_start; + i32 word_size = S.pos - S.token_start; if (word_size < sizeof(S.tb)){ if (S.pp_state == LSPP_body_if){ @@ -862,7 +811,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s } } - u32_4tech *item_ptr = 0; + u32 *item_ptr = 0; cpp__table_match(&S.keyword_table, S.tb, S.tb_pos-1, &item_ptr); if (item_ptr != 0){ @@ -900,15 +849,15 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s --S.pos; if (S.tb_pos < sizeof(S.tb)){ - i32_4tech pos = S.tb_pos-1; - i32_4tech i = 1; + i32 pos = S.tb_pos-1; + i32 i = 1; for (;i < pos; ++i){ if (S.tb[i] != ' '){ break; } } - u32_4tech *item_ptr = 0; + u32 *item_ptr = 0; cpp__table_match(&S.preprops_table, S.tb+i, S.tb_pos-i-1, &item_ptr); if (item_ptr != 0){ @@ -919,7 +868,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s else{ S.token.flags = 0; } - S.pp_state = (u8_4tech)cpp__pp_directive_to_state(S.token.type); + S.pp_state = (u8)cpp__pp_directive_to_state(S.token.type); break; } } @@ -945,7 +894,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s if (S.fsm.emit_token == 0){ S.chunk_pos += size; token_array_out->count = token_i; - DfrYield(5, LexResult_NeedChunk); + DrYield(5, LexResult_NeedChunk); } else{ break; @@ -992,10 +941,10 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s if (S.fsm.emit_token == 0){ S.chunk_pos += size; token_array_out->count = token_i; - DfrYield(7, LexResult_NeedChunk); + DrYield(7, LexResult_NeedChunk); } else{ - u8_4tech emit_state = S.fsm.state - LSSTR_count; + u8 emit_state = S.fsm.state - LSSTR_count; switch (emit_state){ case LSSTR_default: { @@ -1007,7 +956,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s { if (S.tb_pos <= 17){ S.delim_length = S.tb_pos-1; - for (i32_4tech n = 0; n < S.delim_length; ++n){ + for (i32 n = 0; n < S.delim_length; ++n){ S.raw_delim[n] = S.tb[n]; } S.tb_pos = 0; @@ -1025,11 +974,11 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s goto doublebreak; } else if (S.tb_pos >= S.delim_length){ - u32_4tech m = S.tb_pos - S.delim_length - 2; + u32 m = S.tb_pos - S.delim_length - 2; if (S.tb[LEXER_TB(m)] == ')'){ - b32_4tech is_match = true; + b32 is_match = true; ++m; - for (i32_4tech n = 0; n < S.delim_length; ++n, ++m){ + for (i32 n = 0; n < S.delim_length; ++n, ++m){ if (S.tb[LEXER_TB(m)] != S.raw_delim[n]){ is_match = false; break; @@ -1068,7 +1017,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s if (S.fsm.emit_token == 0){ S.chunk_pos += size; token_array_out->count = token_i; - DfrYield(8, LexResult_NeedChunk); + DrYield(8, LexResult_NeedChunk); } else{ break; @@ -1096,7 +1045,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s if (S.fsm.emit_token == 0){ S.chunk_pos += size; token_array_out->count = token_i; - DfrYield(6, LexResult_NeedChunk); + DrYield(6, LexResult_NeedChunk); } else{ break; @@ -1133,7 +1082,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s if (S.fsm.emit_token == 0){ S.chunk_pos += size; token_array_out->count = token_i; - DfrYield(9, LexResult_NeedChunk); + DrYield(9, LexResult_NeedChunk); } else{ break; @@ -1311,8 +1260,8 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s case LS_single_op: { - u32_4tech plain_version = 0; - u32_4tech eq_version = 0; + u32 plain_version = 0; + u32 eq_version = 0; S.token.flags = CPP_TFLAG_IS_OPERATOR; switch (S.tb[0]){ case '*': plain_version = CPP_TOKEN_STAR; eq_version = CPP_TOKEN_MULEQ; break; @@ -1400,10 +1349,10 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s if (S.pos == end_pos){ S.chunk_pos += size; token_array_out->count = token_i; - DfrYield(10, LexResult_NeedChunk); + DrYield(10, LexResult_NeedChunk); } token_array_out->count = token_i; - DfrYield(2, LexResult_NeedTokenMemory); + DrYield(2, LexResult_NeedTokenMemory); } } @@ -1413,12 +1362,12 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s } token_array_out->count = token_i; - DfrReturn(LexResult_Finished); + DrReturn(LexResult_Finished); } -FCPP_LINK Cpp_Lex_Result -cpp_lex_nonalloc_null_end_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech size, - Cpp_Token_Array *token_array_out, i32_4tech max_tokens_out){ +internal Cpp_Lex_Result +cpp_lex_nonalloc_null_end_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32 size, + Cpp_Token_Array *token_array_out, i32 max_tokens_out){ Cpp_Token_Array temp_array = *token_array_out; if (temp_array.max_count > temp_array.count + max_tokens_out){ temp_array.max_count = temp_array.count + max_tokens_out; @@ -1436,8 +1385,8 @@ cpp_lex_nonalloc_null_end_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech return(result); } -FCPP_LINK Cpp_Lex_Result -cpp_lex_nonalloc_no_null_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech size, i32_4tech full_size, +internal Cpp_Lex_Result +cpp_lex_nonalloc_no_null_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32 size, i32 full_size, Cpp_Token_Array *token_array_out){ Cpp_Lex_Result result = 0; if (S_ptr->pos >= full_size){ @@ -1456,9 +1405,9 @@ cpp_lex_nonalloc_no_null_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech si return(result); } -FCPP_LINK Cpp_Lex_Result -cpp_lex_nonalloc_no_null_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech size, i32_4tech full_size, - Cpp_Token_Array *token_array_out, i32_4tech max_tokens_out){ +internal Cpp_Lex_Result +cpp_lex_nonalloc_no_null_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32 size, i32 full_size, + Cpp_Token_Array *token_array_out, i32 max_tokens_out){ Cpp_Token_Array temp_stack = *token_array_out; if (temp_stack.max_count > temp_stack.count + max_tokens_out){ temp_stack.max_count = temp_stack.count + max_tokens_out; @@ -1478,11 +1427,11 @@ cpp_lex_nonalloc_no_null_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech s return(result); } -#define HAS_NULL_TERM ((i32_4tech)(-1)) -#define NO_OUT_LIMIT ((i32_4tech)(-1)) +#define HAS_NULL_TERM ((i32)(-1)) +#define NO_OUT_LIMIT ((i32)(-1)) -API_EXPORT FCPP_LINK Cpp_Lex_Result -cpp_lex_step(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech size, i32_4tech full_size, Cpp_Token_Array *token_array_out, i32_4tech max_tokens_out)/* +API_EXPORT internal Cpp_Lex_Result +cpp_lex_step(Cpp_Lex_Data *S_ptr, char *chunk, i32 size, i32 full_size, Cpp_Token_Array *token_array_out, i32 max_tokens_out)/* DOC_PARAM(S_ptr, The lexer state. Go to the Cpp_Lex_Data section to see how to initialize the state.) DOC_PARAM(chunk, The first or next chunk of the file being lexed.) DOC_PARAM(size, The number of bytes in the chunk including the null terminator if the chunk ends in a null terminator. If the chunk ends in a null terminator the system will interpret it as the end of the file.) @@ -1541,8 +1490,8 @@ DOC_SEE(Cpp_Lex_Result) return(result); } -API_EXPORT FCPP_LINK Cpp_Lex_Data -cpp_lex_data_init(b32_4tech ignore_string_delims, Cpp_Keyword_Table keywords, Cpp_Keyword_Table preprocessor_words)/* +API_EXPORT internal Cpp_Lex_Data +cpp_lex_data_init(b32 ignore_string_delims, Cpp_Keyword_Table keywords, Cpp_Keyword_Table preprocessor_words)/* DOC_PARAM(ignore_string_delims, TODO) DOC_PARAM(keywords, TODO) DOC_PARAM(preprocessor_words, TODO) @@ -1551,13 +1500,13 @@ DOC_RETURN(A brand new lex state setup to lex from the beginning of the file.) DOC(Creates a new lex state in the form of a Cpp_Lex_Data struct and returns the struct.) */{ Cpp_Lex_Data data = {}; - data.ignore_string_delims = (b8_4tech)ignore_string_delims; + data.ignore_string_delims = (b8)ignore_string_delims; data.keyword_table = keywords; data.preprops_table = preprocessor_words; return(data); } -API_EXPORT FCPP_LINK void +API_EXPORT internal void cpp_rebase_tables(Cpp_Lex_Data *data, void *old_base, void *new_base) /* DOC_PARAM(data, The lex data in which to perform the rebase.) @@ -1565,32 +1514,32 @@ DOC_PARAM(old_base, The old base memory address in which the tables were stored. DOC_PARAM(new_base, The new base memory address in which the tables are or will be stored.) DOC(Updates the base address pointers for the all the tables in the lex data as if the data in the original memory chunk old_base was copied to new_base.) */{ - u8_4tech *old_base_ptr = (u8_4tech*)old_base; - u8_4tech *new_base_ptr = (u8_4tech*)new_base; + u8 *old_base_ptr = (u8*)old_base; + u8 *new_base_ptr = (u8*)new_base; - u8_4tech *ptr = (u8_4tech*)data->keyword_table.keywords; - data->keyword_table.keywords = (u64_4tech*)(ptr + (new_base_ptr - old_base_ptr)); + u8 *ptr = (u8*)data->keyword_table.keywords; + data->keyword_table.keywords = (u64*)(ptr + (new_base_ptr - old_base_ptr)); - ptr = (u8_4tech*)data->preprops_table.keywords; - data->preprops_table.keywords = (u64_4tech*)(ptr + (new_base_ptr - old_base_ptr)); + ptr = (u8*)data->preprops_table.keywords; + data->preprops_table.keywords = (u64*)(ptr + (new_base_ptr - old_base_ptr)); } -FCPP_LINK char -cpp_token_get_pp_state(u16_4tech bitfield){ +internal char +cpp_token_get_pp_state(u16 bitfield){ return (char)(bitfield); } -FCPP_LINK void -cpp_shift_token_starts(Cpp_Token_Array *array, i32_4tech from_token_i, i32_4tech shift_amount){ +internal void +cpp_shift_token_starts(Cpp_Token_Array *array, i32 from_token_i, i32 shift_amount){ Cpp_Token *token = array->tokens + from_token_i; - i32_4tech count = array->count, i = 0; + i32 count = array->count, i = 0; for (i = from_token_i; i < count; ++i, ++token){ token->start += shift_amount; } } -FCPP_LINK Cpp_Token -cpp_index_array(Cpp_Token_Array *array, i32_4tech file_size, i32_4tech index){ +internal Cpp_Token +cpp_index_array(Cpp_Token_Array *array, i32 file_size, i32 index){ Cpp_Token result; if (index < array->count){ result = array->tokens[index]; @@ -1605,8 +1554,8 @@ cpp_index_array(Cpp_Token_Array *array, i32_4tech file_size, i32_4tech index){ return(result); } -API_EXPORT FCPP_LINK Cpp_Relex_Range -cpp_get_relex_range(Cpp_Token_Array *array, i32_4tech start_pos, i32_4tech end_pos) +API_EXPORT internal Cpp_Relex_Range +cpp_get_relex_range(Cpp_Token_Array *array, i32 start_pos, i32 end_pos) /* DOC_PARAM(array, A pointer to the token array that will be modified by the relex, this array should already contain the tokens for the previous state of the file.) @@ -1625,7 +1574,7 @@ DOC_PARAM(end_pos, The end position of the edited region of the file. In particu get_result = cpp_get_token(*array, end_pos); range.end_token_index = get_result.token_index; - i32_4tech token_start = 0; + i32 token_start = 0; if (range.end_token_index >= 0){ token_start = array->tokens[range.end_token_index].start; } @@ -1639,8 +1588,8 @@ DOC_PARAM(end_pos, The end position of the edited region of the file. In particu return(range); } -API_EXPORT FCPP_LINK Cpp_Relex_Data -cpp_relex_init(Cpp_Token_Array *array, i32_4tech start_pos, i32_4tech end_pos, i32_4tech character_shift_amount, b32_4tech ignore_string_delims, Cpp_Keyword_Table keywords, Cpp_Keyword_Table preprocessor_words) +API_EXPORT internal Cpp_Relex_Data +cpp_relex_init(Cpp_Token_Array *array, i32 start_pos, i32 end_pos, i32 character_shift_amount, b32 ignore_string_delims, Cpp_Keyword_Table keywords, Cpp_Keyword_Table preprocessor_words) /* DOC_PARAM(array, A pointer to the token array that will be modified by the relex, this array should already contain the tokens for the previous state of the file.) DOC_PARAM(start_pos, The start position of the edited region of the file. The start and end points are based on the edited region of the file before the edit.) @@ -1688,7 +1637,7 @@ DOC_SEE(cpp_relex_is_start_chunk) return(state); } -API_EXPORT FCPP_LINK i32_4tech +API_EXPORT internal i32 cpp_relex_start_position(Cpp_Relex_Data *S_ptr) /* DOC_PARAM(S_ptr, A pointer to a state that is done with the first stage of initialization (cpp_relex_init)) @@ -1703,12 +1652,12 @@ DOC_SEE(cpp_relex_init) DOC_SEE(cpp_relex_declare_first_chunk_position) */{ - i32_4tech result = S_ptr->relex_start_position; + i32 result = S_ptr->relex_start_position; return(result); } -API_EXPORT FCPP_LINK void -cpp_relex_declare_first_chunk_position(Cpp_Relex_Data *S_ptr, i32_4tech position) +API_EXPORT internal void +cpp_relex_declare_first_chunk_position(Cpp_Relex_Data *S_ptr, i32 position) /* DOC_PARAM(S_ptr, A pointer to a state that is done with the first stage of initialization (cpp_relex_init)) DOC_PARAM(position, The start position of the first chunk that will be fed to the relex process.) @@ -1726,8 +1675,8 @@ DOC_SEE(cpp_relex_start_position) S_ptr->lex.chunk_pos = position; } -API_EXPORT FCPP_LINK i32_4tech -cpp_relex_is_start_chunk(Cpp_Relex_Data *S_ptr, char *chunk, i32_4tech chunk_size) +API_EXPORT internal i32 +cpp_relex_is_start_chunk(Cpp_Relex_Data *S_ptr, char *chunk, i32 chunk_size) /* DOC_PARAM(S_ptr, A pointer to a state that is done with the first stage of initialization (cpp_relex_init)) DOC_PARAM(chunk, The chunk to check.) @@ -1744,11 +1693,11 @@ in the one and only call to cpp_relex_step.) DOC_SEE(cpp_relex_init) */{ - i32_4tech pos = S_ptr->relex_start_position; - i32_4tech start = S_ptr->lex.chunk_pos; - i32_4tech end = start + chunk_size; + i32 pos = S_ptr->relex_start_position; + i32 start = S_ptr->lex.chunk_pos; + i32 end = start + chunk_size; - i32_4tech good_chunk = 0; + i32 good_chunk = 0; if (start <= pos && pos < end){ good_chunk = 1; } @@ -1765,8 +1714,8 @@ DOC_SEE(cpp_relex_init) return(good_chunk); } -API_EXPORT FCPP_LINK Cpp_Lex_Result -cpp_relex_step(Cpp_Relex_Data *S_ptr, char *chunk, i32_4tech chunk_size, i32_4tech full_size, +API_EXPORT internal Cpp_Lex_Result +cpp_relex_step(Cpp_Relex_Data *S_ptr, char *chunk, i32 chunk_size, i32 full_size, Cpp_Token_Array *array, Cpp_Token_Array *relex_array) /* DOC_PARAM(S_ptr, A pointer to a fully initiazed relex state.) @@ -1821,8 +1770,8 @@ DOC_SEE(cpp_relex_abort) Cpp_Lex_Result step_result = LexResult_Finished; switch (S.__pc__){ - DfrCase(1); - DfrCase(2); + DrCase(1); + DrCase(2); } cpp_shift_token_starts(array, S.end_token_index, S.character_shift_amount); @@ -1855,13 +1804,13 @@ DOC_SEE(cpp_relex_abort) case LexResult_NeedChunk: { S_ptr->result_state = LexResult_NeedChunk; - DfrYield(1, LexResult_NeedChunk); + DrYield(1, LexResult_NeedChunk); }break; case LexResult_NeedTokenMemory: { S_ptr->result_state = LexResult_NeedTokenMemory; - DfrYield(2, LexResult_NeedTokenMemory); + DrYield(2, LexResult_NeedTokenMemory); }break; case LexResult_Finished: goto double_break; @@ -1870,11 +1819,11 @@ DOC_SEE(cpp_relex_abort) double_break:; S_ptr->result_state = LexResult_Finished; - DfrReturn(LexResult_Finished); + DrReturn(LexResult_Finished); } -API_EXPORT FCPP_LINK i32_4tech -cpp_relex_get_new_count(Cpp_Relex_Data *S_ptr, i32_4tech current_count, Cpp_Token_Array *relex_array) +API_EXPORT internal i32 +cpp_relex_get_new_count(Cpp_Relex_Data *S_ptr, i32 current_count, Cpp_Token_Array *relex_array) /* DOC_PARAM(S_ptr, A pointer to a state that has gone through cpp_relex_step with a LexResult_Finished return.) DOC_PARAM(current_count, The count of tokens in the original array before the edit.) @@ -1884,11 +1833,11 @@ DOC(After getting a LexResult_Finished from cpp_relex_step, this call can be use the size the new array will have. If the original array doesn't have enough capacity to store the new array, it's capacity should be increased before passing to cpp_relex_complete.) */{ - i32_4tech result = -1; + i32 result = -1; if (S_ptr->result_state == LexResult_Finished){ - i32_4tech delete_amount = S_ptr->end_token_index - S_ptr->start_token_index; - i32_4tech shift_amount = relex_array->count - delete_amount; + i32 delete_amount = S_ptr->end_token_index - S_ptr->start_token_index; + i32 shift_amount = relex_array->count - delete_amount; result = current_count + shift_amount; } @@ -1899,13 +1848,13 @@ the new array, it's capacity should be increased before passing to cpp_relex_com #include #endif -FCPP_LINK void -cpp__block_move(void *dst, void *src, i32_4tech size){ +internal void +cpp__block_move(void *dst, void *src, i32 size){ #if !defined(FCPP_FORBID_MEMCPY) memmove(dst, src, size); #else // TODO(allen): find a way to write a fast one of these. - u8_4tech *d = (u8_4tech*)dst, *s = (u8_4tech*)src; + u8 *d = (u8*)dst, *s = (u8*)src; if (d < s || d >= s + size){ for (; size > 0; --size){ *(d++) = *(s++); @@ -1921,7 +1870,7 @@ cpp__block_move(void *dst, void *src, i32_4tech size){ #endif } -API_EXPORT FCPP_LINK void +API_EXPORT internal void cpp_relex_complete(Cpp_Relex_Data *S_ptr, Cpp_Token_Array *array, Cpp_Token_Array *relex_array) /* DOC_PARAM(S_ptr, A pointer to a state that has gone through cpp_relex_step with a LexResult_Finished return.) @@ -1932,11 +1881,11 @@ DOC(After getting a LexResult_Finished from cpp_relex_step, and ensuring that array has a large enough capacity by calling cpp_relex_get_new_count, this call does the necessary replacement of tokens in the array to make it match the new file.) */{ - i32_4tech delete_amount = S_ptr->end_token_index - S_ptr->start_token_index; - i32_4tech shift_amount = relex_array->count - delete_amount; + i32 delete_amount = S_ptr->end_token_index - S_ptr->start_token_index; + i32 shift_amount = relex_array->count - delete_amount; if (shift_amount != 0){ - i32_4tech shift_size = array->count - S_ptr->end_token_index; + i32 shift_size = array->count - S_ptr->end_token_index; if (shift_size > 0){ Cpp_Token *old_base = array->tokens + S_ptr->end_token_index; cpp__block_move(old_base + shift_amount, old_base, sizeof(Cpp_Token)*shift_size); @@ -1947,7 +1896,7 @@ does the necessary replacement of tokens in the array to make it match the new f cpp__block_move(array->tokens + S_ptr->start_token_index, relex_array->tokens, sizeof(Cpp_Token)*relex_array->count); } -API_EXPORT FCPP_LINK void +API_EXPORT internal void cpp_relex_abort(Cpp_Relex_Data *S_ptr, Cpp_Token_Array *array) /* DOC_PARAM(S_ptr, A pointer to a state that has gone through at least one cpp_relex_step.) @@ -1967,8 +1916,8 @@ is dead.) #include #include -API_EXPORT FCPP_LINK Cpp_Token_Array -cpp_make_token_array(i32_4tech starting_max)/* +API_EXPORT internal Cpp_Token_Array +cpp_make_token_array(i32 starting_max)/* DOC_PARAM(starting_max, The number of tokens to initialize the array with.) DOC_RETURN(An empty Cpp_Token_Array with memory malloc'd for storing tokens.) DOC(This call allocates a Cpp_Token_Array with malloc for use in other @@ -1982,7 +1931,7 @@ used in the convenience functions.) return(token_array); } -API_EXPORT FCPP_LINK void +API_EXPORT internal void cpp_free_token_array(Cpp_Token_Array token_array)/* DOC_PARAM(token_array, An array previously allocated by cpp_make_token_array) DOC(This call frees a Cpp_Token_Array.) @@ -1991,8 +1940,8 @@ DOC_SEE(cpp_make_token_array) free(token_array.tokens); } -API_EXPORT FCPP_LINK void -cpp_resize_token_array(Cpp_Token_Array *token_array, i32_4tech new_max)/* +API_EXPORT internal void +cpp_resize_token_array(Cpp_Token_Array *token_array, i32 new_max)/* DOC_PARAM(token_array, An array previously allocated by cpp_make_token_array.) DOC_PARAM(new_max, The new maximum size the array should support. If this is not greater than the current size of the array the operation is ignored.) @@ -2012,7 +1961,7 @@ DOC_SEE(cpp_make_token_array) } } -API_EXPORT FCPP_LINK Cpp_Keyword_Table +API_EXPORT internal Cpp_Keyword_Table cpp_alloc_make_table_default(Cpp_Word_Table_Type type) /* DOC_PARAM(type, Specifies for which slot of the parser context to get a default result.) @@ -2023,7 +1972,7 @@ DOC_SEE(Cpp_Word_Table_Type) DOC_SEE(cpp_make_table) */{ Cpp_Keyword_Table result = {}; - umem_4tech size = cpp_get_table_memory_size_default(type); + umem size = cpp_get_table_memory_size_default(type); if (size > 0){ void *mem = malloc((size_t)size); result = cpp_make_table_default(type, mem, size); @@ -2031,7 +1980,7 @@ DOC_SEE(cpp_make_table) return(result); } -API_EXPORT FCPP_LINK void +API_EXPORT internal void cpp_free_table(Cpp_Keyword_Table table) /* DOC_PARAM(table, A table previously allocated by cpp_alloc_make_table_default.) @@ -2040,8 +1989,8 @@ DOC(Frees the memory allocated in a cpp_alloc_make_table call.) free(table.keywords); } -API_EXPORT FCPP_LINK void -cpp_lex_file(char *data, i32_4tech size, Cpp_Token_Array *token_array_out)/* +API_EXPORT internal void +cpp_lex_file(char *data, i32 size, Cpp_Token_Array *token_array_out)/* DOC_PARAM(data, The file data to be lexed in a single contiguous block.) DOC_PARAM(size, The number of bytes in data.) DOC_PARAM(token_array_out, The token array where the output tokens will be pushed. @@ -2069,13 +2018,13 @@ DOC_SEE(cpp_make_token_array) Cpp_Keyword_Table preprocessor_words = cpp_alloc_make_table_default(CPP_TABLE_PREPROCESSOR_DIRECTIVES); Cpp_Lex_Data S = cpp_lex_data_init(false, keywords, preprocessor_words); - i32_4tech quit = 0; + i32 quit = 0; char empty = 0; token_array_out->count = 0; for (;!quit;){ - i32_4tech result = cpp_lex_step(&S, data, size, HAS_NULL_TERM, token_array_out, NO_OUT_LIMIT); + i32 result = cpp_lex_step(&S, data, size, HAS_NULL_TERM, token_array_out, NO_OUT_LIMIT); switch (result){ case LexResult_Finished: { @@ -2098,7 +2047,7 @@ DOC_SEE(cpp_make_token_array) // NOTE(allen): We told the system to use all of the output memory // but we ran out anyway, so allocate more memory. We hereby assume // the stack was allocated using cpp_make_token_array. - i32_4tech new_max = 2*token_array_out->max_count + 1; + i32 new_max = 2*token_array_out->max_count + 1; cpp_resize_token_array(token_array_out, new_max); }break; } @@ -2110,12 +2059,6 @@ DOC_SEE(cpp_make_token_array) #endif - -#undef DfrYield -#undef DfrReturn -#undef DfrCase - - #endif // BOTTOM diff --git a/4coder_lib/4cpp_lexer_tables.c b/4coder_lib/4cpp_lexer_tables.c index 18c93903..1ad3d28f 100644 --- a/4coder_lib/4cpp_lexer_tables.c +++ b/4coder_lib/4cpp_lexer_tables.c @@ -1,4 +1,4 @@ -u16_4tech whitespace_fsm_eq_classes[] = { +u16 whitespace_fsm_eq_classes[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 20, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -17,15 +17,15 @@ u16_4tech whitespace_fsm_eq_classes[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -const i32_4tech num_whitespace_fsm_eq_classes = 3; +const i32 num_whitespace_fsm_eq_classes = 3; -u8_4tech whitespace_fsm_table[] = { +u8 whitespace_fsm_table[] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -u16_4tech int_fsm_eq_classes[] = { +u16 int_fsm_eq_classes[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -44,16 +44,16 @@ u16_4tech int_fsm_eq_classes[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -const i32_4tech num_int_fsm_eq_classes = 4; +const i32 num_int_fsm_eq_classes = 4; -u8_4tech int_fsm_table[] = { +u8 int_fsm_table[] = { 8, 9, 10, 11, 12, 13, 14, 15, 3, 5, 10, 6, 12, 7, 14, 15, 1, 9, 7, 7, 12, 13, 7, 15, 2, 4, 6, 11, 7, 13, 14, 15, }; -u16_4tech raw_str_eq_classes[] = { +u16 raw_str_eq_classes[] = { 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 9, 3, 12, 3, 3, 3, 3, 3, 15, 9, 3, 3, 3, 3, 3, 3, @@ -72,9 +72,9 @@ u16_4tech raw_str_eq_classes[] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, }; -const i32_4tech num_raw_str_eq_classes = 6; +const i32 num_raw_str_eq_classes = 6; -u8_4tech raw_str_table[] = { +u8 raw_str_table[] = { 3, 6, 6, 0, 1, 2, 3, 2, 2, @@ -83,11 +83,11 @@ u8_4tech raw_str_table[] = { 4, 1, 2, }; -u8_4tech raw_str_flags[] = { +u8 raw_str_flags[] = { 0x00,0x00,0x01, }; -u16_4tech normal_str_eq_classes[] = { +u16 normal_str_eq_classes[] = { 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 9, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, @@ -106,9 +106,9 @@ u16_4tech normal_str_eq_classes[] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, }; -const i32_4tech num_normal_str_eq_classes = 5; +const i32 num_normal_str_eq_classes = 5; -u8_4tech normal_str_table[] = { +u8 normal_str_table[] = { 4, 0, 4, 0, 0, 2, 4, 2, 4, @@ -116,11 +116,11 @@ u8_4tech normal_str_table[] = { 1, 0, 1, }; -u8_4tech normal_str_flags[] = { +u8 normal_str_flags[] = { 0x00,0x00,0x01, }; -u16_4tech include_str_eq_classes[] = { +u16 include_str_eq_classes[] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -139,15 +139,15 @@ u16_4tech include_str_eq_classes[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; -const i32_4tech num_include_str_eq_classes = 3; +const i32 num_include_str_eq_classes = 3; -u8_4tech include_str_table[] = { +u8 include_str_table[] = { 2, 0, 1, }; -u16_4tech normal_char_eq_classes[] = { +u16 normal_char_eq_classes[] = { 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 9, 3, 3, 3, 3, 3, 3, 3, 3, @@ -166,9 +166,9 @@ u16_4tech normal_char_eq_classes[] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, }; -const i32_4tech num_normal_char_eq_classes = 5; +const i32 num_normal_char_eq_classes = 5; -u8_4tech normal_char_table[] = { +u8 normal_char_table[] = { 4, 0, 4, 0, 0, 2, 4, 2, 4, @@ -176,11 +176,11 @@ u8_4tech normal_char_table[] = { 1, 0, 1, }; -u8_4tech normal_char_flags[] = { +u8 normal_char_flags[] = { 0x00,0x00,0x01, }; -u16_4tech main_fsm_eq_classes[] = { +u16 main_fsm_eq_classes[] = { 0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496, @@ -199,9 +199,9 @@ u16_4tech main_fsm_eq_classes[] = { 713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713, }; -const i32_4tech num_main_fsm_eq_classes = 32; +const i32 num_main_fsm_eq_classes = 32; -u8_4tech main_fsm_table[] = { +u8 main_fsm_table[] = { 31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, @@ -236,7 +236,7 @@ u8_4tech main_fsm_table[] = { 26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, }; -u16_4tech pp_include_fsm_eq_classes[] = { +u16 pp_include_fsm_eq_classes[] = { 0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496, @@ -255,9 +255,9 @@ u16_4tech pp_include_fsm_eq_classes[] = { 713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713, }; -const i32_4tech num_pp_include_fsm_eq_classes = 32; +const i32 num_pp_include_fsm_eq_classes = 32; -u8_4tech pp_include_fsm_table[] = { +u8 pp_include_fsm_table[] = { 31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, @@ -292,7 +292,7 @@ u8_4tech pp_include_fsm_table[] = { 26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, }; -u16_4tech pp_macro_fsm_eq_classes[] = { +u16 pp_macro_fsm_eq_classes[] = { 0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496, @@ -311,9 +311,9 @@ u16_4tech pp_macro_fsm_eq_classes[] = { 713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713, }; -const i32_4tech num_pp_macro_fsm_eq_classes = 32; +const i32 num_pp_macro_fsm_eq_classes = 32; -u8_4tech pp_macro_fsm_table[] = { +u8 pp_macro_fsm_table[] = { 31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, @@ -348,7 +348,7 @@ u8_4tech pp_macro_fsm_table[] = { 26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, }; -u16_4tech pp_identifier_fsm_eq_classes[] = { +u16 pp_identifier_fsm_eq_classes[] = { 0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496, @@ -367,9 +367,9 @@ u16_4tech pp_identifier_fsm_eq_classes[] = { 713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713, }; -const i32_4tech num_pp_identifier_fsm_eq_classes = 32; +const i32 num_pp_identifier_fsm_eq_classes = 32; -u8_4tech pp_identifier_fsm_table[] = { +u8 pp_identifier_fsm_table[] = { 31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, @@ -404,7 +404,7 @@ u8_4tech pp_identifier_fsm_table[] = { 26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, }; -u16_4tech pp_body_if_fsm_eq_classes[] = { +u16 pp_body_if_fsm_eq_classes[] = { 0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496, @@ -423,9 +423,9 @@ u16_4tech pp_body_if_fsm_eq_classes[] = { 713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713, }; -const i32_4tech num_pp_body_if_fsm_eq_classes = 32; +const i32 num_pp_body_if_fsm_eq_classes = 32; -u8_4tech pp_body_if_fsm_table[] = { +u8 pp_body_if_fsm_table[] = { 31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, @@ -460,7 +460,7 @@ u8_4tech pp_body_if_fsm_table[] = { 26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, }; -u16_4tech pp_body_fsm_eq_classes[] = { +u16 pp_body_fsm_eq_classes[] = { 0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496, @@ -479,9 +479,9 @@ u16_4tech pp_body_fsm_eq_classes[] = { 713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713, }; -const i32_4tech num_pp_body_fsm_eq_classes = 32; +const i32 num_pp_body_fsm_eq_classes = 32; -u8_4tech pp_body_fsm_table[] = { +u8 pp_body_fsm_table[] = { 31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, @@ -516,7 +516,7 @@ u8_4tech pp_body_fsm_table[] = { 26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, }; -u16_4tech pp_number_fsm_eq_classes[] = { +u16 pp_number_fsm_eq_classes[] = { 0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496, @@ -535,9 +535,9 @@ u16_4tech pp_number_fsm_eq_classes[] = { 713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713, }; -const i32_4tech num_pp_number_fsm_eq_classes = 32; +const i32 num_pp_number_fsm_eq_classes = 32; -u8_4tech pp_number_fsm_table[] = { +u8 pp_number_fsm_table[] = { 31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, @@ -572,7 +572,7 @@ u8_4tech pp_number_fsm_table[] = { 26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, }; -u16_4tech pp_error_fsm_eq_classes[] = { +u16 pp_error_fsm_eq_classes[] = { 0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, @@ -591,15 +591,15 @@ u16_4tech pp_error_fsm_eq_classes[] = { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, }; -const i32_4tech num_pp_error_fsm_eq_classes = 3; +const i32 num_pp_error_fsm_eq_classes = 3; -u8_4tech pp_error_fsm_table[] = { +u8 pp_error_fsm_table[] = { 31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, }; -u16_4tech pp_junk_fsm_eq_classes[] = { +u16 pp_junk_fsm_eq_classes[] = { 0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496, @@ -618,9 +618,9 @@ u16_4tech pp_junk_fsm_eq_classes[] = { 713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713, }; -const i32_4tech num_pp_junk_fsm_eq_classes = 32; +const i32 num_pp_junk_fsm_eq_classes = 32; -u8_4tech pp_junk_fsm_table[] = { +u8 pp_junk_fsm_table[] = { 31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, 0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, @@ -655,7 +655,7 @@ u8_4tech pp_junk_fsm_table[] = { 26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, }; -u16_4tech no_string_fsm_eq_classes[] = { +u16 no_string_fsm_eq_classes[] = { 0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 124,155,186,217,248,155,279,186,310,310,341,372,310,403,434,465, @@ -674,9 +674,9 @@ u16_4tech no_string_fsm_eq_classes[] = { 651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651, }; -const i32_4tech num_no_string_fsm_eq_classes = 26; +const i32 num_no_string_fsm_eq_classes = 26; -u8_4tech no_string_fsm_table[] = { +u8 no_string_fsm_table[] = { 31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 32, 33, 34, 35, 62, 62, 62, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, 0, 32, 33, 34, 35, 62, 62, 62, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30, diff --git a/4coder_lib/4cpp_lexer_types.h b/4coder_lib/4cpp_lexer_types.h index d81461a6..0e419c30 100644 --- a/4coder_lib/4cpp_lexer_types.h +++ b/4coder_lib/4cpp_lexer_types.h @@ -392,9 +392,9 @@ DOC_SEE(cpp_make_token_array) HIDE_MEMBERS() */ STRUCT Cpp_Keyword_Table{ void *mem; - umem_4tech memsize; - u64_4tech *keywords; - u32_4tech max; + umem memsize; + u64 *keywords; + u32 max; }; /* DOC(Cpp_Lex_Data represents the state of the lexer so that the system may be resumable and the user can manage the lexer state and decide when to resume lexing with it. To create a new lexer state call cpp_lex_data_init. @@ -404,31 +404,31 @@ DOC_SEE(cpp_lex_data_init) HIDE_MEMBERS() */ STRUCT Cpp_Lex_Data{ char tb[32]; - i32_4tech tb_pos; - i32_4tech token_start; + i32 tb_pos; + i32 token_start; - i32_4tech pos; - i32_4tech pos_overide; - i32_4tech chunk_pos; + i32 pos; + i32 pos_overide; + i32 chunk_pos; Cpp_Lex_FSM fsm; - u8_4tech white_done; - u8_4tech pp_state; - u8_4tech completed; + u8 white_done; + u8 pp_state; + u8 completed; Cpp_Token token; char raw_delim[16]; - i32_4tech delim_length; + i32 delim_length; - b8_4tech str_raw; - b8_4tech str_include; - b8_4tech ignore_string_delims; + b8 str_raw; + b8 str_include; + b8 ignore_string_delims; Cpp_Keyword_Table keyword_table; Cpp_Keyword_Table preprops_table; - i32_4tech __pc__; + i32 __pc__; }; /* DOC(Cpp_Lex_Result is returned from the lexing engine to indicate why it stopped lexing.) */ diff --git a/4coder_lists.cpp b/4coder_lists.cpp index 840c96af..6f06bbc8 100644 --- a/4coder_lists.cpp +++ b/4coder_lists.cpp @@ -16,7 +16,6 @@ CUSTOM_DOC("A lister mode command that quits the list without executing any acti CUSTOM_COMMAND_SIG(lister__activate) CUSTOM_DOC("A lister mode command that activates the list's action on the highlighted item.") { - Partition *scratch = &global_part; Heap *heap = &global_heap; View_ID view = 0; get_active_view(app, AccessAll, &view); @@ -26,7 +25,7 @@ CUSTOM_DOC("A lister mode command that activates the list's action on the highli if (0 <= state->raw_item_index && state->raw_item_index < state->lister.data.options.count){ user_data = lister_get_user_data(&state->lister.data, state->raw_item_index); } - lister_call_activate_handler(app, scratch, heap, view, state, user_data, false); + lister_call_activate_handler(app, heap, view, state, user_data, false); } } @@ -77,7 +76,6 @@ CUSTOM_DOC("A lister mode command that dispatches to the lister's navigate down CUSTOM_COMMAND_SIG(lister__wheel_scroll) CUSTOM_DOC("A lister mode command that scrolls the list in response to the mouse wheel.") { - Partition *scratch = &global_part; View_ID view = 0; get_active_view(app, AccessAll, &view); GUI_Scroll_Vars scroll = {}; @@ -87,19 +85,18 @@ CUSTOM_DOC("A lister mode command that scrolls the list in response to the mouse view_set_scroll(app, view, scroll); Lister_State *state = view_get_lister_state(view); if (state->initialized){ - lister_update_ui(app, scratch, view, state); + lister_update_ui(app, view, state); } } CUSTOM_COMMAND_SIG(lister__mouse_press) CUSTOM_DOC("A lister mode command that beings a click interaction with a list item under the mouse.") { - Partition *scratch = &global_part; View_ID view = 0; get_active_view(app, AccessAll, &view); Lister_State *state = view_get_lister_state(view); if (state->initialized){ - UI_Item clicked = lister_get_clicked_item(app, view, scratch); + UI_Item clicked = lister_get_clicked_item(app, view); state->hot_user_data = clicked.user_data; } } @@ -107,15 +104,14 @@ CUSTOM_DOC("A lister mode command that beings a click interaction with a list it CUSTOM_COMMAND_SIG(lister__mouse_release) CUSTOM_DOC("A lister mode command that ends a click interaction with a list item under the mouse, possibly activating it.") { - Partition *scratch = &global_part; Heap *heap = &global_heap; View_ID view = 0; get_active_view(app, AccessAll, &view); Lister_State *state = view_get_lister_state(view); if (state->initialized && state->hot_user_data != 0){ - UI_Item clicked = lister_get_clicked_item(app, view, scratch); + UI_Item clicked = lister_get_clicked_item(app, view); if (state->hot_user_data == clicked.user_data){ - lister_call_activate_handler(app, scratch, heap, view, state, clicked.user_data, true); + lister_call_activate_handler(app, heap, view, state, clicked.user_data, true); } } state->hot_user_data = 0; @@ -124,19 +120,17 @@ CUSTOM_DOC("A lister mode command that ends a click interaction with a list item CUSTOM_COMMAND_SIG(lister__repaint) CUSTOM_DOC("A lister mode command that updates the lists UI data.") { - Partition *scratch = &global_part; View_ID view = 0; get_active_view(app, AccessAll, &view); Lister_State *state = view_get_lister_state(view); if (state->initialized){ - lister_update_ui(app, scratch, view, state); + lister_update_ui(app, view, state); } } CUSTOM_COMMAND_SIG(lister__write_character__default) CUSTOM_DOC("A lister mode command that inserts a new character to the text field.") { - Partition *scratch = &global_part; View_ID view = 0; get_active_view(app, AccessAll, &view); Lister_State *state = view_get_lister_state(view); @@ -145,11 +139,11 @@ CUSTOM_DOC("A lister mode command that inserts a new character to the text field u8 character[4]; u32 length = to_writable_character(in, character); if (length > 0){ - append(&state->lister.data.text_field, make_string(character, length)); - append(&state->lister.data.key_string, make_string(character, length)); + lister_append_text_field(&state->lister, SCu8(character, length)); + lister_append_key(&state->lister, SCu8(character, length)); state->item_index = 0; view_zero_scroll(app, view); - lister_update_ui(app, scratch, view, state); + lister_update_ui(app, view, state); } } } @@ -157,23 +151,21 @@ CUSTOM_DOC("A lister mode command that inserts a new character to the text field CUSTOM_COMMAND_SIG(lister__backspace_text_field__default) CUSTOM_DOC("A lister mode command that backspaces one character from the text field.") { - Partition *scratch = &global_part; View_ID view = 0; get_active_view(app, AccessAll, &view); Lister_State *state = view_get_lister_state(view); if (state->initialized){ - backspace_utf8(&state->lister.data.text_field); - backspace_utf8(&state->lister.data.key_string); + state->lister.data.text_field.string = backspace_utf8(state->lister.data.text_field.string); + state->lister.data.key_string.string = backspace_utf8(state->lister.data.key_string.string); state->item_index = 0; view_zero_scroll(app, view); - lister_update_ui(app, scratch, view, state); + lister_update_ui(app, view, state); } } CUSTOM_COMMAND_SIG(lister__move_up__default) CUSTOM_DOC("A lister mode command that moves the highlighted item one up in the list.") { - Partition *scratch = &global_part; View_ID view = 0; get_active_view(app, AccessAll, &view); Lister_State *state = view_get_lister_state(view); @@ -183,14 +175,13 @@ CUSTOM_DOC("A lister mode command that moves the highlighted item one up in the state->item_index = state->item_count_after_filter - 1; } state->set_view_vertical_focus_to_item = true; - lister_update_ui(app, scratch, view, state); + lister_update_ui(app, view, state); } } CUSTOM_COMMAND_SIG(lister__move_down__default) CUSTOM_DOC("A lister mode command that moves the highlighted item one down in the list.") { - Partition *scratch = &global_part; View_ID view = 0; get_active_view(app, AccessAll, &view); Lister_State *state = view_get_lister_state(view); @@ -200,14 +191,13 @@ CUSTOM_DOC("A lister mode command that moves the highlighted item one down in th state->item_index = 0; } state->set_view_vertical_focus_to_item = true; - lister_update_ui(app, scratch, view, state); + lister_update_ui(app, view, state); } } CUSTOM_COMMAND_SIG(lister__write_character__file_path) CUSTOM_DOC("A lister mode command that inserts a character into the text field of a file system list.") { - Partition *scratch = &global_part; View_ID view = 0; get_active_view(app, AccessAll, &view); Lister_State *state = view_get_lister_state(view); @@ -216,16 +206,17 @@ CUSTOM_DOC("A lister mode command that inserts a character into the text field o u8 character[4]; u32 length = to_writable_character(in, character); if (length > 0){ - append(&state->lister.data.text_field, make_string(character, length)); - copy(&state->lister.data.key_string, front_of_directory(state->lister.data.text_field)); + lister_append_text_field(&state->lister, SCu8(character, length)); + String_Const_u8 front_name = string_front_of_path(state->lister.data.text_field.string); + lister_set_key(&state->lister, front_name); if (character[0] == '/' || character[0] == '\\'){ - String new_hot = state->lister.data.text_field; - directory_set_hot(app, new_hot.str, new_hot.size); + String_Const_u8 new_hot = state->lister.data.text_field.string; + set_hot_directory(app, new_hot); lister_call_refresh_handler(app, &state->lister); } state->item_index = 0; view_zero_scroll(app, view); - lister_update_ui(app, scratch, view, state); + lister_update_ui(app, view, state); } } } @@ -233,17 +224,17 @@ CUSTOM_DOC("A lister mode command that inserts a character into the text field o CUSTOM_COMMAND_SIG(lister__backspace_text_field__file_path) CUSTOM_DOC("A lister mode command that backspaces one character from the text field of a file system list.") { - Partition *scratch = &global_part; View_ID view = 0; get_active_view(app, AccessAll, &view); Lister_State *state = view_get_lister_state(view); if (state->initialized){ if (state->lister.data.text_field.size > 0){ char last_char = state->lister.data.text_field.str[state->lister.data.text_field.size - 1]; - backspace_utf8(&state->lister.data.text_field); + state->lister.data.text_field.string = backspace_utf8(state->lister.data.text_field.string); if (last_char == '/' || last_char == '\\'){ User_Input input = get_command_input(app); - String new_hot = path_of_directory(state->lister.data.text_field); + String_Const_u8 text_field = state->lister.data.text_field.string; + String_Const_u8 new_hot = string_remove_last_folder(text_field); b32 is_modified = (input.key.modifiers[MDFR_SHIFT_INDEX] || input.key.modifiers[MDFR_CONTROL_INDEX] || input.key.modifiers[MDFR_ALT_INDEX] || @@ -252,20 +243,22 @@ CUSTOM_DOC("A lister mode command that backspaces one character from the text fi if (whole_word_backspace){ state->lister.data.text_field.size = new_hot.size; } - directory_set_hot(app, new_hot.str, new_hot.size); + set_hot_directory(app, new_hot); // TODO(allen): We have to protect against lister_call_refresh_handler changing // the text_field here. Clean this up. - String dingus = state->lister.data.text_field; + String_u8 dingus = state->lister.data.text_field; lister_call_refresh_handler(app, &state->lister); state->lister.data.text_field = dingus; } else{ - copy(&state->lister.data.key_string, front_of_directory(state->lister.data.text_field)); + String_Const_u8 text_field = state->lister.data.text_field.string; + String_Const_u8 new_key = string_front_of_path(text_field); + lister_set_key(&state->lister, new_key); } state->item_index = 0; view_zero_scroll(app, view); - lister_update_ui(app, scratch, view, state); + lister_update_ui(app, view, state); } } } @@ -273,7 +266,6 @@ CUSTOM_DOC("A lister mode command that backspaces one character from the text fi CUSTOM_COMMAND_SIG(lister__write_character__fixed_list) CUSTOM_DOC("A lister mode command that handles input for the fixed sure to kill list.") { - Partition *scratch = &global_part; Heap *heap = &global_heap; View_ID view = 0; get_active_view(app, AccessAll, &view); @@ -289,14 +281,15 @@ CUSTOM_DOC("A lister mode command that handles input for the fixed sure to kill node != 0; node = node->next){ char *hotkeys = (char*)(node + 1); - if (has_substr(hotkeys, make_string(character, length))){ + String_Const_u8 hot_key_string = SCu8(hotkeys); + if (string_find_first(hot_key_string, SCu8(character, length)) < hot_key_string.size){ user_data = node->user_data; did_shortcut_key = true; break; } } if (did_shortcut_key){ - lister_call_activate_handler(app, scratch, heap, view, state, user_data, false); + lister_call_activate_handler(app, heap, view, state, user_data, false); } } } @@ -330,24 +323,24 @@ begin_integrated_lister__with_refresh_handler(Application_Links *app, char *quer void *user_data, i32 user_data_size, View_ID view){ if (handlers.refresh != 0){ - Partition *scratch = &global_part; Heap *heap = &global_heap; view_begin_ui_mode(app, view); view_set_setting(app, view, ViewSetting_UICommandMap, default_lister_ui_map); Lister_State *state = view_get_lister_state(view); init_lister_state(app, state, heap); lister_first_init(app, &state->lister, user_data, user_data_size); - lister_set_query_string(&state->lister.data, query_string); + lister_set_query(&state->lister, query_string); state->lister.data.handlers = handlers; handlers.refresh(app, &state->lister); - lister_update_ui(app, scratch, view, state); + lister_update_ui(app, view, state); } else{ - char space[256]; - String str = make_fixed_width_string(space); - append(&str, "ERROR: No refresh handler specified for lister (query_string = \""); - append(&str, query_string); - append(&str, "\")\n"); + Scratch_Block scratch(app); + List_String_Const_u8 list = {}; + string_list_push(scratch, &list, string_u8_litexpr("ERROR: No refresh handler specified for lister (query_string = \"")); + string_list_push(scratch, &list, SCu8(query_string)); + string_list_push(scratch, &list, string_u8_litexpr("\")\n")); + String_Const_u8 str = string_list_flatten(scratch, list); print_message(app, str); } } @@ -368,7 +361,6 @@ begin_integrated_lister__basic_list(Application_Links *app, char *query_string, Lister_Option *options, i32 option_count, i32 estimated_string_space_size, View_ID view){ - Partition *scratch = &global_part; Heap *heap = &global_heap; view_begin_ui_mode(app, view); view_set_setting(app, view, ViewSetting_UICommandMap, default_lister_ui_map); @@ -378,10 +370,10 @@ begin_integrated_lister__basic_list(Application_Links *app, char *query_string, for (i32 i = 0; i < option_count; i += 1){ lister_add_item(&state->lister, options[i].string, options[i].status, options[i].user_data, 0); } - lister_set_query_string(&state->lister.data, query_string); + lister_set_query(&state->lister, query_string); state->lister.data.handlers = lister_get_default_handlers(); state->lister.data.handlers.activate = activate; - lister_update_ui(app, scratch, view, state); + lister_update_ui(app, view, state); } static void @@ -391,7 +383,6 @@ begin_integrated_lister__with_fixed_options(Application_Links *app, char *query_ Lister_Fixed_Option *options, i32 option_count, i32 estimated_string_space_size, View_ID view){ - Partition *scratch = &global_part; Heap *heap = &global_heap; view_begin_ui_mode(app, view); view_set_setting(app, view, ViewSetting_UICommandMap, default_lister_ui_map); @@ -400,18 +391,18 @@ begin_integrated_lister__with_fixed_options(Application_Links *app, char *query_ lister_first_init(app, &state->lister, user_data, user_data_size); for (i32 i = 0; i < option_count; i += 1){ char *shortcut_chars = options[i].shortcut_chars; - i32 shortcut_chars_length = str_size(shortcut_chars); + umem shortcut_chars_length = cstring_length(shortcut_chars); void *extra = lister_add_item(&state->lister, - make_string_slowly(options[i].string), - make_string_slowly(options[i].status), + SCu8(options[i].string), + SCu8(options[i].status), options[i].user_data, shortcut_chars_length + 1); memcpy(extra, shortcut_chars, shortcut_chars_length + 1); } - lister_set_query_string(&state->lister.data, query_string); + lister_set_query(&state->lister, query_string); state->lister.data.handlers = handlers; state->lister.data.handlers.refresh = 0; - lister_update_ui(app, scratch, view, state); + lister_update_ui(app, view, state); } static void @@ -437,7 +428,6 @@ begin_integrated_lister__theme_list(Application_Links *app, char *query_string, Lister_UI_Option *options, i32 option_count, i32 estimated_string_space_size, View_ID view){ - Partition *scratch = &global_part; Heap *heap = &global_heap; view_begin_ui_mode(app, view); view_set_setting(app, view, ViewSetting_UICommandMap, default_lister_ui_map); @@ -447,14 +437,14 @@ begin_integrated_lister__theme_list(Application_Links *app, char *query_string, state->lister.data.theme_list = true; for (i32 i = 0; i < option_count; i += 1){ lister_add_theme_item(&state->lister, - make_string_slowly(options[i].string), + SCu8(options[i].string), options[i].index, options[i].user_data, 0); } - lister_set_query_string(&state->lister.data, query_string); + lister_set_query(&state->lister, query_string); state->lister.data.handlers = handlers; state->lister.data.handlers.refresh = 0; - lister_update_ui(app, scratch, view, state); + lister_update_ui(app, view, state); } static void @@ -479,36 +469,22 @@ static void generate_all_buffers_list__output_buffer(Application_Links *app, Lister *lister, Buffer_ID buffer){ Dirty_State dirty = 0; buffer_get_dirty_state(app, buffer, &dirty); - String status = {}; + String_Const_u8 status = {}; switch (dirty){ - case DirtyState_UnsavedChanges: status = make_lit_string("*"); break; - case DirtyState_UnloadedChanges: status = make_lit_string("!"); break; - case DirtyState_UnsavedChangesAndUnloadedChanges: status = make_lit_string("*!"); break; + case DirtyState_UnsavedChanges: status = string_u8_litexpr("*"); break; + case DirtyState_UnloadedChanges: status = string_u8_litexpr("!"); break; + case DirtyState_UnsavedChangesAndUnloadedChanges: status = string_u8_litexpr("*!"); break; } Arena *scratch = context_get_arena(app); - Temp_Memory_Arena temp = begin_temp_memory(scratch); - String buffer_name = buffer_push_unique_buffer_name(app, buffer, scratch); + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 buffer_name = buffer_push_unique_buffer_name(app, buffer, scratch); lister_add_item(lister, buffer_name, status, IntAsPtr(buffer), 0); - end_temp_memory(temp); + end_temp(temp); } static void generate_all_buffers_list(Application_Links *app, Lister *lister){ - i32 buffer_count = get_buffer_count(app); - i32 memory_size = 0; - memory_size += buffer_count*(sizeof(Lister_Node) + 3); - { - Buffer_ID buffer = 0; - for (get_buffer_next(app, 0, AccessAll, &buffer); - buffer != 0; - get_buffer_next(app, buffer, AccessAll, &buffer)){ - i32 name_length = 0; - buffer_get_unique_buffer_name(app, buffer, 0, &name_length); - memory_size += name_length; - } - } - - lister_begin_new_item_set(app, lister, memory_size); + lister_begin_new_item_set(app, lister); Buffer_ID buffers_currently_being_viewed[16]; i32 currently_viewed_buffer_count = 0; @@ -573,44 +549,32 @@ generate_all_buffers_list(Application_Links *app, Lister *lister){ static void generate_hot_directory_file_list(Application_Links *app, Lister *lister){ - Temp_Memory_Arena temp = begin_temp_memory(&lister->arena); - String hot = get_hot_directory(app, &lister->arena); - if (hot.size > 0 && hot.str[hot.size - 1] != '/' && hot.str[hot.size - 1] != '\\'){ - if (push_array(&lister->arena, char, 1) != 0){ - hot.memory_size += 1; - append_s_char(&hot, '/'); - } + Temp_Memory temp = begin_temp(&lister->arena); + String_Const_u8 hot = push_hot_directory(app, &lister->arena); + if (!character_is_slash(string_get_character(hot, hot.size - 1))){ + hot = string_u8_pushf(&lister->arena, "%.*s/", string_expand(hot)); } - lister_set_text_field_string(&lister->data, hot); - lister_set_key_string(&lister->data, front_of_directory(hot)); + lister_set_text_field(lister, hot); + lister_set_key(lister, string_front_of_path(hot)); - File_List file_list = get_file_list(app, hot.str, hot.size); - end_temp_memory(temp); + File_List file_list = {}; + get_file_list(app, hot, &file_list); + end_temp(temp); File_Info *one_past_last = file_list.infos + file_list.count; - i32 memory_requirement = 0; - memory_requirement += lister->data.user_data_size; - memory_requirement += file_list.count*(sizeof(Lister_Node) + 10); - memory_requirement += hot.size + 2; - for (File_Info *info = file_list.infos; - info < one_past_last; - info += 1){ - memory_requirement += info->filename_len; - } + lister_begin_new_item_set(app, lister); - lister_begin_new_item_set(app, lister, memory_requirement); - - hot = get_hot_directory(app, &lister->arena); + hot = push_hot_directory(app, &lister->arena); push_align(&lister->arena, 8); if (hot.str != 0){ - String empty_string = make_lit_string(""); - Lister_Prealloced_String empty_string_prealloced = {empty_string}; + String_Const_u8 empty_string = string_u8_litexpr(""); + Lister_Prealloced_String empty_string_prealloced = lister_prealloced(empty_string); for (File_Info *info = file_list.infos; info < one_past_last; info += 1){ if (!info->folder) continue; - String file_name = string_push_f(&lister->arena, "%.*s/", info->filename_len, info->filename); + String_Const_u8 file_name = string_u8_pushf(&lister->arena, "%.*s/", info->filename_len, info->filename); lister_add_item(lister, lister_prealloced(file_name), empty_string_prealloced, file_name.str, 0); } @@ -618,7 +582,7 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){ info < one_past_last; info += 1){ if (info->folder) continue; - String file_name = string_push_copy(&lister->arena, make_string(info->filename, info->filename_len)); + String_Const_u8 file_name = string_copy(&lister->arena, SCu8(info->filename, info->filename_len)); char *is_loaded = ""; char *status_flag = ""; @@ -626,19 +590,14 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){ Buffer_ID buffer = {}; { - Temp_Memory_Arena path_temp = begin_temp_memory(&lister->arena); - String full_file_path = {}; - full_file_path.size = 0; - full_file_path.memory_size = hot.size + 1 + info->filename_len + 1; - full_file_path.str = push_array(&lister->arena, char, full_file_path.memory_size); - append(&full_file_path, hot); - if (full_file_path.size == 0 || - char_is_slash(full_file_path.str[full_file_path.size - 1])){ - append(&full_file_path, "/"); - } - append(&full_file_path, make_string(info->filename, info->filename_len)); + Temp_Memory path_temp = begin_temp(&lister->arena); + List_String_Const_u8 list = {}; + string_list_push(&lister->arena, &list, hot); + string_list_push_overlap(&lister->arena, &list, '/', + SCu8(info->filename, info->filename_len)); + String_Const_u8 full_file_path = string_list_flatten(&lister->arena, list); get_buffer_by_file_name(app, full_file_path, AccessAll, &buffer); - end_temp_memory(path_temp); + end_temp(path_temp); } if (buffer != 0){ @@ -651,7 +610,7 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){ case DirtyState_UnsavedChangesAndUnloadedChanges: status_flag = " *!"; break; } } - String status = string_push_f(&lister->arena, "%s%s", is_loaded, status_flag); + String_Const_u8 status = string_u8_pushf(&lister->arena, "%s%s", is_loaded, status_flag); lister_add_item(lister, lister_prealloced(file_name), lister_prealloced(status), file_name.str, 0); } } @@ -689,8 +648,7 @@ enum{ }; static void -activate_confirm_kill(Application_Links *app, Partition *scratch, Heap *heap, View_ID view, Lister_State *state, - String text_field, void *user_data, b32 clicked){ +activate_confirm_kill(Application_Links *app, Heap *heap, View_ID view, Lister_State *state, String_Const_u8 text_field, void *user_data, b32 clicked){ i32 behavior = (i32)PtrAsInt(user_data); Buffer_ID buffer_id = *(Buffer_ID*)(state->lister.data.user_data); switch (behavior){ @@ -699,31 +657,28 @@ activate_confirm_kill(Application_Links *app, Partition *scratch, Heap *heap, Vi case SureToKill_Yes: { - kill_buffer(app, buffer_identifier(buffer_id), BufferKill_AlwaysKill); + Buffer_Kill_Result ignore = 0; + buffer_kill(app, buffer_id, BufferKill_AlwaysKill, &ignore); }break; case SureToKill_Save: { - Arena *scratch_arena = context_get_arena(app); - Temp_Memory_Arena temp = begin_temp_memory(scratch_arena); - String file_name = buffer_push_file_name(app, buffer_id, scratch_arena); - + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 file_name = buffer_push_file_name(app, buffer_id, scratch); if (buffer_save(app, buffer_id, file_name, BufferSave_IgnoreDirtyFlag)){ buffer_kill(app, buffer_id, BufferKill_AlwaysKill, 0); } else{ - char space[256]; - String str = make_fixed_width_string(space); - append(&str, "Did not close '"); - append(&str, file_name); - append(&str, "' because it did not successfully save.\n"); - print_message(app, str.str, str.size); + String_Const_u8 str = string_u8_pushf(scratch, "Did not close '%.*s' because it did not successfully save.", + string_expand(file_name)); + print_message(app, str); } - end_temp_memory(temp); + end_temp(temp); }break; } - lister_default(app, scratch, heap, view, state, ListerActivation_Finished); + lister_default(app, heap, view, state, ListerActivation_Finished); } static void @@ -741,9 +696,9 @@ do_gui_sure_to_kill(Application_Links *app, Buffer_ID buffer, View_ID view){ } static void -activate_confirm_close_4coder(Application_Links *app, Partition *scratch, Heap *heap, +activate_confirm_close_4coder(Application_Links *app, Heap *heap, View_ID view, Lister_State *state, - String text_field, void *user_data, b32 clicked){ + String_Const_u8 text_field, void *user_data, b32 clicked){ i32 behavior = (i32)PtrAsInt(user_data); switch (behavior){ case SureToKill_No: @@ -762,8 +717,7 @@ activate_confirm_close_4coder(Application_Links *app, Partition *scratch, Heap * send_exit_signal(app); }break; } - lister_default(app, scratch, heap, view, state, ListerActivation_Finished); - + lister_default(app, heap, view, state, ListerActivation_Finished); } static void @@ -783,14 +737,14 @@ do_gui_sure_to_close_4coder(Application_Links *app, View_ID view){ //////////////////////////////// static void -activate_switch_buffer(Application_Links *app, Partition *scratch, Heap *heap, +activate_switch_buffer(Application_Links *app, Heap *heap, View_ID view, Lister_State *state, - String text_field, void *user_data, b32 activated_by_mouse){ + String_Const_u8 text_field, void *user_data, b32 activated_by_mouse){ if (user_data != 0){ Buffer_ID buffer_id = (Buffer_ID)(PtrAsInt(user_data)); view_set_buffer(app, view, buffer_id, SetBuffer_KeepOriginalGUI); } - lister_default(app, scratch, heap, view, state, ListerActivation_Finished); + lister_default(app, heap, view, state, ListerActivation_Finished); } CUSTOM_COMMAND_SIG(interactive_switch_buffer) @@ -803,10 +757,10 @@ CUSTOM_DOC("Interactively switch to an open buffer.") } static void -activate_kill_buffer(Application_Links *app, Partition *scratch, Heap *heap, +activate_kill_buffer(Application_Links *app, Heap *heap, View_ID view, struct Lister_State *state, - String text_field, void *user_data, b32 activated_by_mouse){ - lister_default(app, scratch, heap, view, state, ListerActivation_Finished); + String_Const_u8 text_field, void *user_data, b32 activated_by_mouse){ + lister_default(app, heap, view, state, ListerActivation_Finished); if (user_data != 0){ Buffer_ID buffer_id = (Buffer_ID)(PtrAsInt(user_data)); kill_buffer(app, buffer_identifier(buffer_id), view, 0); @@ -823,27 +777,27 @@ CUSTOM_DOC("Interactively kill an open buffer.") } static Lister_Activation_Code -activate_open_or_new__generic(Application_Links *app, Partition *scratch, View_ID view, - String path, String file_name, b32 is_folder, +activate_open_or_new__generic(Application_Links *app, View_ID view, + String_Const_u8 path, String_Const_u8 file_name, b32 is_folder, Buffer_Create_Flag flags){ Lister_Activation_Code result = 0; if (file_name.size == 0){ - char msg[] = "Zero length file_name passed to activate_open_or_new__generic\n"; - print_message(app, msg, sizeof(msg) - 1); +#define M "Zero length file_name passed to activate_open_or_new__generic\n" + print_message(app, string_u8_litexpr(M)); +#undef M result = ListerActivation_Finished; } else{ - Temp_Memory temp = begin_temp_memory(scratch); - String full_file_name = {}; - if (path.size == 0 || !char_is_slash(path.str[path.size - 1])){ - full_file_name = string_push_f(scratch, "%.*s/%.*s", path.size, path.str, file_name.size, file_name.str); - } - else{ - full_file_name = string_push_f(scratch, "%.*s%.*s", path.size, path.str, file_name.size, file_name.str); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 full_file_name = {}; + if (character_is_slash(string_get_character(path, path.size - 1))){ + path = string_chop(path, 1); } + full_file_name = string_u8_pushf(scratch, "%.*s/%.*s", string_expand(path), string_expand(file_name)); if (is_folder){ - directory_set_hot(app, full_file_name.str, full_file_name.size); + set_hot_directory(app, full_file_name); result = ListerActivation_ContinueAndRefresh; } else{ @@ -854,37 +808,38 @@ activate_open_or_new__generic(Application_Links *app, Partition *scratch, View_I } result = ListerActivation_Finished; } - end_temp_memory(temp); + end_temp(temp); } return(result); } static void -activate_open_or_new(Application_Links *app, Partition *scratch, Heap *heap, +activate_open_or_new(Application_Links *app, Heap *heap, View_ID view, struct Lister_State *state, - String text_field, void *user_data, b32 clicked){ + String_Const_u8 text_field, void *user_data, b32 clicked){ Lister_Activation_Code result = 0; - String file_name = {}; + String_Const_u8 file_name = {}; if (user_data == 0){ - file_name = front_of_directory(text_field); + file_name = string_front_of_path(text_field); } else{ - file_name = make_string_slowly((char*)user_data); + file_name = SCu8((u8*)user_data); } if (file_name.size == 0){ result = ListerActivation_Finished; } else{ - String path = state->lister.data.text_field; - if (path.size > 0 && !char_is_slash(path.str[path.size - 1])){ - path = path_of_directory(path); + String_Const_u8 path = state->lister.data.text_field.string; + if (!character_is_slash(string_get_character(path, path.size - 1))){ + path = string_remove_last_folder(path); } - b32 is_folder = (file_name.str[file_name.size - 1] == '/' && user_data != 0); + b32 is_folder = (character_is_slash(string_get_character(file_name, file_name.size - 1)) && + user_data != 0); Buffer_Create_Flag flags = 0; - result = activate_open_or_new__generic(app, scratch, view, path, file_name, is_folder, flags); + result = activate_open_or_new__generic(app, view, path, file_name, is_folder, flags); } - lister_default(app, scratch, heap, view, state, result); + lister_default(app, heap, view, state, result); } CUSTOM_COMMAND_SIG(interactive_open_or_new) @@ -897,13 +852,13 @@ CUSTOM_DOC("Interactively open a file out of the file system.") } static void -activate_new(Application_Links *app, Partition *scratch, Heap *heap, +activate_new(Application_Links *app, Heap *heap, View_ID view, struct Lister_State *state, - String text_field, void *user_data, b32 clicked){ + String_Const_u8 text_field, void *user_data, b32 clicked){ Lister_Activation_Code result = 0; - String file_name = front_of_directory(text_field); + String_Const_u8 file_name = string_front_of_path(text_field); if (user_data != 0){ - String item_name = make_string_slowly((char*)user_data); + String_Const_u8 item_name = SCu8((u8*)user_data); if (item_name.str[item_name.size - 1] == '/'){ file_name = item_name; } @@ -915,15 +870,16 @@ activate_new(Application_Links *app, Partition *scratch, Heap *heap, result = ListerActivation_Finished; } else{ - String path = state->lister.data.text_field; - if (path.size > 0 && !char_is_slash(path.str[path.size - 1])){ - path = path_of_directory(path); + String_Const_u8 path = state->lister.data.text_field.string; + if (character_is_slash(string_get_character(path, path.size - 1))){ + path = string_remove_last_folder(path); } - b32 is_folder = (file_name.str[file_name.size - 1] == '/' && user_data != 0); + b32 is_folder = (character_is_slash(string_get_character(file_name, file_name.size - 1)) && + user_data != 0); Buffer_Create_Flag flags = BufferCreate_AlwaysNew; - result = activate_open_or_new__generic(app, scratch, view, path, file_name, is_folder, flags); + result = activate_open_or_new__generic(app, view, path, file_name, is_folder, flags); } - lister_default(app, scratch, heap, view, state, result); + lister_default(app, heap, view, state, result); } CUSTOM_COMMAND_SIG(interactive_new) @@ -936,27 +892,28 @@ CUSTOM_DOC("Interactively creates a new file.") } static void -activate_open(Application_Links *app, Partition *scratch, Heap *heap, +activate_open(Application_Links *app, Heap *heap, View_ID view, struct Lister_State *state, - String text_field, void *user_data, b32 clicked){ + String_Const_u8 text_field, void *user_data, b32 clicked){ Lister_Activation_Code result = 0; - String file_name = {}; + String_Const_u8 file_name = {}; if (user_data != 0){ - file_name = make_string_slowly((char*)user_data); + file_name = SCu8((u8*)user_data); } if (file_name.size == 0){ result = ListerActivation_Finished; } else{ - String path = state->lister.data.text_field; - if (path.size > 0 && !char_is_slash(path.str[path.size - 1])){ - path = path_of_directory(path); + String_Const_u8 path = state->lister.data.text_field.string; + if (!character_is_slash(string_get_character(path, path.size - 1))){ + path = string_remove_last_folder(path); } - b32 is_folder = (file_name.str[file_name.size - 1] == '/' && user_data != 0); + b32 is_folder = (character_is_slash(string_get_character(file_name, file_name.size - 1)) && + user_data != 0); Buffer_Create_Flag flags = BufferCreate_NeverNew; - result = activate_open_or_new__generic(app, scratch, view, path, file_name, is_folder, flags); + result = activate_open_or_new__generic(app, view, path, file_name, is_folder, flags); } - lister_default(app, scratch, heap, view, state, result); + lister_default(app, heap, view, state, result); } CUSTOM_COMMAND_SIG(interactive_open) @@ -972,7 +929,7 @@ CUSTOM_DOC("Interactively opens a file.") static void activate_select_theme(Application_Links *app, Partition *scratch, Heap *heap, View_ID view, struct Lister_State *state, - String text_field, void *user_data, b32 clicked){ + String_Const_u8 text_field, void *user_data, b32 clicked){ change_theme_by_index(app, (i32)PtrAsInt(user_data)); lister_default(app, scratch, heap, view, state, ListerActivation_Finished); } @@ -1008,10 +965,10 @@ CUSTOM_DOC("Opens the 4coder theme selector list.") //////////////////////////////// static void -activate_command(Application_Links *app, Partition *scratch, Heap *heap, +activate_command(Application_Links *app, Heap *heap, View_ID view, Lister_State *state, - String text_field, void *user_data, b32 activated_by_mouse){ - lister_default(app, scratch, heap, view, state, ListerActivation_Finished); + String_Const_u8 text_field, void *user_data, b32 activated_by_mouse){ + lister_default(app, heap, view, state, ListerActivation_Finished); if (user_data != 0){ Custom_Command_Function *command = (Custom_Command_Function*)user_data; command(app); @@ -1024,24 +981,24 @@ launch_custom_command_lister(Application_Links *app, i32 *command_ids, i32 comma command_id_count = command_one_past_last_id; } - Partition *arena = &global_part; + Arena *scratch = context_get_arena(app); View_ID view = 0; get_active_view(app, AccessAll, &view); view_end_ui_mode(app, view); - Temp_Memory temp = begin_temp_memory(arena); - Lister_Option *options = push_array(arena, Lister_Option, command_id_count); + Temp_Memory temp = begin_temp(scratch); + Lister_Option *options = push_array(scratch, Lister_Option, command_id_count); for (i32 i = 0; i < command_id_count; i += 1){ i32 j = i; if (command_ids != 0){ j = command_ids[i]; } j = clamp(0, j, command_one_past_last_id); - options[i].string = make_string_slowly(fcoder_metacmd_table[j].name); - options[i].status = make_string_slowly(fcoder_metacmd_table[j].description); + options[i].string = SCu8(fcoder_metacmd_table[j].name); + options[i].status = SCu8(fcoder_metacmd_table[j].description); options[i].user_data = (void*)fcoder_metacmd_table[j].proc; } begin_integrated_lister__basic_list(app, "Command:", activate_command, 0, 0, options, command_id_count, 0, view); - end_temp_memory(temp); + end_temp(temp); } CUSTOM_COMMAND_SIG(command_lister) diff --git a/4coder_malloc_allocator.cpp b/4coder_malloc_allocator.cpp new file mode 100644 index 00000000..0ee8d54f --- /dev/null +++ b/4coder_malloc_allocator.cpp @@ -0,0 +1,48 @@ +/* + * 4coder malloc base allocator + */ + +// TOP + +#include +#include + +internal void* +base_reserve__malloc(void *user_data, umem size, umem *size_out){ + *size_out = size; + return(malloc(size)); +} + +internal void +base_free__malloc(void *user_data, void *ptr){ + free(ptr); +} + +internal Base_Allocator +make_malloc_base_allocator(void){ + return(make_base_allocator(base_reserve__malloc, 0, 0, + base_free__malloc, 0, 0)); +} + +global Base_Allocator malloc_base_allocator = {}; + +internal Arena +make_arena_malloc(umem chunk_size, umem align){ + if (malloc_base_allocator.reserve == 0){ + malloc_base_allocator = make_malloc_base_allocator(); + } + return(make_arena(&malloc_base_allocator, chunk_size, align)); +} + +internal Arena +make_arena_malloc(umem chunk_size){ + return(make_arena_malloc(chunk_size, 8)); +} + +internal Arena +make_arena_malloc(void){ + return(make_arena_malloc(KB(16), 8)); +} + +// BOTTOM + diff --git a/4coder_metadata_generator.cpp b/4coder_metadata_generator.cpp index e1a20cee..a6361464 100644 --- a/4coder_metadata_generator.cpp +++ b/4coder_metadata_generator.cpp @@ -6,6 +6,14 @@ #define COMMAND_METADATA_OUT "4coder_generated/command_metadata.h" +#include "4coder_base_types.h" + +#include "4coder_lib/4coder_string.h" + +#include "4coder_base_types.cpp" +#include "4coder_stringf.cpp" +#include "4coder_malloc_allocator.cpp" + #include "4coder_file.h" #include "4coder_lib/4cpp_lexer.h" @@ -14,8 +22,8 @@ #include #include -#define str_to_l_c(s) ((s).size), ((s).str) -#define str_to_c_l(s) ((s).str), ((s).size) +#define str_to_l_c(s) ((i32)(s).size), ((s).str) +#define str_to_c_l(s) ((s).str), ((i32)(s).size) /////////////////////////////// @@ -25,12 +33,12 @@ struct Line_Column_Coordinates{ }; static Line_Column_Coordinates -line_column_coordinates(String text, int32_t pos){ +line_column_coordinates(String_Const_char text, int32_t pos){ if (pos < 0){ pos = 0; } if (pos > text.size){ - pos = text.size; + pos = (i32)text.size; } Line_Column_Coordinates coords = {}; @@ -51,13 +59,13 @@ line_column_coordinates(String text, int32_t pos){ } static int32_t -line_number(String text, int32_t pos){ +line_number(String_Const_char text, int32_t pos){ Line_Column_Coordinates coords = line_column_coordinates(text, pos); return(coords.line); } static void -error(char *source_name, String text, int32_t pos, char *msg){ +error(char *source_name, String_Const_char text, int32_t pos, char *msg){ Line_Column_Coordinates coords = line_column_coordinates(text, pos); fprintf(stdout, "%s:%d:%d: %s\n", source_name, coords.line, coords.column, msg); fflush(stdout); @@ -66,8 +74,9 @@ error(char *source_name, String text, int32_t pos, char *msg){ /////////////////////////////// struct Reader{ + Arena *error_arena; char *source_name; - String text; + String_Const_char text; Cpp_Token_Array tokens; Cpp_Token *ptr; }; @@ -78,7 +87,7 @@ struct Temp_Read{ }; static Reader -make_reader(Cpp_Token_Array array, char *source_name, String text){ +make_reader(Cpp_Token_Array array, char *source_name, String_Const_char text){ Reader reader = {}; reader.tokens = array; reader.ptr = array.tokens; @@ -130,7 +139,7 @@ get_token(Reader *reader){ else{ reader->ptr = reader->tokens.tokens + reader->tokens.count; memset(&result, 0, sizeof(result)); - result.start = reader->text.size; + result.start = (i32)reader->text.size; break; } @@ -151,7 +160,7 @@ peek_token(Reader *reader){ } if (reader->ptr >= reader->tokens.tokens + reader->tokens.count){ - result.start = reader->text.size; + result.start = (i32)reader->text.size; } else{ result = *reader->ptr; @@ -192,18 +201,14 @@ end_temp_read(Temp_Read temp){ /////////////////////////////// -static String -token_str(String text, Cpp_Token token){ - String str = substr(text, token.start, token.size); +static String_Const_char +token_str(String_Const_char text, Cpp_Token token){ + String_Const_char str = string_prefix(string_skip(text, token.start), token.size); return(str); } /////////////////////////////// -#define sll_push(f,l,n) if((f)==0){(f)=(l)=(n);}else{(l)->next=(n);(l)=(n);}(n)->next=0 - -/////////////////////////////// - typedef uint32_t Meta_Command_Entry_Type; enum{ MetaCommandEntry_DocString, @@ -212,15 +217,15 @@ enum{ struct Meta_Command_Entry{ Meta_Command_Entry *next; - String name; + String_Const_char name; char *source_name; int32_t line_number; union{ struct{ - String doc; + String_Const_char doc; } docstring; struct{ - String potential; + String_Const_char potential; } alias; }; }; @@ -237,15 +242,13 @@ struct Meta_Command_Entry_Arrays{ /////////////////////////////// -#define Swap(T,a,b) {T t=a; a=b; b=t;} - static int32_t quick_sort_part(Meta_Command_Entry **entries, int32_t first, int32_t one_past_last){ int32_t pivot = one_past_last - 1; - String pivot_key = entries[pivot]->name; + String_Const_char pivot_key = entries[pivot]->name; int32_t j = first; for (int32_t i = first; i < pivot; ++i){ - if (compare(entries[i]->name, pivot_key) < 0){ + if (string_compare(entries[i]->name, pivot_key) < 0){ Swap(Meta_Command_Entry*, entries[i], entries[j]); ++j; } @@ -264,8 +267,8 @@ quick_sort(Meta_Command_Entry **entries, int32_t first, int32_t one_past_last){ } static Meta_Command_Entry** -get_sorted_meta_commands(Partition *part, Meta_Command_Entry *first, int32_t count){ - Meta_Command_Entry **entries = push_array(part, Meta_Command_Entry*, count); +get_sorted_meta_commands(Arena *arena, Meta_Command_Entry *first, int32_t count){ + Meta_Command_Entry **entries = push_array(arena, Meta_Command_Entry*, count); int32_t i = 0; for (Meta_Command_Entry *entry = first; @@ -282,13 +285,13 @@ get_sorted_meta_commands(Partition *part, Meta_Command_Entry *first, int32_t cou /////////////////////////////// -static bool32 -has_duplicate_entry(Meta_Command_Entry *first, String name){ - bool32 has_duplicate = false; +static b32 +has_duplicate_entry(Meta_Command_Entry *first, String_Const_char name){ + b32 has_duplicate = false; for (Meta_Command_Entry *entry = first; entry != 0; entry = entry->next){ - if (match(name, entry->name)){ + if (string_match(name, entry->name)){ has_duplicate = true; } } @@ -297,14 +300,16 @@ has_duplicate_entry(Meta_Command_Entry *first, String name){ /////////////////////////////// -static bool32 +static b32 require_key_identifier(Reader *reader, char *str, int32_t *opt_pos_out = 0){ - bool32 success = false; + b32 success = false; + + String_Const_char string = SCchar(str); Cpp_Token token = get_token(reader); if (token.type == CPP_TOKEN_IDENTIFIER){ - String lexeme = token_str(reader->text, token); - if (match(lexeme, str)){ + String_Const_char lexeme = token_str(reader->text, token); + if (string_match(lexeme, string)){ success = true; if (opt_pos_out != 0){ *opt_pos_out = token.start; @@ -313,21 +318,18 @@ require_key_identifier(Reader *reader, char *str, int32_t *opt_pos_out = 0){ } if (!success){ - char space[1024]; - String s = make_fixed_width_string(space); - copy(&s, "expected to find '"); - append(&s, str); - append(&s, "'"); - terminate_with_null(&s); - error(reader, token.start, s.str); + Temp_Memory temp = begin_temp(reader->error_arena); + String_Const_char error_string = string_pushf(reader->error_arena, "expected to find '%s'", str); + error(reader, token.start, error_string.str); + end_temp(temp); } return(success); } -static bool32 +static b32 require_open_parenthese(Reader *reader, int32_t *opt_pos_out = 0){ - bool32 success = false; + b32 success = false; Cpp_Token token = get_token(reader); if (token.type == CPP_TOKEN_PARENTHESE_OPEN){ @@ -344,9 +346,9 @@ require_open_parenthese(Reader *reader, int32_t *opt_pos_out = 0){ return(success); } -static bool32 +static b32 require_close_parenthese(Reader *reader, int32_t *opt_pos_out = 0){ - bool32 success = false; + b32 success = false; Cpp_Token token = get_token(reader); if (token.type == CPP_TOKEN_PARENTHESE_CLOSE){ @@ -363,9 +365,9 @@ require_close_parenthese(Reader *reader, int32_t *opt_pos_out = 0){ return(success); } -static bool32 +static b32 require_comma(Reader *reader, int32_t *opt_pos_out = 0){ - bool32 success = false; + b32 success = false; Cpp_Token token = get_token(reader); if (token.type == CPP_TOKEN_COMMA){ @@ -382,9 +384,9 @@ require_comma(Reader *reader, int32_t *opt_pos_out = 0){ return(success); } -static bool32 +static b32 require_define(Reader *reader, int32_t *opt_pos_out = 0){ - bool32 success = false; + b32 success = false; Cpp_Token token = get_token(reader); if (token.type == CPP_PP_DEFINE){ @@ -401,13 +403,13 @@ require_define(Reader *reader, int32_t *opt_pos_out = 0){ return(success); } -static bool32 -extract_identifier(Reader *reader, String *str_out, int32_t *opt_pos_out = 0){ - bool32 success = false; +static b32 +extract_identifier(Reader *reader, String_Const_char *str_out, int32_t *opt_pos_out = 0){ + b32 success = false; Cpp_Token token = get_token(reader); if (token.type == CPP_TOKEN_IDENTIFIER){ - String lexeme = token_str(reader->text, token); + String_Const_char lexeme = token_str(reader->text, token); *str_out = lexeme; success = true; if (opt_pos_out != 0){ @@ -422,13 +424,13 @@ extract_identifier(Reader *reader, String *str_out, int32_t *opt_pos_out = 0){ return(success); } -static bool32 -extract_integer(Reader *reader, String *str_out, int32_t *opt_pos_out = 0){ - bool32 success = false; +static b32 +extract_integer(Reader *reader, String_Const_char *str_out, int32_t *opt_pos_out = 0){ + b32 success = false; Cpp_Token token = get_token(reader); if (token.type == CPP_TOKEN_INTEGER_CONSTANT){ - String lexeme = token_str(reader->text, token); + String_Const_char lexeme = token_str(reader->text, token); *str_out = lexeme; success = true; if (opt_pos_out != 0){ @@ -443,13 +445,13 @@ extract_integer(Reader *reader, String *str_out, int32_t *opt_pos_out = 0){ return(success); } -static bool32 -extract_string(Reader *reader, String *str_out, int32_t *opt_pos_out = 0){ - bool32 success = false; +static b32 +extract_string(Reader *reader, String_Const_char *str_out, int32_t *opt_pos_out = 0){ + b32 success = false; Cpp_Token token = get_token(reader); if (token.type == CPP_TOKEN_STRING_CONSTANT){ - String lexeme = token_str(reader->text, token); + String_Const_char lexeme = token_str(reader->text, token); *str_out = lexeme; success = true; if (opt_pos_out != 0){ @@ -464,12 +466,12 @@ extract_string(Reader *reader, String *str_out, int32_t *opt_pos_out = 0){ return(success); } -static bool32 -parse_documented_command(Partition *part, Meta_Command_Entry_Arrays *arrays, Reader *reader){ - String name = {}; - String file_name = {}; - String line_number = {}; - String doc = {}; +static b32 +parse_documented_command(Arena *arena, Meta_Command_Entry_Arrays *arrays, Reader *reader){ + String_Const_char name = {}; + String_Const_char file_name = {}; + String_Const_char line_number = {}; + String_Const_char doc = {}; // Getting the command's name int32_t start_pos = 0; @@ -533,27 +535,26 @@ parse_documented_command(Partition *part, Meta_Command_Entry_Arrays *arrays, Rea return(false); } - doc = substr(doc, 1, doc.size - 2); + doc = string_chop(string_skip(doc, 1), 1); - char *source_name = push_array(part, char, file_name.size + 1); - push_align(part, 8); - string_interpret_escapes(substr(file_name, 1, file_name.size - 2), source_name); + String_Const_char file_name_unquoted = string_chop(string_skip(file_name, 1), 1); + String_Const_char source_name = string_interpret_escapes(arena, file_name_unquoted); - Meta_Command_Entry *new_entry = push_array(part, Meta_Command_Entry, 1); + Meta_Command_Entry *new_entry = push_array(arena, Meta_Command_Entry, 1); new_entry->name = name; - new_entry->source_name = source_name; - new_entry->line_number = str_to_int(line_number); + new_entry->source_name = source_name.str; + new_entry->line_number = (i32)string_to_integer(line_number, 10); new_entry->docstring.doc = doc; - sll_push(arrays->first_doc_string, arrays->last_doc_string, new_entry); + sll_queue_push(arrays->first_doc_string, arrays->last_doc_string, new_entry); ++arrays->doc_string_count; return(true); } -static bool32 -parse_alias(Partition *part, Meta_Command_Entry_Arrays *arrays, Reader *reader){ - String name = {}; - String potential = {}; +static b32 +parse_alias(Arena *arena, Meta_Command_Entry_Arrays *arrays, Reader *reader){ + String_Const_char name = {}; + String_Const_char potential = {}; // Getting the alias's name int32_t start_pos = 0; @@ -582,12 +583,12 @@ parse_alias(Partition *part, Meta_Command_Entry_Arrays *arrays, Reader *reader){ return(false); } - Meta_Command_Entry *new_entry = push_array(part, Meta_Command_Entry, 1); + Meta_Command_Entry *new_entry = push_array(arena, Meta_Command_Entry, 1); new_entry->name = name; new_entry->source_name = reader->source_name; new_entry->line_number = line_number(reader, start_pos); new_entry->alias.potential = potential; - sll_push(arrays->first_alias, arrays->last_alias, new_entry); + sll_queue_push(arrays->first_alias, arrays->last_alias, new_entry); ++arrays->alias_count; return(true); @@ -596,9 +597,9 @@ parse_alias(Partition *part, Meta_Command_Entry_Arrays *arrays, Reader *reader){ /////////////////////////////// static void -parse_text(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, char *source_name, String text){ +parse_text(Arena *arena, Meta_Command_Entry_Arrays *entry_arrays, char *source_name, String_Const_char text){ Cpp_Token_Array array = cpp_make_token_array(1024); - cpp_lex_file(text.str, text.size, &array); + cpp_lex_file(text.str, (i32)text.size, &array); Reader reader_ = make_reader(array, source_name, text); Reader *reader = &reader_; @@ -607,19 +608,19 @@ parse_text(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, char *sourc Cpp_Token token = get_token(reader); if (token.type == CPP_TOKEN_IDENTIFIER){ - String lexeme = token_str(text, token); + String_Const_char lexeme = token_str(text, token); - bool32 in_preproc_body = ((token.flags & CPP_TFLAG_PP_BODY) != 0); + b32 in_preproc_body = ((token.flags & CPP_TFLAG_PP_BODY) != 0); - if (!in_preproc_body && match(lexeme, "CUSTOM_DOC")){ + if (!in_preproc_body && string_match(lexeme, string_litexpr("CUSTOM_DOC"))){ Temp_Read temp_read = begin_temp_read(reader); - bool32 found_start_pos = false; + b32 found_start_pos = false; for (int32_t R = 0; R < 10; ++R){ Cpp_Token p_token = prev_token(reader); if (p_token.type == CPP_TOKEN_IDENTIFIER){ - String p_lexeme = token_str(text, p_token); - if (match(p_lexeme, "CUSTOM_COMMAND_SIG")){ + String_Const_char p_lexeme = token_str(text, p_token); + if (string_match(p_lexeme, string_litexpr("CUSTOM_COMMAND_SIG"))){ found_start_pos = true; break; } @@ -633,15 +634,15 @@ parse_text(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, char *sourc end_temp_read(temp_read); } else{ - if (!parse_documented_command(part, entry_arrays, reader)){ + if (!parse_documented_command(arena, entry_arrays, reader)){ end_temp_read(temp_read); } } } - else if (match(lexeme, "CUSTOM_ALIAS")){ + else if (string_match(lexeme, string_litexpr("CUSTOM_ALIAS"))){ Temp_Read temp_read = begin_temp_read(reader); - bool32 found_start_pos = false; + b32 found_start_pos = false; for (int32_t R = 0; R < 3; ++R){ Cpp_Token p_token = prev_token(reader); if (p_token.type == CPP_PP_DEFINE){ @@ -659,7 +660,7 @@ parse_text(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, char *sourc end_temp_read(temp_read); } else{ - if (!parse_alias(part, entry_arrays, reader)){ + if (!parse_alias(arena, entry_arrays, reader)){ end_temp_read(temp_read); } } @@ -675,8 +676,8 @@ parse_text(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, char *sourc } static void -parse_file(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, Filename_Character *name_, int32_t len){ - char *name = unencode(part, name_, len); +parse_file(Arena *arena, Meta_Command_Entry_Arrays *entry_arrays, Filename_Character *name_, int32_t len){ + char *name = unencode(arena, name_, len); if (name == 0){ if (sizeof(*name_) == 2){ fprintf(stdout, "warning: could not unencode file name %ls - file skipped\n", (wchar_t*)name_); @@ -687,17 +688,23 @@ parse_file(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, Filename_Ch return; } - String text = file_dump(part, name); - parse_text(part, entry_arrays, name, text); + String_Const_char text = file_dump(arena, name); + parse_text(arena, entry_arrays, name, text); } static void -parse_files_by_pattern(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, Filename_Character *pattern, bool32 recursive){ - Cross_Platform_File_List list = get_file_list(part, pattern, filter_all); +parse_files_by_pattern(Arena *arena, Meta_Command_Entry_Arrays *entry_arrays, Filename_Character *pattern, b32 recursive){ + Cross_Platform_File_List list = get_file_list(arena, pattern, filter_all); for (int32_t i = 0; i < list.count; ++i){ Cross_Platform_File_Info *info = &list.info[i]; - if (info->is_folder && match(make_string(info->name, info->len), "4coder_generated")){ + String_Const_Any info_name = SCany(info->name, info->len); + Temp_Memory temp = begin_temp(arena); + String_Const_char info_name_ascii = string_char_from_any(arena, info_name); + b32 is_generated = string_match(info_name_ascii, string_litexpr("4coder_generated")); + end_temp(temp); + + if (info->is_folder && is_generated){ continue; } if (!recursive && info->is_folder){ @@ -708,8 +715,7 @@ parse_files_by_pattern(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, if (info->is_folder){ full_name_len += 2; } - Filename_Character *full_name = push_array(part, Filename_Character, full_name_len + 1); - push_align(part, 8); + Filename_Character *full_name = push_array(arena, Filename_Character, full_name_len + 1); if (full_name == 0){ fprintf(stdout, "fatal error: not enough memory to recurse to sub directory\n"); @@ -722,12 +728,12 @@ parse_files_by_pattern(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, full_name[full_name_len] = 0; if (!info->is_folder){ - parse_file(part, entry_arrays, full_name, full_name_len); + parse_file(arena, entry_arrays, full_name, full_name_len); } else{ full_name[full_name_len - 2] = SLASH; full_name[full_name_len - 1] = '*'; - parse_files_by_pattern(part, entry_arrays, full_name, true); + parse_files_by_pattern(arena, entry_arrays, full_name, true); } } } @@ -748,15 +754,13 @@ main(int argc, char **argv){ show_usage(argc, argv); } - bool32 recursive = match(argv[1], "-R"); + b32 recursive = string_match(SCchar(argv[1]), string_litexpr("-R")); if (recursive && argc < 4){ show_usage(argc, argv); } - int32_t size = (256 << 20); - void *mem = malloc(size); - Partition part_ = make_part(mem, size); - Partition *part = &part_; + Arena arena_ = make_arena_malloc(MB(1), 8); + Arena *arena = &arena_; char *out_directory = argv[2]; @@ -767,24 +771,24 @@ main(int argc, char **argv){ Meta_Command_Entry_Arrays entry_arrays = {}; for (int32_t i = start_i; i < argc; ++i){ - Filename_Character *pattern_name = encode(part, argv[i]); - parse_files_by_pattern(part, &entry_arrays, pattern_name, recursive); + Filename_Character *pattern_name = encode(arena, argv[i]); + parse_files_by_pattern(arena, &entry_arrays, pattern_name, recursive); } - int32_t out_dir_len = str_size(out_directory); + umem out_dir_len = cstring_length(out_directory); if (out_directory[0] == '"'){ out_directory += 1; out_dir_len -= 2; } { - String str = make_string(out_directory, out_dir_len); - str = skip_chop_whitespace(str); + String_Const_char str = SCchar(out_directory, out_dir_len); + str = string_skip_chop_whitespace(str); out_directory = str.str; out_dir_len = str.size; } - int32_t len = out_dir_len + 1 + sizeof(COMMAND_METADATA_OUT) - 1; + umem len = out_dir_len + 1 + sizeof(COMMAND_METADATA_OUT) - 1; char *out_file_name = (char*)malloc(len + 1); memcpy(out_file_name, out_directory, out_dir_len); memcpy(out_file_name + out_dir_len, "/", 1); @@ -794,7 +798,7 @@ main(int argc, char **argv){ if (out != 0){ int32_t entry_count = entry_arrays.doc_string_count; - Meta_Command_Entry **entries = get_sorted_meta_commands(part, entry_arrays.first_doc_string, entry_count); + Meta_Command_Entry **entries = get_sorted_meta_commands(arena, entry_arrays.first_doc_string, entry_count); fprintf(out, "#if !defined(META_PASS)\n"); fprintf(out, "#define command_id(c) (fcoder_metacmd_ID_##c)\n"); @@ -832,26 +836,23 @@ main(int argc, char **argv){ for (int32_t i = 0; i < entry_count; ++i){ Meta_Command_Entry *entry = entries[i]; - Temp_Memory temp = begin_temp_memory(part); + Temp_Memory temp = begin_temp(arena); // HACK(allen): We could just get these at the HEAD END of the process, // then we only have to do it once per file, and pass the lengths through. - int32_t source_name_len = str_size(entry->source_name); - - char *fixed_name = push_array(part, char, source_name_len*2 + 1); - String s = make_string_cap(fixed_name, 0, source_name_len*2 + 1); - copy(&s, entry->source_name); - int32_t unescaped_size = s.size; - replace_str(&s, "\\", "\\\\"); - terminate_with_null(&s); + //umem source_name_len = cstring_length(entry->source_name); + String_Const_char source_name = SCchar(entry->source_name); + String_Const_char printable = string_replace(arena, source_name, + SCchar("\\"), SCchar("\\\\"), + StringFill_NullTerminate); fprintf(out, "{ PROC_LINKS(%.*s, 0), \"%.*s\", %d, \"%.*s\", %d, \"%s\", %d, %d },\n", str_to_l_c(entry->name), - str_to_l_c(entry->name), entry->name.size, - str_to_l_c(entry->docstring.doc), entry->docstring.doc.size, - s.str, unescaped_size, entry->line_number); - end_temp_memory(temp); + str_to_l_c(entry->name), (i32)entry->name.size, + str_to_l_c(entry->docstring.doc), (i32)entry->docstring.doc.size, + printable.str, (i32)source_name.size, entry->line_number); + end_temp(temp); } fprintf(out, "};\n"); diff --git a/4coder_miblo_numbers.cpp b/4coder_miblo_numbers.cpp index 93fe3d45..75e1efdd 100644 --- a/4coder_miblo_numbers.cpp +++ b/4coder_miblo_numbers.cpp @@ -5,29 +5,23 @@ and decrementing various forms of number as numerical objects despite being enco // TOP -static i32 -get_numeric_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start_pos, i32 *numeric_start, i32 *numeric_end){ - i32 result = 0; +static Range +get_numeric_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start_pos){ + Range result = {}; char current = buffer_get_char(app, buffer, start_pos); - - if (char_is_numeric(current)){ + if (character_is_base10(current)){ char chunk[1024]; i32 chunk_size = sizeof(chunk); Stream_Chunk stream = {}; i32 pos = start_pos; - - i32 pos1 = 0; - i32 pos2 = 0; - if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){ - b32 still_looping = true; for (;still_looping;){ for (; pos >= stream.start; --pos){ char at_pos = stream.data[pos]; - if (!char_is_numeric(at_pos)){ + if (!character_is_base10(at_pos)){ ++pos; goto double_break_1; } @@ -35,25 +29,23 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start still_looping = backward_stream_chunk(&stream); } double_break_1:; - pos1 = pos; + i32 pos1 = pos; if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){ - still_looping = 1; + still_looping = true; while (still_looping){ for (; pos < stream.end; ++pos){ char at_pos = stream.data[pos]; - if (!char_is_numeric(at_pos)){ + if (!character_is_base10(at_pos)){ goto double_break_2; } } still_looping = forward_stream_chunk(&stream); } double_break_2:; - pos2 = pos; + i32 pos2 = pos; - result = 1; - *numeric_start = pos1; - *numeric_end = pos2; + result = make_range(pos1, pos2); } } } @@ -61,6 +53,19 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start return(result); } +#if 0 +static b32 +get_numeric_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start_pos, i32 *numeric_start, i32 *numeric_end){ + Range range = get_numeric_string_at_cursor(app, buffer, start_pos); + b32 result = (range_size(range) > 0); + if (result){ + *numeric_start = range.start; + *numeric_end = range.end; + } + return(result); +} +#endif + struct Miblo_Number_Info{ union{ Range range; @@ -70,27 +75,20 @@ struct Miblo_Number_Info{ i32 x; }; -static i32 +static b32 get_numeric_at_cursor(Application_Links *app, Buffer_ID buffer, i32 pos, Miblo_Number_Info *info){ - i32 result = 0; - - i32 numeric_start = 0, numeric_end = 0; - if (get_numeric_string_at_cursor(app, buffer, pos, &numeric_start, &numeric_end)){ - char numeric_string[1024]; - String str = make_string(numeric_string, numeric_end - numeric_start, sizeof(numeric_string)); - if (str.size < str.memory_size){ - buffer_read_range(app, buffer, numeric_start, numeric_end, numeric_string); - - i32 x = str_to_int(str); - int_to_str(&str, x+1); - - info->start = numeric_start; - info->end = numeric_end; + b32 result = false; + Range range = get_numeric_string_at_cursor(app, buffer, pos); + if (range_size(range) > 0){ + Scratch_Block scratch(app); + String_Const_u8 str = scratch_read(app, scratch, buffer, range); + if (str.size > 0){ + i32 x = (i32)string_to_integer(str, 10); + info->range = range; info->x = x; - result = 1; + result = true; } } - return(result); } @@ -105,11 +103,10 @@ CUSTOM_DOC("Increment an integer under the cursor by one.") view_get_cursor_pos(app, view, &pos); Miblo_Number_Info number = {}; if (get_numeric_at_cursor(app, buffer, pos, &number)){ - char str_space[1024]; - String str = make_fixed_width_string(str_space); - int_to_str(&str, number.x + 1); + Scratch_Block scratch(app); + String_Const_u8 str = string_u8_pushf(scratch, "%d", number.x + 1); buffer_replace_range(app, buffer, number.range, str); - view_set_cursor(app, view, seek_pos(number.start + str.size - 1), true); + view_set_cursor(app, view, seek_pos(number.start + (i32)str.size - 1), true); } } @@ -124,24 +121,23 @@ CUSTOM_DOC("Decrement an integer under the cursor by one.") view_get_cursor_pos(app, view, &pos); Miblo_Number_Info number = {}; if (get_numeric_at_cursor(app, buffer, pos, &number)){ - char str_space[1024]; - String str = make_fixed_width_string(str_space); - int_to_str(&str, number.x - 1); + Scratch_Block scratch(app); + String_Const_u8 str = string_u8_pushf(scratch, "%d", number.x - 1); buffer_replace_range(app, buffer, number.range, str); - view_set_cursor(app, view, seek_pos(number.start + str.size - 1), true); + view_set_cursor(app, view, seek_pos(number.start + (i32)str.size - 1), true); } } // NOTE(allen): miblo time stamp format // (h+:)?m?m:ss -static i32 -get_timestamp_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start_pos, i32 *timestamp_start, i32 *timestamp_end){ - i32 result = 0; +static Range +get_timestamp_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start_pos){ + Range result = {}; char current = buffer_get_char(app, buffer, start_pos); - if (char_is_numeric(current) || current == ':'){ + if (character_is_base10(current) || current == ':'){ char chunk[1024]; i32 chunk_size = sizeof(chunk); Stream_Chunk stream = {}; @@ -152,12 +148,11 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 sta i32 pos2 = 0; if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){ - - i32 still_looping = 1; + b32 still_looping = true; while (still_looping){ for (; pos >= stream.start; --pos){ char at_pos = stream.data[pos]; - if (!(char_is_numeric(at_pos) || at_pos == ':')){ + if (!(character_is_base10(at_pos) || at_pos == ':')){ ++pos; goto double_break_1; } @@ -168,12 +163,11 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 sta pos1 = pos; if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){ - - still_looping = 1; + still_looping = true; while (still_looping){ for (; pos < stream.end; ++pos){ char at_pos = stream.data[pos]; - if (!(char_is_numeric(at_pos) || at_pos == ':')){ + if (!(character_is_base10(at_pos) || at_pos == ':')){ goto double_break_2; } } @@ -182,9 +176,7 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 sta double_break_2:; pos2 = pos; - result = 1; - *timestamp_start = pos1; - *timestamp_end = pos2; + result = make_range(pos1, pos2); } } } @@ -192,6 +184,16 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 sta return(result); } +#if 0 +static b32 +get_timestamp_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start_pos, i32 *timestamp_start, i32 *timestamp_end){ + Range range = get_timestamp_string_at_cursor(app, buffer, start_pos); + *timestamp_start = range.start; + *timestamp_end = range.end; + return(range_size(range) > 0); +} +#endif + struct Miblo_Timestamp{ i32 second; i32 minute; @@ -253,34 +255,18 @@ increment_timestamp(Miblo_Timestamp t, i32 type, i32 amt){ return(r); } -static void -timestamp_to_str(String *dest, Miblo_Timestamp t){ - dest->size = 0; - +static String_Const_u8 +timestamp_to_string(Arena *arena, Miblo_Timestamp t){ + List_String_Const_u8 list = {}; if (t.hour > 0){ - append_int_to_str(dest, t.hour); - append(dest, ":"); - } - - if (t.minute >= 10){ - append_int_to_str(dest, t.minute); - } - else if (t.hour > 0){ - append(dest, "0"); - append_int_to_str(dest, t.minute); - } - else{ - append_int_to_str(dest, t.minute); - } - append(dest, ":"); - - if (t.second >= 10){ - append_int_to_str(dest, t.second); - } - else{ - append(dest, "0"); - append_int_to_str(dest, t.second); + string_list_pushf(arena, &list, "%d:", t.hour); } + i32 minute = clamp_bot(0, t.minute); + string_list_pushf(arena, &list, "%02d:", minute); + i32 second = clamp_bot(0, t.second); + string_list_pushf(arena, &list, "%02d", second); + String_Const_u8 str = string_list_flatten(arena, list); + return(str); } struct Miblo_Timestamp_Info{ @@ -292,76 +278,81 @@ struct Miblo_Timestamp_Info{ Miblo_Timestamp time; }; -static i32 +static b32 get_timestamp_at_cursor(Application_Links *app, Buffer_ID buffer, i32 pos, Miblo_Timestamp_Info *info){ - i32 result = 0; + b32 result = false; - i32 timestamp_start = 0, timestamp_end = 0; - if (get_timestamp_string_at_cursor(app, buffer, pos, ×tamp_start, ×tamp_end)){ - char timestamp_string[1024]; - String str = make_string(timestamp_string, timestamp_end - timestamp_start, sizeof(timestamp_string)); - if (str.size < str.memory_size){ - buffer_read_range(app, buffer, timestamp_start, timestamp_end, timestamp_string); - + Scratch_Block scratch(app); + + Range time_stamp_range = get_timestamp_string_at_cursor(app, buffer, pos); + if (range_size(time_stamp_range) > 0){ + String_Const_u8 string = scratch_read(app, scratch, buffer, time_stamp_range); + if (string.size > 0){ i32 count_colons = 0; - for (i32 i = 0; i < str.size; ++i){ - if (str.str[i] == ':'){ - ++count_colons; + for (umem i = 0; i < string.size; ++i){ + if (string.str[i] == ':'){ + count_colons += 1; } } if (count_colons == 1 || count_colons == 2){ Miblo_Timestamp t = {}; - i32 success = 0; + b32 success = false; - i32 i = 0; - i32 number_start[3], number_end[3]; + umem i = 0; + umem number_start[3]; + umem number_end[3]; for (i32 k = 0; k < 3; ++k){ number_start[k] = i; - for (; i <= str.size; ++i){ - if (i == str.size || str.str[i] == ':'){ + for (; i <= string.size; ++i){ + if (i == string.size || string.str[i] == ':'){ number_end[k] = i; break; } } ++i; - if (i >= timestamp_end){ + if (i >= time_stamp_range.one_past_last){ break; } } if (count_colons == 2){ - t.hour = str_to_int(make_string(str.str + number_start[0], number_end[0] - number_start[0])); + String_Const_u8 hour_str = SCu8(string.str + number_start[0], + string.str + number_end[0]); + t.hour = (i32)string_to_integer(hour_str, 10); if (number_end[1] - number_start[1] == 2){ - - t.minute = str_to_int(make_string(str.str + number_start[1], number_end[1] - number_start[1])); - + String_Const_u8 minute_str = SCu8(string.str + number_start[1], + string.str + number_end[1]); + t.minute = (i32)string_to_integer(minute_str, 10); if (number_end[2] - number_start[2] == 2){ - t.second = str_to_int(make_string(str.str + number_start[2], number_end[2] - number_start[2])); - - success = 1; + String_Const_u8 second_str = SCu8(string.str + number_start[2], + string.str + number_end[2]); + t.second = (i32)string_to_integer(second_str, 10); + success = true; } } } else{ if (number_end[0] - number_start[0] == 2 || number_end[0] - number_start[0] == 1){ - t.minute = str_to_int(make_string(str.str + number_start[0], number_end[0] - number_start[0])); + String_Const_u8 minute_str = SCu8(string.str + number_start[0], + string.str + number_end[0]); + t.minute = (i32)string_to_integer(minute_str, 10); if (number_end[1] - number_start[1] == 2){ - t.second = str_to_int(make_string(str.str + number_start[1], number_end[1] - number_start[1])); - - success = 1; + String_Const_u8 second_str = SCu8(string.str + number_start[2], + string.str + number_end[2]); + t.second = (i32)string_to_integer(second_str, 10); + success = true; } } } if (success){ - info->start = timestamp_start; - info->end = timestamp_end; + info->range = time_stamp_range; info->time = t; - result = 1; + result = true; } } } @@ -381,13 +372,11 @@ miblo_time_stamp_alter(Application_Links *app, i32 unit_type, i32 amt){ Miblo_Timestamp_Info timestamp = {}; if (get_timestamp_at_cursor(app, buffer, pos, ×tamp)){ - char str_space[1024]; - String str = make_fixed_width_string(str_space); - + Scratch_Block scratch(app); Miblo_Timestamp inc_timestamp = increment_timestamp(timestamp.time, unit_type, amt); - timestamp_to_str(&str, inc_timestamp); + String_Const_u8 str = timestamp_to_string(scratch, inc_timestamp); buffer_replace_range(app, buffer, timestamp.range, str); - view_set_cursor(app, view, seek_pos(timestamp.start + str.size - 1), true); + view_set_cursor(app, view, seek_pos(timestamp.start + (i32)str.size - 1), true); } } diff --git a/4coder_os_comp_cracking.h b/4coder_os_comp_cracking.h deleted file mode 100644 index b62acfb4..00000000 --- a/4coder_os_comp_cracking.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 31.03.2017 - * - * OS & Compiler cracking for 4coder - * - */ - -// TOP - -#if !defined(FCODER_OS_COMP_CRACKING_H) -#define FCODER_OS_COMP_CRACKING_H - -#if defined(_MSC_VER) /* COMPILER */ - -# define IS_CL - -// NOTE(allen): I suspect snprintf is defined in VS 2015 (I test on 2017) -#if _MSC_VER <= 1800 -# define snprintf _snprintf -#endif - -# if defined(_WIN32) /* OS */ -# define IS_WINDOWS -# pragma comment(lib, "Kernel32.lib") -# else -# error This compiler/platform combo is not supported yet -# endif - -# if defined(_M_AMD64) /* Architecture */ -# define CALL_CONVENTION -# define BUILD_X64 -# elif defined(_M_IX86) -# define CALL_CONVENTION __stdcall -# define BUILD_X86 -# else -# error architecture not supported yet -# endif - -#elif defined(__GNUC__) || defined(__GNUG__) - -# define IS_GCC /* COMPILER */ - -# if defined(__gnu_linux__) /* OS */ -# define IS_LINUX -# define CALL_CONVENTION -# elif defined(__APPLE__) && defined(__MACH__) /* OS */ -# define IS_MAC -# define CALL_CONVENTION -#else -# error This compiler/platform combo is not supported yet -# endif - -#else -# error This compiler is not supported yet -#endif - -#endif - -// BOTTOM - diff --git a/4coder_project_commands.cpp b/4coder_project_commands.cpp index 3905a741..83570c42 100644 --- a/4coder_project_commands.cpp +++ b/4coder_project_commands.cpp @@ -5,48 +5,34 @@ // TOP static Project current_project = {}; -static Partition current_project_arena = {}; +static Arena current_project_arena = {}; /////////////////////////////// static Project_File_Pattern_Array -get_pattern_array_from_cstring_array(Partition *arena, CString_Array list){ +get_pattern_array_from_string_array(Arena *arena, String_Const_u8_Array list){ Project_File_Pattern_Array array = {}; - i32 count = list.count; - array.patterns = push_array(arena, Project_File_Pattern, count); - array.count = count; - for (i32 i = 0; i < count; ++i){ - String base_str = make_string_slowly(list.strings[i]); - String str = string_push(arena, base_str.size + 3); - append(&str, "*."); - append(&str, base_str); - terminate_with_null(&str); - get_absolutes(str, &array.patterns[i].absolutes, false, false); + array.count = list.count; + array.patterns = push_array(arena, Project_File_Pattern, list.count); + for (i32 i = 0; i < list.count; ++i){ + String_Const_u8 str = string_u8_pushf(arena, "*.%.*s", string_expand(list.strings[i])); + array.patterns[i].absolutes = string_split_wildcards(arena, str); } return(array); } -static Project_File_Pattern_Array -get_pattern_array_from_extension_list(Partition *arena, Extension_List extension_list){ - CString_Array list = {}; - list.strings = extension_list.exts; - list.count = extension_list.count; - return(get_pattern_array_from_cstring_array(arena, list)); -} - /////////////////////////////// static void -close_all_files_with_extension(Application_Links *app, Partition *scratch_part, CString_Array extension_array){ - Temp_Memory temp = begin_temp_memory(scratch_part); +close_all_files_with_extension(Application_Links *app, String_Const_u8_Array extension_array){ + Scratch_Block scratch(app); - i32 buffers_to_close_max = part_remaining(scratch_part)/sizeof(i32); - i32 *buffers_to_close = push_array(scratch_part, i32, buffers_to_close_max); + i32 buffers_to_close_max = Thousand(100); + Buffer_ID *buffers_to_close = push_array(scratch, Buffer_ID, buffers_to_close_max); - i32 buffers_to_close_count = 0; b32 do_repeat = false; do{ - buffers_to_close_count = 0; + i32 buffers_to_close_count = 0; do_repeat = false; Buffer_ID buffer = 0; @@ -56,20 +42,19 @@ close_all_files_with_extension(Application_Links *app, Partition *scratch_part, b32 is_match = true; if (extension_array.count > 0){ - Arena *scratch = context_get_arena(app); - Temp_Memory_Arena name_temp = begin_temp_memory(scratch); - String file_name = buffer_push_file_name(app, buffer, scratch); + Temp_Memory name_temp = begin_temp(scratch); + String_Const_u8 file_name = buffer_push_file_name(app, buffer, scratch); is_match = false; if (file_name.size > 0){ - String extension = file_extension(file_name); + String_Const_u8 extension = string_file_extension(file_name); for (i32 i = 0; i < extension_array.count; ++i){ - if (match(extension, extension_array.strings[i])){ + if (string_match(extension, extension_array.strings[i])){ is_match = true; break; } } } - end_temp_memory(name_temp); + end_temp(name_temp); } if (is_match){ @@ -85,16 +70,14 @@ close_all_files_with_extension(Application_Links *app, Partition *scratch_part, kill_buffer(app, buffer_identifier(buffers_to_close[i]), true, 0); } }while(do_repeat); - - end_temp_memory(temp); } static b32 -match_in_pattern_array(char *str, Project_File_Pattern_Array array){ +match_in_pattern_array(String_Const_u8 string, Project_File_Pattern_Array array){ b32 found_match = false; Project_File_Pattern *pattern = array.patterns; for (i32 i = 0; i < array.count; ++i, ++pattern){ - if (wildcard_match_c(&pattern->absolutes, str, true)){ + if (string_wildcard_match(pattern->absolutes, string, StringMatch_Exact)){ found_match = true; break; } @@ -103,41 +86,46 @@ match_in_pattern_array(char *str, Project_File_Pattern_Array array){ } static void -open_all_files_in_directory_pattern_match__inner(Application_Links *app, String space, - Project_File_Pattern_Array whitelist, - Project_File_Pattern_Array blacklist, - u32 flags){ - File_List list = get_file_list(app, space.str, space.size); - i32 dir_size = space.size; +open_all_files_in_directory_pattern_match__recursive(Application_Links *app, + String_Const_u8 path, + Project_File_Pattern_Array whitelist, + Project_File_Pattern_Array blacklist, + u32 flags){ + Scratch_Block scratch(app); + File_List list = {}; + get_file_list(app, path, &list); File_Info *info = list.infos; for (u32 i = 0; i < list.count; ++i, ++info){ + String_Const_u8 file_name = SCu8(info->filename, info->filename_len); + if (info->folder){ if ((flags & OpenAllFilesFlag_Recursive) == 0){ continue; } - if (match_in_pattern_array(info->filename, blacklist)){ + if (match_in_pattern_array(file_name, blacklist)){ continue; } - space.size = dir_size; - String str = make_string(info->filename, info->filename_len); - append(&space, str); - append(&space, "/"); - open_all_files_in_directory_pattern_match__inner(app, space, whitelist, blacklist, flags); + String_Const_u8 new_path = string_u8_pushf(scratch, "%.*s%.*s/", + string_expand(path), + string_expand(file_name)); + open_all_files_in_directory_pattern_match__recursive(app, new_path, + whitelist, blacklist, flags); } else{ - if (!match_in_pattern_array(info->filename, whitelist)){ + if (!match_in_pattern_array(file_name, whitelist)){ continue; } - if (match_in_pattern_array(info->filename, blacklist)){ + if (match_in_pattern_array(file_name, blacklist)){ continue; } - space.size = dir_size; - String str = make_string(info->filename, info->filename_len); - append(&space, str); - create_buffer(app, space.str, space.size, 0); + String_Const_u8 full_path = string_u8_pushf(scratch, "%.*s%.*s", + string_expand(path), + string_expand(file_name)); + Buffer_ID ignore = 0; + create_buffer(app, full_path, 0, &ignore); } } @@ -145,85 +133,66 @@ open_all_files_in_directory_pattern_match__inner(Application_Links *app, String } static Project_File_Pattern_Array -get_standard_blacklist(Partition *arena){ - static char *dot_str = ".*"; - CString_Array black_array = {}; - black_array.strings = &dot_str; +get_standard_blacklist(Arena *arena){ + String_Const_u8 dot = string_u8_litexpr(".*"); + String_Const_u8_Array black_array = {}; + black_array.strings = ˙ black_array.count = 1; - return(get_pattern_array_from_cstring_array(arena, black_array)); + return(get_pattern_array_from_string_array(arena, black_array)); } static void -open_all_files_in_directory_pattern_match(Application_Links *app, Partition *scratch, - String dir, +open_all_files_in_directory_pattern_match(Application_Links *app, + String_Const_u8 dir, Project_File_Pattern_Array whitelist, Project_File_Pattern_Array blacklist, u32 flags){ - Temp_Memory temp = begin_temp_memory(scratch); - i32 size = 32 << 10; - char *mem = push_array(scratch, char, size); - String space = make_string_cap(mem, 0, size); - append(&space, dir); - if (space.size == 0 || !char_is_slash(space.str[space.size - 1])){ - append(&space, '/'); + Scratch_Block scratch(app); + String_Const_u8 directory = dir; + if (!character_is_slash(string_get_character(directory, directory.size - 1))){ + directory = string_u8_pushf(scratch, "%.*s/", string_expand(dir)); } - open_all_files_in_directory_pattern_match__inner(app, space, whitelist, blacklist, flags); - end_temp_memory(temp); + open_all_files_in_directory_pattern_match__recursive(app, directory, whitelist, blacklist, flags); } static void -open_all_files_in_directory_with_extension(Application_Links *app, Partition *scratch, - String dir, CString_Array array, - u32 flags){ - Temp_Memory temp = begin_temp_memory(scratch); - Project_File_Pattern_Array whitelist = get_pattern_array_from_cstring_array(scratch, array); +open_all_files_in_directory_with_extension(Application_Links *app, String_Const_u8 dir, String_Const_u8_Array array, u32 flags){ + Scratch_Block scratch(app); + Project_File_Pattern_Array whitelist = get_pattern_array_from_string_array(scratch, array); Project_File_Pattern_Array blacklist = get_standard_blacklist(scratch); - open_all_files_in_directory_pattern_match(app, scratch, dir, whitelist, blacklist, flags); - end_temp_memory(temp); + open_all_files_in_directory_pattern_match(app, dir, whitelist, blacklist, flags); } static void -open_all_files_in_hot_with_extension(Application_Links *app, Partition *scratch, - CString_Array array, - u32 flags){ - Temp_Memory temp = begin_temp_memory(scratch); - i32 size = 32 << 10; - char *mem = push_array(scratch, char, size); - String space = make_string_cap(mem, 0, size); - space.size = directory_get_hot(app, space.str, space.memory_size); - if (space.size == 0 || !char_is_slash(space.str[space.size - 1])){ - append(&space, '/'); +open_all_files_in_hot_with_extension(Application_Links *app, String_Const_u8_Array array, u32 flags){ + Scratch_Block scratch(app); + String_Const_u8 hot = push_hot_directory(app, scratch); + String_Const_u8 directory = hot; + if (!character_is_slash(string_get_character(hot, hot.size - 1))){ + directory = string_u8_pushf(scratch, "%.*s/", string_expand(hot)); } - Project_File_Pattern_Array whitelist = get_pattern_array_from_cstring_array(scratch, array); - Project_File_Pattern_Array blacklist = get_standard_blacklist(scratch); - open_all_files_in_directory_pattern_match__inner(app, space, whitelist, blacklist, flags); - end_temp_memory(temp); + open_all_files_in_directory_with_extension(app, hot, array, flags); } /////////////////////////////// -#if defined(IS_WINDOWS) +#if OS_WINDOWS #define PlatformName "win" -#elif defined(IS_LINUX) +#elif OS_LINUX #define PlatformName "linux" -#elif defined(IS_MAC) +#elif OS_MAC #define PlatformName "mac" #else # error no project configuration names for this platform #endif static Project* -parse_project__config_data__version_0(Partition *arena, String file_dir, Config *parsed){ - Project *project = push_array(arena, Project, 1); - memset(project, 0, sizeof(*project)); +parse_project__config_data__version_0(Arena *arena, String_Const_u8 file_dir, Config *parsed){ + Project *project = push_array_zero(arena, Project, 1); // Set new project directory { - i32 cap = file_dir.size + 1; - char *mem = push_array(arena, char, cap); - project->dir = make_string(mem, 0, cap); - copy(&project->dir, file_dir); - terminate_with_null(&project->dir); + project->dir = string_copy(arena, file_dir); project->load_path_array.paths = push_array(arena, Project_File_Load_Path, 1); project->load_path_array.count = 1; @@ -236,11 +205,10 @@ parse_project__config_data__version_0(Partition *arena, String file_dir, Config } // Read the settings from project.4coder - String str = {}; + String_Const_u8 str = {}; if (config_string_var(parsed, "extensions", 0, &str)){ - Extension_List extension_list; - parse_extension_line_to_extension_list(str, &extension_list); - project->pattern_array = get_pattern_array_from_extension_list(arena, extension_list); + String_Const_u8_Array extension_list = parse_extension_line_to_extension_list(arena, str); + project->pattern_array = get_pattern_array_from_string_array(arena, extension_list); project->blacklist_pattern_array = get_standard_blacklist(arena); } @@ -257,22 +225,20 @@ parse_project__config_data__version_0(Partition *arena, String file_dir, Config Project_Command *command = project->command_array.commands; for (i32 j = 1; j <= 16; ++j, ++command){ project->fkey_commands[j - 1] = j - 1; - memset(command, 0, sizeof(*command)); + block_zero_struct(command); + + command->name = string_u8_pushf(arena, "%d", j); Config_Compound *compound = 0; if (config_compound_var(parsed, fkey_command_name, j, &compound)){ - command->name = string_push(arena, 4); - append_int_to_str(&command->name, j); - terminate_with_null(&command->name); - - String cmd = {}; + String_Const_u8 cmd = {}; if (config_compound_string_member(parsed, compound, "cmd", 0, &cmd)){ - command->cmd = string_push_copy(arena, cmd); + command->cmd = string_copy(arena, cmd); } - String out = {}; + String_Const_u8 out = {}; if (config_compound_string_member(parsed, compound, "out", 1, &out)){ - command->out = string_push_copy(arena, out); + command->out = string_copy(arena, out); } b32 footer_panel = false; @@ -285,11 +251,6 @@ parse_project__config_data__version_0(Partition *arena, String file_dir, Config command->save_dirty_files = save_dirty_files; } } - else{ - command->name = string_push(arena, 4); - append_int_to_str(&command->name, j); - terminate_with_null(&command->name); - } } project->loaded = true; @@ -297,9 +258,7 @@ parse_project__config_data__version_0(Partition *arena, String file_dir, Config } static void -parse_project__extract_pattern_array(Partition *arena, Config *parsed, - char *root_variable_name, - Project_File_Pattern_Array *array_out){ +parse_project__extract_pattern_array(Arena *arena, Config *parsed, char *root_variable_name, Project_File_Pattern_Array *array_out){ Config_Compound *compound = 0; if (config_compound_var(parsed, root_variable_name, 0, &compound)){ Config_Get_Result_List list = typed_string_array_reference_list(arena, parsed, compound); @@ -311,47 +270,41 @@ parse_project__extract_pattern_array(Partition *arena, Config *parsed, for (Config_Get_Result_Node *node = list.first; node != 0; node = node->next, i += 1){ - String str = string_push_copy(arena, node->result.string); - get_absolutes(str, &array_out->patterns[i].absolutes, false, false); + String_Const_u8 str = string_copy(arena, node->result.string); + array_out->patterns[i].absolutes = string_split_wildcards(arena, str); } } } static Project_OS_Match_Level -parse_project__version_1__os_match(String str, String this_os_str){ - if (match(str, this_os_str)){ +parse_project__version_1__os_match(String_Const_u8 str, String_Const_u8 this_os_str){ + if (string_match(str, this_os_str)){ return(ProjectOSMatchLevel_ActiveMatch); } - else if (match(str, make_lit_string("all"))){ + else if (string_match(str, string_u8_litexpr("all"))){ return(ProjectOSMatchLevel_ActiveMatch); } - else if (match(str, make_lit_string("default"))){ + else if (string_match(str, string_u8_litexpr("default"))){ return(ProjectOSMatchLevel_PassiveMatch); } return(ProjectOSMatchLevel_NoMatch); } static Project* -parse_project__config_data__version_1(Partition *arena, String root_dir, Config *parsed){ - Project *project = push_array(arena, Project, 1); - memset(project, 0, sizeof(*project)); +parse_project__config_data__version_1(Arena *arena, String_Const_u8 root_dir, Config *parsed){ + Project *project = push_array_zero(arena, Project, 1); // Set new project directory - { - i32 cap = root_dir.size + 1; - project->dir = string_push(arena, cap); - copy(&project->dir, root_dir); - terminate_with_null(&project->dir); - } + project->dir = string_copy(arena, root_dir); // project_name { - String str = {}; + String_Const_u8 str = {}; if (config_string_var(parsed, "project_name", 0, &str)){ - project->name = string_push_copy(arena, str); + project->name = string_copy(arena, str); } else{ - project->name = make_lit_string(""); + project->name = SCu8(""); } } @@ -380,9 +333,9 @@ parse_project__config_data__version_1(Partition *arena, String root_dir, Config Config_Compound *paths = 0; if (config_compound_compound_member(parsed, paths_option, "paths", 0, &paths)){ - String str = {}; + String_Const_u8 str = {}; if (config_compound_string_member(parsed, paths_option, "os", 1, &str)){ - Project_OS_Match_Level r = parse_project__version_1__os_match(str, make_lit_string(PlatformName)); + Project_OS_Match_Level r = parse_project__version_1__os_match(str, string_u8_litexpr(PlatformName)); if (r == ProjectOSMatchLevel_ActiveMatch){ found_match = true; best_paths = paths; @@ -413,9 +366,9 @@ parse_project__config_data__version_1(Partition *arena, String root_dir, Config dst->recursive = true; dst->relative = true; - String str = {}; + String_Const_u8 str = {}; if (config_compound_string_member(parsed, src, "path", 0, &str)){ - dst->path = string_push_copy(arena, str); + dst->path = string_copy(arena, str); } config_compound_bool_member(parsed, src, "recursive", 1, &dst->recursive); @@ -438,21 +391,21 @@ parse_project__config_data__version_1(Partition *arena, String root_dir, Config for (Config_Get_Result_Node *node = list.first; node != 0; node = node->next, ++dst){ - char *pos = node->result.pos; + u8 *pos = node->result.pos; Config_Compound *src = node->result.compound; - memset(dst, 0, sizeof(*dst)); + block_zero_struct(dst); b32 can_emit_command = true; - String name = {}; Config_Get_Result cmd_result = {}; Config_Compound *cmd_set = 0; - char *cmd_pos = 0; - String cmd_str = {}; - String out = {}; + u8 *cmd_pos = 0; + String_Const_u8 cmd_str = {}; + String_Const_u8 out = {}; b32 footer_panel = false; b32 save_dirty_files = true; b32 cursor_at_end = false; + String_Const_u8 name = {}; if (!config_compound_string_member(parsed, src, "name", 0, &name)){ can_emit_command = false; @@ -461,7 +414,7 @@ parse_project__config_data__version_1(Partition *arena, String root_dir, Config } cmd_result = config_compound_member(parsed, src, - make_lit_string("cmd"), 1); + string_u8_litexpr("cmd"), 1); if (cmd_result.success){ cmd_set = cmd_result.compound; cmd_pos = cmd_result.pos; @@ -483,11 +436,11 @@ parse_project__config_data__version_1(Partition *arena, String root_dir, Config } Config_Compound *cmd_option = result.get.compound; - String cmd = {}; + String_Const_u8 cmd = {}; if (config_compound_string_member(parsed, cmd_option, "cmd", 0, &cmd)){ - String str = {}; + String_Const_u8 str = {}; if (config_compound_string_member(parsed, cmd_option, "os", 1, &str)){ - Project_OS_Match_Level r = parse_project__version_1__os_match(str, make_lit_string(PlatformName)); + Project_OS_Match_Level r = parse_project__version_1__os_match(str, string_u8_litexpr(PlatformName)); if (r == ProjectOSMatchLevel_ActiveMatch){ can_emit_command = true; cmd_str = cmd; @@ -515,9 +468,9 @@ parse_project__config_data__version_1(Partition *arena, String root_dir, Config config_compound_bool_member(parsed, src, "cursor_at_end", 5, &cursor_at_end); - dst->name = string_push_copy(arena, name); - dst->cmd = string_push_copy(arena, cmd_str); - dst->out = string_push_copy(arena, out); + dst->name = string_copy(arena, name); + dst->cmd = string_copy(arena, cmd_str); + dst->out = string_copy(arena, out); dst->footer_panel = footer_panel; dst->save_dirty_files = save_dirty_files; dst->cursor_at_end = cursor_at_end; @@ -530,13 +483,13 @@ parse_project__config_data__version_1(Partition *arena, String root_dir, Config // fkey_command { for (i32 i = 1; i <= 16; ++i){ - String name = {}; + String_Const_u8 name = {}; i32 index = -1; if (config_string_var(parsed, "fkey_command", i, &name)){ i32 count = project->command_array.count; Project_Command *command_ptr = project->command_array.commands; for (i32 j = 0; j < count; ++j, ++command_ptr){ - if (match(command_ptr->name, name)){ + if (string_match(command_ptr->name, name)){ index = j; break; } @@ -551,7 +504,7 @@ parse_project__config_data__version_1(Partition *arena, String root_dir, Config } static Project* -parse_project__config_data(Partition *arena, String file_dir, Config *parsed){ +parse_project__config_data(Arena *arena, String_Const_u8 file_dir, Config *parsed){ i32 version = 0; if (parsed->version != 0){ version = *parsed->version; @@ -576,7 +529,8 @@ parse_project__config_data(Partition *arena, String file_dir, Config *parsed){ } static Project_Parse_Result -parse_project__data(Partition *arena, String file_name, String data, String file_dir){ +parse_project__data(Arena *arena, String_Const_u8 file_name, Data raw_data, String_Const_u8 file_dir){ + String_Const_u8 data = SCu8(raw_data); Project_Parse_Result result = {}; Cpp_Token_Array array = text_data_to_token_array(arena, data); if (array.tokens != 0){ @@ -589,117 +543,79 @@ parse_project__data(Partition *arena, String file_name, String data, String file } static Project_Parse_Result -parse_project__nearest_file(Application_Links *app, Partition *arena){ +parse_project__nearest_file(Application_Links *app, Arena *arena){ Project_Parse_Result result = {}; - Temp_Memory restore_point = begin_temp_memory(arena); - String project_path = {}; - i32 size = 32 << 10; - char *space = push_array(arena, char, size); - if (space != 0){ - project_path = make_string_cap(space, 0, size); - project_path.size = directory_get_hot(app, project_path.str, project_path.memory_size); - end_temp_memory(restore_point); - push_array(arena, char, project_path.size); - project_path.memory_size = project_path.size; - if (project_path.size == 0){ - print_message(app, literal("The hot directory is empty, cannot search for a project.\n")); + Temp_Memory restore_point = begin_temp(arena); + String_Const_u8 project_path = {}; + get_hot_directory(app, arena, &project_path); + if (project_path.size == 0){ + print_message(app, string_u8_litexpr("The hot directory is empty, cannot search for a project.\n")); + } + else{ + File_Name_Data dump = dump_file_search_up_path(app, arena, project_path, string_u8_litexpr("project.4coder")); + if (dump.data.data != 0){ + String_Const_u8 project_root = string_remove_last_folder(dump.file_name); + result = parse_project__data(arena, dump.file_name, dump.data, project_root); } else{ - File_Name_Path_Data dump = dump_file_search_up_path(arena, project_path, make_lit_string("project.4coder")); - if (dump.data.str != 0){ - String project_root = dump.path; - remove_last_folder(&project_root); - result = parse_project__data(arena, dump.file_name, dump.data, project_root); - } - else{ - char message_space[512]; - String message = make_fixed_width_string(message_space); - append(&message, "Did not find project.4coder. "); - if (current_project.loaded){ - if (current_project.name.size > 0){ - append(&message, "Continuing with: "); - append(&message, current_project.name); - } - else{ - append(&message, "Continuing with: "); - append(&message, current_project.dir); - } + List_String_Const_u8 list = {}; + string_list_push(arena, &list, string_u8_litexpr("Did not find project.4coder. ")); + if (current_project.loaded){ + string_list_push(arena, &list, string_u8_litexpr("Continuing with: ")); + if (current_project.name.size > 0){ + string_list_push(arena, &list, current_project.name); } else{ - append(&message, "Continuing without a project"); + string_list_push(arena, &list, current_project.dir); } - append(&message, '\n'); - print_message(app, message.str, message.size); } + else{ + string_list_push(arena, &list, string_u8_litexpr("Continuing without a project.")); + } + string_list_push(arena, &list, string_u8_litexpr("\n")); + String_Const_u8 message = string_list_flatten(arena, list); + print_message(app, message); + end_temp(restore_point); } } return(result); } -static b32 -project_deep_copy__pattern_array(Partition *arena, Project_File_Pattern_Array *src_array, - Project_File_Pattern_Array *dst_array){ +static void +project_deep_copy__pattern_array(Arena *arena, Project_File_Pattern_Array *src_array, Project_File_Pattern_Array *dst_array){ i32 pattern_count = src_array->count; dst_array->patterns = push_array(arena, Project_File_Pattern, pattern_count); - if (dst_array->patterns == 0){ - return(false); - } dst_array->count = pattern_count; - Project_File_Pattern *dst = dst_array->patterns; Project_File_Pattern *src = src_array->patterns; for (i32 i = 0; i < pattern_count; ++i, ++dst, ++src){ - i32 abs_count = src->absolutes.count; - dst->absolutes.count = abs_count; - for (i32 j = 0; j < abs_count; ++j){ - dst->absolutes.a[j] = string_push_copy(arena, src->absolutes.a[j]); - if (dst->absolutes.a[j].str == 0){ - return(false); - } + for (Node_String_Const_u8 *node = src->absolutes.first; + node != 0; + node = node->next){ + string_list_push(arena, &dst->absolutes, node->string); } } - - return(true); } static Project -project_deep_copy__inner(Partition *arena, Project *project){ +project_deep_copy__inner(Arena *arena, Project *project){ Project result = {}; - - result.dir = string_push_copy(arena, project->dir); - if (result.dir.str == 0){ - return(result); - } - - result.name = string_push_copy(arena, project->name); - if (result.name.str == 0){ - return(result); - } - - if (!project_deep_copy__pattern_array(arena, &project->pattern_array, &result.pattern_array)){ - return(result); - } - if (!project_deep_copy__pattern_array(arena, &project->blacklist_pattern_array, &result.blacklist_pattern_array)){ - return(result); - } + result.dir = string_copy(arena, project->dir); + result.name = string_copy(arena, project->name); + project_deep_copy__pattern_array(arena, &project->pattern_array, &result.pattern_array); + project_deep_copy__pattern_array(arena, &project->blacklist_pattern_array, &result.blacklist_pattern_array); { i32 path_count = project->load_path_array.count; result.load_path_array.paths = push_array(arena, Project_File_Load_Path, path_count); - if (result.load_path_array.paths == 0){ - return(result); - } result.load_path_array.count = path_count; Project_File_Load_Path *dst = result.load_path_array.paths; Project_File_Load_Path *src = project->load_path_array.paths; for (i32 i = 0; i < path_count; ++i, ++dst, ++src){ - dst->path = string_push_copy(arena, src->path); - if (dst->path.str == 0){ - return(result); - } + dst->path = string_copy(arena, src->path); dst->recursive = src->recursive; dst->relative = src->relative; } @@ -707,33 +623,20 @@ project_deep_copy__inner(Partition *arena, Project *project){ { i32 command_count = project->command_array.count; - result.command_array.commands = push_array(arena, Project_Command, command_count); - if (result.command_array.commands == 0){ - return(result); - } + result.command_array.commands = push_array_zero(arena, Project_Command, command_count); result.command_array.count = command_count; Project_Command *dst = result.command_array.commands; Project_Command *src = project->command_array.commands; for (i32 i = 0; i < command_count; ++i, ++dst, ++src){ - memset(dst, 0, sizeof(*dst)); if (src->name.str != 0){ - dst->name = string_push_copy(arena, src->name); - if (dst->name.str == 0){ - return(result); - } + dst->name = string_copy(arena, src->name); } if (src->cmd.str != 0){ - dst->cmd = string_push_copy(arena, src->cmd); - if (dst->cmd.str == 0){ - return(result); - } + dst->cmd = string_copy(arena, src->cmd); } if (src->out.str != 0){ - dst->out = string_push_copy(arena, src->out); - if (dst->out.str == 0){ - return(result); - } + dst->out = string_copy(arena, src->out); } dst->footer_panel = src->footer_panel; dst->save_dirty_files = src->save_dirty_files; @@ -741,108 +644,85 @@ project_deep_copy__inner(Partition *arena, Project *project){ } } - { - memcpy(result.fkey_commands, project->fkey_commands, sizeof(result.fkey_commands)); - } + memcpy(result.fkey_commands, project->fkey_commands, sizeof(result.fkey_commands)); result.loaded = true; return(result); } static Project -project_deep_copy(Partition *arena, Project *project){ - Temp_Memory temp = begin_temp_memory(arena); +project_deep_copy(Arena *arena, Project *project){ + Temp_Memory restore_point = begin_temp(arena); Project result = project_deep_copy__inner(arena, project); if (!result.loaded){ - end_temp_memory(temp); - memset(&result, 0, sizeof(result)); + end_temp(restore_point); + block_zero_struct(&result); } return(result); } static void -config_feedback_file_pattern_array(String *space, char *name, Project_File_Pattern_Array *array){ - append(space, name); - append(space, " = {\n"); +config_feedback_file_pattern_array(Arena *arena, List_String_Const_u8 *list, char *name, Project_File_Pattern_Array *array){ + string_list_pushf(arena, list, "%s = {\n", name); Project_File_Pattern *pattern = array->patterns; for (i32 i = 0; i < array->count; ++i, ++pattern){ - append(space, "\""); - String *absolute = pattern->absolutes.a; - for (i32 j = 0; j < pattern->absolutes.count; ++j, ++absolute){ - if (j != 0){ - append(space, "*"); + string_list_push_u8_lit(arena, list, "\""); + b32 is_first = true; + for (Node_String_Const_u8 *node = pattern->absolutes.first; + node != 0; + node = node->next){ + if (is_first){ + string_list_push(arena, list, node->string); + is_first = false; + } + else{ + string_list_pushf(arena, list, "*%.*s", string_expand(node->string)); } - append(space, *absolute); } - append(space, "\",\n"); + string_list_push_u8_lit(arena, list, "\",\n"); } - append(space, "};\n"); + string_list_push_u8_lit(arena, list, "};\n"); } static void -config_feedback_file_load_path_array(String *space, char *name, Project_File_Load_Path_Array *array){ - append(space, name); - append(space, " = {\n"); +config_feedback_file_load_path_array(Arena *arena, List_String_Const_u8 *list, char *name, Project_File_Load_Path_Array *array){ + string_list_pushf(arena, list, "%s = {\n", name); Project_File_Load_Path *path = array->paths; for (i32 i = 0; i < array->count; ++i, ++path){ - append(space, "{ "); - append(space, ".path = \""); - append(space, path->path); - append(space, "\", "); - append(space, ".recursive = "); - append(space, (char*)(path->recursive?"true":"false")); - append(space, ", "); - append(space, ".relative = "); - append(space, (char*)(path->relative?"true":"false")); - append(space, ", "); - append(space, "},\n"); + string_list_pushf(arena, list, "{ .path = \"%.*s\", .recursive = %s, .relative = %s, },\n", + string_expand(path->path), (char*)(path->recursive?"true":"false"), (char*)(path->relative?"true":"false")); } - append(space, "};\n"); + string_list_push_u8_lit(arena, list, "};\n"); } static void -config_feedback_command_array(String *space, char *name, Project_Command_Array *array){ - append(space, name); - append(space, " = {\n"); +config_feedback_command_array(Arena *arena, List_String_Const_u8 *list, char *name, Project_Command_Array *array){ + string_list_pushf(arena, list, "%s = {\n", name); Project_Command *command = array->commands; for (i32 i = 0; i < array->count; ++i, ++command){ - append(space, "{ "); - append(space, ".name = \""); - append(space, command->name); - append(space, "\", "); - append(space, ".cmd = \""); - append(space, command->cmd); - append(space, "\", "); - append(space, ".out = \""); - append(space, command->out); - append(space, "\", "); - append(space, ".footer_panel = "); - append(space, (char*)(command->footer_panel?"true":"false")); - append(space, ", "); - append(space, ".save_dirty_files = "); - append(space, (char*)(command->save_dirty_files?"true":"false")); - append(space, ", "); - append(space, ".cursor_at_end = "); - append(space, (char*)(command->cursor_at_end?"true":"false")); - append(space, ", "); - append(space, "},\n"); + string_list_pushf(arena, list, + "{ .name = \"%.*s\", .cmd = \"%.*s\", .out = \"%.*s\", " + ".footer_panel = %s, .save_dirty_files = %s, .cursor_at_end = %s, },\n", + string_expand(command->name), string_expand(command->cmd), string_expand(command->out), + (char*)(command->footer_panel?"true":"false"), + (char*)(command->save_dirty_files?"true":"false"), + (char*)(command->cursor_at_end?"true":"false")); } - append(space, "};\n"); + string_list_push_u8_lit(arena, list, "};\n"); } static void -set_current_project(Application_Links *app, Partition *scratch, Project *project, Config *parsed){ +set_current_project(Application_Links *app, Project *project, Config *parsed){ b32 print_feedback = false; + Scratch_Block scratch(app); if (parsed != 0 && project != 0){ - if (current_project_arena.base == 0){ - i32 project_mem_size = (1 << 20); - void *project_mem = memory_allocate(app, project_mem_size); - current_project_arena = make_part(project_mem, project_mem_size); + if (current_project_arena.base_allocator == 0){ + current_project_arena = make_arena_app_links(app, KB(64)); } // Copy project to current_project - current_project_arena.pos = 0; + linalloc_clear(¤t_project_arena); Project new_project = project_deep_copy(¤t_project_arena, project); if (new_project.loaded){ current_project = new_project; @@ -857,50 +737,36 @@ set_current_project(Application_Links *app, Partition *scratch, Project *project flags |= OpenAllFilesFlag_Recursive; } - Temp_Memory temp = begin_temp_memory(scratch); - String path_str = load_path->path; - String file_dir = path_str; + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 path_str = load_path->path; + String_Const_u8 file_dir = path_str; if (load_path->relative){ - String project_dir = current_project.dir; - i32 cap = path_str.size + project_dir.size + 2; - char *mem = push_array(scratch, char, cap); - push_align(scratch, 8); - if (mem != 0){ - file_dir = make_string_cap(mem, 0, cap); - append(&file_dir, project_dir); - if (file_dir.size == 0 || file_dir.str[file_dir.size - 1] != '/'){ - append(&file_dir, "/"); - } - append(&file_dir, path_str); - if (file_dir.size == 0 || file_dir.str[file_dir.size - 1] != '/'){ - append(&file_dir, "/"); - } - terminate_with_null(&file_dir); - } + String_Const_u8 project_dir = current_project.dir; + List_String_Const_u8 file_dir_list = {}; + string_list_push(scratch, &file_dir_list, project_dir); + string_list_push_overlap(scratch, &file_dir_list, '/', path_str); + string_list_push_overlap(scratch, &file_dir_list, '/', SCu8()); + file_dir = string_list_flatten(scratch, file_dir_list, StringFill_NullTerminate); } Project_File_Pattern_Array whitelist = current_project.pattern_array; Project_File_Pattern_Array blacklist = current_project.blacklist_pattern_array; - open_all_files_in_directory_pattern_match(app, scratch, file_dir, - whitelist, blacklist, - flags); - - end_temp_memory(temp); + open_all_files_in_directory_pattern_match(app, file_dir, whitelist, blacklist, flags); + end_temp(temp); } // Set window title if (project->name.size > 0){ - char space[1024]; - String builder = make_fixed_width_string(space); - append(&builder, "4coder project: "); - append(&builder, project->name); - terminate_with_null(&builder); - set_window_title(app, builder.str); + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 builder = string_u8_pushf(scratch, "4coder project: %.*s", + string_expand(project->name)); + set_window_title(app, builder); + end_temp(temp); } } else{ #define M "Failed to initialize new project; need more memory dedicated to the project system.\n" - print_message(app, literal(M)); + print_message(app, string_u8_litexpr(M)); #undef M } } @@ -909,57 +775,58 @@ set_current_project(Application_Links *app, Partition *scratch, Project *project } if (print_feedback){ - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); // Top - print_message(app, literal("Loaded project file:\n")); + print_message(app, string_u8_litexpr("Loaded project file:\n")); // Errors - String error_text = config_stringize_errors(scratch, parsed); - print_message(app, error_text.str, error_text.size); + String_Const_u8 error_text = config_stringize_errors(scratch, parsed); + print_message(app, error_text); // Values if (project == 0){ - print_message(app, literal("Could not instantiate project\n")); + print_message(app, string_u8_litexpr("Could not instantiate project\n")); } else{ - Temp_Memory temp2 = begin_temp_memory(scratch); - String space = string_push(scratch, part_remaining(scratch)); + Temp_Memory temp2 = begin_temp(scratch); + List_String_Const_u8 list = {}; - { - config_feedback_string(&space, "'root_directory'", project->dir); - config_feedback_string(&space, "project_name", project->name); - - config_feedback_file_pattern_array(&space, "patterns", &project->pattern_array); - config_feedback_file_pattern_array(&space, "blacklist_patterns", &project->blacklist_pattern_array); - config_feedback_file_load_path_array(&space, "load_paths", &project->load_path_array); - config_feedback_command_array(&space, "command_list", &project->command_array); - } + config_feedback_string(scratch, &list, "'root_directory'", project->dir); + config_feedback_string(scratch, &list, "project_name", project->name); - append(&space, "\n"); - print_message(app, space.str, space.size); - end_temp_memory(temp2); + config_feedback_file_pattern_array(scratch, &list, "patterns", &project->pattern_array); + config_feedback_file_pattern_array(scratch, &list, "blacklist_patterns", &project->blacklist_pattern_array); + config_feedback_file_load_path_array(scratch, &list, "load_paths", &project->load_path_array); + config_feedback_command_array(scratch, &list, "command_list", &project->command_array); + + string_list_push_u8_lit(scratch, &list, "\n"); + + String_Const_u8 message = string_list_flatten(scratch, list); + print_message(app, message); + end_temp(temp2); } - end_temp_memory(temp); + end_temp(temp); } } static void -set_current_project_from_data(Application_Links *app, Partition *scratch, - String file_name, String data, String file_dir){ - Temp_Memory temp = begin_temp_memory(scratch); +set_current_project_from_data(Application_Links *app, String_Const_u8 file_name, Data data, String_Const_u8 file_dir){ + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); Project_Parse_Result project_parse = parse_project__data(scratch, file_name, data, file_dir); - set_current_project(app, scratch, project_parse.project, project_parse.parsed); - end_temp_memory(temp); + set_current_project(app, project_parse.project, project_parse.parsed); + end_temp(temp); } static void -set_current_project_from_nearest_project_file(Application_Links *app, Partition *scratch){ - Temp_Memory temp = begin_temp_memory(scratch); +set_current_project_from_nearest_project_file(Application_Links *app){ + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); Project_Parse_Result project_parse = parse_project__nearest_file(app, scratch); - set_current_project(app, scratch, project_parse.project, project_parse.parsed); - end_temp_memory(temp); + set_current_project(app, project_parse.project, project_parse.parsed); + end_temp(temp); } static void @@ -982,11 +849,11 @@ exec_project_command(Application_Links *app, Project_Command *command){ b32 set_fancy_font = false; if (command->out.size > 0){ - buffer_id = buffer_identifier(command->out.str, command->out.size); + buffer_id = buffer_identifier(command->out); if (footer_panel){ view = get_or_open_build_panel(app); - if (match(command->out, "*compilation*")){ + if (string_match(command->out, string_u8_litexpr("*compilation*"))){ set_fancy_font = true; } } @@ -998,17 +865,17 @@ exec_project_command(Application_Links *app, Project_Command *command){ } } - memset(&prev_location, 0, sizeof(prev_location)); - lock_jump_buffer(command->out.str, command->out.size); + block_zero_struct(&prev_location); + lock_jump_buffer(command->out); } else{ // TODO(allen): fix the exec_system_command call so it can take a null buffer_id. - buffer_id = buffer_identifier(literal("*dump*")); + buffer_id = buffer_identifier(string_u8_litexpr("*dump*")); } - String dir = current_project.dir; - String cmd = command->cmd; - exec_system_command(app, view, buffer_id, dir.str, dir.size, cmd.str, cmd.size, flags); + String_Const_u8 dir = current_project.dir; + String_Const_u8 cmd = command->cmd; + exec_system_command(app, view, buffer_id, dir, cmd, flags); if (set_fancy_font){ set_fancy_compilation_buffer_font(app); } @@ -1041,13 +908,13 @@ exec_project_fkey_command(Application_Links *app, i32 fkey_index){ } static void -exec_project_command_by_name(Application_Links *app, String name){ +exec_project_command_by_name(Application_Links *app, String_Const_u8 name){ if (!current_project.loaded){ return; } Project_Command *command = current_project.command_array.commands; for (i32 i = 0; i < current_project.command_array.count; ++i, ++command){ - if (match(command->name, name)){ + if (string_match(command->name, name)){ exec_project_command(app, command); break; } @@ -1056,7 +923,7 @@ exec_project_command_by_name(Application_Links *app, String name){ static void exec_project_command_by_name(Application_Links *app, char *name){ - exec_project_command_by_name(app, make_string_slowly(name)); + exec_project_command_by_name(app, SCu8(name)); } //////////////////////////////// @@ -1064,22 +931,19 @@ exec_project_command_by_name(Application_Links *app, char *name){ CUSTOM_COMMAND_SIG(close_all_code) CUSTOM_DOC("Closes any buffer with a filename ending with an extension configured to be recognized as a code file type.") { - CString_Array extensions = get_code_extensions(&global_config.code_exts); - close_all_files_with_extension(app, &global_part, extensions); + close_all_files_with_extension(app, global_config.code_exts); } CUSTOM_COMMAND_SIG(open_all_code) CUSTOM_DOC("Open all code in the current directory. File types are determined by extensions. An extension is considered code based on the extensions specified in 4coder.config.") { - CString_Array extensions = get_code_extensions(&global_config.code_exts); - open_all_files_in_hot_with_extension(app, &global_part, extensions, 0); + open_all_files_in_hot_with_extension(app, global_config.code_exts, 0); } CUSTOM_COMMAND_SIG(open_all_code_recursive) CUSTOM_DOC("Works as open_all_code but also runs in all subdirectories.") { - CString_Array extensions = get_code_extensions(&global_config.code_exts); - open_all_files_in_hot_with_extension(app, &global_part, extensions, OpenAllFilesFlag_Recursive); + open_all_files_in_hot_with_extension(app, global_config.code_exts, OpenAllFilesFlag_Recursive); } /////////////////////////////// @@ -1088,7 +952,7 @@ CUSTOM_COMMAND_SIG(load_project) CUSTOM_DOC("Looks for a project.4coder file in the current directory and tries to load it. Looks in parent directories until a project file is found or there are no more parents.") { save_all_dirty_buffers(app); - set_current_project_from_nearest_project_file(app, &global_part); + set_current_project_from_nearest_project_file(app); } CUSTOM_COMMAND_SIG(project_fkey_command) @@ -1118,54 +982,46 @@ CUSTOM_COMMAND_SIG(project_go_to_root_directory) CUSTOM_DOC("Changes 4coder's hot directory to the root directory of the currently loaded project. With no loaded project nothing hapepns.") { if (current_project.loaded){ - String dir = current_project.dir; - directory_set_hot(app, dir.str, dir.size); + set_hot_directory(app, current_project.dir); } } /////////////////////////////// static Project_Setup_Status -project_is_setup(Application_Links *app, Partition *scratch, String script_path, String script_file){ +project_is_setup(Application_Links *app, String_Const_u8 script_path, String_Const_u8 script_file){ Project_Setup_Status result = {}; - - Temp_Memory temp = begin_temp_memory(scratch); - - static i32 needed_extra_space = 15; - char *space = push_array(&global_part, char, script_path.size + needed_extra_space); - String str = make_string_cap(space, 0, script_path.size + needed_extra_space); - copy(&str, script_path); - - i32 dir_len = str.size; - append(&str, "/"); - append(&str, script_file); - append(&str, ".bat"); - result.bat_exists = file_exists(app, str.str, str.size); - - str.size = dir_len; - append(&str, "/"); - append(&str, script_file); - append(&str, ".sh"); - result.sh_exists = file_exists(app, str.str, str.size); - - str.size = dir_len; - append(&str, "/project.4coder"); - result.project_exists = file_exists(app, str.str, str.size); - - result.everything_exists = result.bat_exists && result.sh_exists && result.project_exists; - - end_temp_memory(temp); - + { + Scratch_Block scratch(app); + String_Const_u8 bat_path = string_u8_pushf(scratch, "%.*s/%.*s.bat", + string_expand(script_path), + string_expand(script_file)); + result.bat_exists = file_exists(app, bat_path); + } + { + Scratch_Block scratch(app); + String_Const_u8 sh_path = string_u8_pushf(scratch, "%.*s/%.*s.sh", + string_expand(script_path), + string_expand(script_file)); + result.sh_exists = file_exists(app, sh_path); + } + { + Scratch_Block scratch(app); + String_Const_u8 project_path = string_u8_pushf(scratch, "%.*s/project.4coder", + string_expand(script_path)); + result.sh_exists = file_exists(app, project_path); + } + result.everything_exists = (result.bat_exists && result.sh_exists && result.project_exists); return(result); } static Project_Key_Strings project_key_strings_query_user(Application_Links *app, b32 get_script_file, b32 get_code_file, - char *script_file_space, i32 script_file_cap, - char *code_file_space, i32 code_file_cap, - char *output_dir_space, i32 output_dir_cap, - char *binary_file_space, i32 binary_file_cap){ + u8 *script_file_space, i32 script_file_cap, + u8 *code_file_space, i32 code_file_cap, + u8 *output_dir_space, i32 output_dir_cap, + u8 *binary_file_space, i32 binary_file_cap){ Project_Key_Strings keys = {}; Query_Bar script_file_bar = {}; @@ -1174,37 +1030,36 @@ project_key_strings_query_user(Application_Links *app, Query_Bar binary_file_bar = {}; if (get_script_file){ - script_file_bar.prompt = make_lit_string("Script Name: "); - script_file_bar.string = make_string_cap(script_file_space, 0, script_file_cap); - + script_file_bar.prompt = string_u8_litexpr("Script Name: "); + script_file_bar.string = SCu8(script_file_space, (umem)0); + script_file_bar.string_capacity = script_file_cap; if (!query_user_string(app, &script_file_bar)) return(keys); if (script_file_bar.string.size == 0) return(keys); } if (get_code_file){ - code_file_bar.prompt = make_lit_string("Build Target: "); - code_file_bar.string = make_string_cap(code_file_space, 0, code_file_cap); - + code_file_bar.prompt = string_u8_litexpr("Build Target: "); + code_file_bar.string = SCu8(code_file_space, (umem)0); + code_file_bar.string_capacity = code_file_cap; if (!query_user_string(app, &code_file_bar)) return(keys); if (code_file_bar.string.size == 0) return(keys); } - output_dir_bar.prompt = make_lit_string("Output Directory: "); - output_dir_bar.string = make_string_cap(output_dir_space, 0, output_dir_cap); - + output_dir_bar.prompt = string_u8_litexpr("Output Directory: "); + output_dir_bar.string = SCu8(output_dir_space, (umem)0); + output_dir_bar.string_capacity = output_dir_cap; if (!query_user_string(app, &output_dir_bar)) return(keys); - if (output_dir_bar.string.size == 0){ - copy(&output_dir_bar.string, "."); + if (output_dir_bar.string.size == 0 && output_dir_cap > 0){ + output_dir_bar.string.str[0] = '.'; + output_dir_bar.string.size = 1; } - - binary_file_bar.prompt = make_lit_string("Binary Output: "); - binary_file_bar.string = make_string_cap(binary_file_space, 0, binary_file_cap); - + binary_file_bar.prompt = string_u8_litexpr("Binary Output: "); + binary_file_bar.string = SCu8(binary_file_space, (umem)0); + binary_file_bar.string_capacity = binary_file_cap; if (!query_user_string(app, &binary_file_bar)) return(keys); if (binary_file_bar.string.size == 0) return(keys); - keys.success = true; keys.script_file = script_file_bar.string; keys.code_file = code_file_bar.string; @@ -1215,121 +1070,93 @@ project_key_strings_query_user(Application_Links *app, } static b32 -project_generate_bat_script(Partition *scratch, String opts, String compiler, - String script_path, String script_file, - String code_file, String output_dir, String binary_file){ +project_generate_bat_script(Arena *scratch, String_Const_u8 opts, String_Const_u8 compiler, + String_Const_u8 script_path, String_Const_u8 script_file, + String_Const_u8 code_file, String_Const_u8 output_dir, String_Const_u8 binary_file){ b32 success = false; - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); - String cf = string_push_copy(scratch, code_file); - String od = string_push_copy(scratch, output_dir); - String bf = string_push_copy(scratch, binary_file); + String_Const_u8 cf = string_copy(scratch, code_file); + String_Const_u8 od = string_copy(scratch, output_dir); + String_Const_u8 bf = string_copy(scratch, binary_file); - replace_char(&cf, '/', '\\'); - replace_char(&od, '/', '\\'); - replace_char(&bf, '/', '\\'); + cf = string_mod_replace_character(cf, '/', '\\'); + od = string_mod_replace_character(od, '/', '\\'); + bf = string_mod_replace_character(bf, '/', '\\'); - i32 space_cap = part_remaining(scratch); - char *space = push_array(scratch, char, space_cap); - String file_name = make_string_cap(space, 0, space_cap); - append(&file_name, script_path); - append(&file_name, "/"); - append(&file_name, script_file); - append(&file_name, ".bat"); - terminate_with_null(&file_name); + String_Const_u8 file_name = string_u8_pushf(scratch, "%.*s/%.*s.bat", + string_expand(script_path), + string_expand(script_file)); - FILE *bat_script = fopen(file_name.str, "wb"); + FILE *bat_script = fopen((char*)file_name.str, "wb"); if (bat_script != 0){ fprintf(bat_script, "@echo off\n\n"); - fprintf(bat_script, "set opts=%.*s\n", opts.size, opts.str); + fprintf(bat_script, "set opts=%.*s\n", (i32)opts.size, opts.str); fprintf(bat_script, "set code=%%cd%%\n"); - - fprintf(bat_script, "pushd %.*s\n", od.size, od.str); + fprintf(bat_script, "pushd %.*s\n", (i32)od.size, od.str); fprintf(bat_script, "%.*s %%opts%% %%code%%\\%.*s -Fe%.*s\n", - compiler.size, compiler.str, cf.size, cf.str, bf.size, bf.str); + (i32)compiler.size, compiler.str, (i32)cf.size, cf.str, (i32)bf.size, bf.str); fprintf(bat_script, "popd\n"); - fclose(bat_script); success = true; } - end_temp_memory(temp); + end_temp(temp); return(success); } static b32 -project_generate_sh_script(Partition *scratch, String opts, String compiler, - String script_path, String script_file, - String code_file, String output_dir, String binary_file){ +project_generate_sh_script(Arena *scratch, String_Const_u8 opts, String_Const_u8 compiler, + String_Const_u8 script_path, String_Const_u8 script_file, + String_Const_u8 code_file, String_Const_u8 output_dir, String_Const_u8 binary_file){ b32 success = false; - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); - String cf = code_file; - String od = output_dir; - String bf = binary_file; + String_Const_u8 cf = code_file; + String_Const_u8 od = output_dir; + String_Const_u8 bf = binary_file; - i32 space_cap = part_remaining(scratch); - char *space = push_array(scratch, char, space_cap); - String file_name = make_string_cap(space, 0, space_cap); - append(&file_name, script_path); - append(&file_name, "/"); - append(&file_name, script_file); - append(&file_name, ".sh"); - terminate_with_null(&file_name); + String_Const_u8 file_name = string_u8_pushf(scratch, "%.*s/%.*s.sh", + string_expand(script_path), + string_expand(script_file)); - FILE *sh_script = fopen(file_name.str, "wb"); + FILE *sh_script = fopen((char*)file_name.str, "wb"); if (sh_script != 0){ fprintf(sh_script, "#!/bin/bash\n\n"); - fprintf(sh_script, "code=\"$PWD\"\n"); - - fprintf(sh_script, "opts=%.*s\n", opts.size, opts.str); - - fprintf(sh_script, "cd %.*s > /dev/null\n", od.size, od.str); - fprintf(sh_script, "%.*s $opts $code/%.*s -o %.*s\n", - compiler.size, compiler.str, cf.size, cf.str, bf.size, bf.str); + fprintf(sh_script, "opts=%.*s\n", string_expand(opts)); + fprintf(sh_script, "cd %.*s > /dev/null\n", string_expand(od)); + fprintf(sh_script, "%.*s $opts $code/%.*s -o %.*s\n", string_expand(compiler), string_expand(cf), string_expand(bf)); fprintf(sh_script, "cd $code > /dev/null\n"); - fclose(sh_script); success = true; } - end_temp_memory(temp); + end_temp(temp); return(success); } static b32 -project_generate_project_4coder_file(Partition *scratch, - String script_path, String script_file, - String output_dir, String binary_file){ +project_generate_project_4coder_file(Arena *scratch, String_Const_u8 script_path, String_Const_u8 script_file, String_Const_u8 output_dir, String_Const_u8 binary_file){ b32 success = false; - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); - String od = output_dir; - String bf = binary_file; + String_Const_u8 od = output_dir; + String_Const_u8 bf = binary_file; - String od_win = string_push(scratch, od.size*2); - String bf_win = string_push(scratch, bf.size*2); + String_Const_u8 od_win = string_replace(scratch, od, + string_u8_litexpr("/"), string_u8_litexpr("\\")); + String_Const_u8 bf_win = string_replace(scratch, bf, + string_u8_litexpr("/"), string_u8_litexpr("\\")); - append(&od_win, od); - append(&bf_win, bf); + String_Const_u8 file_name = string_u8_pushf(scratch, "%.*s/project.4coder", string_expand(script_path)); - replace_str(&od_win, "/", "\\\\"); - replace_str(&bf_win, "/", "\\\\"); - - i32 space_cap = part_remaining(scratch); - char *space = push_array(scratch, char, space_cap); - String file_name = make_string_cap(space, 0, space_cap); - append(&file_name, script_path); - append(&file_name, "/project.4coder"); - terminate_with_null(&file_name); - - FILE *out = fopen(file_name.str, "wb"); + FILE *out = fopen((char*)file_name.str, "wb"); if (out != 0){ fprintf(out, "version(1);\n"); fprintf(out, "project_name = \"%.*s\";\n", binary_file.size, binary_file.str); @@ -1382,23 +1209,21 @@ project_generate_project_4coder_file(Partition *scratch, success = true; } - end_temp_memory(temp); + end_temp(temp); return(success); } static void -project_setup_scripts__generic(Application_Links *app, Partition *scratch, - b32 do_project_file, - b32 do_bat_script, - b32 do_sh_script){ - Temp_Memory temp = begin_temp_memory(scratch); - String script_path = get_hot_directory(app, scratch); +project_setup_scripts__generic(Application_Links *app, b32 do_project_file, b32 do_bat_script, b32 do_sh_script){ + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 script_path = push_hot_directory(app, scratch); b32 needs_to_do_work = false; Project_Setup_Status status = {}; if (do_project_file){ - status = project_is_setup(app, scratch, script_path, make_lit_string("build")); + status = project_is_setup(app, script_path, string_u8_litexpr("build")); needs_to_do_work = !status.project_exists || (do_bat_script && !status.bat_exists) || @@ -1410,34 +1235,33 @@ project_setup_scripts__generic(Application_Links *app, Partition *scratch, if (needs_to_do_work){ // Query the User for Key File Names - char script_file_space[1024]; - char code_file_space [1024]; - char output_dir_space [1024]; - char binary_file_space[1024]; + u8 script_file_space[1024]; + u8 code_file_space [1024]; + u8 output_dir_space [1024]; + u8 binary_file_space[1024]; b32 get_script_file = !do_project_file; b32 get_code_file = (do_bat_script && !status.bat_exists) || (do_sh_script && !status.sh_exists); - Project_Key_Strings keys = - project_key_strings_query_user(app, - get_script_file, get_code_file, - script_file_space, sizeof(script_file_space), - code_file_space, sizeof(code_file_space), - output_dir_space, sizeof(output_dir_space), - binary_file_space, sizeof(binary_file_space)); + Project_Key_Strings keys = {}; + keys = project_key_strings_query_user(app, get_script_file, get_code_file, + script_file_space, sizeof(script_file_space), + code_file_space, sizeof(code_file_space), + output_dir_space, sizeof(output_dir_space), + binary_file_space, sizeof(binary_file_space)); if (!keys.success){ return; } if (do_project_file){ - keys.script_file = make_lit_string("build"); + keys.script_file = string_u8_litexpr("build"); } if (!do_project_file){ - status = project_is_setup(app, scratch, script_path, keys.script_file); + status = project_is_setup(app, script_path, keys.script_file); } // Generate Scripts @@ -1448,11 +1272,11 @@ project_setup_scripts__generic(Application_Links *app, Partition *scratch, global_config.default_compiler_bat, script_path, keys.script_file, keys.code_file, keys.output_dir, keys.binary_file)){ - print_message(app, literal("could not create build.bat for new project\n")); + print_message(app, string_u8_litexpr("could not create build.bat for new project\n")); } } else{ - print_message(app, literal("the batch script already exists, no changes made to it\n")); + print_message(app, string_u8_litexpr("the batch script already exists, no changes made to it\n")); } } @@ -1463,91 +1287,94 @@ project_setup_scripts__generic(Application_Links *app, Partition *scratch, global_config.default_compiler_sh, script_path, keys.script_file, keys.code_file, keys.output_dir, keys.binary_file)){ - print_message(app, literal("could not create build.sh for new project\n")); + print_message(app, string_u8_litexpr("could not create build.sh for new project\n")); } } else{ - print_message(app, literal("the shell script already exists, no changes made to it\n")); + print_message(app, string_u8_litexpr("the shell script already exists, no changes made to it\n")); } } if (do_project_file){ if (!status.project_exists){ - if (!project_generate_project_4coder_file(scratch, script_path, keys.script_file, - keys.output_dir, keys.binary_file)){ - print_message(app, literal("could not create project.4coder for new project\n")); + if (!project_generate_project_4coder_file(scratch, + script_path, + keys.script_file, + keys.output_dir, + keys.binary_file)){ + print_message(app, string_u8_litexpr("could not create project.4coder for new project\n")); } } else{ - print_message(app, literal("project.4coder already exists, no changes made to it\n")); + print_message(app, string_u8_litexpr("project.4coder already exists, no changes made to it\n")); } } } else{ if (do_project_file){ - print_message(app, literal("project already setup, no changes made\n")); + print_message(app, string_u8_litexpr("project already setup, no changes made\n")); } } - end_temp_memory(temp); + end_temp(temp); } CUSTOM_COMMAND_SIG(setup_new_project) CUSTOM_DOC("Queries the user for several configuration options and initializes a new 4coder project with build scripts for every OS.") { - project_setup_scripts__generic(app, &global_part, true, true, true); + project_setup_scripts__generic(app, true, true, true); load_project(app); } CUSTOM_COMMAND_SIG(setup_build_bat) CUSTOM_DOC("Queries the user for several configuration options and initializes a new build batch script.") { - project_setup_scripts__generic(app, &global_part, false, true, false); + project_setup_scripts__generic(app, false, true, false); } CUSTOM_COMMAND_SIG(setup_build_sh) CUSTOM_DOC("Queries the user for several configuration options and initializes a new build shell script.") { - project_setup_scripts__generic(app, &global_part, false, false, true); + project_setup_scripts__generic(app, false, false, true); } CUSTOM_COMMAND_SIG(setup_build_bat_and_sh) CUSTOM_DOC("Queries the user for several configuration options and initializes a new build batch script.") { - project_setup_scripts__generic(app, &global_part, false, true, true); + project_setup_scripts__generic(app, false, true, true); } /////////////////////////////// static void -activate_project_command(Application_Links *app, Partition *scratch, Heap *heap, View_ID view, Lister_State *state, String text_field, void *user_data, b32 activated_by_mouse){ +activate_project_command(Application_Links *app, Heap *heap, View_ID view, Lister_State *state, String_Const_u8 text_field, void *user_data, b32 activated_by_mouse){ i32 command_index = (i32)PtrAsInt(user_data); exec_project_command_by_index(app, command_index); - lister_default(app, scratch, heap, view, state, ListerActivation_Finished); + lister_default(app, heap, view, state, ListerActivation_Finished); } CUSTOM_COMMAND_SIG(project_command_lister) CUSTOM_DOC("Open a lister of all commands in the currently loaded project.") { - if (!current_project.loaded){ - return; + if (current_project.loaded){ + Arena *scratch = context_get_arena(app); + + View_ID view = 0; + get_active_view(app, AccessAll, &view); + view_end_ui_mode(app, view); + Temp_Memory temp = begin_temp(scratch); + i32 option_count = current_project.command_array.count; + Lister_Option *options = push_array(scratch, Lister_Option, option_count); + for (i32 i = 0; + i < current_project.command_array.count; + i += 1){ + options[i].string = string_copy(scratch, current_project.command_array.commands[i].name); + options[i].status = string_copy(scratch, current_project.command_array.commands[i].cmd); + options[i].user_data = IntAsPtr(i); + } + begin_integrated_lister__basic_list(app, "Command:", activate_project_command, 0, 0, options, option_count, 0, view); + end_temp(temp); } - - Partition *arena = &global_part; - - View_ID view = 0; - get_active_view(app, AccessAll, &view); - view_end_ui_mode(app, view); - Temp_Memory temp = begin_temp_memory(arena); - i32 option_count = current_project.command_array.count; - Lister_Option *options = push_array(arena, Lister_Option, option_count); - for (i32 i = 0; i < current_project.command_array.count; i += 1){ - options[i].string = string_push_copy(arena, current_project.command_array.commands[i].name); - options[i].status = string_push_copy(arena, current_project.command_array.commands[i].cmd); - options[i].user_data = IntAsPtr(i); - } - begin_integrated_lister__basic_list(app, "Command:", activate_project_command, 0, 0, options, option_count, 0, view); - end_temp_memory(temp); } // BOTTOM diff --git a/4coder_project_commands.h b/4coder_project_commands.h index 192fd722..afd284fe 100644 --- a/4coder_project_commands.h +++ b/4coder_project_commands.h @@ -14,7 +14,7 @@ enum{ /////////////////////////////// struct Project_File_Pattern{ - Absolutes absolutes; + List_String_Const_u8 absolutes; }; struct Project_File_Pattern_Array{ @@ -23,7 +23,7 @@ struct Project_File_Pattern_Array{ }; struct Project_File_Load_Path{ - String path; + String_Const_u8 path; b32 recursive; b32 relative; }; @@ -34,9 +34,9 @@ struct Project_File_Load_Path_Array{ }; struct Project_Command{ - String name; - String cmd; - String out; + String_Const_u8 name; + String_Const_u8 cmd; + String_Const_u8 out; b32 footer_panel; b32 save_dirty_files; b32 cursor_at_end; @@ -50,8 +50,8 @@ struct Project_Command_Array{ struct Project{ b32 loaded; - String dir; - String name; + String_Const_u8 dir; + String_Const_u8 name; Project_File_Pattern_Array pattern_array; Project_File_Pattern_Array blacklist_pattern_array; @@ -84,10 +84,10 @@ struct Project_Setup_Status{ struct Project_Key_Strings{ b32 success; - String script_file; - String code_file; - String output_dir; - String binary_file; + String_Const_u8 script_file; + String_Const_u8 code_file; + String_Const_u8 output_dir; + String_Const_u8 binary_file; }; #endif diff --git a/4coder_remapping_commands.cpp b/4coder_remapping_commands.cpp index e5b6970d..837e3c0e 100644 --- a/4coder_remapping_commands.cpp +++ b/4coder_remapping_commands.cpp @@ -30,60 +30,50 @@ mac_default_keys(Bind_Helper *context){ // static Bind_Helper -get_context_on_global_part(void){ +get_context_on_arena(Arena *arena){ Bind_Helper result = {}; - i32 size = (1 << 20); - for (;;){ - void *data = push_array(&global_part, char, size); - if (data != 0){ - result = begin_bind_helper(data, size); - break; - } - size = (size >> 1); - } + result = begin_bind_helper(push_array(arena, char, MB(1)), MB(1)); return(result); } CUSTOM_COMMAND_SIG(set_bindings_choose) CUSTOM_DOC("Remap keybindings using the 'choose' mapping rule.") { -#if defined(IS_WINDOWS) || defined(IS_LINUX) - +#if OS_WINDOWS || OS_LINUX set_bindings_default(app); - -#elif defined(IS_MAC) - +#elif OS_MAC set_bindings_mac_default(app); - #endif } CUSTOM_COMMAND_SIG(set_bindings_default) CUSTOM_DOC("Remap keybindings using the 'default' mapping rule.") { - Temp_Memory temp = begin_temp_memory(&global_part); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); - Bind_Helper context = get_context_on_global_part(); + Bind_Helper context = get_context_on_arena(scratch); set_all_default_hooks(&context); default_keys(&context); Bind_Buffer result = end_bind_helper_get_buffer(&context); global_set_mapping(app, result.data, result.size); - end_temp_memory(temp); + end_temp(temp); } CUSTOM_COMMAND_SIG(set_bindings_mac_default) CUSTOM_DOC("Remap keybindings using the 'mac-default' mapping rule.") { - Temp_Memory temp = begin_temp_memory(&global_part); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); - Bind_Helper context = get_context_on_global_part(); + Bind_Helper context = get_context_on_arena(scratch); set_all_default_hooks(&context); mac_default_keys(&context); Bind_Buffer result = end_bind_helper_get_buffer(&context); global_set_mapping(app, result.data, result.size); - end_temp_memory(temp); + end_temp(temp); } #endif diff --git a/4coder_scope_commands.cpp b/4coder_scope_commands.cpp index 354024fc..94526031 100644 --- a/4coder_scope_commands.cpp +++ b/4coder_scope_commands.cpp @@ -399,7 +399,7 @@ CUSTOM_DOC("Finds the first scope started by '{' before the cursor and puts the } static void -place_begin_and_end_on_own_lines(Application_Links *app, Partition *scratch, char *begin, char *end){ +place_begin_and_end_on_own_lines(Application_Links *app, char *begin, char *end){ View_ID view = 0; get_active_view(app, AccessOpen, &view); Buffer_ID buffer = 0; @@ -412,82 +412,73 @@ place_begin_and_end_on_own_lines(Application_Links *app, Partition *scratch, cha range.min = buffer_get_line_start(app, buffer, lines.min); range.max = buffer_get_line_end(app, buffer, lines.max); - b32 do_full = (lines.min < lines.max) || (!buffer_line_is_blank(app, buffer, lines.min)); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); - Temp_Memory temp = begin_temp_memory(scratch); - i32 begin_len = str_size(begin); - i32 end_len = str_size(end); + b32 min_line_blank = buffer_line_is_blank(app, buffer, lines.min); + b32 max_line_blank = buffer_line_is_blank(app, buffer, lines.max); - i32 str_size = begin_len + end_len + 2; - char *str = push_array(scratch, char, str_size); - String builder = make_string_cap(str, 0, str_size); - append(&builder, begin); - append(&builder, "\n"); - append(&builder, "\n"); - append(&builder, end); - - if (do_full){ - Buffer_Edit edits[2]; + if ((lines.min < lines.max) || (!min_line_blank)){ + String_Const_u8 begin_str = {}; + String_Const_u8 end_str = {}; - i32 min_adjustment = 0; - i32 max_adjustment = 4; + umem min_adjustment = 0; + umem max_adjustment = 0; - if (buffer_line_is_blank(app, buffer, lines.min)){ - memmove(str + 1, str, begin_len); - str[0] = '\n'; - ++min_adjustment; + if (min_line_blank){ + begin_str = string_u8_pushf(scratch, "\n%s", begin); + min_adjustment += 1; + } + else{ + begin_str = string_u8_pushf(scratch, "%s\n", begin); + } + if (max_line_blank){ + end_str = string_u8_pushf(scratch, "%s\n", end); + } + else{ + end_str = string_u8_pushf(scratch, "\n%s", end); + max_adjustment += 1; } - if (buffer_line_is_blank(app, buffer, lines.max)){ - memmove(str + begin_len + 1, str + begin_len + 2, end_len); - str[begin_len + end_len + 1] = '\n'; - --max_adjustment; + max_adjustment += begin_str.size; + Range new_pos = make_range(range.min + (i32)min_adjustment, range.max + (i32)max_adjustment); + + i32 cursor_pos = 0; + i32 mark_pos = 0; + view_get_cursor_pos(app, view, &cursor_pos); + + if (cursor_pos == range.min){ + cursor_pos = new_pos.min; + mark_pos = new_pos.max; + } + else{ + cursor_pos = new_pos.max; + mark_pos = new_pos.min; } - i32 min_pos = range.min + min_adjustment; - i32 max_pos = range.max + max_adjustment; - - i32 cursor_pos = min_pos; - i32 mark_pos = max_pos; - - i32 view_cursor_pos = 0; - view_get_cursor_pos(app, view, &view_cursor_pos); - i32 view_mark_pos = 0; - view_get_mark_pos(app, view, &view_mark_pos); - if (view_cursor_pos > view_mark_pos){ - cursor_pos = max_pos; - mark_pos = min_pos; - } - - edits[0].str_start = 0; - edits[0].len = begin_len + 1; - edits[0].start = range.min; - edits[0].end = range.min; - - edits[1].str_start = begin_len + 1; - edits[1].len = end_len + 1; - edits[1].start = range.max; - edits[1].end = range.max; - - buffer_batch_edit(app, buffer, str, edits, 2); + History_Group group = begin_history_group(app, buffer); + buffer_replace_range(app, buffer, make_range(range.min), begin_str); + buffer_replace_range(app, buffer, make_range(range.max + (i32)begin_str.size), end_str); + end_history_group(group); view_set_cursor(app, view, seek_pos(cursor_pos), true); view_set_mark(app, view, seek_pos(mark_pos)); } else{ - buffer_replace_range(app, buffer, range, make_string(str, str_size)); - i32 center_pos = range.min + begin_len + 1; + String_Const_u8 str = string_u8_pushf(scratch, "%s\n\n%s", begin, end); + buffer_replace_range(app, buffer, range, str); + i32 center_pos = range.min + (i32)cstring_length(begin) + 1; view_set_cursor(app, view, seek_pos(center_pos), true); view_set_mark(app, view, seek_pos(center_pos)); } - end_temp_memory(temp); + end_temp(temp); } CUSTOM_COMMAND_SIG(place_in_scope) CUSTOM_DOC("Wraps the code contained in the range between cursor and mark with a new curly brace scope.") { - place_begin_and_end_on_own_lines(app, &global_part, "{", "}"); + place_begin_and_end_on_own_lines(app, "{", "}"); } CUSTOM_COMMAND_SIG(delete_current_scope) @@ -548,7 +539,7 @@ parse_for_down(Application_Links *app, Statement_Parser *parser, Cpp_Token *toke Cpp_Token *token = parser_next_token(parser); i32 paren_level = 0; - while (token != 0){ + for (;token != 0;){ if (!(token->flags & CPP_TFLAG_PP_BODY)){ switch (token->type){ case CPP_TOKEN_PARENTHESE_OPEN: @@ -570,7 +561,6 @@ parse_for_down(Application_Links *app, Statement_Parser *parser, Cpp_Token *toke }break; } } - token = parser_next_token(parser); } @@ -582,21 +572,15 @@ static b32 parse_if_down(Application_Links *app, Statement_Parser *parser, Cpp_Token *token_out){ b32 success = false; Cpp_Token *token = parser_next_token(parser); - if (token != 0){ success = parse_statement_down(app, parser, token_out); if (success){ token = parser_next_token(parser); - if (token != 0 && cpp_token_category_from_type(token->type) == CPP_TOKEN_CAT_CONTROL_FLOW){ - char lexeme[32]; - token_get_lexeme(app, parser->buffer, token, lexeme, sizeof(lexeme)); - if (match(lexeme, "else")){ - success = parse_statement_down(app, parser, token_out); - } + if (token != 0 && token->type == CPP_TOKEN_ELSE){ + success = parse_statement_down(app, parser, token_out); } } } - return(success); } @@ -753,20 +737,15 @@ CUSTOM_DOC("If a scope is currently selected, and a statement or block statement bottom = x; } - Partition *part = &global_part; - - Temp_Memory temp = begin_temp_memory(part); if (buffer_get_char(app, buffer, top) == '{' && buffer_get_char(app, buffer, bottom - 1) == '}'){ + Scratch_Block scratch(app); Range range = {}; if (find_whole_statement_down(app, buffer, bottom, &range.start, &range.end)){ - char *string_space = push_array(part, char, range.end - range.start); - buffer_read_range(app, buffer, range.start, range.end, string_space); - - String string = make_string(string_space, range.end - range.start); - string = skip_chop_whitespace(string); + String_Const_u8 base_string = scratch_read(app, scratch, buffer, range); + String_Const_u8 string = string_skip_chop_whitespace(base_string); i32 newline_count = 0; - for (char *ptr = string_space; ptr < string.str; ++ptr){ + for (u8 *ptr = base_string.str; ptr < string.str; ++ptr){ if (*ptr == '\n'){ ++newline_count; } @@ -777,37 +756,26 @@ CUSTOM_DOC("If a scope is currently selected, and a statement or block statement extra_newline = true; } - i32 edit_len = string.size + 1; + String_Const_u8 edit_str = {}; if (extra_newline){ - edit_len += 1; - } - - char *edit_str = push_array(part, char, edit_len); - if (extra_newline){ - edit_str[0] = '\n'; - copy_fast_unsafe(edit_str+1, string); - edit_str[edit_len-1] = '\n'; + edit_str = string_u8_pushf(scratch, "\n%.*s\n", string_expand(string)); } else{ - copy_fast_unsafe(edit_str, string); - edit_str[edit_len-1] = '\n'; + edit_str = string_u8_pushf(scratch, "%.*s\n", string_expand(string)); } Buffer_Edit edits[2]; edits[0].str_start = 0; - edits[0].len = edit_len; - edits[0].start = bottom-1; - edits[0].end = bottom-1; - + edits[0].len = (i32)edit_str.size; + edits[0].start = bottom - 1; + edits[0].end = bottom - 1; edits[1].str_start = 0; edits[1].len = 0; edits[1].start = range.start; edits[1].end = range.end; - - buffer_batch_edit(app, buffer, edit_str, edits, 2); + buffer_batch_edit(app, buffer, (char*)edit_str.str, edits, 2); } } - end_temp_memory(temp); no_mark_snap_to_cursor(app, view); } diff --git a/4coder_search.cpp b/4coder_search.cpp index 0fe2ec3a..3f98aff9 100644 --- a/4coder_search.cpp +++ b/4coder_search.cpp @@ -10,14 +10,12 @@ and list all locations. // static void -search_key_alloc(Heap *heap, Search_Key *key, int32_t *size, int32_t count){ - if (count > ArrayCount(key->words)){ - count = ArrayCount(key->words); - } +search_key_alloc(Heap *heap, Search_Key *key, umem *size, i32 count){ + count = clamp_top(count, ArrayCount(key->words)); - int32_t min_size = 0x7FFFFFFF; - int32_t total_size = 0; - for (int32_t i = 0; i < count; ++i){ + umem min_size = 0x7FFFFFFF; + umem total_size = 0; + for (i32 i = 0; i < count; ++i){ total_size += size[i]; if (min_size > size[i]){ min_size = size[i]; @@ -25,22 +23,26 @@ search_key_alloc(Heap *heap, Search_Key *key, int32_t *size, int32_t count){ } if (key->base == 0){ - int32_t max_base_size = total_size*2; - key->base = heap_array(heap, char, max_base_size); + umem max_base_size = total_size*2; + key->base = heap_array(heap, u8, (i32)max_base_size); key->base_size = max_base_size; } else if (key->base_size < total_size){ - int32_t max_base_size = total_size*2; + umem max_base_size = total_size*2; heap_free(heap, key->base); - key->base = heap_array(heap, char, max_base_size); + key->base = heap_array(heap, u8, (i32)max_base_size); key->base_size = max_base_size; } - char *char_ptr = key->base; - for (int32_t i = 0; i < count; ++i){ + u8 *char_ptr = key->base; + for (i32 i = 0; i < count; ++i){ + key->words[i].str = char_ptr; + key->words[i].size = 0; +#if 0 key->words[i].str = char_ptr; key->words[i].size = 0; key->words[i].memory_size = size[i]; +#endif char_ptr += size[i]; } @@ -56,14 +58,14 @@ search_iter_init(Search_Iter *iter, Search_Key key){ } static void -search_set_init(Heap *heap, Search_Set *set, int32_t range_count){ +search_set_init(Heap *heap, Search_Set *set, i32 range_count){ if (set->ranges == 0){ - int32_t max = range_count*2; + i32 max = range_count*2; set->ranges = heap_array(heap, Search_Range, max); set->max = max; } else if (set->max < range_count){ - int32_t max = range_count*2; + i32 max = range_count*2; heap_free(heap, set->ranges); set->ranges = heap_array(heap, Search_Range, max); set->max = max; @@ -72,9 +74,9 @@ search_set_init(Heap *heap, Search_Set *set, int32_t range_count){ } static void -search_hits_table_alloc(Heap *heap, Table *hits, int32_t table_size){ +search_hits_table_alloc(Heap *heap, Table *hits, i32 table_size){ void *mem = 0; - int32_t mem_size = table_required_mem_size(table_size, sizeof(Offset_String)); + i32 mem_size = table_required_mem_size(table_size, sizeof(Offset_String)); if (hits->hash_array == 0){ mem = heap_allocate(heap, mem_size); } @@ -86,12 +88,12 @@ search_hits_table_alloc(Heap *heap, Table *hits, int32_t table_size){ } static void -search_hits_init(Heap *heap, Table *hits, String_Space *str, int32_t table_size, int32_t str_size){ +search_hits_init(Heap *heap, Table *hits, String_Space *str, i32 table_size, i32 str_size){ if (hits->hash_array == 0){ search_hits_table_alloc(heap, hits, table_size); } else{ - int32_t mem_size = table_required_mem_size(table_size, sizeof(Offset_String)); + i32 mem_size = table_required_mem_size(table_size, sizeof(Offset_String)); heap_free(heap, hits->hash_array); void *mem = heap_allocate(heap, mem_size); table_init_memory(hits, mem, table_size, sizeof(Offset_String)); @@ -115,15 +117,13 @@ search_hits_init(Heap *heap, Table *hits, String_Space *str, int32_t table_size, // Table Operations // -static int32_t -search_hit_add(Heap *heap, Table *hits, String_Space *space, char *str, int32_t len){ - int32_t result = false; - +static b32 +search_hit_add(Heap *heap, Table *hits, String_Space *space, char *str, i32 len){ + b32 result = false; Assert(len != 0); - Offset_String ostring = strspace_append(space, str, len); if (ostring.size == 0){ - int32_t new_size = space->max*2; + i32 new_size = space->max*2; if (new_size < space->max + len){ new_size = space->max + len; } @@ -156,12 +156,17 @@ search_hit_add(Heap *heap, Table *hits, String_Space *space, char *str, int32_t return(result); } +static b32 +search_hit_add(Heap *heap, Table *hits, String_Space *space, String_Const_u8 string){ + return(search_hit_add(heap, hits, space, (char*)string.str, (i32)string.size)); +} + // // Search Key Checking // static void -seek_potential_match(Application_Links *app, Search_Range *range, Search_Key key, Search_Match *result, Seek_Potential_Match_Direction direction, int32_t start_pos, int32_t end_pos){ +seek_potential_match(Application_Links *app, Search_Range *range, Search_Key key, Search_Match *result, Seek_Potential_Match_Direction direction, i32 start_pos, i32 end_pos){ b32 case_insensitive = ((range->flags & SearchFlag_CaseInsensitive) != 0); b32 forward = (direction == SeekPotentialMatch_Forward); #define OptFlag(b,f) ((b)?(f):(0)) @@ -170,15 +175,15 @@ seek_potential_match(Application_Links *app, Search_Range *range, Search_Key key | OptFlag(!forward, BufferSeekString_Backward); result->buffer = range->buffer; - int32_t best_pos = -1; + i32 best_pos = -1; if (forward){ best_pos = end_pos; } - for (int32_t i = 0; i < key.count; ++i){ - String word = key.words[i]; - int32_t new_pos = -1; - buffer_seek_string(app, result->buffer, start_pos, end_pos, range->start, word.str, word.size, &new_pos, flags); + for (i32 i = 0; i < key.count; ++i){ + String_Const_u8 word = key.words[i]; + i32 new_pos = -1; + buffer_seek_string(app, result->buffer, start_pos, end_pos, range->start, word, &new_pos, flags); if (new_pos >= 0){ if (forward){ @@ -198,15 +203,15 @@ seek_potential_match(Application_Links *app, Search_Range *range, Search_Key key } static i32 -buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_ID buffer_id, int32_t pos){ +buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_ID buffer_id, i32 pos){ char space[1024]; Stream_Chunk chunk = {}; if (init_stream_chunk(&chunk, app, buffer_id, pos, space, sizeof(space))){ - int32_t still_looping = true; + i32 still_looping = true; do{ for (; pos < chunk.end; ++pos){ u8 at_pos = (u8)chunk.data[pos]; - if (!char_is_alpha_numeric_utf8(at_pos)) goto double_break; + if (!character_is_alpha_numeric_unicode(at_pos)) goto double_break; } still_looping = forward_stream_chunk(&chunk); }while(still_looping); @@ -215,37 +220,37 @@ buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_ID buffer_id, int32 return(pos); } -static int32_t -match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Match *result_ptr, Search_Key key){ - int32_t result_code = FindResult_None; +static i32 +match_check(Application_Links *app, Search_Range *range, i32 *pos, Search_Match *result_ptr, Search_Key key){ + i32 result_code = FindResult_None; Search_Match result = *result_ptr; - int32_t end_pos = range->start + range->size; + i32 end_pos = range->start + range->size; - int32_t type = (range->flags & SearchFlag_MatchMask); + i32 type = (range->flags & SearchFlag_MatchMask); result.match_word_index = -1; - for (int32_t i = 0; i < key.count; ++i){ - String word = key.words[i]; + for (i32 i = 0; i < key.count; ++i){ + String_Const_u8 word = key.words[i]; - int32_t found_match = FindResult_None; + i32 found_match = FindResult_None; switch (type){ case SearchFlag_MatchWholeWord: { - char prev = ' '; - if (char_is_alpha_numeric_utf8(word.str[0])){ + u8 prev = ' '; + if (character_is_alpha_numeric(string_get_character(word, 0))){ prev = buffer_get_char(app, result.buffer, result.start - 1); } - if (!char_is_alpha_numeric_utf8(prev)){ - result.end = result.start + word.size; + if (!character_is_alpha_numeric(prev)){ + result.end = result.start + (i32)word.size; if (result.end <= end_pos){ - char next = ' '; - if (char_is_alpha_numeric_utf8(word.str[word.size-1])){ + u8 next = ' '; + if (character_is_alpha_numeric_unicode(string_get_character(word, word.size - 1))){ next = buffer_get_char(app, result.buffer, result.end); } - if (!char_is_alpha_numeric_utf8(next)){ + if (!character_is_alpha_numeric_unicode(next)){ result.found_match = true; found_match = FindResult_FoundMatch; } @@ -258,8 +263,8 @@ match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Ma case SearchFlag_MatchWordPrefix: { - char prev = buffer_get_char(app, result.buffer, result.start - 1); - if (!char_is_alpha_numeric_utf8(prev)){ + u8 prev = buffer_get_char(app, result.buffer, result.start - 1); + if (!character_is_alpha_numeric_unicode(prev)){ result.end = buffer_seek_alpha_numeric_end(app, result.buffer, result.start); if (result.end <= end_pos){ result.found_match = true; @@ -273,7 +278,7 @@ match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Ma case SearchFlag_MatchSubstring: { - result.end = result.start + word.size; + result.end = result.start + (i32)word.size; if (result.end <= end_pos){ result.found_match = true; found_match = FindResult_FoundMatch; @@ -303,15 +308,15 @@ match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Ma // Find Next Match // -static int32_t -search_front_to_back(Application_Links *app, Search_Range *range, Search_Key key, int32_t *pos, Search_Match *result){ - int32_t found_match = FindResult_None; +static i32 +search_front_to_back(Application_Links *app, Search_Range *range, Search_Key key, i32 *pos, Search_Match *result){ + i32 found_match = FindResult_None; for (;found_match == FindResult_None;){ found_match = FindResult_None; - int32_t end_pos = range->start + range->size; + i32 end_pos = range->start + range->size; if (*pos + key.min_size < end_pos){ - int32_t start_pos = *pos; + i32 start_pos = *pos; if (start_pos < range->start){ start_pos = range->start; } @@ -338,13 +343,13 @@ search_front_to_back(Application_Links *app, Search_Range *range, Search_Key key return(found_match); } -static int32_t -search_back_to_front(Application_Links *app, Search_Range *range, Search_Key key, int32_t *pos, Search_Match *result){ - int32_t found_match = FindResult_None; +static i32 +search_back_to_front(Application_Links *app, Search_Range *range, Search_Key key, i32 *pos, Search_Match *result){ + i32 found_match = FindResult_None; for (;found_match == FindResult_None;){ found_match = FindResult_None; if (*pos > range->start){ - int32_t start_pos = *pos; + i32 start_pos = *pos; seek_potential_match(app, range, key, result, SeekPotentialMatch_Backward, start_pos, 0); @@ -352,7 +357,7 @@ search_back_to_front(Application_Links *app, Search_Range *range, Search_Key key *pos = result->start - 1; found_match = match_check(app, range, pos, result, key); if (found_match == FindResult_FoundMatch){ - *pos = result->start - key.words[result->match_word_index].size; + *pos = result->start - (i32)key.words[result->match_word_index].size; } } else{ @@ -379,11 +384,11 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){ Search_Match result = {}; Search_Iter iter = *it_ptr; - int32_t count = set->count; + i32 count = set->count; for (;iter.i < count;){ Search_Range *range = set->ranges + iter.i; - int32_t find_result = FindResult_None; + i32 find_result = FindResult_None; if (!iter.range_initialized){ iter.range_initialized = true; @@ -417,8 +422,8 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){ Search_Match forward_match = {}; Search_Match backward_match = {}; - int32_t forward_result = FindResult_PastEnd; - int32_t backward_result = FindResult_PastEnd; + i32 forward_result = FindResult_PastEnd; + i32 backward_result = FindResult_PastEnd; if (iter.pos < range->start + range->size){ forward_result = search_front_to_back(app, range, iter.key, &iter.pos, &forward_match); @@ -432,9 +437,9 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){ if (backward_result == FindResult_FoundMatch){ find_result = FindResult_FoundMatch; - int32_t forward_start = range->mid_start + range->mid_size; - int32_t forward_distance = (forward_match.start - forward_start); - int32_t backward_distance = (range->mid_start - backward_match.end); + i32 forward_start = range->mid_start + range->mid_size; + i32 forward_distance = (forward_match.start - forward_start); + i32 backward_distance = (range->mid_start - backward_match.end); if (backward_distance < forward_distance){ iter.pos = forward_match.start; @@ -482,25 +487,23 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){ // static void -initialize_generic_search_all_buffers(Application_Links *app, Heap *heap, String *strings, i32 count, Search_Range_Flag match_flags, Buffer_ID *skip_buffers, i32 skip_buffer_count, Search_Set *set, Search_Iter *iter){ - memset(set, 0, sizeof(*set)); - memset(iter, 0, sizeof(*iter)); +initialize_generic_search_all_buffers(Application_Links *app, Heap *heap, String_Const_u8 *strings, i32 count, Search_Range_Flag match_flags, Buffer_ID *skip_buffers, i32 skip_buffer_count, Search_Set *set, Search_Iter *iter){ + block_zero_struct(set); + block_zero_struct(iter); Search_Key key = {}; - i32 sizes[ArrayCount(key.words)]; - memset(sizes, 0, sizeof(sizes)); - - if (count > ArrayCount(key.words)){ - count = ArrayCount(key.words); - } + umem sizes[ArrayCount(key.words)] = {}; + count = clamp_top(count, ArrayCount(key.words)); for (i32 i = 0; i < count; ++i){ sizes[i] = strings[i].size; } // TODO(allen): Why on earth am I allocating these separately in this case? Upgrade to just use the string array on the stack! + // NOTE(allen): ?? What did that TODO mean!? search_key_alloc(heap, &key, sizes, count); for (i32 i = 0; i < count; ++i){ - copy(&key.words[i], strings[i]); + key.words[i].size = strings[i].size; + block_copy(key.words[i].str, strings[i].str, strings[i].size); } search_iter_init(iter, key); @@ -568,63 +571,14 @@ initialize_generic_search_all_buffers(Application_Links *app, Heap *heap, String //////////////////////////////// -static String search_name = make_lit_string("*search*"); - -// TODO(allen): can this get merged with the insertion stuff??? -struct Buffered_Printing{ - Partition *part; - Temp_Memory temp; - Buffer_ID buffer; - i32 pos; -}; - -static Buffered_Printing -make_buffered_print(Application_Links *app, Partition *part, Buffer_ID buffer){ - Buffered_Printing buffered_print = {}; - buffered_print.part = part; - buffered_print.temp = begin_temp_memory(part); - buffered_print.buffer = buffer; - buffer_get_size(app, buffer, &buffered_print.pos); - return(buffered_print); -} +static String_Const_u8 search_name = string_u8_litexpr("*search*"); static void -buffered_print_flush(Application_Links *app, Buffered_Printing *out){ - i32 write_size = out->part->pos - out->temp.pos; - char *str = out->part->base + out->temp.pos; - buffer_replace_range(app, out->buffer, make_range(out->pos), make_string(str, write_size)); - out->pos += write_size; - end_temp_memory(out->temp); -} - -static char* -buffered_memory_reserve(Application_Links *app, Buffered_Printing *out, i32 length, b32 *did_flush){ - char *mem = push_array(out->part, char, length); - *did_flush = false; - if (mem == 0){ - buffered_print_flush(app, out); - mem = push_array(out->part, char, length); - *did_flush = true; - } - Assert(mem != 0); - return(mem); -} - -static char* -buffered_memory_reserve(Application_Links *app, Buffered_Printing *out, i32 length){ - b32 ignore; - return(buffered_memory_reserve(app, out, length, &ignore)); -} - -static i32 -buffered_print_buffer_length(Buffered_Printing *out){ - return(out->part->pos - out->temp.pos); -} - -static void -list__parameters_buffer(Application_Links *app, Heap *heap, Partition *scratch, - String *strings, i32 count, Search_Range_Flag match_flags, +list__parameters_buffer(Application_Links *app, Heap *heap, + String_Const_u8 *strings, i32 count, Search_Range_Flag match_flags, Buffer_ID search_buffer_id){ + Arena *scratch = context_get_arena(app); + // Setup the search buffer for 'init' mode buffer_set_setting(app, search_buffer_id, BufferSetting_ReadOnly, true); buffer_set_setting(app, search_buffer_id, BufferSetting_RecordsHistory, false); @@ -635,11 +589,12 @@ list__parameters_buffer(Application_Links *app, Heap *heap, Partition *scratch, initialize_generic_search_all_buffers(app, heap, strings, count, match_flags, &search_buffer_id, 1, &set, &iter); // List all locations into search buffer - Temp_Memory all_temp = begin_temp_memory(scratch); - Partition line_part = part_sub_part(scratch, (4 << 10)); + Temp_Memory all_temp = begin_temp(scratch); // Setup buffered output - Buffered_Printing out = make_buffered_print(app, scratch, search_buffer_id); + Cursor buffering_cursor = make_cursor(push_array(scratch, u8, KB(64)), KB(64)); + Buffer_Insertion out = begin_buffer_insertion_at_buffered(app, search_buffer_id, 0, &buffering_cursor); + Buffer_ID prev_match_id = 0; b32 no_matches = true; @@ -650,71 +605,46 @@ list__parameters_buffer(Application_Links *app, Heap *heap, Partition *scratch, if (buffer_compute_cursor(app, match.buffer, seek_pos(match.start), &word_pos)){ if (prev_match_id != match.buffer){ if (prev_match_id != 0){ - char *newline = buffered_memory_reserve(app, &out, 1); - *newline = '\n'; + insertc(&out, '\n'); } prev_match_id = match.buffer; } - char file_name_space[256]; - String file_name = make_fixed_width_string(file_name_space); - buffer_get_file_name(app, match.buffer, &file_name, 0); - i32 line_num_len = int_to_str_size(word_pos.line); - i32 column_num_len = int_to_str_size(word_pos.character); - - Temp_Memory line_temp = begin_temp_memory(&line_part); - Partial_Cursor line_start_cursor = {}; - Partial_Cursor line_one_past_last_cursor = {}; - String full_line_str = {}; - if (read_line(app, &line_part, match.buffer, word_pos.line, &full_line_str, &line_start_cursor, &line_one_past_last_cursor)){ - String line_str = skip_chop_whitespace(full_line_str); - - i32 str_len = file_name.size + 1 + line_num_len + 1 + column_num_len + 1 + 1 + line_str.size + 1; - char *spare = buffered_memory_reserve(app, &out, str_len); - - String out_line = make_string_cap(spare, 0, str_len); - append_ss(&out_line, file_name); - append_s_char(&out_line, ':'); - append_int_to_str(&out_line, word_pos.line); - append_s_char(&out_line, ':'); - append_int_to_str(&out_line, word_pos.character); - append_s_char(&out_line, ':'); - append_s_char(&out_line, ' '); - append_ss(&out_line, line_str); - append_s_char(&out_line, '\n'); - Assert(out_line.size == str_len); + Temp_Memory line_temp = begin_temp(scratch); + String_Const_u8 file_name = buffer_push_file_name(app, match.buffer, scratch); + String_Const_u8 full_line_str = scratch_read_line(app, scratch, match.buffer, word_pos.line); + if (full_line_str.size > 0){ + String_Const_u8 line_str = string_skip_chop_whitespace(full_line_str); + insertf(&out, "%.*s:%d:%d: %.*s\n", string_expand(file_name), word_pos.line, word_pos.character, string_expand(line_str)); } - end_temp_memory(line_temp); + end_temp(line_temp); no_matches = false; } } if (no_matches){ - char no_matches_message[] = "no matches\n"; - i32 no_matches_message_length = sizeof(no_matches_message) - 1; - char *no_matches_message_out = buffered_memory_reserve(app, &out, no_matches_message_length); - memcpy(no_matches_message_out, no_matches_message, no_matches_message_length); + insert_string(&out, string_u8_litexpr("no matches\n")); } - buffered_print_flush(app, &out); + end_buffer_insertion(&out); - end_temp_memory(all_temp); + end_temp(all_temp); // Lock *search* as the jump buffer - lock_jump_buffer(search_name.str, search_name.size); + lock_jump_buffer(search_name); } static void -list__parameters(Application_Links *app, Heap *heap, Partition *scratch, String *strings, i32 count, Search_Range_Flag match_flags, View_ID default_target_view){ +list__parameters(Application_Links *app, Heap *heap, String_Const_u8 *strings, i32 count, Search_Range_Flag match_flags, View_ID default_target_view){ // Open the search buffer - Buffer_ID search_buffer_id = create_or_switch_to_buffer_by_name(app, search_name, default_target_view); - list__parameters_buffer(app, heap, scratch, strings, count, match_flags, search_buffer_id); + Buffer_ID search_buffer_id = create_or_switch_to_buffer_and_clear_by_name(app, search_name, default_target_view); + list__parameters_buffer(app, heap, strings, count, match_flags, search_buffer_id); } static void -list_single__parameters(Application_Links *app, Heap *heap, Partition *scratch, String str, b32 substrings, b32 case_insensitive, View_ID default_target_view){ +list_single__parameters(Application_Links *app, Heap *heap, String_Const_u8 str, b32 substrings, b32 case_insensitive, View_ID default_target_view){ Search_Range_Flag flags = 0; if (substrings){ flags |= SearchFlag_MatchSubstring; @@ -725,20 +655,20 @@ list_single__parameters(Application_Links *app, Heap *heap, Partition *scratch, if (case_insensitive){ flags |= SearchFlag_CaseInsensitive; } - list__parameters(app, heap, scratch, &str, 1, flags, default_target_view); + list__parameters(app, heap, &str, 1, flags, default_target_view); } static void -list_query__parameters(Application_Links *app, Heap *heap, Partition *scratch, b32 substrings, b32 case_insensitive, View_ID default_target_view){ +list_query__parameters(Application_Links *app, Heap *heap, b32 substrings, b32 case_insensitive, View_ID default_target_view){ char space[1024]; - String str = get_query_string(app, "List Locations For: ", space, sizeof(space)); + String_Const_u8 str = get_query_string(app, "List Locations For: ", space, sizeof(space)); if (str.size > 0){ - list_single__parameters(app, heap, scratch, str, substrings, case_insensitive, default_target_view); + list_single__parameters(app, heap, str, substrings, case_insensitive, default_target_view); } } static void -list_identifier__parameters(Application_Links *app, Heap *heap, Partition *scratch, b32 substrings, b32 case_insensitive, View_ID default_target_view){ +list_identifier__parameters(Application_Links *app, Heap *heap, b32 substrings, b32 case_insensitive, View_ID default_target_view){ View_ID view = 0; get_active_view(app, AccessProtected, &view); Buffer_ID buffer = 0; @@ -746,45 +676,47 @@ list_identifier__parameters(Application_Links *app, Heap *heap, Partition *scrat if (buffer != 0){ i32 pos = 0; view_get_cursor_pos(app, view, &pos); - char space[512]; - String str = get_token_or_word_under_pos(app, buffer, pos, space, sizeof(space)); + Scratch_Block scratch(app); + String_Const_u8 str = get_token_or_word_under_pos(app, scratch, buffer, pos); if (str.size > 0){ - list_single__parameters(app, heap, scratch, str, substrings, case_insensitive, default_target_view); + list_single__parameters(app, heap, str, substrings, case_insensitive, default_target_view); } } } static void -list_selected_range__parameters(Application_Links *app, Heap *heap, Partition *scratch, b32 substrings, b32 case_insensitive, View_ID default_target_view){ +list_selected_range__parameters(Application_Links *app, Heap *heap, b32 substrings, b32 case_insensitive, View_ID default_target_view){ View_ID view = 0; get_active_view(app, AccessProtected, &view); - Temp_Memory temp = begin_temp_memory(scratch); - String str = get_string_in_view_range(app, scratch, view); + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 str = get_string_in_view_range(app, scratch, view); if (str.size > 0){ - list_single__parameters(app, heap, scratch, str, substrings, case_insensitive, default_target_view); + list_single__parameters(app, heap, str, substrings, case_insensitive, default_target_view); } - end_temp_memory(temp); + end_temp(temp); } static void -list_type_definition__parameters(Application_Links *app, Heap *heap, Partition *scratch, String str, View_ID default_target_view){ - Temp_Memory temp = begin_temp_memory(scratch); +list_type_definition__parameters(Application_Links *app, Heap *heap, String_Const_u8 str, View_ID default_target_view){ + Arena *scratch = context_get_arena(app); + Temp_Memory temp = begin_temp(scratch); - String match_strings[9]; + String_Const_u8 match_strings[9]; i32 i = 0; - match_strings[i++] = string_push_f(scratch, "struct %.*s{" , str.size, str.str); - match_strings[i++] = string_push_f(scratch, "struct %.*s\n{", str.size, str.str); - match_strings[i++] = string_push_f(scratch, "struct %.*s {" , str.size, str.str); - match_strings[i++] = string_push_f(scratch, "union %.*s{" , str.size, str.str); - match_strings[i++] = string_push_f(scratch, "union %.*s\n{" , str.size, str.str); - match_strings[i++] = string_push_f(scratch, "union %.*s {" , str.size, str.str); - match_strings[i++] = string_push_f(scratch, "enum %.*s{" , str.size, str.str); - match_strings[i++] = string_push_f(scratch, "enum %.*s\n{" , str.size, str.str); - match_strings[i++] = string_push_f(scratch, "enum %.*s {" , str.size, str.str); + match_strings[i++] = (string_u8_pushf(scratch, "struct %.*s{" , string_expand(str))); + match_strings[i++] = (string_u8_pushf(scratch, "struct %.*s\n{", string_expand(str))); + match_strings[i++] = (string_u8_pushf(scratch, "struct %.*s {" , string_expand(str))); + match_strings[i++] = (string_u8_pushf(scratch, "union %.*s{" , string_expand(str))); + match_strings[i++] = (string_u8_pushf(scratch, "union %.*s\n{" , string_expand(str))); + match_strings[i++] = (string_u8_pushf(scratch, "union %.*s {" , string_expand(str))); + match_strings[i++] = (string_u8_pushf(scratch, "enum %.*s{" , string_expand(str))); + match_strings[i++] = (string_u8_pushf(scratch, "enum %.*s\n{" , string_expand(str))); + match_strings[i++] = (string_u8_pushf(scratch, "enum %.*s {" , string_expand(str))); - list__parameters(app, heap, scratch, match_strings, ArrayCount(match_strings), 0, default_target_view); + list__parameters(app, heap, match_strings, ArrayCount(match_strings), 0, default_target_view); - end_temp_memory(temp); + end_temp(temp); } //////////////////////////////// @@ -793,66 +725,66 @@ CUSTOM_COMMAND_SIG(list_all_locations) CUSTOM_DOC("Queries the user for a string and lists all exact case-sensitive matches found in all open buffers.") { View_ID target_view = get_next_view_after_active(app, AccessAll); - list_query__parameters(app, &global_heap, &global_part, false, false, target_view); + list_query__parameters(app, &global_heap, false, false, target_view); } CUSTOM_COMMAND_SIG(list_all_substring_locations) CUSTOM_DOC("Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.") { View_ID target_view = get_next_view_after_active(app, AccessAll); - list_query__parameters(app, &global_heap, &global_part, true, false, target_view); + list_query__parameters(app, &global_heap, true, false, target_view); } CUSTOM_COMMAND_SIG(list_all_locations_case_insensitive) CUSTOM_DOC("Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.") { View_ID target_view = get_next_view_after_active(app, AccessAll); - list_query__parameters(app, &global_heap, &global_part, false, true, target_view); + list_query__parameters(app, &global_heap, false, true, target_view); } CUSTOM_COMMAND_SIG(list_all_substring_locations_case_insensitive) CUSTOM_DOC("Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.") { View_ID target_view = get_next_view_after_active(app, AccessAll); - list_query__parameters(app, &global_heap, &global_part, true, true, target_view); + list_query__parameters(app, &global_heap, true, true, target_view); } CUSTOM_COMMAND_SIG(list_all_locations_of_identifier) CUSTOM_DOC("Reads a token or word under the cursor and lists all exact case-sensitive mathces in all open buffers.") { View_ID target_view = get_next_view_after_active(app, AccessAll); - list_identifier__parameters(app, &global_heap, &global_part, false, false, target_view); + list_identifier__parameters(app, &global_heap, false, false, target_view); } CUSTOM_COMMAND_SIG(list_all_locations_of_identifier_case_insensitive) CUSTOM_DOC("Reads a token or word under the cursor and lists all exact case-insensitive mathces in all open buffers.") { View_ID target_view = get_next_view_after_active(app, AccessAll); - list_identifier__parameters(app, &global_heap, &global_part, false, true, target_view); + list_identifier__parameters(app, &global_heap, false, true, target_view); } CUSTOM_COMMAND_SIG(list_all_locations_of_selection) CUSTOM_DOC("Reads the string in the selected range and lists all exact case-sensitive mathces in all open buffers.") { View_ID target_view = get_next_view_after_active(app, AccessAll); - list_selected_range__parameters(app, &global_heap, &global_part, false, false, target_view); + list_selected_range__parameters(app, &global_heap, false, false, target_view); } CUSTOM_COMMAND_SIG(list_all_locations_of_selection_case_insensitive) CUSTOM_DOC("Reads the string in the selected range and lists all exact case-insensitive mathces in all open buffers.") { View_ID target_view = get_next_view_after_active(app, AccessAll); - list_selected_range__parameters(app, &global_heap, &global_part, false, true, target_view); + list_selected_range__parameters(app, &global_heap, false, true, target_view); } CUSTOM_COMMAND_SIG(list_all_locations_of_type_definition) CUSTOM_DOC("Queries user for string, lists all locations of strings that appear to define a type whose name matches the input string.") { char space[1024]; - String str = get_query_string(app, "List Definitions For: ", space, sizeof(space)); + String_Const_u8 str = get_query_string(app, "List Definitions For: ", space, sizeof(space)); if (str.size > 0){ View_ID target_view = get_next_view_after_active(app, AccessAll); - list_type_definition__parameters(app, &global_heap, &global_part, str, target_view); + list_type_definition__parameters(app, &global_heap, str, target_view); } } @@ -865,11 +797,11 @@ CUSTOM_DOC("Reads a token or word under the cursor and lists all locations of st view_get_buffer(app, target_view, AccessProtected, &buffer); i32 pos = 0; view_get_cursor_pos(app, target_view, &pos); - char space[512]; - String str = get_token_or_word_under_pos(app, buffer, pos, space, sizeof(space) - 1); + Scratch_Block scratch(app); + String_Const_u8 str = get_token_or_word_under_pos(app, scratch, buffer, pos); if (str.size > 0){ target_view = get_next_view_after_active(app, AccessAll); - list_type_definition__parameters(app, &global_heap, &global_part, str, target_view); + list_type_definition__parameters(app, &global_heap, str, target_view); } } @@ -889,7 +821,8 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with if (view_get_buffer(app, view, AccessOpen, &buffer)){ i32 do_init = false; - Managed_Scope scope = view_get_managed_scope(app, view); + Managed_Scope scope = 0; + view_get_managed_scope(app, view, &scope); u64 rewrite = 0; managed_variable_get(app, scope, view_rewrite_loc, &rewrite); @@ -904,7 +837,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with i32 word_end = 0; i32 word_start = 0; i32 cursor_pos = 0; - i32 size = 0; + umem size = 0; if (do_init){ // NOTE(allen): Get the range where the @@ -920,11 +853,11 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with i32 still_looping = true; do{ for (; cursor_pos >= chunk.start; --cursor_pos){ - char c = chunk.data[cursor_pos]; - if (char_is_alpha_utf8(c)){ + u8 c = chunk.data[cursor_pos]; + if (character_is_alpha_unicode(c)){ word_start = cursor_pos; } - else if (!char_is_numeric(c)){ + else if (!character_is_base10(c)){ goto double_break; } } @@ -944,7 +877,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with complete_state.initialized = true; Search_Key key = {}; search_key_alloc(&global_heap, &key, &size, 1); - buffer_read_range(app, buffer, word_start, word_end, key.words[0].str); + buffer_read_range(app, buffer, word_start, word_end, (char*)key.words[0].str); key.words[0].size = size; search_iter_init(&complete_state.iter, key); @@ -960,7 +893,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with ranges[0].start = 0; buffer_get_size(app, buffer, &ranges[0].size); ranges[0].mid_start = word_start; - ranges[0].mid_size = size; + ranges[0].mid_size = (i32)size; Buffer_ID buffer_it = 0; @@ -981,8 +914,8 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with // NOTE(allen): Initialize the search hit table. search_hits_init(&global_heap, &complete_state.hits, &complete_state.str, 100, (4 << 10)); - String word = complete_state.iter.key.words[0]; - search_hit_add(&global_heap, &complete_state.hits, &complete_state.str, word.str, word.size); + String_Const_u8 word = complete_state.iter.key.words[0]; + search_hit_add(&global_heap, &complete_state.hits, &complete_state.str, word); complete_state.word_start = word_start; complete_state.word_end = word_end; @@ -990,7 +923,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with else{ word_start = complete_state.word_start; word_end = complete_state.word_end; - size = complete_state.iter.key.words[0].size; + size = (i32)complete_state.iter.key.words[0].size; } // NOTE(allen): Iterate through matches. @@ -1001,33 +934,31 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with if (match.found_match){ match_size = match.end - match.start; - Temp_Memory temp = begin_temp_memory(&global_part); - char *spare = push_array(&global_part, char, match_size); + Arena *scratch = context_get_arena(app); + Scratch_Block temp_auto_closer(scratch); + char *spare = push_array(scratch, char, match_size); buffer_read_range(app, match.buffer, match.start, match.end, spare); if (search_hit_add(&global_heap, &complete_state.hits, &complete_state.str, spare, match_size)){ - buffer_replace_range(app, buffer, make_range(word_start, word_end), make_string(spare, match_size)); + buffer_replace_range(app, buffer, make_range(word_start, word_end), SCu8(spare, match_size)); view_set_cursor(app, view, seek_pos(word_start + match_size), true); complete_state.word_end = word_start + match_size; complete_state.set.ranges[0].mid_size = match_size; - end_temp_memory(temp); break; } - end_temp_memory(temp); } else{ complete_state.iter.pos = 0; complete_state.iter.i = 0; search_hits_init(&global_heap, &complete_state.hits, &complete_state.str, 100, (4 << 10)); - String word = complete_state.iter.key.words[0]; - search_hit_add(&global_heap, &complete_state.hits, &complete_state.str, word.str, word.size); + String_Const_u8 word = complete_state.iter.key.words[0]; + search_hit_add(&global_heap, &complete_state.hits, &complete_state.str, word); - match_size = word.size; - char *str = word.str; - buffer_replace_range(app, buffer, make_range(word_start, word_end), make_string(str, match_size)); + match_size = (i32)word.size; + buffer_replace_range(app, buffer, make_range(word_start, word_end), word); view_set_cursor(app, view, seek_pos(word_start + match_size), true); complete_state.word_end = word_start + match_size; diff --git a/4coder_search.h b/4coder_search.h index d8fb14ba..abeb3797 100644 --- a/4coder_search.h +++ b/4coder_search.h @@ -52,11 +52,11 @@ struct Search_Set{ }; struct Search_Key{ - char *base; - i32 base_size; - String words[16]; + u8 *base; + umem base_size; + umem min_size; + String_Const_u8 words[16]; i32 count; - i32 min_size; }; struct Search_Iter{ diff --git a/4coder_seek.cpp b/4coder_seek.cpp index ed0158e9..5e280d69 100644 --- a/4coder_seek.cpp +++ b/4coder_seek.cpp @@ -74,7 +74,7 @@ move_past_lead_whitespace(Application_Links *app, View_ID view, Buffer_ID buffer do{ for (; i < chunk.end; ++i){ char at_pos = chunk.data[i]; - if (at_pos == '\n' || !char_is_whitespace(at_pos)){ + if (at_pos == '\n' || !character_is_whitespace(at_pos)){ goto break2; } } @@ -103,7 +103,7 @@ buffer_seek_whitespace_up(Application_Links *app, Buffer_ID buffer_id, i32 pos){ for (;still_looping;){ for (; pos >= stream.start; --pos){ char at_pos = stream.data[pos]; - if (!char_is_whitespace(at_pos)){ + if (!character_is_whitespace(at_pos)){ goto double_break_1; } } @@ -128,7 +128,7 @@ buffer_seek_whitespace_up(Application_Links *app, Buffer_ID buffer_id, i32 pos){ no_hard = true; } } - else if (!char_is_whitespace(at_pos)){ + else if (!character_is_whitespace(at_pos)){ no_hard = false; } } @@ -160,7 +160,7 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_ID buffer_id, i32 pos do{ for (; pos < stream.end; ++pos){ char at_pos = stream.data[pos]; - if (!char_is_whitespace(at_pos)){ + if (!character_is_whitespace(at_pos)){ goto double_break_1; } } @@ -187,7 +187,7 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_ID buffer_id, i32 pos prev_endline = pos; } } - else if (!char_is_whitespace(at_pos)){ + else if (!character_is_whitespace(at_pos)){ no_hard = false; } } @@ -221,13 +221,13 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_ID buffer_id, i32 po stream.add_null = true; if (init_stream_chunk(&stream, app, buffer_id, pos, data_chunk, sizeof(data_chunk))){ b32 still_looping = true; - b32 is_whitespace_1 = char_is_whitespace(buffer_get_char(app, buffer_id, pos - 1)); + b32 is_whitespace_1 = character_is_whitespace(buffer_get_char(app, buffer_id, pos - 1)); do{ for (; pos < stream.end; ++pos){ char c2 = stream.data[pos]; b32 is_whitespace_2 = true; if (c2 != 0){ - is_whitespace_2 = char_is_whitespace(c2); + is_whitespace_2 = character_is_whitespace(c2); } if (!is_whitespace_1 && is_whitespace_2){ result = pos; @@ -258,11 +258,11 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_ID buffer_id, i32 pos Stream_Chunk stream = {}; if (init_stream_chunk(&stream, app, buffer_id, pos, data_chunk, sizeof(data_chunk))){ b32 still_looping = true; - b32 is_whitespace_2 = char_is_whitespace(buffer_get_char(app, buffer_id, pos + 1)); + b32 is_whitespace_2 = character_is_whitespace(buffer_get_char(app, buffer_id, pos + 1)); do{ for (; pos >= stream.start; --pos){ char c1 = stream.data[pos]; - b32 is_whitespace_1 = char_is_whitespace(c1); + b32 is_whitespace_1 = character_is_whitespace(c1); if (is_whitespace_1 && !is_whitespace_2){ result = pos + 1; goto double_break; @@ -275,7 +275,7 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_ID buffer_id, i32 pos } } if (pos == -1){ - if (!char_is_whitespace(buffer_get_char(app, buffer_id, 0))){ + if (!character_is_whitespace(buffer_get_char(app, buffer_id, 0))){ result = 0; } } @@ -290,7 +290,8 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_ID buffer_id, i32 b32 still_looping = true; do{ for (; pos < stream.end; ++pos){ - if (char_is_alpha_numeric_true_utf8(stream.data[pos])){ + u8 c = stream.data[pos]; + if (c != '_' && character_is_alpha_numeric_unicode(c)){ goto double_break1; } } @@ -300,7 +301,8 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_ID buffer_id, i32 still_looping = true; do{ for (; pos < stream.end; ++pos){ - if (!char_is_alpha_numeric_true_utf8(stream.data[pos])){ + u8 c = stream.data[pos]; + if (!(c != '_' && character_is_alpha_numeric_unicode(c))){ goto double_break2; } } @@ -321,7 +323,8 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_ID buffer_id, i32 p b32 still_looping = true; do{ for (; pos >= stream.start; --pos){ - if (char_is_alpha_numeric_true_utf8(stream.data[pos])){ + u8 c = stream.data[pos]; + if (c != '_' && character_is_alpha_numeric_unicode(c)){ goto double_break1; } } @@ -331,7 +334,8 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_ID buffer_id, i32 p still_looping = true; do{ for (; pos >= stream.start; --pos){ - if (!char_is_alpha_numeric_true_utf8(stream.data[pos])){ + u8 c = stream.data[pos]; + if (!(c != '_' && character_is_alpha_numeric_unicode(c))){ ++pos; goto double_break2; } @@ -355,7 +359,8 @@ buffer_seek_alphanumeric_or_underscore_right(Application_Links *app, Buffer_ID b b32 still_looping = true; do{ for (; pos < stream.end; ++pos){ - if (char_is_alpha_numeric_utf8(stream.data[pos])){ + u8 c = stream.data[pos]; + if (character_is_alpha_numeric_unicode(c)){ goto double_break1; } } @@ -365,7 +370,8 @@ buffer_seek_alphanumeric_or_underscore_right(Application_Links *app, Buffer_ID b still_looping = true; do{ for (; pos < stream.end; ++pos){ - if (!char_is_alpha_numeric_utf8(stream.data[pos])){ + u8 c = stream.data[pos]; + if (!character_is_alpha_numeric_unicode(c)){ goto double_break2; } } @@ -386,7 +392,8 @@ buffer_seek_alphanumeric_or_underscore_left(Application_Links *app, Buffer_ID bu b32 still_looping = true; do{ for (; pos >= stream.start; --pos){ - if (char_is_alpha_numeric_utf8(stream.data[pos])){ + u8 c = stream.data[pos]; + if (character_is_alpha_numeric_unicode(c)){ goto double_break1; } } @@ -396,7 +403,8 @@ buffer_seek_alphanumeric_or_underscore_left(Application_Links *app, Buffer_ID bu still_looping = true; do{ for (; pos >= stream.start; --pos){ - if (!char_is_alpha_numeric_utf8(stream.data[pos])){ + u8 c = stream.data[pos]; + if (!character_is_alpha_numeric_unicode(c)){ ++pos; goto double_break2; } @@ -420,13 +428,14 @@ buffer_seek_range_camel_right(Application_Links *app, Buffer_ID buffer_id, i32 p if (pos < an_pos){ stream.max_end = an_pos; if (init_stream_chunk(&stream, app, buffer_id, pos, data_chunk, sizeof(data_chunk))){ - u8 c = 0, pc = stream.data[pos]; + u8 c = 0; + u8 pc = stream.data[pos]; ++pos; b32 still_looping = false; do{ for (; pos < stream.end; ++pos){ c = stream.data[pos]; - if (char_is_upper(c) && char_is_lower_utf8(pc)){ + if (character_is_upper(c) && character_is_lower_unicode(pc)){ goto double_break1; } pc = c; @@ -450,12 +459,13 @@ buffer_seek_range_camel_left(Application_Links *app, Buffer_ID buffer_id, i32 po if (pos > 0){ stream.min_start = an_pos+1; if (init_stream_chunk(&stream, app, buffer_id, pos, data_chunk, sizeof(data_chunk))){ - char c = 0, pc = stream.data[pos]; + u8 c = 0; + u8 pc = stream.data[pos]; b32 still_looping = false; do{ for (; pos >= stream.start; --pos){ c = stream.data[pos]; - if (char_is_upper(c) && char_is_lower_utf8(pc)){ + if (character_is_upper(c) && character_is_lower_unicode(pc)){ goto double_break1; } pc = c; @@ -514,27 +524,28 @@ seek_token_right(Cpp_Token_Array *tokens, i32 pos, i32 buffer_end){ } static Cpp_Token_Array -buffer_get_all_tokens(Application_Links *app, Partition *part, Buffer_ID buffer_id){ +buffer_get_all_tokens(Application_Links *app, Arena *arena, Buffer_ID buffer_id){ Cpp_Token_Array array = {}; if (buffer_exists(app, buffer_id)){ b32 is_lexed = false; - if (buffer_get_setting(app, buffer_id, BufferSetting_Lex, &is_lexed) && - is_lexed){ - buffer_token_count(app, buffer_id, &array.count); - array.max_count = array.count; - array.tokens = push_array(part, Cpp_Token, array.count); - buffer_read_tokens(app, buffer_id, 0, array.count, array.tokens); + if (buffer_get_setting(app, buffer_id, BufferSetting_Lex, &is_lexed)){ + if (is_lexed){ + buffer_token_count(app, buffer_id, &array.count); + array.max_count = array.count; + array.tokens = push_array(arena, Cpp_Token, array.count); + buffer_read_tokens(app, buffer_id, 0, array.count, array.tokens); + } } } return(array); } static i32 -buffer_boundary_seek(Application_Links *app, Buffer_ID buffer_id, Partition *part, i32 start_pos, b32 seek_forward, Seek_Boundary_Flag flags){ +buffer_boundary_seek(Application_Links *app, Buffer_ID buffer_id, Arena *scratch, i32 start_pos, b32 seek_forward, Seek_Boundary_Flag flags){ i32 result = 0; // TODO(allen): reduce duplication? - Temp_Memory temp = begin_temp_memory(part); + Temp_Memory temp = begin_temp(scratch); if (buffer_exists(app, buffer_id)){ i32 pos[4]; i32 size = 0; @@ -559,7 +570,7 @@ buffer_boundary_seek(Application_Links *app, Buffer_ID buffer_id, Partition *par if (flags & BoundaryToken){ if (buffer_tokens_are_ready(app, buffer_id)){ - Cpp_Token_Array array = buffer_get_all_tokens(app, part, buffer_id); + Cpp_Token_Array array = buffer_get_all_tokens(app, scratch, buffer_id); pos[1] = seek_token_right(&array, start_pos, size); } else{ @@ -597,7 +608,7 @@ buffer_boundary_seek(Application_Links *app, Buffer_ID buffer_id, Partition *par if (flags & BoundaryToken){ if (buffer_tokens_are_ready(app, buffer_id)){ - Cpp_Token_Array array = buffer_get_all_tokens(app, part, buffer_id); + Cpp_Token_Array array = buffer_get_all_tokens(app, scratch, buffer_id); pos[1] = seek_token_left(&array, start_pos); } else{ @@ -626,7 +637,7 @@ buffer_boundary_seek(Application_Links *app, Buffer_ID buffer_id, Partition *par } result = new_pos; } - end_temp_memory(temp); + end_temp(temp); return(result); } @@ -681,11 +692,8 @@ buffer_seek_delimiter_backward(Application_Links *app, Buffer_ID buffer_id, i32 finished:; } -// NOTE(allen): This is limitted to a string size of 512. -// You can push it up or do something more clever by just -// replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_forward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 end, char *str, i32 size, i32 *result){ +buffer_seek_string_forward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 end, String_Const_u8 needle_string, i32 *result){ i32 buffer_size = 0; buffer_get_size(app, buffer_id, &buffer_size); if (buffer_size > end){ @@ -695,14 +703,13 @@ buffer_seek_string_forward(Application_Links *app, Buffer_ID buffer_id, i32 pos, *result = end; } - char read_buffer[512]; - if (size > 0 && size <= sizeof(read_buffer)){ + Scratch_Block scratch(app); + if (0 < needle_string.size){ if (buffer_exists(app, buffer_id)){ - String read_str = make_fixed_width_string(read_buffer); - String needle_str = make_string(str, size); - char first_char = str[0]; + u8 first_char = string_get_character(needle_string, 0); - read_str.size = size; + u8 *read_buffer = push_array(scratch, u8, needle_string.size); + String_Const_u8 read_str = SCu8(read_buffer, needle_string.size); char chunk[1024]; Stream_Chunk stream = {}; @@ -712,10 +719,10 @@ buffer_seek_string_forward(Application_Links *app, Buffer_ID buffer_id, i32 pos, b32 still_looping = true; do{ for(; pos < stream.end; ++pos){ - char at_pos = stream.data[pos]; + u8 at_pos = stream.data[pos]; if (at_pos == first_char){ - buffer_read_range(app, buffer_id, pos, pos+size, read_buffer); - if (match_ss(needle_str, read_str)){ + buffer_read_range(app, buffer_id, pos, (i32)(pos + needle_string.size), (char*)read_buffer); + if (string_match(needle_string, read_str)){ *result = pos; goto finished; } @@ -737,29 +744,28 @@ buffer_seek_string_forward(Application_Links *app, Buffer_ID buffer_id, i32 pos, } } -// NOTE(allen): This is limitted to a string size of 512. -// You can push it up or do something more clever by just -// replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_backward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 min, char *str, i32 size, i32 *result){ - char read_buffer[512]; +buffer_seek_string_backward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 min, String_Const_u8 needle_string, i32 *result){ + Scratch_Block scratch(app); *result = min - 1; - if (size > 0 && size <= sizeof(read_buffer) && buffer_exists(app, buffer_id)){ - String read_str = make_fixed_width_string(read_buffer); - String needle_str = make_string(str, size); - char first_char = str[0]; - read_str.size = size; + if (0 < needle_string.size && buffer_exists(app, buffer_id)){ + u8 first_char = string_get_character(needle_string, 0); + + u8 *read_buffer = push_array(scratch, u8, needle_string.size); + String_Const_u8 read_str = SCu8(read_buffer, needle_string.size); + char chunk[1024]; Stream_Chunk stream = {}; stream.min_start = min; + if (init_stream_chunk(&stream, app, buffer_id, pos, chunk, sizeof(chunk))){ - i32 still_looping = 1; + b32 still_looping = true; do{ for(; pos >= stream.start; --pos){ - char at_pos = stream.data[pos]; + u8 at_pos = stream.data[pos]; if (at_pos == first_char){ - buffer_read_range(app, buffer_id, pos, pos+size, read_buffer); - if (match_ss(needle_str, read_str)){ + buffer_read_range(app, buffer_id, pos, (i32)(pos + needle_string.size), (char*)read_buffer); + if (string_match(needle_string, read_str)){ *result = pos; goto finished; } @@ -772,11 +778,8 @@ buffer_seek_string_backward(Application_Links *app, Buffer_ID buffer_id, i32 pos } } -// NOTE(allen): This is limitted to a string size of 512. -// You can push it up or do something more clever by just -// replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 end, char *str, i32 size, i32 *result){ +buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 end, String_Const_u8 needle_string, i32 *result){ i32 buffer_size = 0; buffer_get_size(app, buffer_id, &buffer_size); if (buffer_size > end){ @@ -785,24 +788,26 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_ID buffer_ else{ *result = end; } - char read_buffer[512]; - char chunk[1024]; - i32 chunk_size = sizeof(chunk); - Stream_Chunk stream = {}; - stream.max_end = end; - if (size > 0 && size <= sizeof(read_buffer) && buffer_exists(app, buffer_id)){ - String read_str = make_fixed_width_string(read_buffer); - String needle_str = make_string(str, size); - char first_char = char_to_upper(str[0]); - read_str.size = size; - if (init_stream_chunk(&stream, app, buffer_id, pos, chunk, chunk_size)){ - i32 still_looping = 1; + + Scratch_Block scratch(app); + if (0 < needle_string.size && buffer_exists(app, buffer_id)){ + u8 first_char = character_to_upper(string_get_character(needle_string, 0)); + + u8 *read_buffer = push_array(scratch, u8, needle_string.size); + String_Const_u8 read_str = SCu8(read_buffer, needle_string.size); + + char chunk[1024]; + Stream_Chunk stream = {}; + stream.max_end = end; + + if (init_stream_chunk(&stream, app, buffer_id, pos, chunk, sizeof(chunk))){ + b32 still_looping = true; do{ for(; pos < stream.end; ++pos){ - char at_pos = char_to_upper(stream.data[pos]); + u8 at_pos = character_to_upper(stream.data[pos]); if (at_pos == first_char){ - buffer_read_range(app, buffer_id, pos, pos+size, read_buffer); - if (match_insensitive_ss(needle_str, read_str)){ + buffer_read_range(app, buffer_id, pos, (i32)(pos + needle_string.size), (char*)read_buffer); + if (string_match_insensitive(needle_string, read_str)){ *result = pos; goto finished; } @@ -815,31 +820,28 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_ID buffer_ } } -// NOTE(allen): This is limitted to a string size of 512. -// You can push it up or do something more clever by just -// replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 min, char *str, i32 size, i32 *result){ - char read_buffer[512]; - char chunk[1024]; - i32 chunk_size = sizeof(chunk); - Stream_Chunk stream = {}; - stream.min_start = min; - +buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 min, String_Const_u8 needle_string, i32 *result){ + Scratch_Block scratch(app); *result = min - 1; - if (size > 0 && size <= sizeof(read_buffer) && buffer_exists(app, buffer_id)){ - String read_str = make_fixed_width_string(read_buffer); - String needle_str = make_string(str, size); - char first_char = char_to_upper(str[0]); - read_str.size = size; - if (init_stream_chunk(&stream, app, buffer_id, pos, chunk, chunk_size)){ - i32 still_looping = 1; + if (0 < needle_string.size && buffer_exists(app, buffer_id)){ + u8 first_char = character_to_upper(string_get_character(needle_string, 0)); + + u8 *read_buffer = push_array(scratch, u8, needle_string.size); + String_Const_u8 read_str = SCu8(read_buffer, needle_string.size); + + char chunk[1024]; + Stream_Chunk stream = {}; + stream.min_start = min; + + if (init_stream_chunk(&stream, app, buffer_id, pos, chunk, sizeof(chunk))){ + b32 still_looping = true; do{ for(; pos >= stream.start; --pos){ - char at_pos = char_to_upper(stream.data[pos]); + u8 at_pos = character_to_upper(stream.data[pos]); if (at_pos == first_char){ - buffer_read_range(app, buffer_id, pos, pos+size, read_buffer); - if (match_insensitive_ss(needle_str, read_str)){ + buffer_read_range(app, buffer_id, pos, (i32)(pos + needle_string.size), (char*)read_buffer); + if (string_match_insensitive(needle_string, read_str)){ *result = pos; goto finished; } @@ -855,26 +857,26 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_ID buffer //////////////////////////////// static void -buffer_seek_string(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 end, i32 min, char *str, i32 size, i32 *result, Buffer_Seek_String_Flags flags){ +buffer_seek_string(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 end, i32 min, String_Const_u8 str, i32 *result, Buffer_Seek_String_Flags flags){ switch (flags & 3){ case 0: { - buffer_seek_string_forward(app, buffer_id, pos, end, str, size, result); + buffer_seek_string_forward(app, buffer_id, pos, end, str, result); }break; case BufferSeekString_Backward: { - buffer_seek_string_backward(app, buffer_id, pos, min, str, size, result); + buffer_seek_string_backward(app, buffer_id, pos, min, str, result); }break; case BufferSeekString_CaseInsensitive: { - buffer_seek_string_insensitive_forward(app, buffer_id, pos, end, str, size, result); + buffer_seek_string_insensitive_forward(app, buffer_id, pos, end, str, result); }break; case BufferSeekString_Backward|BufferSeekString_CaseInsensitive: { - buffer_seek_string_insensitive_backward(app, buffer_id, pos, min, str, size, result); + buffer_seek_string_insensitive_backward(app, buffer_id, pos, min, str, result); }break; } } @@ -904,7 +906,7 @@ buffer_line_is_blank(Application_Links *app, Buffer_ID buffer_id, i32 line){ do{ for (;i < stream.end; ++i){ char c = stream.data[i]; - if (!char_is_whitespace(c)){ + if (!character_is_whitespace(c)){ result = false; goto double_break; } @@ -917,9 +919,9 @@ buffer_line_is_blank(Application_Links *app, Buffer_ID buffer_id, i32 line){ return(result); } -static String -read_identifier_at_pos(Application_Links *app, Buffer_ID buffer_id, i32 pos, char *space, i32 max, Range *range_out){ - String query = {}; +static String_Const_u8 +read_identifier_at_pos(Application_Links *app, Arena *arena, Buffer_ID buffer_id, i32 pos, Range *range_out){ + String_Const_u8 result = {}; i32 start = buffer_seek_alphanumeric_or_underscore_left(app, buffer_id, pos); i32 end = buffer_seek_alphanumeric_or_underscore_right(app, buffer_id, start); @@ -930,17 +932,13 @@ read_identifier_at_pos(Application_Links *app, Buffer_ID buffer_id, i32 pos, cha } if (start <= pos && pos < end){ - i32 size = end - start; - if (size <= max){ - if (range_out != 0){ - *range_out = make_range(start, end); - } - buffer_read_range(app, buffer_id, start, end, space); - query = make_string_cap(space, size, max); + if (range_out != 0){ + *range_out = make_range(start, end); } + result = scratch_read(app, arena, buffer_id, start, end); } - return(query); + return(result); } //////////////////////////////// @@ -959,14 +957,16 @@ flip_dir(i32 dir){ static i32 buffer_boundary_seek(Application_Links *app, Buffer_ID buffer_id, i32 start_pos, i32 dir, Seek_Boundary_Flag flags){ b32 forward = (dir != DirLeft); - return(buffer_boundary_seek(app, buffer_id, &global_part, start_pos, forward, flags)); + Arena *scratch = context_get_arena(app); + return(buffer_boundary_seek(app, buffer_id, scratch, start_pos, forward, flags)); } static void view_buffer_boundary_seek_set_pos(Application_Links *app, View_ID view, Buffer_ID buffer_id, i32 dir, u32 flags){ i32 cursor_pos = 0; view_get_cursor_pos(app, view, &cursor_pos); - i32 pos = buffer_boundary_seek(app, buffer_id, &global_part, cursor_pos, dir, flags); + Arena *scratch = context_get_arena(app); + i32 pos = buffer_boundary_seek(app, buffer_id, scratch, cursor_pos, dir, flags); view_set_cursor(app, view, seek_pos(pos), true); no_mark_snap_to_cursor_if_shift(app, view); } @@ -1005,7 +1005,7 @@ view_buffer_snipe_range(Application_Links *app, View_ID view, Buffer_ID buffer_i i32 pos2 = buffer_boundary_seek(app, buffer_id, pos1, flip_dir(dir), flags); if (0 <= pos2 && pos2 <= buffer_size){ if (dir == DirLeft){ - pos2 = clamp_bottom(pos2, pos0); + pos2 = clamp_bot(pos2, pos0); } else{ pos2 = clamp_top(pos2, pos0); @@ -1023,7 +1023,7 @@ current_view_boundary_delete(Application_Links *app, i32 dir, u32 flags){ Buffer_ID buffer_id = 0; view_get_buffer(app, view, AccessOpen, &buffer_id); Range range = view_buffer_boundary_range(app, view, buffer_id, dir, flags); - buffer_replace_range(app, buffer_id, range, make_lit_string("")); + buffer_replace_range(app, buffer_id, range, string_u8_litexpr("")); } static void @@ -1033,7 +1033,7 @@ current_view_snipe_delete(Application_Links *app, i32 dir, u32 flags){ Buffer_ID buffer_id = 0; view_get_buffer(app, view, AccessOpen, &buffer_id); Range range = view_buffer_snipe_range(app, view, buffer_id, dir, flags); - buffer_replace_range(app, buffer_id, range, make_lit_string("")); + buffer_replace_range(app, buffer_id, range, string_u8_litexpr("")); } //////////////////////////////// diff --git a/4coder_stringf.cpp b/4coder_stringf.cpp new file mode 100644 index 00000000..6d50a361 --- /dev/null +++ b/4coder_stringf.cpp @@ -0,0 +1,72 @@ +/* + * Printf style operations for strings and what-not + */ + +// TOP + +#include +#include + +static String_Const_char +string_pushfv(Arena *arena, char *format, va_list args){ + i32 size = vsnprintf(0, 0, format, args); + String_Const_char result = string_const_char_push(arena, size + 1); + vsnprintf(result.str, result.size, format, args); + result.size -= 1; + result.str[result.size] = 0; + return(result); +} +static String_Const_char +string_pushf(Arena *arena, char *format, ...){ + va_list args; + va_start(args, format); + String_Const_char result = string_pushfv(arena, format, args); + va_end(args); + return(result); +} +static String_Const_u8 +string_u8_pushfv(Arena *arena, char *format, va_list args){ + return(SCu8(string_pushfv(arena, format, args))); +} +static String_Const_u8 +string_u8_pushf(Arena *arena, char *format, ...){ + va_list args; + va_start(args, format); + String_Const_u8 result = SCu8(string_pushfv(arena, format, args)); + va_end(args); + return(result); +} + +static void +string_list_pushfv(Arena *arena, List_String_Const_char *list, char *format, va_list args){ + String_Const_char string = string_pushfv(arena, format, args); + if (arena->alignment < sizeof(umem)){ + push_align(arena, sizeof(umem)); + } + string_list_push(arena, list, string); +} +static void +string_list_pushf(Arena *arena, List_String_Const_char *list, char *format, ...){ + va_list args; + va_start(args, format); + string_list_pushfv(arena, list, format, args); + va_end(args); +} +static void +string_list_pushfv(Arena *arena, List_String_Const_u8 *list, char *format, va_list args){ + String_Const_u8 string = string_u8_pushfv(arena, format, args); + if (arena->alignment < sizeof(umem)){ + push_align(arena, sizeof(umem)); + } + string_list_push(arena, list, string); +} +static void +string_list_pushf(Arena *arena, List_String_Const_u8 *list, char *format, ...){ + va_list args; + va_start(args, format); + string_list_pushfv(arena, list, format, args); + va_end(args); +} + +// BOTTOM + diff --git a/4coder_system_command.cpp b/4coder_system_command.cpp index 50ad9ba2..9766bcba 100644 --- a/4coder_system_command.cpp +++ b/4coder_system_command.cpp @@ -7,32 +7,41 @@ CUSTOM_COMMAND_SIG(execute_previous_cli) CUSTOM_DOC("If the command execute_any_cli has already been used, this will execute a CLI reusing the most recent buffer name and command.") { - String out_buffer = make_string_slowly(out_buffer_space); - String cmd = make_string_slowly(command_space); - String hot_directory = make_string_slowly(hot_directory_space); + String_Const_u8 out_buffer = SCu8(out_buffer_space); + String_Const_u8 cmd = SCu8(command_space); + String_Const_u8 hot_directory = SCu8(hot_directory_space); if (out_buffer.size > 0 && cmd.size > 0 && hot_directory.size > 0){ View_ID view = 0; get_active_view(app, AccessAll, &view); - exec_system_command(app, view, buffer_identifier(out_buffer.str, out_buffer.size), hot_directory.str, hot_directory.size, cmd.str, cmd.size, CLI_OverlapWithConflict|CLI_CursorAtEnd|CLI_SendEndSignal); + Buffer_Identifier id = buffer_identifier(out_buffer); + exec_system_command(app, view, id, hot_directory, cmd, CLI_OverlapWithConflict|CLI_CursorAtEnd|CLI_SendEndSignal); lock_jump_buffer(out_buffer); } } CUSTOM_COMMAND_SIG(execute_any_cli) CUSTOM_DOC("Queries for an output buffer name and system command, runs the system command as a CLI and prints the output to the specified buffer."){ - Query_Bar bar_out = {}; - Query_Bar bar_cmd = {}; + Scratch_Block scratch(app); - bar_out.prompt = make_lit_string("Output Buffer: "); - bar_out.string = make_fixed_width_string(out_buffer_space); + Query_Bar bar_out = {}; + bar_out.prompt = string_u8_litexpr("Output Buffer: "); + bar_out.string = SCu8(out_buffer_space, (umem)0); + bar_out.string_capacity = sizeof(out_buffer_space); if (!query_user_string(app, &bar_out)) return; - bar_cmd.prompt = make_lit_string("Command: "); - bar_cmd.string = make_fixed_width_string(command_space); + Query_Bar bar_cmd = {}; + bar_cmd.prompt = string_u8_litexpr("Command: "); + bar_cmd.string = SCu8(command_space, (umem)0); + bar_cmd.string_capacity = sizeof(command_space); if (!query_user_string(app, &bar_cmd)) return; - directory_get_hot(app, hot_directory_space, sizeof(hot_directory_space)); + String_Const_u8 hot = push_hot_directory(app, scratch); + { + umem size = clamp_top(hot.size, sizeof(hot_directory_space)); + block_copy(hot_directory_space, hot.str, size); + hot_directory_space[hot.size] = 0; + } execute_previous_cli(app); } diff --git a/4coder_ui_helper.cpp b/4coder_ui_helper.cpp index ed78529f..0fa9bf69 100644 --- a/4coder_ui_helper.cpp +++ b/4coder_ui_helper.cpp @@ -31,7 +31,7 @@ view_get_ui_data(Application_Links *app, View_ID view_id, View_Get_UI_Flags flag storage.data = ui_data; storage.arena = arena; storage.arena_object = arena_object; - storage.temp = begin_temp_memory(arena); + storage.temp = begin_temp(arena); if (managed_object_store_data(app, new_ui_data_object, 0, 1, &storage)){ if (managed_variable_set(app, scope, view_ui_data, new_ui_data_object)){ ui_data_object = new_ui_data_object; @@ -45,7 +45,7 @@ view_get_ui_data(Application_Links *app, View_ID view_id, View_Get_UI_Flags flag *ui_data_out = storage.data; *ui_arena_out = storage.arena; if ((flags & ViewGetUIFlag_ClearData) != 0){ - end_temp_memory(storage.temp); + end_temp(storage.temp); } result = true; } @@ -297,8 +297,6 @@ init_lister_state(Application_Links *app, Lister_State *state, Heap *heap){ state->item_index = 0; state->set_view_vertical_focus_to_item = false; state->item_count_after_filter = 0; - arena_release_all(&state->lister.arena); - memset(&state->lister, 0, sizeof(state->lister)); } UI_QUIT_FUNCTION(lister_quit_function){ @@ -308,9 +306,8 @@ UI_QUIT_FUNCTION(lister_quit_function){ } static UI_Item -lister_get_clicked_item(Application_Links *app, View_ID view_id, Partition *scratch){ +lister_get_clicked_item(Application_Links *app, View_ID view_id){ UI_Item result = {}; - Temp_Memory temp = begin_temp_memory(scratch); UI_Data *ui_data = 0; Arena *ui_arena = 0; if (view_get_ui_data(app, view_id, ViewGetUIFlag_KeepDataAsIs, &ui_data, &ui_arena)){ @@ -327,7 +324,6 @@ lister_get_clicked_item(Application_Links *app, View_ID view_id, Partition *scra result = *clicked; } } - end_temp_memory(temp); return(result); } @@ -349,7 +345,7 @@ lister_get_block_height(f32 line_height, b32 is_theme_list){ } static void -lister_update_ui(Application_Links *app, Partition *scratch, View_ID view, Lister_State *state){ +lister_update_ui(Application_Links *app, View_ID view, Lister_State *state){ b32 is_theme_list = state->lister.data.theme_list; Rect_f32 screen_rect = {}; @@ -369,7 +365,8 @@ lister_update_ui(Application_Links *app, Partition *scratch, View_ID view, Liste f32 block_height = lister_get_block_height(line_height, is_theme_list); f32 text_field_height = lister_get_text_field_height(metrics.line_height); - Temp_Memory full_temp = begin_temp_memory(scratch); + Arena *scratch = context_get_arena(app); + Temp_Memory full_temp = begin_temp(scratch); // TODO(allen): switch to float Rect_i32 buffer_region = {}; @@ -388,21 +385,25 @@ lister_update_ui(Application_Links *app, Partition *scratch, View_ID view, Liste Lister_Node_Ptr_Array substring_matches = {}; substring_matches.node_ptrs = push_array(scratch, Lister_Node*, node_count); - String key = state->lister.data.key_string; - Absolutes absolutes = {}; - get_absolutes(key, &absolutes, true, true); - b32 has_wildcard = (absolutes.count > 3); + String_Const_u8 key = state->lister.data.key_string.string; + List_String_Const_u8 absolutes = {}; + string_list_push(scratch, &absolutes, string_u8_litexpr("")); + List_String_Const_u8 splits = string_split(scratch, key, (u8*)"*", 1); + b32 has_wildcard = (splits.node_count > 1); + string_list_push(&absolutes, &splits); + string_list_push(scratch, &absolutes, string_u8_litexpr("")); for (Lister_Node *node = state->lister.data.options.first; node != 0; node = node->next){ if (key.size == 0 || - wildcard_match_s(&absolutes, node->string, false)){ - if (match_insensitive(node->string, key) && exact_matches.count == 0){ + string_wildcard_match_insensitive(absolutes, node->string)){ + String_Const_u8 node_string = node->string; + if (string_match_insensitive(node_string, key) && exact_matches.count == 0){ exact_matches.node_ptrs[exact_matches.count++] = node; } else if (!has_wildcard && - match_part_insensitive(node->string, key) && + string_match_insensitive(string_prefix(node_string, key.size), key) && node->string.size > key.size && node->string.str[key.size] == '.'){ before_extension_matches.node_ptrs[before_extension_matches.count++] = node; @@ -458,7 +459,7 @@ lister_update_ui(Application_Links *app, Partition *scratch, View_ID view, Liste else{ //i32 style_index = node->index; - String name = make_lit_string("name"); + String_Const_u8 name = string_u8_litexpr("name"); item.lines[0] = fancy_string_list_single(push_fancy_string(ui_arena, fancy_id(Stag_Default), name)); Fancy_String_List list = {}; @@ -531,9 +532,9 @@ lister_update_ui(Application_Links *app, Partition *scratch, View_ID view, Liste item.inner_margin = 0; { Fancy_String_List list = {}; - push_fancy_string (ui_arena, &list, fancy_id(Stag_Pop1 ), state->lister.data.query); + push_fancy_string (ui_arena, &list, fancy_id(Stag_Pop1 ), state->lister.data.query.string); push_fancy_stringf(ui_arena, &list, fancy_id(Stag_Pop1 ), " "); - push_fancy_string (ui_arena, &list, fancy_id(Stag_Default), state->lister.data.text_field); + push_fancy_string (ui_arena, &list, fancy_id(Stag_Default), state->lister.data.text_field.string); item.lines[0] = list; item.line_count = 1; } @@ -550,11 +551,11 @@ lister_update_ui(Application_Links *app, Partition *scratch, View_ID view, Liste view_set_quit_ui_handler(app, view, lister_quit_function); } - end_temp_memory(full_temp); + end_temp(full_temp); } static Lister_Prealloced_String -lister_prealloced(String string){ +lister_prealloced(String_Const_u8 string){ Lister_Prealloced_String result = {}; result.string = string; return(result); @@ -562,11 +563,16 @@ lister_prealloced(String string){ static void lister_first_init(Application_Links *app, Lister *lister, void *user_data, i32 user_data_size){ - memset(lister, 0, sizeof(*lister)); - lister->arena = make_arena(app, (16 << 10)); - lister->data.query = make_fixed_width_string(lister->data.query_space); - lister->data.text_field = make_fixed_width_string(lister->data.text_field_space); - lister->data.key_string = make_fixed_width_string(lister->data.key_string_space); + if (lister->arena.base_allocator == 0) { + lister->arena = make_arena_app_links(app, KB(16)); + } + else{ + linalloc_clear(&lister->arena); + } + block_zero_struct(&lister->data); + lister->data.query = Su8(lister->data.query_space, 0, sizeof(lister->data.query_space)); + lister->data.text_field = Su8(lister->data.text_field_space, 0, sizeof(lister->data.text_field_space)); + lister->data.key_string = Su8(lister->data.key_string_space, 0, sizeof(lister->data.key_string_space)); lister->data.user_data = push_array(&lister->arena, char, user_data_size); lister->data.user_data_size = user_data_size; push_align(&lister->arena, 8); @@ -576,45 +582,45 @@ lister_first_init(Application_Links *app, Lister *lister, void *user_data, i32 u } static void -lister_begin_new_item_set(Application_Links *app, Lister *lister, i32 list_memory_size){ - arena_release_all(&lister->arena); - memset(&lister->data.options, 0, sizeof(lister->data.options)); +lister_begin_new_item_set(Application_Links *app, Lister *lister){ + linalloc_clear(&lister->arena); + block_zero_struct(&lister->data.options); } static void* lister_add_item(Lister *lister, Lister_Prealloced_String string, Lister_Prealloced_String status, - void *user_data, i32 extra_space){ - Lister_Node *node = push_array(&lister->arena, Lister_Node, 1); + void *user_data, umem extra_space){ + void *base_memory = push_array(&lister->arena, u8, sizeof(Lister_Node) + extra_space); + Lister_Node *node = (Lister_Node*)base_memory; node->string = string.string; node->status = status.string; node->user_data = user_data; node->raw_index = lister->data.options.count; zdll_push_back(lister->data.options.first, lister->data.options.last, node); lister->data.options.count += 1; - void *result = push_array(&lister->arena, char, extra_space); - push_align(&lister->arena, 8); + void *result = (node + 1); return(result); } static void* -lister_add_item(Lister *lister, Lister_Prealloced_String string, String status, - void *user_data, i32 extra_space){ - return(lister_add_item(lister, string, lister_prealloced(string_push_copy(&lister->arena, status)), +lister_add_item(Lister *lister, Lister_Prealloced_String string, String_Const_u8 status, + void *user_data, umem extra_space){ + return(lister_add_item(lister, string, lister_prealloced(string_copy(&lister->arena, status)), user_data, extra_space)); } static void* -lister_add_item(Lister *lister, String string, Lister_Prealloced_String status, - void *user_data, i32 extra_space){ - return(lister_add_item(lister, lister_prealloced(string_push_copy(&lister->arena, string)), status, +lister_add_item(Lister *lister, String_Const_u8 string, Lister_Prealloced_String status, + void *user_data, umem extra_space){ + return(lister_add_item(lister, lister_prealloced(string_copy(&lister->arena, string)), status, user_data, extra_space)); } static void* -lister_add_item(Lister *lister, String string, String status, void *user_data, i32 extra_space){ +lister_add_item(Lister *lister, String_Const_u8 string, String_Const_u8 status, void *user_data, umem extra_space){ return(lister_add_item(lister, - lister_prealloced(string_push_copy(&lister->arena, string)), - lister_prealloced(string_push_copy(&lister->arena, status)), + lister_prealloced(string_copy(&lister->arena, string)), + lister_prealloced(string_copy(&lister->arena, status)), user_data, extra_space)); } @@ -635,9 +641,9 @@ lister_add_theme_item(Lister *lister, } static void* -lister_add_theme_item(Lister *lister, String string, i32 index, +lister_add_theme_item(Lister *lister, String_Const_u8 string, i32 index, void *user_data, i32 extra_space){ - return(lister_add_theme_item(lister, lister_prealloced(string_push_copy(&lister->arena, string)), index, + return(lister_add_theme_item(lister, lister_prealloced(string_copy(&lister->arena, string)), index, user_data, extra_space)); } @@ -666,13 +672,13 @@ lister_call_refresh_handler(Application_Links *app, Lister *lister){ } static void -lister_default(Application_Links *app, Partition *scratch, Heap *heap, View_ID view, Lister_State *state, Lister_Activation_Code code){ +lister_default(Application_Links *app, Heap *heap, View_ID view, Lister_State *state, Lister_Activation_Code code){ switch (code){ case ListerActivation_Finished: { view_end_ui_mode(app, view); state->initialized = false; - arena_release_all(&state->lister.arena); + linalloc_clear(&state->lister.arena); }break; case ListerActivation_Continue: @@ -685,50 +691,130 @@ lister_default(Application_Links *app, Partition *scratch, Heap *heap, View_ID v view_begin_ui_mode(app, view); state->item_index = 0; lister_call_refresh_handler(app, &state->lister); - lister_update_ui(app, scratch, view, state); + lister_update_ui(app, view, state); }break; } } static void -lister_call_activate_handler(Application_Links *app, Partition *scratch, Heap *heap, View_ID view, Lister_State *state, void *user_data, b32 activated_by_mouse){ +lister_call_activate_handler(Application_Links *app, Heap *heap, View_ID view, Lister_State *state, void *user_data, b32 activated_by_mouse){ Lister_Data *lister = &state->lister.data; if (lister->handlers.activate != 0){ - lister->handlers.activate(app, scratch, heap, view, state, lister->text_field, user_data, activated_by_mouse); + lister->handlers.activate(app, heap, view, state, lister->text_field.string, user_data, activated_by_mouse); } else{ - lister_default(app, scratch, heap, view, state, ListerActivation_Finished); + lister_default(app, heap, view, state, ListerActivation_Finished); } } static void -lister_set_query_string(Lister_Data *lister, char *string){ - copy(&lister->query, string); +lister_set_string(String_Const_u8 string, String_u8 *target){ + target->size = 0; + string_append(target, string); +} +static void +lister_append_string(String_Const_u8 string, String_u8 *target){ + string_append(target, string); } static void -lister_set_query_string(Lister_Data *lister, String string){ - copy(&lister->query, string); +lister_set_query(Lister_Data *lister, String_Const_u8 string){ + lister_set_string(string, &lister->query); +} +static void +lister_set_query(Lister_Data *lister, char *string){ + lister_set_string(SCu8(string), &lister->query); +} +static void +lister_set_text_field(Lister_Data *lister, String_Const_u8 string){ + lister_set_string(string, &lister->text_field); +} +static void +lister_set_text_field(Lister_Data *lister, char *string){ + lister_set_string(SCu8(string), &lister->text_field); +} +static void +lister_set_key(Lister_Data *lister, String_Const_u8 string){ + lister_set_string(string, &lister->key_string); +} +static void +lister_set_key(Lister_Data *lister, char *string){ + lister_set_string(SCu8(string), &lister->key_string); } static void -lister_set_text_field_string(Lister_Data *lister, char *string){ - copy(&lister->text_field, string); +lister_set_query(Lister *lister, String_Const_u8 string){ + lister_set_query(&lister->data, string); +} +static void +lister_set_query(Lister *lister, char *string){ + lister_set_query(&lister->data, string); +} +static void +lister_set_text_field(Lister *lister, String_Const_u8 string){ + lister_set_text_field(&lister->data, string); +} +static void +lister_set_text_field(Lister *lister, char *string){ + lister_set_text_field(&lister->data, string); +} +static void +lister_set_key(Lister *lister, String_Const_u8 string){ + lister_set_key(&lister->data, string); +} +static void +lister_set_key(Lister *lister, char *string){ + lister_set_key(&lister->data, string); } static void -lister_set_text_field_string(Lister_Data *lister, String string){ - copy(&lister->text_field, string); +lister_append_query(Lister_Data *lister, String_Const_u8 string){ + lister_append_string(string, &lister->query); +} +static void +lister_append_query(Lister_Data *lister, char *string){ + lister_append_string(SCu8(string), &lister->query); +} +static void +lister_append_text_field(Lister_Data *lister, String_Const_u8 string){ + lister_append_string(string, &lister->text_field); +} +static void +lister_append_text_field(Lister_Data *lister, char *string){ + lister_append_string(SCu8(string), &lister->text_field); +} +static void +lister_append_key(Lister_Data *lister, String_Const_u8 string){ + lister_append_string(string, &lister->key_string); +} +static void +lister_append_key(Lister_Data *lister, char *string){ + lister_append_string(SCu8(string), &lister->key_string); } static void -lister_set_key_string(Lister_Data *lister, char *string){ - copy(&lister->key_string, string); +lister_append_query(Lister *lister, String_Const_u8 string){ + lister_append_query(&lister->data, string); } - static void -lister_set_key_string(Lister_Data *lister, String string){ - copy(&lister->key_string, string); +lister_append_query(Lister *lister, char *string){ + lister_append_query(&lister->data, string); +} +static void +lister_append_text_field(Lister *lister, String_Const_u8 string){ + lister_append_text_field(&lister->data, string); +} +static void +lister_append_text_field(Lister *lister, char *string){ + lister_append_text_field(&lister->data, string); +} +static void +lister_append_key(Lister *lister, String_Const_u8 string){ + lister_append_key(&lister->data, string); +} +static void +lister_append_key(Lister *lister, char *string){ + lister_append_key(&lister->data, string); } // BOTTOM diff --git a/4coder_ui_helper.h b/4coder_ui_helper.h index 2058b6e8..ec979b1b 100644 --- a/4coder_ui_helper.h +++ b/4coder_ui_helper.h @@ -48,7 +48,7 @@ struct UI_Storage{ UI_Data *data; Arena *arena; Managed_Object arena_object; - Temp_Memory_Arena temp; + Temp_Memory temp; }; //////////////////////////////// @@ -60,18 +60,18 @@ enum{ ListerActivation_ContinueAndRefresh = 2, }; -typedef void Lister_Activation_Function_Type(Application_Links *app, Partition *scratch, Heap *heap, +typedef void Lister_Activation_Function_Type(Application_Links *app, Heap *heap, View_ID view, struct Lister_State *state, - String text_field, void *user_data, b32 activated_by_mouse); + String_Const_u8 text_field, void *user_data, b32 activated_by_mouse); typedef void Lister_Regenerate_List_Function_Type(Application_Links *app, struct Lister *lister); struct Lister_Node{ Lister_Node *next; Lister_Node *prev; - String string; + String_Const_u8 string; union{ - String status; + String_Const_u8 status; i32 index; }; void *user_data; @@ -105,12 +105,12 @@ struct Lister_Data{ // List Data void *user_data; i32 user_data_size; - char query_space[256]; - String query; - char text_field_space[256]; - String text_field; - char key_string_space[256]; - String key_string; + u8 query_space[256]; + u8 text_field_space[256]; + u8 key_string_space[256]; + String_u8 query; + String_u8 text_field; + String_u8 key_string; Lister_Option_List options; b32 theme_list; }; @@ -137,14 +137,14 @@ struct Lister_State{ }; struct Lister_Prealloced_String{ - String string; + String_Const_u8 string; }; //////////////////////////////// struct Lister_Option{ - String string; - String status; + String_Const_u8 string; + String_Const_u8 status; void *user_data; }; diff --git a/4ed.cpp b/4ed.cpp index cc858d6b..04e3f092 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -119,8 +119,8 @@ SCROLL_RULE_SIG(fallback_scroll_rule){ #define DEFAULT_UI_MAP_SIZE 32 internal void -setup_ui_commands(Command_Map *commands, Partition *part, i32 parent){ - map_init(commands, part, DEFAULT_UI_MAP_SIZE, parent); +setup_ui_commands(Command_Map *commands, Cursor *cursor, i32 parent){ + map_init(commands, cursor, DEFAULT_UI_MAP_SIZE, parent); // TODO(allen): do(fix the weird built-in-ness of the ui map) u8 mdfr_array[] = {MDFR_NONE, MDFR_SHIFT, MDFR_CTRL, MDFR_SHIFT | MDFR_CTRL}; for (i32 i = 0; i < 4; ++i){ @@ -134,24 +134,23 @@ setup_ui_commands(Command_Map *commands, Partition *part, i32 parent){ } internal void -setup_file_commands(Command_Map *commands, Partition *part, i32 parent){ - map_init(commands, part, DEFAULT_MAP_SIZE, parent); +setup_file_commands(Command_Map *commands, Cursor *cursor, i32 parent){ + map_init(commands, cursor, DEFAULT_MAP_SIZE, parent); } internal void -setup_top_commands(Command_Map *commands, Partition *part, i32 parent){ - map_init(commands, part, DEFAULT_MAP_SIZE, parent); +setup_top_commands(Command_Map *commands, Cursor *cursor, i32 parent){ + map_init(commands, cursor, DEFAULT_MAP_SIZE, parent); } +// TODO(allen): REWRITE REWRITE REWRITE! internal b32 interpret_binding_buffer(Models *models, void *buffer, i32 size){ b32 result = true; Heap *gen = &models->mem.heap; - Partition *part = &models->mem.part; - Temp_Memory temp = begin_temp_memory(part); - - Partition local_part = {}; + Arena *scratch = &models->mem.arena; + Temp_Memory temp = begin_temp(scratch); Mapping new_mapping = {}; @@ -179,10 +178,10 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){ new_mapping.user_map_count = user_map_count; // Initialize Table and User Maps in Temp Buffer - new_mapping.map_id_table = push_array(part, i32, user_map_count); + new_mapping.map_id_table = push_array(scratch, i32, user_map_count); memset(new_mapping.map_id_table, -1, user_map_count*sizeof(i32)); - new_mapping.user_maps = push_array(part, Command_Map, user_map_count); + new_mapping.user_maps = push_array(scratch, Command_Map, user_map_count); memset(new_mapping.user_maps, 0, user_map_count*sizeof(Command_Map)); // Find the Size of Each Map @@ -227,12 +226,12 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){ // Add up the Map Counts i32 count_global = DEFAULT_MAP_SIZE; if (did_top){ - count_global = clamp_bottom(6, new_mapping.map_top.count*3/2); + count_global = clamp_bot(6, new_mapping.map_top.count*3/2); } i32 count_file = DEFAULT_MAP_SIZE; if (did_file){ - count_file = clamp_bottom(6, new_mapping.map_file.count*3/2); + count_file = clamp_bot(6, new_mapping.map_file.count*3/2); } i32 count_ui = DEFAULT_UI_MAP_SIZE; @@ -240,7 +239,7 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){ i32 count_user = 0; for (i32 i = 0; i < user_map_count; ++i){ Command_Map *map = &new_mapping.user_maps[i]; - count_user += clamp_bottom(6, map->max*3/2); + count_user += clamp_bot(6, map->max*3/2); } i32 binding_memsize = (count_global + count_file + count_ui + count_user)*sizeof(Command_Binding); @@ -249,23 +248,23 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){ i32 map_id_table_memsize = user_map_count*sizeof(i32); i32 user_maps_memsize = user_map_count*sizeof(Command_Map); - i32 map_id_table_rounded_memsize = l_round_up_i32(map_id_table_memsize, 8); - i32 user_maps_rounded_memsize = l_round_up_i32(user_maps_memsize, 8); + i32 map_id_table_rounded_memsize = round_up_i32(map_id_table_memsize, 8); + i32 user_maps_rounded_memsize = round_up_i32(user_maps_memsize, 8); - i32 binding_rounded_memsize = l_round_up_i32(binding_memsize, 8); + i32 binding_rounded_memsize = round_up_i32(binding_memsize, 8); i32 needed_memsize = map_id_table_rounded_memsize + user_maps_rounded_memsize + binding_rounded_memsize; new_mapping.memory = heap_allocate(gen, needed_memsize); - local_part = make_part(new_mapping.memory, needed_memsize); + Cursor local_cursor = make_cursor(new_mapping.memory, needed_memsize); // Move ID Table Memory and Pointer i32 *old_table = new_mapping.map_id_table; - new_mapping.map_id_table = push_array(&local_part, i32, user_map_count); + new_mapping.map_id_table = push_array(&local_cursor, i32, user_map_count); memmove(new_mapping.map_id_table, old_table, map_id_table_memsize); // Move User Maps Memory and Pointer Command_Map *old_maps = new_mapping.user_maps; - new_mapping.user_maps = push_array(&local_part, Command_Map, user_map_count); + new_mapping.user_maps = push_array(&local_cursor, Command_Map, user_map_count); memmove(new_mapping.user_maps, old_maps, user_maps_memsize); // Fill in Command Maps @@ -304,8 +303,8 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){ // NOTE(allen): Map can begin multiple times, only alloc and clear when we first see it. if (map_ptr->commands == 0){ i32 count = map->max; - i32 table_max = clamp_bottom(6, count*3/2); - map_init(map_ptr, &local_part, table_max, mapid_global); + i32 table_max = clamp_bot(6, count*3/2); + map_init(map_ptr, &local_cursor, table_max, mapid_global); } } }break; @@ -424,17 +423,17 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){ } if (!did_top){ - setup_top_commands(&new_mapping.map_top, &local_part, mapid_global); + setup_top_commands(&new_mapping.map_top, &local_cursor, mapid_global); } if (!did_file){ - setup_file_commands(&new_mapping.map_file, &local_part, mapid_global); + setup_file_commands(&new_mapping.map_file, &local_cursor, mapid_global); } - setup_ui_commands(&new_mapping.map_ui, &local_part, mapid_global); + setup_ui_commands(&new_mapping.map_ui, &local_cursor, mapid_global); } else{ // TODO(allen): do(Error report: bad binding units map.) // TODO(allen): do(no bindings set recovery plan.) - InvalidCodePath; + InvalidPath; } Mapping old_mapping = models->mapping; @@ -443,7 +442,7 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){ } models->mapping = new_mapping; - end_temp_memory(temp); + end_temp(temp); return(result); } @@ -528,10 +527,10 @@ fill_hardcode_default_style(Color_Table color_table){ internal void app_hardcode_default_style(Models *models){ - Partition *part = &models->mem.part; + Arena *arena = &models->mem.arena; Color_Table color_table = {}; - color_table.vals = push_array(part, u32, Stag_COUNT); color_table.count = Stag_COUNT; + color_table.vals = push_array(arena, u32, color_table.count); fill_hardcode_default_style(color_table); models->fallback_color_table = color_table; } @@ -704,13 +703,59 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings, } } +//////////////////////////////// + +internal void* +base_reserve__system(void *user_data, umem size, umem *size_out){ + System_Functions *system = (System_Functions*)user_data; + umem extra_size = 128; + umem increased_size = size + extra_size; + size = round_up_umem(increased_size, KB(4)); + *size_out = size - extra_size; + void *ptr = system->memory_allocate(size); + *(umem*)ptr = size; + ptr = (u8*)ptr + extra_size; + return(ptr); +} + +internal void +base_free__system(void *user_data, void *ptr){ + System_Functions *system = (System_Functions*)user_data; + umem extra_size = 128; + ptr = (u8*)ptr - extra_size; + umem size = *(umem*)ptr; + system->memory_free(ptr, size); +} + +internal Base_Allocator +make_base_allocator_system(System_Functions *system){ + return(make_base_allocator(base_reserve__system, 0, 0, + base_free__system, 0, system)); +} + +internal Arena +make_arena_models(Models *models, umem chunk_size, umem align){ + return(make_arena(&models->allocator, chunk_size, align)); +} + +internal Arena +make_arena_models(Models *models, umem chunk_size){ + return(make_arena(&models->allocator, chunk_size, 8)); +} + +internal Arena +make_arena_models(Models *models){ + return(make_arena(&models->allocator, KB(16), 8)); +} + +//////////////////////////////// + internal App_Vars* app_setup_memory(System_Functions *system, Application_Memory *memory){ - Partition _partition = make_part(memory->vars_memory, memory->vars_memory_size); - App_Vars *vars = push_array(&_partition, App_Vars, 1); - Assert(vars != 0); - memset(vars, 0, sizeof(*vars)); - vars->models.mem.part = _partition; + Cursor cursor = make_cursor(memory->vars_memory, memory->vars_memory_size); + App_Vars *vars = push_array_zero(&cursor, App_Vars, 1); + vars->models.allocator = make_base_allocator_system(system); + vars->models.mem.arena = make_arena(&vars->models.allocator); heap_init(&vars->models.mem.heap); heap_extend(&vars->models.mem.heap, memory->target_memory, memory->target_memory_size); return(vars); @@ -813,18 +858,18 @@ App_Init_Sig(app_init){ models->keep_playing = true; app_links_init(system, &models->app_links, memory->user_memory, memory->user_memory_size); - models->custom_layer_arena = make_arena(&models->app_links); + models->custom_layer_arena = make_arena_models(models); models->config_api = api; models->app_links.cmd_context = models; - Partition *part = &models->mem.part; + Arena *arena = &models->mem.arena; // NOTE(allen): live set { models->live_set.count = 0; models->live_set.max = MAX_VIEWS; - models->live_set.views = push_array(part, View, models->live_set.max); + models->live_set.views = push_array(arena, View, models->live_set.max); //dll_init_sentinel models->live_set.free_sentinel.next = &models->live_set.free_sentinel; @@ -843,7 +888,7 @@ App_Init_Sig(app_init){ { umem memsize = KB(8); - void *mem = push_array(part, u8, (i32)memsize); + void *mem = push_array(arena, u8, (i32)memsize); parse_context_init_memory(&models->parse_context_memory, mem, memsize); parse_context_add_default(&models->parse_context_memory, &models->mem.heap); } @@ -860,7 +905,7 @@ App_Init_Sig(app_init){ dynamic_workspace_init(&models->mem.heap, &models->lifetime_allocator, DynamicWorkspace_Global, 0, &models->dynamic_workspace); // NOTE(allen): file setup - working_set_init(system, &models->working_set, part, &vars->models.mem.heap); + working_set_init(system, &models->working_set, arena, &vars->models.mem.heap); models->working_set.default_display_width = DEFAULT_DISPLAY_WIDTH; models->working_set.default_minimum_base_display_width = DEFAULT_MINIMUM_BASE_DISPLAY_WIDTH; @@ -876,8 +921,8 @@ App_Init_Sig(app_init){ // TODO(allen): do(better clipboard allocation) if (clipboard.str != 0){ - String *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, clipboard.size); - copy(dest, make_string((char*)clipboard.str, clipboard.size)); + String_Const_u8 *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, clipboard.size); + block_copy(dest->str, clipboard.str, clipboard.size); } // NOTE(allen): style setup @@ -887,7 +932,7 @@ App_Init_Sig(app_init){ // NOTE(allen): title space models->has_new_title = true; models->title_capacity = KB(4); - models->title_space = push_array(part, char, models->title_capacity); + models->title_space = push_array(arena, char, models->title_capacity); { String builder = make_string_cap(models->title_space, 0, models->title_capacity); append(&builder, WINDOW_NAME); @@ -900,21 +945,21 @@ App_Init_Sig(app_init){ // NOTE(allen): init baked in buffers File_Init init_files[] = { - { make_lit_string("*messages*"), &models->message_buffer, true , }, - { make_lit_string("*scratch*"), &models->scratch_buffer, false, }, + { string_u8_litinit("*messages*"), &models->message_buffer, true , }, + { string_u8_litinit("*scratch*"), &models->scratch_buffer, false, }, }; Heap *heap = &models->mem.heap; for (i32 i = 0; i < ArrayCount(init_files); ++i){ Editing_File *file = working_set_alloc_always(&models->working_set, heap, &models->lifetime_allocator); - buffer_bind_name(models, heap, part, &models->working_set, file, init_files[i].name); + buffer_bind_name(models, heap, arena, &models->working_set, file, init_files[i].name); if (init_files[i].ptr != 0){ *init_files[i].ptr = file; } File_Attributes attributes = {}; - file_create_from_string(system, models, file, make_lit_string(""), attributes); + file_create_from_string(system, models, file, SCu8(), attributes); if (init_files[i].read_only){ file->settings.read_only = true; history_free(&models->mem.heap, &file->state.history); @@ -927,7 +972,7 @@ App_Init_Sig(app_init){ // NOTE(allen): setup first panel { - Panel *panel = layout_initialize(part, &models->layout); + Panel *panel = layout_initialize(arena, &models->layout); View *new_view = live_set_alloc_view(&models->mem.heap, &models->lifetime_allocator, &models->live_set, panel); view_set_file(system, models, new_view, models->scratch_buffer); } @@ -953,10 +998,10 @@ App_Step_Sig(app_step){ models->input = input; // NOTE(allen): OS clipboard event handling - String clipboard = input->clipboard; + String_Const_u8 clipboard = input->clipboard; if (clipboard.str != 0){ - String *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, clipboard.size); - dest->size = eol_convert_in(dest->str, clipboard.str, clipboard.size); + String_Const_u8 *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, clipboard.size); + dest->size = eol_convert_in((char*)dest->str, (char*)clipboard.str, (i32)clipboard.size); if (input->clipboard_changed && models->clipboard_change != 0){ models->clipboard_change(&models->app_links, *dest, ClipboardFlag_FromOS); } @@ -968,20 +1013,20 @@ App_Step_Sig(app_step){ i32 size = 0; i32 buffer_size = KB(32); - Partition *part = &models->mem.part; - Temp_Memory temp = begin_temp_memory(part); - char *buffer = push_array(part, char, buffer_size); + Arena *scratch = &models->mem.arena; + Temp_Memory temp = begin_temp(scratch); + char *buffer = push_array(scratch, char, buffer_size); u32 unmark_top = 0; - u32 unmark_max = (8 << 10); - Editing_File **unmark = (Editing_File**)push_array(part, Editing_File*, unmark_max); + u32 unmark_max = Thousand(8); + Editing_File **unmark = (Editing_File**)push_array(scratch, Editing_File*, unmark_max); Working_Set *working_set = &models->working_set; for (;system->get_file_change(buffer, buffer_size, &mem_too_small, &size);){ Assert(!mem_too_small); Editing_File_Name canon = {}; - if (get_canon_name(system, make_string(buffer, size), &canon)){ - Editing_File *file = working_set_contains_canon(working_set, canon.name); + if (get_canon_name(system, SCu8(buffer, size), &canon)){ + Editing_File *file = working_set_contains_canon(working_set, string_from_file_name(&canon)); if (file != 0){ if (file->state.ignore_behind_os == 0){ file_add_dirty_flag(file, DirtyState_UnloadedChanges); @@ -1001,7 +1046,7 @@ App_Step_Sig(app_step){ unmark[i]->state.ignore_behind_os = 0; } - end_temp_memory(temp); + end_temp(temp); } // NOTE(allen): reorganizing panels on screen @@ -1012,10 +1057,10 @@ App_Step_Sig(app_step){ // NOTE(allen): update child processes f32 dt = input->dt; if (dt > 0){ - Partition *scratch = &models->mem.part; + Arena *scratch = &models->mem.arena; Child_Process_Container *child_processes = &models->child_processes; - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); Child_Process **processes_to_free = push_array(scratch, Child_Process*, child_processes->active_child_process_count); i32 processes_to_free_count = 0; @@ -1065,7 +1110,7 @@ App_Step_Sig(app_step){ child_process_free(child_processes, processes_to_free[i]->id); } - end_temp_memory(temp); + end_temp(temp); } // NOTE(allen): input filter and simulated events @@ -1361,7 +1406,9 @@ App_Step_Sig(app_step){ File_Edit_Finished_Function *hook_file_edit_finished = models->hook_file_edit_finished; if (hook_file_edit_finished != 0){ Working_Set *working_set = &models->working_set; - if (working_set->edit_finished_list.next != &working_set->edit_finished_list){ + if (working_set->edit_finished_count > 0){ + Assert(working_set->edit_finished_list_first != 0); + Assert(working_set->edit_finished_list_last != 0); b32 trigger_hook = false; u32 elapse_time = models->edit_finished_hook_repeat_speed; @@ -1381,24 +1428,21 @@ App_Step_Sig(app_step){ trigger_hook = true; } if (trigger_hook){ - Partition *scratch = &models->mem.part; + Arena *scratch = &models->mem.arena; + Temp_Memory temp = begin_temp(scratch); + Node *first = working_set->edit_finished_list_first; - Temp_Memory temp = begin_temp_memory(scratch); - Node *first = working_set->edit_finished_list.next; - Node *stop = &working_set->edit_finished_list; - - Editing_File **file_ptrs = push_array(scratch, Editing_File*, 0); + i32 max_id_count = working_set->edit_finished_count; + Editing_File **file_ptrs = push_array(scratch, Editing_File*, max_id_count); + Buffer_ID *ids = push_array(scratch, Buffer_ID, max_id_count); + i32 id_count = 0; for (Node *node = first; - node != stop; + node != 0; node = node->next){ - Editing_File **file_ptr = push_array(scratch, Editing_File*, 1); - *file_ptr = CastFromMember(Editing_File, edit_finished_mark_node, node); - } - i32 id_count = (i32)(push_array(scratch, Editing_File*, 0) - file_ptrs); - - Buffer_ID *ids = push_array(scratch, Buffer_ID, id_count); - for (i32 i = 0; i < id_count; i += 1){ - ids[i] = file_ptrs[i]->id.id; + Editing_File *file_ptr = CastFromMember(Editing_File, edit_finished_mark_node, node); + file_ptrs[id_count] = file_ptr; + ids[id_count] = file_ptr->id.id; + id_count += 1; } working_set->do_not_mark_edits = true; @@ -1406,13 +1450,15 @@ App_Step_Sig(app_step){ working_set->do_not_mark_edits = false; for (i32 i = 0; i < id_count; i += 1){ - block_zero_struct(&file_ptrs[i]->edit_finished_mark_node); + file_ptrs[i]->edit_finished_marked = false; } - dll_init_sentinel(&working_set->edit_finished_list); + working_set->edit_finished_list_first = 0; + working_set->edit_finished_list_last = 0; + working_set->edit_finished_count = 0; working_set->time_of_next_edit_finished_signal = 0; - end_temp_memory(temp); + end_temp(temp); } } } diff --git a/4ed.h b/4ed.h index 9602c995..98087b50 100644 --- a/4ed.h +++ b/4ed.h @@ -14,6 +14,7 @@ #define MAX_VIEWS 16 +// TODO(allen): This is DONE! GET RID OF IT NAO! struct Application_Memory{ void *vars_memory; i32 vars_memory_size; @@ -66,7 +67,7 @@ struct Plat_Settings{ }; #define App_Read_Command_Line_Sig(name) \ -i32 name(System_Functions *system, Application_Memory *memory, String current_directory, Plat_Settings *plat_settings, char ***files, i32 **file_count, i32 argc, char **argv) +i32 name(System_Functions *system, Application_Memory *memory, String_Const_u8 current_directory, Plat_Settings *plat_settings, char ***files, i32 **file_count, i32 argc, char **argv) typedef App_Read_Command_Line_Sig(App_Read_Command_Line); @@ -76,7 +77,7 @@ struct Custom_API{ }; #define App_Init_Sig(name) \ -void name(System_Functions *system, Render_Target *target, Application_Memory *memory, String clipboard, String current_directory, Custom_API api) +void name(System_Functions *system, Render_Target *target, Application_Memory *memory, String_Const_u8 clipboard, String_Const_u8 current_directory, Custom_API api) typedef App_Init_Sig(App_Init); @@ -96,7 +97,7 @@ struct Application_Step_Input{ f32 dt; Key_Input_Data keys; Mouse_State mouse; - String clipboard; + String_Const_u8 clipboard; b32 clipboard_changed; b32 trying_to_kill; u32 debug_number; diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 20c4d3c8..21ee5f7f 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -9,25 +9,11 @@ // TOP -#define API_EXPORT - internal b32 access_test(u32 lock_flags, u32 access_flags){ return((lock_flags & ~access_flags) == 0); } -internal b32 -api_string_out(String val, String *out, i32 *required_size_out){ - b32 result = false; - if (required_size_out != 0){ - *required_size_out = val.size; - } - if (out != 0){ - result = append_partial(out, val); - } - return(result); -} - internal b32 api_check_panel(Panel *panel){ b32 result = false; @@ -111,8 +97,14 @@ Context_Get_Arena(Application_Links *app){ return(&models->custom_layer_arena); } +API_EXPORT Base_Allocator* +Context_Get_Base_Allocator(Application_Links *app){ + Models *models = (Models*)app->cmd_context; + return(&models->allocator); +} + API_EXPORT b32 -Create_Child_Process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){ +Create_Child_Process(Application_Links *app, String_Const_u8 path, String_Const_u8 command, Child_Process_ID *child_process_id_out){ Models *models = (Models*)app->cmd_context; System_Functions *system = models->system; return(child_process_call(models, system, path, command, child_process_id_out)); @@ -176,7 +168,7 @@ Child_Process_Get_State(Application_Links *app, Child_Process_ID child_process_i // TODO(allen): redocument API_EXPORT b32 -Clipboard_Post(Application_Links *app, i32 clipboard_id, String string) +Clipboard_Post(Application_Links *app, i32 clipboard_id, String_Const_u8 string) /* DOC_PARAM(clipboard_id, This parameter is set up to prepare for future features, it should always be 0 for now.) DOC_PARAM(str, The str parameter specifies the string to be posted to the clipboard, it need not be null terminated.) @@ -185,8 +177,8 @@ DOC(Stores the string str in the clipboard initially with index 0. Also reports DOC_SEE(The_4coder_Clipboard) */{ Models *models = (Models*)app->cmd_context; - String *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, string.size); - copy(dest, string); + String_Const_u8 *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, (i32)string.size); + block_copy(dest->str, string.str, string.size); models->system->post_clipboard(*dest); return(true); } @@ -205,8 +197,9 @@ DOC_SEE(The_4coder_Clipboard) return(true); } +// TODO(allen): redocument API_EXPORT b32 -Clipboard_Index(Application_Links *app, i32 clipboard_id, i32 item_index, String *string_out, i32 *required_size_out) +Clipboard_Index(Application_Links *app, i32 clipboard_id, i32 item_index, Arena *out, String_Const_u8 *string_out) /* DOC_PARAM(clipboard_id, This parameter is set up to prepare for future features, it should always be 0 for now.) DOC_PARAM(item_index, This parameter specifies which item to read, 0 is the most recent copy, 1 is the second most recent copy, etc.) @@ -220,11 +213,11 @@ it is filled with the first len character of the clipboard contents. The output DOC_SEE(The_4coder_Clipboard) */{ Models *models = (Models*)app->cmd_context; - *required_size_out = 0; - String *str = working_set_clipboard_index(&models->working_set, item_index); + String_Const_u8 *str = working_set_clipboard_index(&models->working_set, item_index); b32 result = false; if (str != 0){ - result = api_string_out(*str, string_out, required_size_out); + *string_out = string_copy(out, *str); + result = true; } return(result); } @@ -290,7 +283,7 @@ DOC_SEE(get_buffer_first) // TODO(allen): redocument API_EXPORT b32 -Get_Buffer_By_Name(Application_Links *app, String name, Access_Flag access, Buffer_ID *buffer_id_out) +Get_Buffer_By_Name(Application_Links *app, String_Const_u8 name, Access_Flag access, Buffer_ID *buffer_id_out) /* DOC_PARAM(name, The name parameter specifies the buffer name to try to get. The string need not be null terminated.) DOC_PARAM(len, The len parameter specifies the length of the name string.) @@ -315,7 +308,7 @@ DOC_SEE(Access_Flag) // TODO(allen): redocument API_EXPORT b32 -Get_Buffer_By_File_Name(Application_Links *app, String file_name, Access_Flag access, Buffer_ID *buffer_id_out) +Get_Buffer_By_File_Name(Application_Links *app, String_Const_u8 file_name, Access_Flag access, Buffer_ID *buffer_id_out) /* DOC_PARAM(name, The name parameter specifies the buffer name to try to get. The string need not be null terminated.) DOC_PARAM(len, The len parameter specifies the length of the name string.) @@ -334,7 +327,7 @@ DOC_SEE(Access_Flag) Editing_File_Name canon = {}; b32 result = false; if (get_canon_name(system, file_name, &canon)){ - Editing_File *file = working_set_contains_canon(working_set, canon.name); + Editing_File *file = working_set_contains_canon(working_set, string_from_file_name(&canon)); if (api_check_buffer(file, access)){ *buffer_id_out = file->id.id; result = true; @@ -372,7 +365,7 @@ DOC_SEE(4coder_Buffer_Positioning_System) // TODO(allen): redocument API_EXPORT b32 -Buffer_Replace_Range(Application_Links *app, Buffer_ID buffer_id, Range range, String string) +Buffer_Replace_Range(Application_Links *app, Buffer_ID buffer_id, Range range, String_Const_u8 string) /* DOC_PARAM(buffer, This parameter specifies the buffer to edit.) DOC_PARAM(start, This parameter specifies absolute position of the first character in the replace range.) @@ -395,7 +388,7 @@ DOC_SEE(4coder_Buffer_Positioning_System) size = buffer_size(&file->state.buffer); if (0 <= range.first && range.first <= range.one_past_last && range.one_past_last <= size){ Edit_Behaviors behaviors = {}; - edit_single(models->system, models, file, range, string, behaviors); + edit_single(models->system, models, file, range, string_old_from_new(string), behaviors); result = true; } } @@ -512,34 +505,37 @@ Buffer_Get_Line_Count(Application_Links *app, Buffer_ID buffer_id, i32 *line_cou } API_EXPORT b32 -Buffer_Get_Base_Buffer_Name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){ +Buffer_Get_Base_Buffer_Name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){ Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; if (api_check_buffer(file)){ - result = api_string_out(file->base_name.name, name_out, required_size_out); + *name_out = string_copy(out, string_from_file_name(&file->base_name)); + result = true; } return(result); } API_EXPORT b32 -Buffer_Get_Unique_Buffer_Name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){ +Buffer_Get_Unique_Buffer_Name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){ Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; if (api_check_buffer(file)){ - result = api_string_out(file->unique_name.name, name_out, required_size_out); + *name_out = string_copy(out, string_from_file_name(&file->unique_name)); + result = true; } return(result); } API_EXPORT b32 -Buffer_Get_File_Name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){ +Buffer_Get_File_Name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){ Models *models = (Models*)app->cmd_context; Editing_File *file = imp_get_file(models, buffer_id); b32 result = false; if (api_check_buffer(file)){ - result = api_string_out(file->canon.name, name_out, required_size_out); + *name_out = string_copy(out, string_from_file_name(&file->canon)); + result = true; } return(result); } @@ -989,7 +985,7 @@ This is useful in cases such as clearing a buffer and refilling it with new cont // TODO(allen): redocument API_EXPORT b32 -Create_Buffer(Application_Links *app, String file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out) +Create_Buffer(Application_Links *app, String_Const_u8 file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out) /* DOC_PARAM(filename, The name of the file to associate to the new buffer.) DOC_PARAM(filename_len, The length of the filename string.) @@ -1013,7 +1009,7 @@ DOC_SEE(Buffer_Create_Flag) // TODO(allen): redocument API_EXPORT b32 -Buffer_Save(Application_Links *app, Buffer_ID buffer_id, String file_name, u32 flags) +Buffer_Save(Application_Links *app, Buffer_ID buffer_id, String_Const_u8 file_name, u32 flags) /* DOC_PARAM(buffer, The buffer parameter specifies the buffer to save to a file.) DOC_PARAM(file_name, The file_name parameter specifies the name of the file to write with the contents of the buffer; it need not be null terminated.) @@ -1037,11 +1033,11 @@ DOC_SEE(Buffer_Save_Flag) } if (!skip_save){ - Partition *part = &models->mem.part; - Temp_Memory temp = begin_temp_memory(part); - String name = push_string(part, file_name); + Arena *scratch = &models->mem.arena; + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 name = string_copy(scratch, file_name); save_file_to_name(system, models, file, name.str); - end_temp_memory(temp); + end_temp(temp); result = true; } } @@ -1079,10 +1075,10 @@ DOC_SEE(Buffer_Identifier) } buffer_unbind_name_low_level(working_set, file); - if (file->canon.name.size != 0){ + if (file->canon.name_size != 0){ buffer_unbind_file(system, working_set, file); } - file_free(system, &models->mem.heap, &models->lifetime_allocator, file); + file_free(system, &models->mem.heap, &models->lifetime_allocator, working_set, file); working_set_free_file(&models->mem.heap, working_set, file); Layout *layout = &models->layout; @@ -1132,14 +1128,14 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl Editing_File *file = imp_get_file(models, buffer_id); Buffer_Reopen_Result result = BufferReopenResult_Failed; if (api_check_buffer(file)){ - if (file->canon.name.str != 0 && file->canon.name.size != 0){ + if (file->canon.name_size > 0){ Plat_Handle handle = {}; - if (system->load_handle(file->canon.name.str, &handle)){ + if (system->load_handle((char*)file->canon.name_space, &handle)){ File_Attributes attributes = system->load_attributes(handle); - Partition *part = &models->mem.part; - Temp_Memory temp = begin_temp_memory(part); - char *file_memory = push_array(part, char, (i32)attributes.size); + Arena *arena = &models->mem.arena; + Temp_Memory temp = begin_temp(arena); + char *file_memory = push_array(arena, char, (i32)attributes.size); if (file_memory != 0){ if (system->load_file(handle, file_memory, (i32)attributes.size)){ @@ -1157,21 +1153,21 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl panel != 0; panel = layout_get_next_open_panel(layout, panel)){ View *view_it = panel->view; - if (view_it->file != file){ - continue; + if (view_it->file == file){ + vptrs[vptr_count] = view_it; + File_Edit_Positions edit_pos = view_get_edit_pos(view_it); + Full_Cursor cursor = file_compute_cursor(system, view_it->file, seek_pos(edit_pos.cursor_pos)); + line_numbers[vptr_count] = cursor.line; + column_numbers[vptr_count] = cursor.character; + view_it->file = models->scratch_buffer; + ++vptr_count; } - vptrs[vptr_count] = view_it; - File_Edit_Positions edit_pos = view_get_edit_pos(view_it); - Full_Cursor cursor = file_compute_cursor(system, view_it->file, seek_pos(edit_pos.cursor_pos)); - line_numbers[vptr_count] = cursor.line; - column_numbers[vptr_count] = cursor.character; - view_it->file = models->scratch_buffer; - ++vptr_count; } - file_free(system, &models->mem.heap, &models->lifetime_allocator, file); - working_set_file_default_settings(&models->working_set, file); - file_create_from_string(system, models, file, make_string(file_memory, (i32)attributes.size), attributes); + Working_Set *working_set = &models->working_set; + file_free(system, &models->mem.heap, &models->lifetime_allocator, working_set, file); + working_set_file_default_settings(working_set, file); + file_create_from_string(system, models, file, SCu8(file_memory, attributes.size), attributes); for (i32 i = 0; i < vptr_count; ++i){ view_set_file(system, models, vptrs[i], file); @@ -1191,7 +1187,7 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl system->load_close(handle); } - end_temp_memory(temp); + end_temp(temp); } } } @@ -1515,7 +1511,7 @@ Panel_Set_Split(Application_Links *app, Panel_ID panel_id, Panel_Split_Kind kind default: { - print_message(app, make_lit_string("Invalid split kind passed to panel_set_split, no change made to view layout")); + print_message(app, string_u8_litexpr("Invalid split kind passed to panel_set_split, no change made to view layout")); }break; } layout_propogate_sizes_down_from_node(layout, panel); @@ -2170,7 +2166,7 @@ get_lifetime_object_from_workspace(Dynamic_Workspace *workspace){ }break; default: { - InvalidCodePath; + InvalidPath; }break; } return(result); @@ -2188,12 +2184,21 @@ https://4coder.handmade.network/blogs/p/3412-new_features_p3__memory_management_ { Models *models = (Models*)app->cmd_context; Lifetime_Allocator *lifetime_allocator = &models->lifetime_allocator; - Partition *scratch = &models->mem.part; + Arena *scratch = &models->mem.arena; - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); + + // TODO(allen): revisit this + struct Node_Ptr{ + Node_Ptr *next; + Lifetime_Object *object_ptr; + }; + + Node_Ptr *first = 0; + Node_Ptr *last = 0; + i32 member_count = 0; b32 filled_array = true; - Lifetime_Object **object_ptr_array = push_array(scratch, Lifetime_Object*, 0); for (i32 i = 0; i < count; i += 1){ Dynamic_Workspace *workspace = get_dynamic_workspace(models, scopes[i]); if (workspace == 0){ @@ -2213,40 +2218,51 @@ https://4coder.handmade.network/blogs/p/3412-new_features_p3__memory_management_ { Lifetime_Object *object = get_lifetime_object_from_workspace(workspace); Assert(object != 0); - Lifetime_Object **new_object_ptr = push_array(scratch, Lifetime_Object*, 1); - *new_object_ptr = object; + Node_Ptr *new_node = push_array(scratch, Node_Ptr, 1); + sll_queue_push(first, last, new_node); + new_node->object_ptr = object; + member_count += 1; }break; case DynamicWorkspace_Intersected: { Lifetime_Key *key = (Lifetime_Key*)workspace->user_back_ptr; if (lifetime_key_check(lifetime_allocator, key)){ - i32 member_count = key->count; + i32 key_member_count = key->count; Lifetime_Object **key_member_ptr = key->members; - for (i32 j = 0; j < member_count; j += 1, key_member_ptr += 1){ - Lifetime_Object **new_object_ptr = push_array(scratch, Lifetime_Object*, 1); - *new_object_ptr = *key_member_ptr; + for (i32 j = 0; j < key_member_count; j += 1, key_member_ptr += 1){ + Node_Ptr *new_node = push_array(scratch, Node_Ptr, 1); + sll_queue_push(first, last, new_node); + new_node->object_ptr = *key_member_ptr; + member_count += 1; } } }break; default: { - InvalidCodePath; + InvalidPath; }break; } } Managed_Scope result = 0; if (filled_array){ - i32 member_count = (i32)(push_array(scratch, Lifetime_Object*, 0) - object_ptr_array); + Lifetime_Object **object_ptr_array = push_array(scratch, Lifetime_Object*, member_count); + i32 index = 0; + for (Node_Ptr *node = first; + node != 0; + node = node->next){ + object_ptr_array[index] = node->object_ptr; + index += 1; + } member_count = lifetime_sort_and_dedup_object_set(object_ptr_array, member_count); Heap *heap = &models->mem.heap; Lifetime_Key *key = lifetime_get_or_create_intersection_key(heap, lifetime_allocator, object_ptr_array, member_count); result = (Managed_Scope)key->dynamic_workspace.scope_id; } - end_temp_memory(temp); + end_temp(temp); return(result); } @@ -2303,10 +2319,9 @@ DOC_SEE(managed_variable_create_or_get_id) */ { Models *models = (Models*)app->cmd_context; - String name = make_string_slowly(null_terminated_name); Heap *heap = &models->mem.heap; Dynamic_Variable_Layout *layout = &models->variable_layout; - return(dynamic_variables_create(heap, layout, name, default_value)); + return(dynamic_variables_create(heap, layout, SCu8(null_terminated_name), default_value)); } API_EXPORT Managed_Variable_ID @@ -2319,9 +2334,8 @@ DOC_SEE(managed_variable_create_or_get_id) */ { Models *models = (Models*)app->cmd_context; - String name = make_string_slowly(null_terminated_name); Dynamic_Variable_Layout *layout = &models->variable_layout; - return(dynamic_variables_lookup(layout, name)); + return(dynamic_variables_lookup(layout, SCu8(null_terminated_name))); } API_EXPORT Managed_Variable_ID @@ -2336,10 +2350,9 @@ DOC_SEE(managed_variable_get_id) */ { Models *models = (Models*)app->cmd_context; - String name = make_string_slowly(null_terminated_name); Heap *heap = &models->mem.heap; Dynamic_Variable_Layout *layout = &models->variable_layout; - return(dynamic_variables_lookup_or_create(heap, layout, name, default_value)); + return(dynamic_variables_lookup_or_create(heap, layout, SCu8(null_terminated_name), default_value)); } internal b32 @@ -2551,9 +2564,9 @@ DOC_SEE(Marker_Visual_Take_Rule) b32 result = false; if (data != 0){ Assert(take_rule.take_count_per_step != 0); - take_rule.first_index = clamp_bottom(0, take_rule.first_index); - take_rule.take_count_per_step = clamp_bottom(1, take_rule.take_count_per_step); - take_rule.step_stride_in_marker_count = clamp_bottom(take_rule.take_count_per_step, take_rule.step_stride_in_marker_count); + take_rule.first_index = clamp_bot(0, take_rule.first_index); + take_rule.take_count_per_step = clamp_bot(1, take_rule.take_count_per_step); + take_rule.step_stride_in_marker_count = clamp_bot(take_rule.take_count_per_step, take_rule.step_stride_in_marker_count); data->take_rule = take_rule; if (data->take_rule.maximum_number_of_markers != 0){ i32 whole_steps = take_rule.maximum_number_of_markers/take_rule.take_count_per_step; @@ -2652,8 +2665,9 @@ DOC_RETURN(Returns the number of marker visuals that are currently attached to t return(result); } +// TODO(allen): redocument API_EXPORT Marker_Visual* -Buffer_Markers_Get_Attached_Visual(Application_Links *app, Partition *part, Managed_Object object) +Buffer_Markers_Get_Attached_Visual(Application_Links *app, Arena *arena, Managed_Object object) /* DOC_PARAM(part, The arena to be used to allocate the returned array.) DOC_PARAM(object, The handle to the marker object to be queried.) @@ -2665,7 +2679,7 @@ DOC_RETURN(Pushes an array onto part containing the handle to every marker visua if (object_ptrs.header != 0 && object_ptrs.header->type == ManagedObjectType_Markers){ Managed_Buffer_Markers_Header *markers = (Managed_Buffer_Markers_Header*)object_ptrs.header; i32 count = markers->visual_count; - Marker_Visual *visual = push_array(part, Marker_Visual, count); + Marker_Visual *visual = push_array(arena, Marker_Visual, count); if (visual != 0){ Marker_Visual *v = visual; Managed_Scope scope = object_ptrs.workspace->scope_id; @@ -2958,7 +2972,7 @@ DOC(Stops showing the particular query bar specified by the bar parameter.) } API_EXPORT b32 -Print_Message(Application_Links *app, String message) +Print_Message(Application_Links *app, String_Const_u8 message) /* DOC_PARAM(str, The str parameter specifies the string to post to *messages*; it need not be null terminated.) DOC_PARAM(len, The len parameter specifies the length of the str string.) @@ -2968,130 +2982,13 @@ DOC(This call posts a string to the *messages* buffer.) Editing_File *file = models->message_buffer; b32 result = false; if (file != 0){ - output_file_append(models->system, models, file, message); + output_file_append(models->system, models, file, string_old_from_new(message)); file_cursor_to_end(models->system, models, file); result = true; } return(result); } -#if 0 -//API_EXPORT i32 -Get_Theme_Count(Application_Links *app) -/* -DOC_RETURN(Returns the number of themes that currently exist in the core.) -*/ -{ - Models *models = (Models*)app->cmd_context; - return(models->styles.count); -} - -//API_EXPORT String -Get_Theme_Name(Application_Links *app, struct Partition *arena, i32 index) -/* -DOC_PARAM(arena, The arena which will be used to allocate the returned string.) -DOC_PARAM(index, The index of the theme to query. Index zero always refers to the active theme, all other indices refer to the static copies of available themes.) -DOC_RETURN(On success this call returns a string allocated on arena that is the name of the queried theme, on failure a null string is returned. This call fails when index is not less than the total number of themes, and when there is not enough space in arena to allocate the return string.) -*/ -{ - Models *models = (Models*)app->cmd_context; - Style_Library *library = &models->styles; - String str = {}; - if (0 <= index && index < library->count){ - Style *style = &library->styles[index]; - char *mem = push_array(arena, char, style->name.size + 1); - if (mem != 0){ - str.str = mem; - str.size = style->name.size; - str.memory_size = str.size + 1; - memcpy(str.str, style->name.str, str.size); - str.str[str.size] = 0; - } - } - return(str); -} - -// TODO(allen): redocument -//API_EXPORT b32 -Create_Theme(Application_Links *app, Theme *theme, String theme_name) -/* -DOC_PARAM(theme, The color data of the new theme.) -DOC_PARAM(name, The name of the new theme. This string need not be null terminated.) -DOC_PARAM(len, The length of the name string.) -DOC(This call creates a new theme. If the given name is already the name of a string, the old string will be replaced with the new one. This call does not set the current theme.) -*/{ - Models *models = (Models*)app->cmd_context; - Style_Library *library = &models->styles; - - i32 count = library->count; - Style *destination_style = 0; - Style *style = library->styles + 1; - for (i32 i = 1; i < count; ++i, ++style){ - if (match(style->name, theme_name)){ - destination_style = style; - break; - } - } - - if (destination_style == 0 && library->count < library->max){ - destination_style = &library->styles[library->count++]; - destination_style->name = make_fixed_width_string(destination_style->name_); - copy(&destination_style->name, theme_name); - terminate_with_null(&destination_style->name); - } - - b32 result = false; - if (destination_style != 0){ - block_copy(&destination_style->theme, theme, sizeof(*theme)); - result = true; - } - return(result); -} - -// TODO(allen): redocument -//API_EXPORT b32 -Change_Theme(Application_Links *app, String theme_name) -/* -DOC_PARAM(name, The name parameter specifies the name of the theme to begin using; it need not be null terminated.) -DOC_PARAM(len, The len parameter specifies the length of the name string.) -DOC(This call changes 4coder's color pallet to one of the built in themes.) -*/{ - Models *models = (Models*)app->cmd_context; - Style_Library *styles = &models->styles; - i32 count = styles->count; - b32 result = false; - Style *s = styles->styles + 1; - for (i32 i = 1; i < count; ++i, ++s){ - if (match(s->name, theme_name)){ - styles->styles[0] = *s; - styles->styles[0].name.str = styles->styles[0].name_; - result = true; - break; - } - } - return(result); -} - -//API_EXPORT b32 -Change_Theme_By_Index(Application_Links *app, i32 index) -/* -DOC_PARAM(index, The index parameter specifies the index of theme to begin using.) -DOC_RETURN(Returns non-zero on success and zero on failure. This call fails when index is not less than the total number of themes.) -*/ -{ - Models *models = (Models*)app->cmd_context; - Style_Library *styles = &models->styles; - i32 count = styles->count; - b32 result = false; - if (0 <= index && index < count){ - styles->styles[0] = styles->styles[index]; - styles->styles[0].name.str = styles->styles[0].name_; - result = true; - } - return(result); -} -#endif - API_EXPORT Face_ID Get_Largest_Face_ID(Application_Links *app) /* @@ -3151,8 +3048,8 @@ buffer_history__fill_record_info(Record *record, Record_Info *out){ switch (out->kind){ case RecordKind_Single: { - out->single.string_forward = make_string(record->single.str_forward , record->single.length_forward ); - out->single.string_backward = make_string(record->single.str_backward, record->single.length_backward); + out->single.string_forward = SCu8(record->single.str_forward , record->single.length_forward ); + out->single.string_backward = SCu8(record->single.str_backward, record->single.length_backward); out->single.first = record->single.first; }break; case RecordKind_Group: @@ -3161,7 +3058,7 @@ buffer_history__fill_record_info(Record *record, Record_Info *out){ }break; default: { - InvalidCodePath; + InvalidPath; }break; } } @@ -3214,9 +3111,14 @@ Buffer_History_Get_Group_Sub_Record(Application_Links *app, Buffer_ID buffer_id, if (0 < index){ Record *record = history_get_record(history, index); if (record->kind == RecordKind_Group){ - record = history_get_sub_record(record, sub_index); - buffer_history__fill_record_info(record, record_out); - result = true; + record = history_get_sub_record(record, sub_index + 1); + if (record != 0){ + buffer_history__fill_record_info(record, record_out); + result = true; + } + else{ + record_out->error = RecordError_SubIndexOutOfBounds; + } } else{ record_out->error = RecordError_WrongRecordTypeAtIndex; @@ -3276,12 +3178,12 @@ Buffer_History_Merge_Record_Range(Application_Links *app, Buffer_ID buffer_id, H if (file != 0 && history_is_activated(&file->state.history)){ History *history = &file->state.history; i32 max_index = history_get_record_count(history); - first_index = clamp_bottom(1, first_index); + first_index = clamp_bot(1, first_index); if (first_index <= last_index && last_index <= max_index){ i32 current_index = file->state.current_record_index; if (first_index <= current_index && current_index < last_index){ System_Functions *system = models->system; - u32 in_range_handler = flags & (bit_0 | bit_1); + u32 in_range_handler = flags & bitmask_2; switch (in_range_handler){ case RecordMergeFlag_StateInRange_MoveStateForward: { @@ -3302,7 +3204,7 @@ Buffer_History_Merge_Record_Range(Application_Links *app, Buffer_ID buffer_id, H } } if (first_index < last_index){ - history_merge_records(&models->mem.part, &models->mem.heap, history, first_index, last_index); + history_merge_records(&models->mem.arena, &models->mem.heap, history, first_index, last_index); } if (current_index >= last_index){ current_index -= (last_index - first_index); @@ -3641,7 +3543,7 @@ Finalize_Color(Application_Links *app, int_color color){ // TODO(allen): redocument API_EXPORT b32 -Get_Hot_Directory(Application_Links *app, String *out, i32 *required_size_out) +Get_Hot_Directory(Application_Links *app, Arena *out, String_Const_u8 *out_directory) /* DOC_PARAM(out, On success this character buffer is filled with the 4coder 'hot directory'.) DOC_PARAM(capacity, Specifies the capacity in bytes of the of the out buffer.) @@ -3652,12 +3554,13 @@ DOC_SEE(directory_set_hot) Models *models = (Models*)app->cmd_context; Hot_Directory *hot = &models->hot_directory; hot_directory_clean_end(hot); - return(api_string_out(hot->string, out, required_size_out)); + *out_directory = string_copy(out, SCu8(hot->string_space, hot->string_size)); + return(true); } // TODO(allen): redocument API_EXPORT b32 -Set_Hot_Directory(Application_Links *app, String string) +Set_Hot_Directory(Application_Links *app, String_Const_u8 string) /* DOC_PARAM(str, The new value of the hot directory. This does not need to be a null terminated string.) DOC_PARAM(len, The length of str in bytes.) @@ -3668,7 +3571,7 @@ DOC_SEE(directory_get_hot) Models *models = (Models*)app->cmd_context; Hot_Directory *hot = &models->hot_directory; b32 success = false; - if (string.size < hot->string.memory_size){ + if (string.size < sizeof(hot->string_space)){ hot_directory_set(models->system, hot, string); success = true; } @@ -3677,7 +3580,7 @@ DOC_SEE(directory_get_hot) // TODO(allen): redocument API_EXPORT b32 -Get_File_List(Application_Links *app, String directory, File_List *list_out) +Get_File_List(Application_Links *app, String_Const_u8 directory, File_List *list_out) /* DOC_PARAM(dir, This parameter specifies the directory whose files will be enumerated in the returned list; it need not be null terminated.) DOC_PARAM(len, This parameter the length of the dir string.) @@ -3686,15 +3589,23 @@ DOC_SEE(File_List) */{ Models *models = (Models*)app->cmd_context; System_Functions *system = models->system; - Partition *part = &models->mem.part; block_zero_struct(list_out); Editing_File_Name canon = {}; b32 result = false; if (get_canon_name(system, directory, &canon)){ - Temp_Memory temp = begin_temp_memory(part); - String str = push_string(part, canon.name.str, canon.name.size); - system->set_file_list(list_out, str.str, 0, 0, 0); - end_temp_memory(temp); + Arena *scratch = &models->mem.arena; + Temp_Memory temp = begin_temp(scratch); + char *str = 0; + if (canon.name_size < sizeof(canon.name_space)){ + canon.name_space[canon.name_size] = 0; + str = (char*)canon.name_space; + } + else{ + String_Const_u8 s = string_copy(scratch, string_from_file_name(&canon)); + str = (char*)s.str; + } + system->set_file_list(list_out, str, 0, 0, 0); + end_temp(temp); result = true; } return(result); @@ -3767,17 +3678,26 @@ DOC_SEE(memory_allocate) } API_EXPORT b32 -File_Get_Attributes(Application_Links *app, String file_name, File_Attributes *attributes_out) +File_Get_Attributes(Application_Links *app, String_Const_u8 file_name, File_Attributes *attributes_out) { Models *models = (Models*)app->cmd_context; *attributes_out = models->system->quick_file_attributes(file_name); return(attributes_out->last_write_time > 0); } +// TODO(allen): remove this nonsense and make a real API here instead. +// TODO(allen): remove this nonsense and make a real API here instead. +// TODO(allen): remove this nonsense and make a real API here instead. +// TODO(allen): remove this nonsense and make a real API here instead. +// TODO(allen): remove this nonsense and make a real API here instead. +// TODO(allen): remove this nonsense and make a real API here instead. +// TODO(allen): remove this nonsense and make a real API here instead. +// TODO(allen): remove this nonsense and make a real API here instead. +// TODO(allen): remove this nonsense and make a real API here instead. // TODO(allen): remove this nonsense and make a real API here instead. // TODO(allen): redocument API_EXPORT b32 -Directory_CD(Application_Links *app, String *directory, String relative_path) +Directory_CD(Application_Links *app, String_Const_u8 directory, String_Const_u8 relative_path, Arena *out, String_Const_u8 *directory_out) /* DOC_PARAM(dir, This parameter provides a character buffer that stores a directory; it need not be null terminated.) DOC_PARAM(len, This parameter specifies the length of the dir string.) @@ -3791,13 +3711,19 @@ This call succeeds if the new directory exists and it fits inside the dir buffer For instance if dir contains "C:/Users/MySelf" and rel is "Documents" the buffer will contain "C:/Users/MySelf/Documents" and len will contain the length of that string. This call can also be used with rel set to ".." to traverse to parent folders. )*/{ Models *models = (Models*)app->cmd_context; - return(models->system->directory_cd(directory->str, &directory->size, directory->memory_size, - relative_path.str,relative_path.size)); + i32 memory_size = (i32)(directory.size + relative_path.size + 2); + char *memory = push_array(out, char, memory_size); + i32 size = (i32)directory.size; + block_copy(memory, directory.str, directory.size); + b32 result = models->system->directory_cd(memory, &size, memory_size, + (char*)relative_path.str, (i32)relative_path.size); + *directory_out = SCu8(memory, size); + return(result); } // TODO(allen): redocument API_EXPORT b32 -Get_4ed_Path(Application_Links *app, String *path_out, i32 *required_size_out) +Get_4ed_Path(Application_Links *app, Arena *out, String_Const_u8 *path_out) /* DOC_PARAM(out, This parameter provides a character buffer that receives the path to the 4ed executable file.) DOC_PARAM(capacity, This parameter specifies the maximum capacity of the out buffer.) @@ -3807,15 +3733,10 @@ DOC_RETURN(This call returns non-zero on success.) System_Functions *system = models->system; // TODO(allen): rewrite this with a better OS layer API i32 required_size = system->get_4ed_path(0, 0); - *required_size_out = required_size; - i32 remaining_size = path_out->memory_size - path_out->size; - b32 result = false; - if (required_size <= remaining_size){ - *required_size_out = system->get_4ed_path(path_out->str + path_out->size, remaining_size); - path_out->size += required_size; - result = true; - } - return(result); + char *memory = push_array(out, char, required_size + 1); + required_size = system->get_4ed_path(memory, required_size); + *path_out = SCu8(memory, required_size); + return(true); } // TODO(allen): do(add a "shown but auto-hides on timer" setting for cursor show type) @@ -3845,7 +3766,7 @@ DOC(This call tells 4coder to set the full_screen mode. The change to full scre Models *models = (Models*)app->cmd_context; b32 success = models->system->set_fullscreen(full_screen); if (!success){ - print_message(app, make_lit_string("ERROR: Failed to go fullscreen.\n")); + print_message(app, string_u8_litexpr("ERROR: Failed to go fullscreen.\n")); } return(success); } @@ -3875,20 +3796,18 @@ To make send_exit_signal exit no matter what, setup your hook in such a way that // TODO(allen): redocument API_EXPORT b32 -Set_Window_Title(Application_Links *app, String title) +Set_Window_Title(Application_Links *app, String_Const_u8 title) /* DOC_PARAM(title, A null terminated string indicating the new title for the 4coder window.) DOC(Sets 4coder's window title to the specified title string.) */{ Models *models = (Models*)app->cmd_context; models->has_new_title = true; - String dst = make_string_cap(models->title_space, 0, models->title_capacity); - b32 result = false; - if (append(&dst, title)){ - terminate_with_null(&dst); - result = true; - } - return(result); + umem cap_before_null = (umem)(models->title_capacity - 1); + umem copy_size = clamp_top(title.size, cap_before_null); + block_copy(models->title_space, title.str, copy_size); + models->title_space[copy_size] = 0; + return(true); } API_EXPORT Microsecond_Time_Stamp @@ -3971,7 +3890,7 @@ draw_helper__screen_space_to_view_space(View *view, f32_Rect rect){ // To make text scroll with the buffer users should read the view's scroll position and subtract it first. API_EXPORT Vec2 -Draw_String(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta) +Draw_String(Application_Links *app, Face_ID font_id, String_Const_u8 str, Vec2 point, int_color color, u32 flags, Vec2 delta) { Vec2 result = point; Models *models = (Models*)app->cmd_context; @@ -3990,7 +3909,7 @@ Draw_String(Application_Links *app, Face_ID font_id, String str, Vec2 point, int } API_EXPORT f32 -Get_String_Advance(Application_Links *app, Face_ID font_id, String str) +Get_String_Advance(Application_Links *app, Face_ID font_id, String_Const_u8 str) { Models *models = (Models*)app->cmd_context; return(font_string_width(models->system, models->target, font_id, str)); @@ -4160,11 +4079,11 @@ Compute_Render_Layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_ f32 smallest_char_width = 6.f; f32 smallest_char_height = 8.f; i32 max = (i32)(layout_dim.x*layout_dim.y/(smallest_char_width*smallest_char_height))*2; - if (view->layout_arena.app == 0){ - view->layout_arena = make_arena(app); + if (view->layout_arena.base_allocator == 0){ + view->layout_arena = make_arena_app_links(app); } else{ - arena_release_all(&view->layout_arena); + linalloc_clear(&view->layout_arena); } Buffer_Render_Item *items = push_array(&view->layout_arena, Buffer_Render_Item, max); @@ -4172,13 +4091,6 @@ Compute_Render_Layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_ Face_ID font_id = file->settings.font_id; Font_Pointers font = system->font.get_pointers_by_id(font_id); -#if 0 - File_Edit_Positions edit_pos = view_get_edit_pos(view); - f32 scroll_x = edit_pos.scroll.scroll_x; - f32 scroll_y = edit_pos.scroll.scroll_y; - - Full_Cursor render_cursor = view_get_render_cursor(system, view); -#else Full_Cursor intermediate_cursor = file_compute_cursor(system, file, seek_line_char(buffer_point.line_number, 1)); f32 scroll_x = buffer_point.pixel_shift.x; f32 scroll_y = intermediate_cursor.wrapped_y; @@ -4187,7 +4099,6 @@ Compute_Render_Layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_ } scroll_y += buffer_point.pixel_shift.y; Full_Cursor render_cursor = file_get_render_cursor(system, file, scroll_y); -#endif i32 item_count = 0; i32 end_pos = 0; @@ -4288,7 +4199,7 @@ Draw_Render_Layout(Application_Links *app, View_ID view_id){ render_loaded_file_in_view__inner(models, models->target, view, view->render.buffer_rect, view->render.cursor, view->render.range, view->render.items, view->render.item_count); - arena_release_all(&view->layout_arena); + linalloc_clear(&view->layout_arena); } } @@ -4322,7 +4233,7 @@ Animate_In_N_Milliseconds(Application_Links *app, u32 n) // TODO(casey): Allen, this routine is very intricate and needs to be tested thoroughly before mainlining. I've only done cursory testing on it and have probably missed bugs that only occur in highly segmented buffers. // TODO(casey): I think this routine could potentially be simplified by making it into something that always works with a partial match list, where the partial matches have 0 characters matched, and they just get moved forward as they go. This would solve the duplicate code problem the routine currently has where it does the same thing in its two halves, but slightly differently. API_EXPORT Found_String_List -Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String key, Partition *memory) +Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String_Const_u8 key, Arena *arena) { Found_String_List result = {}; @@ -4354,7 +4265,7 @@ Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 s while(*partial) { Found_String *check = *partial; - i32 trailing_char_at = ((check->location.start + key.size) - check->location.end); + i32 trailing_char_at = ((check->location.start + (i32)key.size) - check->location.end); i32 remaining = trailing_char_at; b32 valid = true; b32 full = true; @@ -4428,7 +4339,7 @@ Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 s if(remaining >= key.size) { full = true; - remaining = key.size; + remaining = (i32)key.size; } u32 exact_matched = FoundString_Sensitive; @@ -4461,7 +4372,7 @@ Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 s } else { - found = push_array(memory, Found_String, 1); + found = push_array(arena, Found_String, 1); } if(found) @@ -4475,7 +4386,7 @@ Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 s // NOTE(casey): Although technically "full matches" are full, we haven't yet checked the trailing edge for tokenization, // so we need to shunt to partial in the cases where we _can't_ check the overhanging character. - i32 trailing_char_at = (at + key.size); + i32 trailing_char_at = (at + (i32)key.size); full = full && (trailing_char_at < size); if(full) diff --git a/4ed_app_models.h b/4ed_app_models.h index d9b34498..42bb88ef 100644 --- a/4ed_app_models.h +++ b/4ed_app_models.h @@ -28,6 +28,7 @@ struct App_Settings{ }; struct Models{ + Base_Allocator allocator; Mem_Options mem; App_Settings settings; @@ -168,6 +169,7 @@ struct Consumption_Record{ char consumer[32]; }; +// TODO(allen): GET RID OF IT! struct App_Vars{ Models models; App_State state; @@ -188,7 +190,7 @@ struct Command_In{ }; struct File_Init{ - String name; + String_Const_u8 name; Editing_File **ptr; b32 read_only; }; diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index e18bb960..ef3d6597 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -9,17 +9,19 @@ // TOP +//#define REMOVE_OLD_STRING + // TODO(allen): get away from string.h #include #include "4coder_API/4coder_custom.h" -#include "4ed_defines.h" -//#include "4ed_math.h" +#include "4coder_base_types.h" #include "4ed_font.h" #include "4ed_system.h" -#define PREFERRED_ALIGNMENT 8 +#include "4coder_base_types.cpp" +#include "4coder_app_links_allocator.cpp" #include "4coder_lib/4coder_arena.cpp" #include "4coder_lib/4coder_heap.cpp" @@ -28,8 +30,9 @@ #include "4coder_lib/4coder_table.h" #include "4coder_lib/4coder_utf8.h" +// TODO(allen): stop this nonsense struct Mem_Options{ - Partition part; + Arena arena; Heap heap; }; diff --git a/4ed_buffer.cpp b/4ed_buffer.cpp index 4866092a..3d9edb32 100644 --- a/4ed_buffer.cpp +++ b/4ed_buffer.cpp @@ -290,25 +290,22 @@ buffer_size(Gap_Buffer *buffer){ } internal Gap_Buffer_Init -buffer_begin_init(Gap_Buffer *buffer, char *data, i32 size){ +buffer_begin_init(Gap_Buffer *buffer, u8 *data, umem size){ Gap_Buffer_Init init; init.buffer = buffer; - init.data = data; - init.size = size; + init.data = (char*)data; + init.size = (i32)size; return(init); } -internal i32 +internal b32 buffer_init_need_more(Gap_Buffer_Init *init){ - i32 result = 1; - if (init->buffer->data) result = 0; - return(result); + return(init->buffer->data == 0); } internal i32 buffer_init_page_size(Gap_Buffer_Init *init){ - i32 result = init->size * 2; - return(result); + return(init->size * 2); } internal void @@ -319,13 +316,13 @@ buffer_init_provide_page(Gap_Buffer_Init *init, void *page, i32 page_size){ } internal b32 -buffer_end_init(Gap_Buffer_Init *init, void *scratch, i32 scratch_size){ +buffer_end_init(Gap_Buffer_Init *init){ Gap_Buffer *buffer = init->buffer; b32 result = false; - if (buffer->data && buffer->max >= init->size){ + if (buffer->data != 0 && buffer->max >= init->size){ i32 size = init->size; - i32 size2 = size >> 1; + i32 size2 = (size >> 1); i32 osize1 = size - size2; i32 size1 = osize1; @@ -423,12 +420,11 @@ buffer_replace_range_compute_shift(i32 start, i32 end, i32 len){ return(len - (end - start)); } -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){ +internal b32 +buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len, i32 shift_amount, i32 *request_amount){ char *data = buffer->data; i32 size = buffer_size(buffer); - i32 result = false; + b32 result = false; i32 move_size = 0; Assert(0 <= start); @@ -458,22 +454,15 @@ buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len, Assert(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max); } else{ - *request_amount = l_round_up_i32(2*(shift_amount + size), 4 << 10); + *request_amount = round_up_i32(2*(shift_amount + size), KB(4)); result = true; } return(result); } -// TODO(allen): do(optimize Gap_Buffer batch edit) -// Now that we are just using Gap_Buffer we could afford to improve -// this for the Gap_Buffer's behavior. - -// TODO(allen): This now relies on Edit and Edit_Array from 4ed_edit.h even though we sort of think of that -// as cheating... gotta rethink the separation of buffer from everything else moving forward or something. - internal b32 -buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Edit_Array sorted_edits, void *scratch, i32 scratch_size, i32 *request_amount){ +buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Edit_Array sorted_edits, i32 *request_amount){ b32 result = false; i32 shift_total = state->shift_total; @@ -486,7 +475,7 @@ buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Edit_Array i32 start = edit->range.first + shift_total; i32 end = edit->range.one_past_last + shift_total; i32 shift_amount = buffer_replace_range_compute_shift(start, end, length); - result = buffer_replace_range(buffer, start, end, str, length, shift_amount, scratch, scratch_size, request_amount); + result = buffer_replace_range(buffer, start, end, str, length, shift_amount, request_amount); if (result){ break; } @@ -521,22 +510,31 @@ buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, i32 new_max){ // High level buffer operations // -internal String_Array -buffer_get_chunks(Partition *part, Gap_Buffer *buffer){ - String_Array result = {}; - result.vals = push_array(part, String, 0); +internal String_Const_u8_Array +buffer_get_chunks(Cursor *cursor, Gap_Buffer *buffer, Buffer_Get_Chunk_Mode mode){ + i32 total_count = (buffer->size1 > 0) + (buffer->size2 > 0) + (mode == BufferGetChunk_ZeroTerminated); + String_Const_u8_Array result = {}; + result.vals = push_array(cursor, String_Const_u8, total_count); if (buffer->size1 > 0){ - String *s = push_array(part, String, 1); - *s = make_string(buffer->data, buffer->size1); + result.vals[result.count] = SCu8(buffer->data, buffer->size1); + result.count += 1; } if (buffer->size2 > 0){ - String *s = push_array(part, String, 1); - *s = make_string(buffer->data + buffer->size1 + buffer->gap_size, buffer->size2); + result.vals[result.count] = SCu8(buffer->data + buffer->size1 + buffer->gap_size, buffer->size2); + result.count += 1; + } + if (mode == BufferGetChunk_ZeroTerminated){ + result.vals[result.count] = SCu8(); + result.count += 1; } - result.count = (i32)(push_array(part, String, 0) - result.vals); return(result); } +internal String_Const_u8_Array +buffer_get_chunks(Cursor *cursor, Gap_Buffer *buffer){ + return(buffer_get_chunks(cursor, buffer, BufferGetChunk_Basic)); +} + internal void buffer_stringify(Gap_Buffer *buffer, i32 start, i32 end, char *out){ Gap_Buffer_Stream stream = {}; @@ -1278,13 +1276,13 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa case buffer_seek_line_char: { line_index = params.seek.line - 1; - line_index = clamp_bottom(0, line_index); + line_index = clamp_bot(0, line_index); }break; case buffer_seek_unwrapped_xy: { line_index = (i32)(params.seek.y / S.font_height); - line_index = clamp_bottom(0, line_index); + line_index = clamp_bot(0, line_index); }break; case buffer_seek_wrapped_xy: @@ -1292,7 +1290,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa line_index = buffer_get_line_index_from_wrapped_y(params.wrap_line_index, params.seek.y, S.font_height, 0, params.buffer->line_count); }break; - default: InvalidCodePath; + default: InvalidPath; } i32 safe_line_index = line_index; @@ -1341,7 +1339,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa S.still_looping = buffer_stringify_next(&S.stream); }while(S.still_looping); } - InvalidCodePath; + InvalidPath; double_break_vwhite:; } @@ -1548,7 +1546,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa }while(S.still_looping); } - InvalidCodePath; + InvalidPath; buffer_cursor_seek_end:; *params.cursor_out = S.this_cursor; diff --git a/4ed_buffer.h b/4ed_buffer.h index f63a1eec..db7003dc 100644 --- a/4ed_buffer.h +++ b/4ed_buffer.h @@ -12,9 +12,10 @@ #if !defined(FRED_BUFFER_H) #define FRED_BUFFER_H -struct String_Array{ - String *vals; - i32 count; +typedef i32 Buffer_Get_Chunk_Mode; +enum{ + BufferGetChunk_Basic, + BufferGetChunk_ZeroTerminated, }; struct Cursor_With_Index{ diff --git a/4ed_cli.cpp b/4ed_cli.cpp index a4ec9818..bf7bbaa5 100644 --- a/4ed_cli.cpp +++ b/4ed_cli.cpp @@ -11,7 +11,7 @@ internal void child_process_container_init(Child_Process_Container *container, Models *models){ - container->arena = make_arena(&models->app_links); + container->arena = make_arena_app_links(&models->app_links); dll_init_sentinel(&container->child_process_active_list); dll_init_sentinel(&container->child_process_free_list); container->child_process_id_counter = 0; @@ -20,7 +20,7 @@ child_process_container_init(Child_Process_Container *container, Models *models) internal void child_process_container_release(Child_Process_Container *container, Models *models){ - arena_release_all(&container->arena); + linalloc_clear(&container->arena); heap_free(&models->mem.heap, container->id_to_ptr_table.mem); block_zero_struct(container); } @@ -92,26 +92,13 @@ child_process_lookup_return_code(Child_Process_Container *container, Child_Proce //////////////////////////////// internal b32 -child_process_call(Models *models, System_Functions *system, String path, String command, Child_Process_ID *id_out){ +child_process_call(Models *models, System_Functions *system, String_Const_u8 path, String_Const_u8 command, Child_Process_ID *id_out){ b32 result = false; - char *path_cstr = 0; - char *command_cstr = 0; - if (terminate_with_null(&path)){ - path_cstr = path.str; - } - else{ - String s = string_push_copy(&models->mem.part, path); - path_cstr = s.str; - } - if (terminate_with_null(&command)){ - command_cstr = command.str; - } - else{ - String s = string_push_copy(&models->mem.part, command); - command_cstr = s.str; - } + Scratch_Block scratch(&models->app_links); + String_Const_u8 path_n = string_copy(scratch, path); + String_Const_u8 command_n = string_copy(scratch, command); CLI_Handles cli_handles = {}; - if (system->cli_call(path_cstr, command_cstr, &cli_handles)){ + if (system->cli_call((char*)path_n.str, (char*)command_n.str, &cli_handles)){ Child_Process_And_ID new_process = child_process_alloc_new(models, &models->child_processes); *id_out = new_process.id; new_process.process->cli = cli_handles; diff --git a/4ed_code_wrap.cpp b/4ed_code_wrap.cpp index 1dd5bce7..881960d6 100644 --- a/4ed_code_wrap.cpp +++ b/4ed_code_wrap.cpp @@ -110,7 +110,7 @@ wrap_state_consume_token(System_Functions *system, Font_Pointers font, Code_Wrap end = fixed_end_point; } - i = clamp_bottom(line_start, i); + i = clamp_bot(line_start, i); if (i == line_start){ skipping_whitespace = true; } @@ -434,16 +434,16 @@ get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start){ } } - result.shift = clamp_bottom(0.f, result.shift); + result.shift = clamp_bot(0.f, result.shift); return(result); } internal void file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *file, Font_Pointers font){ Heap *heap = &mem->heap; - Partition *part = &mem->part; + Arena *scratch = &mem->arena; - Temp_Memory temp = begin_temp_memory(part); + Temp_Memory temp = begin_temp(scratch); file_allocate_wraps_as_needed(heap, file); file_allocate_indents_as_needed(heap, file, file->state.buffer.line_count); @@ -478,18 +478,18 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil b32 use_tokens = false; + // TODO(allen): REWRITE REWRITE REWRITE Wrap_Indent_Pair *wrap_indent_marks = 0; Potential_Wrap_Indent_Pair *potential_marks = 0; - i32 max_wrap_indent_mark = 0; + i32 max_wrap_indent_mark = Million(1); if (params.virtual_white && file->state.tokens_complete && !file->state.still_lexing){ wrap_state_init(system, &wrap_state, file, font); use_tokens = true; - potential_marks = push_array(part, Potential_Wrap_Indent_Pair, floor32(width)); + potential_marks = push_array(scratch, Potential_Wrap_Indent_Pair, floor32(width)); - max_wrap_indent_mark = part_remaining(part)/sizeof(Wrap_Indent_Pair); - wrap_indent_marks = push_array(part, Wrap_Indent_Pair, max_wrap_indent_mark); + wrap_indent_marks = push_array(scratch, Wrap_Indent_Pair, max_wrap_indent_mark); } i32 real_count = 0; @@ -910,7 +910,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil ++stage; } - current_line_shift = clamp_bottom(0.f, current_line_shift); + current_line_shift = clamp_bot(0.f, current_line_shift); } else{ current_line_shift = 0.f; @@ -934,7 +934,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil file->state.wrap_positions[wrap_position_index++] = size; file->state.wrap_position_count = wrap_position_index; - end_temp_memory(temp); + end_temp(temp); } // BOTTOM diff --git a/4ed_command.cpp b/4ed_command.cpp index c41aa1cb..52dcfc56 100644 --- a/4ed_command.cpp +++ b/4ed_command.cpp @@ -157,11 +157,11 @@ map_drop(Command_Map *map, Key_Code event_code, u8 modifiers){ } internal void -map_init(Command_Map *map, Partition *part, i32 max, i32 parent){ +map_init(Command_Map *map, Cursor *cursor, i32 max, i32 parent){ Assert(max >= 6); Assert(map->commands == 0); map->parent = parent; - map->commands = push_array(part, Command_Binding, max); + map->commands = push_array(cursor, Command_Binding, max); map->count = 0; map->max = max; diff --git a/4ed_defines.h b/4ed_defines.h deleted file mode 100644 index 5f93e2c6..00000000 --- a/4ed_defines.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 21.01.2017 - * - * Standard defines across 4coder code base. - * - */ - -// TOP - -#if !defined(FTECH_DEFINES) -#define FTECH_DEFINES - -#define internal static -#define local_persist static -#define global static -#define local_const static const -#define global_const static const -#define external extern "C" - -#define FixSize(s) struct{ u8 __size_fixer__[s]; } - -#define DrCase(PC) case PC: goto resumespot_##PC -#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); } - -#endif - -// BOTTOM - diff --git a/4ed_dynamic_variables.cpp b/4ed_dynamic_variables.cpp index 4ba06281..36023c91 100644 --- a/4ed_dynamic_variables.cpp +++ b/4ed_dynamic_variables.cpp @@ -16,11 +16,11 @@ dynamic_variables_init(Dynamic_Variable_Layout *layout){ } internal Managed_Variable_ID -dynamic_variables_lookup(Dynamic_Variable_Layout *layout, String name){ +dynamic_variables_lookup(Dynamic_Variable_Layout *layout, String_Const_u8 name){ for (Dynamic_Variable_Slot *slot = layout->sentinel.next; slot != &layout->sentinel; slot = slot->next){ - if (match(slot->name, name)){ + if (string_match(slot->name, name)){ return(slot->location); } } @@ -28,35 +28,35 @@ dynamic_variables_lookup(Dynamic_Variable_Layout *layout, String name){ } internal Managed_Variable_ID -dynamic_variables_create__always(Heap *heap, Dynamic_Variable_Layout *layout, String name, u64 default_value){ - i32 alloc_size = name.size + 1 + sizeof(Dynamic_Variable_Slot); +dynamic_variables_create__always(Heap *heap, Dynamic_Variable_Layout *layout, String_Const_u8 name, u64 default_value){ + i32 alloc_size = (i32)(name.size + 1 + sizeof(Dynamic_Variable_Slot)); void *ptr = heap_allocate(heap, alloc_size); + Managed_Variable_ID result = ManagedVariableIndex_ERROR; if (ptr != 0){ Dynamic_Variable_Slot *new_slot = (Dynamic_Variable_Slot*)ptr; char *c_str = (char*)(new_slot + 1); - String str = make_string_cap(c_str, 0, name.size + 1); - copy(&str, name); - terminate_with_null(&str); - new_slot->name = str; + block_copy(c_str, name.str, name.size); + c_str[name.size] = 0; + new_slot->name = SCu8(c_str, name.size); new_slot->default_value = default_value; new_slot->location = layout->location_counter++; dll_insert_back(&layout->sentinel, new_slot); - return(new_slot->location); + result = new_slot->location; } - return(ManagedVariableIndex_ERROR); + return(result); } internal Managed_Variable_ID -dynamic_variables_lookup_or_create(Heap *heap, Dynamic_Variable_Layout *layout, String name, u64 default_value){ +dynamic_variables_lookup_or_create(Heap *heap, Dynamic_Variable_Layout *layout, String_Const_u8 name, u64 default_value){ Managed_Variable_ID lookup_id = dynamic_variables_lookup(layout, name); - if (lookup_id != ManagedVariableIndex_ERROR){ - return(lookup_id); + if (lookup_id == ManagedVariableIndex_ERROR){ + lookup_id = dynamic_variables_create__always(heap, layout, name, default_value); } - return(dynamic_variables_create__always(heap, layout, name, default_value)); + return(lookup_id); } internal i32 -dynamic_variables_create(Heap *heap, Dynamic_Variable_Layout *layout, String name, u64 default_value){ +dynamic_variables_create(Heap *heap, Dynamic_Variable_Layout *layout, String_Const_u8 name, u64 default_value){ Managed_Variable_ID lookup_id = dynamic_variables_lookup(layout, name); if (lookup_id == ManagedVariableIndex_ERROR){ return(dynamic_variables_create__always(heap, layout, name, default_value)); @@ -130,14 +130,12 @@ insert_u32_Ptr_table(Heap *heap, Memory_Bank *mem_bank, u32_Ptr_Table *table, u3 if (table->mem != 0){ b32 result = move_u32_Ptr_table(&new_table, table); Assert(result); - AllowLocal(result); memory_bank_free(mem_bank, table->mem); } *table = new_table; } b32 result = insert_u32_Ptr_table(table, &key, &val); Assert(result); - AllowLocal(result); } //////////////////////////////// @@ -151,7 +149,7 @@ internal Marker_Visual_Data* dynamic_workspace_alloc_visual(Heap *heap, Memory_Bank *mem_bank, Dynamic_Workspace *workspace){ Marker_Visual_Allocator *allocator = &workspace->visual_allocator; if (allocator->free_count == 0){ - i32 new_slots_count = clamp_bottom(16, allocator->total_visual_count); + i32 new_slots_count = clamp_bot(16, allocator->total_visual_count); i32 memsize = new_slots_count*sizeof(Marker_Visual_Data); void *new_slots_memory = memory_bank_allocate(heap, mem_bank, memsize); memset(new_slots_memory, 0, memsize); @@ -400,8 +398,8 @@ lifetime__key_table_erase(Lifetime_Key_Table *table, Lifetime_Key *erase_key){ internal Lifetime_Key_Table lifetime__key_table_copy(Heap *heap, Lifetime_Key_Table table, u32 new_max){ Lifetime_Key_Table new_table = {}; - new_table.max = clamp_bottom(table.max, new_max); - new_table.max = clamp_bottom(307, new_table.max); + new_table.max = clamp_bot(table.max, new_max); + new_table.max = clamp_bot(307, new_table.max); i32 item_size = sizeof(*new_table.hashes) + sizeof(*new_table.keys); new_table.mem_ptr = heap_allocate(heap, item_size*new_table.max); memset(new_table.mem_ptr, 0, item_size*new_table.max); @@ -746,7 +744,7 @@ managed_object_alloc_managed_arena_in_scope(Heap *heap, Dynamic_Workspace *works header->std_header.item_size = sizeof(Arena*); header->std_header.count = 1; zdll_push_back(workspace->arena_list.first, workspace->arena_list.last, header); - header->arena = make_arena(app, page_size); + header->arena = make_arena_app_links(app, page_size); if (arena_out != 0){ *arena_out = &header->arena; } @@ -776,7 +774,7 @@ managed_object_free(Dynamic_Workspace *workspace, Managed_Object object){ case ManagedObjectType_Arena: { Managed_Arena_Header *header = (Managed_Arena_Header*)object_ptr; - arena_release_all(&header->arena); + linalloc_clear(&header->arena); zdll_remove(workspace->arena_list.first, workspace->arena_list.last, header); }break; } diff --git a/4ed_dynamic_variables.h b/4ed_dynamic_variables.h index cfb7d09a..4778740a 100644 --- a/4ed_dynamic_variables.h +++ b/4ed_dynamic_variables.h @@ -94,7 +94,7 @@ struct Managed_Arena_Header_List{ struct Dynamic_Variable_Slot{ Dynamic_Variable_Slot *next; Dynamic_Variable_Slot *prev; - String name; + String_Const_u8 name; u64 default_value; i32 location; }; diff --git a/4ed_edit.cpp b/4ed_edit.cpp index d9cb65ec..e21cf70e 100644 --- a/4ed_edit.cpp +++ b/4ed_edit.cpp @@ -20,7 +20,7 @@ edit_pre_state_change(System_Functions *system, Heap *heap, Models *models, Edit file->state.still_lexing = 0; } file_add_dirty_flag(file, DirtyState_UnsavedChanges); - file_unmark_edit_finished(file); + file_unmark_edit_finished(&models->working_set, file); Layout *layout = &models->layout; for (Panel *panel = layout_get_first_open_panel(layout); panel != 0; @@ -79,7 +79,7 @@ edit_fix_markers__read_workspace_markers(Dynamic_Workspace *workspace, Buffer_ID internal f32 edit_fix_markers__compute_scroll_y(i32 line_height, f32 old_y_val, f32 new_y_val_aligned){ - f32 y_offset = MOD(old_y_val, line_height); + f32 y_offset = mod_f32(old_y_val, line_height); f32 y_position = new_y_val_aligned + y_offset; return(y_position); } @@ -91,11 +91,8 @@ edit_fix_markers__compute_scroll_y(i32 line_height, i32 old_y_val, f32 new_y_val internal void edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, Edit edit){ - Partition *part = &models->mem.part; Layout *layout = &models->layout; - Temp_Memory cursor_temp = begin_temp_memory(part); - Lifetime_Object *file_lifetime_object = file->lifetime_object; Buffer_ID file_id = file->id.id; Assert(file_lifetime_object != 0); @@ -118,10 +115,12 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E key_index += count; } } - cursor_max += total_marker_count; - Cursor_With_Index *cursors = push_array(part, Cursor_With_Index, cursor_max); - Cursor_With_Index *r_cursors = push_array(part, Cursor_With_Index, cursor_max); + + Arena *scratch = &models->mem.arena; + Temp_Memory cursor_temp = begin_temp(scratch); + Cursor_With_Index *cursors = push_array(scratch, Cursor_With_Index, cursor_max); + Cursor_With_Index *r_cursors = push_array(scratch, Cursor_With_Index, cursor_max); i32 cursor_count = 0; i32 r_cursor_count = 0; Assert(cursors != 0); @@ -226,7 +225,7 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E } } - end_temp_memory(cursor_temp); + end_temp(cursor_temp); } internal void @@ -236,15 +235,14 @@ edit_single(System_Functions *system, Models *models, Editing_File *file, Range edit.length = string.size; edit.range = range; - Mem_Options *mem = &models->mem; - Heap *heap = &mem->heap; - Partition *part = &mem->part; Gap_Buffer *buffer = &file->state.buffer; Assert(0 <= edit.range.first); Assert(edit.range.first <= edit.range.one_past_last); Assert(edit.range.one_past_last <= buffer_size(buffer)); + Heap *heap = &models->mem.heap; + // NOTE(allen): history update if (!behaviors.do_not_post_to_history){ // TODO(allen): if the edit number counter is not updated, maybe auto-merge edits? Wouldn't that just work? @@ -258,18 +256,15 @@ edit_single(System_Functions *system, Models *models, Editing_File *file, Range // NOTE(allen): edit range hook if (models->hook_file_edit_range != 0){ - models->hook_file_edit_range(&models->app_links, file->id.id, edit.range, make_string(edit.str, edit.length)); + models->hook_file_edit_range(&models->app_links, file->id.id, edit.range, SCu8(edit.str, edit.length)); } // NOTE(allen): expand spec, compute shift i32 shift_amount = buffer_replace_range_compute_shift(edit.range.first, edit.range.one_past_last, edit.length); // NOTE(allen): actual text replacement - i32 scratch_size = part_remaining(part); - Assert(scratch_size > 0); i32 request_amount = 0; - for (;buffer_replace_range(buffer, edit.range.first, edit.range.one_past_last, edit.str, edit.length, - shift_amount, part->base + part->pos, scratch_size, &request_amount);){ + for (;buffer_replace_range(buffer, edit.range.first, edit.range.one_past_last, edit.str, edit.length, shift_amount, &request_amount);){ void *new_data = 0; if (request_amount > 0){ new_data = heap_allocate(heap, request_amount); @@ -302,7 +297,7 @@ edit_single(System_Functions *system, Models *models, Editing_File *file, Range } // NOTE(allen): wrap meta data - file_measure_wraps(system, mem, file, font); + file_measure_wraps(system, &models->mem, file, font); // NOTE(allen): cursor fixing edit_fix_markers(system, models, file, edit); @@ -385,7 +380,7 @@ edit__apply_record_forward(System_Functions *system, Models *models, Editing_Fil default: { - InvalidCodePath; + InvalidPath; }break; } } @@ -416,7 +411,7 @@ edit__apply_record_backward(System_Functions *system, Models *models, Editing_Fi default: { - InvalidCodePath; + InvalidPath; }break; } } @@ -459,16 +454,16 @@ edit_change_current_history_state(System_Functions *system, Models *models, Edit //////////////////////////////// internal Editing_File* -create_file(Models *models, String file_name, Buffer_Create_Flag flags){ +create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags){ Editing_File *result = 0; if (file_name.size > 0){ System_Functions *system = models->system; Working_Set *working_set = &models->working_set; Heap *heap = &models->mem.heap; - Partition *part = &models->mem.part; - Temp_Memory temp = begin_temp_memory(part); + Arena *scratch = &models->mem.arena; + Temp_Memory temp = begin_temp(scratch); Editing_File *file = 0; b32 do_empty_buffer = false; @@ -477,10 +472,10 @@ create_file(Models *models, String file_name, Buffer_Create_Flag flags){ b32 buffer_is_for_new_file = false; // NOTE(allen): Try to get the file by canon name. - if ((flags & BufferCreate_NeverAttachToFile) == 0){ + if (HasFlag(flags, BufferCreate_NeverAttachToFile) == 0){ if (get_canon_name(system, file_name, &canon)){ has_canon_name = true; - file = working_set_contains_canon(working_set, canon.name); + file = working_set_contains_canon(working_set, string_from_file_name(&canon)); } else{ do_empty_buffer = true; @@ -504,7 +499,7 @@ create_file(Models *models, String file_name, Buffer_Create_Flag flags){ do_empty_buffer = true; } else{ - if (!system->load_handle(canon.name.str, &handle)){ + if (!system->load_handle((char*)canon.name_space, &handle)){ do_empty_buffer = true; } } @@ -518,11 +513,12 @@ create_file(Models *models, String file_name, Buffer_Create_Flag flags){ file = working_set_alloc_always(working_set, heap, &models->lifetime_allocator); if (file != 0){ if (has_canon_name){ - file_bind_file_name(system, heap, working_set, file, canon.name); + file_bind_file_name(system, heap, working_set, file, string_from_file_name(&canon)); } - buffer_bind_name(models, heap, part, working_set, file, front_of_directory(file_name)); + String_Const_u8 front = string_front_of_path(file_name); + buffer_bind_name(models, heap, scratch, working_set, file, front); File_Attributes attributes = {}; - file_create_from_string(system, models, file, make_lit_string(""), attributes); + file_create_from_string(system, models, file, SCu8(""), attributes); result = file; } } @@ -530,7 +526,7 @@ create_file(Models *models, String file_name, Buffer_Create_Flag flags){ else{ File_Attributes attributes = system->load_attributes(handle); b32 in_heap_mem = false; - char *buffer = push_array(part, char, (i32)attributes.size); + char *buffer = push_array(scratch, char, (i32)attributes.size); if (buffer == 0){ buffer = heap_array(heap, char, (i32)attributes.size); @@ -542,9 +538,10 @@ create_file(Models *models, String file_name, Buffer_Create_Flag flags){ system->load_close(handle); file = working_set_alloc_always(working_set, heap, &models->lifetime_allocator); if (file != 0){ - file_bind_file_name(system, heap, working_set, file, canon.name); - buffer_bind_name(models, heap, part, working_set, file, front_of_directory(file_name)); - file_create_from_string(system, models, file, make_string(buffer, (i32)attributes.size), attributes); + file_bind_file_name(system, heap, working_set, file, string_from_file_name(&canon)); + String_Const_u8 front = string_front_of_path(file_name); + buffer_bind_name(models, heap, scratch, working_set, file, front); + file_create_from_string(system, models, file, SCu8(buffer, (i32)attributes.size), attributes); result = file; } } @@ -580,7 +577,7 @@ create_file(Models *models, String file_name, Buffer_Create_Flag flags){ models->hook_new_file(&models->app_links, file->id.id); } - end_temp_memory(temp); + end_temp(temp); } return(result); diff --git a/4ed_file.cpp b/4ed_file.cpp index 7055c2e0..4f79f9a0 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -16,6 +16,11 @@ to_file_id(i32 id){ return(result); } +internal String_Const_u8 +string_from_file_name(Editing_File_Name *name){ + return(SCu8(name->name_space, name->name_size)); +} + //////////////////////////////// internal void @@ -123,14 +128,24 @@ file_clear_dirty_flags(Editing_File *file){ //////////////////////////////// +internal void +file_name_terminate(Editing_File_Name *name){ + umem size = name->name_size; + size = clamp_top(size, sizeof(name->name_space) - 1); + name->name_space[size] = 0; + name->name_size = size; +} + +//////////////////////////////// + internal b32 -save_file_to_name(System_Functions *system, Models *models, Editing_File *file, char *file_name){ +save_file_to_name(System_Functions *system, Models *models, Editing_File *file, u8 *file_name){ b32 result = false; b32 using_actual_file_name = false; if (file_name == 0){ - terminate_with_null(&file->canon.name); - file_name = file->canon.name.str; + file_name_terminate(&file->canon); + file_name = file->canon.name_space; using_actual_file_name = true; } @@ -151,19 +166,15 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, max = buffer_size(buffer); } - b32 used_heap = 0; - Temp_Memory temp = begin_temp_memory(&mem->part); + Arena *scratch = &mem->arena; + Temp_Memory temp = begin_temp(scratch); char empty = 0; char *data = 0; if (max == 0){ data = ∅ } else{ - data = (char*)push_array(&mem->part, char, max); - if (!data){ - used_heap = 1; - data = heap_array(&mem->heap, char, max); - } + data = (char*)push_array(scratch, char, max); } Assert(data != 0); @@ -176,18 +187,16 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, buffer_stringify(buffer, 0, size, data); } - if (!using_actual_file_name && file->canon.name.str != 0){ + if (!using_actual_file_name){ char space[512]; - u32 length = str_size(file_name); - system->get_canonical(file_name, length, space, sizeof(space)); - - char *source_path = file->canon.name.str; - if (match(space, source_path)){ + umem length = cstring_length(file_name); + system->get_canonical((char*)file_name, (u32)length, space, sizeof(space)); + if (string_match(SCu8(space), string_from_file_name(&file->canon))){ using_actual_file_name = true; } } - File_Attributes new_attributes = system->save_file(file_name, data, size); + File_Attributes new_attributes = system->save_file((char*)file_name, data, size); if (new_attributes.last_write_time > 0){ if (using_actual_file_name){ file->state.ignore_behind_os = 1; @@ -196,12 +205,7 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, } file_clear_dirty_flags(file); - - if (used_heap){ - heap_free(&mem->heap, data); - } - end_temp_memory(temp); - + end_temp(temp); } return(result); @@ -331,7 +335,7 @@ file_grow_starts_as_needed(Heap *heap, Gap_Buffer *buffer, i32 additional_lines) i32 count = buffer->line_count; i32 target_lines = count + additional_lines; if (target_lines > max || max == 0){ - max = l_round_up_i32(target_lines + max, KB(1)); + max = round_up_i32(target_lines + max, KB(1)); i32 *new_lines = heap_array(heap, i32, max); if (new_lines != 0){ result = GROW_SUCCESS; @@ -371,14 +375,14 @@ file_measure_starts(Heap *heap, Gap_Buffer *buffer){ internal void file_allocate_metadata_as_needed(Heap *heap, Gap_Buffer *buffer, void **mem, i32 *mem_max_count, i32 count, i32 item_size){ if (*mem == 0){ - i32 max = l_round_up_i32(((count + 1)*2), KB(1)); + i32 max = round_up_i32(((count + 1)*2), KB(1)); *mem = heap_allocate(heap, max*item_size); *mem_max_count = max; Assert(*mem != 0); } else if (*mem_max_count < count){ i32 old_max = *mem_max_count; - i32 max = l_round_up_i32(((count + 1)*2), KB(1)); + i32 max = round_up_i32(((count + 1)*2), KB(1)); void *new_mem = heap_allocate(heap, item_size*max); memcpy(new_mem, *mem, item_size*old_max); heap_free(heap, *mem); @@ -421,16 +425,16 @@ file_allocate_wrap_positions_as_needed(Heap *heap, Editing_File *file, i32 min_l //////////////////////////////// internal void -file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String val, File_Attributes attributes){ +file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String_Const_u8 val, File_Attributes attributes){ Heap *heap = &models->mem.heap; - Partition *part = &models->mem.part; + Arena *scratch = &models->mem.arena; Application_Links *app_links = &models->app_links; block_zero_struct(&file->state); Gap_Buffer_Init 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 = l_round_up_i32(page_size, KB(4)); + page_size = round_up_i32(page_size, KB(4)); if (page_size < KB(4)){ page_size = KB(4); } @@ -438,10 +442,8 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * buffer_init_provide_page(&init, data, page_size); } - i32 scratch_size = part_remaining(part); - Assert(scratch_size > 0); - b32 init_success = buffer_end_init(&init, part->base + part->pos, scratch_size); - AllowLocal(init_success); Assert(init_success); + b32 init_success = buffer_end_init(&init); + Assert(init_success); if (buffer_size(&file->state.buffer) < val.size){ file->settings.dos_write_mode = true; @@ -488,7 +490,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * } internal void -file_free(System_Functions *system, Heap *heap, Lifetime_Allocator *lifetime_allocator, Editing_File *file){ +file_free(System_Functions *system, Heap *heap, Lifetime_Allocator *lifetime_allocator, Working_Set *working_set, Editing_File *file){ if (file->state.still_lexing){ system->cancel_job(BACKGROUND_THREADS, file->state.lex_job); if (file->state.swap_array.tokens){ @@ -514,7 +516,7 @@ file_free(System_Functions *system, Heap *heap, Lifetime_Allocator *lifetime_all history_free(heap, &file->state.history); - file_unmark_edit_finished(file); + file_unmark_edit_finished(working_set, file); } //////////////////////////////// diff --git a/4ed_file.h b/4ed_file.h index d947b12d..3aae1ffd 100644 --- a/4ed_file.h +++ b/4ed_file.h @@ -97,8 +97,8 @@ struct Editing_File_State{ }; struct Editing_File_Name{ - char name_[256]; - String name; + u8 name_space[256]; + umem name_size; }; struct Editing_File{ @@ -113,6 +113,7 @@ struct Editing_File{ Editing_File_Name unique_name; Editing_File_Name canon; Node main_chain_node; + b32 edit_finished_marked; Node edit_finished_mark_node; }; diff --git a/4ed_file_lex.cpp b/4ed_file_lex.cpp index 7f0b02b6..fa610b6c 100644 --- a/4ed_file_lex.cpp +++ b/4ed_file_lex.cpp @@ -9,19 +9,7 @@ // TOP -internal String_Array -file_lex_chunks(Partition *part, Gap_Buffer *buffer){ - String_Array result = {}; - result.vals = push_array(part, String, 0); - buffer_get_chunks(part, buffer); - { - String *s = push_array(part, String, 1); - block_zero(s, sizeof(*s)); - } - result.count = (i32)(push_array(part, String, 0) - result.vals); - return(result); -} - +// TODO(allen): this needs a rewrite _BAD_ internal void job_full_lex(System_Functions *system, Thread_Context *thread, Thread_Memory *memory, void *data[4]){ Editing_File *file = (Editing_File*)data[0]; @@ -58,17 +46,17 @@ job_full_lex(System_Functions *system, Thread_Context *thread, Thread_Memory *me Cpp_Lex_Data lex = cpp_lex_data_init(file->settings.tokens_without_strings, parse_context.kw_table, parse_context.pp_table); - String chunk_space[3]; - Partition chunk_part = make_part(chunk_space, sizeof(chunk_space)); - String_Array chunks = file_lex_chunks(&chunk_part, buffer); + String_Const_u8 chunk_space[3]; + Cursor chunk_cursor = make_cursor(chunk_space, sizeof(chunk_space)); + String_Const_u8_Array chunks = buffer_get_chunks(&chunk_cursor, buffer); i32 chunk_index = 0; do{ - char *chunk = chunks.vals[chunk_index].str; - i32 chunk_size = chunks.vals[chunk_index].size; + u8 *chunk = chunks.vals[chunk_index].str; + umem chunk_size = chunks.vals[chunk_index].size; - i32 result = cpp_lex_step(&lex, chunk, chunk_size, text_size, &tokens, 2048); + i32 result = cpp_lex_step(&lex, (char*)chunk, (i32)chunk_size, text_size, &tokens, 2048); switch (result){ case LexResult_NeedChunk: { @@ -108,7 +96,7 @@ job_full_lex(System_Functions *system, Thread_Context *thread, Thread_Memory *me } }while(still_lexing); - i32 new_max = l_round_up_i32(tokens.count+1, KB(1)); + i32 new_max = round_up_i32(tokens.count + 1, KB(1)); system->acquire_lock(FRAME_LOCK); { @@ -179,7 +167,7 @@ file_first_lex_parallel(System_Functions *system, Models *models, Editing_File * internal void file_first_lex_serial(System_Functions *system, Models *models, Editing_File *file){ Mem_Options *mem = &models->mem; - Partition *part = &mem->part; + Arena *scratch = &mem->arena; Heap *heap = &mem->heap; file->settings.tokens_exist = true; @@ -188,39 +176,37 @@ file_first_lex_serial(System_Functions *system, Models *models, Editing_File *fi if (file->is_loading == 0){ Assert(file->state.token_array.tokens == 0); - Temp_Memory temp = begin_temp_memory(part); + Temp_Memory temp = begin_temp(scratch); - Parse_Context parse_context = parse_context_get(&models->parse_context_memory, file->settings.parse_context_id, push_array(part, u8, 0), part_remaining(part)); + Parse_Context parse_context = parse_context_get(scratch, &models->parse_context_memory, file->settings.parse_context_id); Assert(parse_context.valid); - push_array(part, char, (i32)parse_context.memory_size); Gap_Buffer *buffer = &file->state.buffer; i32 text_size = buffer_size(buffer); - i32 mem_size = part_remaining(part); - - Cpp_Token_Array new_tokens; - new_tokens.max_count = mem_size/sizeof(Cpp_Token); + // TODO(allen): REWRITE REWRITE REWRITE + Cpp_Token_Array new_tokens = {}; + new_tokens.max_count = Million(1); new_tokens.count = 0; - new_tokens.tokens = push_array(part, Cpp_Token, new_tokens.max_count); + new_tokens.tokens = push_array(scratch, Cpp_Token, new_tokens.max_count); b32 still_lexing = true; Cpp_Lex_Data lex = cpp_lex_data_init(file->settings.tokens_without_strings, parse_context.kw_table, parse_context.pp_table); - String chunk_space[3]; - Partition chunk_part = make_part(chunk_space, sizeof(chunk_space)); - String_Array chunks = file_lex_chunks(&chunk_part, buffer); + String_Const_u8_Array chunk_space[3]; + Cursor chunk_cursor = make_cursor(chunk_space, sizeof(chunk_space)); + String_Const_u8_Array chunks = buffer_get_chunks(&chunk_cursor, buffer, BufferGetChunk_ZeroTerminated); i32 chunk_index = 0; Cpp_Token_Array *swap_array = &file->state.swap_array; do{ - char *chunk = chunks.vals[chunk_index].str; - i32 chunk_size = chunks.vals[chunk_index].size; + u8 *chunk = chunks.vals[chunk_index].str; + umem chunk_size = chunks.vals[chunk_index].size; - i32 result = cpp_lex_step(&lex, chunk, chunk_size, text_size, &new_tokens, NO_OUT_LIMIT); + i32 result = cpp_lex_step(&lex, (char*)chunk, (i32)chunk_size, text_size, &new_tokens, NO_OUT_LIMIT); switch (result){ case LexResult_NeedChunk: @@ -232,7 +218,7 @@ file_first_lex_serial(System_Functions *system, Models *models, Editing_File *fi case LexResult_Finished: case LexResult_NeedTokenMemory: { - u32 new_max = l_round_up_u32(swap_array->count + new_tokens.count + 1, KB(1)); + u32 new_max = round_up_u32(swap_array->count + new_tokens.count + 1, KB(1)); if (swap_array->tokens == 0){ swap_array->tokens = heap_array(heap, Cpp_Token, new_max); } @@ -255,7 +241,7 @@ file_first_lex_serial(System_Functions *system, Models *models, Editing_File *fi } }break; - case LexResult_HitTokenLimit: InvalidCodePath; + case LexResult_HitTokenLimit: InvalidPath; } } while (still_lexing); @@ -274,7 +260,7 @@ file_first_lex_serial(System_Functions *system, Models *models, Editing_File *fi file->state.tokens_complete = true; file->state.still_lexing = false; - end_temp_memory(temp); + end_temp(temp); file->state.tokens_complete = true; file_mark_edit_finished(&models->working_set, file); @@ -284,58 +270,176 @@ file_first_lex_serial(System_Functions *system, Models *models, Editing_File *fi internal b32 file_relex_parallel(System_Functions *system, Models *models, Editing_File *file, i32 start_i, i32 end_i, i32 shift_amount){ Mem_Options *mem = &models->mem; + Arena *scratch = &mem->arena; Heap *heap = &mem->heap; - Partition *part = &mem->part; - - if (file->state.token_array.tokens == 0){ - file_first_lex_parallel(system, models, file); - return(true); - } b32 result = true; - b32 internal_lex = !file->state.still_lexing; - if (internal_lex){ + if (file->state.token_array.tokens == 0){ + file_first_lex_parallel(system, models, file); + } + else{ + b32 internal_lex = !file->state.still_lexing; + if (internal_lex){ + Gap_Buffer *buffer = &file->state.buffer; + i32 extra_tolerance = 100; + + Cpp_Token_Array *array = &file->state.token_array; + Cpp_Relex_Range relex_range = cpp_get_relex_range(array, start_i, end_i); + + i32 relex_space_size = relex_range.end_token_index - relex_range.start_token_index + extra_tolerance; + + Temp_Memory temp = begin_temp(scratch); + Parse_Context parse_context = parse_context_get(scratch, &models->parse_context_memory, file->settings.parse_context_id); + Assert(parse_context.valid); + + Cpp_Token_Array relex_array; + relex_array.count = 0; + relex_array.max_count = relex_space_size; + relex_array.tokens = push_array(scratch, Cpp_Token, relex_array.max_count); + + i32 size = buffer_size(buffer); + + Cpp_Relex_Data state = cpp_relex_init(array, start_i, end_i, shift_amount, file->settings.tokens_without_strings, parse_context.kw_table, parse_context.pp_table); + + String_Const_u8_Array chunk_space[3]; + Cursor chunk_cursor = make_cursor(chunk_space, sizeof(chunk_space)); + String_Const_u8_Array chunks = buffer_get_chunks(&chunk_cursor, buffer, BufferGetChunk_ZeroTerminated); + + i32 chunk_index = 0; + u8 *chunk = chunks.vals[chunk_index].str; + umem chunk_size = chunks.vals[chunk_index].size; + + for (;!cpp_relex_is_start_chunk(&state, (char*)chunk, (i32)chunk_size);){ + ++chunk_index; + Assert(chunk_index < chunks.count); + chunk = chunks.vals[chunk_index].str; + chunk_size = chunks.vals[chunk_index].size; + } + + for (;;){ + Cpp_Lex_Result lex_result = + cpp_relex_step(&state, (char*)chunk, (i32)chunk_size, size, array, &relex_array); + + switch (lex_result){ + case LexResult_NeedChunk: + { + ++chunk_index; + Assert(chunk_index < chunks.count); + chunk = chunks.vals[chunk_index].str; + chunk_size = chunks.vals[chunk_index].size; + }break; + + case LexResult_NeedTokenMemory: + { + internal_lex = false; + }goto doublebreak; + + case LexResult_Finished: goto doublebreak; + } + } + doublebreak:; + + if (internal_lex){ + i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array); + if (new_count > array->max_count){ + i32 new_max = round_up_i32(new_count, KB(1)); + void *memory = heap_allocate(heap, new_max*sizeof(Cpp_Token)); + memcpy(memory, array->tokens, array->count*sizeof(Cpp_Token)); + heap_free(heap, array->tokens); + array->tokens = (Cpp_Token*)memory; + array->max_count = new_max; + } + + cpp_relex_complete(&state, array, &relex_array); + file_mark_edit_finished(&models->working_set, file); + } + else{ + cpp_relex_abort(&state, array); + } + + end_temp(temp); + } + + if (!internal_lex){ + Cpp_Token_Array *array = &file->state.token_array; + Cpp_Get_Token_Result get_token_result = cpp_get_token(*array, end_i); + i32 end_token_i = get_token_result.token_index; + + if (end_token_i < 0){ + end_token_i = 0; + } + else if (end_i > array->tokens[end_token_i].start){ + ++end_token_i; + } + + cpp_shift_token_starts(array, end_token_i, shift_amount); + --end_token_i; + if (end_token_i >= 0){ + Cpp_Token *token = array->tokens + end_token_i; + if (token->start < end_i && token->start + token->size > end_i){ + token->size += shift_amount; + } + } + + file->state.still_lexing = true; + + Job_Data job = {}; + job.callback = job_full_lex; + job.data[0] = file; + job.data[1] = heap; + job.data[2] = models; + file->state.lex_job = system->post_job(BACKGROUND_THREADS, job); + result = false; + } + } + return(result); +} + +internal b32 +file_relex_serial(System_Functions *system, Models *models, Editing_File *file, i32 start_i, i32 end_i, i32 shift_amount){ + Mem_Options *mem = &models->mem; + Arena *scratch = &mem->arena; + Heap *heap = &mem->heap; + + if (file->state.token_array.tokens == 0){ + file_first_lex_serial(system, models, file); + } + else{ + Assert(!file->state.still_lexing); + Gap_Buffer *buffer = &file->state.buffer; - i32 extra_tolerance = 100; - Cpp_Token_Array *array = &file->state.token_array; - Cpp_Relex_Range relex_range = cpp_get_relex_range(array, start_i, end_i); - i32 relex_space_size = - relex_range.end_token_index - relex_range.start_token_index + extra_tolerance; - - Temp_Memory temp = begin_temp_memory(part); - Parse_Context parse_context = parse_context_get(&models->parse_context_memory, file->settings.parse_context_id, push_array(part, u8, 0), part_remaining(part)); + Temp_Memory temp = begin_temp(scratch); + Parse_Context parse_context = parse_context_get(scratch, &models->parse_context_memory, file->settings.parse_context_id); Assert(parse_context.valid); - push_array(part, char, (i32)parse_context.memory_size); - Cpp_Token_Array relex_array; + Cpp_Token_Array relex_array = {}; relex_array.count = 0; - relex_array.max_count = relex_space_size; - relex_array.tokens = push_array(part, Cpp_Token, relex_array.max_count); + relex_array.max_count = Million(1); + relex_array.tokens = push_array(scratch, Cpp_Token, relex_array.max_count); i32 size = buffer_size(buffer); Cpp_Relex_Data state = cpp_relex_init(array, start_i, end_i, shift_amount, file->settings.tokens_without_strings, parse_context.kw_table, parse_context.pp_table); - String chunk_space[3]; - Partition chunk_part = make_part(chunk_space, sizeof(chunk_space)); - String_Array chunks = file_lex_chunks(&chunk_part, buffer); + String_Const_u8_Array chunk_space[3]; + Cursor chunk_cursor = make_cursor(chunk_space, sizeof(chunk_space)); + String_Const_u8_Array chunks = buffer_get_chunks(&chunk_cursor, buffer, BufferGetChunk_ZeroTerminated); i32 chunk_index = 0; - char *chunk = chunks.vals[chunk_index].str; - i32 chunk_size = chunks.vals[chunk_index].size; + u8 *chunk = chunks.vals[chunk_index].str; + umem chunk_size = chunks.vals[chunk_index].size; - for (;!cpp_relex_is_start_chunk(&state, chunk, chunk_size);){ + for (;!cpp_relex_is_start_chunk(&state, (char*)chunk, (i32)chunk_size);){ ++chunk_index; Assert(chunk_index < chunks.count); chunk = chunks.vals[chunk_index].str; chunk_size = chunks.vals[chunk_index].size; } - for (;;){ - Cpp_Lex_Result lex_result = - cpp_relex_step(&state, chunk, chunk_size, size, array, &relex_array); + for(;;){ + Cpp_Lex_Result lex_result = cpp_relex_step(&state, (char*)chunk, (i32)chunk_size, size, array, &relex_array); switch (lex_result){ case LexResult_NeedChunk: @@ -346,150 +450,28 @@ file_relex_parallel(System_Functions *system, Models *models, Editing_File *file chunk_size = chunks.vals[chunk_index].size; }break; - case LexResult_NeedTokenMemory: - { - internal_lex = false; - }goto doublebreak; + case LexResult_NeedTokenMemory: InvalidPath; case LexResult_Finished: goto doublebreak; } } doublebreak:; - if (internal_lex){ - i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array); - if (new_count > array->max_count){ - i32 new_max = l_round_up_i32(new_count, KB(1)); - void *memory = heap_allocate(heap, new_max*sizeof(Cpp_Token)); - memcpy(memory, array->tokens, array->count*sizeof(Cpp_Token)); - heap_free(heap, array->tokens); - array->tokens = (Cpp_Token*)memory; - array->max_count = new_max; - } - - cpp_relex_complete(&state, array, &relex_array); - file_mark_edit_finished(&models->working_set, file); - } - else{ - cpp_relex_abort(&state, array); + i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array); + if (new_count > array->max_count){ + i32 new_max = round_up_i32(new_count, KB(1)); + Cpp_Token *new_tokens = heap_array(heap, Cpp_Token, new_max); + memcpy(new_tokens, array->tokens, array->count*sizeof(Cpp_Token)); + heap_free(heap, array->tokens); + array->tokens = new_tokens; + array->max_count = new_max; } - end_temp_memory(temp); - } - - if (!internal_lex){ - Cpp_Token_Array *array = &file->state.token_array; - Cpp_Get_Token_Result get_token_result = cpp_get_token(*array, end_i); - i32 end_token_i = get_token_result.token_index; + cpp_relex_complete(&state, array, &relex_array); - if (end_token_i < 0){ - end_token_i = 0; - } - else if (end_i > array->tokens[end_token_i].start){ - ++end_token_i; - } - - cpp_shift_token_starts(array, end_token_i, shift_amount); - --end_token_i; - if (end_token_i >= 0){ - Cpp_Token *token = array->tokens + end_token_i; - if (token->start < end_i && token->start + token->size > end_i){ - token->size += shift_amount; - } - } - - file->state.still_lexing = true; - - Job_Data job = {}; - job.callback = job_full_lex; - job.data[0] = file; - job.data[1] = heap; - job.data[2] = models; - file->state.lex_job = system->post_job(BACKGROUND_THREADS, job); - result = false; + end_temp(temp); } - return(result); -} - -internal b32 -file_relex_serial(System_Functions *system, Models *models, Editing_File *file, i32 start_i, i32 end_i, i32 shift_amount){ - Mem_Options *mem = &models->mem; - Heap *heap = &mem->heap; - Partition *part = &mem->part; - - if (file->state.token_array.tokens == 0){ - file_first_lex_serial(system, models, file); - return(true); - } - - Assert(!file->state.still_lexing); - - Gap_Buffer *buffer = &file->state.buffer; - Cpp_Token_Array *array = &file->state.token_array; - - Temp_Memory temp = begin_temp_memory(part); - Parse_Context parse_context = parse_context_get(&models->parse_context_memory, file->settings.parse_context_id, push_array(part, u8, 0), part_remaining(part)); - Assert(parse_context.valid); - push_array(part, char, (i32)parse_context.memory_size); - - Cpp_Token_Array relex_array; - relex_array.count = 0; - relex_array.max_count = part_remaining(part) / sizeof(Cpp_Token); - relex_array.tokens = push_array(part, Cpp_Token, relex_array.max_count); - - i32 size = buffer_size(buffer); - - Cpp_Relex_Data state = cpp_relex_init(array, start_i, end_i, shift_amount, file->settings.tokens_without_strings, parse_context.kw_table, parse_context.pp_table); - - String chunk_space[3]; - Partition chunk_part = make_part(chunk_space, sizeof(chunk_space)); - String_Array chunks = file_lex_chunks(&chunk_part, buffer); - - i32 chunk_index = 0; - char *chunk = chunks.vals[chunk_index].str; - i32 chunk_size = chunks.vals[chunk_index].size; - - for (;!cpp_relex_is_start_chunk(&state, chunk, chunk_size);){ - ++chunk_index; - Assert(chunk_index < chunks.count); - chunk = chunks.vals[chunk_index].str; - chunk_size = chunks.vals[chunk_index].size; - } - - for(;;){ - Cpp_Lex_Result lex_result = cpp_relex_step(&state, chunk, chunk_size, size, array, &relex_array); - - switch (lex_result){ - case LexResult_NeedChunk: - { - ++chunk_index; - Assert(chunk_index < chunks.count); - chunk = chunks.vals[chunk_index].str; - chunk_size = chunks.vals[chunk_index].size; - }break; - - case LexResult_NeedTokenMemory: InvalidCodePath; - - case LexResult_Finished: goto doublebreak; - } - } - doublebreak:; - - i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array); - if (new_count > array->max_count){ - i32 new_max = l_round_up_i32(new_count, KB(1)); - Cpp_Token *new_tokens = heap_array(heap, Cpp_Token, new_max); - memcpy(new_tokens, array->tokens, array->count*sizeof(Cpp_Token)); - heap_free(heap, array->tokens); - array->tokens = new_tokens; - array->max_count = new_max; - } - - cpp_relex_complete(&state, array, &relex_array); - - end_temp_memory(temp); - return(true); } diff --git a/4ed_font.cpp b/4ed_font.cpp index f3e6e7e0..b8690e3a 100644 --- a/4ed_font.cpp +++ b/4ed_font.cpp @@ -10,15 +10,15 @@ // TOP internal Face_ID -font_get_id_by_name(System_Functions *system, String name){ +font_get_id_by_name(System_Functions *system, String_Const_u8 name){ Face_ID id = 0; u32 count = system->font.get_count(); for (Face_ID id_it = 1; id_it <= count; ++id_it){ char str[256]; i32 str_len = system->font.get_name_by_id(id_it, str, sizeof(str)); if (str_len > 0){ - String font_name = make_string(str, str_len); - if (match_ss(font_name, name)){ + String_Const_u8 font_name = SCu8(str, str_len); + if (string_match(font_name, name)){ id = id_it; break; } diff --git a/4ed_font_provider_freetype.cpp b/4ed_font_provider_freetype.cpp index 4f39d1bc..eca6f6bf 100644 --- a/4ed_font_provider_freetype.cpp +++ b/4ed_font_provider_freetype.cpp @@ -58,7 +58,6 @@ font_ft_get_face(FT_Library ft, Font_Loadable_Stub *stub, Font_Parameters *param else{ success = false; } - end_temp_memory(path.temp); }break; case SystemFontMethod_RawData: @@ -75,7 +74,6 @@ font_ft_get_face(FT_Library ft, Font_Loadable_Stub *stub, Font_Parameters *param else{ success = false; } - end_temp_memory(data.temp); }break; } } @@ -116,6 +114,8 @@ font_load_page_layout(Font_Settings *settings, Font_Metrics *metrics, Glyph_Page u32 pt_size = settings->parameters.pt_size; b32 use_hinting = settings->parameters.use_hinting; + Temp_Memory temp = begin_temp(&shared_vars.font_scratch); + // TODO(allen): Stop redoing all this init for each call. FT_Library ft; FT_Init_FreeType(&ft); @@ -197,11 +197,13 @@ font_load_page_layout(Font_Settings *settings, Font_Metrics *metrics, Glyph_Page FT_Done_FreeType(ft); + end_temp(temp); + return(has_a_good_face); } internal u32* -font_load_page_pixels(Partition *part, Font_Settings *settings, Glyph_Page *page, u32 page_number, i32 *tex_width_out, i32 *tex_height_out){ +font_load_page_pixels(Arena *arena, Font_Settings *settings, Glyph_Page *page, u32 page_number, i32 *tex_width_out, i32 *tex_height_out){ Assert(page != 0); Assert(page->has_layout); Assert(page->page_number == page_number); @@ -213,10 +215,10 @@ font_load_page_pixels(Partition *part, Font_Settings *settings, Glyph_Page *page FT_Library ft; FT_Init_FreeType(&ft); - FT_Face face; - b32 has_a_good_face = font_ft_get_face(ft, &settings->stub, &settings->parameters, &face); u32 *pixels = 0; + FT_Face face; + b32 has_a_good_face = font_ft_get_face(ft, &settings->stub, &settings->parameters, &face); if (has_a_good_face){ FT_Size_RequestRec_ size = {}; size.type = FT_SIZE_REQUEST_TYPE_NOMINAL; @@ -229,7 +231,7 @@ font_load_page_pixels(Partition *part, Font_Settings *settings, Glyph_Page *page i32 tex_width = page->tex_width; i32 tex_height = page->tex_height; - pixels = (u32*)sysshared_push_block(part, tex_width*tex_height*sizeof(u32)); + pixels = push_array(arena, u32, tex_width*tex_height); if (pixels != 0){ memset(pixels, 0, tex_width*tex_height*sizeof(u32)); @@ -304,7 +306,7 @@ font_release_pages(System_Functions *system, Font_Page_Storage *storage){ Render_Pseudo_Command_Free_Texture *c = push_array(&target.buffer, Render_Pseudo_Command_Free_Texture, 1); c->header.size = sizeof(*c); c->free_texture_node.tex_id = this_page->gpu_tex; - sll_push(target.free_texture_first, target.free_texture_last, &c->free_texture_node); + sll_queue_push(target.free_texture_first, target.free_texture_last, &c->free_texture_node); } system->font.free(this_page); } @@ -360,7 +362,7 @@ font_load(System_Functions *system, Font_Settings *settings, Font_Metrics *metri f32 relative_thickness = notional_to_real_ratio*face->underline_thickness; f32 center = (f32)floor32(metrics->ascent + relative_center); - f32 thickness = clamp_bottom(1.f, relative_thickness); + f32 thickness = clamp_bot(1.f, relative_thickness); metrics->underline_yoff1 = center - thickness*0.5f; metrics->underline_yoff2 = center + thickness*0.5f; @@ -458,7 +460,7 @@ Sys_Font_Face_Allocate_And_Init_Sig(system_font_face_allocate_and_init, new_sett Assert(fontvars.used_slot_count <= slot_max); if (fontvars.used_slot_count == slot_max){ - i32 memsize = l_round_up_i32(SLOT_PAGE_SIZE, KB(4)); + i32 memsize = round_up_i32(SLOT_PAGE_SIZE, KB(4)); i32 page_count = memsize/SLOT_PAGE_SIZE; void *ptr = system_font_allocate(memsize); memset(ptr, 0, memsize); @@ -724,11 +726,11 @@ Sys_Font_Load_Page_Sig(system_font_load_page, settings, metrics, page, page_numb //////////////////////////////// internal Font_Setup_List -system_font_get_local_stubs(Partition *part){ +system_font_get_local_stubs(Arena *arena){ Font_Setup_List list = {}; u32 dir_max = KB(32); - u8 *directory = push_array(part, u8, dir_max); + u8 *directory = push_array(arena, u8, dir_max); String dir_str = make_string_cap(directory, 0, dir_max); u32 dir_len = dir_str.size = system_get_4ed_path(dir_str.str, dir_str.memory_size); Assert(dir_len < dir_max); @@ -737,8 +739,7 @@ system_font_get_local_stubs(Partition *part){ terminate_with_null(&dir_str); dir_len = dir_str.size; - part_reduce(part, dir_max - dir_len - 1); - push_align(part, 8); + pop_array(arena, u8, dir_max - dir_len - 1); File_List file_list = {}; system_set_file_list(&file_list, (char*)directory, 0, 0, 0); @@ -751,12 +752,8 @@ system_font_get_local_stubs(Partition *part){ for (;filename[len];++len); if (dir_len + len + 1 <= sizeof(list.first->stub.name)){ - Font_Setup *setup = push_array(part, Font_Setup, 1); - memset(setup, 0, sizeof(*setup)); - part_align(part, 8); - - sll_push(list.first, list.last, setup); - + Font_Setup *setup = push_array_zero(arena, Font_Setup, 1); + sll_queue_push(list.first, list.last, setup); setup->stub.load_from_path = true; setup->stub.in_font_folder = true; memcpy(&setup->stub.name[0], directory, dir_len); diff --git a/4ed_font_provider_freetype.h b/4ed_font_provider_freetype.h index 6808ba4f..4c7c458c 100644 --- a/4ed_font_provider_freetype.h +++ b/4ed_font_provider_freetype.h @@ -77,14 +77,12 @@ struct Font_Setup_List{ // NOTE(allen): Procedures to be implemented per-OS for the freetype font provider. struct Font_Path{ - Temp_Memory temp; char *name; i32 len; b32 used_base_file; }; struct Font_Raw_Data{ - Temp_Memory temp; u8 *data; i32 size; b32 used_base_file; diff --git a/4ed_history.cpp b/4ed_history.cpp index 8ad8f0ad..cd6e6f2d 100644 --- a/4ed_history.cpp +++ b/4ed_history.cpp @@ -27,7 +27,7 @@ history__to_node(Node *sentinel, i32 index){ internal void history__push_back_record_ptr(Heap *heap, Record_Ptr_Lookup_Table *lookup, Record *record){ if (lookup->records == 0 || lookup->count == lookup->max){ - i32 new_max = clamp_bottom(1024, lookup->max*2); + i32 new_max = clamp_bot(1024, lookup->max*2); Record **new_records = (Record**)heap_allocate(heap, sizeof(Record*)*new_max); block_copy(new_records, lookup->records, sizeof(*new_records)*lookup->count); if (lookup->records != 0){ @@ -120,7 +120,7 @@ global_history_get_edit_number(Global_History *global_history){ internal void global_history_adjust_edit_grouping_counter(Global_History *global_history, i32 adjustment){ i32 original = global_history->edit_grouping_counter; - global_history->edit_grouping_counter = clamp_bottom(0, global_history->edit_grouping_counter + adjustment); + global_history->edit_grouping_counter = clamp_bot(0, global_history->edit_grouping_counter + adjustment); if (global_history->edit_grouping_counter == 0 && original > 0){ global_history->edit_number_counter += 1; } @@ -129,7 +129,7 @@ global_history_adjust_edit_grouping_counter(Global_History *global_history, i32 internal void history_init(Application_Links *app, History *history){ history->activated = true; - history->arena = make_arena(app, KB(32)); + history->arena = make_arena_app_links(app, KB(32)); memory_bank_init(&history->bank); dll_init_sentinel(&history->free_records); dll_init_sentinel(&history->records); @@ -145,7 +145,7 @@ history_is_activated(History *history){ internal void history_free(Heap *heap, History *history){ if (history->activated){ - arena_release_all(&history->arena); + linalloc_clear(&history->arena); memory_bank_free_all(heap, &history->bank); block_zero_struct(history); } @@ -173,11 +173,11 @@ history_get_record(History *history, i32 index){ } internal Record* -history_get_sub_record(Record *record, i32 sub_index){ +history_get_sub_record(Record *record, i32 sub_index_one_based){ Record *result = 0; if (record->kind == RecordKind_Group){ - if (0 <= sub_index && sub_index <= record->group.count){ - Node *node = history__to_node(&record->group.children, sub_index); + if (0 < sub_index_one_based && sub_index_one_based <= record->group.count){ + Node *node = history__to_node(&record->group.children, sub_index_one_based); if (node != 0){ result = CastFromMember(Record, node, node); } @@ -245,7 +245,7 @@ history_record_edit(Heap *heap, Global_History *global_history, History *history Record *new_record = history__allocate_record(heap, history); history__stash_record(heap, history, new_record); - new_record->restore_point = temp_memory_light(begin_temp_memory(&history->arena)); + new_record->restore_point = begin_temp(&history->arena); new_record->edit_number = global_history_get_edit_number(global_history); new_record->kind = RecordKind_Single; @@ -280,7 +280,7 @@ history_dump_records_after_index(History *history, i32 index){ Assert(first_node_to_clear != sentinel); Record *first_record_to_clear = CastFromMember(Record, node, first_node_to_clear); - end_temp_memory(&history->arena, first_record_to_clear->restore_point); + end_temp(first_record_to_clear->restore_point); Node *last_node_to_clear = sentinel->prev; @@ -292,7 +292,7 @@ history_dump_records_after_index(History *history, i32 index){ } internal void -history__optimize_group(Partition *scratch, History *history, Record *record){ +history__optimize_group(Arena *scratch, History *history, Record *record){ Assert(record->kind == RecordKind_Group); for (;;){ Record *right = CastFromMember(Record, node, record->group.children.prev); @@ -312,7 +312,7 @@ history__optimize_group(Partition *scratch, History *history, Record *record){ if (right->kind == RecordKind_Single && left->kind == RecordKind_Single){ b32 do_merge = false; - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); i32 new_length_forward = left->single.length_forward + right->single.length_forward ; i32 new_length_backward = left->single.length_backward + right->single.length_backward; @@ -342,7 +342,7 @@ history__optimize_group(Partition *scratch, History *history, Record *record){ } if (do_merge){ - end_temp_memory(&history->arena, left->restore_point); + end_temp(left->restore_point); char *new_str_forward = push_array(&history->arena, char, new_length_forward ); char *new_str_backward = push_array(&history->arena, char, new_length_backward); @@ -360,7 +360,7 @@ history__optimize_group(Partition *scratch, History *history, Record *record){ record->group.count -= 1; } - end_temp_memory(temp); + end_temp(temp); } else{ break; @@ -369,7 +369,7 @@ history__optimize_group(Partition *scratch, History *history, Record *record){ } internal void -history_merge_records(Partition *scratch, Heap *heap, History *history, i32 first_index, i32 last_index){ +history_merge_records(Arena *scratch, Heap *heap, History *history, i32 first_index, i32 last_index){ if (history->activated){ Assert(history->record_lookup.count == history->record_count); Assert(first_index < last_index); @@ -380,17 +380,14 @@ history_merge_records(Partition *scratch, Heap *heap, History *history, i32 firs Record *new_record = history__allocate_record(heap, history); - Node *left = first_node->prev; - Node *right = last_node->next; - left->next = &new_record->node; - new_record->node.prev = left; - right->prev = &new_record->node; - new_record->node.next = right; - // NOTE(allen): here we remove (last_index - first_index + 1) nodes, and insert 1 node // which simplifies to this: history->record_count -= last_index - first_index; + Node *left = first_node->prev; + dll_remove_multiple(first_node, last_node); + dll_insert(left, &new_record->node); + Record *first_record = CastFromMember(Record, node, first_node); Record *last_record = CastFromMember(Record, node, last_node); @@ -401,10 +398,9 @@ history_merge_records(Partition *scratch, Heap *heap, History *history, i32 firs Node *new_sentinel = &new_record->group.children; dll_init_sentinel(new_sentinel); - Node *one_past_last_node = last_node->next; i32 count = 0; for (Node *node = first_node, *next = 0; - node != one_past_last_node; + node != 0; node = next){ next = node->next; Record *record = CastFromMember(Record, node, node); @@ -422,18 +418,15 @@ history_merge_records(Partition *scratch, Heap *heap, History *history, i32 firs Assert(first != &record->group.children); Assert(last != &record->group.children); - Node *sub_right = new_sentinel; - Node *sub_left = new_sentinel->prev; - sub_left->next = first; - first->prev = sub_left; - last->next = sub_right; - sub_right->prev = last; + dll_insert_multiple_back(new_sentinel, first, last); count += record->group.count; + + // TODO(allen): free the record for the old group!? }break; default: { - InvalidCodePath; + InvalidPath; }break; } } diff --git a/4ed_history.h b/4ed_history.h index 25e7129e..07205384 100644 --- a/4ed_history.h +++ b/4ed_history.h @@ -20,7 +20,7 @@ struct Record_Batch_Slot{ struct Record{ Node node; - Temp_Memory_Arena_Light restore_point; + Temp_Memory restore_point; i32 edit_number; Record_Kind kind; union{ diff --git a/4ed_hot_directory.cpp b/4ed_hot_directory.cpp index 597bfd28..e78a3708 100644 --- a/4ed_hot_directory.cpp +++ b/4ed_hot_directory.cpp @@ -11,10 +11,10 @@ internal void hot_directory_clean_end(Hot_Directory *hot_directory){ - String *str = &hot_directory->string; - if (str->size != 0 && str->str[str->size-1] != '/'){ - str->size = reverse_seek_slash(*str) + 1; - str->str[str->size] = 0; + String_Const_u8 str = SCu8(hot_directory->string_space, hot_directory->string_size); + if (!character_is_slash(string_get_character(str, str.size - 1))){ + str = string_remove_last_folder(str); + str.str[str.size] = 0; } } @@ -23,10 +23,10 @@ hot_directory_quick_partition(File_Info *infos, i32 start, i32 pivot){ File_Info *p = infos + pivot; File_Info *a = infos + start; for (i32 i = start; i < pivot; ++i, ++a){ - i32 comp = 0; - comp = p->folder - a->folder; + i32 comp = p->folder - a->folder; if (comp == 0){ - comp = compare_cc(a->filename, p->filename); + comp = string_compare(SCu8(a->filename, a->filename_len), + SCu8(p->filename, p->filename_len)); } if (comp < 0){ Swap(File_Info, *a, infos[start]); @@ -53,28 +53,32 @@ hot_directory_fixup(Hot_Directory *hot_directory){ } internal void -hot_directory_set(System_Functions *system, Hot_Directory *hot_directory, String str){ - copy_checked_ss(&hot_directory->string, str); - b32 success = terminate_with_null(&hot_directory->string); +hot_directory_set(System_Functions *system, Hot_Directory *hot_directory, String_Const_u8 str){ + b32 success = (str.size < sizeof(hot_directory->string_space)); if (success){ + block_copy(hot_directory->string_space, str.str, str.size); + hot_directory->string_space[str.size] = 0; + hot_directory->string_size = str.size; if (str.size > 0){ - u32 canon_max = hot_directory->canon_dir.memory_size; + u32 canon_max = sizeof(hot_directory->canon_dir_space); + u8 *canon_str = hot_directory->canon_dir_space; u32 canon_length = 0; - char *canon_str = hot_directory->canon_dir.str; - system->set_file_list(&hot_directory->file_list, hot_directory->string.str, canon_str, &canon_length, canon_max); + system->set_file_list(&hot_directory->file_list, (char*)hot_directory->string_space, (char*)canon_str, &canon_length, canon_max); if (canon_length > 0){ - hot_directory->canon_dir.size = canon_length; - if (!char_is_slash(hot_directory->canon_dir.str[canon_length-1])){ - append_s_char(&hot_directory->canon_dir, '/'); + hot_directory->canon_dir_size = canon_length; + if (!character_is_slash(hot_directory->canon_dir_space[canon_length - 1])){ + hot_directory->canon_dir_space[hot_directory->canon_dir_size] = '/'; + hot_directory->canon_dir_size += 1; + hot_directory->canon_dir_space[hot_directory->canon_dir_size] = 0; } } else{ - hot_directory->canon_dir.size = 0; + hot_directory->canon_dir_size = 0; } } else{ system->set_file_list(&hot_directory->file_list, 0, 0, 0, 0); - hot_directory->canon_dir.size = 0; + hot_directory->canon_dir_size = 0; } } hot_directory_fixup(hot_directory); @@ -82,19 +86,22 @@ hot_directory_set(System_Functions *system, Hot_Directory *hot_directory, String internal void hot_directory_reload(System_Functions *system, Hot_Directory *hot_directory){ - hot_directory_set(system, hot_directory, hot_directory->string); + String_Const_u8 string = SCu8(hot_directory->string_space, hot_directory->string_size); + hot_directory_set(system, hot_directory, string); } internal void -hot_directory_init(Hot_Directory *hot_directory, String dir){ - hot_directory->string = make_fixed_width_string(hot_directory->string_space); - hot_directory->canon_dir = make_fixed_width_string(hot_directory->canon_dir_space); - - hot_directory->string.str[255] = 0; - hot_directory->string.size = 0; - copy_ss(&hot_directory->string, dir); - if (hot_directory->string.str[hot_directory->string.size-1] != '/'){ - append_s_char(&hot_directory->string, '/'); +hot_directory_init(Hot_Directory *hot_directory, String_Const_u8 dir){ + hot_directory->string_size = 0; + umem size = clamp_top(dir.size, sizeof(hot_directory->string_space)); + block_copy(hot_directory->string_space, dir.str, size); + if (dir.size < sizeof(hot_directory->string_space)){ + if (hot_directory->string_space[size - 1] != '/'){ + hot_directory->string_space[size] = '/'; + size = clamp_top(size + 1, sizeof(hot_directory->string_space)); + hot_directory->string_space[size] = 0; + hot_directory->string_size = size; + } } } diff --git a/4ed_hot_directory.h b/4ed_hot_directory.h index 7fa3a52f..2ad726f3 100644 --- a/4ed_hot_directory.h +++ b/4ed_hot_directory.h @@ -13,10 +13,10 @@ #define FRED_HOT_DIRECTORY_H struct Hot_Directory{ - char string_space[256]; - char canon_dir_space[256]; - String string; - String canon_dir; + u8 string_space[256]; + umem string_size; + u8 canon_dir_space[256]; + umem canon_dir_size; File_List file_list; }; diff --git a/4ed_layout.cpp b/4ed_layout.cpp index 5a92be78..7038e1e3 100644 --- a/4ed_layout.cpp +++ b/4ed_layout.cpp @@ -74,7 +74,7 @@ layout__evaluate_split(Panel_Split split, i32 v0, i32 v1){ }break; case PanelSplitKind_FixedPixels_Max: { - v = clamp_bottom(v0, v1 - split.v_i32); + v = clamp_bot(v0, v1 - split.v_i32); }break; } return(v); @@ -255,9 +255,9 @@ layout_close_panel(Layout *layout, Panel *panel){ } internal Panel* -layout_initialize(Partition *part, Layout *layout){ +layout_initialize(Arena *arena, Layout *layout){ i32 panel_alloc_count = MAX_VIEWS*2 - 1; - Panel *panels = push_array(part, Panel, panel_alloc_count); + Panel *panels = push_array(arena, Panel, panel_alloc_count); block_zero(panels, sizeof(*panels)*panel_alloc_count); layout->panel_first = panels; diff --git a/4ed_mem.cpp b/4ed_mem.cpp index 1ea3a429..8864dd02 100644 --- a/4ed_mem.cpp +++ b/4ed_mem.cpp @@ -10,73 +10,68 @@ // TODO(allen): Make these as fast as possible +#if 0 internal void -block_zero(void *a, umem_4tech size){ - for (u8_4tech *ptr = (u8_4tech*)a, *e = ptr + size; ptr < e; ptr += 1){ +block_zero(void *a, umem size){ + for (u8 *ptr = (u8*)a, *e = ptr + size; ptr < e; ptr += 1){ *ptr = 0; } } - -#define block_zero_struct(s) block_zero((s), sizeof(*(s))) - internal void -block_fill_ones(void *a, umem_4tech size){ - for (u8_4tech *ptr = (u8_4tech*)a, *e = ptr + size; ptr < e; ptr += 1){ +block_fill_ones(void *a, umem size){ + for (u8 *ptr = (u8*)a, *e = ptr + size; ptr < e; ptr += 1){ *ptr = 0xFF; } } - internal void -block_copy(void *dst, void *src, umem_4tech size){ - for (u8_4tech *d = (u8_4tech*)dst, *s = (u8_4tech*)src, *e = s + size; s < e; d += 1, s += 1){ +block_copy(void *dst, void *src, umem size){ + for (u8 *d = (u8*)dst, *s = (u8*)src, *e = s + size; s < e; d += 1, s += 1){ *d = *s; } } - -internal i32_4tech -block_compare(void *a, void *b, umem_4tech size){ - for (u8_4tech *aptr = (u8_4tech*)a, *bptr = (u8_4tech*)b, *e = bptr + size; bptr < e; aptr += 1, bptr += 1){ - i32_4tech dif = (i32_4tech)*aptr - (i32_4tech)*bptr; +internal i32 +block_compare(void *a, void *b, umem size){ + for (u8 *aptr = (u8*)a, *bptr = (u8*)b, *e = bptr + size; bptr < e; aptr += 1, bptr += 1){ + i32 dif = (i32)*aptr - (i32)*bptr; if (dif != 0){ return(dif > 0?1:-1); } } return(0); } - internal void -block_fill_u8_4tech(void *a, umem_4tech size, u8_4tech val){ - for (u8_4tech *ptr = (u8_4tech*)a, *e = ptr + size; ptr < e; ptr += 1){ +block_fill_u8(void *a, umem size, u8 val){ + for (u8 *ptr = (u8*)a, *e = ptr + size; ptr < e; ptr += 1){ + *ptr = val; + } +} +internal void +block_fill_u16(void *a, umem size, u16 val){ + Assert(size%sizeof(u16) == 0); + umem count = size/sizeof(u16); + for (u16 *ptr = (u16*)a, *e = ptr + count; ptr < e; ptr += 1){ + *ptr = val; + } +} +internal void +block_fill_u32(void *a, umem size, u32 val){ + Assert(size%sizeof(u32) == 0); + umem count = size/sizeof(u32); + for (u32 *ptr = (u32*)a, *e = ptr + count; ptr < e; ptr += 1){ + *ptr = val; + } +} +internal void +block_fill_u64(void *a, umem size, u64 val){ + Assert(size%sizeof(u64) == 0); + umem count = size/sizeof(u64); + for (u64 *ptr = (u64*)a, *e = ptr + count; ptr < e; ptr += 1){ *ptr = val; } } -internal void -block_fill_u16(void *a, umem_4tech size, u16_4tech val){ - Assert(size%sizeof(u16_4tech) == 0); - umem_4tech count = size/sizeof(u16_4tech); - for (u16_4tech *ptr = (u16_4tech*)a, *e = ptr + count; ptr < e; ptr += 1){ - *ptr = val; - } -} - -internal void -block_fill_u32(void *a, umem_4tech size, u32_4tech val){ - Assert(size%sizeof(u32_4tech) == 0); - umem_4tech count = size/sizeof(u32_4tech); - for (u32_4tech *ptr = (u32_4tech*)a, *e = ptr + count; ptr < e; ptr += 1){ - *ptr = val; - } -} - -internal void -block_fill_u64(void *a, umem_4tech size, u64_4tech val){ - Assert(size%sizeof(u64_4tech) == 0); - umem_4tech count = size/sizeof(u64_4tech); - for (u64_4tech *ptr = (u64_4tech*)a, *e = ptr + count; ptr < e; ptr += 1){ - *ptr = val; - } -} +#define block_zero_struct(s) block_zero((s), sizeof(*(s))) +#endif // BOTTOM diff --git a/4ed_memory_bank.cpp b/4ed_memory_bank.cpp index 4f0c3d14..93fdb374 100644 --- a/4ed_memory_bank.cpp +++ b/4ed_memory_bank.cpp @@ -21,11 +21,11 @@ internal void* memory_bank_allocate(Heap *heap, Memory_Bank *mem_bank, i32 size){ void *ptr = heap_allocate(&mem_bank->heap, size); if (ptr == 0){ - i32 alloc_size = clamp_bottom(4096, size*4 + sizeof(Memory_Header)); + i32 alloc_size = clamp_bot(4096, size*4 + sizeof(Memory_Header)); void *new_block = heap_allocate(heap, alloc_size); if (new_block != 0){ Memory_Header *header = (Memory_Header*)new_block; - sll_push(mem_bank->first, mem_bank->last, header); + sll_queue_push(mem_bank->first, mem_bank->last, header); mem_bank->total_memory_size += alloc_size; heap_extend(&mem_bank->heap, header + 1, alloc_size - sizeof(*header)); ptr = heap_allocate(&mem_bank->heap, size); diff --git a/4ed_parse_context.cpp b/4ed_parse_context.cpp index 99f22a6c..96f8581e 100644 --- a/4ed_parse_context.cpp +++ b/4ed_parse_context.cpp @@ -11,11 +11,11 @@ internal void parse_context_init_memory(Parse_Context_Memory *parse_mem, void *mem, umem memsize){ - sll_init_sentinel(&parse_mem->free_sentinel); + parse_mem->free_list = 0; parse_mem->parse_context_array = (Stored_Parse_Context_Slot*)mem; parse_mem->parse_context_counter = 0; - parse_mem->parse_context_max = (u32)(memsize / sizeof(*parse_mem->parse_context_array)); + parse_mem->parse_context_max = (u32)(memsize/sizeof(*parse_mem->parse_context_array)); } internal Parse_Context_ID @@ -30,9 +30,9 @@ parse_context_valid_id(Parse_Context_Memory *parse_mem, Parse_Context_ID id){ internal Parse_Context_ID parse_context_add(Parse_Context_Memory *parse_mem, Heap *heap, Parser_String_And_Type *kw_sats, u32 kw_count, Parser_String_And_Type *pp_sats, u32 pp_count){ Stored_Parse_Context_Slot *slot = 0; - if (parse_mem->free_sentinel.next != &parse_mem->free_sentinel){ - slot = parse_mem->free_sentinel.next; - sll_remove(&parse_mem->free_sentinel, slot); + if (parse_mem->free_list != 0){ + slot = parse_mem->free_list; + sll_stack_pop(parse_mem->free_list); } else if (parse_mem->parse_context_counter < parse_mem->parse_context_max){ slot = &parse_mem->parse_context_array[parse_mem->parse_context_counter++]; @@ -72,9 +72,9 @@ parse_context_add(Parse_Context_Memory *parse_mem, Heap *heap, Parser_String_And internal u32 parse_context_add_default(Parse_Context_Memory *parse_mem, Heap *heap){ Stored_Parse_Context_Slot *slot = 0; - if (parse_mem->free_sentinel.next != &parse_mem->free_sentinel){ - slot = parse_mem->free_sentinel.next; - sll_remove(&parse_mem->free_sentinel, slot); + if (parse_mem->free_list != 0){ + slot = parse_mem->free_list; + sll_stack_pop(parse_mem->free_list); } else if (parse_mem->parse_context_counter < parse_mem->parse_context_max){ slot = &parse_mem->parse_context_array[parse_mem->parse_context_counter++]; @@ -109,10 +109,8 @@ parse_context_add_default(Parse_Context_Memory *parse_mem, Heap *heap){ return(result); } -internal Parse_Context -parse_context_get(Parse_Context_Memory *parse_mem, Parse_Context_ID id, void *mem, umem memsize){ - Parse_Context result = {}; - +internal Stored_Parse_Context_Slot* +parse_context_get_slot(Parse_Context_Memory *parse_mem, Parse_Context_ID id){ Stored_Parse_Context_Slot *slot = 0; if (id == 0){ // do nothing @@ -120,14 +118,19 @@ parse_context_get(Parse_Context_Memory *parse_mem, Parse_Context_ID id, void *me else{ id -= parse_mem->parse_context_max; } - if (id < parse_mem->parse_context_counter){ slot = &parse_mem->parse_context_array[id]; if (slot->freed){ slot = 0; } } - + return(slot); +} + +internal Parse_Context +parse_context_get(Parse_Context_Memory *parse_mem, Parse_Context_ID id, void *mem, umem memsize){ + Stored_Parse_Context_Slot *slot = parse_context_get_slot(parse_mem, id); + Parse_Context result = {}; if (slot != 0){ Stored_Parse_Context *context = slot->context; if (context->memsize < memsize){ @@ -143,7 +146,19 @@ parse_context_get(Parse_Context_Memory *parse_mem, Parse_Context_ID id, void *me memcpy(mem, context, context->memsize); } } - + return(result); +} + +internal Parse_Context +parse_context_get(Arena *arena, Parse_Context_Memory *parse_mem, Parse_Context_ID id){ + Stored_Parse_Context_Slot *slot = parse_context_get_slot(parse_mem, id); + Parse_Context result = {}; + if (slot != 0){ + Stored_Parse_Context *context = slot->context; + umem memsize = context->memsize + 1; + u8 *mem = push_array(arena, u8, memsize); + result = parse_context_get(parse_mem, id, mem, memsize); + } return(result); } diff --git a/4ed_parse_context.h b/4ed_parse_context.h index 1a5c9abc..c3e7e3c7 100644 --- a/4ed_parse_context.h +++ b/4ed_parse_context.h @@ -12,6 +12,8 @@ #if !defined(FRED_PARSE_CONTEXT_H) #define FRED_PARSE_CONTEXT_H +// TODO(allen): this needs a rewrite + struct Stored_Parse_Context{ umem memsize; u64 *kw_keywords; @@ -33,7 +35,7 @@ struct Parse_Context_Memory{ u32 parse_context_counter; u32 parse_context_max; - Stored_Parse_Context_Slot free_sentinel; + Stored_Parse_Context_Slot *free_list; }; struct Parse_Context{ diff --git a/4ed_ptr_check.cpp b/4ed_ptr_check.cpp index 2c545269..e9eed30d 100644 --- a/4ed_ptr_check.cpp +++ b/4ed_ptr_check.cpp @@ -159,14 +159,12 @@ insert_Ptr_table(Heap *heap, Ptr_Table *table, void* key){ if (table->mem != 0){ b32 result = move_Ptr_table(&new_table, table); Assert(result); - AllowLocal(result); heap_free(heap, table->mem); } *table = new_table; } b32 result = insert_Ptr_table(table, &key); Assert(result); - AllowLocal(result); } //////////////////////////////// @@ -351,14 +349,12 @@ insert_u32_Ptr_table(Heap *heap, u32_Ptr_Table *table, u32 key, void* val){ if (table->mem != 0){ b32 result = move_u32_Ptr_table(&new_table, table); Assert(result); - AllowLocal(result); heap_free(heap, table->mem); } *table = new_table; } b32 result = insert_u32_Ptr_table(table, &key, &val); Assert(result); - AllowLocal(result); } // BOTTOM diff --git a/4ed_render_format.cpp b/4ed_render_format.cpp index dc848c35..43a48127 100644 --- a/4ed_render_format.cpp +++ b/4ed_render_format.cpp @@ -135,8 +135,7 @@ snap_point_to_boundary(Vec2 point){ } internal f32 -draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String string, Vec2 point, - u32 color, u32 flags, Vec2 delta){ +draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String_Const_u8 string, Vec2 point, u32 color, u32 flags, Vec2 delta){ f32 total_delta = 0.f; Font_Pointers font = system->font.get_pointers_by_id(font_id); @@ -153,7 +152,7 @@ draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, St Translation_Emits emits = {}; for (u32 i = 0; str < str_end; ++str, ++i){ - translating_fully_process_byte(system, font, &tran, *str, i, string.size, &emits); + translating_fully_process_byte(system, font, &tran, *str, i, (i32)string.size, &emits); for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){ TRANSLATION_DECL_GET_STEP(step, behavior, J, emits); @@ -190,31 +189,30 @@ draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, St } internal f32 -draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String string, Vec2 point, - u32 color){ +draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String_Const_u8 string, Vec2 point, u32 color){ return(draw_string(system, target, font_id, string, point, color, 0, V2(1.f, 0.f))); } internal f32 -draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, char *str, Vec2 point, +draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, u8 *str, Vec2 point, u32 color, u32 flags, Vec2 delta){ - return(draw_string(system, target, font_id, make_string_slowly(str), point, color, flags, delta)); + return(draw_string(system, target, font_id, SCu8(str), point, color, flags, delta)); } internal f32 -draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, char *str, Vec2 point, +draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, u8 *str, Vec2 point, u32 color){ - return(draw_string(system, target, font_id, make_string_slowly(str), point, color, 0, V2(1.f, 0.f))); + return(draw_string(system, target, font_id, SCu8(str), point, color, 0, V2(1.f, 0.f))); } internal f32 -font_string_width(System_Functions *system, Render_Target *target, Face_ID font_id, String str){ +font_string_width(System_Functions *system, Render_Target *target, Face_ID font_id, String_Const_u8 str){ return(draw_string(system, target, font_id, str, V2(0, 0), 0, 0, V2(0, 0))); } internal f32 -font_string_width(System_Functions *system, Render_Target *target, Face_ID font_id, char *str){ - return(draw_string(system, target, font_id, make_string_slowly(str), V2(0, 0), 0, 0, V2(0, 0))); +font_string_width(System_Functions *system, Render_Target *target, Face_ID font_id, u8 *str){ + return(draw_string(system, target, font_id, SCu8(str), V2(0, 0), 0, 0, V2(0, 0))); } // BOTTOM diff --git a/4ed_render_target.h b/4ed_render_target.h index 694827ae..b5a41375 100644 --- a/4ed_render_target.h +++ b/4ed_render_target.h @@ -34,7 +34,8 @@ struct Render_Target{ Render_Free_Texture *free_texture_first; Render_Free_Texture *free_texture_last; - Partition buffer; + // TODO(allen): rewrite render system to work on an arena + Cursor buffer; }; #endif diff --git a/4ed_system.h b/4ed_system.h index 1d79c4c0..0814e184 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -9,6 +9,8 @@ // TOP +// TODO(allen): rewrite using new arenas and strings!!!!! rewrite rewrite rewrite rewrite rewrite + #if !defined(FCODER_SYSTEM_INTERFACE_H) #define FCODER_SYSTEM_INTERFACE_H @@ -31,7 +33,7 @@ typedef Sys_Set_File_List_Sig(System_Set_File_List); typedef Sys_Get_Canonical_Sig(System_Get_Canonical); // file load/save -#define Sys_Quick_File_Attributes_Sig(name) File_Attributes name(String file_name) +#define Sys_Quick_File_Attributes_Sig(name) File_Attributes name(String_Const_u8 file_name) typedef Sys_Quick_File_Attributes_Sig(System_Quick_File_Attributes); #define Sys_Load_Handle_Sig(name) b32 name(char *filename, Plat_Handle *handle_out) @@ -76,7 +78,7 @@ typedef Sys_Wake_Up_Timer_Set_Sig(System_Wake_Up_Timer_Set); typedef Sys_Wake_Up_Timer_Check_Sig(System_Wake_Up_Timer_Check); // clipboard -#define Sys_Post_Clipboard_Sig(name) void name(String str) +#define Sys_Post_Clipboard_Sig(name) void name(String_Const_u8 str) typedef Sys_Post_Clipboard_Sig(System_Post_Clipboard); // cli diff --git a/4ed_text_layout.cpp b/4ed_text_layout.cpp index 0f660a78..af994ff4 100644 --- a/4ed_text_layout.cpp +++ b/4ed_text_layout.cpp @@ -9,10 +9,11 @@ // TOP +// TODO(allen): REWRITE REWRITE REWRITE!!! internal void text_layout_init(Application_Links *app, Text_Layout_Container *container){ block_zero_struct(container); - container->node_arena = make_arena(app); + container->node_arena = make_arena_app_links(app); } internal Text_Layout* diff --git a/4ed_view.cpp b/4ed_view.cpp index 22a7557b..8be6ed91 100644 --- a/4ed_view.cpp +++ b/4ed_view.cpp @@ -146,7 +146,7 @@ view_cursor_limits(Models *models, View *view){ } limits.min = 0; } - limits.max = clamp_bottom(0, limits.max); + limits.max = clamp_bot(0, limits.max); limits.min = clamp(0, limits.min, limits.max); limits.delta = clamp_top(line_height*5, (limits.max - limits.min + 1)/2); return(limits); @@ -155,8 +155,8 @@ view_cursor_limits(Models *models, View *view){ internal i32 view_compute_max_target_y_from_bottom_y(Models *models, View *view, f32 max_item_y){ i32 line_height = view->line_height; - f32 height = clamp_bottom((f32)line_height, view_height(models, view)); - f32 max_target_y = clamp_bottom(0.f, max_item_y - height*0.5f); + f32 height = clamp_bot((f32)line_height, view_height(models, view)); + f32 max_target_y = clamp_bot(0.f, max_item_y - height*0.5f); return(ceil32(max_target_y)); } @@ -200,7 +200,7 @@ view_move_view_to_cursor(System_Functions *system, Models *models, View *view, G target_x = cursor.x - max_x/2; } else if (cursor.x < target_x){ - target_x = clamp_bottom(0, cursor.x - max_x/2); + target_x = clamp_bot(0, cursor.x - max_x/2); } if (target_x != scroll_vars.target_x || target_y != scroll_vars.target_y){ @@ -474,8 +474,9 @@ finalize_color(Color_Table color_table, int_color color){ return(color_argb); } -internal void -get_visual_markers(Partition *arena, Dynamic_Workspace *workspace, Range range, Buffer_ID buffer_id, i32 view_index, Color_Table color_table){ +internal Render_Marker_List +get_visual_markers(Arena *arena, Dynamic_Workspace *workspace, Range range, Buffer_ID buffer_id, i32 view_index, Color_Table color_table){ + Render_Marker_List list = {}; View_ID view_id = view_index + 1; for (Managed_Buffer_Markers_Header *node = workspace->buffer_markers_list.first; node != 0; @@ -519,12 +520,14 @@ get_visual_markers(Partition *arena, Dynamic_Workspace *workspace, Range range, i < take_count_per_step && marker < marker_one_past_last; marker += 1, i += 1){ if (range.first <= marker->pos && marker->pos <= range.one_past_last){ - Render_Marker *render_marker = push_array(arena, Render_Marker, 1); - render_marker->type = type; - render_marker->pos = marker->pos; - render_marker->brush = brush; - render_marker->one_past_last = marker->pos; - render_marker->priority = priority; + Render_Marker_Node *new_node = push_array(arena, Render_Marker_Node, 1); + sll_queue_push(list.first, list.last, new_node); + list.count += 1; + new_node->render_marker.type = type; + new_node->render_marker.pos = marker->pos; + new_node->render_marker.brush = brush; + new_node->render_marker.one_past_last = marker->pos; + new_node->render_marker.priority = priority; } } } @@ -556,12 +559,14 @@ get_visual_markers(Partition *arena, Dynamic_Workspace *workspace, Range range, continue; } - Render_Marker *render_marker = push_array(arena, Render_Marker, 1); - render_marker->type = type; - render_marker->pos = range_b.min; - render_marker->brush = brush; - render_marker->one_past_last = range_b.max; - render_marker->priority = priority; + Render_Marker_Node *new_node = push_array(arena, Render_Marker_Node, 1); + sll_queue_push(list.first, list.last, new_node); + list.count += 1; + new_node->render_marker.type = type; + new_node->render_marker.pos = range_b.min; + new_node->render_marker.brush = brush; + new_node->render_marker.one_past_last = range_b.max; + new_node->render_marker.priority = priority; } } } @@ -569,6 +574,7 @@ get_visual_markers(Partition *arena, Dynamic_Workspace *workspace, Range range, } } } + return(list); } internal i32 @@ -799,7 +805,7 @@ render_loaded_file_in_view__inner(Models *models, Render_Target *target, View *v i32_Rect rect, Full_Cursor render_cursor, Range on_screen_range, Buffer_Render_Item *items, i32 item_count){ Editing_File *file = view->file; - Partition *part = &models->mem.part; + Arena *scratch = &models->mem.arena; Color_Table color_table = models->color_table; Assert(file != 0); @@ -812,14 +818,16 @@ render_loaded_file_in_view__inner(Models *models, Render_Target *target, View *v Face_ID font_id = file->settings.font_id; // NOTE(allen): Get visual markers - Render_Marker_Array markers = {}; - markers.markers = push_array(part, Render_Marker, 0); + Render_Marker_List markers_list = {}; { Lifetime_Object *lifetime_object = file->lifetime_object; Buffer_ID buffer_id = file->id.id; i32 view_index = view_get_index(&models->live_set, view); - get_visual_markers(part, &lifetime_object->workspace, on_screen_range, buffer_id, view_index, color_table); + Render_Marker_List list = get_visual_markers(scratch, &lifetime_object->workspace, on_screen_range, buffer_id, view_index, color_table); + + sll_queue_push_multiple(markers_list.first, markers_list.last, list.first, list.last); + markers_list.count += list.count; i32 key_count = lifetime_object->key_count; i32 key_index = 0; @@ -829,12 +837,24 @@ render_loaded_file_in_view__inner(Models *models, Render_Target *target, View *v i32 local_count = clamp_top(lifetime_key_reference_per_node, key_count - key_index); for (i32 i = 0; i < local_count; i += 1){ Lifetime_Key *key = node->keys[i]; - get_visual_markers(part, &key->dynamic_workspace, on_screen_range, buffer_id, view_index, color_table); + list = get_visual_markers(scratch, &key->dynamic_workspace, on_screen_range, buffer_id, view_index, color_table); + sll_queue_push_multiple(markers_list.first, markers_list.last, list.first, list.last); + markers_list.count += list.count; } key_index += local_count; } } - markers.count = (i32)(push_array(part, Render_Marker, 0) - markers.markers); + + Render_Marker_Array markers = {}; + markers.count = markers_list.count; + markers.markers = push_array(scratch, Render_Marker, markers.count); + i32 marker_index = 0; + for (Render_Marker_Node *node = markers_list.first; + node != 0; + node = node->next){ + markers.markers[marker_index] = node->render_marker; + marker_index += 1; + } // NOTE(allen): Sort visual markers by position Range marker_segments[4]; @@ -859,10 +879,10 @@ render_loaded_file_in_view__inner(Models *models, Render_Target *target, View *v line_range_markers.markers = markers.markers + marker_segments[3].first; line_range_markers.count = marker_segments[3].one_past_last - marker_segments[3].first; - Render_Range_Record *range_stack = push_array(part, Render_Range_Record, range_markers.count); + Render_Range_Record *range_stack = push_array(scratch, Render_Range_Record, range_markers.count); i32 range_stack_top = -1; - Render_Range_Record *line_range_stack = push_array(part, Render_Range_Record, line_range_markers.count); + Render_Range_Record *line_range_stack = push_array(scratch, Render_Range_Record, line_range_markers.count); i32 line_range_stack_top = -1; i32 *line_starts = file->state.buffer.line_starts; @@ -1125,7 +1145,7 @@ render_loaded_file_in_view__inner(Models *models, Render_Target *target, View *v default: { - InvalidCodePath; + InvalidPath; }break; } } diff --git a/4ed_view.h b/4ed_view.h index 48742ab9..f4d3389f 100644 --- a/4ed_view.h +++ b/4ed_view.h @@ -111,12 +111,14 @@ struct File_Bar{ Face_ID font_id; }; +#if 0 struct Style_Color_Edit{ Style_Tag target; Style_Tag fore; Style_Tag back; - String text; + String_Const_u8 text; }; +#endif struct Single_Line_Input_Step{ b8 hit_newline; @@ -136,7 +138,7 @@ enum Single_Line_Input_Type{ struct Single_Line_Mode{ Single_Line_Input_Type type; - String *string; + String_Const_u8 *string; Hot_Directory *hot_directory; b32 fast_folder_select; }; @@ -162,6 +164,17 @@ struct Render_Marker{ i32 priority; }; +struct Render_Marker_Node{ + Render_Marker_Node *next; + Render_Marker render_marker; +}; + +struct Render_Marker_List{ + Render_Marker_Node *first; + Render_Marker_Node *last; + i32 count; +}; + struct Render_Range_Record{ Render_Marker_Brush brush; i32 one_past_last; diff --git a/4ed_working_set.cpp b/4ed_working_set.cpp index 2014b2d2..39d35efd 100644 --- a/4ed_working_set.cpp +++ b/4ed_working_set.cpp @@ -9,40 +9,6 @@ // TOP -// TODO(allen): Find a real home for this... string library needs a makeover. -internal String -push_string(Partition *part, char *str, i32 len){ - char *space = (char*)push_array(part, char, len + 1); - memcpy(space, str, len); - space[len] = 0; - String string = make_string_cap(space, len, len + 1); - return(string); -} - -internal String -push_string(Partition *part, String str){ - String res = push_string(part, str.str, str.size); - return(res); -} - -internal String -push_string(Partition *part, char *str, i32 len, i32 cap){ - cap = clamp_bottom(len + 1, cap); - char *space = (char*)push_array(part, char, cap); - memcpy(space, str, len); - space[len] = 0; - String string = make_string_cap(space, len, cap); - return(string); -} - -internal String -push_string(Partition *part, String str, i32 cap){ - String res = push_string(part, str.str, str.size, cap); - return(res); -} - -//////////////////////////////// - internal void working_set_extend_memory(Working_Set *working_set, Editing_File *new_space, i16 number_of_files){ Assert(working_set->array_count < working_set->array_max); @@ -148,23 +114,27 @@ working_set_get_active_file(Working_Set *working_set, Buffer_ID id){ return(working_set_get_active_file(working_set, to_file_id(id))); } +// TODO(allen): REWRITE all of working set internal void -working_set_init(System_Functions *system, Working_Set *working_set, Partition *partition, Heap *heap){ +working_set_init(System_Functions *system, Working_Set *working_set, Arena *arena, Heap *heap){ i16 init_count = 16; i16 array_init_count = 256; dll_init_sentinel(&working_set->free_sentinel); dll_init_sentinel(&working_set->used_sentinel); - dll_init_sentinel(&working_set->edit_finished_list); + working_set->edit_finished_list_first = 0; + working_set->edit_finished_list_last = 0; + working_set->edit_finished_count = 0; + working_set->time_of_next_edit_finished_signal = 0; working_set->edit_finished_timer = system->wake_up_timer_create(); working_set->do_not_mark_edits = false; working_set->array_max = array_init_count; - working_set->file_arrays = push_array(partition, File_Array, array_init_count); + working_set->file_arrays = push_array(arena, File_Array, array_init_count); - Editing_File *files = push_array(partition, Editing_File, init_count); + Editing_File *files = push_array(arena, Editing_File, init_count); working_set_extend_memory(working_set, files, init_count); // TODO(NAME): do(clean up the rest of the null_file) @@ -217,7 +187,7 @@ working_set__grow_if_needed(Table *table, Heap *heap, void *arg, Hash_Function * } internal Editing_File* -working_set_contains_basic(Working_Set *working_set, Table *table, String name){ +working_set_contains_basic(Working_Set *working_set, Table *table, String_Const_u8 name){ Editing_File *result = 0; File_Name_Entry *entry = (File_Name_Entry*) @@ -230,7 +200,7 @@ working_set_contains_basic(Working_Set *working_set, Table *table, String name){ } internal b32 -working_set_add_basic(Heap *heap, Working_Set *working_set, Table *table, Editing_File *file, String name){ +working_set_add_basic(Heap *heap, Working_Set *working_set, Table *table, Editing_File *file, String_Const_u8 name){ working_set__grow_if_needed(table, heap, 0, tbl_string_hash, tbl_string_compare); File_Name_Entry entry; @@ -241,40 +211,40 @@ working_set_add_basic(Heap *heap, Working_Set *working_set, Table *table, Editin } internal void -working_set_remove_basic(Working_Set *working_set, Table *table, String name){ +working_set_remove_basic(Working_Set *working_set, Table *table, String_Const_u8 name){ table_remove_match(table, &name, 0, tbl_string_hash, tbl_string_compare); } internal Editing_File* -working_set_contains_canon(Working_Set *working_set, String name){ +working_set_contains_canon(Working_Set *working_set, String_Const_u8 name){ Editing_File *result = working_set_contains_basic(working_set, &working_set->canon_table, name); return(result); } internal b32 -working_set_canon_add(Heap *heap, Working_Set *working_set, Editing_File *file, String name){ +working_set_canon_add(Heap *heap, Working_Set *working_set, Editing_File *file, String_Const_u8 name){ b32 result = working_set_add_basic(heap,working_set, &working_set->canon_table, file, name); return(result); } internal void -working_set_canon_remove(Working_Set *working_set, String name){ +working_set_canon_remove(Working_Set *working_set, String_Const_u8 name){ working_set_remove_basic(working_set, &working_set->canon_table, name); } internal Editing_File* -working_set_contains_name(Working_Set *working_set, String name){ +working_set_contains_name(Working_Set *working_set, String_Const_u8 name){ return(working_set_contains_basic(working_set, &working_set->name_table, name)); } internal b32 -working_set_add_name(Heap *heap, Working_Set *working_set, Editing_File *file, String name){ +working_set_add_name(Heap *heap, Working_Set *working_set, Editing_File *file, String_Const_u8 name){ b32 result = working_set_add_basic(heap, working_set, &working_set->name_table, file, name); return(result); } internal void -working_set_remove_name(Working_Set *working_set, String name){ +working_set_remove_name(Working_Set *working_set, String_Const_u8 name){ working_set_remove_basic(working_set, &working_set->name_table, name); } @@ -285,7 +255,7 @@ get_file_from_identifier(System_Functions *system, Working_Set *working_set, Buf file = working_set_get_active_file(working_set, buffer.id); } else if (buffer.name != 0){ - String name = make_string(buffer.name, buffer.name_len); + String_Const_u8 name = SCu8(buffer.name, buffer.name_len); file = working_set_contains_name(working_set, name); } return(file); @@ -294,8 +264,8 @@ get_file_from_identifier(System_Functions *system, Working_Set *working_set, Buf //////////////////////////////// // TODO(allen): Bring the clipboard fully to the custom side. -internal String* -working_set_next_clipboard_string(Heap *heap, Working_Set *working, i32 str_size){ +internal String_Const_u8* +working_set_next_clipboard_string(Heap *heap, Working_Set *working, umem str_size){ i32 clipboard_current = working->clipboard_current; if (working->clipboard_size == 0){ clipboard_current = 0; @@ -310,29 +280,20 @@ working_set_next_clipboard_string(Heap *heap, Working_Set *working, i32 str_size working->clipboard_size = clipboard_current + 1; } } - String *result = &working->clipboards[clipboard_current]; + String_Const_u8 *result = &working->clipboards[clipboard_current]; working->clipboard_current = clipboard_current; working->clipboard_rolling = clipboard_current; if (result->str != 0){ - if (result->memory_size <= str_size){ - heap_free(heap, result->str); - char *new_str = (char*)heap_allocate(heap, str_size + 1); - *result = make_string_cap(new_str, 0, str_size + 1); - } - else{ - result->size = 0; - } - } - else{ - char *new_str = (char*)heap_allocate(heap, str_size + 1); - *result = make_string_cap(new_str, 0, str_size + 1); + heap_free(heap, result->str); } + u8 *new_str = (u8*)heap_allocate(heap, (i32)(str_size + 1)); + *result = SCu8(new_str, str_size); return(result); } -internal String* +internal String_Const_u8* working_set_clipboard_index(Working_Set *working, i32 index){ - String *result = 0; + String_Const_u8 *result = 0; i32 size = working->clipboard_size; i32 current = working->clipboard_current; if (index >= 0 && size > 0){ @@ -344,9 +305,9 @@ working_set_clipboard_index(Working_Set *working, i32 index){ return(result); } -internal String* +internal String_Const_u8* working_set_clipboard_head(Working_Set *working){ - String *result = 0; + String_Const_u8 *result = 0; if (working->clipboard_size > 0){ working->clipboard_rolling = 0; result = working_set_clipboard_index(working, working->clipboard_rolling); @@ -354,9 +315,9 @@ working_set_clipboard_head(Working_Set *working){ return(result); } -internal String* +internal String_Const_u8* working_set_clipboard_roll_down(Working_Set *working){ - String *result = 0; + String_Const_u8 *result = 0; if (working->clipboard_size > 0){ i32 clipboard_index = working->clipboard_rolling; ++clipboard_index; @@ -369,151 +330,168 @@ working_set_clipboard_roll_down(Working_Set *working){ //////////////////////////////// internal b32 -get_canon_name(System_Functions *system, String file_name, Editing_File_Name *canon_name){ - canon_name->name = make_fixed_width_string(canon_name->name_); - canon_name->name.size = system->get_canonical(file_name.str, file_name.size, canon_name->name.str, canon_name->name.memory_size); - terminate_with_null(&canon_name->name); - b32 result = (canon_name->name.size != 0); - return(result); +get_canon_name(System_Functions *system, String_Const_u8 file_name, Editing_File_Name *canon_name){ + canon_name->name_size = system->get_canonical((char*)file_name.str, (u32)file_name.size, + (char*)canon_name->name_space, sizeof(canon_name->name_space)); + file_name_terminate(canon_name); + return(canon_name->name_size > 0); } internal void -file_bind_file_name(System_Functions *system, Heap *heap, Working_Set *working_set, Editing_File *file, String canon_file_name){ - Assert(file->unique_name.name.size == 0); - Assert(file->canon.name.size == 0); - file->canon.name = make_fixed_width_string(file->canon.name_); - copy(&file->canon.name, canon_file_name); - terminate_with_null(&file->canon.name); - system->add_listener(file->canon.name.str); - if (!working_set_canon_add(heap, working_set, file, file->canon.name)){ - InvalidCodePath; - } +file_bind_file_name(System_Functions *system, Heap *heap, Working_Set *working_set, Editing_File *file, String_Const_u8 canon_file_name){ + Assert(file->unique_name.name_size == 0); + Assert(file->canon.name_size == 0); + umem size = canon_file_name.size; + size = clamp_top(size, sizeof(file->canon.name_space) - 1); + file->canon.name_size = size; + block_copy(file->canon.name_space, canon_file_name.str, size); + file_name_terminate(&file->canon); + system->add_listener((char*)file->canon.name_space); + b32 result = working_set_canon_add(heap, working_set, file, string_from_file_name(&file->canon)); + Assert(result); } internal void buffer_unbind_file(System_Functions *system, Working_Set *working_set, Editing_File *file){ - Assert(file->unique_name.name.size == 0); - Assert(file->canon.name.size != 0); - - system->remove_listener(file->canon.name_); - working_set_canon_remove(working_set, file->canon.name); - file->canon.name.size = 0; + Assert(file->unique_name.name_size == 0); + Assert(file->canon.name_size != 0); + system->remove_listener((char*)file->canon.name_space); + working_set_canon_remove(working_set, string_from_file_name(&file->canon)); + file->canon.name_size = 0; } internal b32 -buffer_name_has_conflict(Working_Set *working_set, String base_name){ +buffer_name_has_conflict(Working_Set *working_set, String_Const_u8 base_name){ b32 hit_conflict = false; - Node *used_nodes = &working_set->used_sentinel; for (Node *node = used_nodes->next; node != used_nodes; node = node->next){ Editing_File *file_ptr = CastFromMember(Editing_File, main_chain_node, node); - if (file_is_ready(file_ptr) && match(base_name, file_ptr->unique_name.name)){ + if (file_is_ready(file_ptr) && string_match(base_name, string_from_file_name(&file_ptr->unique_name))){ hit_conflict = true; break; } } - return(hit_conflict); } internal void -buffer_resolve_name_low_level(Working_Set *working_set, Editing_File_Name *name, String base_name){ - Assert(name->name.str != 0); - - copy(&name->name, base_name); - - i32 original_len = name->name.size; - i32 file_x = 0; +buffer_resolve_name_low_level(Arena *scratch, Working_Set *working_set, Editing_File_Name *name, String_Const_u8 base_name){ + umem size = base_name.size; + size = clamp_top(size, sizeof(name->name_space)); + block_copy(name->name_space, base_name.str, size); + String_u8 string = Su8(name->name_space, size, sizeof(name->name_space)); + umem original_size = string.size; + u64 file_x = 0; for (b32 hit_conflict = true; hit_conflict;){ - hit_conflict = buffer_name_has_conflict(working_set, name->name); + hit_conflict = buffer_name_has_conflict(working_set, string.string); if (hit_conflict){ - ++file_x; - name->name.size = original_len; - append(&name->name, " ("); - append_int_to_str(&name->name, file_x); - append(&name->name, ")"); + file_x += 1; + string.size = original_size; + Temp_Memory temp = begin_temp(scratch); + String_Const_u8 int_str = string_from_integer(scratch, file_x, 10); + string_append(&string, string_u8_litexpr(" (")); + string_append(&string, int_str); + string_append(&string, string_u8_litexpr(")")); + end_temp(temp); } } + name->name_size = string.size; } internal void -buffer_bind_name_low_level(Heap *heap, Working_Set *working_set, Editing_File *file, String base_name, String name){ - Assert(file->base_name.name.size == 0); - Assert(file->unique_name.name.size == 0); +buffer_bind_name_low_level(Arena *scratch, Heap *heap, Working_Set *working_set, Editing_File *file, String_Const_u8 base_name, String_Const_u8 name){ + Assert(file->base_name.name_size == 0); + Assert(file->unique_name.name_size == 0); Editing_File_Name new_name = {}; - new_name.name = make_fixed_width_string(new_name.name_); - buffer_resolve_name_low_level(working_set, &new_name, name); + buffer_resolve_name_low_level(scratch, working_set, &new_name, name); - file->base_name.name = make_fixed_width_string(file->base_name.name_); - copy(&file->base_name.name, base_name); - - file->unique_name.name = make_fixed_width_string(file->unique_name.name_); - copy(&file->unique_name.name, new_name.name); - - if (!working_set_add_name(heap, working_set, file, file->unique_name.name)){ - InvalidCodePath; + { + umem size = base_name.size; + size = clamp_top(size, sizeof(file->base_name.name_space)); + block_copy(file->base_name.name_space, base_name.str, size); + file->base_name.name_size = size; } + + { + umem size = new_name.name_size; + block_copy(file->unique_name.name_space, new_name.name_space, size); + file->unique_name.name_size = size; + } + + b32 result = working_set_add_name(heap, working_set, file, string_from_file_name(&file->unique_name)); + Assert(result); } internal void buffer_unbind_name_low_level(Working_Set *working_set, Editing_File *file){ - Assert(file->base_name.name.size != 0); - Assert(file->unique_name.name.size != 0); - working_set_remove_name(working_set, file->unique_name.name); - file->base_name.name.size = 0; - file->unique_name.name.size = 0; + Assert(file->base_name.name_size != 0); + Assert(file->unique_name.name_size != 0); + working_set_remove_name(working_set, string_from_file_name(&file->unique_name)); + file->base_name.name_size = 0; + file->unique_name.name_size = 0; } internal void -buffer_bind_name(Models *models, Heap *heap, Partition *scratch, Working_Set *working_set, Editing_File *file, String base_name){ - Temp_Memory temp = begin_temp_memory(scratch); +buffer_bind_name(Models *models, Heap *heap, Arena *scratch, Working_Set *working_set, Editing_File *file, String_Const_u8 base_name){ + Temp_Memory temp = begin_temp(scratch); // List of conflict files. - Editing_File **conflict_file_ptrs = push_array(scratch, Editing_File*, 0); + struct Node_Ptr{ + Node_Ptr *next; + Editing_File *file_ptr; + }; + Node_Ptr *conflict_first = 0; + Node_Ptr *conflict_last = 0; i32 conflict_count = 0; { - Editing_File **new_file_ptr = push_array(scratch, Editing_File*, 1); - *new_file_ptr = file; - ++conflict_count; + Node_Ptr *node = push_array(scratch, Node_Ptr, 1); + sll_queue_push(conflict_first, conflict_last, node); + node->file_ptr = file; + conflict_count += 1; } Node *used_nodes = &working_set->used_sentinel; - for (Node *node = used_nodes->next; node != used_nodes; node = node->next){ + for (Node *node = used_nodes->next; + node != used_nodes; + node = node->next){ Editing_File *file_ptr = CastFromMember(Editing_File, main_chain_node, node); - if (file_is_ready(file_ptr) && match(base_name, file_ptr->base_name.name)){ - Editing_File **new_file_ptr = push_array(scratch, Editing_File*, 1); - *new_file_ptr = file_ptr; - ++conflict_count; + if (file_is_ready(file_ptr) && string_match(base_name, string_from_file_name(&file_ptr->base_name))){ + Node_Ptr *new_node = push_array(scratch, Node_Ptr, 1); + sll_queue_push(conflict_first, conflict_last, new_node); + new_node->file_ptr = file_ptr; + conflict_count += 1; } } // Fill conflict array. Buffer_Name_Conflict_Entry *conflicts = push_array(scratch, Buffer_Name_Conflict_Entry, conflict_count); - for (i32 i = 0; i < conflict_count; ++i){ - Editing_File *file_ptr = conflict_file_ptrs[i]; - Buffer_Name_Conflict_Entry *entry = &conflicts[i]; - entry->buffer_id = file_ptr->id.id; - - String file_name = push_string(scratch, file_ptr->canon.name); - entry->file_name = file_name.str; - entry->file_name_len = file_name.size; - - String term_base_name = push_string(scratch, base_name); - entry->base_name = term_base_name.str; - entry->base_name_len = term_base_name.size; - - String b = base_name; - if (i > 0){ - b = file_ptr->unique_name.name; + { + i32 i = 0; + for (Node_Ptr *node = conflict_first; + node != 0; + node = node->next, i += 1){ + Editing_File *file_ptr = node->file_ptr; + Buffer_Name_Conflict_Entry *entry = &conflicts[i]; + entry->buffer_id = file_ptr->id.id; + + entry->file_name = string_copy(scratch, string_from_file_name(&file_ptr->canon)); + entry->base_name = string_copy(scratch, base_name); + + String_Const_u8 b = base_name; + if (i > 0){ + b = string_from_file_name(&file_ptr->unique_name); + } + umem unique_name_capacity = 256; + u8 *unique_name_buffer = push_array(scratch, u8, unique_name_capacity); + Assert(b.size <= unique_name_capacity); + block_copy(unique_name_buffer, b.str, b.size); + entry->unique_name_in_out = unique_name_buffer; + entry->unique_name_len_in_out = b.size; + entry->unique_name_capacity = unique_name_capacity; } - i32 unique_name_capacity = 256; - String unique_name = push_string(scratch, b, unique_name_capacity); - entry->unique_name_in_out = unique_name.str; - entry->unique_name_len_in_out = unique_name.size; - entry->unique_name_capacity = unique_name_capacity; } // Get user's resolution data. @@ -522,20 +500,31 @@ buffer_bind_name(Models *models, Heap *heap, Partition *scratch, Working_Set *wo } // Re-bind all of the files - for (i32 i = 0; i < conflict_count; ++i){ - Editing_File *file_ptr = conflict_file_ptrs[i]; - if (file_ptr->unique_name.name.str != 0){ - buffer_unbind_name_low_level(working_set, file_ptr); + { + i32 i = 0; + for (Node_Ptr *node = conflict_first; + node != 0; + node = node->next, i += 1){ + Editing_File *file_ptr = node->file_ptr; + if (file_ptr->unique_name.name_size > 0){ + buffer_unbind_name_low_level(working_set, file_ptr); + } } } - for (i32 i = 0; i < conflict_count; ++i){ - Editing_File *file_ptr = conflict_file_ptrs[i]; - Buffer_Name_Conflict_Entry *entry = &conflicts[i]; - String unique_name = make_string(entry->unique_name_in_out, entry->unique_name_len_in_out); - buffer_bind_name_low_level(heap, working_set, file_ptr, base_name, unique_name); + + { + i32 i = 0; + for (Node_Ptr *node = conflict_first; + node != 0; + node = node->next, i += 1){ + Editing_File *file_ptr = node->file_ptr; + Buffer_Name_Conflict_Entry *entry = &conflicts[i]; + String_Const_u8 unique_name = SCu8(entry->unique_name_in_out, entry->unique_name_len_in_out); + buffer_bind_name_low_level(scratch, heap, working_set, file_ptr, base_name, unique_name); + } } - end_temp_memory(temp); + end_temp(temp); } //////////////////////////////// @@ -571,18 +560,31 @@ file_mark_edit_finished(Working_Set *working_set, Editing_File *file){ // This current method only works for synchronous calls, asynchronous calls will get the // wrong do_not_mark_edits value. if (!working_set->do_not_mark_edits){ - if (file->edit_finished_mark_node.next == 0){ - dll_insert_back(&working_set->edit_finished_list, &file->edit_finished_mark_node); + if (!file->edit_finished_marked == 0){ + zdll_push_back(working_set->edit_finished_list_first, + working_set->edit_finished_list_last, + &file->edit_finished_mark_node); + file->edit_finished_marked = true; + working_set->edit_finished_count += 1; } } } internal b32 -file_unmark_edit_finished(Editing_File *file){ +file_unmark_edit_finished(Working_Set *working_set, Editing_File *file){ b32 result = false; - if (file->edit_finished_mark_node.next != 0){ - dll_remove(&file->edit_finished_mark_node); - result = true; + if (!working_set->do_not_mark_edits){ + if (file->edit_finished_marked){ + zdll_remove(working_set->edit_finished_list_first, + working_set->edit_finished_list_last, + &file->edit_finished_mark_node); + file->edit_finished_mark_node.next = 0; + file->edit_finished_mark_node.prev = 0; + file->edit_finished_marked = false; + working_set->edit_finished_count -= 1; + + result = true; + } } return(result); } diff --git a/4ed_working_set.h b/4ed_working_set.h index 7b3330c0..333f8d84 100644 --- a/4ed_working_set.h +++ b/4ed_working_set.h @@ -12,11 +12,6 @@ #if !defined(FRED_WORKING_SET_H) #define FRED_WORKING_SET_H -struct Non_File_Table_Entry{ - String name; - Buffer_Slot_ID id; -}; - struct File_Array{ Editing_File *files; i32 size; @@ -32,7 +27,10 @@ struct Working_Set{ Node free_sentinel; Node used_sentinel; - Node edit_finished_list; + Node *edit_finished_list_first; + Node *edit_finished_list_last; + i32 edit_finished_count; + u64 time_of_next_edit_finished_signal; Plat_Handle edit_finished_timer; b32 do_not_mark_edits; @@ -41,7 +39,7 @@ struct Working_Set{ Table name_table; // TODO(allen): do(update clipboard system to exist fully in the custom layer) - String clipboards[64]; + String_Const_u8 clipboards[64]; i32 clipboard_size; i32 clipboard_max_size; i32 clipboard_current; @@ -54,7 +52,7 @@ struct Working_Set{ }; struct File_Name_Entry{ - String name; + String_Const_u8 name; Buffer_Slot_ID id; }; @@ -62,7 +60,7 @@ internal void file_mark_edit_finished(Working_Set *working_set, Editing_File *file); internal b32 -file_unmark_edit_finished(Editing_File *file); +file_unmark_edit_finished(Working_Set *working_set, Editing_File *file); #endif diff --git a/build.bat b/build.bat index f284209d..04f67d53 100644 --- a/build.bat +++ b/build.bat @@ -1,6 +1,6 @@ @echo off -set opts=/W4 /wd4310 /wd4100 /wd4201 /wd4505 /wd4996 /wd4127 /wd4510 /wd4512 /wd4610 /wd4390 /WX +set opts=/W4 /wd4310 /wd4100 /wd4201 /wd4505 /wd4996 /wd4127 /wd4510 /wd4512 /wd4610 /wd4390 /wd4189 /WX set opts=%opts% /GR- /EHa- /nologo /FC set FirstError=0 diff --git a/build_site.bat b/build_site.bat deleted file mode 100644 index c2f8774c..00000000 --- a/build_site.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off - -build.bat /DSITE_BUILD \ No newline at end of file diff --git a/build_site.sh b/build_site.sh deleted file mode 100755 index 38757812..00000000 --- a/build_site.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -chmod 777 build.sh -./build.sh "-DSITE_BUILD" - diff --git a/build_string.bat b/build_string.bat deleted file mode 100644 index 23ee197d..00000000 --- a/build_string.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off - -build.bat /DSTRING_BUILD diff --git a/build_string.sh b/build_string.sh deleted file mode 100755 index 7a9fd107..00000000 --- a/build_string.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -chmod 777 build.sh -./build.sh "-DSTRING_BUILD" - diff --git a/buildsuper_x64.bat b/buildsuper_x64.bat index af44efc9..496d96dc 100644 --- a/buildsuper_x64.bat +++ b/buildsuper_x64.bat @@ -30,6 +30,8 @@ metadata_generator -R "%code_home%" "%cd%\\%preproc_file%" call cl /I"%code_home%" %opts% %mode% %src% /Fecustom_4coder %build_dll% %exports% +exit + REM file spammation preventation del metadata_generator* del *.exp diff --git a/meta/4ed_build.cpp b/meta/4ed_build.cpp index 16ffd088..1a689d66 100644 --- a/meta/4ed_build.cpp +++ b/meta/4ed_build.cpp @@ -11,12 +11,14 @@ //#define FM_PRINT_COMMANDS -#include "../4ed_defines.h" #include "../4coder_base_types.h" # include "../4coder_lib/4coder_arena.h" # include "../4coder_lib/4coder_arena.cpp" + +#if 0 # define FSTRING_IMPLEMENTATION # include "../4coder_lib/4coder_string.h" +#endif #define FTECH_FILE_MOVING_IMPLEMENTATION #include "4ed_file_moving.h" @@ -55,19 +57,19 @@ char *compiler_names[] = { "gcc", }; -#if defined(IS_WINDOWS) +#if OS_WINDOWS # define This_OS Platform_Windows -#elif defined(IS_LINUX) +#elif OS_LINUX # define This_OS Platform_Linux -#elif defined(IS_MAC) +#elif OS_MAC # define This_OS Platform_Mac #else # error This platform is not enumerated. #endif -#if defined(IS_CL) +#if COMPILER_CL # define This_Compiler Compiler_CL -#elif defined(IS_GCC) +#elif COMPILER_GCC # define This_Compiler Compiler_GCC #else # error This compilers is not enumerated. @@ -165,20 +167,20 @@ enum{ }; internal char** -get_defines_from_flags(Partition *part, u32 flags){ +get_defines_from_flags(Arena *arena, u32 flags){ char **result = 0; - if (flags & KEEP_ASSERT){ - result = fm_list(part, fm_list_one_item(part, "FRED_KEEP_ASSERT"), result); + if (HasFlag(flags, KEEP_ASSERT)){ + result = fm_list(arena, fm_list_one_item(arena, "FRED_KEEP_ASSERT"), result); } - if (flags & INTERNAL){ - result = fm_list(part, fm_list_one_item(part, "FRED_INTERNAL"), result); + if (HasFlag(flags, INTERNAL)){ + result = fm_list(arena, fm_list_one_item(arena, "FRED_INTERNAL"), result); } - if (flags & SUPER){ - result = fm_list(part, fm_list_one_item(part, "FRED_SUPER"), result); + if (HasFlag(flags, SUPER)){ + result = fm_list(arena, fm_list_one_item(arena, "FRED_SUPER"), result); } - if (flags & LOG){ + if (HasFlag(flags, LOG)){ char *log_defines[] = { "USE_LOG", "USE_LOGF", 0}; - result = fm_list(part, log_defines, result); + result = fm_list(arena, log_defines, result); } return(result); } @@ -187,12 +189,12 @@ get_defines_from_flags(Partition *part, u32 flags){ // build implementation: cl // -#if defined(IS_CL) +#if COMPILER_CL #define CL_OPTS \ "-W4 -wd4310 -wd4100 -wd4201 -wd4505 -wd4996 " \ "-wd4127 -wd4510 -wd4512 -wd4610 -wd4390 " \ -"-wd4611 -WX -GR- -EHa- -nologo -FC" +"-wd4611 -wd4189 -WX -GR- -EHa- -nologo -FC" #define CL_LIBS_X64 \ "user32.lib winmm.lib gdi32.lib opengl32.lib comdlg32.lib " \ @@ -205,7 +207,7 @@ FOREIGN_WIN"\\x86\\freetype.lib" #define CL_ICON "..\\4coder-non-source\\res\\icon.res" internal void -build(Partition *part, u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, char *out_file, char **defines, char **exports, char **inc_folders){ +build(Arena *arena, u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, char *out_file, char **defines, char **exports, char **inc_folders){ Temp_Dir temp = fm_pushdir(out_path); Build_Line line; @@ -224,13 +226,13 @@ build(Partition *part, u32 flags, u32 arch, char *code_path, char **code_files, switch (arch){ case Arch_X64: fm_add_to_line(line, "-DFTECH_64_BIT"); break; case Arch_X86: fm_add_to_line(line, "-DFTECH_32_BIT"); break; - default: InvalidCodePath; + default: InvalidPath; } fm_add_to_line(line, "-I%s", code_path); if (inc_folders != 0){ for (u32 i = 0; inc_folders[i] != 0; ++i){ - char *str = fm_str(part, code_path, "/", inc_folders[i]); + char *str = fm_str(arena, code_path, "/", inc_folders[i]); fm_add_to_line(line, "-I%s", str); } } @@ -239,7 +241,7 @@ build(Partition *part, u32 flags, u32 arch, char *code_path, char **code_files, switch (arch){ case Arch_X64: fm_add_to_line(line, CL_LIBS_X64); break; case Arch_X86: fm_add_to_line(line, CL_LIBS_X86); break; - default: InvalidCodePath; + default: InvalidPath; } } @@ -262,7 +264,7 @@ build(Partition *part, u32 flags, u32 arch, char *code_path, char **code_files, if (defines != 0){ for (u32 i = 0; defines[i] != 0; ++i){ - char *define_flag = fm_str(part, "-D", defines[i]); + char *define_flag = fm_str(arena, "-D", defines[i]); fm_add_to_line(line, "%s", define_flag); } } @@ -277,7 +279,7 @@ build(Partition *part, u32 flags, u32 arch, char *code_path, char **code_files, switch (arch){ case Arch_X64: fm_add_to_line(line, "-MACHINE:X64"); break; case Arch_X86: fm_add_to_line(line, "-MACHINE:X86"); break; - default: InvalidCodePath; + default: InvalidPath; } if (flags & DEBUG_INFO){ @@ -288,7 +290,7 @@ build(Partition *part, u32 flags, u32 arch, char *code_path, char **code_files, Assert(exports != 0); fm_add_to_line(line, "-OPT:REF"); for (u32 i = 0; exports[i] != 0; ++i){ - char *str = fm_str(part, "-EXPORT:", exports[i]); + char *str = fm_str(arena, "-EXPORT:", exports[i]); fm_add_to_line(line, "%s", str); } } @@ -306,9 +308,9 @@ build(Partition *part, u32 flags, u32 arch, char *code_path, char **code_files, // build implementation: gcc // -#elif defined(IS_GCC) +#elif COMPILER_GCC -#if defined(IS_LINUX) +#if OS_LINUX # define GCC_OPTS \ "-Wno-write-strings " \ @@ -323,7 +325,7 @@ build(Partition *part, u32 flags, u32 arch, char *code_path, char **code_files, #define GCC_LIBS_X64 GCC_LIBS_COMMON #define GCC_LIBS_X86 GCC_LIBS_COMMON -#elif defined(IS_MAC) +#elif OS_MAC # define GCC_OPTS \ "-Wno-write-strings -Wno-deprecated-declarations " \ @@ -421,11 +423,9 @@ build(Partition *part, u32 flags, u32 arch, char *code_path, char **code_files, #endif internal void -build(Partition *part, u32 flags, u32 arch, char *code_path, char *code_file, char *out_path, char *out_file, char **defines, char **exports, char **inc_folders){ - char *code_files[2]; - code_files[0] = code_file; - code_files[1] = 0; - build(part, flags, arch, code_path, code_files, out_path, out_file, defines, exports, inc_folders); +build(Arena *arena, u32 flags, u32 arch, char *code_path, char *code_file, char *out_path, char *out_file, char **defines, char **exports, char **inc_folders){ + char **code_files = fm_list_one_item(arena, code_file); + build(arena, flags, arch, code_path, code_files, out_path, out_file, defines, exports, inc_folders); } // TODO(NAME): build metadata fully from C++ and eliminate build_metadata.bat and build_metadata.sh @@ -436,88 +436,88 @@ build_metadata(void){ } internal void -site_build(Partition *part, char *cdir, u32 flags){ +site_build(Arena *arena, char *cdir, u32 flags){ build_metadata(); { - char *file = fm_str(part, "site/4ed_sitegen.cpp"); - char *dir = fm_str(part, BUILD_DIR); + char *file = fm_str(arena, "site/4ed_sitegen.cpp"); + char *dir = fm_str(arena, BUILD_DIR); BEGIN_TIME_SECTION(); - build(part, OPTS | flags, Arch_X64, cdir, file, dir, "sitegen", get_defines_from_flags(part, flags), 0, includes); + build(arena, OPTS | flags, Arch_X64, cdir, file, dir, "sitegen", get_defines_from_flags(arena, flags), 0, includes); END_TIME_SECTION("build sitegen"); } if (prev_error == 0){ BEGIN_TIME_SECTION(); - char *cmd = fm_str(part, BUILD_DIR "/sitegen"); - char *code_dir = fm_str(part, "."); - char *asset_dir = fm_str(part, "../4coder-non-source/site_resources"); - char *site_source_dir = fm_str(part, "site/source_material"); - char *dest_dir = fm_str(part, "../site"); - fm_make_folder_if_missing(part, dest_dir); + char *cmd = fm_str(arena, BUILD_DIR "/sitegen"); + char *code_dir = fm_str(arena, "."); + char *asset_dir = fm_str(arena, "../4coder-non-source/site_resources"); + char *site_source_dir = fm_str(arena, "site/source_material"); + char *dest_dir = fm_str(arena, "../site"); + fm_make_folder_if_missing(arena, dest_dir); systemf("%s %s %s %s %s", cmd, code_dir, asset_dir, site_source_dir, dest_dir); END_TIME_SECTION("run sitegen"); } } internal void -build_and_run(Partition *part, char *cdir, char *filename, char *name, u32 flags){ - char *dir = fm_str(part, BUILD_DIR); +build_and_run(Arena *arena, char *cdir, char *filename, char *name, u32 flags){ + char *dir = fm_str(arena, BUILD_DIR); { - char *file = fm_str(part, filename); + char *file = fm_str(arena, filename); BEGIN_TIME_SECTION(); - build(part, flags, Arch_X64, cdir, file, dir, name, get_defines_from_flags(part, flags), 0, includes); - END_TIME_SECTION(fm_str(part, "build ", name)); + build(arena, flags, Arch_X64, cdir, file, dir, name, get_defines_from_flags(arena, flags), 0, includes); + END_TIME_SECTION(fm_str(arena, "build ", name)); } if (prev_error == 0){ - char *cmd = fm_str(part, dir, "/", name); + char *cmd = fm_str(arena, dir, "/", name); BEGIN_TIME_SECTION(); fm_execute_in_dir(cdir, cmd, 0); - END_TIME_SECTION(fm_str(part, "run ", name)); + END_TIME_SECTION(fm_str(arena, "run ", name)); } } internal void -fsm_generator(Partition *part, char *cdir){ - build_and_run(part, cdir, "meta/4ed_fsm_table_generator.cpp", "fsmgen", OPTS | DEBUG_INFO); +fsm_generator(Arena *arena, char *cdir){ + build_and_run(arena, cdir, "meta/4ed_fsm_table_generator.cpp", "fsmgen", OPTS | DEBUG_INFO); } internal void -metagen(Partition *part, char *cdir){ - build_and_run(part, cdir, "meta/4ed_metagen.cpp", "metagen", OPTS | DEBUG_INFO); +metagen(Arena *arena, char *cdir){ + build_and_run(arena, cdir, "meta/4ed_metagen.cpp", "metagen", OPTS | DEBUG_INFO); } internal void -string_build(Partition *part, char *cdir){ - char *dir = fm_str(part, BUILD_DIR); +string_build(Arena *arena, char *cdir){ + char *dir = fm_str(arena, BUILD_DIR); { - char *file = fm_str(part, "string/4ed_string_builder.cpp"); + char *file = fm_str(arena, "string/4ed_string_builder.cpp"); BEGIN_TIME_SECTION(); - build(part, OPTS | DEBUG_INFO, Arch_X64, cdir, file, dir, "string_builder", 0, 0, includes); + build(arena, OPTS | DEBUG_INFO, Arch_X64, cdir, file, dir, "string_builder", 0, 0, includes); END_TIME_SECTION("build string_builder"); } if (prev_error == 0){ - char *cmd = fm_str(part, cdir, "/", dir, "/string_builder"); + char *cmd = fm_str(arena, cdir, "/", dir, "/string_builder"); BEGIN_TIME_SECTION(); - fm_execute_in_dir(fm_str(part, cdir, "/string"), cmd, 0); + fm_execute_in_dir(fm_str(arena, cdir, "/string"), cmd, 0); END_TIME_SECTION("run string_builder"); } } internal void -do_buildsuper(Partition *part, char *cdir, char *file, u32 arch){ +do_buildsuper(Arena *arena, char *cdir, char *file, u32 arch){ BEGIN_TIME_SECTION(); - Temp_Dir temp = fm_pushdir(fm_str(part, BUILD_DIR)); + Temp_Dir temp = fm_pushdir(fm_str(arena, BUILD_DIR)); - char *build_script = fm_str(part, "buildsuper_", arch_names[arch], BAT); + char *build_script = fm_str(arena, "buildsuper_", arch_names[arch], BAT); - char *build_command = fm_str(part, "\"", cdir, "/", build_script, "\" \"", file, "\""); + char *build_command = fm_str(arena, "\"", cdir, "/", build_script, "\" \"", file, "\""); if (This_OS == Platform_Windows){ - build_command = fm_str(part, "call ", build_command); + build_command = fm_str(arena, "call ", build_command); } systemf("%s", build_command); @@ -530,7 +530,7 @@ internal i32 get_freetype_include(char *out, u32 max){ i32 size = 0; #if 0 -#if defined(IS_LINUX) +#if OS_LINUX char freetype_include[512]; FILE *file = popen("pkg-config --cflags freetype2", "r"); if (file != 0){ @@ -539,7 +539,7 @@ get_freetype_include(char *out, u32 max){ memcpy(out, freetype_include, size); pclose(file); } -#elif defined(IS_MAC) +#elif OS_MAC char *freetype_include = "/usr/local/include/freetype2"; size = strlen(freetype_include); memcpy(out, freetype_include, size); @@ -549,12 +549,12 @@ get_freetype_include(char *out, u32 max){ } internal void -build_main(Partition *part, char *cdir, b32 update_local_theme, u32 flags, u32 arch){ - char *dir = fm_str(part, BUILD_DIR); +build_main(Arena *arena, char *cdir, b32 update_local_theme, u32 flags, u32 arch){ + char *dir = fm_str(arena, BUILD_DIR); { - char *file = fm_str(part, "4ed_app_target.cpp"); - char **exports = fm_list_one_item(part, "app_get_functions"); + char *file = fm_str(arena, "4ed_app_target.cpp"); + char **exports = fm_list_one_item(arena, "app_get_functions"); char **build_includes = includes; @@ -563,67 +563,67 @@ build_main(Partition *part, char *cdir, b32 update_local_theme, u32 flags, u32 a if (ft_size > 0){ ft_include[ft_size] = 0; fprintf(stdout, "FREETYPE: %s\n", ft_include); - build_includes = fm_list(part, build_includes, fm_list_one_item(part, ft_include)); + build_includes = fm_list(arena, build_includes, fm_list_one_item(arena, ft_include)); } BEGIN_TIME_SECTION(); - build(part, OPTS | SHARED_CODE | flags, arch, cdir, file, dir, "4ed_app" DLL, get_defines_from_flags(part, flags), exports, build_includes); + build(arena, OPTS | SHARED_CODE | flags, arch, cdir, file, dir, "4ed_app" DLL, get_defines_from_flags(arena, flags), exports, build_includes); END_TIME_SECTION("build 4ed_app"); } { BEGIN_TIME_SECTION(); - char **inc = (char**)fm_list(part, includes, platform_includes[This_OS][This_Compiler]); - build(part, OPTS | LIBS | ICON | flags, arch, cdir, platform_layers[This_OS], dir, "4ed", get_defines_from_flags(part, flags), 0, inc); + char **inc = (char**)fm_list(arena, includes, platform_includes[This_OS][This_Compiler]); + build(arena, OPTS | LIBS | ICON | flags, arch, cdir, platform_layers[This_OS], dir, "4ed", get_defines_from_flags(arena, flags), 0, inc); END_TIME_SECTION("build 4ed"); } if (update_local_theme){ BEGIN_TIME_SECTION(); - char *themes_folder = fm_str(part, "../build/themes"); - char *source_themes_folder = fm_str(part, "themes"); + char *themes_folder = fm_str(arena, "../build/themes"); + char *source_themes_folder = fm_str(arena, "themes"); fm_clear_folder(themes_folder); - fm_make_folder_if_missing(part, themes_folder); + fm_make_folder_if_missing(arena, themes_folder); fm_copy_all(source_themes_folder, "*", themes_folder); END_TIME_SECTION("move files"); } } internal void -standard_build(Partition *part, char *cdir, u32 flags, u32 arch){ - fsm_generator(part, cdir); - metagen(part, cdir); - //do_buildsuper(part, cdir, fm_str(part, custom_files[Custom_Default]), arch); - do_buildsuper(part, cdir, fm_str(part, custom_files[Custom_Experiments]), arch); - //do_buildsuper(part, cdir, fm_str(part, custom_files[Custom_Casey]), arch); - //do_buildsuper(part, cdir, fm_str(part, custom_files[Custom_ChronalVim]), arch); - build_main(part, cdir, true, flags, arch); +standard_build(Arena *arena, char *cdir, u32 flags, u32 arch){ + fsm_generator(arena, cdir); + metagen(arena, cdir); + //do_buildsuper(arena, cdir, fm_str(arena, custom_files[Custom_Default]), arch); + do_buildsuper(arena, cdir, fm_str(arena, custom_files[Custom_Experiments]), arch); + //do_buildsuper(arena, cdir, fm_str(arena, custom_files[Custom_Casey]), arch); + //do_buildsuper(arena, cdir, fm_str(arena, custom_files[Custom_ChronalVim]), arch); + build_main(arena, cdir, true, flags, arch); } internal char* -get_4coder_dist_name(Partition *part, u32 platform, char *tier, u32 arch){ - char *name = fm_str(part, "4coder-alpha-" MAJOR_STR "-" MINOR_STR "-" PATCH_STR); +get_4coder_dist_name(Arena *arena, u32 platform, char *tier, u32 arch){ + char *name = fm_str(arena, "4coder-alpha-" MAJOR_STR "-" MINOR_STR "-" PATCH_STR); if (strcmp(tier, "alpha") != 0){ - name = fm_str(part, name, "-", tier); + name = fm_str(arena, name, "-", tier); } if (platform != Platform_None){ - name = fm_str(part, name, "-", platform_names[platform]); + name = fm_str(arena, name, "-", platform_names[platform]); } if (arch != Arch_None){ - name = fm_str(part, name, "-", arch_names[arch]); + name = fm_str(arena, name, "-", arch_names[arch]); } return(name); } internal void -package(Partition *part, char *cdir){ +package(Arena *arena, char *cdir){ // NOTE(allen): meta - fsm_generator(part, cdir); - metagen(part, cdir); + fsm_generator(arena, cdir); + metagen(arena, cdir); - char *build_dir = fm_str(part, BUILD_DIR); - char *pack_dir = fm_str(part, PACK_DIR); - char *fonts_source_dir = fm_str(part, "../4coder-non-source/dist_files/fonts"); + char *build_dir = fm_str(arena, BUILD_DIR); + char *pack_dir = fm_str(arena, PACK_DIR); + char *fonts_source_dir = fm_str(arena, "../4coder-non-source/dist_files/fonts"); char *base_package_root = "../current_dist"; @@ -642,62 +642,62 @@ package(Partition *part, char *cdir){ char *tier = tiers[tier_index]; u32 flags = base_flags | tier_flags[tier_index]; - Temp_Memory temp = begin_temp_memory(part); - char *tier_package_root = fm_str(part, base_package_root, "_", tier); + Temp_Memory temp = begin_temp(arena); + char *tier_package_root = fm_str(arena, base_package_root, "_", tier); for (u32 arch = 0; arch < Arch_COUNT; ++arch){ - char *par_dir = fm_str(part, tier_package_root, "_", arch_names[arch]); - char *dir = fm_str(part, par_dir, "/4coder"); - char *fonts_dir = fm_str(part, dir, "/fonts"); - char *zip_dir = fm_str(part, pack_dir, "/", tier, "_", arch_names[arch]); + char *par_dir = fm_str(arena, tier_package_root, "_", arch_names[arch]); + char *dir = fm_str(arena, par_dir, "/4coder"); + char *fonts_dir = fm_str(arena, dir, "/fonts"); + char *zip_dir = fm_str(arena, pack_dir, "/", tier, "_", arch_names[arch]); build_metadata(); - build_main(part, cdir, false, flags, arch); + build_main(arena, cdir, false, flags, arch); fm_clear_folder(par_dir); - fm_make_folder_if_missing(part, dir); - fm_copy_file(fm_str(part, build_dir, "/4ed" EXE), fm_str(part, dir, "/4ed" EXE)); - fm_copy_file(fm_str(part, build_dir, "/4ed_app" DLL), fm_str(part, dir, "/4ed_app" DLL)); + fm_make_folder_if_missing(arena, dir); + fm_copy_file(fm_str(arena, build_dir, "/4ed" EXE), fm_str(arena, dir, "/4ed" EXE)); + fm_copy_file(fm_str(arena, build_dir, "/4ed_app" DLL), fm_str(arena, dir, "/4ed_app" DLL)); - fm_copy_folder(part, cdir, dir, "themes"); - fm_copy_file(fm_str(part, cdir, "/LICENSE.txt"), fm_str(part, dir, "/LICENSE.txt")); - fm_copy_file(fm_str(part, cdir, "/README.txt"), fm_str(part, dir, "/README.txt")); - fm_copy_file(fm_str(part, cdir, "/changes.txt"), fm_str(part, dir, "/changes.txt")); + fm_copy_folder(arena, cdir, dir, "themes"); + fm_copy_file(fm_str(arena, cdir, "/LICENSE.txt"), fm_str(arena, dir, "/LICENSE.txt")); + fm_copy_file(fm_str(arena, cdir, "/README.txt"), fm_str(arena, dir, "/README.txt")); + fm_copy_file(fm_str(arena, cdir, "/changes.txt"), fm_str(arena, dir, "/changes.txt")); - fm_make_folder_if_missing(part, fonts_dir); + fm_make_folder_if_missing(arena, fonts_dir); fm_copy_all(fonts_source_dir, "*", fonts_dir); - fm_copy_file(fm_str(part, cdir, "/release-config.4coder"), fm_str(part, dir, "/config.4coder")); + fm_copy_file(fm_str(arena, cdir, "/release-config.4coder"), fm_str(arena, dir, "/config.4coder")); if (tier_index == Tier_Super){ fm_copy_all(0, "4coder_*", dir); - do_buildsuper(part, cdir, fm_str(part, custom_files[Custom_Default]), arch); - fm_copy_file(fm_str(part, build_dir, "/custom_4coder" DLL), fm_str(part, dir, "/custom_4coder" DLL)); + do_buildsuper(arena, cdir, fm_str(arena, custom_files[Custom_Default]), arch); + fm_copy_file(fm_str(arena, build_dir, "/custom_4coder" DLL), fm_str(arena, dir, "/custom_4coder" DLL)); - char *build_script = fm_str(part, "buildsuper_", arch_names[arch], BAT); - fm_copy_file(build_script, fm_str(part, dir, "/buildsuper" BAT)); + char *build_script = fm_str(arena, "buildsuper_", arch_names[arch], BAT); + fm_copy_file(build_script, fm_str(arena, dir, "/buildsuper" BAT)); if (This_OS == Platform_Windows){ - fm_copy_folder(part, cdir, dir, "windows_scripts"); + fm_copy_folder(arena, cdir, dir, "windows_scripts"); } - fm_copy_folder(part, cdir, dir, "4coder_API"); - fm_copy_folder(part, cdir, dir, "4coder_lib"); - fm_copy_folder(part, cdir, dir, "4coder_generated"); - fm_copy_folder(part, cdir, dir, "languages"); + fm_copy_folder(arena, cdir, dir, "4coder_API"); + fm_copy_folder(arena, cdir, dir, "4coder_lib"); + fm_copy_folder(arena, cdir, dir, "4coder_generated"); + fm_copy_folder(arena, cdir, dir, "languages"); } - char *dist_name = get_4coder_dist_name(part, This_OS, tier, arch); - char *zip_name = fm_str(part, zip_dir, "/", dist_name, ".zip"); - fm_make_folder_if_missing(part, zip_dir); + char *dist_name = get_4coder_dist_name(arena, This_OS, tier, arch); + char *zip_name = fm_str(arena, zip_dir, "/", dist_name, ".zip"); + fm_make_folder_if_missing(arena, zip_dir); fm_zip(par_dir, "4coder", zip_name); } - end_temp_memory(temp); + end_temp(temp); } } int main(int argc, char **argv){ - Partition part = fm_init_system(); + Arena arena = fm_init_system(); char cdir[256]; BEGIN_TIME_SECTION(); @@ -714,16 +714,10 @@ int main(int argc, char **argv){ #if defined(DEV_BUILD_X86) arch = Arch_X86; #endif - standard_build(&part, cdir, flags, arch); + standard_build(&arena, cdir, flags, arch); #elif defined(PACKAGE) - package(&part, cdir); - -#elif defined(SITE_BUILD) - site_build(&part, cdir, DEBUG_INFO); - -#elif defined(STRING_BUILD) - string_build(&part, cdir); + package(&arena, cdir); #else # error No build type specified. diff --git a/meta/4ed_file_moving.h b/meta/4ed_file_moving.h index 304b512d..5716f4a2 100644 --- a/meta/4ed_file_moving.h +++ b/meta/4ed_file_moving.h @@ -12,13 +12,16 @@ #if !defined(FRED_FILE_MOVING_H) #define FRED_FILE_MOVING_H -#include "../4coder_os_comp_cracking.h" +#include "../4coder_base_types.h" #include // include system for windows #include // include system for linux (YAY!) #include #include +#include "../4coder_base_types.cpp" +#include "../4coder_malloc_allocator.cpp" + // // API // @@ -36,7 +39,6 @@ static i32 prev_error = 0; #define systemf(...) do{ \ i32 n = snprintf(SF_CMD, sizeof(SF_CMD), __VA_ARGS__); \ - AllowLocal(n); \ Assert(n < sizeof(SF_CMD)); \ SYSTEMF_PRINTF("%s\n", SF_CMD); \ prev_error = system(SF_CMD); \ @@ -46,7 +48,7 @@ static i32 prev_error = 0; internal void fm_execute_in_dir(char *dir, char *str, char *args); // Init -internal Partition fm_init_system(); +internal Arena fm_init_system(); // Timing internal u64 fm_get_time(); @@ -56,12 +58,12 @@ internal u64 fm_get_time(); #define END_TIME_SECTION(n) u64 total = fm_get_time() - start; printf("%-20s: %.2llu.%.6llu\n", (n), LLU_CAST(total/1000000), LLU_CAST(total%1000000)); // Files and Folders Manipulation -internal void fm_make_folder_if_missing(Partition *part, char *dir); +internal void fm_make_folder_if_missing(Arena *arena, char *dir); internal void fm_clear_folder(char *folder); internal void fm_delete_file(char *file); internal void fm_copy_file(char *file, char *newname); internal void fm_copy_all(char *source, char *tag, char *folder); -internal void fm_copy_folder(Partition *part, char *src_dir, char *dst_dir, char *src_folder); +internal void fm_copy_folder(Arena *arena, char *src_dir, char *dst_dir, char *src_folder); // File Reading and Writing internal void fm_write_file(char *file_name, char *data, u32 size); @@ -73,16 +75,16 @@ internal void fm_zip(char *parent, char *folder, char *dest); internal void fm_slash_fix(char *path); // Memory concat helpers -internal char *fm_prepare_string_internal(Partition *part, char *s1, ...); +internal char *fm_prepare_string_internal(Arena *arena, char *s1, ...); #define fm_str(...) fm_prepare_string_internal(__VA_ARGS__, (void*)0) -internal char *fm_basic_string_internal(Partition *part, char *s1, ...); +internal char *fm_basic_string_internal(Arena *arena, char *s1, ...); #define fm_basic_str(...) fm_basic_string_internal(__VA_ARGS__, (void*)0) -internal char **fm_prepare_list_internal(Partition *part, char **l1, ...); +internal char **fm_prepare_list_internal(Arena *arena, char **l1, ...); #define fm_list(...) fm_prepare_list_internal(__VA_ARGS__, (void*)0) -internal char **fm_list_one_item(Partition *part, char *item); +internal char **fm_list_one_item(Arena *arena, char *item); // File System Navigation internal i32 fm_get_current_directory(char *buffer, i32 max); @@ -109,7 +111,7 @@ internal void fm_finish_build_line(Build_Line *line); internal void fm__swap_ptr(char **A, char **B); -#if defined(IS_CL) +#if COMPILER_CL #define fm_add_to_line(line, str, ...) do{ \ snprintf(line.build_options, \ @@ -118,7 +120,7 @@ internal void fm__swap_ptr(char **A, char **B); fm__swap_ptr(&line.build_options, &line.build_options_prev); \ }while(0) -#elif defined(IS_GCC) +#elif COMPILER_GCC #define fm_add_to_line(line, str, ...) do{ \ snprintf(line.build_options, line.build_max, "%s "str, \ @@ -129,10 +131,10 @@ internal void fm__swap_ptr(char **A, char **B); #endif // Slashes -#if defined(IS_WINDOWS) +#if OS_WINDOWS # define SLASH "\\" static char platform_correct_slash = '\\'; -#elif defined(IS_LINUX) || defined(IS_MAC) +#elif OS_LINUX || OS_MAC # define SLASH "/" static char platform_correct_slash = '/'; #else @@ -140,33 +142,33 @@ static char platform_correct_slash = '/'; #endif // File Extensions -#if defined(IS_WINDOWS) +#if OS_WINDOWS # define EXE ".exe" -#elif defined(IS_LINUX) || defined(IS_MAC) +#elif OS_LINUX || OS_MAC # define EXE "" #else # error No EXE format specified for this OS #endif -#if defined(IS_WINDOWS) +#if OS_WINDOWS # define PDB ".pdb" -#elif defined(IS_LINUX) || defined(IS_MAC) +#elif OS_LINUX || OS_MAC # define PDB "" #else # error No PDB format specified for this OS #endif -#if defined(IS_WINDOWS) +#if OS_WINDOWS # define DLL ".dll" -#elif defined(IS_LINUX) || defined(IS_MAC) +#elif OS_LINUX || OS_MAC # define DLL ".so" #else # error No DLL format specified for this OS #endif -#if defined(IS_WINDOWS) +#if OS_WINDOWS # define BAT ".bat" -#elif defined(IS_LINUX) || defined(IS_MAC) +#elif OS_LINUX || OS_MAC # define BAT ".sh" #else # error No BAT format specified for this OS @@ -181,18 +183,16 @@ static char platform_correct_slash = '/'; #if defined(FTECH_FILE_MOVING_IMPLEMENTATION) && !defined(FTECH_FILE_MOVING_IMPL_GUARD) #define FTECH_FILE_MOVING_IMPL_GUARD -internal Partition -fm__init_memory(){ - i32_4tech size = MB(512); - Partition part = make_part(malloc(size), size); - return(part); +internal Arena +fm__init_memory(void){ + return(make_arena_malloc(MB(512), 8)); } // // Windows implementation // -#if defined(IS_WINDOWS) +#if OS_WINDOWS typedef u32 DWORD; typedef i32 LONG; @@ -270,8 +270,8 @@ extern "C"{ global u64 perf_frequency; -internal Partition -fm_init_system(){ +internal Arena +fm_init_system(void){ LARGE_INTEGER lint; if (QueryPerformanceFrequency(&lint)){ perf_frequency = lint.QuadPart; @@ -341,8 +341,8 @@ fm_slash_fix(char *path){ } internal void -fm_make_folder_if_missing(Partition *part, char *dir){ - char *path = fm_str(part, dir); +fm_make_folder_if_missing(Arena *arena, char *dir){ + char *path = fm_str(arena, dir); char *p = path; for (; *p; ++p){ if (*p == '\\'){ @@ -415,7 +415,7 @@ fm_zip(char *parent, char *folder, char *dest){ // Unix implementation // -#elif defined(IS_LINUX) || defined(IS_MAC) +#elif OS_LINUX || OS_MAC #include #include @@ -545,10 +545,10 @@ fm_zip(char *parent, char *folder, char *file){ #endif internal void -fm_copy_folder(Partition *part, char *src_dir, char *dst_dir, char *src_folder){ +fm_copy_folder(Arena *arena, char *src_dir, char *dst_dir, char *src_folder){ Temp_Dir temp = fm_pushdir(src_dir); - fm_make_folder_if_missing(part, fm_str(part, dst_dir, "/", src_folder)); - char *copy_name = fm_str(part, dst_dir, "/", src_folder); + fm_make_folder_if_missing(arena, fm_str(arena, dst_dir, "/", src_folder)); + char *copy_name = fm_str(arena, dst_dir, "/", src_folder); fm_copy_all(src_folder, "*", copy_name); fm_popdir(temp); } @@ -564,58 +564,56 @@ listsize(void *p, umem item_size){ } internal void* -fm__prepare(Partition *part, i32 item_size, void *i1, va_list list){ +fm__prepare(Arena *arena, i32 item_size, void *i1, va_list list){ + List_String_Const_char out_list = {}; i32 size = listsize(i1, item_size); - void *result = push_array(part, char, size); - memcpy(result, i1, (size_t)size); - + string_list_push(arena, &out_list, SCchar((char*)i1, size)); void *ln = va_arg(list, void*); for (;ln != 0;){ size = listsize(ln, item_size); - void *new_str = push_array(part, char, size); - memcpy(new_str, ln, (size_t)size); + string_list_push(arena, &out_list, SCchar((char*)ln, size)); ln = va_arg(list, void*); } - - void *terminator = push_array(part, char, item_size); - memset(terminator, 0, (size_t)item_size); - return(result); + void *terminator = push_array_zero(arena, char, item_size); + string_list_push(arena, &out_list, SCchar((char*)terminator, item_size)); + String_Const_char result = string_list_flatten(arena, out_list); + return(result.str); } internal char* -fm_basic_string_internal(Partition *part, char *s1, ...){ +fm_basic_string_internal(Arena *arena, char *s1, ...){ i32 item_size = sizeof(*s1); va_list list; va_start(list, s1); - char *result = (char*)fm__prepare(part, item_size, s1, list); + char *result = (char*)fm__prepare(arena, item_size, s1, list); va_end(list); return(result); } internal char* -fm_prepare_string_internal(Partition *part, char *s1, ...){ +fm_prepare_string_internal(Arena *arena, char *s1, ...){ i32 item_size = sizeof(*s1); va_list list; va_start(list, s1); - char *result = (char*)fm__prepare(part, item_size, s1, list); + char *result = (char*)fm__prepare(arena, item_size, s1, list); va_end(list); fm_slash_fix(result); return(result); } internal char** -fm_prepare_list_internal(Partition *part, char **p1, ...){ +fm_prepare_list_internal(Arena *arena, char **p1, ...){ i32 item_size = sizeof(*p1); va_list list; va_start(list, p1); - char **result = (char**)fm__prepare(part, item_size, p1, list); + char **result = (char**)fm__prepare(arena, item_size, p1, list); va_end(list); return(result); } internal char** -fm_list_one_item(Partition *part, char *item){ - char **result = push_array(part, char*, 2); +fm_list_one_item(Arena *arena, char *item){ + char **result = push_array(arena, char*, 2); result[0] = item; result[1] = 0; return(result); diff --git a/meta/4ed_fsm_table_generator.cpp b/meta/4ed_fsm_table_generator.cpp index f2fc5a38..4573bebb 100644 --- a/meta/4ed_fsm_table_generator.cpp +++ b/meta/4ed_fsm_table_generator.cpp @@ -7,54 +7,13 @@ // TOP -// 4tech_standard_preamble.h -#if !defined(FTECH_INTEGERS) -#define FTECH_INTEGERS -#include -typedef int8_t i8_4tech; -typedef int16_t i16_4tech; -typedef int32_t i32_4tech; -typedef int64_t i64_4tech; - -typedef uint8_t u8_4tech; -typedef uint16_t u16_4tech; -typedef uint32_t u32_4tech; -typedef uint64_t u64_4tech; - -#if defined(FTECH_32_BIT) -typedef u32_4tech umem_4tech; -#else -typedef u64_4tech umem_4tech; -#endif - -typedef float f32_4tech; -typedef double f64_4tech; - -typedef int8_t b8_4tech; -typedef int32_t b32_4tech; -#endif - -#if !defined(Assert) -# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0) -#endif - -#if !defined(API_EXPORT) -# define API_EXPORT -#endif - -#if !defined(internal) -# define internal static -#endif -// standard preamble end +#include "../4coder_base_types.h" +#include "../4coder_base_types.cpp" #include #include #include -typedef int32_t bool32; - -#define ArrayCount(a) (sizeof(a)/sizeof(*a)) - #define LEXER_TABLE_FILE "4coder_lib/4cpp_lexer_tables.c" #include "../4coder_lib/4cpp_lexer_types.h" @@ -76,7 +35,7 @@ whitespace_skip_fsm(Whitespace_FSM wfsm, char c){ return(wfsm); } -#define FSM_SIG(n) Cpp_Lex_FSM n(Cpp_Lex_FSM fsm, char c, b32_4tech get_flags) +#define FSM_SIG(n) Cpp_Lex_FSM n(Cpp_Lex_FSM fsm, char c, b32 get_flags) typedef FSM_SIG(FSM_Function); FSM_SIG(int_fsm){ @@ -271,26 +230,26 @@ FSM_SIG(include_str_fsm){ return(fsm); } -b32_4tech -is_identifier_char(u8_4tech c, b32_4tech ignore_string_delims){ - b32_4tech result = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$' || c >= 128 || (ignore_string_delims && (c == '\'' || c == '"')); +b32 +is_identifier_char(u8 c, b32 ignore_string_delims){ + b32 result = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$' || c >= 128 || (ignore_string_delims && (c == '\'' || c == '"')); return(result); } -b32_4tech -is_identifier_char_restricted(u8_4tech c, b32_4tech ignore_string_delims){ - b32_4tech result = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c >= 128 || (ignore_string_delims && (c == '\'' || c == '"')); +b32 +is_identifier_char_restricted(u8 c, b32 ignore_string_delims){ + b32 result = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c >= 128 || (ignore_string_delims && (c == '\'' || c == '"')); return(result); } -b32_4tech -is_identifier_char_non_numeric(u8_4tech c, b32_4tech ignore_string_delims){ - b32_4tech result = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$' || c >= 128 || (ignore_string_delims && (c == '\'' || c == '"')); +b32 +is_identifier_char_non_numeric(u8 c, b32 ignore_string_delims){ + b32 result = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$' || c >= 128 || (ignore_string_delims && (c == '\'' || c == '"')); return(result); } Cpp_Lex_FSM -main_fsm(Cpp_Lex_FSM fsm, uint8_t pp_state, uint8_t c, bool32 ignore_string_delims){ +main_fsm(Cpp_Lex_FSM fsm, uint8_t pp_state, uint8_t c, b32 ignore_string_delims){ if (c == 0){ switch (fsm.state){ case LS_string_R: @@ -418,7 +377,7 @@ main_fsm(Cpp_Lex_FSM fsm, uint8_t pp_state, uint8_t c, bool32 ignore_string_deli case LS_identifier: { - b32_4tech is_ident = is_identifier_char(c, ignore_string_delims); + b32 is_ident = is_identifier_char(c, ignore_string_delims); if (!is_ident){ fsm.emit_token = true; } @@ -463,7 +422,7 @@ main_fsm(Cpp_Lex_FSM fsm, uint8_t pp_state, uint8_t c, bool32 ignore_string_deli default: { fsm.state = LS_identifier; - b32_4tech is_ident = is_identifier_char(c, ignore_string_delims); + b32 is_ident = is_identifier_char(c, ignore_string_delims); if (!is_ident){ fsm.emit_token = true; } @@ -486,7 +445,7 @@ main_fsm(Cpp_Lex_FSM fsm, uint8_t pp_state, uint8_t c, bool32 ignore_string_deli default: { fsm.state = LS_identifier; - b32_4tech is_ident = is_identifier_char(c, ignore_string_delims); + b32 is_ident = is_identifier_char(c, ignore_string_delims); if (!is_ident){ fsm.emit_token = true; } @@ -510,7 +469,7 @@ main_fsm(Cpp_Lex_FSM fsm, uint8_t pp_state, uint8_t c, bool32 ignore_string_deli default: { fsm.state = LS_identifier; - b32_4tech is_ident = is_identifier_char(c, ignore_string_delims); + b32 is_ident = is_identifier_char(c, ignore_string_delims); if (!is_ident){ fsm.emit_token = true; } @@ -770,15 +729,15 @@ end_table(FILE *file){ } struct FSM_Tables{ - u8_4tech *full_transition_table; - u8_4tech *marks; - u8_4tech *eq_class; - u8_4tech *eq_class_rep; - u8_4tech *reduced_transition_table; - u8_4tech *flags; + u8 *full_transition_table; + u8 *marks; + u8 *eq_class; + u8 *eq_class_rep; + u8 *reduced_transition_table; + u8 *flags; - u8_4tech eq_class_counter; - u16_4tech state_count; + u8 eq_class_counter; + u16 state_count; }; static void @@ -849,30 +808,30 @@ generate_whitespace_skip_table(){ } static FSM_Tables -generate_table(u8_4tech state_count, FSM_Function *fsm_call){ +generate_table(u8 state_count, FSM_Function *fsm_call){ FSM_Tables table = {}; allocate_full_tables(&table, state_count); - i32_4tech i = 0; + i32 i = 0; Cpp_Lex_FSM fsm = {}; Cpp_Lex_FSM new_fsm = {}; for (uint16_t c = 0; c < 256; ++c){ - for (u8_4tech state = 0; state < state_count; ++state){ + for (u8 state = 0; state < state_count; ++state){ fsm.state = state; fsm.emit_token = false; - new_fsm = fsm_call(fsm, (u8_4tech)c, false); + new_fsm = fsm_call(fsm, (u8)c, false); table.full_transition_table[i++] = new_fsm.state + state_count*new_fsm.emit_token; } } - for (u8_4tech state = 0; state < state_count; ++state){ + for (u8 state = 0; state < state_count; ++state){ fsm.state = state; fsm.emit_token = false; fsm.flags = 0; new_fsm = fsm_call(fsm, 0, true); if (new_fsm.flags != 0){ if (table.flags == 0){ - table.flags = (u8_4tech*)malloc(state_count); + table.flags = (u8*)malloc(state_count); memset(table.flags, 0, state_count); } table.flags[state] = new_fsm.flags; @@ -885,7 +844,7 @@ generate_table(u8_4tech state_count, FSM_Function *fsm_call){ } static FSM_Tables -generate_fsm_table(uint8_t pp_state, bool32 ignore_string_delims){ +generate_fsm_table(uint8_t pp_state, b32 ignore_string_delims){ uint8_t state_count = LS_count; FSM_Tables table = {}; allocate_full_tables(&table, state_count); @@ -909,8 +868,8 @@ generate_fsm_table(uint8_t pp_state, bool32 ignore_string_delims){ static void render_fsm_table(FILE *file, FSM_Tables tables, char *group_name){ - begin_table(file, "u16_4tech", group_name, "eq_classes"); - for (u16_4tech c = 0; c < 256; ++c){ + begin_table(file, "u16", group_name, "eq_classes"); + for (u16 c = 0; c < 256; ++c){ if ((c % 16) == 0 && c > 0){ end_row(file); } @@ -919,12 +878,12 @@ render_fsm_table(FILE *file, FSM_Tables tables, char *group_name){ end_row(file); end_table(file); - fprintf(file, "const i32_4tech num_%s_eq_classes = %d;\n\n", group_name, tables.eq_class_counter); + fprintf(file, "const i32 num_%s_eq_classes = %d;\n\n", group_name, tables.eq_class_counter); - i32_4tech i = 0; - begin_table(file, "u8_4tech", group_name, "table"); - for (u16_4tech c = 0; c < tables.eq_class_counter; ++c){ - for (u8_4tech state = 0; state < tables.state_count; ++state){ + i32 i = 0; + begin_table(file, "u8", group_name, "table"); + for (u16 c = 0; c < tables.eq_class_counter; ++c){ + for (u8 state = 0; state < tables.state_count; ++state){ do_table_item(file, tables.reduced_transition_table[i++]); } end_row(file); @@ -932,8 +891,8 @@ render_fsm_table(FILE *file, FSM_Tables tables, char *group_name){ end_table(file); if (tables.flags != 0){ - begin_table(file, "u8_4tech", group_name, "flags"); - for (u8_4tech state = 0; state < tables.state_count; ++state){ + begin_table(file, "u8", group_name, "flags"); + for (u8 state = 0; state < tables.state_count; ++state){ if ((state % 4) == 0 && state > 0){ end_row(file); } @@ -957,7 +916,7 @@ render_comment(FILE *file, char *comment){ struct PP_Names{ uint8_t pp_state; char *name; - bool32 ignore_string_delims; + b32 ignore_string_delims; }; static PP_Names pp_names[] = { @@ -995,7 +954,7 @@ main(){ {"normal_char", LSSTR_count, normal_char_fsm } }; - for (u32_4tech i = 0; i < ArrayCount(tables); ++i){ + for (u32 i = 0; i < ArrayCount(tables); ++i){ FSM_Tables str_tables = generate_table(tables[i].count, tables[i].fsm_call); render_fsm_table(file, str_tables, tables[i].name); } diff --git a/meta/4ed_meta_defines.h b/meta/4ed_meta_defines.h index 9004857c..8f4fd950 100644 --- a/meta/4ed_meta_defines.h +++ b/meta/4ed_meta_defines.h @@ -12,8 +12,6 @@ #if !defined(FTECH_META_DEFINES_H) #define FTECH_META_DEFINES_H -#include "../4ed_defines.h" - #include #include @@ -29,13 +27,11 @@ __meta_finish__(){ #define META_FINISH() } __META_FINISH__: __meta_finish__() -#define LINE_STR STR_(__LINE__) - #if defined(Assert) # undef Assert #endif -#define Assert(c) do { if (!(c)) { META_ASSERT_MSG = __FILE__":"LINE_STR": "#c; longjmp(META_ASSERT_ENV, 1); } } while(0) +#define Assert(c) do { if (!(c)) { META_ASSERT_MSG = FNLN " assert: " #c; longjmp(META_ASSERT_ENV, 1); } } while(0) #define META_BEGIN() META_ASSERT_MSG = 0; if (setjmp(META_ASSERT_ENV) == 1){ goto __META_FINISH__; } { diff --git a/meta/4ed_meta_generate_parser.cpp b/meta/4ed_meta_generate_parser.cpp index 24d6e707..7207922c 100644 --- a/meta/4ed_meta_generate_parser.cpp +++ b/meta/4ed_meta_generate_parser.cpp @@ -11,7 +11,7 @@ #include -#include "../4ed_defines.h" +#include "4coder_base_types.h" #include "4ed_meta_generate_parser.h" #define ConfigOpClassList(M) \ diff --git a/meta/4ed_meta_keywords.h b/meta/4ed_meta_keywords.h index b6f54ba8..167745ea 100644 --- a/meta/4ed_meta_keywords.h +++ b/meta/4ed_meta_keywords.h @@ -13,14 +13,14 @@ #define FRED_META_KEYWORDS_H internal Meta_Keywords meta_keywords[] = { - {make_lit_string("API_EXPORT") , Item_Function } , - {make_lit_string("API_EXPORT_INLINE") , Item_Function } , - {make_lit_string("API_EXPORT_MACRO") , Item_Macro } , - {make_lit_string("CPP_NAME") , Item_CppName } , - {make_lit_string("TYPEDEF") , Item_Typedef } , - {make_lit_string("STRUCT") , Item_Struct } , - {make_lit_string("UNION") , Item_Union } , - {make_lit_string("ENUM") , Item_Enum } , + {string_litinit("API_EXPORT") , Item_Function } , + {string_litinit("API_EXPORT_INLINE") , Item_Function } , + {string_litinit("API_EXPORT_MACRO") , Item_Macro } , + {string_litinit("CPP_NAME") , Item_CppName } , + {string_litinit("TYPEDEF") , Item_Typedef } , + {string_litinit("STRUCT") , Item_Struct } , + {string_litinit("UNION") , Item_Union } , + {string_litinit("ENUM") , Item_Enum } , }; #endif diff --git a/meta/4ed_meta_parser.cpp b/meta/4ed_meta_parser.cpp index b7bd1c48..9b228436 100644 --- a/meta/4ed_meta_parser.cpp +++ b/meta/4ed_meta_parser.cpp @@ -20,8 +20,10 @@ struct Parse_Context{ }; struct Argument{ - String param_string; - String param_name; + String_Const_char param_string; + String_Const_char param_name; + //String param_string; + //String param_name; }; struct Argument_Breakdown{ @@ -31,12 +33,17 @@ struct Argument_Breakdown{ struct Documentation{ i32 param_count; - String *param_name; - String *param_docs; - String return_doc; - String main_doc; + String_Const_char *param_name; + String_Const_char *param_docs; + String_Const_char return_doc; + String_Const_char main_doc; i32 see_also_count; - String *see_also; + String_Const_char *see_also; + //String *param_name; + //String *param_docs; + //String return_doc; + //String main_doc; + //String *see_also; }; enum Item_Type{ @@ -55,17 +62,29 @@ enum Item_Type{ struct Item_Node{ i32 t; - String cpp_name; - String name; - String ret; - String args; - String body; - String marker; + String_Const_char cpp_name; + String_Const_char name; + String_Const_char ret; + String_Const_char args; + String_Const_char body; + String_Const_char marker; - String value; - String type; - String type_postfix; - String doc_string; + String_Const_char value; + String_Const_char type; + String_Const_char type_postfix; + String_Const_char doc_string; + + //String cpp_name; + //String name; + //String ret; + //String args; + //String body; + //String marker; + + //String value; + //String type; + //String type_postfix; + //String doc_string; Argument_Breakdown breakdown; Documentation doc; @@ -80,7 +99,8 @@ struct Item_Set{ }; struct Parse{ - String code; + String_Const_char code; + //String code; Cpp_Token_Array tokens; i32 item_count; }; @@ -92,25 +112,27 @@ struct Meta_Unit{ }; struct Meta_Keywords{ - String key; + String_Const_char key; + //String key; Item_Type type; }; struct Used_Links{ - String *strs; + String_Const_char *strs; + //String *strs; i32 count, max; }; internal Item_Node null_item_node = {}; -internal String -str_start_end(char *data, i32 start, i32 end){ - return(make_string(data + start, end - start)); +internal String_Const_char +SCchar_range(char *data, i32 start, i32 end){ + return(SCchar(data + start, data + end)); } -internal String +internal String_Const_char get_lexeme(Cpp_Token token, char *code){ - String str = make_string(code + token.start, token.size); + String_Const_char str = SCchar(code + token.start, token.size); return(str); } @@ -186,35 +208,29 @@ set_token(Parse_Context *context, Cpp_Token *token){ } internal Item_Set -allocate_item_set(Partition *part, i32 count){ +allocate_item_set(Arena *arena, i32 count){ Item_Set item_set = {}; if (count > 0){ - item_set.items = push_array(part, Item_Node, count); + item_set.items = push_array(arena, Item_Node, count); item_set.count = count; memset(item_set.items, 0, sizeof(Item_Node)*count); } return(item_set); } -internal String +internal String_Const_char file_dump(char *filename){ - String result = {}; + String_Const_char result = {}; FILE *file = fopen(filename, "rb"); - if (file){ fseek(file, 0, SEEK_END); result.size = ftell(file); fseek(file, 0, SEEK_SET); - - result.memory_size = result.size + 1; - result.str = (char*)malloc(result.memory_size); - + result.str = (char*)malloc(result.size + 1); fread(result.str, 1, result.size, file); result.str[result.size] = 0; - fclose(file); } - return(result); } @@ -224,47 +240,40 @@ meta_lex(char *filename){ result.code = file_dump(filename); if (result.code.str != 0){ result.tokens = cpp_make_token_array(1024); - cpp_lex_file(result.code.str, result.code.size, &result.tokens); + cpp_lex_file(result.code.str, (i32)result.code.size, &result.tokens); } return(result); } -internal String -get_first_line(String source){ - String line = {}; - i32 pos = find_s_char(source, 0, '\n'); - line = substr(source, 0, pos); +internal String_Const_char +get_first_line(String_Const_char source){ + umem pos = string_find_first(source, '\n'); + String_Const_char line = string_prefix(source, pos); return(line); } -internal String -get_next_line(String source, String line){ - String next = {}; - i32 pos = (i32)(line.str - source.str) + line.size; - i32 start = 0; +internal String_Const_char +get_next_line(String_Const_char source, String_Const_char line){ + String_Const_char next = {}; + umem pos = (umem)(line.str - source.str) + line.size; + umem start = 0; if (pos < source.size){ Assert(source.str[pos] == '\n'); start = pos + 1; if (start < source.size){ - pos = find_s_char(source, start, '\n'); - next = substr(source, start, pos - start); + pos = string_find_first(string_skip(source, start), '\n'); + next = string_prefix(string_skip(source, start), pos - start); } } return(next); } -internal i32 -is_comment(String str){ - i32 result = 0; - if (str.size >= 2){ - if (str.str[0] == '/' && - str.str[1] == '/'){ - result = 1; - } - } +internal b32 +is_comment(String_Const_char str){ + b32 result = string_match(string_prefix(str, 2), string_litexpr("//")); return(result); } @@ -277,19 +286,19 @@ typedef enum Doc_Note_Type{ HIDE_MEMBERS, } Doc_Note_Type; -internal String +internal String_Const_char defined_doc_notes[] = { - make_lit_string("DOC_PARAM"), - make_lit_string("DOC_RETURN"), - make_lit_string("DOC"), - make_lit_string("DOC_SEE"), - make_lit_string("DOC_HIDE"), - make_lit_string("HIDE_MEMBERS"), + string_litinit("DOC_PARAM"), + string_litinit("DOC_RETURN"), + string_litinit("DOC"), + string_litinit("DOC_SEE"), + string_litinit("DOC_HIDE"), + string_litinit("HIDE_MEMBERS"), }; -internal i32 -check_and_fix_docs(String *doc_string){ - i32 result = false; +internal b32 +check_and_fix_docs(String_Const_char *doc_string){ + b32 result = false; if (doc_string->size > 4){ if (doc_string->str[0] == '/'){ @@ -297,8 +306,7 @@ check_and_fix_docs(String *doc_string){ if (doc_string->str[doc_string->size - 2] == '*'){ if (doc_string->str[doc_string->size - 1] == '/'){ result = true; - doc_string->str += 2; - doc_string->size -= 4; + *doc_string = string_skip(string_chop(*doc_string, 2), 2); } } } @@ -309,7 +317,7 @@ check_and_fix_docs(String *doc_string){ } internal i32 -get_doc_string_from_prev(Parse_Context *context, String *doc_string){ +get_doc_string_from_prev(Parse_Context *context, String_Const_char *doc_string){ i32 result = false; if (can_back_step(context)){ @@ -320,7 +328,7 @@ get_doc_string_from_prev(Parse_Context *context, String *doc_string){ result = true; } else{ - *doc_string = null_string; + block_zero_struct(doc_string); } } } @@ -328,9 +336,9 @@ get_doc_string_from_prev(Parse_Context *context, String *doc_string){ return(result); } -internal String -doc_parse_note(String source, i32 *pos){ - String result = {}; +internal String_Const_char +doc_parse_note(String_Const_char source, i32 *pos){ + String_Const_char result = {}; i32 p = *pos; i32 start = p; @@ -340,17 +348,17 @@ doc_parse_note(String source, i32 *pos){ } } if (p != source.size){ - result = make_string(source.str + start, p - start); - result = skip_chop_whitespace(result); + result = SCchar(source.str + start, source.str + p); + result = string_skip_chop_whitespace(result); } *pos = p; return(result); } -internal String -doc_parse_note_string(String source, i32 *pos){ - String result = {}; +internal String_Const_char +doc_parse_note_string(String_Const_char source, i32 *pos){ + String_Const_char result = {}; Assert(source.str[*pos] == '('); @@ -373,8 +381,8 @@ doc_parse_note_string(String source, i32 *pos){ } } if (p != source.size){ - result = make_string(source.str + start, p - start); - result = skip_chop_whitespace(result); + result = SCchar(source.str + start, source.str + p); + result = string_skip_chop_whitespace(result); ++p; } *pos = p; @@ -382,9 +390,9 @@ doc_parse_note_string(String source, i32 *pos){ return(result); } -internal String -doc_parse_parameter(String source, i32 *pos){ - String result = {}; +internal String_Const_char +doc_parse_parameter(String_Const_char source, i32 *pos){ + String_Const_char result = {}; i32 p = *pos; i32 start = p; @@ -395,8 +403,8 @@ doc_parse_parameter(String source, i32 *pos){ } } if (p != source.size){ - result = make_string(source.str + start, p - start); - result = skip_chop_whitespace(result); + result = SCchar(source.str + start, source.str + start + p); + result = string_skip_chop_whitespace(result); ++p; } *pos = p; @@ -404,9 +412,9 @@ doc_parse_parameter(String source, i32 *pos){ return(result); } -internal String -doc_parse_last_parameter(String source, i32 *pos){ - String result = {}; +internal String_Const_char +doc_parse_last_parameter(String_Const_char source, i32 *pos){ + String_Const_char result = {}; i32 p = *pos; i32 start = p; @@ -417,16 +425,35 @@ doc_parse_last_parameter(String source, i32 *pos){ } } if (p == source.size){ - result = make_string(source.str + start, p - start); - result = skip_chop_whitespace(result); + result = SCchar(source.str + start, source.str + p); + result = string_skip_chop_whitespace(result); } *pos = p; return(result); } +internal b32 +string_set_match_table(void *string_array, umem item_size, i32 count, String_Const_char needle, i32 *index_out){ + b32 result = false; + u8 *ptr = (u8*)string_array; + for (i32 i = 0; i < count; i += 1, ptr += item_size){ + String_Const_char *string_ptr = (String_Const_char*)ptr; + if (string_match(*string_ptr, needle)){ + *index_out = i; + result = true; + break; + } + } + return(result); +} + +internal b32 +string_set_match(String_Const_char *string_array, i32 count, String_Const_char needle, i32 *index_out){ + return(string_set_match_table(string_array, sizeof(*string_array), count, needle, index_out)); +} internal void -perform_doc_parse(Partition *part, String doc_string, Documentation *doc){ +perform_doc_parse(Arena *arena, String_Const_char doc_string, Documentation *doc){ i32 keep_parsing = true; i32 pos = 0; @@ -434,7 +461,7 @@ perform_doc_parse(Partition *part, String doc_string, Documentation *doc){ i32 see_count = 0; do{ - String doc_note = doc_parse_note(doc_string, &pos); + String_Const_char doc_note = doc_parse_note(doc_string, &pos); if (doc_note.size == 0){ keep_parsing = false; } @@ -453,11 +480,9 @@ perform_doc_parse(Partition *part, String doc_string, Documentation *doc){ }while(keep_parsing); if (param_count + see_count > 0){ - i32 memory_size = sizeof(String)*(2*param_count + see_count); - doc->param_name = push_array(part, String, memory_size); - doc->param_docs = doc->param_name + param_count; - doc->see_also = doc->param_docs + param_count; - + doc->param_name = push_array(arena, String_Const_char, param_count); + doc->param_docs = push_array(arena, String_Const_char, param_count); + doc->see_also = push_array(arena, String_Const_char, see_count); doc->param_count = param_count; doc->see_also_count = see_count; } @@ -468,7 +493,7 @@ perform_doc_parse(Partition *part, String doc_string, Documentation *doc){ keep_parsing = true; pos = 0; do{ - String doc_note = doc_parse_note(doc_string, &pos); + String_Const_char doc_note = doc_parse_note(doc_string, &pos); if (doc_note.size == 0){ keep_parsing = false; } @@ -476,15 +501,15 @@ perform_doc_parse(Partition *part, String doc_string, Documentation *doc){ i32 doc_note_type; if (string_set_match(defined_doc_notes, ArrayCount(defined_doc_notes), doc_note, &doc_note_type)){ - String doc_note_string = doc_parse_note_string(doc_string, &pos); + String_Const_char doc_note_string = doc_parse_note_string(doc_string, &pos); switch (doc_note_type){ case DOC_PARAM: { Assert(param_index < param_count); i32 param_pos = 0; - String param_name = doc_parse_parameter(doc_note_string, ¶m_pos); - String param_docs = doc_parse_last_parameter(doc_note_string, ¶m_pos); + String_Const_char param_name = doc_parse_parameter(doc_note_string, ¶m_pos); + String_Const_char param_docs = doc_parse_last_parameter(doc_note_string, ¶m_pos); doc->param_name[param_index] = param_name; doc->param_docs[param_index] = param_docs; ++param_index; @@ -508,14 +533,14 @@ perform_doc_parse(Partition *part, String doc_string, Documentation *doc){ } } else{ - fprintf(stderr, "warning: invalid doc note %.*s\n", doc_note.size, doc_note.str); + fprintf(stderr, "warning: invalid doc note %.*s\n", (i32)doc_note.size, doc_note.str); } } }while(keep_parsing); } internal i32 -struct_parse(Partition *part, i32 is_struct, Parse_Context *context, Item_Node *top_member); +struct_parse(Arena *arena, i32 is_struct, Parse_Context *context, Item_Node *top_member); internal i32 struct_parse_member(Parse_Context *context, Item_Node *member){ @@ -523,7 +548,7 @@ struct_parse_member(Parse_Context *context, Item_Node *member){ Cpp_Token *token = get_token(context); - String doc_string = {}; + String_Const_char doc_string = {}; get_doc_string_from_prev(context, &doc_string); Cpp_Token *start_token = token; @@ -535,7 +560,7 @@ struct_parse_member(Parse_Context *context, Item_Node *member){ } if (token){ - String name = {}; + String_Const_char name = {}; Cpp_Token *token_j = 0; i32 nest_level = 0; @@ -557,11 +582,11 @@ struct_parse_member(Parse_Context *context, Item_Node *member){ } } - name = skip_chop_whitespace(get_lexeme(*token_j, context->data)); + name = string_skip_chop_whitespace(get_lexeme(*token_j, context->data)); - String type = skip_chop_whitespace(str_start_end(context->data, start_token->start, token_j->start)); + String_Const_char type = string_skip_chop_whitespace(SCchar_range(context->data, start_token->start, token_j->start)); - String type_postfix = skip_chop_whitespace(str_start_end(context->data, token_j->start + token_j->size, token->start)); + String_Const_char type_postfix = string_skip_chop_whitespace(SCchar_range(context->data, token_j->start + token_j->size, token->start)); set_token(context, token+1); result = true; @@ -578,7 +603,7 @@ struct_parse_member(Parse_Context *context, Item_Node *member){ } internal Item_Node* -struct_parse_next_member(Partition *part, Parse_Context *context){ +struct_parse_next_member(Arena *arena, Parse_Context *context){ Item_Node *result = 0; Cpp_Token *token = 0; @@ -586,11 +611,11 @@ struct_parse_next_member(Partition *part, Parse_Context *context){ for (; (token = get_token(context)) != 0; get_next_token(context)){ if (token->type == CPP_TOKEN_IDENTIFIER || (token->flags & CPP_TFLAG_IS_KEYWORD)){ - String lexeme = get_lexeme(*token, context->data); + String_Const_char lexeme = get_lexeme(*token, context->data); - if (match(lexeme, "STRUCT")){ - Item_Node *member = push_array(part, Item_Node, 1); - if (struct_parse(part, true, context, member)){ + if (string_match(lexeme, string_litexpr("STRUCT"))){ + Item_Node *member = push_array(arena, Item_Node, 1); + if (struct_parse(arena, true, context, member)){ result = member; break; } @@ -598,9 +623,9 @@ struct_parse_next_member(Partition *part, Parse_Context *context){ Assert(!"unhandled error"); } } - else if (match(lexeme, "UNION")){ - Item_Node *member = push_array(part, Item_Node, 1); - if (struct_parse(part, false, context, member)){ + else if (string_match(lexeme, string_litexpr("UNION"))){ + Item_Node *member = push_array(arena, Item_Node, 1); + if (struct_parse(arena, false, context, member)){ result = member; break; } @@ -609,7 +634,7 @@ struct_parse_next_member(Partition *part, Parse_Context *context){ } } else{ - Item_Node *member = push_array(part, Item_Node, 1); + Item_Node *member = push_array(arena, Item_Node, 1); if (struct_parse_member(context, member)){ result = member; break; @@ -628,13 +653,13 @@ struct_parse_next_member(Partition *part, Parse_Context *context){ } internal i32 -struct_parse(Partition *part, i32 is_struct, Parse_Context *context, Item_Node *top_member){ +struct_parse(Arena *arena, i32 is_struct, Parse_Context *context, Item_Node *top_member){ i32 result = false; Cpp_Token *start_token = get_token(context); Cpp_Token *token = 0; - String doc_string = {}; + String_Const_char doc_string = {}; get_doc_string_from_prev(context, &doc_string); for (; (token = get_token(context)) != 0; get_next_token(context)){ @@ -652,28 +677,28 @@ struct_parse(Partition *part, i32 is_struct, Parse_Context *context, Item_Node * } } - String name = {}; + String_Const_char name = {}; if (token_j != start_token){ - name = skip_chop_whitespace(get_lexeme(*token_j, context->data)); + name = string_skip_chop_whitespace(get_lexeme(*token_j, context->data)); } - String type = {}; + String_Const_char type = {}; if (is_struct){ - type = make_lit_string("struct"); + type = string_litexpr("struct"); } else{ - type = make_lit_string("union"); + type = string_litexpr("union"); } set_token(context, token+1); - Item_Node *new_member = struct_parse_next_member(part, context); + Item_Node *new_member = struct_parse_next_member(arena, context); if (new_member){ top_member->first_child = new_member; Item_Node *head_member = new_member; for(;;){ - new_member = struct_parse_next_member(part, context); + new_member = struct_parse_next_member(arena, context); if (new_member){ head_member->next_sibling = new_member; head_member = new_member; @@ -713,7 +738,7 @@ typedef_parse(Parse_Context *context, Item_Node *item){ i32 result = false; Cpp_Token *token = get_token(context); - String doc_string = {}; + String_Const_char doc_string = {}; get_doc_string_from_prev(context, &doc_string); Cpp_Token *start_token = token; @@ -733,9 +758,9 @@ typedef_parse(Parse_Context *context, Item_Node *item){ } } - String name = get_lexeme(*token_j, context->data); + String_Const_char name = get_lexeme(*token_j, context->data); - String type = skip_chop_whitespace(str_start_end(context->data, start_token->start + start_token->size, token_j->start)); + String_Const_char type = string_skip_chop_whitespace(SCchar_range(context->data, start_token->start + start_token->size, token_j->start)); item->t = Item_Typedef; item->type = type; @@ -750,10 +775,10 @@ typedef_parse(Parse_Context *context, Item_Node *item){ } internal i32 -enum_parse(Partition *part, Parse_Context *context, Item_Node *item){ +enum_parse(Arena *arena, Parse_Context *context, Item_Node *item){ i32 result = false; - String parent_doc_string = {}; + String_Const_char parent_doc_string = {}; get_doc_string_from_prev(context, &parent_doc_string); Cpp_Token *parent_start_token = get_token(context); @@ -766,7 +791,7 @@ enum_parse(Partition *part, Parse_Context *context, Item_Node *item){ } if (token){ - String parent_name = {}; + String_Const_char parent_name = {}; Cpp_Token *token_j = 0; for (; (token_j = get_token(context)) != 0; get_prev_token(context)){ @@ -793,9 +818,9 @@ enum_parse(Partition *part, Parse_Context *context, Item_Node *item){ break; } else if (token->type == CPP_TOKEN_IDENTIFIER){ - String doc_string = {}; - String name = {}; - String value = {}; + String_Const_char doc_string = {}; + String_Const_char name = {}; + String_Const_char value = {}; get_doc_string_from_prev(context, &doc_string); name = get_lexeme(*token, context->data); @@ -813,7 +838,7 @@ enum_parse(Partition *part, Parse_Context *context, Item_Node *item){ } } - value = skip_chop_whitespace(str_start_end(context->data, start_token->start + start_token->size, token->start)); + value = string_skip_chop_whitespace(SCchar_range(context->data, start_token->start + start_token->size, token->start)); get_prev_token(context); } @@ -822,7 +847,7 @@ enum_parse(Partition *part, Parse_Context *context, Item_Node *item){ } } - Item_Node *new_member = push_array(part, Item_Node, 1); + Item_Node *new_member = push_array(arena, Item_Node, 1); if (first_member == 0){ first_member = new_member; } @@ -860,11 +885,11 @@ enum_parse(Partition *part, Parse_Context *context, Item_Node *item){ } internal Argument_Breakdown -allocate_argument_breakdown(Partition *part, i32 count){ +allocate_argument_breakdown(Arena *arena, i32 count){ Argument_Breakdown breakdown = {}; if (count > 0){ breakdown.count = count; - breakdown.args = push_array(part, Argument, count); + breakdown.args = push_array(arena, Argument, count); memset(breakdown.args, 0, sizeof(Argument)*count); } return(breakdown); @@ -876,7 +901,7 @@ foo(a, ... , z) ^ ^ */ internal Argument_Breakdown -parameter_parse(Partition *part, char *data, Cpp_Token *args_start_token, Cpp_Token *args_end_token){ +parameter_parse(Arena *arena, char *data, Cpp_Token *args_start_token, Cpp_Token *args_end_token){ i32 arg_index = 0; Cpp_Token *arg_token = args_start_token + 1; i32 param_string_start = arg_token->start; @@ -889,7 +914,7 @@ parameter_parse(Partition *part, char *data, Cpp_Token *args_start_token, Cpp_To } } - Argument_Breakdown breakdown = allocate_argument_breakdown(part, arg_count); + Argument_Breakdown breakdown = allocate_argument_breakdown(arena, arg_count); arg_token = args_start_token + 1; for (; arg_token <= args_end_token; ++arg_token){ @@ -897,8 +922,8 @@ parameter_parse(Partition *part, char *data, Cpp_Token *args_start_token, Cpp_To arg_token->type == CPP_TOKEN_PARENTHESE_CLOSE){ i32 size = arg_token->start - param_string_start; - String param_string = make_string(data + param_string_start, size); - param_string = chop_whitespace(param_string); + String_Const_char param_string = SCchar(data + param_string_start, size); + param_string = string_chop_whitespace(param_string); breakdown.args[arg_index].param_string = param_string; for (Cpp_Token *param_name_token = arg_token - 1; @@ -907,7 +932,7 @@ parameter_parse(Partition *part, char *data, Cpp_Token *args_start_token, Cpp_To if (param_name_token->type == CPP_TOKEN_IDENTIFIER){ i32 name_start = param_name_token->start; i32 name_size = param_name_token->size; - breakdown.args[arg_index].param_name = make_string(data + name_start, name_size); + breakdown.args[arg_index].param_name = SCchar(data + name_start, name_size); break; } } @@ -961,11 +986,11 @@ Moves the context in the following way: ^ ---------------> ^ */ internal i32 -function_get_doc(Parse_Context *context, char *data, String *doc_string){ +function_get_doc(Parse_Context *context, char *data, String_Const_char *doc_string){ i32 result = false; Cpp_Token *token = get_token(context); - String lexeme = {}; + String_Const_char lexeme = {}; if (function_parse_goto_name(context)){ if (token->type == CPP_TOKEN_IDENTIFIER){ @@ -989,7 +1014,7 @@ function_get_doc(Parse_Context *context, char *data, String *doc_string){ } internal i32 -cpp_name_parse(Parse_Context *context, String *name){ +cpp_name_parse(Parse_Context *context, String_Const_char *name){ i32 result = false; Cpp_Token *token = 0; @@ -1020,7 +1045,7 @@ Moves the context in the following way: ^ ---------------> ^ */ internal i32 -function_sig_parse(Partition *part, Parse_Context *context, Item_Node *item, String cpp_name){ +function_sig_parse(Arena *arena, Parse_Context *context, Item_Node *item, String_Const_char cpp_name){ i32 result = false; Cpp_Token *token = 0; @@ -1032,7 +1057,7 @@ function_sig_parse(Partition *part, Parse_Context *context, Item_Node *item, Str args_start_token = token+1; item->name = get_lexeme(*token, context->data); - item->ret = chop_whitespace(str_start_end(context->data, ret_token->start, token->start)); + item->ret = string_chop_whitespace(SCchar_range(context->data, ret_token->start, token->start)); for (; (token = get_token(context)) != 0; get_next_token(context)){ if (token->type == CPP_TOKEN_PARENTHESE_CLOSE){ @@ -1041,10 +1066,10 @@ function_sig_parse(Partition *part, Parse_Context *context, Item_Node *item, Str } if (token){ - item->args = str_start_end(context->data, args_start_token->start, token->start + token->size); + item->args = SCchar_range(context->data, args_start_token->start, token->start + token->size); item->t = Item_Function; item->cpp_name = cpp_name; - item->breakdown = parameter_parse(part, context->data, args_start_token, token); + item->breakdown = parameter_parse(arena, context->data, args_start_token, token); Assert(get_token(context)->type == CPP_TOKEN_PARENTHESE_CLOSE); result = true; @@ -1060,10 +1085,10 @@ Moves the context in the following way: ^ -------------------> ^ */ internal i32 -function_parse(Partition *part, Parse_Context *context, Item_Node *item, String cpp_name){ +function_parse(Arena *arena, Parse_Context *context, Item_Node *item, String_Const_char cpp_name){ i32 result = false; - String doc_string = {}; + String_Const_char doc_string = {}; Cpp_Token *token = get_token(context); item->marker = get_lexeme(*token, context->data); @@ -1074,7 +1099,7 @@ function_parse(Partition *part, Parse_Context *context, Item_Node *item, String set_token(context, token); if (get_next_token(context)){ - if (function_sig_parse(part, context, item, cpp_name)){ + if (function_sig_parse(arena, context, item, cpp_name)){ Assert(get_token(context)->type == CPP_TOKEN_PARENTHESE_CLOSE); result = true; } @@ -1113,14 +1138,14 @@ Moves the context in the following way: ^ ----------------------------> ^ */ internal i32 -macro_parse(Partition *part, Parse_Context *context, Item_Node *item){ +macro_parse(Arena *arena, Parse_Context *context, Item_Node *item){ i32 result = false; Cpp_Token *token = 0; Cpp_Token *doc_token = 0; Cpp_Token *args_start_token = 0; - String doc_string = {}; + String_Const_char doc_string = {}; if (macro_parse_check(context)){ token = get_token(context); @@ -1150,9 +1175,9 @@ macro_parse(Partition *part, Parse_Context *context, Item_Node *item){ } if (token){ - item->args = str_start_end(context->data, args_start_token->start, token->start + token->size); + item->args = SCchar_range(context->data, args_start_token->start, token->start + token->size); - item->breakdown = parameter_parse(part, context->data, args_start_token, token); + item->breakdown = parameter_parse(arena, context->data, args_start_token, token); if ((token = get_next_token(context)) != 0){ Cpp_Token *body_start = token; @@ -1166,7 +1191,7 @@ macro_parse(Partition *part, Parse_Context *context, Item_Node *item){ token = get_prev_token(context); - item->body = str_start_end(context->data, body_start->start,token->start + token->size); + item->body = SCchar_range(context->data, body_start->start,token->start + token->size); } } @@ -1183,28 +1208,27 @@ macro_parse(Partition *part, Parse_Context *context, Item_Node *item){ } internal Meta_Unit -compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keywords *meta_keywords, i32 key_count){ +compile_meta_unit(Arena *arena, char *code_directory, char **files, Meta_Keywords *meta_keywords, i32 key_count){ Meta_Unit unit = {}; i32 file_count = 0; for (char **file_ptr = files; *file_ptr; ++file_ptr, ++file_count); unit.count = file_count; - unit.parse = push_array(part, Parse, file_count); + unit.parse = push_array(arena, Parse, file_count); b32 all_files_lexed = true; i32 i = 0; for (char **file_ptr = files; *file_ptr; ++file_ptr, ++i){ - char str_space[512]; - String name = make_fixed_width_string(str_space); - append_sc(&name, code_directory); -#if defined(_WIN32) - append_sc(&name, "\\"); + List_String_Const_char name_list = {}; + string_list_push(arena, &name_list, SCchar(code_directory)); +#if OS_WINDOWS + string_list_push_lit(arena, &name_list, "\\"); #else - append_sc(&name, "/"); + string_list_push_lit(arena, &name_list, "/"); #endif - append_sc(&name, *file_ptr); - terminate_with_null(&name); + string_list_push(arena, &name_list, SCchar(*file_ptr)); + String_Const_char name = string_list_flatten(arena, name_list, StringFill_NullTerminate); unit.parse[i] = meta_lex(name.str); if (unit.parse[i].code.str == 0){ @@ -1223,7 +1247,7 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw for (; (token = get_token(context)) != 0; get_next_token(context)){ if (!(token->flags & CPP_TFLAG_PP_BODY)){ - String lexeme = get_lexeme(*token, context->data); + String_Const_char lexeme = get_lexeme(*token, context->data); i32 match_index = 0; if (string_set_match_table(meta_keywords, sizeof(*meta_keywords), key_count, lexeme, &match_index)){ Item_Type type = meta_keywords[match_index].type; @@ -1240,7 +1264,7 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw } if (unit.set.count > 0){ - unit.set = allocate_item_set(part, unit.set.count); + unit.set = allocate_item_set(arena, unit.set.count); } i32 index = 0; @@ -1250,13 +1274,13 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw Parse_Context context_ = setup_parse_context(unit.parse[J]); Parse_Context *context = &context_; - String cpp_name = {}; + String_Const_char cpp_name = {}; i32 has_cpp_name = 0; for (; (token = get_token(context)) != 0; get_next_token(context)){ if (!(token->flags & CPP_TFLAG_PP_BODY)){ - String lexeme = get_lexeme(*token, context->data); + String_Const_char lexeme = get_lexeme(*token, context->data); i32 match_index = 0; if (string_set_match_table(meta_keywords, sizeof(*meta_keywords), key_count, lexeme, &match_index)){ Item_Type type = meta_keywords[match_index].type; @@ -1264,7 +1288,7 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw switch (type){ case Item_Function: { - if (function_parse(part, context, unit.set.items + index, cpp_name)){ + if (function_parse(arena, context, unit.set.items + index, cpp_name)){ Assert(unit.set.items[index].t == Item_Function); ++index; } @@ -1285,7 +1309,7 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw case Item_Macro: { - if (macro_parse(part, context, unit.set.items + index)){ + if (macro_parse(arena, context, unit.set.items + index)){ Assert(unit.set.items[index].t == Item_Macro); ++index; } @@ -1307,7 +1331,7 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw case Item_Struct: case Item_Union: //struct/union { - if (struct_parse(part, (type == Item_Struct), context, unit.set.items + index)){ + if (struct_parse(arena, (type == Item_Struct), context, unit.set.items + index)){ Assert(unit.set.items[index].t == Item_Struct ||unit.set.items[index].t == Item_Union); ++index; } @@ -1318,7 +1342,7 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw case Item_Enum: //ENUM { - if (enum_parse(part, context, unit.set.items + index)){ + if (enum_parse(arena, context, unit.set.items + index)){ Assert(unit.set.items[index].t == Item_Enum); ++index; } @@ -1335,7 +1359,7 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw has_cpp_name = 0; } else{ - cpp_name = null_string; + block_zero_struct(&cpp_name); } unit.parse[J].item_count = index; @@ -1356,10 +1380,9 @@ compile_meta_unit(Partition *part, char *code_directory, char **files, Meta_Keyw } internal Meta_Unit -compile_meta_unit(Partition *part, char *code_directory, char *file, Meta_Keywords *meta_keywords, i32 key_count){ +compile_meta_unit(Arena *arena, char *code_directory, char *file, Meta_Keywords *meta_keywords, i32 key_count){ char *file_array[2] = {file, 0}; - Meta_Unit unit = compile_meta_unit(part, code_directory, file_array, meta_keywords, key_count); - return(unit); + return(compile_meta_unit(arena, code_directory, file_array, meta_keywords, key_count)); } #endif diff --git a/meta/4ed_metagen.cpp b/meta/4ed_metagen.cpp index 033e28e4..25d56f81 100644 --- a/meta/4ed_metagen.cpp +++ b/meta/4ed_metagen.cpp @@ -12,13 +12,14 @@ #define API_H "4coder_generated/app_functions.h" #define REMAPPING_FILE "4coder_generated/remapping.h" -#include "4ed_defines.h" #include "4coder_base_types.h" #include "4ed_meta_defines.h" #include "4coder_API/4coder_version.h" #include "4coder_API/4coder_keycodes.h" # include "4coder_lib/4coder_arena.h" +#include "4coder_base_types.cpp" +#include "4coder_stringf.cpp" # include "4coder_lib/4coder_arena.cpp" # define FSTRING_IMPLEMENTATION # include "4coder_lib/4coder_string.h" @@ -38,8 +39,8 @@ // struct App_API_Name{ - String macro; - String public_name; + String_Const_char macro; + String_Const_char public_name; }; struct App_API{ @@ -47,49 +48,50 @@ struct App_API{ }; internal App_API -allocate_app_api(Partition *part, i32 count){ +allocate_app_api(Arena *arena, i32 count){ App_API app_api = {}; - app_api.names = push_array(part, App_API_Name, count); + app_api.names = push_array(arena, App_API_Name, count); memset(app_api.names, 0, sizeof(App_API_Name)*count); return(app_api); } internal void -generate_custom_headers(Partition *part){ - Temp_Memory temp = begin_temp_memory(part); +generate_custom_headers(Arena *arena){ + Temp_Memory temp = begin_temp(arena); // NOTE(allen): Parse the customization API files static char *functions_files[] = { "4ed_api_implementation.cpp", 0 }; - Meta_Unit unit_custom = compile_meta_unit(part, ".", functions_files, ExpandArray(meta_keywords)); + Meta_Unit unit_custom = compile_meta_unit(arena, ".", functions_files, ExpandArray(meta_keywords)); if (unit_custom.parse == 0){ Assert(!"Missing one or more input files!"); } // NOTE(allen): Compute and store variations of the function names - App_API func_4ed_names = allocate_app_api(part, unit_custom.set.count); + App_API func_4ed_names = allocate_app_api(arena, unit_custom.set.count); for (i32 i = 0; i < unit_custom.set.count; ++i){ - String name_string = unit_custom.set.items[i].name; - String *macro = &func_4ed_names.names[i].macro; - String *public_name = &func_4ed_names.names[i].public_name; + String_Const_char name_string = unit_custom.set.items[i].name; - *macro = string_push(part, name_string.size + 4); - to_upper(macro, name_string); - append(macro, make_lit_string("_SIG")); + List_String_Const_char macro_list = {}; + string_list_push(arena, ¯o_list, string_mod_upper(string_copy(arena, name_string))); + string_list_push_lit(arena, ¯o_list, "_SIG"); + func_4ed_names.names[i].macro = string_list_flatten(arena, macro_list); - *public_name = string_push(part, name_string.size); - to_lower(public_name, name_string); - - push_align(part, 8); + func_4ed_names.names[i].public_name = string_mod_lower(string_copy(arena, name_string)); } // NOTE(allen): Output - String out = string_push(part, 10 << 20); + List_String_Const_char out_list = {}; // NOTE(allen): Custom API headers - append(&out, "struct Application_Links;\n"); + string_list_push_lit(arena, &out_list, "struct Application_Links;\n"); for (i32 i = 0; i < unit_custom.set.count; ++i){ + string_list_pushf(arena, &out_list, "#define %.*s(n) %.*s n%.*s\n", + string_expand(func_4ed_names.names[i].macro), + string_expand(unit_custom.set.items[i].ret), + string_expand(unit_custom.set.items[i].args)); +#if 0 append(&out, "#define "); append(&out, func_4ed_names.names[i].macro); append(&out, "(n) "); @@ -97,110 +99,125 @@ generate_custom_headers(Partition *part){ append(&out, " n"); append(&out, unit_custom.set.items[i].args); append_s_char(&out, '\n'); +#endif } for (i32 i = 0; i < unit_custom.set.count; ++i){ + string_list_pushf(arena, &out_list, "typedef %.*s(%.*s_Function);\n", + string_expand(func_4ed_names.names[i].macro), + string_expand(unit_custom.set.items[i].name)); +#if 0 append(&out, "typedef "); append(&out, func_4ed_names.names[i].macro); append_s_char(&out, '('); append(&out, unit_custom.set.items[i].name); append(&out, "_Function);\n"); +#endif } - append(&out, "struct Application_Links{\n"); - - append(&out, "#if defined(ALLOW_DEP_4CODER)\n"); + string_list_push_lit(arena, &out_list, "struct Application_Links{\n"); + string_list_push_lit(arena, &out_list, "#if defined(ALLOW_DEP_4CODER)\n"); for (i32 i = 0; i < unit_custom.set.count; ++i){ + string_list_pushf(arena, &out_list, "%.*s_Function *%.*s;\n", + string_expand(unit_custom.set.items[i].name), + string_expand(func_4ed_names.names[i].public_name)); +#if 0 append(&out, unit_custom.set.items[i].name); append(&out, "_Function *"); append(&out, func_4ed_names.names[i].public_name); append(&out, ";\n"); +#endif } - append(&out, "#else\n"); + string_list_push_lit(arena, &out_list, "#else\n"); for (i32 i = 0; i < unit_custom.set.count; ++i){ + string_list_pushf(arena, &out_list, "%.*s_Function *%.*s_;\n", + string_expand(unit_custom.set.items[i].name), + string_expand(func_4ed_names.names[i].public_name)); +#if 0 append(&out, unit_custom.set.items[i].name); append(&out, "_Function *"); append(&out, func_4ed_names.names[i].public_name); append(&out, "_;\n"); +#endif } - append(&out, "#endif\n"); - append(&out, - "void *memory;\n" - "int32_t memory_size;\n" - "void *cmd_context;\n" - "void *system_links;\n" - "void *current_coroutine;\n" - "int32_t type_coroutine;\n" - "};\n"); + string_list_push_lit(arena, &out_list, "#endif\n"); + + string_list_push_lit(arena, &out_list, + "void *memory;\n" + "int32_t memory_size;\n" + "void *cmd_context;\n" + "void *system_links;\n" + "void *current_coroutine;\n" + "int32_t type_coroutine;\n" + "};\n"); + + string_list_push_lit(arena, &out_list, "#define FillAppLinksAPI(app_links) do{"); - append(&out, "#define FillAppLinksAPI(app_links) do{"); for (i32 i = 0; i < unit_custom.set.count; ++i){ - append(&out, "\\\napp_links->"); - append(&out, func_4ed_names.names[i].public_name); - append(&out, "_ = "); - append(&out, unit_custom.set.items[i].name); - append_s_char(&out, ';'); + string_list_pushf(arena, &out_list, "\\\napp_links->%.*s_ = %.*s;", + string_expand(func_4ed_names.names[i].public_name), + string_expand(unit_custom.set.items[i].name)); } - append(&out, "} while(false)\n"); - append(&out, "#if defined(ALLOW_DEP_4CODER)\n"); + string_list_push_lit(arena, &out_list, "} while(false)\n"); + + string_list_push_lit(arena, &out_list, "#if defined(ALLOW_DEP_4CODER)\n"); for (i32 use_dep = 1; use_dep >= 0; --use_dep){ for (i32 i = 0; i < unit_custom.set.count; ++i){ Argument_Breakdown breakdown = unit_custom.set.items[i].breakdown; - String ret = unit_custom.set.items[i].ret; - String public_name = func_4ed_names.names[i].public_name; + String_Const_char ret = unit_custom.set.items[i].ret; + String_Const_char public_name = func_4ed_names.names[i].public_name; - append(&out, "static "); - append(&out, ret); - append(&out, " "); - append(&out, public_name); - - append(&out, "("); - for (i32 j = 0; j < breakdown.count; ++j){ - append(&out, breakdown.args[j].param_string); - if (j+1 != breakdown.count){ - append(&out, ", "); + string_list_pushf(arena, &out_list, "static %.*s %.*s(", + string_expand(ret), string_expand(public_name)); + for (i32 j = 0; j < breakdown.count; j += 1){ + if (j + 1 != breakdown.count){ + string_list_pushf(arena, &out_list, "%.*s, ", + string_expand(breakdown.args[j].param_string)); + } + else{ + string_list_push(arena, &out_list, breakdown.args[j].param_string); } } - append(&out, "){"); + string_list_push_lit(arena, &out_list, "){"); - if (match(ret, make_lit_string("void"))){ - append(&out, "("); + if (string_match(ret, string_litexpr("void"))){ + string_list_push_lit(arena, &out_list, "("); } else{ - append(&out, "return("); + string_list_push_lit(arena, &out_list, "return("); } - append(&out, "app->"); - append(&out, public_name); + string_list_pushf(arena, &out_list, "app->%.*s", string_expand(public_name)); if (!use_dep){ - append(&out, "_"); + string_list_push_lit(arena, &out_list, "_"); } - append(&out, "("); + string_list_push_lit(arena, &out_list, "("); for (i32 j = 0; j < breakdown.count; ++j){ - append(&out, breakdown.args[j].param_name); - if (j+1 != breakdown.count){ - append(&out, ", "); + if (j + 1 != breakdown.count){ + string_list_pushf(arena, &out_list, "%.*s, ", + string_expand(breakdown.args[j].param_name)); + } + else{ + string_list_push(arena, &out_list, breakdown.args[j].param_name); } } - append(&out, ")"); - - append(&out, ");}\n"); + string_list_push_lit(arena, &out_list, "));}\n"); } if (use_dep == 1){ - append(&out, "#else\n"); + string_list_push_lit(arena, &out_list, "#else\n"); } } - append(&out, "#endif\n"); + string_list_push_lit(arena, &out_list, "#endif\n"); - fm_write_file(API_H, out.str, out.size); - out.size = 0; + String_Const_char out = string_list_flatten(arena, out_list); + fm_write_file(API_H, out.str, (i32)out.size); - end_temp_memory(temp); + end_temp(temp); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -263,17 +280,17 @@ enum{ ////////////////////////////////////////////////////////////////////////////////////////////////// internal void -emit_begin_mapping(Partition *part, Mapping_Array *array, char *name, char *description){ +emit_begin_mapping(Arena *arena, Mapping_Array *array, char *name, char *description){ Assert(array->current_mapping == 0); - Mapping *mapping = push_array(part, Mapping, 1); - mapping->name = fm_basic_str(part, name); - mapping->name_len = str_size(name); - mapping->description = fm_basic_str(part, description); - mapping->description_len = str_size(description); + Mapping *mapping = push_array(arena, Mapping, 1); + mapping->name = fm_basic_str(arena, name); + mapping->name_len = (i32)cstring_length(name); + mapping->description = fm_basic_str(arena, description); + mapping->description_len = (i32)cstring_length(description); mapping->first_sub_map = 0; mapping->last_sub_map = 0; mapping->sub_map_count = 0; - sll_push(array->first_mapping, array->last_mapping, mapping); + sll_queue_push(array->first_mapping, array->last_mapping, mapping); ++array->mapping_count; array->current_mapping = mapping; } @@ -285,15 +302,15 @@ emit_end_mapping(Mapping_Array *array){ } internal void -emit_begin_map(Partition *part, Mapping_Array *array, char *mapid, char *description){ +emit_begin_map(Arena *arena, Mapping_Array *array, char *mapid, char *description){ Assert(array->current_mapping != 0); Assert(array->current_sub_map == 0); - Sub_Map *sub_map = push_array(part, Sub_Map, 1); - sub_map->name = fm_basic_str(part, mapid); - sub_map->name_len = str_size(mapid); - sub_map->description = fm_basic_str(part, description); - sub_map->description_len = str_size(description); + Sub_Map *sub_map = push_array(arena, Sub_Map, 1); + sub_map->name = fm_basic_str(arena, mapid); + sub_map->name_len = (i32)cstring_length(mapid); + sub_map->description = fm_basic_str(arena, description); + sub_map->description_len = (i32)cstring_length(description); sub_map->parent = 0; sub_map->parent_len = 0; sub_map->first_key_bind = 0; @@ -301,7 +318,7 @@ emit_begin_map(Partition *part, Mapping_Array *array, char *mapid, char *descrip sub_map->key_bind_count = 0; Mapping *mapping = array->current_mapping; - sll_push(mapping->first_sub_map, mapping->last_sub_map, sub_map); + sll_queue_push(mapping->first_sub_map, mapping->last_sub_map, sub_map); ++mapping->sub_map_count; array->current_sub_map = sub_map; @@ -315,19 +332,19 @@ emit_end_map(Mapping_Array *array){ } internal void -emit_inherit_map(Partition *part, Mapping_Array *array, char *mapid){ +emit_inherit_map(Arena *arena, Mapping_Array *array, char *mapid){ Assert(array->current_mapping != 0); Assert(array->current_sub_map != 0); Sub_Map *sub_map = array->current_sub_map; Assert(sub_map->parent == 0); - sub_map->parent = fm_basic_str(part, mapid); - sub_map->parent_len = str_size(mapid); + sub_map->parent = fm_basic_str(arena, mapid); + sub_map->parent_len = (i32)cstring_length(mapid); } internal void -emit_bind(Partition *part, Mapping_Array *array, u32 keycode, u32 modifiers, char *command){ +emit_bind(Arena *arena, Mapping_Array *array, u32 keycode, u32 modifiers, char *command){ Assert(array->current_mapping != 0); Assert(array->current_sub_map != 0); @@ -344,31 +361,31 @@ emit_bind(Partition *part, Mapping_Array *array, u32 keycode, u32 modifiers, cha } if (!is_duplicate){ - Key_Bind *bind = push_array(part, Key_Bind, 1); + Key_Bind *bind = push_array(arena, Key_Bind, 1); bind->vanilla = false; bind->keycode = keycode; bind->modifiers = modifiers; - bind->command = fm_basic_str(part, command); - bind->command_len = str_size(command); - sll_push(sub_map->first_key_bind, sub_map->last_key_bind, bind); + bind->command = fm_basic_str(arena, command); + bind->command_len = (i32)cstring_length(command); + sll_queue_push(sub_map->first_key_bind, sub_map->last_key_bind, bind); ++sub_map->key_bind_count; } } internal void -emit_bind_all_modifiers(Partition *part, Mapping_Array *mappings, u32 code, char *command){ - emit_bind(part, mappings, code, MDFR_NONE, command); - emit_bind(part, mappings, code, MDFR_CTRL, command); - emit_bind(part, mappings, code, MDFR_ALT , command); - emit_bind(part, mappings, code, MDFR_CMND, command); - emit_bind(part, mappings, code, MDFR_CTRL|MDFR_ALT , command); - emit_bind(part, mappings, code, MDFR_ALT |MDFR_CMND, command); - emit_bind(part, mappings, code, MDFR_CTRL|MDFR_CMND, command); - emit_bind(part, mappings, code, MDFR_CTRL|MDFR_ALT|MDFR_CMND, command); +emit_bind_all_modifiers(Arena *arena, Mapping_Array *mappings, u32 code, char *command){ + emit_bind(arena, mappings, code, MDFR_NONE, command); + emit_bind(arena, mappings, code, MDFR_CTRL, command); + emit_bind(arena, mappings, code, MDFR_ALT , command); + emit_bind(arena, mappings, code, MDFR_CMND, command); + emit_bind(arena, mappings, code, MDFR_CTRL|MDFR_ALT , command); + emit_bind(arena, mappings, code, MDFR_ALT |MDFR_CMND, command); + emit_bind(arena, mappings, code, MDFR_CTRL|MDFR_CMND, command); + emit_bind(arena, mappings, code, MDFR_CTRL|MDFR_ALT|MDFR_CMND, command); } internal void -emit_bind_vanilla_keys(Partition *part, Mapping_Array *array, u32 modifiers, char *command){ +emit_bind_vanilla_keys(Arena *arena, Mapping_Array *array, u32 modifiers, char *command){ Assert(array->current_mapping != 0); Assert(array->current_sub_map != 0); @@ -385,13 +402,13 @@ emit_bind_vanilla_keys(Partition *part, Mapping_Array *array, u32 modifiers, cha } if (!is_duplicate){ - Key_Bind *bind = push_array(part, Key_Bind, 1); + Key_Bind *bind = push_array(arena, Key_Bind, 1); bind->vanilla = true; bind->keycode = 0; bind->modifiers = modifiers; - bind->command = fm_basic_str(part, command); - bind->command_len = str_size(command); - sll_push(sub_map->first_key_bind, sub_map->last_key_bind, bind); + bind->command = fm_basic_str(arena, command); + bind->command_len = (i32)cstring_length(command); + sll_queue_push(sub_map->first_key_bind, sub_map->last_key_bind, bind); ++sub_map->key_bind_count; } } @@ -408,459 +425,459 @@ emit_bind_vanilla_keys(Partition *part, Mapping_Array *array, u32 modifiers, cha ////////////////////////////////////////////////////////////////////////////////////////////////// internal void -generate_remapping_code_and_data(Partition *part){ - Temp_Memory temp = begin_temp_memory(part); +generate_remapping_code_and_data(Arena *arena){ + Temp_Memory temp = begin_temp(arena); // Generate mapping array data structure Mapping_Array mappings_ = {}; Mapping_Array *mappings = &mappings_; - begin_mapping(part, mappings, default, "The default 4coder bindings - typically good for Windows and Linux"); + begin_mapping(arena, mappings, default, "The default 4coder bindings - typically good for Windows and Linux"); { // NOTE(allen): GLOBAL - begin_map(part, mappings, mapid_global, "The following bindings apply in all situations."); + begin_map(arena, mappings, mapid_global, "The following bindings apply in all situations."); - bind(part, mappings, ',', MDFR_CTRL, change_active_panel); - bind(part, mappings, '<', MDFR_CTRL, change_active_panel_backwards); + bind(arena, mappings, ',', MDFR_CTRL, change_active_panel); + bind(arena, mappings, '<', MDFR_CTRL, change_active_panel_backwards); - bind(part, mappings, 'n', MDFR_CTRL, interactive_new); - bind(part, mappings, 'o', MDFR_CTRL, interactive_open_or_new); - bind(part, mappings, 'o', MDFR_ALT , open_in_other); - bind(part, mappings, 'k', MDFR_CTRL, interactive_kill_buffer); - bind(part, mappings, 'i', MDFR_CTRL, interactive_switch_buffer); - bind(part, mappings, 'h', MDFR_CTRL, project_go_to_root_directory); - bind(part, mappings, 'S', MDFR_CTRL, save_all_dirty_buffers); + bind(arena, mappings, 'n', MDFR_CTRL, interactive_new); + bind(arena, mappings, 'o', MDFR_CTRL, interactive_open_or_new); + bind(arena, mappings, 'o', MDFR_ALT , open_in_other); + bind(arena, mappings, 'k', MDFR_CTRL, interactive_kill_buffer); + bind(arena, mappings, 'i', MDFR_CTRL, interactive_switch_buffer); + bind(arena, mappings, 'h', MDFR_CTRL, project_go_to_root_directory); + bind(arena, mappings, 'S', MDFR_CTRL, save_all_dirty_buffers); - bind(part, mappings, key_scroll_lock, MDFR_NONE, toggle_filebar); - bind(part, mappings, key_pause, MDFR_NONE, toggle_filebar); - bind(part, mappings, key_caps, MDFR_NONE, toggle_filebar); + bind(arena, mappings, key_scroll_lock, MDFR_NONE, toggle_filebar); + bind(arena, mappings, key_pause, MDFR_NONE, toggle_filebar); + bind(arena, mappings, key_caps, MDFR_NONE, toggle_filebar); - bind(part, mappings, '.', MDFR_ALT, change_to_build_panel); - bind(part, mappings, ',', MDFR_ALT, close_build_panel); - bind(part, mappings, 'n', MDFR_ALT, goto_next_jump_sticky); - bind(part, mappings, 'N', MDFR_ALT, goto_prev_jump_sticky); - bind(part, mappings, 'M', MDFR_ALT, goto_first_jump_sticky); - bind(part, mappings, 'm', MDFR_ALT, build_in_build_panel); - bind(part, mappings, 'b', MDFR_ALT, toggle_filebar); + bind(arena, mappings, '.', MDFR_ALT, change_to_build_panel); + bind(arena, mappings, ',', MDFR_ALT, close_build_panel); + bind(arena, mappings, 'n', MDFR_ALT, goto_next_jump_sticky); + bind(arena, mappings, 'N', MDFR_ALT, goto_prev_jump_sticky); + bind(arena, mappings, 'M', MDFR_ALT, goto_first_jump_sticky); + bind(arena, mappings, 'm', MDFR_ALT, build_in_build_panel); + bind(arena, mappings, 'b', MDFR_ALT, toggle_filebar); - bind(part, mappings, 'z', MDFR_ALT, execute_any_cli); - bind(part, mappings, 'Z', MDFR_ALT, execute_previous_cli); + bind(arena, mappings, 'z', MDFR_ALT, execute_any_cli); + bind(arena, mappings, 'Z', MDFR_ALT, execute_previous_cli); - bind(part, mappings, 'x', MDFR_ALT, command_lister); - bind(part, mappings, 'X', MDFR_ALT, project_command_lister); + bind(arena, mappings, 'x', MDFR_ALT, command_lister); + bind(arena, mappings, 'X', MDFR_ALT, project_command_lister); - bind(part, mappings, 'I', MDFR_CTRL, list_all_functions_all_buffers_lister); - bind(part, mappings, 'E', MDFR_ALT, exit_4coder); + bind(arena, mappings, 'I', MDFR_CTRL, list_all_functions_all_buffers_lister); + bind(arena, mappings, 'E', MDFR_ALT, exit_4coder); - bind(part, mappings, key_f1, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f2, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f3, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f4, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f1, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f2, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f3, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f4, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f5, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f6, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f7, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f8, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f5, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f6, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f7, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f8, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f9, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f10, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f11, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f12, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f9, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f10, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f11, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f12, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f13, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f14, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f15, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f16, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f13, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f14, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f15, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f16, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_mouse_wheel, MDFR_NONE, mouse_wheel_scroll); - bind(part, mappings, key_mouse_wheel, MDFR_CTRL, mouse_wheel_change_face_size); + bind(arena, mappings, key_mouse_wheel, MDFR_NONE, mouse_wheel_scroll); + bind(arena, mappings, key_mouse_wheel, MDFR_CTRL, mouse_wheel_change_face_size); end_map(mappings); // NOTE(allen): FILE - begin_map(part, mappings, mapid_file, "The following bindings apply in general text files and most apply in code files, but some are overriden by other commands specific to code files."); + begin_map(arena, mappings, mapid_file, "The following bindings apply in general text files and most apply in code files, but some are overriden by other commands specific to code files."); - bind_vanilla_keys(part, mappings, MDFR_NONE, write_character); + bind_vanilla_keys(arena, mappings, MDFR_NONE, write_character); - bind(part, mappings, key_mouse_left, MDFR_NONE, click_set_cursor_and_mark); - bind(part, mappings, key_click_activate_view, MDFR_NONE, click_set_cursor_and_mark); - bind(part, mappings, key_mouse_left_release, MDFR_NONE, click_set_cursor); - bind(part, mappings, key_mouse_move, MDFR_NONE, click_set_cursor_if_lbutton); + bind(arena, mappings, key_mouse_left, MDFR_NONE, click_set_cursor_and_mark); + bind(arena, mappings, key_click_activate_view, MDFR_NONE, click_set_cursor_and_mark); + bind(arena, mappings, key_mouse_left_release, MDFR_NONE, click_set_cursor); + bind(arena, mappings, key_mouse_move, MDFR_NONE, click_set_cursor_if_lbutton); - bind(part, mappings, key_del, MDFR_NONE, delete_char); - bind(part, mappings, key_del, MDFR_SHIFT, delete_char); - bind(part, mappings, key_back, MDFR_NONE, backspace_char); - bind(part, mappings, key_back, MDFR_SHIFT, backspace_char); + bind(arena, mappings, key_del, MDFR_NONE, delete_char); + bind(arena, mappings, key_del, MDFR_SHIFT, delete_char); + bind(arena, mappings, key_back, MDFR_NONE, backspace_char); + bind(arena, mappings, key_back, MDFR_SHIFT, backspace_char); - bind(part, mappings, key_up, MDFR_NONE, move_up); - bind(part, mappings, key_down, MDFR_NONE, move_down); - bind(part, mappings, key_left, MDFR_NONE, move_left); - bind(part, mappings, key_right, MDFR_NONE, move_right); - bind(part, mappings, key_up, MDFR_SHIFT, move_up); - bind(part, mappings, key_down, MDFR_SHIFT, move_down); - bind(part, mappings, key_left, MDFR_SHIFT, move_left); - bind(part, mappings, key_right, MDFR_SHIFT, move_right); + bind(arena, mappings, key_up, MDFR_NONE, move_up); + bind(arena, mappings, key_down, MDFR_NONE, move_down); + bind(arena, mappings, key_left, MDFR_NONE, move_left); + bind(arena, mappings, key_right, MDFR_NONE, move_right); + bind(arena, mappings, key_up, MDFR_SHIFT, move_up); + bind(arena, mappings, key_down, MDFR_SHIFT, move_down); + bind(arena, mappings, key_left, MDFR_SHIFT, move_left); + bind(arena, mappings, key_right, MDFR_SHIFT, move_right); - bind(part, mappings, key_end, MDFR_NONE, seek_end_of_line); - bind(part, mappings, key_home, MDFR_NONE, seek_beginning_of_line); - bind(part, mappings, key_page_up, MDFR_CTRL, goto_beginning_of_file); - bind(part, mappings, key_page_down, MDFR_CTRL, goto_end_of_file); - bind(part, mappings, key_page_up, MDFR_NONE, page_up); - bind(part, mappings, key_page_down, MDFR_NONE, page_down); - bind(part, mappings, key_end, MDFR_SHIFT, seek_end_of_line); - bind(part, mappings, key_home, MDFR_SHIFT, seek_beginning_of_line); - bind(part, mappings, key_page_up, MDFR_CTRL|MDFR_SHIFT, goto_beginning_of_file); - bind(part, mappings, key_page_down, MDFR_CTRL|MDFR_SHIFT, goto_end_of_file); - bind(part, mappings, key_page_up, MDFR_SHIFT, page_up); - bind(part, mappings, key_page_down, MDFR_SHIFT, page_down); + bind(arena, mappings, key_end, MDFR_NONE, seek_end_of_line); + bind(arena, mappings, key_home, MDFR_NONE, seek_beginning_of_line); + bind(arena, mappings, key_page_up, MDFR_CTRL, goto_beginning_of_file); + bind(arena, mappings, key_page_down, MDFR_CTRL, goto_end_of_file); + bind(arena, mappings, key_page_up, MDFR_NONE, page_up); + bind(arena, mappings, key_page_down, MDFR_NONE, page_down); + bind(arena, mappings, key_end, MDFR_SHIFT, seek_end_of_line); + bind(arena, mappings, key_home, MDFR_SHIFT, seek_beginning_of_line); + bind(arena, mappings, key_page_up, MDFR_CTRL|MDFR_SHIFT, goto_beginning_of_file); + bind(arena, mappings, key_page_down, MDFR_CTRL|MDFR_SHIFT, goto_end_of_file); + bind(arena, mappings, key_page_up, MDFR_SHIFT, page_up); + bind(arena, mappings, key_page_down, MDFR_SHIFT, page_down); - bind(part, mappings, key_up, MDFR_CTRL, seek_whitespace_up_end_line); - bind(part, mappings, key_down, MDFR_CTRL, seek_whitespace_down_end_line); - bind(part, mappings, key_left, MDFR_CTRL, seek_whitespace_left); - bind(part, mappings, key_right, MDFR_CTRL, seek_whitespace_right); - bind(part, mappings, key_up, MDFR_CTRL|MDFR_SHIFT, seek_whitespace_up_end_line); - bind(part, mappings, key_down, MDFR_CTRL|MDFR_SHIFT, seek_whitespace_down_end_line); - bind(part, mappings, key_left, MDFR_CTRL|MDFR_SHIFT, seek_whitespace_left); - bind(part, mappings, key_right, MDFR_CTRL|MDFR_SHIFT, seek_whitespace_right); + bind(arena, mappings, key_up, MDFR_CTRL, seek_whitespace_up_end_line); + bind(arena, mappings, key_down, MDFR_CTRL, seek_whitespace_down_end_line); + bind(arena, mappings, key_left, MDFR_CTRL, seek_whitespace_left); + bind(arena, mappings, key_right, MDFR_CTRL, seek_whitespace_right); + bind(arena, mappings, key_up, MDFR_CTRL|MDFR_SHIFT, seek_whitespace_up_end_line); + bind(arena, mappings, key_down, MDFR_CTRL|MDFR_SHIFT, seek_whitespace_down_end_line); + bind(arena, mappings, key_left, MDFR_CTRL|MDFR_SHIFT, seek_whitespace_left); + bind(arena, mappings, key_right, MDFR_CTRL|MDFR_SHIFT, seek_whitespace_right); - bind(part, mappings, key_up, MDFR_ALT, move_line_up); - bind(part, mappings, key_down, MDFR_ALT, move_line_down); + bind(arena, mappings, key_up, MDFR_ALT, move_line_up); + bind(arena, mappings, key_down, MDFR_ALT, move_line_down); - bind(part, mappings, key_back, MDFR_CTRL, backspace_word); - bind(part, mappings, key_del, MDFR_CTRL, delete_word); - bind(part, mappings, key_back, MDFR_ALT, snipe_token_or_word); - bind(part, mappings, key_del, MDFR_ALT, snipe_token_or_word_right); + bind(arena, mappings, key_back, MDFR_CTRL, backspace_word); + bind(arena, mappings, key_del, MDFR_CTRL, delete_word); + bind(arena, mappings, key_back, MDFR_ALT, snipe_token_or_word); + bind(arena, mappings, key_del, MDFR_ALT, snipe_token_or_word_right); - bind(part, mappings, ' ', MDFR_CTRL, set_mark); - bind(part, mappings, 'a', MDFR_CTRL, replace_in_range); - bind(part, mappings, 'c', MDFR_CTRL, copy); - bind(part, mappings, 'd', MDFR_CTRL, delete_range); - bind(part, mappings, 'D', MDFR_CTRL, delete_line); - bind(part, mappings, 'e', MDFR_CTRL, center_view); - bind(part, mappings, 'E', MDFR_CTRL, left_adjust_view); - bind(part, mappings, 'f', MDFR_CTRL, search); - bind(part, mappings, 'F', MDFR_CTRL, list_all_locations); - bind(part, mappings, 'F', MDFR_ALT , list_all_substring_locations_case_insensitive); - bind(part, mappings, 'g', MDFR_CTRL, goto_line); - bind(part, mappings, 'G', MDFR_CTRL, list_all_locations_of_selection); - bind(part, mappings, 'j', MDFR_CTRL, snippet_lister); - bind(part, mappings, 'K', MDFR_CTRL, kill_buffer); - bind(part, mappings, 'L', MDFR_CTRL, duplicate_line); - bind(part, mappings, 'm', MDFR_CTRL, cursor_mark_swap); - bind(part, mappings, 'O', MDFR_CTRL, reopen); - bind(part, mappings, 'q', MDFR_CTRL, query_replace); - bind(part, mappings, 'Q', MDFR_CTRL, query_replace_identifier); - bind(part, mappings, 'q', MDFR_ALT , query_replace_selection); - bind(part, mappings, 'r', MDFR_CTRL, reverse_search); - bind(part, mappings, 's', MDFR_CTRL, save); - bind(part, mappings, 't', MDFR_CTRL, search_identifier); - bind(part, mappings, 'T', MDFR_CTRL, list_all_locations_of_identifier); - bind(part, mappings, 'v', MDFR_CTRL, paste_and_indent); - bind(part, mappings, 'V', MDFR_CTRL, paste_next_and_indent); - bind(part, mappings, 'x', MDFR_CTRL, cut); - bind(part, mappings, 'y', MDFR_CTRL, redo); - bind(part, mappings, 'z', MDFR_CTRL, undo); + bind(arena, mappings, ' ', MDFR_CTRL, set_mark); + bind(arena, mappings, 'a', MDFR_CTRL, replace_in_range); + bind(arena, mappings, 'c', MDFR_CTRL, copy); + bind(arena, mappings, 'd', MDFR_CTRL, delete_range); + bind(arena, mappings, 'D', MDFR_CTRL, delete_line); + bind(arena, mappings, 'e', MDFR_CTRL, center_view); + bind(arena, mappings, 'E', MDFR_CTRL, left_adjust_view); + bind(arena, mappings, 'f', MDFR_CTRL, search); + bind(arena, mappings, 'F', MDFR_CTRL, list_all_locations); + bind(arena, mappings, 'F', MDFR_ALT , list_all_substring_locations_case_insensitive); + bind(arena, mappings, 'g', MDFR_CTRL, goto_line); + bind(arena, mappings, 'G', MDFR_CTRL, list_all_locations_of_selection); + bind(arena, mappings, 'j', MDFR_CTRL, snippet_lister); + bind(arena, mappings, 'K', MDFR_CTRL, kill_buffer); + bind(arena, mappings, 'L', MDFR_CTRL, duplicate_line); + bind(arena, mappings, 'm', MDFR_CTRL, cursor_mark_swap); + bind(arena, mappings, 'O', MDFR_CTRL, reopen); + bind(arena, mappings, 'q', MDFR_CTRL, query_replace); + bind(arena, mappings, 'Q', MDFR_CTRL, query_replace_identifier); + bind(arena, mappings, 'q', MDFR_ALT , query_replace_selection); + bind(arena, mappings, 'r', MDFR_CTRL, reverse_search); + bind(arena, mappings, 's', MDFR_CTRL, save); + bind(arena, mappings, 't', MDFR_CTRL, search_identifier); + bind(arena, mappings, 'T', MDFR_CTRL, list_all_locations_of_identifier); + bind(arena, mappings, 'v', MDFR_CTRL, paste_and_indent); + bind(arena, mappings, 'V', MDFR_CTRL, paste_next_and_indent); + bind(arena, mappings, 'x', MDFR_CTRL, cut); + bind(arena, mappings, 'y', MDFR_CTRL, redo); + bind(arena, mappings, 'z', MDFR_CTRL, undo); - bind(part, mappings, '1', MDFR_CTRL, view_buffer_other_panel); - bind(part, mappings, '2', MDFR_CTRL, swap_buffers_between_panels); + bind(arena, mappings, '1', MDFR_CTRL, view_buffer_other_panel); + bind(arena, mappings, '2', MDFR_CTRL, swap_buffers_between_panels); - bind(part, mappings, '\n', MDFR_NONE, newline_or_goto_position_sticky); - bind(part, mappings, '\n', MDFR_SHIFT, newline_or_goto_position_same_panel_sticky); - bind(part, mappings, '>', MDFR_CTRL, view_jump_list_with_lister); - bind(part, mappings, ' ', MDFR_SHIFT, write_character); + bind(arena, mappings, '\n', MDFR_NONE, newline_or_goto_position_sticky); + bind(arena, mappings, '\n', MDFR_SHIFT, newline_or_goto_position_same_panel_sticky); + bind(arena, mappings, '>', MDFR_CTRL, view_jump_list_with_lister); + bind(arena, mappings, ' ', MDFR_SHIFT, write_character); end_map(mappings); // NOTE(allen): CODE - begin_map(part, mappings, default_code_map, "The following commands only apply in files where the lexer (syntax highlighting) is turned on."); + begin_map(arena, mappings, default_code_map, "The following commands only apply in files where the lexer (syntax highlighting) is turned on."); - inherit_map(part, mappings, mapid_file); + inherit_map(arena, mappings, mapid_file); - bind(part, mappings, key_left, MDFR_CTRL, seek_alphanumeric_or_camel_left); - bind(part, mappings, key_right, MDFR_CTRL, seek_alphanumeric_or_camel_right); + bind(arena, mappings, key_left, MDFR_CTRL, seek_alphanumeric_or_camel_left); + bind(arena, mappings, key_right, MDFR_CTRL, seek_alphanumeric_or_camel_right); - bind(part, mappings, '\n', MDFR_NONE, write_and_auto_tab); - bind(part, mappings, '\n', MDFR_SHIFT, write_and_auto_tab); - bind(part, mappings, '}', MDFR_NONE, write_and_auto_tab); - bind(part, mappings, ')', MDFR_NONE, write_and_auto_tab); - bind(part, mappings, ']', MDFR_NONE, write_and_auto_tab); - bind(part, mappings, ';', MDFR_NONE, write_and_auto_tab); - bind(part, mappings, '#', MDFR_NONE, write_and_auto_tab); + bind(arena, mappings, '\n', MDFR_NONE, write_and_auto_tab); + bind(arena, mappings, '\n', MDFR_SHIFT, write_and_auto_tab); + bind(arena, mappings, '}', MDFR_NONE, write_and_auto_tab); + bind(arena, mappings, ')', MDFR_NONE, write_and_auto_tab); + bind(arena, mappings, ']', MDFR_NONE, write_and_auto_tab); + bind(arena, mappings, ';', MDFR_NONE, write_and_auto_tab); + bind(arena, mappings, '#', MDFR_NONE, write_and_auto_tab); - bind(part, mappings, ';', MDFR_CTRL, comment_line_toggle); + bind(arena, mappings, ';', MDFR_CTRL, comment_line_toggle); - bind(part, mappings, '\t', MDFR_NONE, word_complete); - bind(part, mappings, '\t', MDFR_CTRL, auto_tab_range); - bind(part, mappings, '\t', MDFR_SHIFT, auto_tab_line_at_cursor); + bind(arena, mappings, '\t', MDFR_NONE, word_complete); + bind(arena, mappings, '\t', MDFR_CTRL, auto_tab_range); + bind(arena, mappings, '\t', MDFR_SHIFT, auto_tab_line_at_cursor); - bind(part, mappings, 'r', MDFR_ALT, write_block); - bind(part, mappings, 't', MDFR_ALT, write_todo); - bind(part, mappings, 'y', MDFR_ALT, write_note); + bind(arena, mappings, 'r', MDFR_ALT, write_block); + bind(arena, mappings, 't', MDFR_ALT, write_todo); + bind(arena, mappings, 'y', MDFR_ALT, write_note); - bind(part, mappings, 'D', MDFR_ALT, list_all_locations_of_type_definition); - bind(part, mappings, 'T', MDFR_ALT, list_all_locations_of_type_definition_of_identifier); + bind(arena, mappings, 'D', MDFR_ALT, list_all_locations_of_type_definition); + bind(arena, mappings, 'T', MDFR_ALT, list_all_locations_of_type_definition_of_identifier); - bind(part, mappings, '[', MDFR_CTRL, open_long_braces); - bind(part, mappings, '{', MDFR_CTRL, open_long_braces_semicolon); - bind(part, mappings, '}', MDFR_CTRL, open_long_braces_break); + bind(arena, mappings, '[', MDFR_CTRL, open_long_braces); + bind(arena, mappings, '{', MDFR_CTRL, open_long_braces_semicolon); + bind(arena, mappings, '}', MDFR_CTRL, open_long_braces_break); - bind(part, mappings, '[', MDFR_ALT, select_surrounding_scope); - bind(part, mappings, ']', MDFR_ALT, select_prev_scope_absolute); - bind(part, mappings, '\'', MDFR_ALT, select_next_scope_absolute); - bind(part, mappings, '/', MDFR_ALT, place_in_scope); - bind(part, mappings, '-', MDFR_ALT, delete_current_scope); - bind(part, mappings, 'j', MDFR_ALT, scope_absorb_down); + bind(arena, mappings, '[', MDFR_ALT, select_surrounding_scope); + bind(arena, mappings, ']', MDFR_ALT, select_prev_scope_absolute); + bind(arena, mappings, '\'', MDFR_ALT, select_next_scope_absolute); + bind(arena, mappings, '/', MDFR_ALT, place_in_scope); + bind(arena, mappings, '-', MDFR_ALT, delete_current_scope); + bind(arena, mappings, 'j', MDFR_ALT, scope_absorb_down); - bind(part, mappings, 'i', MDFR_ALT, if0_off); + bind(arena, mappings, 'i', MDFR_ALT, if0_off); - bind(part, mappings, '1', MDFR_ALT, open_file_in_quotes); - bind(part, mappings, '2', MDFR_ALT, open_matching_file_cpp); - bind(part, mappings, '0', MDFR_CTRL, write_zero_struct); + bind(arena, mappings, '1', MDFR_ALT, open_file_in_quotes); + bind(arena, mappings, '2', MDFR_ALT, open_matching_file_cpp); + bind(arena, mappings, '0', MDFR_CTRL, write_zero_struct); end_map(mappings); // NOTE(allen): LISTER - begin_map(part, mappings, default_lister_ui_map, + begin_map(arena, mappings, default_lister_ui_map, "These commands apply in 'lister mode' such as when you open a file."); - bind_vanilla_keys(part, mappings, MDFR_NONE, lister__write_character); - bind(part, mappings, key_esc, MDFR_NONE, lister__quit); - bind(part, mappings, '\n', MDFR_NONE, lister__activate); - bind(part, mappings, '\t', MDFR_NONE, lister__activate); - bind_all_modifiers(part, mappings, key_back, lister__backspace_text_field); - bind(part, mappings, key_up , MDFR_NONE, lister__move_up); - bind(part, mappings, 'k' , MDFR_ALT , lister__move_up); - bind(part, mappings, key_page_up , MDFR_NONE, lister__move_up); - bind(part, mappings, key_down , MDFR_NONE, lister__move_down); - bind(part, mappings, 'j' , MDFR_ALT , lister__move_down); - bind(part, mappings, key_page_down, MDFR_NONE, lister__move_down); - bind(part, mappings, key_mouse_wheel , MDFR_NONE, lister__wheel_scroll); - bind(part, mappings, key_mouse_left , MDFR_NONE, lister__mouse_press); - bind(part, mappings, key_mouse_left_release, MDFR_NONE, lister__mouse_release); - bind(part, mappings, key_mouse_move, MDFR_NONE, lister__repaint); - bind(part, mappings, key_animate , MDFR_NONE, lister__repaint); + bind_vanilla_keys(arena, mappings, MDFR_NONE, lister__write_character); + bind(arena, mappings, key_esc, MDFR_NONE, lister__quit); + bind(arena, mappings, '\n', MDFR_NONE, lister__activate); + bind(arena, mappings, '\t', MDFR_NONE, lister__activate); + bind_all_modifiers(arena, mappings, key_back, lister__backspace_text_field); + bind(arena, mappings, key_up , MDFR_NONE, lister__move_up); + bind(arena, mappings, 'k' , MDFR_ALT , lister__move_up); + bind(arena, mappings, key_page_up , MDFR_NONE, lister__move_up); + bind(arena, mappings, key_down , MDFR_NONE, lister__move_down); + bind(arena, mappings, 'j' , MDFR_ALT , lister__move_down); + bind(arena, mappings, key_page_down, MDFR_NONE, lister__move_down); + bind(arena, mappings, key_mouse_wheel , MDFR_NONE, lister__wheel_scroll); + bind(arena, mappings, key_mouse_left , MDFR_NONE, lister__mouse_press); + bind(arena, mappings, key_mouse_left_release, MDFR_NONE, lister__mouse_release); + bind(arena, mappings, key_mouse_move, MDFR_NONE, lister__repaint); + bind(arena, mappings, key_animate , MDFR_NONE, lister__repaint); end_map(mappings); } end_mapping(mappings); - begin_mapping(part, mappings, mac_default, "Default 4coder bindings on a Mac keyboard"); + begin_mapping(arena, mappings, mac_default, "Default 4coder bindings on a Mac keyboard"); { // NOTE(allen): GLOBAL - begin_map(part, mappings, mapid_global, "The following bindings apply in all situations."); + begin_map(arena, mappings, mapid_global, "The following bindings apply in all situations."); - bind(part, mappings, ',', MDFR_CMND, change_active_panel); - bind(part, mappings, '<', MDFR_CMND, change_active_panel_backwards); + bind(arena, mappings, ',', MDFR_CMND, change_active_panel); + bind(arena, mappings, '<', MDFR_CMND, change_active_panel_backwards); - bind(part, mappings, 'n', MDFR_CMND, interactive_new); - bind(part, mappings, 'o', MDFR_CMND, interactive_open_or_new); - bind(part, mappings, 'o', MDFR_CTRL, open_in_other); - bind(part, mappings, 'k', MDFR_CMND, interactive_kill_buffer); - bind(part, mappings, 'i', MDFR_CMND, interactive_switch_buffer); - bind(part, mappings, 'h', MDFR_CMND, project_go_to_root_directory); - bind(part, mappings, 'S', MDFR_CMND, save_all_dirty_buffers); + bind(arena, mappings, 'n', MDFR_CMND, interactive_new); + bind(arena, mappings, 'o', MDFR_CMND, interactive_open_or_new); + bind(arena, mappings, 'o', MDFR_CTRL, open_in_other); + bind(arena, mappings, 'k', MDFR_CMND, interactive_kill_buffer); + bind(arena, mappings, 'i', MDFR_CMND, interactive_switch_buffer); + bind(arena, mappings, 'h', MDFR_CMND, project_go_to_root_directory); + bind(arena, mappings, 'S', MDFR_CMND, save_all_dirty_buffers); - bind(part, mappings, '.', MDFR_CTRL, change_to_build_panel); - bind(part, mappings, ',', MDFR_CTRL, close_build_panel); - bind(part, mappings, 'n', MDFR_CTRL, goto_next_jump_sticky); - bind(part, mappings, 'N', MDFR_CTRL, goto_prev_jump_sticky); - bind(part, mappings, 'M', MDFR_CTRL, goto_first_jump_sticky); - bind(part, mappings, 'm', MDFR_CTRL, build_in_build_panel); - bind(part, mappings, 'b', MDFR_CTRL, toggle_filebar); + bind(arena, mappings, '.', MDFR_CTRL, change_to_build_panel); + bind(arena, mappings, ',', MDFR_CTRL, close_build_panel); + bind(arena, mappings, 'n', MDFR_CTRL, goto_next_jump_sticky); + bind(arena, mappings, 'N', MDFR_CTRL, goto_prev_jump_sticky); + bind(arena, mappings, 'M', MDFR_CTRL, goto_first_jump_sticky); + bind(arena, mappings, 'm', MDFR_CTRL, build_in_build_panel); + bind(arena, mappings, 'b', MDFR_CTRL, toggle_filebar); - bind(part, mappings, 'z', MDFR_CTRL, execute_any_cli); - bind(part, mappings, 'Z', MDFR_CTRL, execute_previous_cli); + bind(arena, mappings, 'z', MDFR_CTRL, execute_any_cli); + bind(arena, mappings, 'Z', MDFR_CTRL, execute_previous_cli); - bind(part, mappings, 'x', MDFR_CTRL, command_lister); - bind(part, mappings, 'X', MDFR_CTRL, project_command_lister); + bind(arena, mappings, 'x', MDFR_CTRL, command_lister); + bind(arena, mappings, 'X', MDFR_CTRL, project_command_lister); - bind(part, mappings, 'I', MDFR_CMND, list_all_functions_all_buffers_lister); - bind(part, mappings, 'E', MDFR_CTRL, exit_4coder); + bind(arena, mappings, 'I', MDFR_CMND, list_all_functions_all_buffers_lister); + bind(arena, mappings, 'E', MDFR_CTRL, exit_4coder); - bind(part, mappings, key_f1, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f2, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f3, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f4, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f1, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f2, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f3, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f4, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f5, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f6, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f7, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f8, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f5, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f6, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f7, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f8, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f9, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f10, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f11, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f12, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f9, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f10, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f11, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f12, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f13, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f14, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f15, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_f16, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f13, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f14, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f15, MDFR_NONE, project_fkey_command); + bind(arena, mappings, key_f16, MDFR_NONE, project_fkey_command); - bind(part, mappings, key_mouse_wheel, MDFR_NONE, mouse_wheel_scroll); - bind(part, mappings, key_mouse_wheel, MDFR_CMND, mouse_wheel_change_face_size); + bind(arena, mappings, key_mouse_wheel, MDFR_NONE, mouse_wheel_scroll); + bind(arena, mappings, key_mouse_wheel, MDFR_CMND, mouse_wheel_change_face_size); end_map(mappings); // NOTE(allen): FILE - begin_map(part, mappings, mapid_file, "The following bindings apply in general text files and most apply in code files, but some are overriden by other commands specific to code files."); + begin_map(arena, mappings, mapid_file, "The following bindings apply in general text files and most apply in code files, but some are overriden by other commands specific to code files."); - bind_vanilla_keys(part, mappings, MDFR_NONE, write_character); - bind_vanilla_keys(part, mappings, MDFR_ALT, write_character); + bind_vanilla_keys(arena, mappings, MDFR_NONE, write_character); + bind_vanilla_keys(arena, mappings, MDFR_ALT, write_character); - bind(part, mappings, key_mouse_left, MDFR_NONE, click_set_cursor_and_mark); - bind(part, mappings, key_click_activate_view, MDFR_NONE, click_set_cursor_and_mark); - bind(part, mappings, key_mouse_left_release, MDFR_NONE, click_set_cursor); - bind(part, mappings, key_mouse_move, MDFR_NONE, click_set_cursor_if_lbutton); + bind(arena, mappings, key_mouse_left, MDFR_NONE, click_set_cursor_and_mark); + bind(arena, mappings, key_click_activate_view, MDFR_NONE, click_set_cursor_and_mark); + bind(arena, mappings, key_mouse_left_release, MDFR_NONE, click_set_cursor); + bind(arena, mappings, key_mouse_move, MDFR_NONE, click_set_cursor_if_lbutton); - bind(part, mappings, key_del, MDFR_NONE, delete_char); - bind(part, mappings, key_del, MDFR_SHIFT, delete_char); - bind(part, mappings, key_back, MDFR_NONE, backspace_char); - bind(part, mappings, key_back, MDFR_SHIFT, backspace_char); + bind(arena, mappings, key_del, MDFR_NONE, delete_char); + bind(arena, mappings, key_del, MDFR_SHIFT, delete_char); + bind(arena, mappings, key_back, MDFR_NONE, backspace_char); + bind(arena, mappings, key_back, MDFR_SHIFT, backspace_char); - bind(part, mappings, key_up, MDFR_NONE, move_up); - bind(part, mappings, key_down, MDFR_NONE, move_down); - bind(part, mappings, key_left, MDFR_NONE, move_left); - bind(part, mappings, key_right, MDFR_NONE, move_right); - bind(part, mappings, key_up, MDFR_SHIFT, move_up); - bind(part, mappings, key_down, MDFR_SHIFT, move_down); - bind(part, mappings, key_left, MDFR_SHIFT, move_left); - bind(part, mappings, key_right, MDFR_SHIFT, move_right); + bind(arena, mappings, key_up, MDFR_NONE, move_up); + bind(arena, mappings, key_down, MDFR_NONE, move_down); + bind(arena, mappings, key_left, MDFR_NONE, move_left); + bind(arena, mappings, key_right, MDFR_NONE, move_right); + bind(arena, mappings, key_up, MDFR_SHIFT, move_up); + bind(arena, mappings, key_down, MDFR_SHIFT, move_down); + bind(arena, mappings, key_left, MDFR_SHIFT, move_left); + bind(arena, mappings, key_right, MDFR_SHIFT, move_right); - bind(part, mappings, key_end, MDFR_NONE, seek_end_of_line); - bind(part, mappings, key_home, MDFR_NONE, seek_beginning_of_line); - bind(part, mappings, key_page_up, MDFR_CTRL, goto_beginning_of_file); - bind(part, mappings, key_page_down, MDFR_CTRL, goto_end_of_file); - bind(part, mappings, key_page_up, MDFR_NONE, page_up); - bind(part, mappings, key_page_down, MDFR_NONE, page_down); - bind(part, mappings, key_end, MDFR_SHIFT, seek_end_of_line); - bind(part, mappings, key_home, MDFR_SHIFT, seek_beginning_of_line); - bind(part, mappings, key_page_up, MDFR_CTRL|MDFR_SHIFT, goto_beginning_of_file); - bind(part, mappings, key_page_down, MDFR_CTRL|MDFR_SHIFT, goto_end_of_file); - bind(part, mappings, key_page_up, MDFR_SHIFT, page_up); - bind(part, mappings, key_page_down, MDFR_SHIFT, page_down); + bind(arena, mappings, key_end, MDFR_NONE, seek_end_of_line); + bind(arena, mappings, key_home, MDFR_NONE, seek_beginning_of_line); + bind(arena, mappings, key_page_up, MDFR_CTRL, goto_beginning_of_file); + bind(arena, mappings, key_page_down, MDFR_CTRL, goto_end_of_file); + bind(arena, mappings, key_page_up, MDFR_NONE, page_up); + bind(arena, mappings, key_page_down, MDFR_NONE, page_down); + bind(arena, mappings, key_end, MDFR_SHIFT, seek_end_of_line); + bind(arena, mappings, key_home, MDFR_SHIFT, seek_beginning_of_line); + bind(arena, mappings, key_page_up, MDFR_CTRL|MDFR_SHIFT, goto_beginning_of_file); + bind(arena, mappings, key_page_down, MDFR_CTRL|MDFR_SHIFT, goto_end_of_file); + bind(arena, mappings, key_page_up, MDFR_SHIFT, page_up); + bind(arena, mappings, key_page_down, MDFR_SHIFT, page_down); - bind(part, mappings, key_up, MDFR_CMND, seek_whitespace_up_end_line); - bind(part, mappings, key_down, MDFR_CMND, seek_whitespace_down_end_line); - bind(part, mappings, key_left, MDFR_CMND, seek_whitespace_left); - bind(part, mappings, key_right, MDFR_CMND, seek_whitespace_right); - bind(part, mappings, key_up, MDFR_CMND|MDFR_SHIFT, seek_whitespace_up_end_line); - bind(part, mappings, key_down, MDFR_CMND|MDFR_SHIFT, seek_whitespace_down_end_line); - bind(part, mappings, key_left, MDFR_CMND|MDFR_SHIFT, seek_whitespace_left); - bind(part, mappings, key_right, MDFR_CMND|MDFR_SHIFT, seek_whitespace_right); + bind(arena, mappings, key_up, MDFR_CMND, seek_whitespace_up_end_line); + bind(arena, mappings, key_down, MDFR_CMND, seek_whitespace_down_end_line); + bind(arena, mappings, key_left, MDFR_CMND, seek_whitespace_left); + bind(arena, mappings, key_right, MDFR_CMND, seek_whitespace_right); + bind(arena, mappings, key_up, MDFR_CMND|MDFR_SHIFT, seek_whitespace_up_end_line); + bind(arena, mappings, key_down, MDFR_CMND|MDFR_SHIFT, seek_whitespace_down_end_line); + bind(arena, mappings, key_left, MDFR_CMND|MDFR_SHIFT, seek_whitespace_left); + bind(arena, mappings, key_right, MDFR_CMND|MDFR_SHIFT, seek_whitespace_right); - bind(part, mappings, key_up, MDFR_ALT, move_line_up); - bind(part, mappings, key_down, MDFR_ALT, move_line_down); + bind(arena, mappings, key_up, MDFR_ALT, move_line_up); + bind(arena, mappings, key_down, MDFR_ALT, move_line_down); - bind(part, mappings, key_back, MDFR_CMND, backspace_word); - bind(part, mappings, key_del, MDFR_CMND, delete_word); - bind(part, mappings, key_back, MDFR_CTRL, snipe_token_or_word); - bind(part, mappings, key_del, MDFR_CTRL, snipe_token_or_word_right); + bind(arena, mappings, key_back, MDFR_CMND, backspace_word); + bind(arena, mappings, key_del, MDFR_CMND, delete_word); + bind(arena, mappings, key_back, MDFR_CTRL, snipe_token_or_word); + bind(arena, mappings, key_del, MDFR_CTRL, snipe_token_or_word_right); - bind(part, mappings, '/', MDFR_CMND, set_mark); - bind(part, mappings, 'a', MDFR_CMND, replace_in_range); - bind(part, mappings, 'c', MDFR_CMND, copy); - bind(part, mappings, 'd', MDFR_CMND, delete_range); - bind(part, mappings, 'D', MDFR_CMND, delete_line); - bind(part, mappings, 'e', MDFR_CMND, center_view); - bind(part, mappings, 'E', MDFR_CMND, left_adjust_view); - bind(part, mappings, 'f', MDFR_CMND, search); - bind(part, mappings, 'F', MDFR_CMND, list_all_locations); - bind(part, mappings, 'F', MDFR_CTRL, list_all_substring_locations_case_insensitive); - bind(part, mappings, 'g', MDFR_CMND, goto_line); - bind(part, mappings, 'G', MDFR_CMND, list_all_locations_of_selection); - bind(part, mappings, 'K', MDFR_CMND, kill_buffer); - bind(part, mappings, 'L', MDFR_CMND, duplicate_line); - bind(part, mappings, 'm', MDFR_CMND, cursor_mark_swap); - bind(part, mappings, 'O', MDFR_CMND, reopen); - bind(part, mappings, 'q', MDFR_CMND, query_replace); - bind(part, mappings, 'Q', MDFR_CMND, query_replace_identifier); - bind(part, mappings, 'r', MDFR_CMND, reverse_search); - bind(part, mappings, 's', MDFR_CMND, save); - bind(part, mappings, 't', MDFR_CMND, search_identifier); - bind(part, mappings, 'T', MDFR_CMND, list_all_locations_of_identifier); - bind(part, mappings, 'v', MDFR_CMND, paste_and_indent); - bind(part, mappings, 'V', MDFR_CMND, paste_next_and_indent); - bind(part, mappings, 'x', MDFR_CMND, cut); - bind(part, mappings, 'y', MDFR_CMND, redo); - bind(part, mappings, 'z', MDFR_CMND, undo); + bind(arena, mappings, '/', MDFR_CMND, set_mark); + bind(arena, mappings, 'a', MDFR_CMND, replace_in_range); + bind(arena, mappings, 'c', MDFR_CMND, copy); + bind(arena, mappings, 'd', MDFR_CMND, delete_range); + bind(arena, mappings, 'D', MDFR_CMND, delete_line); + bind(arena, mappings, 'e', MDFR_CMND, center_view); + bind(arena, mappings, 'E', MDFR_CMND, left_adjust_view); + bind(arena, mappings, 'f', MDFR_CMND, search); + bind(arena, mappings, 'F', MDFR_CMND, list_all_locations); + bind(arena, mappings, 'F', MDFR_CTRL, list_all_substring_locations_case_insensitive); + bind(arena, mappings, 'g', MDFR_CMND, goto_line); + bind(arena, mappings, 'G', MDFR_CMND, list_all_locations_of_selection); + bind(arena, mappings, 'K', MDFR_CMND, kill_buffer); + bind(arena, mappings, 'L', MDFR_CMND, duplicate_line); + bind(arena, mappings, 'm', MDFR_CMND, cursor_mark_swap); + bind(arena, mappings, 'O', MDFR_CMND, reopen); + bind(arena, mappings, 'q', MDFR_CMND, query_replace); + bind(arena, mappings, 'Q', MDFR_CMND, query_replace_identifier); + bind(arena, mappings, 'r', MDFR_CMND, reverse_search); + bind(arena, mappings, 's', MDFR_CMND, save); + bind(arena, mappings, 't', MDFR_CMND, search_identifier); + bind(arena, mappings, 'T', MDFR_CMND, list_all_locations_of_identifier); + bind(arena, mappings, 'v', MDFR_CMND, paste_and_indent); + bind(arena, mappings, 'V', MDFR_CMND, paste_next_and_indent); + bind(arena, mappings, 'x', MDFR_CMND, cut); + bind(arena, mappings, 'y', MDFR_CMND, redo); + bind(arena, mappings, 'z', MDFR_CMND, undo); - bind(part, mappings, '1', MDFR_CMND, view_buffer_other_panel); - bind(part, mappings, '2', MDFR_CMND, swap_buffers_between_panels); + bind(arena, mappings, '1', MDFR_CMND, view_buffer_other_panel); + bind(arena, mappings, '2', MDFR_CMND, swap_buffers_between_panels); - bind(part, mappings, '\n', MDFR_NONE, newline_or_goto_position_sticky); - bind(part, mappings, '\n', MDFR_SHIFT, newline_or_goto_position_same_panel_sticky); - bind(part, mappings, '>', MDFR_CMND, view_jump_list_with_lister); - bind(part, mappings, ' ', MDFR_SHIFT, write_character); + bind(arena, mappings, '\n', MDFR_NONE, newline_or_goto_position_sticky); + bind(arena, mappings, '\n', MDFR_SHIFT, newline_or_goto_position_same_panel_sticky); + bind(arena, mappings, '>', MDFR_CMND, view_jump_list_with_lister); + bind(arena, mappings, ' ', MDFR_SHIFT, write_character); end_map(mappings); // NOTE(allen): CODE - begin_map(part, mappings, default_code_map, "The following commands only apply in files where the lexer (syntax highlighting) is turned on."); + begin_map(arena, mappings, default_code_map, "The following commands only apply in files where the lexer (syntax highlighting) is turned on."); - inherit_map(part, mappings, mapid_file); + inherit_map(arena, mappings, mapid_file); - bind(part, mappings, key_left, MDFR_CMND, seek_alphanumeric_or_camel_left); - bind(part, mappings, key_right, MDFR_CMND, seek_alphanumeric_or_camel_right); + bind(arena, mappings, key_left, MDFR_CMND, seek_alphanumeric_or_camel_left); + bind(arena, mappings, key_right, MDFR_CMND, seek_alphanumeric_or_camel_right); - bind(part, mappings, '\n', MDFR_NONE, write_and_auto_tab); - bind(part, mappings, '\n', MDFR_SHIFT, write_and_auto_tab); - bind(part, mappings, '}', MDFR_NONE, write_and_auto_tab); - bind(part, mappings, ')', MDFR_NONE, write_and_auto_tab); - bind(part, mappings, ']', MDFR_NONE, write_and_auto_tab); - bind(part, mappings, ';', MDFR_NONE, write_and_auto_tab); - bind(part, mappings, '#', MDFR_NONE, write_and_auto_tab); + bind(arena, mappings, '\n', MDFR_NONE, write_and_auto_tab); + bind(arena, mappings, '\n', MDFR_SHIFT, write_and_auto_tab); + bind(arena, mappings, '}', MDFR_NONE, write_and_auto_tab); + bind(arena, mappings, ')', MDFR_NONE, write_and_auto_tab); + bind(arena, mappings, ']', MDFR_NONE, write_and_auto_tab); + bind(arena, mappings, ';', MDFR_NONE, write_and_auto_tab); + bind(arena, mappings, '#', MDFR_NONE, write_and_auto_tab); - bind(part, mappings, ';', MDFR_CTRL, comment_line_toggle); + bind(arena, mappings, ';', MDFR_CTRL, comment_line_toggle); - bind(part, mappings, '\t', MDFR_NONE, word_complete); - bind(part, mappings, '\t', MDFR_CMND, auto_tab_range); - bind(part, mappings, '\t', MDFR_SHIFT, auto_tab_line_at_cursor); + bind(arena, mappings, '\t', MDFR_NONE, word_complete); + bind(arena, mappings, '\t', MDFR_CMND, auto_tab_range); + bind(arena, mappings, '\t', MDFR_SHIFT, auto_tab_line_at_cursor); - bind(part, mappings, 'r', MDFR_CTRL, write_block); - bind(part, mappings, 't', MDFR_CTRL, write_todo); - bind(part, mappings, 'y', MDFR_CTRL, write_note); + bind(arena, mappings, 'r', MDFR_CTRL, write_block); + bind(arena, mappings, 't', MDFR_CTRL, write_todo); + bind(arena, mappings, 'y', MDFR_CTRL, write_note); - bind(part, mappings, 'D', MDFR_CTRL, list_all_locations_of_type_definition); - bind(part, mappings, 'T', MDFR_CTRL, list_all_locations_of_type_definition_of_identifier); + bind(arena, mappings, 'D', MDFR_CTRL, list_all_locations_of_type_definition); + bind(arena, mappings, 'T', MDFR_CTRL, list_all_locations_of_type_definition_of_identifier); - bind(part, mappings, '[', MDFR_CMND, open_long_braces); - bind(part, mappings, '{', MDFR_CMND, open_long_braces_semicolon); - bind(part, mappings, '}', MDFR_CMND, open_long_braces_break); + bind(arena, mappings, '[', MDFR_CMND, open_long_braces); + bind(arena, mappings, '{', MDFR_CMND, open_long_braces_semicolon); + bind(arena, mappings, '}', MDFR_CMND, open_long_braces_break); - bind(part, mappings, '[', MDFR_CTRL, select_surrounding_scope); - bind(part, mappings, ']', MDFR_CTRL, select_prev_scope_absolute); - bind(part, mappings, '\'', MDFR_CTRL, select_next_scope_absolute); - bind(part, mappings, '/', MDFR_CTRL, place_in_scope); - bind(part, mappings, '-', MDFR_CTRL, delete_current_scope); - bind(part, mappings, 'j', MDFR_CTRL, scope_absorb_down); + bind(arena, mappings, '[', MDFR_CTRL, select_surrounding_scope); + bind(arena, mappings, ']', MDFR_CTRL, select_prev_scope_absolute); + bind(arena, mappings, '\'', MDFR_CTRL, select_next_scope_absolute); + bind(arena, mappings, '/', MDFR_CTRL, place_in_scope); + bind(arena, mappings, '-', MDFR_CTRL, delete_current_scope); + bind(arena, mappings, 'j', MDFR_CTRL, scope_absorb_down); - bind(part, mappings, 'i', MDFR_CTRL, if0_off); + bind(arena, mappings, 'i', MDFR_CTRL, if0_off); - bind(part, mappings, '1', MDFR_CTRL, open_file_in_quotes); - bind(part, mappings, '2', MDFR_CTRL, open_matching_file_cpp); - bind(part, mappings, '0', MDFR_CMND, write_zero_struct); + bind(arena, mappings, '1', MDFR_CTRL, open_file_in_quotes); + bind(arena, mappings, '2', MDFR_CTRL, open_matching_file_cpp); + bind(arena, mappings, '0', MDFR_CMND, write_zero_struct); end_map(mappings); // NOTE(allen): LISTER - begin_map(part, mappings, default_lister_ui_map, + begin_map(arena, mappings, default_lister_ui_map, "These commands apply in 'lister mode' such as when you open a file."); - bind_vanilla_keys(part, mappings, MDFR_NONE, lister__write_character); - bind(part, mappings, key_esc, MDFR_NONE, lister__quit); - bind(part, mappings, '\n', MDFR_NONE, lister__activate); - bind(part, mappings, '\t', MDFR_NONE, lister__activate); - bind_all_modifiers(part, mappings, key_back, lister__backspace_text_field); - bind(part, mappings, key_up , MDFR_NONE, lister__move_up); - bind(part, mappings, key_page_up , MDFR_NONE, lister__move_up); - bind(part, mappings, key_down , MDFR_NONE, lister__move_down); - bind(part, mappings, key_page_down, MDFR_NONE, lister__move_down); - bind(part, mappings, key_mouse_wheel , MDFR_NONE, lister__wheel_scroll); - bind(part, mappings, key_mouse_left , MDFR_NONE, lister__mouse_press); - bind(part, mappings, key_mouse_left_release, MDFR_NONE, lister__mouse_release); - bind(part, mappings, key_mouse_move, MDFR_NONE, lister__repaint); - bind(part, mappings, key_animate , MDFR_NONE, lister__repaint); + bind_vanilla_keys(arena, mappings, MDFR_NONE, lister__write_character); + bind(arena, mappings, key_esc, MDFR_NONE, lister__quit); + bind(arena, mappings, '\n', MDFR_NONE, lister__activate); + bind(arena, mappings, '\t', MDFR_NONE, lister__activate); + bind_all_modifiers(arena, mappings, key_back, lister__backspace_text_field); + bind(arena, mappings, key_up , MDFR_NONE, lister__move_up); + bind(arena, mappings, key_page_up , MDFR_NONE, lister__move_up); + bind(arena, mappings, key_down , MDFR_NONE, lister__move_down); + bind(arena, mappings, key_page_down, MDFR_NONE, lister__move_down); + bind(arena, mappings, key_mouse_wheel , MDFR_NONE, lister__wheel_scroll); + bind(arena, mappings, key_mouse_left , MDFR_NONE, lister__mouse_press); + bind(arena, mappings, key_mouse_left_release, MDFR_NONE, lister__mouse_release); + bind(arena, mappings, key_mouse_move, MDFR_NONE, lister__repaint); + bind(arena, mappings, key_animate , MDFR_NONE, lister__repaint); end_map(mappings); } @@ -888,50 +905,51 @@ generate_remapping_code_and_data(Partition *part){ for (Key_Bind *bind = sub_map->first_key_bind; bind != 0; bind = bind->next){ - char mdfr_str[256]; - String m = make_fixed_width_string(mdfr_str); + Temp_Memory bind_temp = begin_temp(arena); + + List_String_Const_char mdfr_list = {}; b32 has_base = false; if (bind->modifiers & MDFR_CTRL){ if (has_base){ - append(&m, "|"); + string_list_push_lit(arena, &mdfr_list, "|"); } - append(&m, "MDFR_CTRL"); + string_list_push_lit(arena, &mdfr_list, "MDFR_CTRL"); has_base = true; } if (bind->modifiers & MDFR_ALT){ if (has_base){ - append(&m, "|"); + string_list_push_lit(arena, &mdfr_list, "|"); } - append(&m, "MDFR_ALT"); + string_list_push_lit(arena, &mdfr_list, "MDFR_ALT"); has_base = true; } if (bind->modifiers & MDFR_CMND){ if (has_base){ - append(&m, "|"); + string_list_push_lit(arena, &mdfr_list, "|"); } - append(&m, "MDFR_CMND"); + string_list_push_lit(arena, &mdfr_list, "MDFR_CMND"); has_base = true; } if (bind->modifiers & MDFR_SHIFT){ if (has_base){ - append(&m, "|"); + string_list_push_lit(arena, &mdfr_list, "|"); } - append(&m, "MDFR_SHIFT"); + string_list_push_lit(arena, &mdfr_list, "MDFR_SHIFT"); has_base = true; } if (bind->modifiers == 0){ - append(&m, "MDFR_NONE"); + string_list_push_lit(arena, &mdfr_list, "MDFR_NONE"); has_base = true; } - terminate_with_null(&m); + String_Const_char mdfr = string_list_flatten(arena, mdfr_list, StringFill_NullTerminate); if (bind->vanilla){ if (bind->modifiers == 0){ fprintf(out, "bind_vanilla_keys(context, %s);\n", bind->command); } else{ - fprintf(out, "bind_vanilla_keys(context, %s, %s);\n", mdfr_str, bind->command); + fprintf(out, "bind_vanilla_keys(context, %s, %s);\n", mdfr.str, bind->command); } } else{ @@ -961,8 +979,10 @@ generate_remapping_code_and_data(Partition *part){ } } - fprintf(out, "bind(context, %s, %s, %s);\n", key_str, mdfr_str, bind->command); + fprintf(out, "bind(context, %s, %s, %s);\n", key_str, mdfr.str, bind->command); } + + end_temp(bind_temp); } fprintf(out, "end_map(context);\n"); @@ -1071,16 +1091,16 @@ generate_remapping_code_and_data(Partition *part){ fclose(out); } - end_temp_memory(temp); + end_temp(temp); } ////////////////////////////////////////////////////////////////////////////////////////////////// int main(int argc, char **argv){ META_BEGIN(); - Partition part = fm_init_system(); - generate_custom_headers(&part); - generate_remapping_code_and_data(&part); + Arena arena = fm_init_system(); + generate_custom_headers(&arena); + generate_remapping_code_and_data(&arena); META_FINISH(); } diff --git a/old_string_api.h b/old_string_api.h new file mode 100644 index 00000000..009f923f --- /dev/null +++ b/old_string_api.h @@ -0,0 +1,245 @@ +// old string api + +// TOP + +#if !defined(OLD_STRING_API_H) +#define OLD_STRING_API_H + +struct String_OLD{ + char *str; + i32 size; + i32 memory_size; +}; + +static String null_string = {}; + +FSTRING_INLINE b32_4tech char_is_slash(char c); +FSTRING_INLINE b32_4tech char_is_upper(char c); +FSTRING_INLINE b32_4tech char_is_upper_utf8(char c); +FSTRING_INLINE b32_4tech char_is_lower(char c); +FSTRING_INLINE b32_4tech char_is_lower_utf8(u8_4tech c); +FSTRING_INLINE char char_to_upper(char c); +FSTRING_INLINE char char_to_lower(char c); +FSTRING_INLINE b32_4tech char_is_whitespace(char c); +FSTRING_INLINE b32_4tech char_is_alpha_numeric(char c); +FSTRING_INLINE b32_4tech char_is_alpha_numeric_utf8(u8_4tech c); +FSTRING_INLINE b32_4tech char_is_alpha_numeric_true(char c); +FSTRING_INLINE b32_4tech char_is_alpha_numeric_true_utf8(u8_4tech c); +FSTRING_INLINE b32_4tech char_is_alpha(char c); +FSTRING_INLINE b32_4tech char_is_alpha_utf8(u8_4tech c); +FSTRING_INLINE b32_4tech char_is_alpha_true(char c); +FSTRING_INLINE b32_4tech char_is_alpha_true_utf8(u8_4tech c); +FSTRING_INLINE b32_4tech char_is_hex(char c); +FSTRING_INLINE b32_4tech char_is_hex_utf8(u8_4tech c); +FSTRING_INLINE b32_4tech char_is_numeric(char c); +FSTRING_INLINE b32_4tech char_is_numeric_utf8(u8_4tech c); +FSTRING_INLINE String make_string_cap(void *str, i32_4tech size, i32_4tech mem_size); +FSTRING_INLINE String make_string(void *str, i32_4tech size); +#ifndef make_lit_string +# define make_lit_string(s) (make_string_cap((char*)(s), sizeof(s)-1, sizeof(s))) +#endif +#ifndef lit +# define lit(s) make_lit_string(s) +#endif +#ifndef make_fixed_width_string +# define make_fixed_width_string(s) (make_string_cap((char*)(s), 0, sizeof(s))) +#endif +#ifndef expand_str +# define expand_str(s) ((s).str), ((s).size) +#endif +FSTRING_LINK i32_4tech str_size(char *str); +FSTRING_INLINE String make_string_slowly(void *str); +FSTRING_INLINE String substr_tail(String str, i32_4tech start); +FSTRING_INLINE String substr(String str, i32_4tech start, i32_4tech size); +FSTRING_LINK String skip_whitespace(String str); +FSTRING_LINK String skip_whitespace_measure(String str, i32_4tech *skip_length); +FSTRING_LINK String chop_whitespace(String str); +FSTRING_LINK String skip_chop_whitespace(String str); +FSTRING_LINK String skip_chop_whitespace_measure(String str, i32_4tech *skip_length); +FSTRING_INLINE String tailstr(String str); +FSTRING_LINK b32_4tech match_cc(char *a, char *b); +FSTRING_LINK b32_4tech match_sc(String a, char *b); +FSTRING_INLINE b32_4tech match_cs(char *a, String b); +FSTRING_LINK b32_4tech match_ss(String a, String b); +FSTRING_LINK b32_4tech match_part_ccl(char *a, char *b, i32_4tech *len); +FSTRING_LINK b32_4tech match_part_scl(String a, char *b, i32_4tech *len); +FSTRING_INLINE b32_4tech match_part_cc(char *a, char *b); +FSTRING_INLINE b32_4tech match_part_sc(String a, char *b); +FSTRING_LINK b32_4tech match_part_cs(char *a, String b); +FSTRING_LINK b32_4tech match_part_ss(String a, String b); +FSTRING_LINK b32_4tech match_insensitive_cc(char *a, char *b); +FSTRING_LINK b32_4tech match_insensitive_sc(String a, char *b); +FSTRING_INLINE b32_4tech match_insensitive_cs(char *a, String b); +FSTRING_LINK b32_4tech match_insensitive_ss(String a, String b); +FSTRING_LINK b32_4tech match_part_insensitive_ccl(char *a, char *b, i32_4tech *len); +FSTRING_LINK b32_4tech match_part_insensitive_scl(String a, char *b, i32_4tech *len); +FSTRING_INLINE b32_4tech match_part_insensitive_cc(char *a, char *b); +FSTRING_INLINE b32_4tech match_part_insensitive_sc(String a, char *b); +FSTRING_LINK b32_4tech match_part_insensitive_cs(char *a, String b); +FSTRING_LINK b32_4tech match_part_insensitive_ss(String a, String b); +FSTRING_LINK i32_4tech compare_cc(char *a, char *b); +FSTRING_LINK i32_4tech compare_sc(String a, char *b); +FSTRING_INLINE i32_4tech compare_cs(char *a, String b); +FSTRING_LINK i32_4tech compare_ss(String a, String b); +FSTRING_LINK i32_4tech find_c_char(char *str, i32_4tech start, char character); +FSTRING_LINK i32_4tech find_s_char(String str, i32_4tech start, char character); +FSTRING_LINK i32_4tech rfind_s_char(String str, i32_4tech start, char character); +FSTRING_LINK i32_4tech find_c_chars(char *str, i32_4tech start, char *characters); +FSTRING_LINK i32_4tech find_s_chars(String str, i32_4tech start, char *characters); +FSTRING_LINK i32_4tech find_substr_c(char *str, i32_4tech start, String seek); +FSTRING_LINK i32_4tech find_substr_s(String str, i32_4tech start, String seek); +FSTRING_LINK i32_4tech rfind_substr_s(String str, i32_4tech start, String seek); +FSTRING_LINK i32_4tech find_substr_insensitive_c(char *str, i32_4tech start, String seek); +FSTRING_LINK i32_4tech find_substr_insensitive_s(String str, i32_4tech start, String seek); +FSTRING_INLINE b32_4tech has_substr_c(char *s, String seek); +FSTRING_INLINE b32_4tech has_substr_s(String s, String seek); +FSTRING_INLINE b32_4tech has_substr_insensitive_c(char *s, String seek); +FSTRING_INLINE b32_4tech has_substr_insensitive_s(String s, String seek); +FSTRING_LINK i32_4tech copy_fast_unsafe_cc(char *dest, char *src); +FSTRING_LINK i32_4tech copy_fast_unsafe_cs(char *dest, String src); +FSTRING_LINK b32_4tech copy_checked_ss(String *dest, String src); +FSTRING_LINK b32_4tech copy_checked_cs(char *dest, i32_4tech dest_cap, String src); +FSTRING_LINK b32_4tech copy_partial_sc(String *dest, char *src); +FSTRING_LINK b32_4tech copy_partial_ss(String *dest, String src); +FSTRING_LINK b32_4tech copy_partial_cs(char *dest, i32_4tech dest_cap, String src); +FSTRING_INLINE i32_4tech copy_cc(char *dest, char *src); +FSTRING_INLINE void copy_ss(String *dest, String src); +FSTRING_INLINE void copy_sc(String *dest, char *src); +FSTRING_LINK b32_4tech append_checked_ss(String *dest, String src); +FSTRING_LINK b32_4tech append_partial_sc(String *dest, char *src); +FSTRING_LINK b32_4tech append_partial_ss(String *dest, String src); +FSTRING_LINK b32_4tech append_s_char(String *dest, char c); +FSTRING_INLINE b32_4tech append_ss(String *dest, String src); +FSTRING_INLINE b32_4tech append_sc(String *dest, char *src); +FSTRING_LINK b32_4tech terminate_with_null(String *str); +FSTRING_LINK b32_4tech append_padding(String *dest, char c, i32_4tech target_size); +FSTRING_LINK void string_interpret_escapes(String src, char *dst); +FSTRING_LINK void replace_char(String *str, char replace, char with); +FSTRING_LINK void replace_str_ss(String *str, String replace, String with); +FSTRING_LINK void replace_str_sc(String *str, String replace, char *with); +FSTRING_LINK void replace_str_cs(String *str, char *replace, String with); +FSTRING_LINK void replace_str_cc(String *str, char *replace, char *with); +FSTRING_LINK void to_lower_cc(char *src, char *dst); +FSTRING_LINK void to_lower_ss(String *dst, String src); +FSTRING_LINK void to_lower_s(String *str); +FSTRING_LINK void to_upper_cc(char *src, char *dst); +FSTRING_LINK void to_upper_ss(String *dst, String src); +FSTRING_LINK void to_upper_s(String *str); +FSTRING_LINK void to_camel_cc(char *src, char *dst); +FSTRING_LINK i32_4tech int_to_str_size(i32_4tech x); +FSTRING_LINK b32_4tech int_to_str(String *dest, i32_4tech x); +FSTRING_LINK b32_4tech append_int_to_str(String *dest, i32_4tech x); +FSTRING_LINK i32_4tech u64_to_str_size(uint64_t x); +FSTRING_LINK b32_4tech u64_to_str(String *dest, uint64_t x); +FSTRING_LINK b32_4tech append_u64_to_str(String *dest, uint64_t x); +FSTRING_LINK i32_4tech float_to_str_size(float x); +FSTRING_LINK b32_4tech append_float_to_str(String *dest, float x); +FSTRING_LINK b32_4tech float_to_str(String *dest, float x); +FSTRING_LINK i32_4tech str_is_int_c(char *str); +FSTRING_LINK b32_4tech str_is_int_s(String str); +FSTRING_LINK i32_4tech str_to_int_c(char *str); +FSTRING_LINK i32_4tech str_to_int_s(String str); +FSTRING_LINK i32_4tech hexchar_to_int(char c); +FSTRING_LINK char int_to_hexchar(i32_4tech x); +FSTRING_LINK u32_4tech hexstr_to_int(String str); +FSTRING_LINK b32_4tech color_to_hexstr(String *s, u32_4tech color); +FSTRING_LINK b32_4tech hexstr_to_color(String s, u32_4tech *out); +FSTRING_LINK i32_4tech reverse_seek_slash_pos(String str, i32_4tech pos); +FSTRING_INLINE i32_4tech reverse_seek_slash(String str); +FSTRING_INLINE String front_of_directory(String dir); +FSTRING_INLINE String path_of_directory(String dir); +FSTRING_LINK b32_4tech set_last_folder_sc(String *dir, char *folder_name, char slash); +FSTRING_LINK b32_4tech set_last_folder_ss(String *dir, String folder_name, char slash); +FSTRING_LINK String file_extension(String str); +FSTRING_LINK b32_4tech remove_extension(String *str); +FSTRING_LINK b32_4tech remove_last_folder(String *str); +FSTRING_LINK b32_4tech string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index); +FSTRING_LINK b32_4tech string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_index); +FSTRING_LINK String get_first_double_line(String source); +FSTRING_LINK String get_next_double_line(String source, String line); +FSTRING_LINK String get_next_word(String source, String prev_word); +FSTRING_LINK String get_first_word(String source); +FSTRING_LINK String string_push(Partition *part, i32_4tech size); +FSTRING_LINK String string_push_copy(Partition *part, String str); + +FSTRING_INLINE String make_string(void *str, i32_4tech size, i32_4tech mem_size){return(make_string_cap(str,size,mem_size));} +FSTRING_INLINE String substr(String str, i32_4tech start){return(substr_tail(str,start));} +FSTRING_LINK String skip_whitespace(String str, i32_4tech *skip_length){return(skip_whitespace_measure(str,skip_length));} +FSTRING_LINK String skip_chop_whitespace(String str, i32_4tech *skip_length){return(skip_chop_whitespace_measure(str,skip_length));} +FSTRING_LINK b32_4tech match(char *a, char *b){return(match_cc(a,b));} +FSTRING_LINK b32_4tech match(String a, char *b){return(match_sc(a,b));} +FSTRING_INLINE b32_4tech match(char *a, String b){return(match_cs(a,b));} +FSTRING_LINK b32_4tech match(String a, String b){return(match_ss(a,b));} +FSTRING_LINK b32_4tech match_part(char *a, char *b, i32_4tech *len){return(match_part_ccl(a,b,len));} +FSTRING_LINK b32_4tech match_part(String a, char *b, i32_4tech *len){return(match_part_scl(a,b,len));} +FSTRING_INLINE b32_4tech match_part(char *a, char *b){return(match_part_cc(a,b));} +FSTRING_INLINE b32_4tech match_part(String a, char *b){return(match_part_sc(a,b));} +FSTRING_LINK b32_4tech match_part(char *a, String b){return(match_part_cs(a,b));} +FSTRING_LINK b32_4tech match_part(String a, String b){return(match_part_ss(a,b));} +FSTRING_LINK b32_4tech match_insensitive(char *a, char *b){return(match_insensitive_cc(a,b));} +FSTRING_LINK b32_4tech match_insensitive(String a, char *b){return(match_insensitive_sc(a,b));} +FSTRING_INLINE b32_4tech match_insensitive(char *a, String b){return(match_insensitive_cs(a,b));} +FSTRING_LINK b32_4tech match_insensitive(String a, String b){return(match_insensitive_ss(a,b));} +FSTRING_LINK b32_4tech match_part_insensitive(char *a, char *b, i32_4tech *len){return(match_part_insensitive_ccl(a,b,len));} +FSTRING_LINK b32_4tech match_part_insensitive(String a, char *b, i32_4tech *len){return(match_part_insensitive_scl(a,b,len));} +FSTRING_INLINE b32_4tech match_part_insensitive(char *a, char *b){return(match_part_insensitive_cc(a,b));} +FSTRING_INLINE b32_4tech match_part_insensitive(String a, char *b){return(match_part_insensitive_sc(a,b));} +FSTRING_LINK b32_4tech match_part_insensitive(char *a, String b){return(match_part_insensitive_cs(a,b));} +FSTRING_LINK b32_4tech match_part_insensitive(String a, String b){return(match_part_insensitive_ss(a,b));} +FSTRING_LINK i32_4tech compare(char *a, char *b){return(compare_cc(a,b));} +FSTRING_LINK i32_4tech compare(String a, char *b){return(compare_sc(a,b));} +FSTRING_INLINE i32_4tech compare(char *a, String b){return(compare_cs(a,b));} +FSTRING_LINK i32_4tech compare(String a, String b){return(compare_ss(a,b));} +FSTRING_LINK i32_4tech find(char *str, i32_4tech start, char character){return(find_c_char(str,start,character));} +FSTRING_LINK i32_4tech find(String str, i32_4tech start, char character){return(find_s_char(str,start,character));} +FSTRING_LINK i32_4tech rfind(String str, i32_4tech start, char character){return(rfind_s_char(str,start,character));} +FSTRING_LINK i32_4tech find(char *str, i32_4tech start, char *characters){return(find_c_chars(str,start,characters));} +FSTRING_LINK i32_4tech find(String str, i32_4tech start, char *characters){return(find_s_chars(str,start,characters));} +FSTRING_LINK i32_4tech find_substr(char *str, i32_4tech start, String seek){return(find_substr_c(str,start,seek));} +FSTRING_LINK i32_4tech find_substr(String str, i32_4tech start, String seek){return(find_substr_s(str,start,seek));} +FSTRING_LINK i32_4tech rfind_substr(String str, i32_4tech start, String seek){return(rfind_substr_s(str,start,seek));} +FSTRING_LINK i32_4tech find_substr_insensitive(char *str, i32_4tech start, String seek){return(find_substr_insensitive_c(str,start,seek));} +FSTRING_LINK i32_4tech find_substr_insensitive(String str, i32_4tech start, String seek){return(find_substr_insensitive_s(str,start,seek));} +FSTRING_INLINE b32_4tech has_substr(char *s, String seek){return(has_substr_c(s,seek));} +FSTRING_INLINE b32_4tech has_substr(String s, String seek){return(has_substr_s(s,seek));} +FSTRING_INLINE b32_4tech has_substr_insensitive(char *s, String seek){return(has_substr_insensitive_c(s,seek));} +FSTRING_INLINE b32_4tech has_substr_insensitive(String s, String seek){return(has_substr_insensitive_s(s,seek));} +FSTRING_LINK i32_4tech copy_fast_unsafe(char *dest, char *src){return(copy_fast_unsafe_cc(dest,src));} +FSTRING_LINK i32_4tech copy_fast_unsafe(char *dest, String src){return(copy_fast_unsafe_cs(dest,src));} +FSTRING_LINK b32_4tech copy_checked(String *dest, String src){return(copy_checked_ss(dest,src));} +FSTRING_LINK b32_4tech copy_checked(char *dest, i32_4tech dest_cap, String src){return(copy_checked_cs(dest,dest_cap,src));} +FSTRING_LINK b32_4tech copy_partial(String *dest, char *src){return(copy_partial_sc(dest,src));} +FSTRING_LINK b32_4tech copy_partial(String *dest, String src){return(copy_partial_ss(dest,src));} +FSTRING_LINK b32_4tech copy_partial(char *dest, i32_4tech dest_cap, String src){return(copy_partial_cs(dest,dest_cap,src));} +FSTRING_INLINE i32_4tech copy(char *dest, char *src){return(copy_cc(dest,src));} +FSTRING_INLINE void copy(String *dest, String src){return(copy_ss(dest,src));} +FSTRING_INLINE void copy(String *dest, char *src){return(copy_sc(dest,src));} +FSTRING_LINK b32_4tech append_checked(String *dest, String src){return(append_checked_ss(dest,src));} +FSTRING_LINK b32_4tech append_partial(String *dest, char *src){return(append_partial_sc(dest,src));} +FSTRING_LINK b32_4tech append_partial(String *dest, String src){return(append_partial_ss(dest,src));} +FSTRING_LINK b32_4tech append(String *dest, char c){return(append_s_char(dest,c));} +FSTRING_INLINE b32_4tech append(String *dest, String src){return(append_ss(dest,src));} +FSTRING_INLINE b32_4tech append(String *dest, char *src){return(append_sc(dest,src));} +FSTRING_LINK void replace_str(String *str, String replace, String with){return(replace_str_ss(str,replace,with));} +FSTRING_LINK void replace_str(String *str, String replace, char *with){return(replace_str_sc(str,replace,with));} +FSTRING_LINK void replace_str(String *str, char *replace, String with){return(replace_str_cs(str,replace,with));} +FSTRING_LINK void replace_str(String *str, char *replace, char *with){return(replace_str_cc(str,replace,with));} +FSTRING_LINK void to_lower(char *src, char *dst){return(to_lower_cc(src,dst));} +FSTRING_LINK void to_lower(String *dst, String src){return(to_lower_ss(dst,src));} +FSTRING_LINK void to_lower(String *str){return(to_lower_s(str));} +FSTRING_LINK void to_upper(char *src, char *dst){return(to_upper_cc(src,dst));} +FSTRING_LINK void to_upper(String *dst, String src){return(to_upper_ss(dst,src));} +FSTRING_LINK void to_upper(String *str){return(to_upper_s(str));} +FSTRING_LINK void to_camel(char *src, char *dst){return(to_camel_cc(src,dst));} +FSTRING_LINK i32_4tech str_is_int(char *str){return(str_is_int_c(str));} +FSTRING_LINK b32_4tech str_is_int(String str){return(str_is_int_s(str));} +FSTRING_LINK i32_4tech str_to_int(char *str){return(str_to_int_c(str));} +FSTRING_LINK i32_4tech str_to_int(String str){return(str_to_int_s(str));} +FSTRING_LINK i32_4tech reverse_seek_slash(String str, i32_4tech pos){return(reverse_seek_slash_pos(str,pos));} +FSTRING_LINK b32_4tech set_last_folder(String *dir, char *folder_name, char slash){return(set_last_folder_sc(dir,folder_name,slash));} +FSTRING_LINK b32_4tech set_last_folder(String *dir, String folder_name, char slash){return(set_last_folder_ss(dir,folder_name,slash));} +FSTRING_LINK b32_4tech string_set_match(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index){return(string_set_match_table(str_set,item_size,count,str,match_index));} + +#endif + +// BOTTOM diff --git a/opengl/4ed_opengl_render.cpp b/opengl/4ed_opengl_render.cpp index 3c5a78da..137e483d 100644 --- a/opengl/4ed_opengl_render.cpp +++ b/opengl/4ed_opengl_render.cpp @@ -49,7 +49,7 @@ private_draw_set_color(Render_Target *t, u32 color){ } internal void -interpret_render_buffer(Render_Target *t, Partition *growable_scratch){ +interpret_render_buffer(Render_Target *t, Arena *scratch){ local_persist b32 first_opengl_call = true; if (first_opengl_call){ first_opengl_call = false; @@ -110,7 +110,8 @@ interpret_render_buffer(Render_Target *t, Partition *growable_scratch){ free_texture = free_texture->next){ glDeleteTextures(1, &free_texture->tex_id); } - sll_clear(t->free_texture_first, t->free_texture_last); + t->free_texture_first = 0; + t->free_texture_last = 0; u8 *start = (u8*)t->buffer.base; u8 *end = (u8*)t->buffer.base + t->buffer.pos; @@ -169,13 +170,13 @@ interpret_render_buffer(Render_Target *t, Partition *growable_scratch){ } if (!page->has_gpu_setup){ - Temp_Memory temp = begin_temp_memory(growable_scratch); + Temp_Memory temp = begin_temp(scratch); i32 tex_width = 0; i32 tex_height = 0; - u32 *pixels = font_load_page_pixels(growable_scratch, font.settings, page, page_number, &tex_width, &tex_height); + u32 *pixels = font_load_page_pixels(scratch, font.settings, page, page_number, &tex_width, &tex_height); page->has_gpu_setup = true; page->gpu_tex = private_texture_initialize(tex_width, tex_height, pixels); - end_temp_memory(temp); + end_temp(temp); } if (page->gpu_tex == 0){ diff --git a/platform_all/4ed_shared_init_logic.cpp b/platform_all/4ed_shared_init_logic.cpp index 31de07f4..b245c1e3 100644 --- a/platform_all/4ed_shared_init_logic.cpp +++ b/platform_all/4ed_shared_init_logic.cpp @@ -12,9 +12,9 @@ internal void memory_init(){ #if defined(FRED_INTERNAL) -# if defined(FTECH_64_BIT) +# if ARCH_64BIT void *bases[] = { (void*)TB(1), (void*)TB(2), }; -# elif defined(FTECH_32_BIT) +# else void *bases[] = { (void*)MB(96), (void*)MB(512), }; # endif #else @@ -31,7 +31,7 @@ memory_init(){ memory_vars.debug_memory = system_memory_allocate_extended(0, memory_vars.debug_memory_size); i32 render_memsize = MB(1); - target.buffer = make_part(system_memory_allocate(render_memsize), render_memsize); + target.buffer = make_cursor(system_memory_allocate(render_memsize), render_memsize); b32 alloc_success = true; if (memory_vars.vars_memory == 0 || memory_vars.target_memory == 0 || memory_vars.user_memory == 0 || target.buffer.base == 0){ @@ -132,9 +132,8 @@ read_command_line(i32 argc, char **argv){ system_error_box("Could not get current directory at launch."); } - String curdir = make_string_cap(cwd, size, sizeof(cwd)); - terminate_with_null(&curdir); - replace_char(&curdir, '\\', '/'); + String_Const_u8 curdir = SCu8(cwd, size); + curdir = string_mod_replace_character(curdir, '\\', '/'); char **files = 0; i32 *file_count = 0; diff --git a/platform_all/4ed_system_shared.cpp b/platform_all/4ed_system_shared.cpp index 54b09026..3f5de7fe 100644 --- a/platform_all/4ed_system_shared.cpp +++ b/platform_all/4ed_system_shared.cpp @@ -24,17 +24,9 @@ system_get_binary_path_string(String *out){ internal void init_shared_vars(){ - umem scratch_size = KB(128); - void *scratch_memory = system_memory_allocate(scratch_size); - shared_vars.scratch = make_part(scratch_memory, (i32)scratch_size); - - umem font_scratch_size = MB(4); - void *font_scratch_memory = system_memory_allocate(font_scratch_size); - shared_vars.font_scratch = make_part(font_scratch_memory, (i32)font_scratch_size); - - umem pixel_scratch_size = MB(4); - void *pixel_scratch_memory = system_memory_allocate(pixel_scratch_size); - shared_vars.pixel_scratch = make_part(pixel_scratch_memory, (i32)pixel_scratch_size); + shared_vars.scratch = make_arena_system(&sysfunc); + shared_vars.font_scratch = make_arena_system(&sysfunc); + shared_vars.pixel_scratch = make_arena_system(&sysfunc); } // @@ -54,38 +46,6 @@ sysshared_filter_real_files(char **files, i32 *file_count){ *file_count = j; } -// HACK(allen): Get rid of this now!? -internal Partition -sysshared_scratch_partition(i32 size){ - void *data = system_memory_allocate((umem)size); - Partition part = make_part(data, size); - return(part); -} - -internal void -sysshared_partition_grow(Partition *part, i32 new_size){ - Assert(part->pos == 0); - - void *data = 0; - if (new_size > part->max){ - data = system_memory_allocate((umem)new_size); - memcpy(data, part->base, part->pos); - system_memory_free(part->base, part->max); - part->base = (char*)data; - part->max = new_size; - } -} - -internal void* -sysshared_push_block(Partition *part, i32 size){ - void *result = push_array(part, i8, size); - if (result == 0){ - sysshared_partition_grow(part, size + part->max); - result = push_array(part, i8, size); - } - return(result); -} - internal b32 sysshared_to_binary_path(String *out_filename, char *filename){ b32 translate_success = 0; diff --git a/platform_all/4ed_system_shared.h b/platform_all/4ed_system_shared.h index 3e2b458a..1e4286a7 100644 --- a/platform_all/4ed_system_shared.h +++ b/platform_all/4ed_system_shared.h @@ -28,9 +28,9 @@ global File_Data null_file_data = {}; internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made); struct Shared_Vars{ - Partition scratch; - Partition font_scratch; - Partition pixel_scratch; + Arena scratch; + Arena font_scratch; + Arena pixel_scratch; }; global Shared_Vars shared_vars; diff --git a/platform_all/4ed_work_queues.cpp b/platform_all/4ed_work_queues.cpp index cb48a254..81601b94 100644 --- a/platform_all/4ed_work_queues.cpp +++ b/platform_all/4ed_work_queues.cpp @@ -341,7 +341,7 @@ Sys_Grow_Thread_Memory_Sig(system_grow_thread_memory){ system_acquire_lock(cancel_lock); void *old_data = memory->data; i32 old_size = memory->size; - i32 new_size = l_round_up_i32(memory->size*2, KB(4)); + i32 new_size = round_up_i32(memory->size*2, KB(4)); memory->data = system_memory_allocate(new_size); memory->size = new_size; if (old_data != 0){ @@ -356,9 +356,7 @@ work_system_init(){ AssertThreadSizes(); u32 core_count = CORE_COUNT; - i32 thread_system_memory_size = core_count*(sizeof(Thread_Context) + sizeof(Thread_Memory)); - void *thread_system_memory = system_memory_allocate(thread_system_memory_size); - Partition thread_part = make_part(thread_system_memory, thread_system_memory_size); + Arena thread_arena = make_arena_system(&sysfunc); for (i32 i = 0; i < LOCK_COUNT; ++i){ system_init_lock(&threadvars.locks[i]); @@ -368,10 +366,10 @@ work_system_init(){ system_init_cv(&threadvars.conds[i]); } - threadvars.thread_memory = push_array(&thread_part, Thread_Memory, core_count); + threadvars.thread_memory = push_array(&thread_arena, Thread_Memory, core_count); for (u32 group_i = 0; group_i < THREAD_GROUP_COUNT; ++group_i){ - Thread_Context *threads = push_array(&thread_part, Thread_Context, core_count); + Thread_Context *threads = push_array(&thread_arena, Thread_Context, core_count); threadvars.groups[group_i].threads = threads; threadvars.groups[group_i].count = core_count; threadvars.groups[group_i].cancel_lock0 = CANCEL_LOCK0; diff --git a/platform_linux/linux_4ed.cpp b/platform_linux/linux_4ed.cpp index 6be0833c..7e9b7b03 100644 --- a/platform_linux/linux_4ed.cpp +++ b/platform_linux/linux_4ed.cpp @@ -11,10 +11,9 @@ // TOP #define IS_PLAT_LAYER -#include "4coder_os_comp_cracking.h" #include -#include "4ed_defines.h" +#include "4coder_base_types.h" #include "4coder_API/4coder_version.h" #include "4coder_lib/4coder_utf8.h" diff --git a/platform_mac/mac_4ed.cpp b/platform_mac/mac_4ed.cpp index 338fade3..b6de3ced 100644 --- a/platform_mac/mac_4ed.cpp +++ b/platform_mac/mac_4ed.cpp @@ -11,7 +11,7 @@ #define IS_PLAT_LAYER -#include "4ed_defines.h" +#include "4coder_base_types.h" #include "4coder_API/4coder_version.h" #include "4coder_lib/4coder_utf8.h" diff --git a/platform_mac/mac_4ed.m b/platform_mac/mac_4ed.m index 4b42f917..ecb0fba9 100644 --- a/platform_mac/mac_4ed.m +++ b/platform_mac/mac_4ed.m @@ -11,9 +11,8 @@ #define IS_OBJC_LAYER -#define internal internal -#include "4ed_defines.h" -#undef internal +#include "4coder_base_types.h" + #include "4coder_API/4coder_version.h" #include "4coder_API/4coder_keycodes.h" @@ -21,7 +20,6 @@ #include "4ed_cursor_codes.h" #include "4ed_linked_node_macros.h" -#undef internal #undef global #undef external #define external diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index 083661c3..319723e3 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -10,7 +10,6 @@ // TOP #define IS_PLAT_LAYER -#include "4coder_os_comp_cracking.h" // // Program setup @@ -21,7 +20,6 @@ #define FPS 60 #define frame_useconds (1000000 / FPS) -#include "4ed_defines.h" #include "4coder_base_types.h" #include "4coder_API/4coder_version.h" @@ -31,6 +29,11 @@ #if defined(FRED_SUPER) # include "4coder_lib/4coder_arena.h" # include "4coder_lib/4coder_heap.h" + +# include "4coder_lib/4coder_string.h" + +#include "4coder_base_types.cpp" + # include "4coder_lib/4coder_arena.cpp" # include "4coder_lib/4coder_heap.cpp" # define FSTRING_IMPLEMENTATION @@ -114,6 +117,58 @@ struct Win32_Input_Chunk{ //////////////////////////////// +// TODO(allen): MERGE WITH 4ed.exe version!!!!!!! + +internal void* +base_reserve__system(void *user_data, umem size, umem *size_out){ + System_Functions *system = (System_Functions*)user_data; + umem extra_size = 128; + umem increased_size = size + extra_size; + size = round_up_umem(increased_size, KB(4)); + *size_out = size - extra_size; + void *ptr = system->memory_allocate(size); + *(umem*)ptr = size; + ptr = (u8*)ptr + extra_size; + return(ptr); +} + +internal void +base_free__system(void *user_data, void *ptr){ + System_Functions *system = (System_Functions*)user_data; + umem extra_size = 128; + ptr = (u8*)ptr - extra_size; + umem size = *(umem*)ptr; + system->memory_free(ptr, size); +} + +internal Base_Allocator +make_base_allocator_system(System_Functions *system){ + return(make_base_allocator(base_reserve__system, 0, 0, + base_free__system, 0, system)); +} + +global Base_Allocator base_allocator_system = {}; + +internal Arena +make_arena_system(System_Functions *system, umem chunk_size, umem align){ + if (base_allocator_system.reserve == 0){ + base_allocator_system = make_base_allocator_system(system); + } + return(make_arena(&base_allocator_system, chunk_size, align)); +} + +internal Arena +make_arena_system(System_Functions *system, umem chunk_size){ + return(make_arena_system(system, chunk_size, 8)); +} + +internal Arena +make_arena_system(System_Functions *system){ + return(make_arena_system(system, KB(16), 8)); +} + +//////////////////////////////// + #define SLASH '\\' #define DLL "dll" @@ -172,8 +227,8 @@ struct Win32_Vars{ b32 next_clipboard_is_self; DWORD clipboard_sequence; - Partition clip_post_part; - i32 clip_post_len; + Arena clip_post_arena; + String_Const_u8 clip_post; HWND window_handle; i32 dpi_x; @@ -404,7 +459,7 @@ struct File_Track_Note_Node{ }; Heap file_track_heap = {}; -Partition file_track_scratch = {}; +Arena file_track_scratch = {}; CString_Ptr_Table file_track_dir_table = {}; Directory_Track_Node *file_track_dir_free_first = 0; @@ -607,7 +662,7 @@ alloc_insert_CString_Ptr_table(CString_Ptr_Table *table, char*key, i32 key_size, internal String file_track_store_string_copy(String string){ i32 alloc_size = string.size + 1; - alloc_size = l_round_up_i32(alloc_size, 16); + alloc_size = round_up_i32(alloc_size, 16); char *buffer = (char*)heap_allocate(&file_track_heap, alloc_size); if (buffer == 0){ i32 size = MB(1); @@ -826,7 +881,7 @@ file_track_worker(void*){ i32 req_size = dir_len + (len + 1)*2 + 4; - Temp_Memory temp = begin_temp_memory(&file_track_scratch); + Temp_Memory temp = begin_temp(&file_track_scratch); u8 *buffer = push_array(&file_track_scratch, u8, req_size); if (buffer != 0){ @@ -854,7 +909,7 @@ file_track_worker(void*){ } } - end_temp_memory(temp); + end_temp(temp); } LeaveCriticalSection(&file_track_critical_section); } @@ -864,8 +919,7 @@ file_track_worker(void*){ internal void file_track_init(){ heap_init(&file_track_heap); - i32 scratch_size = KB(128); - file_track_scratch = make_part(system_memory_allocate(scratch_size), scratch_size); + file_track_scratch = make_arena_system(&sysfunc); InitializeCriticalSection(&file_track_critical_section); file_track_iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, 1); file_track_thread = CreateThread(0, 0, file_track_worker, 0, 0, 0); @@ -889,7 +943,7 @@ Sys_Add_Listener_Sig(system_add_listener){ Directory_Track_Node *existing_dir_node = file_track_dir_lookup(dir_name_string); if (existing_dir_node == 0){ - Temp_Memory temp = begin_temp_memory(&file_track_scratch); + Temp_Memory temp = begin_temp(&file_track_scratch); String dir_name_string_terminated = string_push_copy(&file_track_scratch, dir_name_string); HANDLE dir_handle = CreateFile_utf8(&file_track_scratch, (u8*)dir_name_string_terminated.str, FILE_LIST_DIRECTORY, @@ -906,7 +960,7 @@ Sys_Add_Listener_Sig(system_add_listener){ existing_dir_node = new_node; } - end_temp_memory(temp); + end_temp(temp); } if (existing_dir_node != 0){ @@ -1000,13 +1054,18 @@ win32_post_clipboard(char *text, i32 len){ internal Sys_Post_Clipboard_Sig(system_post_clipboard){ - Partition *part = &win32vars.clip_post_part; - part->pos = 0; - u8 *post = (u8*)sysshared_push_block(part, str.size + 1); - if (post != 0){ - memcpy(post, str.str, str.size); - post[str.size] = 0; - win32vars.clip_post_len = str.size; + Arena *arena = &win32vars.clip_post_arena; + if (arena->base_allocator == 0){ + *arena = make_arena_system(&sysfunc); + } + else{ + linalloc_clear(arena); + } + win32vars.clip_post.str = push_array(arena, u8, str.size + 1); + if (win32vars.clip_post.str != 0){ + block_copy(win32vars.clip_post.str, str.str, str.size); + win32vars.clip_post.str[str.size] = 0; + win32vars.clip_post.size = str.size; } else{ LOGF("Failed to allocate buffer for clipboard post (%d)\n", str.size + 1); @@ -1015,8 +1074,8 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){ internal b32 win32_read_clipboard_contents(void){ - Partition *scratch = &shared_vars.scratch; - Temp_Memory temp = begin_temp_memory(scratch); + Arena *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp(scratch); b32 result = false; @@ -1045,7 +1104,7 @@ win32_read_clipboard_contents(void){ for (;clip_8_len >= win32vars.clip_max && !error;){ system_memory_free(win32vars.clip_buffer, win32vars.clip_max); - win32vars.clip_max = l_round_up_u32(clip_8_len + 1, KB(4)); + win32vars.clip_max = round_up_u32(clip_8_len + 1, KB(4)); win32vars.clip_buffer = (u8*)system_memory_allocate(win32vars.clip_max); clip_8_len = (u32)utf16_to_utf8_minimal_checking(win32vars.clip_buffer, win32vars.clip_max - 1, clip_16, clip_16_len, &error); } @@ -1067,7 +1126,7 @@ win32_read_clipboard_contents(void){ if (clip_ascii_len >= win32vars.clip_max){ system_memory_free(win32vars.clip_buffer, win32vars.clip_max); - win32vars.clip_max = l_round_up_u32(clip_ascii_len + 1, KB(4)); + win32vars.clip_max = round_up_u32(clip_ascii_len + 1, KB(4)); win32vars.clip_buffer = (u8*)system_memory_allocate(win32vars.clip_max); } memcpy(win32vars.clip_buffer, clip_ascii, clip_ascii_len + 1); @@ -1086,7 +1145,7 @@ win32_read_clipboard_contents(void){ } } - end_temp_memory(temp); + end_temp(temp); return(result); } @@ -1196,14 +1255,14 @@ Sys_CLI_Update_Step_Sig(system_cli_update_step){ if (remaining + pos < max){ has_more = 1; ReadFile(handle, dest + pos, remaining, &read_amount, 0); - TentativeAssert(remaining == read_amount); + Assert(remaining == read_amount); pos += remaining; remaining = 0; } else{ has_more = 1; ReadFile(handle, dest + pos, max - pos, &read_amount, 0); - TentativeAssert(max - pos == read_amount); + Assert(max - pos == read_amount); loop->remaining_amount = remaining - (max - pos); pos = max; break; @@ -1283,20 +1342,11 @@ Sys_Font_Data(name, parameters){ SelectObject(hdc, hfont); DWORD size = GetFontData(hdc, 0, 0, NULL, 0); if (size > 0){ - Partition *part = &shared_vars.font_scratch; - data.temp = begin_temp_memory(part); - u8 *buffer = push_array(part, u8, size); - if (buffer == 0){ - sysshared_partition_grow(part, l_round_up_i32(size, KB(4))); - buffer = push_array(part, u8, size); - } - - if (buffer != 0){ - push_align(part, 8); - if (GetFontData(hdc, 0, 0, buffer, size) == size){ - data.data = buffer; - data.size = size; - } + Arena *arena = &shared_vars.font_scratch; + u8 *buffer = push_array(arena, u8, size); + if (GetFontData(hdc, 0, 0, buffer, size) == size){ + data.data = buffer; + data.size = size; } } DeleteDC(hdc); @@ -1307,7 +1357,7 @@ Sys_Font_Data(name, parameters){ } struct Win32_Font_Enum{ - Partition *part; + Arena *arena; Font_Setup_List *list; }; @@ -1323,40 +1373,30 @@ LPARAM lParam ENUMLOGFONTEXDV *log_font = (ENUMLOGFONTEXDV*)lpelfe; TCHAR *name = ((log_font)->elfEnumLogfontEx).elfLogFont.lfFaceName; - if ((char)name[0] == '@'){ - return(1); - } - - i32 len = 0; - for (;name[len]!=0;++len); - - if (len >= sizeof(((Font_Loadable_Stub*)0)->name)){ - return(1); - } - - Win32_Font_Enum p = *(Win32_Font_Enum*)lParam; - - Temp_Memory reset = begin_temp_memory(p.part); - Font_Setup *setup = push_array(p.part, Font_Setup, 1); - if (setup != 0){ - memset(setup, 0, sizeof(*setup)); + if ((char)name[0] != '@'){ + i32 len = 0; + for (;name[len]!=0;++len); - b32 good = true; - for (i32 i = 0; i < len; ++i){ - if (name[i] >= 128){ - good = false; - break; + if (len < sizeof(Member(Font_Loadable_Stub, name))){ + Win32_Font_Enum p = *(Win32_Font_Enum*)lParam; + Temp_Memory reset = begin_temp(p.arena); + Font_Setup *setup = push_array_zero(p.arena, Font_Setup, 1); + b32 good = true; + for (i32 i = 0; i < len; ++i){ + if (name[i] >= 128){ + good = false; + break; + } + setup->stub.name[i] = (char)name[i]; + } + if (good){ + setup->stub.load_from_path = false; + setup->stub.len = len; + sll_queue_push(p.list->first, p.list->last, setup); + } + else{ + end_temp(reset); } - setup->stub.name[i] = (char)name[i]; - } - - if (good){ - setup->stub.load_from_path = false; - setup->stub.len = len; - sll_push(p.list->first, p.list->last, setup); - } - else{ - end_temp_memory(reset); } } } @@ -1365,7 +1405,7 @@ LPARAM lParam } internal void -win32_get_loadable_fonts(Partition *part, Font_Setup_List *list){ +win32_get_loadable_fonts(Arena *arena, Font_Setup_List *list){ HDC hdc= GetDC(0); LOGFONT log_font = {}; @@ -1373,11 +1413,10 @@ win32_get_loadable_fonts(Partition *part, Font_Setup_List *list){ log_font.lfFaceName[0] = 0; Win32_Font_Enum p = {}; - p.part = part; + p.arena = arena; p.list = list; - int result = EnumFontFamiliesEx(hdc, &log_font, win32_font_enum_callback, (LPARAM)&p,0); - AllowLocal(result); + EnumFontFamiliesEx(hdc, &log_font, win32_font_enum_callback, (LPARAM)&p,0); ReleaseDC(0, hdc); } @@ -1690,6 +1729,10 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ case WM_KEYDOWN: case WM_KEYUP: { + b8 release = HasFlag(lParam, bit_32); + b8 down = !release; + b8 is_right = HasFlag(lParam, bit_25); + switch (wParam){ case VK_CONTROL:case VK_LCONTROL:case VK_RCONTROL: case VK_MENU:case VK_LMENU:case VK_RMENU: @@ -1698,49 +1741,46 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ Control_Keys *controls = &win32vars.input_chunk.pers.controls; b8 *control_keys = win32vars.input_chunk.pers.control_keys; - b8 down = ((lParam & bit_31)?(0):(1)); - b8 is_right = ((lParam & bit_24)?(1):(0)); - if (wParam != 255){ switch (wParam){ case VK_SHIFT: { control_keys[MDFR_SHIFT_INDEX] = down; }break; - case VK_CONTROL: { - if (is_right) controls->r_ctrl = down; - else controls->l_ctrl = down; + if (is_right){ + controls->r_ctrl = down; + } + else{ + controls->l_ctrl = down; + } }break; - case VK_MENU: { - if (is_right) controls->r_alt = down; - else controls->l_alt = down; + if (is_right){ + controls->r_alt = down; + } + else{ + controls->l_alt = down; + } }break; } b8 ctrl = (controls->r_ctrl || (controls->l_ctrl && !controls->r_alt)); b8 alt = (controls->l_alt || (controls->r_alt && !controls->l_ctrl)); - - if (win32vars.lctrl_lalt_is_altgr){ - if (controls->l_alt && controls->l_ctrl){ - ctrl = 0; - alt = 0; - } + if (win32vars.lctrl_lalt_is_altgr && controls->l_alt && controls->l_ctrl){ + ctrl = false; + alt = false; } - control_keys[MDFR_CONTROL_INDEX] = ctrl; control_keys[MDFR_ALT_INDEX] = alt; } }break; } - b8 current_state = ((lParam & bit_31)?(0):(1)); - if (current_state){ + if (down){ Key_Code key = keycode_lookup_table[(u8)wParam]; - if (key != 0){ i32 *count = &win32vars.input_chunk.trans.key_data.count; Key_Event_Data *data = win32vars.input_chunk.trans.key_data.keys; @@ -1858,7 +1898,6 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ win32vars.got_useful_event = true; win32vars.input_chunk.pers.mouse_l = 0; win32vars.input_chunk.pers.mouse_r = 0; - for (i32 i = 0; i < MDFR_INDEX_COUNT; ++i){ win32vars.input_chunk.pers.control_keys[i] = 0; } @@ -1898,7 +1937,6 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); // NOTE(allen): Do nothing? - AllowLocal(hdc); EndPaint(hwnd, &ps); }break; @@ -2089,12 +2127,12 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // LOG("Initializing fonts\n"); - Partition *scratch = &shared_vars.scratch; - Temp_Memory temp = begin_temp_memory(scratch); + Arena *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp(scratch); Font_Setup_List font_setup = system_font_get_local_stubs(scratch); win32_get_loadable_fonts(scratch, &font_setup); system_font_init(&sysfunc.font, plat_settings.font_size, plat_settings.use_hinting, font_setup); - end_temp_memory(temp); + end_temp(temp); // // Misc System Initializations @@ -2151,12 +2189,11 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS if (size == 0 || size >= sizeof(cwd)){ system_error_box("Could not get current directory at launch."); } - String curdir = make_string(cwd, size); - terminate_with_null(&curdir); - replace_char(&curdir, '\\', '/'); + String_Const_u8 curdir = SCu8(cwd, size); + curdir = string_mod_replace_character(curdir, '\\', '/'); LOG("Initializing application variables\n"); - app.init(&sysfunc, &target, &memory_vars, win32vars.clipboard_contents, curdir, custom_api); + app.init(&sysfunc, &target, &memory_vars, string_new_u8_from_old(win32vars.clipboard_contents), curdir, custom_api); // // Main loop @@ -2355,9 +2392,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS win32vars.clipboard_sequence = new_number; } } - input.clipboard = win32vars.clipboard_contents; + input.clipboard = string_new_u8_from_old(win32vars.clipboard_contents); - win32vars.clip_post_len = 0; + win32vars.clip_post.size = 0; // NOTE(allen): Application Core Update @@ -2375,8 +2412,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } // NOTE(allen): Post New Clipboard Content - if (win32vars.clip_post_len > 0){ - win32_post_clipboard((char*)win32vars.clip_post_part.base, win32vars.clip_post_len); + if (win32vars.clip_post.size > 0){ + win32_post_clipboard((char*)win32vars.clip_post.str, (i32)win32vars.clip_post.size); } // NOTE(allen): Switch to New Title diff --git a/platform_win32/win32_4ed_functions.cpp b/platform_win32/win32_4ed_functions.cpp index a77d3cae..a4310796 100644 --- a/platform_win32/win32_4ed_functions.cpp +++ b/platform_win32/win32_4ed_functions.cpp @@ -276,12 +276,11 @@ internal Sys_Get_Canonical_Sig(system_get_canonical){ u32 result = 0; + String_Const_char file_name = SCchar(filename, len); char src_space[MAX_PATH + 32]; if (len < sizeof(src_space) && - (len >= 2 && - ((filename[0] >= 'a' && filename[0] <= 'z') || - (filename[0] >= 'A' && filename[0] <= 'Z')) && filename[1] == ':') || - (filename[0] == '\\' && filename[1] == '\\')){ + ((character_is_alpha(string_get_character(file_name, 0)) && string_get_character(file_name, 1) == ':') || + string_match(string_prefix(file_name, 2), string_litexpr("\\\\")))){ memcpy(src_space, filename, len); src_space[len] = 0; @@ -473,11 +472,11 @@ color_picker_hook(HWND Window, UINT Message, WPARAM WParam, LPARAM LParam){ color_picker *picker = (color_picker *)win32_params->lCustData; SetWindowLongPtr(Window, GWLP_USERDATA, (LONG_PTR)LParam); - u16_4tech Temp[256]; + u16 Temp[256]; Temp[ArrayCount(Temp) - 1] = 0; - b32_4tech ignored; - utf8_to_utf16_minimal_checking(Temp, ArrayCount(Temp), (u8_4tech *)picker->title.str, picker->title.size, &ignored); + b32 ignored; + utf8_to_utf16_minimal_checking(Temp, ArrayCount(Temp), (u8 *)picker->title.str, picker->title.size, &ignored); if(picker->title.size < ArrayCount(Temp)) { Temp[picker->title.size] = 0; diff --git a/platform_win32/win32_utf8.cpp b/platform_win32/win32_utf8.cpp index 064ec64e..97a58e96 100644 --- a/platform_win32/win32_utf8.cpp +++ b/platform_win32/win32_utf8.cpp @@ -12,8 +12,9 @@ #if !defined(FRED_WIN32_UTF8_CPP) #define FRED_WIN32_UTF8_CPP +// TODO(allen): rewrite _EVERYTHING_ that does Win32 UTF16 <-> UTF8 internal Win32_UTF16 -input_8_to_16(Partition *scratch, u8 *in, u32 in_length){ +input_8_to_16(Arena *scratch, u8 *in, u32 in_length){ Win32_UTF16 r = {}; u32 utf16_max = (in_length + 1)*2; u16 *utf16 = push_array(scratch, u16, utf16_max); @@ -31,35 +32,35 @@ input_8_to_16(Partition *scratch, u8 *in, u32 in_length){ } internal Win32_UTF16 -input_8_to_16(Partition *scratch, u8 *in){ +input_8_to_16(Arena *scratch, u8 *in){ u32 length = 0; for (;in[length];++length); return(input_8_to_16(scratch, in, length)); } internal Win32_UTF16 -input_8_to_16(Partition *scratch, String in){ +input_8_to_16(Arena *scratch, String in){ return(input_8_to_16(scratch, (u8*)in.str, in.size)); } internal HANDLE -CreateFile_utf8(Partition *scratch, u8 *name, DWORD access, DWORD share, LPSECURITY_ATTRIBUTES security, DWORD creation, DWORD flags, HANDLE template_file){ +CreateFile_utf8(Arena *scratch, u8 *name, DWORD access, DWORD share, LPSECURITY_ATTRIBUTES security, DWORD creation, DWORD flags, HANDLE template_file){ HANDLE result = INVALID_HANDLE_VALUE; - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); Win32_UTF16 name_16 = input_8_to_16(scratch, name); if (name_16.success){ result = CreateFileW((LPWSTR)name_16.utf16, access, share, security, creation, flags, template_file); } - end_temp_memory(temp); + end_temp(temp); return(result); } internal DWORD -GetFinalPathNameByHandle_utf8(Partition *scratch, HANDLE file, u8 *file_path_out, DWORD path_max, DWORD flags){ +GetFinalPathNameByHandle_utf8(Arena *scratch, HANDLE file, u8 *file_path_out, DWORD path_max, DWORD flags){ DWORD result = 0; if (file_path_out == 0){ @@ -67,7 +68,7 @@ GetFinalPathNameByHandle_utf8(Partition *scratch, HANDLE file, u8 *file_path_out result *= 2; } else{ - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); u32 path_16_max = KB(32); u16 *path_16 = push_array(scratch, u16, path_16_max); @@ -83,48 +84,48 @@ GetFinalPathNameByHandle_utf8(Partition *scratch, HANDLE file, u8 *file_path_out } } - end_temp_memory(temp); + end_temp(temp); } return(result); } internal HANDLE -FindFirstFile_utf8(Partition *scratch, u8 *name, LPWIN32_FIND_DATA find_data){ +FindFirstFile_utf8(Arena *scratch, u8 *name, LPWIN32_FIND_DATA find_data){ HANDLE result = INVALID_HANDLE_VALUE; - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); Win32_UTF16 name_16 = input_8_to_16(scratch, name); if (name_16.success){ result = FindFirstFileW((LPWSTR)name_16.utf16, find_data); } - end_temp_memory(temp); + end_temp(temp); return(result); } internal DWORD -GetFileAttributes_utf8(Partition *scratch, u8 *name){ +GetFileAttributes_utf8(Arena *scratch, u8 *name){ DWORD result = 0; - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); Win32_UTF16 name_16 = input_8_to_16(scratch, name); if (name_16.success){ result = GetFileAttributesW((LPWSTR)name_16.utf16); } - end_temp_memory(temp); + end_temp(temp); return(result); } internal DWORD -GetModuleFileName_utf8(Partition *scratch, HMODULE module, u8 *file_out, DWORD max){ +GetModuleFileName_utf8(Arena *scratch, HMODULE module, u8 *file_out, DWORD max){ DWORD result = 0; - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); u32 file_16_max = KB(40); u16 *file_16 = push_array(scratch, u16, file_16_max); DWORD file_16_len = GetModuleFileNameW(module, (LPWSTR)file_16, file_16_max); @@ -134,15 +135,15 @@ GetModuleFileName_utf8(Partition *scratch, HMODULE module, u8 *file_out, DWORD m if (convert_error || file_8_len >= max){ result = 0; } - end_temp_memory(temp); + end_temp(temp); return(result); } internal BOOL -CreateProcess_utf8(Partition *scratch, u8 *app_name, u8 *command, LPSECURITY_ATTRIBUTES security, LPSECURITY_ATTRIBUTES thread, BOOL inherit_handles, DWORD creation, LPVOID environment, u8 *curdir, LPSTARTUPINFO startup, LPPROCESS_INFORMATION process){ +CreateProcess_utf8(Arena *scratch, u8 *app_name, u8 *command, LPSECURITY_ATTRIBUTES security, LPSECURITY_ATTRIBUTES thread, BOOL inherit_handles, DWORD creation, LPVOID environment, u8 *curdir, LPSTARTUPINFO startup, LPPROCESS_INFORMATION process){ BOOL result = false; - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); Win32_UTF16 app_name_16 = input_8_to_16(scratch, app_name); @@ -156,16 +157,16 @@ CreateProcess_utf8(Partition *scratch, u8 *app_name, u8 *command, LPSECURITY_ATT } } - end_temp_memory(temp); + end_temp(temp); return(result); } internal DWORD -GetCurrentDirectory_utf8(Partition *scratch, DWORD max, u8 *buffer){ +GetCurrentDirectory_utf8(Arena *scratch, DWORD max, u8 *buffer){ DWORD result = 0; - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); u32 buffer_16_max = KB(40); u16 *buffer_16 = push_array(scratch, u16, buffer_16_max); @@ -180,15 +181,15 @@ GetCurrentDirectory_utf8(Partition *scratch, DWORD max, u8 *buffer){ result = buffer_8_len; } - end_temp_memory(temp); + end_temp(temp); return(result); } internal int -MessageBox_utf8(Partition *scratch, HWND owner, u8 *text, u8 *caption, UINT type){ +MessageBox_utf8(Arena *scratch, HWND owner, u8 *text, u8 *caption, UINT type){ int result = 0; - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); Win32_UTF16 text_16 = input_8_to_16(scratch, text); if (text_16.success){ Win32_UTF16 caption_16 = input_8_to_16(scratch, caption); @@ -196,31 +197,31 @@ MessageBox_utf8(Partition *scratch, HWND owner, u8 *text, u8 *caption, UINT type result = MessageBoxW(owner, (LPWSTR)text_16.utf16, (LPWSTR)caption_16.utf16, type); } } - end_temp_memory(temp); + end_temp(temp); return(result); } internal BOOL -SetWindowText_utf8(Partition *scratch, HWND window, u8 *string){ +SetWindowText_utf8(Arena *scratch, HWND window, u8 *string){ BOOL result = FALSE; - Temp_Memory temp = begin_temp_memory(scratch); + Temp_Memory temp = begin_temp(scratch); Win32_UTF16 string_16 = input_8_to_16(scratch, string); if (string_16.success){ result = SetWindowTextW(window, (LPWSTR)string_16.utf16); } - end_temp_memory(temp); + end_temp(temp); return(result); } internal BOOL -GetFileAttributesEx_utf8String(Partition *scratch, String file_name, GET_FILEEX_INFO_LEVELS info_level_id, LPVOID file_info){ +GetFileAttributesEx_utf8String(Arena *scratch, String_Const_u8 file_name, GET_FILEEX_INFO_LEVELS info_level_id, LPVOID file_info){ BOOL result = FALSE; - Temp_Memory temp = begin_temp_memory(scratch); - Win32_UTF16 string_16 = input_8_to_16(scratch, file_name); + Temp_Memory temp = begin_temp(scratch); + Win32_UTF16 string_16 = input_8_to_16(scratch, string_old_from_new(file_name)); if (string_16.success){ result = GetFileAttributesExW((LPWSTR)string_16.utf16, info_level_id, file_info); } - end_temp_memory(temp); + end_temp(temp); return(result); } diff --git a/platform_win32/win32_utf8.h b/platform_win32/win32_utf8.h index 98d862f5..5add73e7 100644 --- a/platform_win32/win32_utf8.h +++ b/platform_win32/win32_utf8.h @@ -13,34 +13,34 @@ #define FRED_WIN32_UTF8_H internal HANDLE -CreateFile_utf8(Partition *scratch, u8 *name, DWORD access, DWORD share, LPSECURITY_ATTRIBUTES security, DWORD creation, DWORD flags, HANDLE template_file); +CreateFile_utf8(Arena *scratch, u8 *name, DWORD access, DWORD share, LPSECURITY_ATTRIBUTES security, DWORD creation, DWORD flags, HANDLE template_file); internal DWORD -GetFinalPathNameByHandle_utf8(Partition *scratch, HANDLE file, u8 *file_path_out, DWORD path_max, DWORD flags); +GetFinalPathNameByHandle_utf8(Arena *scratch, HANDLE file, u8 *file_path_out, DWORD path_max, DWORD flags); internal HANDLE -FindFirstFile_utf8(Partition *scratch, u8 *name, LPWIN32_FIND_DATA find_data); +FindFirstFile_utf8(Arena *scratch, u8 *name, LPWIN32_FIND_DATA find_data); internal DWORD -GetFileAttributes_utf8(Partition *scratch, u8 *name); +GetFileAttributes_utf8(Arena *scratch, u8 *name); internal DWORD -GetModuleFileName_utf8(Partition *scratch, HMODULE module, u8 *file_out, DWORD max); +GetModuleFileName_utf8(Arena *scratch, HMODULE module, u8 *file_out, DWORD max); internal BOOL -CreateProcess_utf8(Partition *scratch, u8 *app_name, u8 *command, LPSECURITY_ATTRIBUTES security, LPSECURITY_ATTRIBUTES thread, BOOL inherit_handles, DWORD creation, LPVOID environment, u8 *curdir, LPSTARTUPINFO startup, LPPROCESS_INFORMATION process); +CreateProcess_utf8(Arena *scratch, u8 *app_name, u8 *command, LPSECURITY_ATTRIBUTES security, LPSECURITY_ATTRIBUTES thread, BOOL inherit_handles, DWORD creation, LPVOID environment, u8 *curdir, LPSTARTUPINFO startup, LPPROCESS_INFORMATION process); internal DWORD -GetCurrentDirectory_utf8(Partition *scratch, DWORD max, u8 *buffer); +GetCurrentDirectory_utf8(Arena *scratch, DWORD max, u8 *buffer); internal int -MessageBox_utf8(Partition *scratch, HWND owner, u8 *text, u8 *caption, UINT type); +MessageBox_utf8(Arena *scratch, HWND owner, u8 *text, u8 *caption, UINT type); internal BOOL -SetWindowText_utf8(Partition *scratch, HWND window, u8 *string); +SetWindowText_utf8(Arena *scratch, HWND window, u8 *string); internal BOOL -GetFileAttributesEx_utf8String(Partition *scratch, String file_name, GET_FILEEX_INFO_LEVELS info_level_id, LPVOID file_info); +GetFileAttributesEx_utf8String(Arena *scratch, String_Const_u8 file_name, GET_FILEEX_INFO_LEVELS info_level_id, LPVOID file_info); // For implementation diff --git a/project.4coder b/project.4coder index d3717483..19bb10db 100644 --- a/project.4coder +++ b/project.4coder @@ -33,16 +33,6 @@ command_list = { .cmd = { {"echo build: x64 & build.bat" , .os = "win" }, {"echo build: x64 & ./build.sh", .os = "linux"}, {"echo build: x64 & ./build.sh", .os = "mac" }, }, }, - { .name = "build site", - .out = "*site*", .footer_panel = false, .save_dirty_files = true, - .cmd = { {"build_site.bat" , .os = "win" }, - {"./build_site.sh", .os = "linux"}, - {"./build_site.sh", .os = "mac" }, }, }, - { .name = "build string", - .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, - .cmd = { {"build_string.bat" , .os = "win" }, - {"./build_string.sh", .os = "linux"}, - {"./build_string.sh", .os = "mac" }, }, }, { .name = "build x86", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cmd = { {build_x86_win32, .os = "win" }, @@ -68,21 +58,27 @@ command_list = { .cmd = { {"..\\build\\generate_config_parser", .os = "win" }, {"../build/generate_config_parser" , .os = "linux"}, {"../build/generate_config_parser" , .os = "mac" }, }, }, + { .name = "build one time", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cmd = { { "pushd ..\\..\\one_time_code & build.bat" , .os = "win" }, }, }, { .name = "run one time", .out = "*run*", .footer_panel = false, .save_dirty_files = false, .cmd = { { "pushd ..\\..\\one_time_code\\build & one_time", .os = "win" }, }, }, + + { .name = "build pinky one time", + .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, + .cmd = { { "pushd ..\\..\\pinky\\code & build.bat" , .os = "win" }, }, }, + { .name = "run pinky one time", + .out = "*run*", .footer_panel = false, .save_dirty_files = false, + .cmd = { { "pushd ..\\..\\pinky\\build & one_time", .os = "win" }, }, }, }; fkey_command[1] = "build x64"; -fkey_command[2] = "build site"; -fkey_command[3] = "build string"; -fkey_command[4] = "build x86"; -fkey_command[5] = "build metadata"; -fkey_command[6] = "build config parser generator"; -fkey_command[7] = "generate config parser"; -fkey_command[9] = "build one time"; -fkey_command[10] = "run one time"; +fkey_command[3] = "build x86"; +fkey_command[4] = "build metadata"; +fkey_command[5] = "build config parser generator"; +fkey_command[6] = "generate config parser"; +fkey_command[9] = "build pinky one time"; +fkey_command[10] = "run pinky one time"; fkey_command[12] = "package"; diff --git a/site/4ed_abstract_document.cpp b/site/4ed_abstract_document.cpp deleted file mode 100644 index 99a2db97..00000000 --- a/site/4ed_abstract_document.cpp +++ /dev/null @@ -1,2255 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 25.02.2016 - * - * Document data structure and generator for 4coder documentation. - * - */ - -// TOP - -struct Enriched_Text{ - String fname; - String source; -}; - -internal Enriched_Text -load_enriched_text(Partition *arena, char *directory, char *filename){ - Enriched_Text result = {}; - result.fname = make_string_slowly(fm_str(arena, directory, "/", filename)); - result.source = file_dump(result.fname.str); - return(result); -} - -//////////////////////////////// - -typedef u32 Mangle_Rule; -enum{ - MangleRule_None, - MangleRule_MacroSig, - MangleRule_ToLower, -}; - -internal Mangle_Rule -get_mangle_rule(String mangle){ - Mangle_Rule result = MangleRule_None; - if (match(mangle, "macro sig")){ - result = MangleRule_MacroSig; - } - else if (match(mangle, "to lower")){ - result = MangleRule_ToLower; - } - return(result); -} - -internal String -apply_mangle_rule(Partition *arena, String name, u32 mangle_rule){ - String result = {}; - switch (mangle_rule){ - case MangleRule_MacroSig: - { - result = string_push(arena, name.size + 5); - push_align(arena, 8); - copy(&result, name); - to_upper(&result); - append(&result, "_SIG"); - terminate_with_null(&result); - }break; - case MangleRule_ToLower: - { - result = string_push(arena, name.size + 1); - push_align(arena, 8); - copy(&result, name); - to_lower(&result); - terminate_with_null(&result); - }break; - default: - { - result = name; - }break; - } - return(result); -} - -//////////////////////////////// - -enum{ - Doc_Root, - Doc_Section, - Doc_Error, - Doc_Todo, - Doc_Include, - Doc_DocList, - Doc_DocFull, - Doc_TableOfContents, - Doc_PlainOldText, - Doc_Version, - Doc_Style, - Doc_DocumentLink, - Doc_Link, - Doc_Image, - Doc_Video, - Doc_BeginParagraph, - Doc_EndParagraph, - Doc_List, - Doc_Item, - // - Doc_COUNT, -}; - -struct Document_Item{ - Document_Item *next; - Document_Item *parent; - i32 type; - - struct{ - Document_Item *first_child; - Document_Item *last_child; - String name; - String id; - b32 show_title; - } section; - - union{ - struct{ - String unit; - u32 mangle_rule; - } unit_elements; - - struct{ - String string; - String string2; - } string; - - struct{ - String name; - struct Abstract_Item *document; - } include; - }; -}; -global Document_Item null_document_item = {}; - -//////////////////////////////// - -internal void -set_item_string(Partition *arena, String *out, String text){ - *out = string_push_copy(arena, text); - push_align(arena, 8); -} - -//////////////////////////////// - -struct Basic_Node{ - Basic_Node *next; -}; - -#define NodeGetData(node, T) ((T*) ((node)+1)) - -struct Basic_List{ - Basic_Node *head; - Basic_Node *tail; - u32 count; -}; - -internal void -clear_list(Basic_List *list){ - memset(list, 0, sizeof(*list)); -} - -internal void* -push_item_on_list(Partition *arena, Basic_List *list, i32 item_size){ - i32 mem_size = item_size + sizeof(Basic_Node); - void *mem = push_array(arena, char, mem_size); - Assert(mem != 0); - memset(mem, 0, mem_size); - push_align(arena, 8); - - Basic_Node *node = (Basic_Node*)mem; - if (list->head == 0){ - list->head = node; - list->tail = node; - } - else{ - list->tail->next = node; - list->tail = node; - } - ++list->count; - - void *result = (node + 1); - return(result); -} - -//////////////////////////////// - -enum{ - ItemType_Document, - ItemType_Image, - ItemType_GenericFile, - ItemType_MetaUnit, - // - ItemType_COUNT, -}; - -struct Abstract_Item{ - i32 item_type; - char *name; - - // Document value members - Document_Item *root_item; - - // Image value members - char *source_file; - char *extension; - float w_h_ratio; - float h_w_ratio; - Basic_List img_instantiations; - - // Meta parse members - Meta_Unit *unit; -}; -global Abstract_Item null_abstract_item = {}; - -internal Abstract_Item* -get_item_by_name(Basic_List list, String name){ - Abstract_Item *result = 0; - - for (Basic_Node *node = list.head; - node != 0; - node = node->next){ - Abstract_Item *item = NodeGetData(node, Abstract_Item); - if (match(item->name, name)){ - result = item; - break; - } - } - - return(result); -} - -internal Abstract_Item* -create_abstract_item(Partition *arena, Basic_List *list, char *name){ - Abstract_Item *result = 0; - Abstract_Item *lookup = get_item_by_name(*list, make_string_slowly(name)); - if (lookup == 0){ - result = (Abstract_Item*)push_item_on_list(arena, list, sizeof(*result)); - } - return(result); -} - -struct Abstract_Item_Array{ - Abstract_Item **items; - u32 count; -}; - -internal Abstract_Item_Array -get_abstract_item_array(Partition *arena, Basic_List *list){ - Abstract_Item_Array result = {}; - - result.items = (Abstract_Item**)push_array(arena, Abstract_Item*, list->count); - result.count = list->count; - - u32 i = 0; - for (Basic_Node *node = list->head; - node != 0; - node = node->next){ - result.items[i++] = NodeGetData(node, Abstract_Item); - } - - return(result); -} - -//////////////////////////////// - -struct Document_System{ - char *code_dir; - char *asset_dir; - char *src_dir; - - Basic_List doc_list; - Basic_List img_list; - Basic_List file_list; - Basic_List meta_list; - - Basic_List unresolved_includes; -}; - -internal Document_System -create_document_system(char *code_dir, char *asset_dir, char *src_dir){ - Document_System system = {}; - system.code_dir = code_dir; - system.asset_dir = asset_dir; - system.src_dir = src_dir; - return(system); -} - -internal void -create_unresolved_include(Partition *arena, Document_System *doc_system, Document_Item *include_item){ - Document_Item **new_item = (Document_Item**)push_item_on_list(arena, &doc_system->unresolved_includes, sizeof(*new_item)); - *new_item = include_item; -} - -//////////////////////////////// - -enum{ - MetaResult_DidParse, - MetaResult_AlreadyExists, - MetaResult_FailedToParse, -}; - -internal u32 -create_meta_unit(Partition *arena, Document_System *doc_system, String name_str, String file_str){ - u32 result = MetaResult_DidParse; - - String name_z = string_push_copy(arena, name_str); - String file_z = string_push_copy(arena, file_str); - char *name = name_z.str; - char *file = file_z.str; - - Abstract_Item *item = create_abstract_item(arena, &doc_system->meta_list, name); - - if (item != 0){ - Meta_Unit *unit = push_array(arena, Meta_Unit, 1); - *unit = compile_meta_unit(arena, doc_system->code_dir, file, ExpandArray(meta_keywords)); - - if (unit->count != 0){ - result = true; - item->item_type = ItemType_MetaUnit; - item->name = name; - item->unit = unit; - } - else{ - result = MetaResult_FailedToParse; - } - } - else{ - result = MetaResult_AlreadyExists; - } - - return(result); -} - -internal Abstract_Item* -add_generic_file(Partition *arena, Document_System *system, char *source_file, char *extension, char *name){ - Abstract_Item *item = create_abstract_item(arena, &system->file_list, name); - if (item){ - char *full_file = fm_str(arena, system->asset_dir, "/", source_file); - - item->item_type = ItemType_GenericFile; - item->extension = extension; - item->source_file = full_file; - item->name = name; - } - return(item); -} - -internal Abstract_Item* -add_image_description(Partition *arena, Document_System *system, char *source_file, char *extension, char *name){ - Abstract_Item *item = create_abstract_item(arena, &system->img_list, name); - if (item != 0){ - char *full_file = fm_str(arena, system->asset_dir, "/", source_file); - - item->item_type = ItemType_Image; - item->name = name; - item->extension = extension; - item->source_file = full_file; - - i32 w = 0, h = 0, comp = 0; - i32 stbi_r = stbi_info(full_file, &w, &h, &comp); - if (!stbi_r){ - fprintf(stdout, "Did not find file %s\n", full_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); - } - } - return(item); -} - -//////////////////////////////// - -struct Image_Instantiation{ - i32 w, h; -}; - -internal Image_Instantiation* -get_image_instantiation(Basic_List list, i32 w, i32 h){ - Image_Instantiation *result = 0; - - for (Basic_Node *node = list.head; - node != 0; - node = node->next){ - Image_Instantiation *instantiation = NodeGetData(node, Image_Instantiation); - if (instantiation->w == w && instantiation->h == h){ - result = instantiation; - break; - } - } - - return(result); -} - -internal void -add_image_instantiation(Partition *arena, Basic_List *list, i32 w, i32 h){ - Image_Instantiation *instantiation = (Image_Instantiation*)push_item_on_list(arena, list, sizeof(*instantiation)); - instantiation->w = w; - instantiation->h = h; -} - -//////////////////////////////// - -struct Document_Builder{ - Abstract_Item *doc; - Document_Item *item_stack[512]; - i32 item_top; -}; - -internal Document_Builder -begin_document_description(Partition *arena, Document_System *system, char *title, char *name, b32 show_title){ - Document_Builder builder = {}; - Abstract_Item *doc = create_abstract_item(arena, &system->doc_list, name); - if (doc != 0){ - builder.doc = doc; - - *doc = null_abstract_item; - doc->item_type = ItemType_Document; - - doc->name = name; - doc->root_item = push_array(arena, Document_Item, 1); - *doc->root_item = null_document_item; - - Document_Item *item = doc->root_item; - set_item_string(arena, &item->section.name, make_string_slowly(name)); - item->section.show_title = show_title; - item->type = Doc_Root; - - builder.item_stack[builder.item_top] = doc->root_item; - } - return(builder); -} - -internal void -append_child(Document_Item *parent, Document_Item *item){ - if (parent->section.last_child == 0){ - parent->section.first_child = item; - } - else{ - parent->section.last_child->next = item; - } - parent->section.last_child = item; - item->parent = parent; -} - -#define PUSH true - -internal void -doc_push(Document_Builder *builder, Document_Item *item){ - Assert(builder->item_top + 1 < ArrayCount(builder->item_stack)); - builder->item_stack[++builder->item_top] = item; -} - -internal Document_Item* -doc_get_item_top(Document_Builder *builder){ - Assert(builder->item_top < ArrayCount(builder->item_stack)); - Document_Item *parent = builder->item_stack[builder->item_top]; - return(parent); -} - -internal Document_Item* -doc_new_item(Partition *arena, Document_Builder *builder, u32 type, b32 push = false){ - Document_Item *parent = doc_get_item_top(builder); - Document_Item *item = push_array(arena, Document_Item, 1); - *item = null_document_item; - item->type = type; - append_child(parent, item); - if (push){ - doc_push(builder, item); - } - return(item); -} - -internal Document_Item* -doc_new_item_strings(Partition *arena, Document_Builder *builder, u32 type, String s1, String s2, b32 push = false){ - Document_Item *item = doc_new_item(arena, builder, type); - if (s1.size > 0){ - set_item_string(arena, &item->string.string, s1); - } - if (s2.size > 0){ - set_item_string(arena, &item->string.string2, s2); - } - if (push){ - doc_push(builder, item); - } - return(item); -} - -internal Document_Item* -doc_new_item_documentation(Partition *arena, Document_Builder *builder, u32 type, String unit, Mangle_Rule mangle_rule, b32 push = false){ - Document_Item *item = doc_new_item(arena, builder, type); - set_item_string(arena, &item->unit_elements.unit, unit); - item->unit_elements.mangle_rule = mangle_rule; - if (push){ - doc_push(builder, item); - } - return(item); -} - -internal void -begin_section(Partition *arena, Document_Builder *builder, char *title, char *id){ - Document_Item *item = doc_new_item(arena, builder, Doc_Section, PUSH); - set_item_string(arena, &item->section.name, make_string_slowly(title)); - item->section.show_title = true; - if (id != 0){ - set_item_string(arena, &item->section.id, make_lit_string(id)); - } -} - -#define doc_end(a,b) doc_pop(a,b) - -#define begin_style(a,b,t) doc_new_item_strings(a, b, Doc_Style, t, null_string, PUSH) -#define begin_link(a,b,t) doc_new_item_strings(a, b, Doc_Link, t, null_string, PUSH); -#define begin_list(a,b) doc_new_item(a, b, Doc_List, PUSH) -#define begin_item(a,b) doc_new_item(a, b, Doc_Item, PUSH) - -internal void -add_include(Partition *arena, Document_System *doc_system, Document_Builder *builder, String text){ - Document_Item *item = doc_new_item(arena, builder, Doc_Include); - set_item_string(arena, &item->include.name, text); - create_unresolved_include(arena, doc_system, item); -} - -#define add_error(a,b,t) doc_new_item_strings(a, b, Doc_Error, t, null_string) -#define add_todo(a,b) doc_new_item(a, b, Doc_Todo) -#define add_doc_list(a,b,u,m) doc_new_item_documentation(a, b, Doc_DocList, u, m) -#define add_doc_full(a,b,u,m) doc_new_item_documentation(a, b, Doc_DocFull, u, m) -#define add_table_of_contents(a,b) doc_new_item(a, b, Doc_TableOfContents) -#define add_plain_old_text(a,b,t) doc_new_item_strings(a, b, Doc_PlainOldText, t, null_string); -#define add_version(a,b) doc_new_item(a, b, Doc_Version) -#define add_document_link(a,b,t) doc_new_item_strings(a, b, Doc_DocumentLink, t, null_string) -#define add_image(a,b,t,e) doc_new_item_strings(a, b, Doc_Image, t, e) -#define add_video(a,b,t) doc_new_item_strings(a, b, Doc_Video, t, null_string) -#define add_begin_paragraph(a,b) doc_new_item(a, b, Doc_BeginParagraph) -#define add_end_paragraph(a,b) doc_new_item(a, b, Doc_EndParagraph) - -internal void -doc_pop(Partition *arena, Document_Builder *builder){ - if (builder->item_top > 0){ - --builder->item_top; - } - else{ - add_error(arena, builder, make_lit_string("unbalanced groups -- extra end")); - } -} - -internal void -end_document_description(Partition *arena, Document_Builder *builder){ - b32 closing_error = (builder->item_top != 0); - if (closing_error){ - add_error(arena, builder, make_lit_string("unbalanced groups -- extra begin")); - } - - for (;builder->item_top > 0;){ - doc_end(arena, builder); - } -} - -//////////////////////////////// - -internal void -report_error_missing_body(Partition *arena, Document_Builder *builder, String command_body){ - char space[512]; - String error_string = make_fixed_width_string(space); - append(&error_string, "missing body for "); - append(&error_string, command_body); - add_error(arena, builder, error_string); -} - -//////////////////////////////// - -enum Command_Types{ - Cmd_BackSlash, - Cmd_End, - Cmd_Section, - Cmd_Style, - Cmd_List, - Cmd_Item, - Cmd_Link, - Cmd_DocumentLink, - Cmd_Image, - Cmd_Video, - Cmd_Version, - Cmd_TableOfContents, - Cmd_Todo, - Cmd_Include, - Cmd_MetaParse, - Cmd_DocList, - Cmd_DocFull, - // never below this - Cmd_COUNT, -}; - -global b32 did_enriched_commands = false; -global String enriched_commands_global_array[Cmd_COUNT]; - -internal String* -get_enriched_commands(){ - if (!did_enriched_commands){ - did_enriched_commands = true; - enriched_commands_global_array[Cmd_BackSlash] = make_lit_string("\\"); - enriched_commands_global_array[Cmd_End] = make_lit_string("END"); - enriched_commands_global_array[Cmd_Section] = make_lit_string("SECTION"); - enriched_commands_global_array[Cmd_Style] = make_lit_string("STYLE"); - enriched_commands_global_array[Cmd_List] = make_lit_string("LIST"); - enriched_commands_global_array[Cmd_Item] = make_lit_string("ITEM"); - enriched_commands_global_array[Cmd_Link] = make_lit_string("LINK"); - enriched_commands_global_array[Cmd_DocumentLink] = make_lit_string("DOC_LINK"); - enriched_commands_global_array[Cmd_Image] = make_lit_string("IMAGE"); - enriched_commands_global_array[Cmd_Video] = make_lit_string("VIDEO"); - enriched_commands_global_array[Cmd_Version] = make_lit_string("VERSION"); - enriched_commands_global_array[Cmd_TableOfContents] = make_lit_string("TABLE_OF_CONTENTS"); - enriched_commands_global_array[Cmd_Todo] = make_lit_string("TODO"); - enriched_commands_global_array[Cmd_Include] = make_lit_string("INCLUDE"); - enriched_commands_global_array[Cmd_MetaParse] = make_lit_string("META_PARSE"); - enriched_commands_global_array[Cmd_DocList] = make_lit_string("DOC_LIST"); - enriched_commands_global_array[Cmd_DocFull] = make_lit_string("DOC_FULL"); - } - return(enriched_commands_global_array); -} - -internal u32 -get_enriched_commands_count(){ - return(ArrayCount(enriched_commands_global_array)); -} - -internal b32 -extract_command_body(String l, i32 *i_in_out, String *body_text_out){ - b32 has_body = false; - i32 i = *i_in_out; - for (; i < l.size; ++i){ - if (!char_is_whitespace(l.str[i])){ - break; - } - } - - if (l.str[i] == '{'){ - i32 body_start = i + 1; - i32 body_end = 0; - for (++i; i < l.size; ++i){ - if (l.str[i] == '}'){ - has_body = true; - body_end = i; - ++i; - break; - } - } - - if (has_body){ - *i_in_out = i; - - String body_text = substr(l, body_start, body_end - body_start); - *body_text_out = skip_chop_whitespace(body_text); - } - } - - return(has_body); -} - -internal Abstract_Item* -make_document_from_text(Partition *arena, Document_System *doc_system, char *title, char *name, Enriched_Text *text){ - String source = text->source; - Document_Builder builder = begin_document_description(arena, doc_system, title, name, false); - - if (source.str == 0){ - char space[512]; - String str = make_fixed_width_string(space); - copy(&str, "could not open source file "); - copy(&str, text->fname); - add_error(arena, &builder, str); - } - else{ - for (String line = get_first_double_line(source); - line.str; - line = get_next_double_line(source, line)){ - String l = skip_chop_whitespace(line); - if (l.size == 0) continue; - - add_begin_paragraph(arena, &builder); - - i32 start = 0, i = 0; - for (; i < l.size; ++i){ - char ch = l.str[i]; - if (ch == '\\'){ - add_plain_old_text(arena, &builder, substr(l, start, i - 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; - } - } - - if (command_end == command_start){ - if (command_end < l.size && l.str[command_end] == '\\'){ - ++command_end; - } - } - - String command_string = substr(l, command_start, command_end - command_start); - - String *enriched_commands = get_enriched_commands(); - u32 enriched_commands_count = get_enriched_commands_count(); - - i = command_end; - - i32 match_index = 0; - if (!string_set_match(enriched_commands, enriched_commands_count, command_string, &match_index)){ - match_index = -1; - } - - switch (match_index){ - case Cmd_BackSlash: - { - add_plain_old_text(arena, &builder, make_lit_string("\\")); - }break; - - case Cmd_End: - { - for (Document_Item *top = doc_get_item_top(&builder); - top->type == Doc_Item; - top = doc_get_item_top(&builder)){ - doc_end(arena, &builder); - } - doc_end(arena, &builder); - }break; - - case Cmd_Section: - { - String body_text = {}; - if (extract_command_body(l, &i, &body_text)){ - String extra_text = {}; - extract_command_body(l, &i, &extra_text); - String title = string_push_copy(arena, body_text); - String id = string_push_copy(arena, extra_text); - begin_section(arena, &builder, title.str, id.str); - } - else{ - report_error_missing_body(arena, &builder, command_string); - } - }break; - - case Cmd_Style: - { - String body_text = {}; - if (extract_command_body(l, &i, &body_text)){ - begin_style(arena, &builder, body_text); - } - else{ - report_error_missing_body(arena, &builder, command_string); - } - }break; - - case Cmd_List: - { - begin_list(arena, &builder); - }break; - - case Cmd_Item: - { - Document_Item *top = doc_get_item_top(&builder); - if (top->type == Doc_Item){ - doc_end(arena, &builder); - } - begin_item(arena, &builder); - }break; - - case Cmd_Link: - { - String body_text = {}; - if (extract_command_body(l, &i, &body_text)){ - begin_link(arena, &builder, body_text); - } - else{ - report_error_missing_body(arena, &builder, command_string); - } - }break; - - // TODO(allen): upgrade this bs - case Cmd_DocumentLink: - { - String body_text = {}; - if (extract_command_body(l, &i, &body_text)){ - add_document_link(arena, &builder, body_text); - } - else{ - report_error_missing_body(arena, &builder, command_string); - } - }break; - - case Cmd_Image: - { - String body_text = {}; - if (extract_command_body(l, &i, &body_text)){ - String size_parameter = {}; - extract_command_body(l, &i, &size_parameter); - add_image(arena, &builder, body_text, size_parameter); - } - else{ - report_error_missing_body(arena, &builder, command_string); - } - }break; - - case Cmd_Video: - { - String body_text = {}; - if (extract_command_body(l, &i, &body_text)){ - add_video(arena, &builder, body_text); - } - else{ - report_error_missing_body(arena, &builder, command_string); - } - }break; - - case Cmd_Version: - { - add_version(arena, &builder); - }break; - - case Cmd_TableOfContents: - { - add_table_of_contents(arena, &builder); - }break; - - case Cmd_Todo: - { - add_todo(arena, &builder); - }break; - - case Cmd_Include: - { - String body_text = {}; - if (extract_command_body(l, &i, &body_text)){ - add_include(arena, doc_system, &builder, body_text); - } - else{ - report_error_missing_body(arena, &builder, command_string); - } - }break; - - case Cmd_MetaParse: - { - String name = {}; - String file = {}; - if (extract_command_body(l, &i, &name)){ - if (extract_command_body(l, &i, &file)){ - u32 result = create_meta_unit(arena, doc_system, name, file); - if (result == MetaResult_FailedToParse){ - char space[512]; - String str = make_fixed_width_string(space); - append(&str, "parse failed for "); - append(&str, file); - add_error(arena, &builder, str); - } - } - else{ - report_error_missing_body(arena, &builder, command_string); - } - } - else{ - report_error_missing_body(arena, &builder, command_string); - } - }break; - - case Cmd_DocList: - case Cmd_DocFull: - { - String name = {}; - if (extract_command_body(l, &i, &name)){ - String mangle = {}; - extract_command_body(l, &i, &mangle); - - u32 mangle_rule = MangleRule_None; - if (match_part(mangle, "mangle:")){ - String mangle_name = substr_tail(mangle, sizeof("mangle:")-1); - mangle_name = skip_chop_whitespace(mangle_name); - mangle_rule = get_mangle_rule(mangle_name); - } - - if (match_index == Cmd_DocList){ - add_doc_list(arena, &builder, name, mangle_rule); - } - else{ - add_doc_full(arena, &builder, name, mangle_rule); - } - - } - else{ - report_error_missing_body(arena, &builder, command_string); - } - }break; - - default: - { - char space[512]; - String error = make_fixed_width_string(space); - append(&error, "unrecognized command "); - append(&error, command_string); - add_error(arena, &builder, error); - }break; - } - - start = i; - } - } - - if (start != i){ - add_plain_old_text(arena, &builder, substr(l, start, i - start)); - } - - add_end_paragraph(arena, &builder); - } - } - - end_document_description(arena, &builder); - return(builder.doc); -} - -//////////////////////////////// - -struct Unresolved_Include_Array{ - Document_Item **items; - u32 count; -}; - -internal Unresolved_Include_Array -get_unresolved_includes(Partition *arena, Document_System *doc_system){ - Unresolved_Include_Array result = {}; - - Basic_List *list = &doc_system->unresolved_includes; - result.items = (Document_Item**)push_array(arena, Document_Item*, list->count); - result.count = list->count; - - u32 i = 0; - for (Basic_Node *node = list->head; - node != 0; - node = node->next){ - result.items[i++] = *NodeGetData(node, Document_Item*); - } - - return(result); -} - -internal void -resolve_all_includes(Partition *arena, Document_System *doc_system){ - for (;doc_system->unresolved_includes.count > 0;){ - Unresolved_Include_Array includes = get_unresolved_includes(arena, doc_system); - clear_list(&doc_system->unresolved_includes); - - Document_Item **item_ptr = includes.items; - for (u32 i = 0; i < includes.count; ++i, ++item_ptr){ - Document_Item *item = *item_ptr; - Assert(item->include.document == 0); - Abstract_Item *inc_doc = get_item_by_name(doc_system->doc_list, item->include.name); - if (inc_doc == 0){ - String source_text = item->include.name; - Enriched_Text *text = push_array(arena, Enriched_Text, 1); - *text = load_enriched_text(arena, doc_system->src_dir, source_text.str); - inc_doc = make_document_from_text(arena, doc_system, source_text.str, source_text.str, text); - } - item->include.document = inc_doc; - } - } -} - -//////////////////////////////// - -// HTML Document Generation - -#define HTML_BACK_COLOR "#FAFAFA" -#define HTML_TEXT_COLOR "#0D0D0D" -#define HTML_CODE_BACK "#DFDFDF" -#define HTML_EXAMPLE_BACK "#EFEFDF" - -#define HTML_POP_COLOR_1 "#309030" -#define HTML_POP_BACK_1 "#E0FFD0" -#define HTML_VISITED_LINK "#A0C050" - -#define HTML_POP_COLOR_2 "#005000" - -#define HTML_CODE_STYLE "font-family: \"Courier New\", Courier, monospace; text-align: left;" - -#define HTML_CODE_BLOCK_STYLE(back) \ -"margin-top: 3mm; margin-bottom: 3mm; font-size: .95em; " \ -"background: "back"; padding: 0.25em;" - -#define HTML_DESCRIPT_SECTION_STYLE HTML_CODE_BLOCK_STYLE(HTML_CODE_BACK) -#define HTML_EXAMPLE_CODE_STYLE HTML_CODE_BLOCK_STYLE(HTML_EXAMPLE_BACK) - -#define HTML_DOC_HEAD_OPEN "
" -#define HTML_DOC_HEAD_CLOSE "
" - -#define HTML_DOC_ITEM_HEAD_STYLE "font-weight: 600;" - -#define HTML_DOC_ITEM_HEAD_INL_OPEN "" -#define HTML_DOC_ITEM_HEAD_INL_CLOSE "" - -#define HTML_DOC_ITEM_HEAD_OPEN "
" -#define HTML_DOC_ITEM_HEAD_CLOSE "
" - -#define HTML_DOC_ITEM_OPEN "
" -#define HTML_DOC_ITEM_CLOSE "
" - -#define HTML_EXAMPLE_CODE_OPEN "
" -#define HTML_EXAMPLE_CODE_CLOSE "
" - -struct Section_Counter{ - i32 counter[16]; - i32 nest_level; - i32 list_item_counter; -}; - -internal b32 -doc_get_link_string(Abstract_Item *doc, char *space, i32 capacity){ - String str = make_string_cap(space, 0, capacity); - append(&str, doc->name); - append(&str, ".html"); - b32 result = terminate_with_null(&str); - return(result); -} - -internal b32 -img_get_link_string(Abstract_Item *img, char *space, i32 capacity, i32 w, i32 h){ - String str = make_string_cap(space, 0, capacity); - append(&str, img->name); - - append(&str, "_"); - append_int_to_str(&str, w); - append(&str, "_"); - append_int_to_str(&str, h); - - append(&str, "."); - append(&str, img->extension); - b32 result = terminate_with_null(&str); - return(result); -} - -internal void -append_section_number_reduced(String *out, Section_Counter *section_counter, i32 reduce){ - i32 level = section_counter->nest_level - reduce; - for (i32 i = 0; i <= level; ++i){ - append_int_to_str(out, section_counter->counter[i]); - if (i != level){ - append(out, "."); - } - } -} - -internal void -append_section_number(String *out, Section_Counter *section_counter){ - append_section_number_reduced(out, section_counter, 0); -} - -#define ERROR_HTML_START "! generator error: " -#define ERROR_HTML_END " !" - -internal void -output_error(String *out, String error){ - append(out, ERROR_HTML_START); - append(out, error); - append(out, ERROR_HTML_END); - fprintf(stdout, "error: %.*s\n", error.size, error.str); -} - -internal void -report_error_html_missing_body(String *out, String command_name){ - char space[512]; - String str = make_fixed_width_string(space); - append(&str, "missing body for "); - append(&str, command_name); - output_error(out, str); -} - -internal void -html_render_section_header(String *out, String section_name, String section_id, Section_Counter *section_counter){ - if (section_counter->nest_level <= 1){ - if (section_id.size > 0){ - append(out, "\n

§"); - } - else{ - append(out, "\n

§"); - } - append_section_number(out, section_counter); - append(out, " "); - append(out, section_name); - append(out, "

"); - } - else{ - if (section_id.size > 0){ - append(out, "

§"); - } - else{ - append(out, "

§"); - } - append_section_number(out, section_counter); - append(out, " "); - append(out, section_name); - append(out, "

"); - } -} - -#define HTML_WIDTH 800 - -internal void -output_plain_old_text(String *out, String l){ - u32 start = 0; - u32 i = 0; - for (; i < (u32)l.size; ++i){ - char ch = l.str[i]; - switch (ch){ - case '<': - { - append(out, substr(l, start, i - start)); - append(out, "<"); - start = i + 1; - }break; - - case '>': - { - append(out, substr(l, start, i - start)); - append(out, ">"); - start = i + 1; - }break; - } - } - if (start != i){ - append(out, substr(l, start, i - start)); - } -} - -internal void -output_begin_style(String *out, String l){ - if (match(l, "code")){ - append(out, ""); - } - else{ - fprintf(stdout, "error: unrecognized style\n"); - append(out, ""); - } -} - -internal void -output_end_style(String *out){ - append(out, ""); -} - -internal void -output_document_link(String *out, String l){ - append(out, ""); - append(out, l); - append(out, ""); -} - -internal void -output_begin_link(Document_System *doc_system, String *out, String l){ - append(out, ""); -} - -internal void -output_end_link(String *out){ - append(out, ""); -} - -internal void -output_image(Partition *arena, Document_System *doc_system, String *out, String l, String l2){ - i32 pixel_height = 10; - i32 pixel_width = HTML_WIDTH; - - if (l2.size > 0){ - if (match_part(l2, "width:")){ - String width_string = substr_tail(l2, sizeof("width:")-1); - if (str_is_int(width_string)){ - pixel_width = str_to_int(width_string); - } - } - } - - if (match_part(l, "image:")){ - String img_name = substr_tail(l, sizeof("image:")-1); - Abstract_Item *img_lookup = get_item_by_name(doc_system->img_list, img_name); - - if (img_lookup){ - pixel_height = ceil32(pixel_width*img_lookup->h_w_ratio); - - append(out, ""); - } - } -} - -internal void -output_video(String *out, String l){ - if (match_part(l, "youtube:")){ - i32 pixel_width = HTML_WIDTH; - i32 pixel_height = (i32)(pixel_width * 0.5625f); - - String youtube_str = substr_tail(l, sizeof("youtube:")-1); - - append(out, ""); - } - else{ - char space[512]; - String str = make_fixed_width_string(space); - append(&str, "unrecognized video type "); - append(&str, l); - output_error(out, str); - } -} - -internal void -output_begin_paragraph(String *out){ - append(out, "

"); -} - -internal void -output_end_paragraph(String *out){ - append(out, "

"); -} - -internal void -output_begin_list(String *out){ - append(out,"
    "); -} - -internal void -output_end_list(String *out){ - append(out, "
"); -} - -internal void -output_begin_item(String *out, Section_Counter *section_counter){ - if (section_counter->list_item_counter == 0){ - append(out, "
  • "); - section_counter->list_item_counter = 1; - } - else{ - append(out, "
  • "); - section_counter->list_item_counter = 0; - } -} - -internal void -output_end_item(String *out){ - append(out, "
  • "); -} - -internal void -print_item_in_list(String *out, String name, char *id_postfix){ - append(out, "
  • "); - append(out, name); - append(out, "
  • "); -} - -internal void -init_used_links(Partition *arena, Used_Links *used, i32 count){ - used->strs = push_array(arena, String, count); - used->count = 0; - used->max = count; -} - -internal b32 -try_to_use_link(Used_Links *used, String str){ - b32 result = true; - i32 index = 0; - if (string_set_match(used->strs, used->count, str, &index)){ - result = false; - } - else{ - Assert(used->count < used->max); - used->strs[used->count++] = str; - } - return(result); -} - -internal void -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; - - append (out, type); - append_s_char (out, ' '); - append (out, name); - append (out, type_postfix); - - if (match_ss(type, make_lit_string("struct")) || - match_ss(type, make_lit_string("union"))){ - - if (hide_children){ - append(out, " { /* non-public internals */ } ;"); - } - else{ - append(out, " {
    "); - - for (Item_Node *member_iter = member->first_child; - member_iter != 0; - member_iter = member_iter->next_sibling){ - print_struct_html(out, member_iter, hide_children); - } - - append(out, "
    };
    "); - } - } - else{ - append(out, ";
    "); - } -} - -internal void -print_function_html(String *out, Used_Links *used, String cpp_name, String ret, char *function_call_head, String name, Argument_Breakdown breakdown){ - - append (out, ret); - append_s_char (out, ' '); - append (out, function_call_head); - append (out, name); - - if (breakdown.count == 0){ - append(out, "()"); - } - else if (breakdown.count == 1){ - append(out, "("); - append(out, breakdown.args[0].param_string); - append(out, ")"); - } - else{ - append(out, "(
    "); - - for (i32 j = 0; j < breakdown.count; ++j){ - append(out, breakdown.args[j].param_string); - if (j < breakdown.count - 1){ - append_s_char(out, ','); - } - append(out, "
    "); - } - - append(out, "
    )"); - } -} - -internal void -print_macro_html(String *out, String name, Argument_Breakdown breakdown){ - - append (out, "#define "); - append (out, name); - - if (breakdown.count == 0){ - append(out, "()"); - } - else if (breakdown.count == 1){ - append_s_char (out, '('); - append (out, breakdown.args[0].param_string); - append_s_char (out, ')'); - } - else{ - append (out, "(
    "); - - for (i32 j = 0; j < breakdown.count; ++j){ - append(out, breakdown.args[j].param_string); - if (j < breakdown.count - 1){ - append_s_char(out, ','); - } - append(out, "
    "); - } - - append(out, ")
    )"); - } -} - -enum Doc_Chunk_Type{ - DocChunk_PlainText, - DocChunk_CodeExample, - - DocChunk_Count -}; - -global String doc_chunk_headers[] = { - make_lit_string(""), - make_lit_string("CODE_EXAMPLE"), -}; - -internal String -get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){ - String chunk = {}; - String word = {}; - i32 pos = source.size; - i32 word_index = 0; - Doc_Chunk_Type t = DocChunk_PlainText; - - 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)); - - for (word = get_first_word(source_tail); - word.str; - word = get_next_word(source_tail, word), ++word_index){ - - for (i32 i = 1; i < DocChunk_Count; ++i){ - if (match_ss(word, doc_chunk_headers[i])){ - pos = (i32)(word.str - source.str); - t = (Doc_Chunk_Type)i; - goto doublebreak; - } - } - } - doublebreak:; - - *type = DocChunk_PlainText; - if (word_index == 0){ - *type = t; - - i32 nest_level = 1; - i32 i = find_s_char(source, pos, '('); - for (++i; i < source.size; ++i){ - if (source.str[i] == '('){ - ++nest_level; - } - else if (source.str[i] == ')'){ - --nest_level; - if (nest_level == 0){ - break; - } - } - } - - pos = i+1; - } - - chunk = substr(source, start_pos, pos - start_pos); - - 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; - } - } - - if (is_all_white){ - chunk = null_string; - } - - return(chunk); -} - -internal String -get_first_doc_chunk(String source, Doc_Chunk_Type *type){ - String start_str = make_string(source.str, 0); - String chunk = get_next_doc_chunk(source, start_str, type); - return(chunk); -} - -internal void -print_doc_description(String *out, String src){ - Doc_Chunk_Type type; - - for (String chunk = get_first_doc_chunk(src, &type); - chunk.str; - chunk = get_next_doc_chunk(src, chunk, &type)){ - - switch (type){ - case DocChunk_PlainText: - { - for (String line = get_first_double_line(chunk); - line.str; - line = get_next_double_line(chunk, line)){ - append(out, line); - append(out, "

    "); - } - }break; - - case DocChunk_CodeExample: - { - i32 start = 0; - i32 end = chunk.size-1; - while (start < end && chunk.str[start] != '(') ++start; - start += 1; - while (end > start && chunk.str[end] != ')') --end; - - - append(out, HTML_EXAMPLE_CODE_OPEN); - - if (start < end){ - String code_example = substr(chunk, start, end - start); - 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)){ - i32 space_i = 0; - for (; space_i < line.size; ++space_i){ - if (line.str[space_i] == ' '){ - append(out, " "); - } - else{ - break; - } - } - - String line_tail = substr_tail(line, space_i); - append(out, line_tail); - append(out, "
    "); - } - first_line = 0; - } - } - - append(out, HTML_EXAMPLE_CODE_CLOSE); - }break; - } - } -} - -internal void -print_struct_docs(Partition *arena, String *out, Item_Node *member){ - for (Item_Node *member_iter = member->first_child; - member_iter != 0; - member_iter = member_iter->next_sibling){ - String type = member_iter->type; - if (match_ss(type, make_lit_string("struct")) || - match_ss(type, make_lit_string("union"))){ - print_struct_docs(arena, out, member_iter); - } - else{ - Documentation doc = {}; - perform_doc_parse(arena, member_iter->doc_string, &doc); - - append(out, "
    "); - - append(out, "
    "HTML_DOC_ITEM_HEAD_INL_OPEN); - append(out, member_iter->name); - append(out, HTML_DOC_ITEM_HEAD_INL_CLOSE"
    "); - - append(out, "
    "HTML_DOC_ITEM_OPEN); - print_doc_description(out, doc.main_doc); - append(out, HTML_DOC_ITEM_CLOSE"
    "); - - append(out, "
    "); - } - } -} - -internal void -print_see_also(String *out, Documentation *doc){ - i32 doc_see_count = doc->see_also_count; - if (doc_see_count > 0){ - append(out, HTML_DOC_HEAD_OPEN"See Also"HTML_DOC_HEAD_CLOSE); - - for (i32 j = 0; j < doc_see_count; ++j){ - String see_also = doc->see_also[j]; - append(out, HTML_DOC_ITEM_OPEN""); - append(out, see_also); - append(out, ""HTML_DOC_ITEM_CLOSE); - } - } -} - -internal void -print_function_docs(Partition *arena, String *out, String name, String doc_string){ - if (doc_string.size == 0){ - append(out, "No documentation generated for this function."); - fprintf(stdout, "warning: no documentation string for %.*s\n", name.size, name.str); - } - - Temp_Memory temp = begin_temp_memory(arena); - - Documentation doc = {}; - - perform_doc_parse(arena, doc_string, &doc); - - i32 doc_param_count = doc.param_count; - if (doc_param_count > 0){ - append(out, HTML_DOC_HEAD_OPEN"Parameters"HTML_DOC_HEAD_CLOSE); - - for (i32 j = 0; j < doc_param_count; ++j){ - String param_name = doc.param_name[j]; - String param_docs = doc.param_docs[j]; - - // TODO(allen): check that param_name is actually a parameter to this function! - - append(out, "
    "HTML_DOC_ITEM_HEAD_OPEN); - append(out, param_name); - append(out, HTML_DOC_ITEM_HEAD_CLOSE"
    "HTML_DOC_ITEM_OPEN); - append(out, param_docs); - append(out, HTML_DOC_ITEM_CLOSE"
    "); - } - } - - String ret_doc = doc.return_doc; - if (ret_doc.size != 0){ - append(out, HTML_DOC_HEAD_OPEN"Return"HTML_DOC_HEAD_CLOSE HTML_DOC_ITEM_OPEN); - append(out, ret_doc); - append(out, HTML_DOC_ITEM_CLOSE); - } - - String main_doc = doc.main_doc; - if (main_doc.size != 0){ - append(out, HTML_DOC_HEAD_OPEN"Description"HTML_DOC_HEAD_CLOSE HTML_DOC_ITEM_OPEN); - print_doc_description(out, main_doc); - append(out, HTML_DOC_ITEM_CLOSE); - } - - print_see_also(out, &doc); - - end_temp_memory(temp); -} - -internal void -print_item_html(Partition *arena, String *out, Used_Links *used, Item_Node *item, char *id_postfix, char *section, i32 I, u32 mangle_rule){ - Temp_Memory temp = begin_temp_memory(arena); - - String name = apply_mangle_rule(arena, item->name, mangle_rule); - - /* NOTE(allen): - Open a div for the whole item. - Put a heading in it with the name and section. - Open a "descriptive" box for the display of the code interface. - */ - append(out, "
    "); - - i32 has_cpp_name = 0; - if (item->cpp_name.str != 0){ - if (try_to_use_link(used, item->cpp_name)){ - append(out, "
    "); - has_cpp_name = 1; - } - } - - append (out, "

    §"); - append (out, section); - append_s_char (out, '.'); - append_int_to_str (out, I); - append (out, ": "); - append (out, name); - append (out, "

    "); - - append(out, "
    "); - - switch (item->t){ - case Item_Function: - { - // NOTE(allen): Code box - print_function_html(out, used, item->cpp_name, item->ret, "", name, item->breakdown); - - // NOTE(allen): Close the code box - append(out, "
    "); - - // NOTE(allen): Descriptive section - print_function_docs(arena, out, name, item->doc_string); - }break; - - case Item_Macro: - { - // NOTE(allen): Code box - print_macro_html(out, name, item->breakdown); - - // NOTE(allen): Close the code box - append(out, "
    "); - - // NOTE(allen): Descriptive section - print_function_docs(arena, out, name, item->doc_string); - }break; - - case Item_Typedef: - { - String type = item->type; - - // NOTE(allen): Code box - append (out, "typedef "); - append (out, type); - append_s_char (out, ' '); - append (out, name); - append_s_char (out, ';'); - - // NOTE(allen): Close the code box - append(out, "
    "); - - // NOTE(allen): Descriptive section - String doc_string = item->doc_string; - Documentation doc = {}; - perform_doc_parse(arena, doc_string, &doc); - - String main_doc = doc.main_doc; - if (main_doc.size != 0){ - append(out, HTML_DOC_HEAD_OPEN"Description"HTML_DOC_HEAD_CLOSE); - - append(out, HTML_DOC_ITEM_OPEN); - print_doc_description(out, main_doc); - append(out, HTML_DOC_ITEM_CLOSE); - } - else{ - fprintf(stdout, "warning: no documentation string for %.*s\n", name.size, name.str); - } - - print_see_also(out, &doc); - - }break; - - case Item_Enum: - { - // NOTE(allen): Code box - append (out, "enum "); - append (out, name); - append_s_char (out, ';'); - - // NOTE(allen): Close the code box - append(out, ""); - - // NOTE(allen): Descriptive section - String doc_string = item->doc_string; - Documentation doc = {}; - perform_doc_parse(arena, doc_string, &doc); - - String main_doc = doc.main_doc; - if (main_doc.size != 0){ - append(out, HTML_DOC_HEAD_OPEN"Description"HTML_DOC_HEAD_CLOSE); - - append(out, HTML_DOC_ITEM_OPEN); - print_doc_description(out, main_doc); - append(out, HTML_DOC_ITEM_CLOSE); - } - else{ - fprintf(stdout, "warning: no documentation string for %.*s\n", name.size, name.str); - } - - if (item->first_child){ - append(out, HTML_DOC_HEAD_OPEN"Values"HTML_DOC_HEAD_CLOSE); - - for (Item_Node *member = item->first_child; - member; - member = member->next_sibling){ - Documentation doc = {}; - perform_doc_parse(arena, member->doc_string, &doc); - - append(out, "
    "); - - // NOTE(allen): Dafuq is this all? - append(out, "
    "HTML_DOC_ITEM_HEAD_INL_OPEN); - append(out, member->name); - append(out, HTML_DOC_ITEM_HEAD_INL_CLOSE); - - if (member->value.str){ - append(out, " = "); - append(out, member->value); - } - - append(out, "
    "); - - append(out, "
    "HTML_DOC_ITEM_OPEN); - print_doc_description(out, doc.main_doc); - append(out, HTML_DOC_ITEM_CLOSE"
    "); - - append(out, "
    "); - } - } - - print_see_also(out, &doc); - - }break; - - case Item_Struct: case Item_Union: - { - String doc_string = item->doc_string; - - i32 hide_members = 0; - - if (doc_string.size == 0){ - hide_members = 1; - } - else{ - for (String word = get_first_word(doc_string); - word.str; - word = get_next_word(doc_string, word)){ - if (match_ss(word, make_lit_string("HIDE_MEMBERS"))){ - hide_members = 1; - break; - } - } - } - - // NOTE(allen): Code box - print_struct_html(out, item, hide_members); - - // NOTE(allen): Close the code box - append(out, ""); - - // NOTE(allen): Descriptive section - { - Documentation doc = {}; - perform_doc_parse(arena, doc_string, &doc); - - String main_doc = doc.main_doc; - if (main_doc.size != 0){ - append(out, HTML_DOC_HEAD_OPEN"Description"HTML_DOC_HEAD_CLOSE); - - append(out, HTML_DOC_ITEM_OPEN); - print_doc_description(out, main_doc); - append(out, HTML_DOC_ITEM_CLOSE); - } - else{ - fprintf(stdout, "warning: no documentation string for %.*s\n", name.size, name.str); - } - - if (!hide_members){ - if (item->first_child){ - append(out, HTML_DOC_HEAD_OPEN"Fields"HTML_DOC_HEAD_CLOSE); - print_struct_docs(arena, out, item); - } - } - - print_see_also(out, &doc); - } - }break; - } - - if (has_cpp_name){ - append(out, ""); - } - - // NOTE(allen): Close the item box - append(out, "
    "); - - end_temp_memory(temp); -} - -global char* html_css = -""; - -struct Include_Stack{ - Abstract_Item *stack[512]; - u32 top; -}; - -struct Document_Output_System{ - String *out; - Document_System *doc_system; - Used_Links *used_links; - Section_Counter *section_counter; - Include_Stack *inc_stack; -}; - -internal Document_Output_System -make_output_system(String *out, Document_System *doc_system, Used_Links *used_links, Section_Counter *section_counter, Include_Stack *inc_stack){ - Document_Output_System sys = {}; - sys.out = out; - sys.doc_system = doc_system; - sys.used_links = used_links; - sys.section_counter = section_counter; - sys.inc_stack = inc_stack; - return(sys); -} - -internal void -doc_item_html(Partition *arena, Document_Output_System sys, Document_Item *item, b32 head){ - switch (item->type){ - case Doc_Root: - { - if (head){ - append(sys.out, - "" - "" - "" - ""); - append(sys.out, item->section.name); - append(sys.out, ""); - - append(sys.out, html_css); - - append(sys.out, - "\n" - "" - "
    "); - - if (item->section.show_title){ - append(sys.out, "

    "); - append(sys.out, item->section.name); - append(sys.out, "

    "); - } - } - else{ - append(sys.out, "
    "); - } - }break; - - case Doc_Section: - { - if (head){ - html_render_section_header(sys.out, item->section.name, item->section.id, sys.section_counter); - } - }break; - - case Doc_Error: - { - if (head){ - output_error(sys.out, item->string.string); - } - }break; - - case Doc_Todo: - { - if (head){ - append(sys.out, "
    Coming Soon
    "); - } - }break; - - case Doc_Include: - { - // NOTE(allen): Do nothing. - }break; - - - case Doc_DocFull: - case Doc_DocList: - { - if (head){ - Mangle_Rule mangle_rule = item->unit_elements.mangle_rule; - String name = item->unit_elements.unit; - - Abstract_Item *unit_item = get_item_by_name(sys.doc_system->meta_list, name); - Meta_Unit *unit = unit_item->unit; - i32 count = unit->set.count; - - if (item->type == Doc_DocList){ - append(sys.out, "
      "); - - for (i32 i = 0; i < count; ++i){ - String name = apply_mangle_rule(arena, unit->set.items[i].name, mangle_rule); - print_item_in_list(sys.out, name, "_doc"); - } - - append(sys.out, "
    "); - } - else{ - char section_space[32]; - String section_str = make_fixed_width_string(section_space); - append_section_number_reduced(§ion_str, sys.section_counter, 1); - terminate_with_null(§ion_str); - - i32 I = 1; - for (i32 i = 0; i < count; ++i, ++I){ - print_item_html(arena, sys.out, sys.used_links, &unit->set.items[i], "_doc", section_str.str, I, mangle_rule); - } - } - } - }break; - - case Doc_TableOfContents: - { - if (head){ - append(sys.out, "

    Table of Contents

    "); - } - }break; - - case Doc_PlainOldText: - { - if (head){ - output_plain_old_text(sys.out, item->string.string); - } - }break; - - case Doc_Version: - { - if (head){ - append(sys.out, VERSION); - } - }break; - - case Doc_Style: - { - if (head){ - output_begin_style(sys.out, item->string.string); - } - else{ - output_end_style(sys.out); - } - }break; - - case Doc_DocumentLink: - { - if (head){ - output_document_link(sys.out, item->string.string); - } - }break; - - case Doc_Link: - { - if (head){ - output_begin_link(sys.doc_system, sys.out, item->string.string); - } - else{ - output_end_link(sys.out); - } - }break; - - case Doc_Image: - { - if (head){ - output_image(arena, sys.doc_system, sys.out, item->string.string, item->string.string2); - } - }break; - - case Doc_Video: - { - if (head){ - output_video(sys.out, item->string.string); - } - }break; - - case Doc_BeginParagraph: - { - if (head){ - output_begin_paragraph(sys.out); - } - }break; - - case Doc_EndParagraph: - { - if (head){ - output_end_paragraph(sys.out); - } - }break; - - case Doc_List: - { - if (head){ - output_begin_list(sys.out); - } - else{ - output_end_list(sys.out); - } - }break; - - case Doc_Item: - { - if (head){ - output_begin_item(sys.out, sys.section_counter); - } - else{ - output_end_item(sys.out); - } - }break; - } -} - -internal void -generate_document_html_inner(Partition *arena, Document_Output_System sys, Abstract_Item *doc); - -internal void -generate_item_html(Partition *arena, Document_Output_System sys, Document_Item *item){ - doc_item_html(arena, sys, item, true); - - if (item->section.first_child != 0){ - if (item->type == Doc_Section){ - i32 level = ++sys.section_counter->nest_level; - sys.section_counter->counter[level] = 1; - sys.section_counter->list_item_counter = 0; - } - - for (Document_Item *m = item->section.first_child; - m != 0; - m = m->next){ - generate_item_html(arena, sys, m); - } - - if (item->type == Doc_Section){ - --sys.section_counter->nest_level; - ++sys.section_counter->counter[sys.section_counter->nest_level]; - } - } - - if (item->type == Doc_Include){ - Abstract_Item *new_doc = item->include.document; - if (new_doc != 0){ - b32 duplicate = false; - for (u32 i = 0; i < sys.inc_stack->top; ++i){ - if (sys.inc_stack->stack[i] == new_doc){ - duplicate = true; - break; - } - } - - if (duplicate){ - String error = make_lit_string("recursive inclusion, halted here"); - Document_Item temp_item = {}; - temp_item.type = Doc_Error; - set_item_string(arena, &temp_item.string.string, error); - generate_item_html(arena, sys, &temp_item); - } - else{ - generate_document_html_inner(arena, sys, new_doc); - } - } - } - - doc_item_html(arena, sys, item, false); -} - -internal void -generate_document_html_inner(Partition *arena, Document_Output_System sys, Abstract_Item *doc){ - Assert(sys.inc_stack->top < ArrayCount(sys.inc_stack->stack)); - sys.inc_stack->stack[sys.inc_stack->top++] = doc; - generate_item_html(arena, sys, doc->root_item); - --sys.inc_stack->top; -} - -internal void -generate_document_html(Partition *arena, String *out, Document_System *doc_system, Abstract_Item *doc){ - Assert(doc->root_item != 0); - - Used_Links used_links = {}; - init_used_links(arena, &used_links, 4000); - - Section_Counter section_counter = {}; - section_counter.counter[section_counter.nest_level] = 1; - - Include_Stack inc_stack = {}; - - Document_Output_System sys = make_output_system(out, doc_system, &used_links, §ion_counter, &inc_stack); - - generate_document_html_inner(arena, sys, doc); -} - -// BOTTOM - diff --git a/site/4ed_sitegen.cpp b/site/4ed_sitegen.cpp deleted file mode 100644 index 8437cec7..00000000 --- a/site/4ed_sitegen.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 25.02.2016 - * - * Site generator for 4coder. - * - */ - -// TOP - -#define STB_IMAGE_IMPLEMENTATION -#include "stb_image.h" -#define STB_IMAGE_RESIZE_IMPLEMENTATION -#include "stb_image_resize.h" -#define STB_IMAGE_WRITE_IMPLEMENTATION -#include "stb_image_write.h" - -#include -#include -#include - -#include "../4ed_defines.h" -#include "../meta/4ed_meta_defines.h" - -#include "../4coder_API/4coder_version.h" -#include "4coder_lib/4coder_arena.h" -#include "4coder_lib/4coder_arena.cpp" -#define FSTRING_IMPLEMENTATION -#include "../4coder_lib/4coder_string.h" -#include "../4coder_lib/4cpp_lexer.h" - -#define FTECH_FILE_MOVING_IMPLEMENTATION -#include "../meta/4ed_file_moving.h" -#include "../meta/4ed_meta_parser.cpp" -#include "../meta/4ed_meta_keywords.h" -#include "4ed_abstract_document.cpp" - -#include "../4coder_generated/command_metadata.h" -#include "../4coder_generated/remapping.h" -#include "../4coder_API/4coder_keycodes.h" - -/////////////////////////////////////////////////////////////////////////// - -internal void -copy_and_fix_name(char *src, char *dst, int32_t cap){ - String s = make_string_cap(dst, 0, cap); - copy(&s, src); - replace_char(&s, '_', '-'); - terminate_with_null(&s); -} - -enum{ - MDFR_NONE = 0x0, - MDFR_CTRL = 0x1, - MDFR_ALT = 0x2, - MDFR_CMND = 0x4, - MDFR_SHIFT = 0x8, -}; - -internal void -generate_binding_list(char *code_directory, char *src_directory){ - char full_path[512]; - String s = make_fixed_width_string(full_path); - append(&s, src_directory); - if (s.size == 0 || !char_is_slash(s.str[s.size - 1])){ - append(&s, "/"); - } - append(&s, "binding_list.txt"); - terminate_with_null(&s); - - FILE *out = fopen(full_path, "wb"); - if (out == 0){ - fprintf(stdout, "could not open binding_list.txt for auto synchronized binding info\n"); - return; - } - - fprintf(out, "\n\\INCLUDE{site_header.txt}\n"); - fprintf(out, "\n4coder version \\VERSION\n"); - - fprintf(out, "\n\\SECTION{Built in Bindings}\n"); - for (i32 i = 0; i < ArrayCount(fcoder_meta_maps); ++i){ - Meta_Mapping *mapping = &fcoder_meta_maps[i]; - - char s[512]; - copy_and_fix_name(mapping->name, s, sizeof(s)); - fprintf(out, "\\ITEM \\STYLE{code} \"%s\" \\END %s\n", s, mapping->description); - } - fprintf(out, "\\END\n"); - - for (i32 i = 0; i < ArrayCount(fcoder_meta_maps); ++i){ - Meta_Mapping *mapping = &fcoder_meta_maps[i]; - - char s[512]; - copy_and_fix_name(mapping->name, s, sizeof(s)); - fprintf(out, "\\SECTION{Map: %s}\n", s); - - for (i32 j = 0; j < mapping->sub_map_count; ++j){ - Meta_Sub_Map *sub_map = &mapping->sub_maps[j]; - - char sub_s[512]; - copy_and_fix_name(sub_map->name, sub_s, sizeof(sub_s)); - fprintf(out, "\\SECTION{%s}\n", sub_s); - fprintf(out, "%s\n", sub_map->description); - fprintf(out, "\\LIST\n", sub_map->description); - - for (i32 k = 0; k < sub_map->bind_count; ++k){ - Meta_Key_Bind *bind = &sub_map->binds[k]; - - // Get modifier key string - char mdfr_str[256]; - String m = make_fixed_width_string(mdfr_str); - b32 has_base = false; - - if (bind->modifiers & MDFR_CTRL){ - if (has_base){ - append(&m, "+"); - } - append(&m, "ctrl"); - } - if (bind->modifiers & MDFR_ALT){ - if (has_base){ - append(&m, "+"); - } - append(&m, "alt"); - } - if (bind->modifiers & MDFR_CMND){ - if (has_base){ - append(&m, "+"); - } - append(&m, "cmnd"); - } - if (bind->modifiers & MDFR_SHIFT){ - if (has_base){ - append(&m, "+"); - } - append(&m, "shift"); - } - if (bind->modifiers != 0){ - append(&m, " "); - } - terminate_with_null(&m); - - // Get printable key string - char key_str_space[2]; - char *key_str = 0; - - if (bind->vanilla){ - key_str = "any character"; - } - else{ - switch (bind->keycode){ - case key_back: key_str = "backspace"; break; - case key_up: key_str = "up"; break; - case key_down: key_str = "down"; break; - case key_left: key_str = "left"; break; - case key_right: key_str = "right"; break; - case key_del: key_str = "delete"; break; - case key_insert: key_str = "insert"; break; - case key_home: key_str = "home"; break; - case key_end: key_str = "end"; break; - case key_page_up: key_str = "page up"; break; - case key_page_down: key_str = "page down"; break; - case key_esc: key_str = "escape"; break; - case key_mouse_left: key_str = "left click"; break; - case key_mouse_right: key_str = "right click"; break; - case key_mouse_left_release: key_str = "left release"; break; - case key_mouse_right_release: key_str = "right release"; break; - case key_mouse_wheel: key_str = "mouse wheel"; break; - case key_mouse_move: key_str = "mouse move"; break; - case key_animate: key_str = "animate"; break; - case key_click_activate_view: key_str = "click_activate_view"; break; - case key_click_deactivate_view: key_str = "click_deactivate_view"; break; - case key_f1: key_str = "f1"; break; - case key_f2: key_str = "f2"; break; - case key_f3: key_str = "f3"; break; - case key_f4: key_str = "f4"; break; - case key_f5: key_str = "f5"; break; - case key_f6: key_str = "f6"; break; - case key_f7: key_str = "f7"; break; - case key_f8: key_str = "f8"; break; - case key_f9: key_str = "f9"; break; - case key_f10: key_str = "f10"; break; - case key_f11: key_str = "f11"; break; - case key_f12: key_str = "f12"; break; - case key_f13: key_str = "f13"; break; - case key_f14: key_str = "f14"; break; - case key_f15: key_str = "f15"; break; - case key_f16: key_str = "f16"; break; - - default: - { - if (bind->keycode == '\n'){ - key_str = "return"; - } - else if (bind->keycode == '\t'){ - key_str = "tab"; - } - else if (bind->keycode == ' '){ - key_str = "space"; - } - else{ - Assert(bind->keycode <= 127); - key_str = key_str_space; - key_str_space[0] = (char)bind->keycode; - key_str_space[1] = 0; - } - }break; - } - } - - // Get description from doc string - char *description = "description missing"; - char *command = bind->command; - for (i32 i = 0; i < command_one_past_last_id; ++i){ - Command_Metadata *metadata = command_metadata_by_id(i); - if (match(metadata->name, command)){ - description = metadata->description; - break; - } - } - - fprintf(out, "\\ITEM \\STYLE{code} <%s%s> \\END %s\n", - mdfr_str, key_str, - description); - } - - fprintf(out, "\\END\n"); - fprintf(out, "\\END\n"); - } - - fprintf(out, "\\END\n"); - } - - fclose(out); -} - -// -// Meta Parse Rules -// - -internal Abstract_Item* -generate_page(Partition *arena, Document_System *doc_system, char *source_text, char *big_title, char *small_name){ - Enriched_Text *home = push_array(arena, Enriched_Text, 1); - *home = load_enriched_text(arena, doc_system->src_dir, source_text); - - Abstract_Item *doc = make_document_from_text(arena, doc_system, big_title, small_name, home); - if (doc == 0){ - fprintf(stdout, "warning: could not create document %s from file %s\n", small_name, source_text); - } - - return(doc); -} - -internal void -do_image_resize(Partition *arena, char *src_file, char *dst_file, char *extension, i32 w, i32 h){ - Temp_Memory temp = begin_temp_memory(arena); - - i32 x = 0, y = 0, channels = 0; - stbi_uc *image = stbi_load(src_file, &x, &y, &channels, 0); - if (image != 0){ - stbi_uc *resized_image = push_array(arena, stbi_uc, w*h*channels); - stbir_resize_uint8(image, x, y, x*channels, resized_image, w, h, w*channels, channels); - if (match_cc(extension, "png")){ - stbi_write_png(dst_file, w, h, channels, resized_image, w*channels); - } - free(image); - } - - end_temp_memory(temp); -} - -internal void -generate_site(Partition *arena, char *code_directory, char *asset_directory, char *src_directory, char *dst_directory){ - fm_clear_folder(dst_directory); - - Document_System doc_system = create_document_system(code_directory, asset_directory, src_directory); - Document_System *docs = &doc_system; - - // TODO(allen): Declare these in the source files. - add_image_description(arena, docs, "4coder_logo_low_green.png", "png", "4coder_logo" ); - add_image_description(arena, docs, "screen_1.png", "png", "screen_1" ); - add_image_description(arena, docs, "screen_2.png", "png", "screen_2" ); - add_image_description(arena, docs, "screen_3.png", "png", "screen_3" ); - add_generic_file (arena, docs, "4coder_icon.ico", "ico", "4coder_icon" ); - - // TODO(allen): From the text file get "Big Title" and "smallname". - generate_page(arena, docs, "docs.txt" , "4coder API Docs" , "custom_docs" ); - generate_page(arena, docs, "home.txt" , "4coder Home" , "home" ); - generate_page(arena, docs, "feature_list.txt", "4coder Feature List", "features" ); - generate_page(arena, docs, "binding_list.txt", "4coder Binding List", "bindings" ); - generate_page(arena, docs, "roadmap.txt" , "4coder Roadmap" , "roadmap" ); - generate_page(arena, docs, "tutorials.txt" , "4coder Tutorials" , "tutorials" ); - - // NOTE(allen): Create a list of the primary documents to generate. - Abstract_Item_Array original_documents = get_abstract_item_array(arena, &doc_system.doc_list); - - // NOTE(allen): Cross link all the includes and pull in any non-primary documents. - resolve_all_includes(arena, &doc_system); - - // NOTE(allen): Generate the html from the primary documents and publish them. - String out = make_string_cap(push_array(arena, char, 10 << 20), 0, 10 << 20); - Assert(out.str != 0); - - Abstract_Item **doc_ptr = original_documents.items; - for (u32 j = 0; j < original_documents.count; ++j, ++doc_ptr){ - Abstract_Item *doc = *doc_ptr; - Assert(doc->item_type == ItemType_Document); - - char doc_link[256]; - if (doc_get_link_string(doc, doc_link, sizeof(doc_link))){ - generate_document_html(arena, &out, &doc_system, doc); - - char *name = fm_str(arena, dst_directory, "/", doc_link); - fm_write_file(name, out.str, out.size); - out.size = 0; - } - } - - // NOTE(allen): Publish files - for (Basic_Node *node = doc_system.file_list.head; - node != 0; - node = node->next){ - Abstract_Item *file = NodeGetData(node, Abstract_Item); - Assert(file->item_type == ItemType_GenericFile); - char *file_name = fm_str(arena, file->name, ".", file->extension); - fm_copy_file(fm_str(arena, file_name), fm_str(arena, dst_directory, "/", file_name)); - } - - // NOTE(allen): Publish images - for (Basic_Node *node = doc_system.img_list.head; - node != 0; - node = node->next){ - Abstract_Item *img = NodeGetData(node, Abstract_Item); - Assert(img->item_type == ItemType_Image); - - for (Basic_Node *node = img->img_instantiations.head; - node != 0; - node = node->next){ - Image_Instantiation *inst = NodeGetData(node, Image_Instantiation); - - char img_link[256]; - if (img_get_link_string(img, img_link, sizeof(img_link), inst->w, inst->h)){ - char *dest_file = fm_str(arena, dst_directory, "/", img_link); - do_image_resize(arena, img->source_file, dest_file, img->extension, inst->w, inst->h); - } - } - } -} - -int main(int argc, char **argv){ - META_BEGIN(); - - if (argc == 5){ - Partition arena = fm_init_system(); - - char *code_directory = argv[1]; - char *asset_directory = argv[2]; - char *src_directory = argv[3]; - char *dst_directory = argv[4]; - generate_binding_list(code_directory, src_directory); - generate_site(&arena, code_directory, asset_directory, src_directory, dst_directory); - } - - META_FINISH(); -} - -// BOTTOM - diff --git a/site/source_material/binding_list.txt b/site/source_material/binding_list.txt deleted file mode 100644 index 986d75e0..00000000 --- a/site/source_material/binding_list.txt +++ /dev/null @@ -1,22 +0,0 @@ - -\INCLUDE{site_header.txt} - -4coder version \VERSION - -\SECTION{Built in Bindings} -\ITEM \STYLE{code} "default" \END The default 4coder bindings - typically good for Windows and Linux -\ITEM \STYLE{code} "mac-default" \END Default 4coder bindings on a Mac keyboard -\END -\SECTION{Map: default} -\SECTION{mapid-global} -The following bindings apply in all situations. -\LIST -\ITEM \STYLE{code} \END Change the currently active panel, moving to the panel with the next highest view_id. -\ITEM \STYLE{code} \END Change the currently active panel, moving to the panel with the next lowest view_id. -\ITEM \STYLE{code} \END Interactively creates a new file. -\ITEM \STYLE{code} \END Interactively open a file out of the file system. -\ITEM \STYLE{code} \END Interactively opens a file in the other panel. -\ITEM \STYLE{code} \END Interactively kill an open buffer. -\ITEM \STYLE{code} \END Interactively switch to an open buffer. -\ITEM \STYLE{code} \END Changes 4coder's hot directory to the root directory of the currently loaded project. With no loaded project nothing hapepns. -\ITEM \STYLE{code} \END Saves all buffers marked dirty (showing the '*' indicator). diff --git a/site/source_material/docs.txt b/site/source_material/docs.txt deleted file mode 100644 index 1a14835a..00000000 --- a/site/source_material/docs.txt +++ /dev/null @@ -1,67 +0,0 @@ -\INCLUDE{site_header.txt} - -\TABLE_OF_CONTENTS - -\SECTION{Introduction}{introduction} - \INCLUDE{introduction.txt} -\END - -\SECTION{4coder Systems}{4coder_systems} - \TODO -\END - -\SECTION{Types and Functions}{types_and_functions} - - \SECTION{Function List} - \DOC_LIST{custom_funcs}{mangle:to lower} - \END - - \SECTION{Type List} - \DOC_LIST{custom_types} - \END - - \SECTION{Function Descriptions} - \DOC_FULL{custom_funcs}{mangle:to lower} - \END - - \SECTION{Type Descriptions} - \DOC_FULL{custom_types} - \END -\END - -\SECTION{String Library}{string_library} - \SECTION{String Library Intro} - \TODO - \END - - \SECTION{String Function List} - \DOC_LIST{string} - \END - - \SECTION{String Function Descriptions} - \DOC_FULL{string} - \END -\END - -\SECTION{Lexer Library}{lexer_library} - \SECTION{Lexer Intro} - \INCLUDE{lexer_introduction.txt} - \END - - \SECTION{Lexer Function List} - \DOC_LIST{lexer_funcs} - \END - - \SECTION{Lexer Type List} - \DOC_LIST{lexer_types} - \END - - \SECTION{Lexer Function Descriptions} - \DOC_FULL{lexer_funcs} - \END - - \SECTION{Lexer Type Descriptions} - \DOC_FULL{lexer_types} - \END -\END - diff --git a/site/source_material/feature_list.txt b/site/source_material/feature_list.txt deleted file mode 100644 index 8f25e358..00000000 --- a/site/source_material/feature_list.txt +++ /dev/null @@ -1,70 +0,0 @@ -\INCLUDE{site_header.txt} - -This page provides a list of 4coder features for anyone trying to determine whether 4coder is the right editor for them. To find a complete list of every default key binding visit \LINK{document:bindings} binding list \END. If a feature is missing here you should check out the \LINK{document:roadmap} roadmap \END page to see what is coming in the future. If the feature you want is on neither, it might be missing from this list, or it might actually be missing from 4coder, you should contact \STYLE{code} editor@4coder.net \END to ask questions and make requests. - -\SECTION{Text Editing} - \LIST - \ITEM Support for UTF8 encoded files - \ITEM Cursor-Mark editing paradigm - \ITEM Navigation by characters, words, tokens, lines, and blank lines - \ITEM Modern style undo and redo - \ITEM Incremental word complete with matching words in open files - \ITEM Incremental word search - \ITEM Word replace - \ITEM List all occurences of words in open buffers - \ITEM Clipboard history and "paste-next" to copy multiple chunks of text around easily - \END -\END - -\SECTION{C/C++ Editing} - \LIST - \ITEM Code highlighting for C/C++ code - \ITEM Code auto-layout rendering engine - \ITEM Text level auto-indenting - \ITEM Run scripts and command line commands in editor - \ITEM Jump to error - \END -\END - -\SECTION{Project Organization} - \LIST - \ITEM Set file extensions you care about in your project type to automatically open all code files - \ITEM Set shell/terminal commands to various fkeys for build scripts, test scripts etc - \ITEM project.4coder is a text file so it works painlessly with source control and can it is easy to start working with an existing project on a new machine - \END -\END - -\SECTION{The Customization API} - These features are included in the alpha builds for supporters at the $5 tier and above. - \LIST - \ITEM Easy key rebinding - \ITEM Create custom commands - \ITEM Buffer reading and editing - \ITEM View opening, closing, positioning - \ITEM Access to the code intelligence engine - \ITEM Access to the clipboard - \END -\END - -\SECTION{The Experimental Features} - These features are included in the alpha builds for supporters at the $10 tier and above and are generally only partially implemented, hence not being fully upgraded to the standard build. - \LIST - \ITEM Moving cursor and mark to surrounding and matching braces - \ITEM Rectangular delete - \ITEM Multi-line editing - \ITEM Rename a parameter - \ITEM Write in explicit enum values from 0 to n - \ITEM Scope aware features: scope navigation & scope absorb down - \END -\END - -\SECTION{Transition From Emacs} -4coder's current setup and editing paradigm is modeled after emacs, so it is very natural to transition to 4coder from emacs for many users. 4coder customization is quite different from emacs though, so anyone who wants to keep their current keybinds will have to take the time to rewrite the keybinding code. Once the initial transition is done, any user who prefers C++ to Lisp will have a much better time in their 4coder configuration code. -\END - -\SECTION{Transition From Vim} -For vim users the built-in editing paradigm will not line up with editing habits, but thanks to the open customization model, a vim paradigm and default vim key bindings can be used in 4coder. The vim customization \LINK{!https://github.com/Chronister/4vim} here \END is an early example of this with many basic vim systems up and running. - -Right now 4coder is admittedly not great for vim users, but the transition path exists so keep your eyes on 4coder as better vim emulation is still on the way. -\END - diff --git a/site/source_material/home.txt b/site/source_material/home.txt deleted file mode 100644 index e8d58a90..00000000 --- a/site/source_material/home.txt +++ /dev/null @@ -1,23 +0,0 @@ -\INCLUDE{site_header.txt} - -4coder is a code editor that lives in a space between an IDE and a power editor such as Emacs or Vim. It targets maximum ease of customization, extension, and cross platform reliability. Earlier versions of 4coder focused entirely on C/C++ but it is now transitioning to be a more general purpose editor. Here you can learn about the features of 4coder, how to get started with 4coder, and how to get the absolute most out of 4coder. - -If you cannot find what you are looking for please contact \STYLE{code} editor@4coder.net \END with questions. - -\LINK{!http://4coder.itch.io/4coder} Get Builds and Support Development \END - -\LINK{document:features} Feature List \END - -\LINK{document:bindings} Bindings \END - -\LINK{document:roadmap} Road Map \END - -\LINK{document:custom_docs} Documentation for Customization \END - -\LINK{document:tutorials} Tutorials for 4coder \END - -\IMAGE{image:screen_1} - -\IMAGE{image:screen_2} - -\IMAGE{image:screen_3} diff --git a/site/source_material/introduction.txt b/site/source_material/introduction.txt deleted file mode 100644 index 7bd7b98c..00000000 --- a/site/source_material/introduction.txt +++ /dev/null @@ -1,3 +0,0 @@ -This is the documentation for \VERSION. The documentation is still under construction so some of the links are linking to sections that have not been written yet. What is here should be correct and I suspect useful even without some of the other sections. - -If you have questions or discover errors please contact \STYLE{code}editor@4coder.net\END or to get help from members of the 4coder and handmade network community you can post on the 4coder forums hosted at \STYLE{code}4coder.handmade.network\END. diff --git a/site/source_material/lexer_introduction.txt b/site/source_material/lexer_introduction.txt deleted file mode 100644 index e4415a42..00000000 --- a/site/source_material/lexer_introduction.txt +++ /dev/null @@ -1,7 +0,0 @@ -The 4cpp lexer system provides a polished, fast, flexible system that takes in C/C++ and outputs a tokenization of the text data. There are two API levels. One level is setup to let you easily get a tokenization of the file. This level manages memory for you with malloc to make it as fast as possible to start getting your tokens. The second level enables deep integration by allowing control over allocation, data chunking, and output rate control. - -To use the quick setup API you simply include 4cpp_lexer.h and read the documentation at \DOC_LINK{cpp_lex_file}. - -To use the the fancier API include 4cpp_lexer.h and read the documentation at \DOC_LINK{cpp_lex_step}. If you want to be absolutely sure you are not including malloc into your program you can define FCPP_FORBID_MALLOC before the include and the "step" API will continue to work. - -There are a few more features in 4cpp that are not documented yet. You are free to try to use these, but I am not totally sure they are ready yet, and when they are they will be documented. diff --git a/site/source_material/roadmap.txt b/site/source_material/roadmap.txt deleted file mode 100644 index 2f793b56..00000000 --- a/site/source_material/roadmap.txt +++ /dev/null @@ -1,30 +0,0 @@ -\INCLUDE{site_header.txt} - -Right now I am working on upgrading some core internal systems that should buy me the flexibility I need to get the rest of the envisioned features done. Because these core upgrades are experimental in nature, it's hard to predict how long it will take before they are ready. - -\SECTION{Improve the Core Buffer Systems} - \LIST - \ITEM Fix up the undo/redo system. - \ITEM Expose undo/redo system in the custom layer. - \ITEM Binary buffer mode. - \ITEM Programmable code wrapping. - \ITEM Virtual/Ghost text for features such as word complete and code folding. - \END -\END - -\SECTION{Provide Customizations for Multiple Editing Paradgims} - \LIST - \ITEM Restructure custom layer to work as an event loop. - \ITEM Custom layer reloading at runtime. - \ITEM Sublime like editing. - \ITEM Vim like editing. - \END -\END - -\SECTION{Platform Layer Features and Porting Issues} - \LIST - \ITEM Upgrade the worker thread system to better support async and parallel solutions. - \ITEM Support for double click opening files in an existing window. - \ITEM Make the rendeirng system modular. - \END -\END diff --git a/site/source_material/site_header.txt b/site/source_material/site_header.txt deleted file mode 100644 index a9901853..00000000 --- a/site/source_material/site_header.txt +++ /dev/null @@ -1,11 +0,0 @@ -\META_PARSE{custom_funcs}{4ed_api_implementation.cpp} -\META_PARSE{custom_types}{4coder_API/4coder_types.h} -\META_PARSE{string} {string/internal_4coder_string.cpp} -\META_PARSE{lexer_funcs} {4coder_lib/4cpp_lexer.h} -\META_PARSE{lexer_types} {4coder_lib/4cpp_lexer_types.h} - -\LINK{document:home} -\IMAGE{image:4coder_logo}{width:200} -\END - - diff --git a/site/source_material/tutorials.txt b/site/source_material/tutorials.txt deleted file mode 100644 index 2d2af140..00000000 --- a/site/source_material/tutorials.txt +++ /dev/null @@ -1,17 +0,0 @@ -\INCLUDE{site_header.txt} - -Getting started with 4coder and navigating your files: - -\VIDEO{youtube:h5cbOcnSrcc} - -Creating and using a "version(1)" project in 4coder: - -\VIDEO{youtube:FX8WPI2WGVI} - -Using customizable keywords in the 4coder custom API: - -\VIDEO{youtube:qoEvc4uC9Uw} - -More tutorials coming soon. - - diff --git a/string/4coder_string_build_num.txt b/string/4coder_string_build_num.txt deleted file mode 100644 index 796c69a9..00000000 --- a/string/4coder_string_build_num.txt +++ /dev/null @@ -1,5 +0,0 @@ -1 -0 -123 - - diff --git a/string/4ed_string_builder.cpp b/string/4ed_string_builder.cpp deleted file mode 100644 index 95f663e4..00000000 --- a/string/4ed_string_builder.cpp +++ /dev/null @@ -1,454 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 21.01.2017 - * - * Builder for the 4coder_string.h header. - * - */ - -// TOP - -// TODO(allen): Make sure to only publish the 4coder_string.h if it builds and passes a series of tests. - -#define BUILD_NUMBER_FILE "4coder_string_build_num.txt" - -#define GENERATED_FILE "4coder_string.h" -#define INTERNAL_STRING "internal_4coder_string.cpp" - -#define BACKUP_FOLDER ".." SLASH ".." SLASH "string_backup" - -#include "../4coder_lib/4coder_arena.h" -#include "../4coder_lib/4coder_arena.cpp" -#define FSTRING_IMPLEMENTATION -#include "../4coder_lib/4coder_string.h" -#include "../4coder_lib/4cpp_lexer.h" - -#include "../4ed_defines.h" -#include "../meta/4ed_meta_defines.h" - -#define FTECH_FILE_MOVING_IMPLEMENTATION -#include "../meta/4ed_file_moving.h" -#include "../meta/4ed_meta_parser.cpp" -#include "../meta/4ed_meta_keywords.h" - -#include -#include - -#define V_MAJ_NUM 1 -#define V_MIN_NUM 0 - -#define V_MAJ STR_(V_MAJ_NUM) -#define V_MIN STR_(V_MIN_NUM) - -internal char* -parse_next_line(char *str, char *str_end){ - char *ptr = str; - for (; ptr < str_end && *ptr != '\n'; ++ptr); - ++ptr; - return(ptr); -} - -internal b32 -parse_build_number(char *file_name, i32 *major_out, i32 *minor_out, i32 *build_out){ - b32 result = false; - String file = file_dump(file_name); - - if (file.str != 0){ - *major_out = 0; - *minor_out = 0; - *build_out = 0; - - char *end_str = file.str + file.size; - char *major_str = file.str; - char *minor_str = parse_next_line(major_str, end_str); - char *build_str = parse_next_line(minor_str, end_str); - char *ender = parse_next_line(build_str, end_str); - - if (major_str < end_str && build_str < end_str && ender < end_str){ - minor_str[-1] = 0; - build_str[-1] = 0; - ender[-1] = 0; - - *major_out = str_to_int_c(major_str); - *minor_out = str_to_int_c(minor_str); - *build_out = str_to_int_c(build_str); - - result = true; - } - - free(file.str); - } - - return(result); -} - -internal void -save_build_number(char *file_name, i32 major, i32 minor, i32 build){ - FILE *out = fopen(file_name, "wb"); - fprintf(out, "%d\n%d\n%d\n\n\n", major, minor, build); - fclose(out); -} - -/////////////////////////////// - -// -// Meta Parse Rules -// - -internal void -print_function_body_code(String *out, Parse_Context *context, i32 start){ - String pstr = {}, lexeme = {}; - Cpp_Token *token = 0; - - i32 do_print = 0; - i32 nest_level = 0; - i32 finish = false; - i32 do_whitespace_print = false; - i32 is_first = true; - - for (; (token = get_token(context)) != 0; get_next_token(context)){ - if (do_whitespace_print){ - pstr = str_start_end(context->data, start, token->start); - append(out, pstr); - } - else{ - do_whitespace_print = true; - } - - do_print = true; - if (token->type == CPP_TOKEN_COMMENT){ - lexeme = get_lexeme(*token, context->data); - if (check_and_fix_docs(&lexeme)){ - do_print = false; - } - } - else if (token->type == CPP_TOKEN_BRACE_OPEN){ - ++nest_level; - } - else if (token->type == CPP_TOKEN_BRACE_CLOSE){ - --nest_level; - if (nest_level == 0){ - finish = true; - } - } - if (is_first){ - do_print = false; - is_first = false; - } - - if (do_print){ - pstr = get_lexeme(*token, context->data); - append(out, pstr); - } - - start = token->start + token->size; - - if (finish){ - break; - } - } -} - -internal void -file_move(Partition *part, char *path, char *file_name){ - fm_copy_file(fm_str(part, file_name), fm_str(part, path, "/", file_name)); -} - -int main(){ - META_BEGIN(); - Partition part_ = fm_init_system(); - Partition *part = &part_; - - // NOTE(allen): Parse the internal string file. - char *string_files[] = { INTERNAL_STRING, 0 }; - Meta_Unit string_unit = compile_meta_unit(part, ".", string_files, ExpandArray(meta_keywords)); - - if (string_unit.parse == 0){ - Assert(!"Missing one or more input files!"); - } - - // NOTE(allen): Parse the version counter file - i32 major_number = 0; - i32 minor_number = 0; - i32 build_number = 0; - b32 parsed_version_counter = parse_build_number(BUILD_NUMBER_FILE, &major_number, &minor_number, &build_number); - Assert(parsed_version_counter); - - if (V_MAJ_NUM < major_number){ - Assert(!"major version mismatch"); - } - else if (V_MAJ_NUM > major_number){ - major_number = V_MAJ_NUM; - minor_number = V_MIN_NUM; - build_number = 0; - } - else{ - if (V_MIN_NUM < minor_number){ - Assert(!"minor version mismatch"); - } - else if (V_MIN_NUM > minor_number){ - minor_number = V_MIN_NUM; - build_number = 0; - } - } - - // NOTE(allen): String Library - String out = string_push(part, 10 << 20); - - Cpp_Token *token = 0; - i32 start = 0; - - Parse parse = string_unit.parse[0]; - Parse_Context pcontext = setup_parse_context(parse); - - for (; (token = get_token(&pcontext)) != 0; get_next_token(&pcontext)){ - if (!(token->flags & CPP_TFLAG_PP_BODY) && - token->type == CPP_TOKEN_IDENTIFIER){ - String lexeme = get_lexeme(*token, pcontext.data); - if (match(lexeme, "FSTRING_BEGIN")){ - start = token->start + token->size; - break; - } - } - } - - append(&out, "/*\n"); - - append(&out, GENERATED_FILE " - Version " V_MAJ "." V_MIN "."); - append_int_to_str(&out, build_number); - append(&out, "\n"); - - append(&out, STANDARD_DISCLAIMER); - append(&out, - "To include implementation: #define FSTRING_IMPLEMENTATION\n" - "To use in C mode: #define FSTRING_C\n"); - - append(&out, "*/\n"); - - String pstr = {}; - i32 do_whitespace_print = true; - - for(;(token = get_next_token(&pcontext)) != 0;){ - if (do_whitespace_print){ - pstr = str_start_end(pcontext.data, start, token->start); - append(&out, pstr); - } - else{ - do_whitespace_print = true; - } - - String lexeme = get_lexeme(*token, pcontext.data); - - i32 do_print = true; - if (match(lexeme, "FSTRING_DECLS")){ - append(&out, "#if !defined(FCODER_STRING_H)\n#define FCODER_STRING_H\n\n"); - do_print = false; - - local_persist i32 RETURN_PADDING = 16; - local_persist i32 SIG_PADDING = 35; - - for (i32 j = 0; j < string_unit.set.count; ++j){ - char line_[2048]; - String line = make_fixed_width_string(line_); - Item_Node *item = string_unit.set.items + j; - - if (item->t == Item_Function){ - append (&line, item->ret); - append_padding (&line, ' ', SIG_PADDING); - append (&line, item->name); - append (&line, item->args); - append (&line, ";\n"); - } - else if (item->t == Item_Macro){ - append (&line, "#ifndef "); - append_padding (&line, ' ', 10); - append (&line, item->name); - append_s_char (&line, '\n'); - - append (&line, "# define "); - append_padding (&line, ' ', 10); - append (&line, item->name); - append (&line, item->args); - append_s_char (&line, ' '); - append (&line, item->body); - append_s_char (&line, '\n'); - - append (&line, "#endif"); - append_s_char (&line, '\n'); - } - else{ - InvalidCodePath; - } - - append(&out, line); - } - - append(&out, "\n#endif\n"); - - // NOTE(allen): C++ overload definitions - append(&out, "\n#if !defined(FSTRING_C) && !defined(FSTRING_GUARD)\n\n"); - - for (i32 j = 0; j < string_unit.set.count; ++j){ - char line_space[2048]; - String line = make_fixed_width_string(line_space); - - Item_Node *item = &string_unit.set.items[j]; - - if (item->t == Item_Function){ - String cpp_name = item->cpp_name; - if (cpp_name.str != 0){ - Argument_Breakdown breakdown = item->breakdown; - - append (&line, item->ret); - append_padding(&line, ' ', SIG_PADDING); - append (&line, cpp_name); - append (&line, item->args); - if (match(item->ret, "void")){ - append(&line, "{("); - } - else{ - append(&line, "{return("); - } - append (&line, item->name); - append_s_char(&line, '('); - - if (breakdown.count > 0){ - for (i32 i = 0; i < breakdown.count; ++i){ - if (i != 0){ - append_s_char(&line, ','); - } - append(&line, breakdown.args[i].param_name); - } - } - else{ - append(&line, "void"); - } - - append(&line, "));}\n"); - - append(&out, line); - } - } - } - - append(&out, "\n#endif\n"); - } - - else if (match(lexeme, "API_EXPORT_MACRO")){ - token = get_next_token(&pcontext); - if (token && token->type == CPP_TOKEN_COMMENT){ - token = get_next_token(&pcontext); - if (token && token->type == CPP_PP_DEFINE){ - for (;(token = get_next_token(&pcontext)) != 0;){ - if (!(token->flags & CPP_TFLAG_PP_BODY)){ - break; - } - } - if (token != 0){ - get_prev_token(&pcontext); - } - do_print = false; - do_whitespace_print = false; - } - } - } - - else if (match(lexeme, "API_EXPORT") || match(lexeme, "API_EXPORT_INLINE")){ - if (!(token->flags & CPP_TFLAG_PP_BODY)){ - if (match(lexeme, "API_EXPORT_INLINE")){ - append(&out, "#if !defined(FSTRING_GUARD)\n"); - } - else{ - append(&out, "#if defined(FSTRING_IMPLEMENTATION)\n"); - } - print_function_body_code(&out, &pcontext, start); - append(&out, "\n#endif"); - do_print = false; - } - } - - else if (match(lexeme, "CPP_NAME")){ - Cpp_Token *token_start = token; - i32 has_cpp_name = false; - - token = get_next_token(&pcontext); - if (token && token->type == CPP_TOKEN_PARENTHESE_OPEN){ - token = get_next_token(&pcontext); - if (token && token->type == CPP_TOKEN_IDENTIFIER){ - token = get_next_token(&pcontext); - if (token && token->type == CPP_TOKEN_PARENTHESE_CLOSE){ - has_cpp_name = true; - do_print = false; - } - } - } - - if (!has_cpp_name){ - token = set_token(&pcontext, token_start); - } - } - - else if (token->type == CPP_TOKEN_COMMENT){ - if (check_and_fix_docs(&lexeme)){ - do_print = false; - } - } - - else if (token->type == CPP_PP_INCLUDE){ - token = get_next_token(&pcontext); - if (token && token->type == CPP_PP_INCLUDE_FILE){ - lexeme = get_lexeme(*token, pcontext.data); - lexeme.size -= 2; - lexeme.str += 1; - - char space[512]; - String str = make_fixed_width_string(space); - append(&str, lexeme); - terminate_with_null(&str); - String dump = file_dump(str.str); - if (dump.str){ - append(&out, dump); - } - else{ - lexeme.size += 2; - lexeme.str -= 1; - append(&out, "#error Could not find "); - append(&out, lexeme); - append(&out, "\n"); - } - free(dump.str); - } - - do_print = false; - } - - if ((token = get_token(&pcontext)) != 0){ - if (do_print){ - pstr = get_lexeme(*token, pcontext.data); - append(&out, pstr); - } - start = token->start + token->size; - } - } - pstr = str_start_end(pcontext.data, start, parse.code.size); - append(&out, pstr); - - fm_write_file(GENERATED_FILE, out.str, out.size); - out.size = 0; - - // NOTE(allen): Publish the new file. (Would like to be able to automatically test the result before publishing). - { - fm_make_folder_if_missing(part, BACKUP_FOLDER SLASH V_MAJ SLASH V_MIN); - file_move(part, BACKUP_FOLDER SLASH V_MAJ SLASH V_MIN, INTERNAL_STRING); - file_move(part, BACKUP_FOLDER SLASH V_MAJ SLASH V_MIN, GENERATED_FILE); - fm_delete_file(GENERATED_FILE); - printf("published " GENERATED_FILE ": v%d.%d.%d\n", major_number, minor_number, build_number); - save_build_number(BUILD_NUMBER_FILE, major_number, minor_number, build_number + 1); - } - - META_FINISH(); -} - -// BOTTOM - diff --git a/string/4tech_standard_preamble.h b/string/4tech_standard_preamble.h deleted file mode 100644 index b6ae1e23..00000000 --- a/string/4tech_standard_preamble.h +++ /dev/null @@ -1,31 +0,0 @@ -// 4tech_standard_preamble.h -#if !defined(FTECH_INTEGERS) -#define FTECH_INTEGERS -#include -typedef int8_t i8_4tech; -typedef int16_t i16_4tech; -typedef int32_t i32_4tech; -typedef int64_t i64_4tech; - -typedef uint8_t u8_4tech; -typedef uint16_t u16_4tech; -typedef uint32_t u32_4tech; -typedef uint64_t u64_4tech; - -#if defined(FTECH_32_BIT) -typedef u32_4tech umem_4tech; -#else -typedef u64_4tech umem_4tech; -#endif - -typedef float f32_4tech; -typedef double f64_4tech; - -typedef int8_t b8_4tech; -typedef int32_t b32_4tech; -#endif - -#if !defined(Assert) -# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0) -#endif -// standard preamble end diff --git a/string/internal_4coder_string.cpp b/string/internal_4coder_string.cpp deleted file mode 100644 index c8a202db..00000000 --- a/string/internal_4coder_string.cpp +++ /dev/null @@ -1,2296 +0,0 @@ -/* -internal_4coder_string.cpp - Base file for generating 4coder_string.h -*/ - -#define FSTRING_DECLS -#define FSTRING_BEGIN -#define API_EXPORT_MACRO - -#ifndef API_EXPORT -# define API_EXPORT -#endif - -#ifndef API_EXPORT_INLINE -# define API_EXPORT_INLINE -#endif - -#define CPP_NAME(n) - -FSTRING_BEGIN -// TOP - -#include "4tech_standard_preamble.h" - -#if !defined(FSTRING_LINK) -# define FSTRING_LINK static -#endif - -#if !defined(FSTRING_INLINE) -# define FSTRING_INLINE static -#endif - -#if !defined(FSTRING_GUARD) -#define literal(s) (s), (sizeof(s) - 1) - -typedef struct String{ - char *str; - i32_4tech size; - i32_4tech memory_size; -} String; - -static String null_string = {}; -static String empty_string = {"", 0, 0}; -#endif - -FSTRING_DECLS - -// -// Character Helpers -// - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_slash(char c) -/* DOC(This call returns non-zero if c is \ or /.) */{ - return (c == '\\' || c == '/'); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_upper(char c) -/* DOC(If c is an uppercase letter this call returns true.) */{ - return (c >= 'A' && c <= 'Z'); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_upper_utf8(char c) -/* DOC(If c is an uppercase letter this call returns true.) */{ - return ((c >= 'A' && c <= 'Z') || (unsigned char)c >= 128); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_lower(char c) -/* DOC(If c is a lower letter this call returns true.) */{ - return (c >= 'a' && c <= 'z'); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_lower_utf8(u8_4tech c) -/* DOC(If c is a lower letter this call returns true.) */{ - return ((c >= 'a' && c <= 'z') || (unsigned char)c >= 128); -} - -API_EXPORT_INLINE FSTRING_INLINE char -char_to_upper(char c) -/* DOC(If c is a lowercase letter this call returns the uppercase equivalent, otherwise it returns c.) */{ - return (c >= 'a' && c <= 'z') ? c + (char)('A' - 'a') : c; -} - -API_EXPORT_INLINE FSTRING_INLINE char -char_to_lower(char c) -/* DOC(If c is an uppercase letter this call returns the lowercase equivalent, otherwise it returns c.) */{ - return (c >= 'A' && c <= 'Z') ? c - (char)('A' - 'a') : c; -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_whitespace(char c) -/* DOC(This call returns non-zero if c is whitespace.) */{ - return (c == ' ' || c == '\n' || c == '\r' || c == '\t'); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_alpha_numeric(char c) -/* DOC(This call returns non-zero if c is any alphanumeric character including underscore.) */{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_alpha_numeric_utf8(u8_4tech c) -/* DOC(This call returns non-zero if c is any alphanumeric character including underscore, or is a part of a UTF8 sequence outside of ASCII.) */{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || (unsigned char)c >= 128); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_alpha_numeric_true(char c) -/* DOC(This call returns non-zero if c is any alphanumeric character no including underscore.) */{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_alpha_numeric_true_utf8(u8_4tech c) -/* DOC(This call returns non-zero if c is any alphanumeric character no including underscore.) */{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (unsigned char)c >= 128); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_alpha(char c) -/* DOC(This call returns non-zero if c is any alphabetic character including underscore.) */{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_alpha_utf8(u8_4tech c) -/* DOC(This call returns non-zero if c is any alphabetic character including underscore, or is a part of a UTF8 sequence outside of ASCII.) */{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (unsigned char)c >= 128); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_alpha_true(char c) -/* DOC(This call returns non-zero if c is any alphabetic character.) */{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_alpha_true_utf8(u8_4tech c) -/* DOC(This call returns non-zero if c is any alphabetic character, or is a part of a UTF8 sequence outside of ASCII.) */{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (unsigned char)c >= 128); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_hex(char c) -/* DOC(This call returns non-zero if c is any valid hexadecimal digit.) */{ - return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_hex_utf8(u8_4tech c) -/* DOC(This call returns non-zero if c is any valid hexadecimal digit, or is a part of a UTF8 sequence outside of ASCII.) */{ - return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (unsigned char)c >= 128); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_numeric(char c) -/* DOC(This call returns non-zero if c is any valid decimal digit.) */{ - return (c >= '0' && c <= '9'); -} - -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -char_is_numeric_utf8(u8_4tech c) -/* DOC(This call returns non-zero if c is any valid decimal digit, or is a part of a UTF8 sequence outside of ASCII.) */{ - return ((c >= '0' && c <= '9') || (unsigned char)c >= 128); -} - - -// -// String Making Functions -// - -CPP_NAME(make_string) -API_EXPORT_INLINE FSTRING_INLINE String -make_string_cap(void *str, i32_4tech size, i32_4tech mem_size)/* -DOC_PARAM(str, The str parameter provides the of memory with which the string shall operate.) -DOC_PARAM(size, The size parameter expresses the initial size of the string. -If the memory does not already contain a useful string this should be zero.) -DOC_PARAM(mem_size, The mem_size parameter expresses the full size of the memory provided by str.) -DOC(This call returns the String created from the parameters.) -*/{ - String result; - result.str = (char*)str; - result.size = size; - result.memory_size = mem_size; - return(result); -} - -API_EXPORT_INLINE FSTRING_INLINE String -make_string(void *str, i32_4tech size)/* -DOC_PARAM(str, The str parameter provides the of memory with which the string shall operate.) -DOC_PARAM(size, The size parameter expresses the initial size of the string. -If the memory does not already contain a useful string this should be zero. Since this version -does not specify the size of the memory it is also assumed that this size is the maximum size -of the memory.) -DOC(This call returns the String created from the parameters.) -*/{ - return(make_string(str, size, size)); -} - -API_EXPORT_MACRO -/* DOC(This macro takes a literal string in quotes and uses it to create a String with the correct size and memory size. Strings created this way should usually not be mutated.) */ -#define make_lit_string(s) (make_string_cap((char*)(s), sizeof(s)-1, sizeof(s))) - -API_EXPORT_MACRO -/* DOC(Rename for make_lit_string.) DOC_SEE(make_lit_string) */ -#define lit(s) make_lit_string(s) - -API_EXPORT_MACRO -/* DOC(This macro takes a local char array with a fixed width and uses it to create an empty String with the correct size and memory size to operate on the array.) */ -#define make_fixed_width_string(s) (make_string_cap((char*)(s), 0, sizeof(s))) - -API_EXPORT_MACRO -/* DOC(This macro is a helper for any calls that take a char*,integer pair to specify a string. This macro expands to both of those parameters from one String struct.) */ -#define expand_str(s) ((s).str), ((s).size) - -API_EXPORT FSTRING_LINK i32_4tech -str_size(char *str) -/* DOC(This call returns the number of bytes before a null terminator starting at str.) */{ - i32_4tech i = 0; - if (str != 0){ - for (;str[i];++i); - } - return(i); -} - -API_EXPORT_INLINE FSTRING_INLINE String -make_string_slowly(void *str) -/* DOC(This call makes a string by counting the number of bytes before a null terminator and treating that as the size and memory size of the string.) */{ - String result; - result.str = (char*)str; - result.size = str_size((char*)str); - result.memory_size = result.size + 1; - return(result); -} - -CPP_NAME(substr) -API_EXPORT_INLINE FSTRING_INLINE String -substr_tail(String str, i32_4tech start) -/* DOC(This call creates a substring of str that starts with an offset from str's base. -The new string uses the same underlying memory so both strings will see changes. -Usually strings created this way should only go through immutable calls.) */{ - String result; - result.str = str.str + start; - result.size = str.size - start; - result.memory_size = 0; - return(result); -} - -API_EXPORT_INLINE FSTRING_INLINE String -substr(String str, i32_4tech start, i32_4tech size) -/* DOC(This call creates a substring of str that starts with an offset from str's base, -and has a fixed size. The new string uses the same underlying memory so both strings -will see changes. Usually strings created this way should only go through immutable calls.) */{ - String result; - result.str = str.str + start; - result.size = size; - if (start + size > str.size){ - result.size = str.size - start; - } - result.memory_size = 0; - return(result); -} - -API_EXPORT FSTRING_LINK String -skip_whitespace(String str) -/* DOC(This call creates a substring that starts with the first non-whitespace character of str. -Like other substr calls, the new string uses the underlying memory and so should usually be -considered immutable.) DOC_SEE(substr) */{ - String result = {}; - i32_4tech i = 0; - for (; i < str.size && char_is_whitespace(str.str[i]); ++i); - result = substr(str, i, str.size - i); - return(result); -} - -CPP_NAME(skip_whitespace) -API_EXPORT FSTRING_LINK String -skip_whitespace_measure(String str, i32_4tech *skip_length) -/* DOC(This call creates a substring that starts with the first non-whitespace character of str. -Like other substr calls, the new string uses the underlying memory and so should usually be -considered immutable.) DOC_SEE(substr) */{ - String result = {}; - i32_4tech i = 0; - for (; i < str.size && char_is_whitespace(str.str[i]); ++i); - result = substr(str, i, str.size - i); - *skip_length = i; - return(result); -} - -API_EXPORT FSTRING_LINK String -chop_whitespace(String str) -/* DOC(This call creates a substring that ends with the last non-whitespace character of str. -Like other substr calls, the new string uses the underlying memory and so should usually be -considered immutable.) DOC_SEE(substr) */{ - String result = {}; - i32_4tech i = str.size; - for (; i > 0 && char_is_whitespace(str.str[i-1]); --i); - result = substr(str, 0, i); - return(result); -} - -API_EXPORT FSTRING_LINK String -skip_chop_whitespace(String str) -/* DOC(This call is equivalent to calling skip_whitespace and chop_whitespace together.) -DOC_SEE(skip_whitespace) DOC_SEE(chop_whitespace)*/{ - str = skip_whitespace(str); - str = chop_whitespace(str); - return(str); -} - -CPP_NAME(skip_chop_whitespace) -API_EXPORT FSTRING_LINK String -skip_chop_whitespace_measure(String str, i32_4tech *skip_length) -/* DOC(This call is equivalent to calling skip_whitespace and chop_whitespace together.) -DOC_SEE(skip_whitespace) DOC_SEE(chop_whitespace)*/{ - str = skip_whitespace_measure(str, skip_length); - str = chop_whitespace(str); - return(str); -} - -API_EXPORT_INLINE FSTRING_INLINE String -tailstr(String str) -/* DOC(This call returns an empty String with underlying memory taken from -the portion of str's memory that is not used.) */{ - String result; - result.str = str.str + str.size; - result.memory_size = str.memory_size - str.size; - result.size = 0; - return(result); -} - - -// -// String Comparison -// - -CPP_NAME(match) -API_EXPORT FSTRING_LINK b32_4tech -match_cc(char *a, char *b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ - for (i32_4tech i = 0;; ++i){ - if (a[i] != b[i]){ - return 0; - } - if (a[i] == 0){ - return 1; - } - } -} - -CPP_NAME(match) -API_EXPORT FSTRING_LINK b32_4tech -match_sc(String a, char *b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ - i32_4tech i = 0; - for (; i < a.size; ++i){ - if (a.str[i] != b[i]){ - return 0; - } - } - if (b[i] != 0){ - return 0; - } - return 1; -} - -CPP_NAME(match) -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -match_cs(char *a, String b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ - return(match_sc(b,a)); -} - -CPP_NAME(match) -API_EXPORT FSTRING_LINK b32_4tech -match_ss(String a, String b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ - if (a.size != b.size){ - return 0; - } - for (i32_4tech i = 0; i < b.size; ++i){ - if (a.str[i] != b.str[i]){ - return 0; - } - } - return 1; -} - -CPP_NAME(match_part) -API_EXPORT FSTRING_LINK b32_4tech -match_part_ccl(char *a, char *b, i32_4tech *len)/* -DOC_PARAM(len, If this call returns non-zero this parameter is used to output the length of b.) -DOC(This call is similar to a match call, except that it is permitted for a to be longer than b. -In other words this call returns non-zero if b is a prefix of a.) */{ - if (a == 0){ - a = ""; - } - if (b == 0){ - b = ""; - } - - i32_4tech i; - for (i = 0; b[i] != 0; ++i){ - if (a[i] != b[i]){ - return(0); - } - } - *len = i; - return(1); -} - -CPP_NAME(match_part) -API_EXPORT FSTRING_LINK b32_4tech -match_part_scl(String a, char *b, i32_4tech *len)/* -DOC_PARAM(len, If this call returns non-zero this parameter is used to output the length of b.) -DOC(This call is similar to a match call, except that it is permitted for a to be longer than b. -In other words this call returns non-zero if b is a prefix of a.) */{ - if (b == 0){ - b = ""; - } - i32_4tech i; - for (i = 0; b[i] != 0; ++i){ - if (i == a.size || a.str[i] != b[i]){ - return(0); - } - } - *len = i; - return(1); -} - -CPP_NAME(match_part) -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -match_part_cc(char *a, char *b)/* -DOC_PARAM(len, If this call returns non-zero this parameter is used to output the length of b.) -DOC(This call is similar to a match call, except that it is permitted for a to be longer than b. -In other words this call returns non-zero if b is a prefix of a.) */{ - i32_4tech x; - return match_part_ccl(a,b,&x); -} - -CPP_NAME(match_part) -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -match_part_sc(String a, char *b)/* -DOC(This call is similar to a match call, except that it is permitted for a to be longer than b. -In other words this call returns non-zero if b is a prefix of a.) */{ - i32_4tech x; - return match_part_scl(a,b,&x); -} - -CPP_NAME(match_part) -API_EXPORT FSTRING_LINK b32_4tech -match_part_cs(char *a, String b)/* -DOC(This call is similar to a match call, except that it is permitted for a to be longer than b. -In other words this call returns non-zero if b is a prefix of a.) */{ - for (i32_4tech i = 0; i != b.size; ++i){ - if (a[i] != b.str[i]){ - return 0; - } - } - return 1; -} - -CPP_NAME(match_part) -API_EXPORT FSTRING_LINK b32_4tech -match_part_ss(String a, String b)/* -DOC(This call is similar to a match call, except that it is permitted for a to be longer than b. -In other words this call returns non-zero if b is a prefix of a.) */{ - if (a.size < b.size){ - return(0); - } - for (i32_4tech i = 0; i < b.size; ++i){ - if (a.str[i] != b.str[i]){ - return(0); - } - } - return(1); -} - -CPP_NAME(match_insensitive) -API_EXPORT FSTRING_LINK b32_4tech -match_insensitive_cc(char *a, char *b)/* -DOC(This call returns non-zero if a and b are equivalent under case insensitive comparison.) */{ - for (i32_4tech i = 0;; ++i){ - if (char_to_upper(a[i]) != - char_to_upper(b[i])){ - return 0; - } - if (a[i] == 0){ - return 1; - } - } -} - -CPP_NAME(match_insensitive) -API_EXPORT FSTRING_LINK b32_4tech -match_insensitive_sc(String a, char *b)/* -DOC(This call returns non-zero if a and b are equivalent under case insensitive comparison.) */{ - i32_4tech i = 0; - for (; i < a.size; ++i){ - if (char_to_upper(a.str[i]) != - char_to_upper(b[i])){ - return 0; - } - } - if (b[i] != 0){ - return 0; - } - return 1; -} - -CPP_NAME(match_insensitive) -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -match_insensitive_cs(char *a, String b)/* -DOC(This call returns non-zero if a and b are equivalent under case insensitive comparison.) */{ - return match_insensitive_sc(b,a); -} - -CPP_NAME(match_insensitive) -API_EXPORT FSTRING_LINK b32_4tech -match_insensitive_ss(String a, String b)/* -DOC(This call returns non-zero if a and b are equivalent under case insensitive comparison.) */{ - if (a.size != b.size){ - return 0; - } - for (i32_4tech i = 0; i < b.size; ++i){ - if (char_to_upper(a.str[i]) != - char_to_upper(b.str[i])){ - return 0; - } - } - return 1; -} - -CPP_NAME(match_part_insensitive) -API_EXPORT FSTRING_LINK b32_4tech -match_part_insensitive_ccl(char *a, char *b, i32_4tech *len)/* -DOC_PARAM(len, If this call returns non-zero this parameter is used to output the length of b.) -DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) -DOC_SEE(match_part) */{ - i32_4tech i; - for (i = 0; b[i] != 0; ++i){ - if (char_to_upper(a[i]) != char_to_upper(b[i])){ - return 0; - } - } - *len = i; - return 1; -} - -CPP_NAME(match_part_insensitive) -API_EXPORT FSTRING_LINK b32_4tech -match_part_insensitive_scl(String a, char *b, i32_4tech *len)/* -DOC_PARAM(len, If this call returns non-zero this parameter is used to output the length of b.) -DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) -DOC_SEE(match_part) */{ - i32_4tech i; - for (i = 0; b[i] != 0; ++i){ - if (char_to_upper(a.str[i]) != char_to_upper(b[i]) || - i == a.size){ - return 0; - } - } - *len = i; - return 1; -} - -CPP_NAME(match_part_insensitive) -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -match_part_insensitive_cc(char *a, char *b)/* -DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) -DOC_SEE(match_part) */{ - i32_4tech x; - return match_part_insensitive_ccl(a,b,&x); -} - -CPP_NAME(match_part_insensitive) -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -match_part_insensitive_sc(String a, char *b)/* -DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) -DOC_SEE(match_part) */{ - i32_4tech x; - return match_part_insensitive_scl(a,b,&x); -} - -CPP_NAME(match_part_insensitive) -API_EXPORT FSTRING_LINK b32_4tech -match_part_insensitive_cs(char *a, String b)/* -DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) -DOC_SEE(match_part) */{ - for (i32_4tech i = 0; i != b.size; ++i){ - if (char_to_upper(a[i]) != char_to_upper(b.str[i])){ - return(0); - } - } - return(1); -} - -CPP_NAME(match_part_insensitive) -API_EXPORT FSTRING_LINK b32_4tech -match_part_insensitive_ss(String a, String b)/* -DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) -DOC_SEE(match_part) */{ - if (a.size < b.size){ - return(0); - } - for (i32_4tech i = 0; i < b.size; ++i){ - if (char_to_upper(a.str[i]) != char_to_upper(b.str[i])){ - return(0); - } - } - return(1); -} - -CPP_NAME(compare) -API_EXPORT FSTRING_LINK i32_4tech -compare_cc(char *a, char *b)/* -DOC(This call returns zero if a and b are equivalent, -it returns negative if a sorts before b alphabetically, -and positive if a sorts after b alphabetically.) */{ - i32_4tech i = 0, r = 0; - while (a[i] == b[i] && a[i] != 0){ - ++i; - } - r = (a[i] > b[i]) - (a[i] < b[i]); - return(r); -} - -CPP_NAME(compare) -API_EXPORT FSTRING_LINK i32_4tech -compare_sc(String a, char *b)/* -DOC(This call returns zero if a and b are equivalent, -it returns negative if a sorts before b alphabetically, -and positive if a sorts after b alphabetically.) */{ - i32_4tech i = 0, r = 0; - while (i < a.size && a.str[i] == b[i]){ - ++i; - } - if (i < a.size){ - r = (a.str[i] > b[i]) - (a.str[i] < b[i]); - } - else{ - if (b[i] == 0){ - r = 0; - } - else{ - r = -1; - } - } - return(r); -} - -CPP_NAME(compare) -API_EXPORT_INLINE FSTRING_INLINE i32_4tech -compare_cs(char *a, String b)/* -DOC(This call returns zero if a and b are equivalent, -it returns negative if a sorts before b alphabetically, -and positive if a sorts after b alphabetically.) */{ - i32_4tech r = -compare_sc(b,a); - return(r); -} - -CPP_NAME(compare) -API_EXPORT FSTRING_LINK i32_4tech -compare_ss(String a, String b)/* -DOC(This call returns zero if a and b are equivalent, -it returns negative if a sorts before b alphabetically, -and positive if a sorts after b alphabetically.) */{ - i32_4tech i = 0, r = 0; - i32_4tech m = a.size; - if (b.size < m){ - m = b.size; - } - while (i < m && a.str[i] == b.str[i]){ - ++i; - } - - if (i < m){ - r = (a.str[i] > b.str[i]) - (b.str[i] > a.str[i]); - } - else{ - r = (a.size > b.size) - (b.size > a.size); - } - - return(r); -} - -// -// Finding Characters and Substrings -// - -CPP_NAME(find) -API_EXPORT FSTRING_LINK i32_4tech -find_c_char(char *str, i32_4tech start, char character)/* -DOC_PARAM(str, The str parameter provides a null terminated string to search.) -DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) -DOC_PARAM(character, The character parameter provides the character for which to search.) -DOC(This call returns the index of the first occurance of character, or the size of the string -if the character is not found.) */{ - i32_4tech i = start; - while (str[i] != character && str[i] != 0) ++i; - return(i); -} - -CPP_NAME(find) -API_EXPORT FSTRING_LINK i32_4tech -find_s_char(String str, i32_4tech start, char character)/* -DOC_PARAM(str, The str parameter provides a string to search.) -DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) -DOC_PARAM(character, The character parameter provides the character for which to search.) -DOC(This call returns the index of the first occurance of character, or the size of the string -if the character is not found.) */{ - i32_4tech i = start; - while (i < str.size && str.str[i] != character) ++i; - return(i); -} - -CPP_NAME(rfind) -API_EXPORT FSTRING_LINK i32_4tech -rfind_s_char(String str, i32_4tech start, char character)/* -DOC_PARAM(str, The str parameter provides a string to search.) -DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) -DOC_PARAM(character, The character parameter provides the character for which to search.) -DOC(This call looks for the largest index less than or equal to the start position where -the given character occurs. If the index is found it is returned otherwise -1 is returned.) */{ - i32_4tech i = start; - while (i >= 0 && str.str[i] != character) --i; - return(i); -} - -CPP_NAME(find) -API_EXPORT FSTRING_LINK i32_4tech -find_c_chars(char *str, i32_4tech start, char *characters)/* -DOC_PARAM(str, The str parameter provides a null terminated string to search.) -DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) -DOC_PARAM(character, The characters parameter provides a null terminated array of characters for which to search.) -DOC(This call returns the index of the first occurance of a character in the characters array, -or the size of the string if no such character is not found.) */{ - i32_4tech i = start, j; - while (str[i] != 0){ - for (j = 0; characters[j]; ++j){ - if (str[i] == characters[j]){ - return(i); - } - } - ++i; - } - return(i); -} - -CPP_NAME(find) -API_EXPORT FSTRING_LINK i32_4tech -find_s_chars(String str, i32_4tech start, char *characters)/* -DOC_PARAM(str, The str parameter provides a string to search.) -DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) -DOC_PARAM(character, The characters parameter provides a null terminated array of characters for which to search.) -DOC(This call returns the index of the first occurance of a character in the characters array, -or the size of the string if no such character is not found.) */{ - i32_4tech i = start, j; - while (i < str.size){ - for (j = 0; characters[j]; ++j){ - if (str.str[i] == characters[j]){ - return(i); - } - } - ++i; - } - return(i); -} - -CPP_NAME(find_substr) -API_EXPORT FSTRING_LINK i32_4tech -find_substr_c(char *str, i32_4tech start, String seek)/* -DOC_PARAM(str, The str parameter provides a null terminated string to search.) -DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) -DOC_PARAM(seek, The seek parameter provides a string to find in str.) -DOC(This call returns the index of the first occurance of the seek substring in str or the -size of str if no such substring in str is found.) */{ - i32_4tech i, j, k; - b32_4tech hit; - - if (seek.size == 0){ - i = str_size(str); - return(i); - } - for (i = start; str[i]; ++i){ - if (str[i] == seek.str[0]){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - if (str[k] != seek.str[j]){ - hit = 0; - break; - } - } - if (hit){ - return(i); - } - } - } - return(i); -} - -CPP_NAME(find_substr) -API_EXPORT FSTRING_LINK i32_4tech -find_substr_s(String str, i32_4tech start, String seek)/* -DOC_PARAM(str, The str parameter provides a string to search.) -DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) -DOC_PARAM(seek, The seek parameter provides a string to find in str.) -DOC(This call returns the index of the first occurance of the seek substring in str or the -size of str if no such substring in str is found.) */{ - i32_4tech stop_at, i, j, k; - b32_4tech hit; - - if (seek.size == 0){ - return str.size; - } - stop_at = str.size - seek.size + 1; - for (i = start; i < stop_at; ++i){ - if (str.str[i] == seek.str[0]){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - if (str.str[k] != seek.str[j]){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return(str.size); -} - -CPP_NAME(rfind_substr) -API_EXPORT FSTRING_LINK i32_4tech -rfind_substr_s(String str, i32_4tech start, String seek)/* -DOC_PARAM(str, The str parameter provides a string to search.) -DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) -DOC_PARAM(seek, The seek parameter provides a string to find in str.) -DOC(This call returns the index of the last occurance of the seek substring in str -or -1 if no such substring in str is found.) */{ - i32_4tech i, j, k; - b32_4tech hit; - - if (seek.size == 0){ - return -1; - } - if (start + seek.size > str.size){ - start = str.size - seek.size; - } - for (i = start; i >= 0; --i){ - if (str.str[i] == seek.str[0]){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - if (str.str[k] != seek.str[j]){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return -1; -} - -CPP_NAME(find_substr_insensitive) -API_EXPORT FSTRING_LINK i32_4tech -find_substr_insensitive_c(char *str, i32_4tech start, String seek)/* -DOC_PARAM(str, The str parameter provides a null terminated string to search.) -DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) -DOC_PARAM(seek, The seek parameter provides a string to find in str.) -DOC(This call acts as find_substr under case insensitive comparison.) -DOC_SEE(find_substr)*/{ - i32_4tech i, j, k; - b32_4tech hit; - char a_upper, b_upper; - char first_test_char; - - if (seek.size == 0){ - return str_size(str); - } - first_test_char = char_to_upper(seek.str[0]); - for (i = start; str[i]; ++i){ - a_upper = char_to_upper(str[i]); - if (a_upper == first_test_char){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - a_upper = char_to_upper(str[k]); - b_upper = char_to_upper(seek.str[j]); - if (a_upper != b_upper){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return i; -} - -CPP_NAME(find_substr_insensitive) -API_EXPORT FSTRING_LINK i32_4tech -find_substr_insensitive_s(String str, i32_4tech start, String seek)/* -DOC_PARAM(str, The str parameter provides a string to search.) -DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) -DOC_PARAM(seek, The seek parameter provides a string to find in str.) -DOC(This call acts as find_substr under case insensitive comparison.) -DOC_SEE(find_substr)*/{ - i32_4tech i, j, k; - i32_4tech stop_at; - b32_4tech hit; - char a_upper, b_upper; - char first_test_char; - - if (seek.size == 0){ - return str.size; - } - stop_at = str.size - seek.size + 1; - first_test_char = char_to_upper(seek.str[0]); - for (i = start; i < stop_at; ++i){ - a_upper = char_to_upper(str.str[i]); - if (a_upper == first_test_char){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - a_upper = char_to_upper(str.str[k]); - b_upper = char_to_upper(seek.str[j]); - if (a_upper != b_upper){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return str.size; -} - -CPP_NAME(has_substr) -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -has_substr_c(char *s, String seek)/* -DOC(This call returns non-zero if the string s contains a substring equivalent to seek.) */{ - return (s[find_substr_c(s, 0, seek)] != 0); -} - -CPP_NAME(has_substr) -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -has_substr_s(String s, String seek)/* -DOC(This call returns non-zero if the string s contains a substring equivalent to seek.) */{ - return (find_substr_s(s, 0, seek) < s.size); -} - -CPP_NAME(has_substr_insensitive) -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -has_substr_insensitive_c(char *s, String seek)/* -DOC(This call returns non-zero if the string s contains a substring equivalent to seek -under case insensitive comparison.) */{ - return (s[find_substr_insensitive_c(s, 0, seek)] != 0); -} - -CPP_NAME(has_substr_insensitive) -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -has_substr_insensitive_s(String s, String seek)/* -DOC(This call returns non-zero if the string s contains a substring equivalent to seek -under case insensitive comparison.) */{ - return (find_substr_insensitive_s(s, 0, seek) < s.size); -} - -// -// String Copies and Appends -// - -CPP_NAME(copy_fast_unsafe) -API_EXPORT FSTRING_LINK i32_4tech -copy_fast_unsafe_cc(char *dest, char *src)/* -DOC(This call performs a copy from the src buffer to the dest buffer. -The copy does not stop until a null terminator is found in src. There -is no safety against overrun so dest must be large enough to contain src. -The null terminator is not written to dest. This call returns the number -of bytes coppied to dest.) */{ - char *start = dest; - while (*src != 0){ - *dest = *src; - ++dest; - ++src; - } - return (i32_4tech)(dest - start); -} - -CPP_NAME(copy_fast_unsafe) -API_EXPORT FSTRING_LINK i32_4tech -copy_fast_unsafe_cs(char *dest, String src)/* -DOC(This call performs a copy from the src string to the dest buffer. -The copy does not stop until src.size characters are coppied. There -is no safety against overrun so dest must be large enough to contain src. -The null terminator is not written to dest. This call returns the number -of bytes coppied to dest.) */{ - i32_4tech i = 0; - while (i != src.size){ - dest[i] = src.str[i]; - ++i; - } - return(src.size); -} - -CPP_NAME(copy_checked) -API_EXPORT FSTRING_LINK b32_4tech -copy_checked_ss(String *dest, String src)/* -DOC(This call performs a copy from the src string to the dest string. -The memory_size of dest is checked before any coppying is done. -This call returns non-zero on a successful copy.) */{ - char *dest_str; - i32_4tech i; - if (dest->memory_size < src.size){ - return 0; - } - dest_str = dest->str; - for (i = 0; i < src.size; ++i){ - dest_str[i] = src.str[i]; - } - dest->size = src.size; - return 1; -} - -CPP_NAME(copy_checked) -API_EXPORT FSTRING_LINK b32_4tech -copy_checked_cs(char *dest, i32_4tech dest_cap, String src)/* -DOC(This call performs a copy from the src string to the dest string. -The value dest_cap is checked before any coppying is done. -This call returns non-zero on a successful copy.) -*/{ - i32_4tech i; - if (dest_cap < src.size){ - return 0; - } - for (i = 0; i < src.size; ++i){ - dest[i] = src.str[i]; - } - return 1; -} - -CPP_NAME(copy_partial) -API_EXPORT FSTRING_LINK b32_4tech -copy_partial_sc(String *dest, char *src)/* -DOC(This call performs a copy from the src buffer to the dest string. -The memory_size of dest is checked if the entire copy cannot be performed, -as many bytes as possible are coppied to dest. This call returns non-zero -if the entire string is coppied to dest.) */{ - i32_4tech i = 0; - i32_4tech memory_size = dest->memory_size; - char *dest_str = dest->str; - while (src[i] != 0){ - if (i >= memory_size){ - return 0; - } - dest_str[i] = src[i]; - ++i; - } - dest->size = i; - return 1; -} - -CPP_NAME(copy_partial) -API_EXPORT FSTRING_LINK b32_4tech -copy_partial_ss(String *dest, String src)/* -DOC(This call performs a copy from the src string to the dest string. -The memory_size of dest is checked. If the entire copy cannot be performed, -as many bytes as possible are coppied to dest. -This call returns non-zero if the entire string is coppied to dest.) */{ - char *dest_str = dest->str; - i32_4tech memory_size = dest->memory_size; - b32_4tech result = 0; - if (memory_size >= src.size){ - result = 1; - memory_size = src.size; - } - for (i32_4tech i = 0; i < memory_size; ++i){ - dest_str[i] = src.str[i]; - } - dest->size = memory_size; - return(result); -} - -CPP_NAME(copy_partial) -API_EXPORT FSTRING_LINK b32_4tech -copy_partial_cs(char *dest, i32_4tech dest_cap, String src)/* -DOC(This call performs a copy from the src string to the dest string. -The value dest_cap is checked. If the entire copy cannot be performed, -as many bytes as possible are coppied to dest. -This call returns non-zero if the entire string is coppied to dest.) -*/{ - b32_4tech result = 0; - i32_4tech copy_size = dest_cap; - i32_4tech i; - if (dest_cap >= src.size){ - result = 1; - copy_size = src.size; - } - for (i = 0; i < copy_size; ++i){ - dest[i] = src.str[i]; - } - return(result); -} - -CPP_NAME(copy) -API_EXPORT_INLINE FSTRING_INLINE i32_4tech -copy_cc(char *dest, char *src)/* -DOC(This call performs a copy from src to dest equivalent to copy_fast_unsafe.) -DOC_SEE(copy_fast_unsafe) */{ - return copy_fast_unsafe_cc(dest, src); -} - -CPP_NAME(copy) -API_EXPORT_INLINE FSTRING_INLINE void -copy_ss(String *dest, String src)/* -DOC(This call performs a copy from src to dest equivalent to copy_checked.) -DOC_SEE(copy_checked) */{ - copy_checked_ss(dest, src); -} - -CPP_NAME(copy) -API_EXPORT_INLINE FSTRING_INLINE void -copy_sc(String *dest, char *src)/* -DOC(This call performs a copy from src to dest equivalent to copy_partial.) -DOC_SEE(copy_partial) */{ - copy_partial_sc(dest, src); -} - -CPP_NAME(append_checked) -API_EXPORT FSTRING_LINK b32_4tech -append_checked_ss(String *dest, String src)/* -DOC(This call checks if there is enough space in dest's underlying memory -to append src onto dest. If there is src is appended and the call returns non-zero.) */{ - String end; - end = tailstr(*dest); - b32_4tech result = copy_checked_ss(&end, src); - // NOTE(allen): This depends on end.size still being 0 if - // the check failed and no coppy occurred. - dest->size += end.size; - return result; -} - -CPP_NAME(append_partial) -API_EXPORT FSTRING_LINK b32_4tech -append_partial_sc(String *dest, char *src)/* -DOC(This call attemps to append as much of src into the space in dest's underlying memory -as possible. If the entire string is appended the call returns non-zero.) */{ - String end = tailstr(*dest); - b32_4tech result = copy_partial_sc(&end, src); - dest->size += end.size; - return result; -} - -CPP_NAME(append_partial) -API_EXPORT FSTRING_LINK b32_4tech -append_partial_ss(String *dest, String src)/* -DOC(This call attemps to append as much of src into the space in dest's underlying memory -as possible. If the entire string is appended the call returns non-zero.) */{ - String end = tailstr(*dest); - b32_4tech result = copy_partial_ss(&end, src); - dest->size += end.size; - return result; -} - -CPP_NAME(append) -API_EXPORT FSTRING_LINK b32_4tech -append_s_char(String *dest, char c)/* -DOC(This call attemps to append c onto dest. If there is space left in dest's underlying -memory the character is appended and the call returns non-zero.) */{ - b32_4tech result = 0; - if (dest->size < dest->memory_size){ - dest->str[dest->size++] = c; - result = 1; - } - return result; -} - -CPP_NAME(append) -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -append_ss(String *dest, String src)/* -DOC(This call is equivalent to append_partial.) DOC_SEE(append_partial) */{ - return append_partial_ss(dest, src); -} - -CPP_NAME(append) -API_EXPORT_INLINE FSTRING_INLINE b32_4tech -append_sc(String *dest, char *src)/* -DOC(This call is equivalent to append_partial.) DOC_SEE(append_partial) */{ - return append_partial_sc(dest, src); -} - -API_EXPORT FSTRING_LINK b32_4tech -terminate_with_null(String *str)/* -DOC(This call attemps to append a null terminator onto str without effecting the -size of str. This is usually called when the time comes to pass the the string to an -API that requires a null terminator. This call returns non-zero if there was a spare -byte in the strings underlying memory.) */{ - b32_4tech result = 0; - if (str->size < str->memory_size){ - str->str[str->size] = 0; - result = 1; - } - return(result); -} - -API_EXPORT FSTRING_LINK b32_4tech -append_padding(String *dest, char c, i32_4tech target_size)/* -DOC(This call pads out dest so that it has a size of target_size by appending -the padding character c until the target size is achieved. This call returns -non-zero if dest does not run out of space in the underlying memory.) */{ - b32_4tech result = 1; - i32_4tech offset = target_size - dest->size; - i32_4tech r = 0; - if (offset > 0){ - for (r = 0; r < offset; ++r){ - if (append_s_char(dest, c) == 0){ - result = 0; - break; - } - } - } - return(result); -} - - -// -// Other Edits -// - -API_EXPORT FSTRING_LINK void -string_interpret_escapes(String src, char *dst) -/* DOC(Rewrites a string with escape sequences into a flattened string. In particular: - -"\\" becomes "\" - -"\n" becomes LF - -"\t" becomes TAB - -"\"" becomes """ - -"0" becomes NULL -) */{ - i32_4tech mode = 0; - i32_4tech j = 0; - for (i32_4tech i = 0; i < src.size; ++i){ - switch (mode){ - case 0: - { - if (src.str[i] == '\\'){ - mode = 1; - } - else{ - dst[j++] = src.str[i]; - } - }break; - - case 1: - { - char c = src.str[i]; - switch (c){ - case '\\':{dst[j++] = '\\';} break; - case 'n': {dst[j++] = '\n';} break; - case 't': {dst[j++] = '\t';} break; - case '"': {dst[j++] = '"'; } break; - case '0': {dst[j++] = '\0';} break; - default: {dst[j++] = '\\'; dst[j++] = c;}break; - } - mode = 0; - }break; - } - } - dst[j] = 0; -} - -API_EXPORT FSTRING_LINK void -replace_char(String *str, char replace, char with)/* -DOC_PARAM(str, The str parameter provides the string in which replacement shall be performed.) -DOC_PARAM(replace, The replace character specifies which character should be replaced.) -DOC_PARAM(with, The with character specifies what to write into the positions where replacement occurs.) -DOC(This call replaces all occurances of character in str with another character.) */{ - char *s = str->str; - i32_4tech i = 0; - for (i = 0; i < str->size; ++i, ++s){ - if (*s == replace) *s = with; - } -} - -#if !defined(FSTRING_GUARD) -void -block_move(void *a_ptr, void *b_ptr, i32_4tech s){ - u8_4tech *a = (u8_4tech*)a_ptr; - u8_4tech *b = (u8_4tech*)b_ptr; - if (a < b){ - for (i32_4tech i = 0; i < s; ++i, ++a, ++b){ - *a = *b; - } - } - else if (a > b){ - a = a + s - 1; - b = b + s - 1; - for (i32_4tech i = 0; i < s; ++i, --a, --b){ - *a = *b; - } - } -} - -void -replace_range_str(String *str, i32_4tech first, i32_4tech one_past_last, String with){ - i32_4tech shift = with.size - (one_past_last - first); - i32_4tech new_size = str->size + shift; - if (new_size <= str->memory_size){ - if (shift != 0){ - char *tail = str->str + one_past_last; - char *new_tail_pos = tail + shift; - block_move(new_tail_pos, tail, str->size - one_past_last); - } - block_move(str->str + first, with.str, with.size); - str->size += shift; - } -} -#endif - -CPP_NAME(replace_str) -API_EXPORT FSTRING_LINK void -replace_str_ss(String *str, String replace, String with)/* -DOC_PARAM(str, The string to modify.) -DOC_PARAM(replace, A string matching the zero or more substring to be replaced within str.) -DOC_PARAM(with, The string to be placed into str in place of occurrences of replace.) -DOC(Modifies str so that every occurence of replace that was within str is gone and the string in with has taken their places.) -*/{ - i32_4tech i = 0; - for (;;){ - i = find_substr_s(*str, i, replace); - if (i >= str->size){ - break; - } - replace_range_str(str, i, i + replace.size, with); - i += with.size; - } -} - -CPP_NAME(replace_str) -API_EXPORT FSTRING_LINK void -replace_str_sc(String *str, String replace, char *with)/* -DOC_PARAM(str, The string to modify.) -DOC_PARAM(replace, A string matching the zero or more substring to be replaced within str. Must be null terminated, and will be counted, it is always faster to use a String parameter here when possible.) -DOC_PARAM(with, The string to be placed into str in place of occurrences of replace.) -DOC(Modifies str so that every occurence of replace that was within str is gone and the string in with has taken their places.) -*/{ - String w = make_string_slowly(with); - replace_str_ss(str, replace, w); -} - -CPP_NAME(replace_str) -API_EXPORT FSTRING_LINK void -replace_str_cs(String *str, char *replace, String with)/* -DOC_PARAM(str, The string to modify.) -DOC_PARAM(replace, A string matching the zero or more substring to be replaced within str.) -DOC_PARAM(with, The string to be placed into str in place of occurrences of replace. Must be null terminated, and will be counted, it is always faster to use a String parameter here when possible.) -DOC(Modifies str so that every occurence of replace that was within str is gone and the string in with has taken their places.) -*/{ - String r = make_string_slowly(replace); - replace_str_ss(str, r, with); -} - -CPP_NAME(replace_str) -API_EXPORT FSTRING_LINK void -replace_str_cc(String *str, char *replace, char *with)/* -DOC_PARAM(str, The string to modify.) -DOC_PARAM(replace, A string matching the zero or more substring to be replaced within str. Must be null terminated, and will be counted, it is always faster to use a String parameter here when possible.) -DOC_PARAM(with, The string to be placed into str in place of occurrences of replace. Must be null terminated, and will be counted, it is always faster to use a String parameter here when possible.) -DOC(Modifies str so that every occurence of replace that was within str is gone and the string in with has taken their places.) -*/{ - String r = make_string_slowly(replace); - String w = make_string_slowly(with); - replace_str_ss(str, r, w); -} - -CPP_NAME(to_lower) -API_EXPORT FSTRING_LINK void -to_lower_cc(char *src, char *dst)/* -DOC_PARAM(src, The source string to conver to lowercase. This string must be null terminated.) -DOC_PARAM(dst, The destination buffer to receive the converted string. This must be large -enough to contain all of src and a null terminator.) -DOC(Rewrites the string in src into dst with all letters lowercased. src and dst should not -overlap with the exception that src and dst may be exactly equal in order to convert the -string in place.) -*/{ - for (; *src != 0; ++src){ - *dst++ = char_to_lower(*src); - } - *dst++ = 0; -} - -CPP_NAME(to_lower) -API_EXPORT FSTRING_LINK void -to_lower_ss(String *dst, String src)/* -DOC_PARAM(dst, The destination buffer to receive the converted string. -This must have a capacity of at least the size of src.) -DOC_PARAM(src, The source string to conver to lowercase.) -DOC(Rewrites the string in src into dst. src and dst should not overlap with the exception -that src and dst may be exactly equal in order to convert the string in place.) -*/{ - i32_4tech i = 0; - i32_4tech size = src.size; - char *c = src.str; - char *d = dst->str; - - if (dst->memory_size >= size){ - for (; i < size; ++i){ - *d++ = char_to_lower(*c++); - } - dst->size = size; - } -} - -CPP_NAME(to_lower) -API_EXPORT FSTRING_LINK void -to_lower_s(String *str)/* -DOC_PARAM(str, The string to be converted to all lowercase.) -DOC(This version of to_lower converts str to lowercase in place.) -*/{ - i32_4tech i = 0; - i32_4tech size = str->size; - char *c = str->str; - for (; i < size; ++c, ++i){ - *c = char_to_lower(*c); - } -} - -CPP_NAME(to_upper) -API_EXPORT FSTRING_LINK void -to_upper_cc(char *src, char *dst)/* -DOC_PARAM(src, The source string to convert to uppercase. This string must be null terminated.) -DOC_PARAM(dst, The destination buffer to receive the converted string. -This must be large enough to contain all of src and a null terminator.) -DOC(Rewrites the string in src into dst. src and dst should not overlap with the exception -that src and dst may be exactly equal in order to convert the string in place.) -*/{ - for (; *src != 0; ++src){ - *dst++ = char_to_upper(*src); - } - *dst++ = 0; -} - -CPP_NAME(to_upper) -API_EXPORT FSTRING_LINK void -to_upper_ss(String *dst, String src)/* -DOC_PARAM(dst, The destination buffer to receive the converted string. -This must have a capacity of at least the size of src.) -DOC_PARAM(src, The source string to convert to uppercase.) -DOC(Rewrites the string in src into dst. src and dst should not overlap with the exception -that src and dst may be exactly equal in order to convert the string in place.) -*/{ - i32_4tech i = 0; - i32_4tech size = src.size; - char *c = src.str; - char *d = dst->str; - - if (dst->memory_size >= size){ - for (; i < size; ++i){ - *d++ = char_to_upper(*c++); - } - dst->size = size; - } -} - -CPP_NAME(to_upper) -API_EXPORT FSTRING_LINK void -to_upper_s(String *str)/* -DOC_PARAM(str, The string to be converted to all uppercase.) -DOC(This version of to_upper converts str to uppercase in place.) -*/{ - i32_4tech i = 0; - i32_4tech size = str->size; - char *c = str->str; - for (; i < size; ++c, ++i){ - *c = char_to_upper(*c); - } -} - -CPP_NAME(to_camel) -API_EXPORT FSTRING_LINK void -to_camel_cc(char *src, char *dst)/* -DOC_PARAM(src, The source string to convert to camel case.) -DOC_PARAM(dst, The destination buffer to receive the converted string. -This must be large enough to contain all of src and a null terminator.) -DOC(Rewrites the string in src into dst. src and dst should not overlap -with the exception that src and dst may be exactly equal in order to -convert the string in place.) -*/{ - char *c, ch; - i32_4tech is_first = 1; - for (c = src; *c != 0; ++c){ - ch = *c; - if (char_is_alpha_numeric_true(ch)){ - if (is_first){ - is_first = 0; - ch = char_to_upper(ch); - } - else{ - ch = char_to_lower(ch); - } - } - else{ - is_first = 1; - } - *dst++ = ch; - } - *dst = 0; -} - - -// -// String <-> Number Conversions -// - -API_EXPORT FSTRING_LINK i32_4tech -int_to_str_size(i32_4tech x)/* -DOC(This call returns the number of bytes required to represent x as a string.) */{ - i32_4tech size = 1; - if (x < 0){ - size = 2; - } - x /= 10; - while (x != 0){ - x /= 10; - ++size; - } - return(size); -} - -API_EXPORT FSTRING_LINK b32_4tech -int_to_str(String *dest, i32_4tech x)/* -DOC(This call writes a string representation of x into dest. If there is enough -space in dest this call returns non-zero.) */{ - b32_4tech result = 1; - char *str = dest->str; - i32_4tech memory_size = dest->memory_size; - i32_4tech size, i, j; - b32_4tech negative; - - if (x == 0){ - str[0] = '0'; - dest->size = 1; - } - else{ - size = 0; - negative = 0; - if (x < 0){ - negative = 1; - x = -x; - str[size++] = '-'; - } - while (x != 0){ - if (size == memory_size){ - result = 0; - break; - } - i = x % 10; - x /= 10; - str[size++] = (char)('0' + i); - } - if (result){ - // NOTE(allen): Start i = 0 if not negative, start i = 1 if is negative because - should not be flipped if it is negative :) - for (i = negative, j = size-1; i < j; ++i, --j){ - char temp = str[i]; - str[i] = str[j]; - str[j] = temp; - } - dest->size = size; - } - else{ - dest->size = 0; - } - } - return(result); -} - -API_EXPORT FSTRING_LINK b32_4tech -append_int_to_str(String *dest, i32_4tech x)/* -DOC(This call appends a string representation of x onto dest. If there is enough -space in dest this call returns non-zero.) */{ - String last_part = tailstr(*dest); - b32_4tech result = int_to_str(&last_part, x); - if (result){ - dest->size += last_part.size; - } - return(result); -} - -API_EXPORT FSTRING_LINK i32_4tech -u64_to_str_size(u64_4tech x)/* -DOC(This call returns the number of bytes required to represent x as a string.) */{ - i32_4tech size = 1; - x /= 10; - while (x != 0){ - x /= 10; - ++size; - } - return(size); -} - -API_EXPORT FSTRING_LINK b32_4tech -u64_to_str(String *dest, u64_4tech x)/* -DOC(This call writes a string representation of x into dest. If there is enough -space in dest this call returns non-zero.) */{ - b32_4tech result = 1; - char *str = dest->str; - i32_4tech memory_size = dest->memory_size; - i32_4tech size, i, j; - - if (x == 0){ - str[0] = '0'; - dest->size = 1; - } - else{ - size = 0; - while (x != 0){ - if (size == memory_size){ - result = 0; - break; - } - i = x % 10; - x /= 10; - str[size++] = (char)('0' + i); - } - if (result){ - for (i = 0, j = size-1; i < j; ++i, --j){ - char temp = str[i]; - str[i] = str[j]; - str[j] = temp; - } - dest->size = size; - } - else{ - dest->size = 0; - } - } - return(result); -} - -API_EXPORT FSTRING_LINK b32_4tech -append_u64_to_str(String *dest, u64_4tech x)/* -DOC(This call appends a string representation of x onto dest. If there is enough -space in dest this call returns non-zero.) */{ - String last_part = tailstr(*dest); - b32_4tech result = u64_to_str(&last_part, x); - if (result){ - dest->size += last_part.size; - } - return(result); -} - -#if !defined(FSTRING_GUARD) -typedef struct Float_To_Str_Variables{ - b32_4tech negative; - i32_4tech int_part; - i32_4tech dec_part; -} Float_To_Str_Variables; - -static Float_To_Str_Variables -get_float_vars(float x){ - Float_To_Str_Variables vars = {}; - - if (x < 0){ - vars.negative = 1; - x = -x; - } - - vars.int_part = (i32_4tech)(x); - vars.dec_part = (i32_4tech)((x - vars.int_part) * 1000); - - return(vars); -} -#endif - -API_EXPORT FSTRING_LINK i32_4tech -float_to_str_size(float x)/* -DOC(This call returns the number of bytes required to represent x as a string.) */{ - Float_To_Str_Variables vars = get_float_vars(x); - i32_4tech size = vars.negative + int_to_str_size(vars.int_part) + 1 + int_to_str_size(vars.dec_part); - return(size); -} - -API_EXPORT FSTRING_LINK b32_4tech -append_float_to_str(String *dest, float x)/* -DOC(This call writes a string representation of x into dest. If there is enough space in dest this call returns non-zero.) */{ - b32_4tech result = 1; - Float_To_Str_Variables vars = get_float_vars(x); - - if (vars.negative){ - append_s_char(dest, '-'); - } - - append_int_to_str(dest, vars.int_part); - append_s_char(dest, '.'); - append_int_to_str(dest, vars.dec_part); - - return(result); -} - -API_EXPORT FSTRING_LINK b32_4tech -float_to_str(String *dest, float x)/* -DOC(This call appends a string representation of x onto dest. If there is enough space in dest this call returns non-zero.) */{ - b32_4tech result = 1; - dest->size = 0; - append_float_to_str(dest, x); - return(result); -} - -CPP_NAME(str_is_int) -API_EXPORT FSTRING_LINK i32_4tech -str_is_int_c(char *str)/* -DOC(If str is a valid string representation of an integer, this call returns non-zero) */{ - b32_4tech result = 1; - for (; *str; ++str){ - if (!char_is_numeric(*str)){ - result = 0; - break; - } - } - return(result); -} - -CPP_NAME(str_is_int) -API_EXPORT FSTRING_LINK b32_4tech -str_is_int_s(String str)/* -DOC(If str is a valid string representation of an integer, this call returns non-zero.) */{ - b32_4tech result = 1; - for (i32_4tech i = 0; i < str.size; ++i){ - if (!char_is_numeric(str.str[i])){ - result = 0; - break; - } - } - return(result); -} - -CPP_NAME(str_to_int) -API_EXPORT FSTRING_LINK i32_4tech -str_to_int_c(char *str)/* -DOC(If str is a valid string representation of an integer, this call will return -the integer represented by the string. Otherwise this call returns zero.) */{ - i32_4tech x = 0; - for (; *str; ++str){ - if (*str >= '0' && *str <= '9'){ - x *= 10; - x += *str - '0'; - } - else{ - x = 0; - break; - } - } - return(x); -} - -CPP_NAME(str_to_int) -API_EXPORT FSTRING_LINK i32_4tech -str_to_int_s(String str)/* -DOC(If str represents a valid string representation of an integer, this call will return -the integer represented by the string. Otherwise this call returns zero.) */{ - i32_4tech x, i; - if (str.size == 0){ - x = 0; - } - else{ - x = str.str[0] - '0'; - for (i = 1; i < str.size; ++i){ - x *= 10; - x += str.str[i] - '0'; - } - } - return(x); -} - -API_EXPORT FSTRING_LINK i32_4tech -hexchar_to_int(char c)/* -DOC(If c is a valid hexadecimal digit [0-9a-fA-F] this call returns the value of -the integer value of the digit. Otherwise the return is some nonsense value.) */{ - i32_4tech x = 0; - if (c >= '0' && c <= '9'){ - x = c-'0'; - } - else if (c > 'F'){ - x = c+(10-'a'); - } - else{ - x = c+(10-'A'); - } - return(x); -} - -API_EXPORT FSTRING_LINK char -int_to_hexchar(i32_4tech x)/* -DOC(If x is in the range [0,15] this call returns the equivalent lowercase hexadecimal digit. -Otherwise the return is some nonsense value.) */{ - return (x<10)?((char)x+'0'):((char)x+'a'-10); -} - -API_EXPORT FSTRING_LINK u32_4tech -hexstr_to_int(String str)/* -DOC(This call interprets str has a hexadecimal representation of an integer and returns -the represented integer value.) */{ - u32_4tech x; - i32_4tech i; - if (str.size == 0){ - x = 0; - } - else{ - x = hexchar_to_int(str.str[0]); - for (i = 1; i < str.size; ++i){ - x *= 0x10; - x += hexchar_to_int(str.str[i]); - } - } - return(x); -} - -API_EXPORT FSTRING_LINK b32_4tech -color_to_hexstr(String *s, u32_4tech color)/* -DOC(This call fills s with the hexadecimal representation of the color. -If there is enough memory in s to represent the color this call returns non-zero.) */{ - b32_4tech result = 0; - i32_4tech i; - - if (s->memory_size == 7 || s->memory_size == 8){ - result = 1; - s->size = 6; - s->str[6] = 0; - color = color & 0x00FFFFFF; - for (i = 5; i >= 0; --i){ - s->str[i] = int_to_hexchar(color & 0xF); - color >>= 4; - } - } - else if (s->memory_size > 8){ - result = 1; - s->size = 8; - s->str[8] = 0; - for (i = 7; i >= 0; --i){ - s->str[i] = int_to_hexchar(color & 0xF); - color >>= 4; - } - } - return(result); -} - -API_EXPORT FSTRING_LINK b32_4tech -hexstr_to_color(String s, u32_4tech *out)/* -DOC(This call interprets s as a color and writes the 32-bit integer representation into out.) */{ - b32_4tech result = 0; - u32_4tech color = 0; - if (s.size == 6){ - result = 1; - color = (u32_4tech)hexstr_to_int(s); - color |= (0xFF << 24); - *out = color; - } - else if (s.size == 8){ - result = 1; - color = (u32_4tech)hexstr_to_int(s); - *out = color; - } - return(result); -} - -// -// Directory String Management -// - -CPP_NAME(reverse_seek_slash) -API_EXPORT FSTRING_LINK i32_4tech -reverse_seek_slash_pos(String str, i32_4tech pos)/* -DOC(This call searches for a slash in str by starting pos bytes from the end and going backwards.) */{ - i32_4tech i = str.size - 1 - pos; - while (i >= 0 && !char_is_slash(str.str[i])){ - --i; - } - return i; -} - -API_EXPORT_INLINE FSTRING_INLINE i32_4tech -reverse_seek_slash(String str)/* -DOC(This call searches for a slash in str by starting at the end and going backwards.) */{ - return(reverse_seek_slash_pos(str, 0)); -} - -API_EXPORT_INLINE FSTRING_INLINE String -front_of_directory(String dir)/* -DOC(This call returns a substring of dir containing only the file name or -folder name furthest to the right in the directory.) DOC_SEE(substr) */{ - return substr_tail(dir, reverse_seek_slash(dir) + 1); -} - -API_EXPORT_INLINE FSTRING_INLINE String -path_of_directory(String dir)/* -DOC(This call returns a substring of dir containing the whole path except -for the final file or folder name.) DOC_SEE(substr) */{ - return substr(dir, 0, reverse_seek_slash(dir) + 1); -} - -CPP_NAME(set_last_folder) -API_EXPORT FSTRING_LINK b32_4tech -set_last_folder_sc(String *dir, char *folder_name, char slash)/* -DOC_PARAM(dir, The dir parameter is the directory string in which to set the last folder in the directory.) -DOC_PARAM(folder_name, The folder_name parameter is a null terminated string specifying the name to set -at the end of the directory.) -DOC_PARAM(slash, The slash parameter specifies what slash to use between names in the directory.) -DOC(This call deletes the last file name or folder name in the dir string and appends the new provided one. -If there is enough memory in dir this call returns non-zero.) */{ - b32_4tech result = 0; - i32_4tech size = reverse_seek_slash(*dir) + 1; - dir->size = size; - if (append_sc(dir, folder_name)){ - if (append_s_char(dir, slash)){ - result = 1; - } - } - if (!result){ - dir->size = size; - } - return(result); -} - -CPP_NAME(set_last_folder) -API_EXPORT FSTRING_LINK b32_4tech -set_last_folder_ss(String *dir, String folder_name, char slash)/* -DOC_PARAM(dir, The dir parameter is the directory string in which to set the last folder in the directory.) -DOC_PARAM(folder_name, The folder_name parameter is a string specifying the name to set at the end of the directory.) -DOC_PARAM(slash, The slash parameter specifies what slash to use between names in the directory.) -DOC(This call deletes the last file name or folder name in the dir string and appends the new provided one. -If there is enough memory in dir this call returns non-zero.) */{ - b32_4tech result = 0; - i32_4tech size = reverse_seek_slash(*dir) + 1; - dir->size = size; - if (append_ss(dir, folder_name)){ - if (append_s_char(dir, slash)){ - result = 1; - } - } - if (!result){ - dir->size = size; - } - return(result); -} - -API_EXPORT FSTRING_LINK String -file_extension(String str)/* -DOC(This call returns a substring containing only the file extension of the provided filename.) -DOC_SEE(substr) */{ - i32_4tech i; - for (i = str.size - 1; i >= 0; --i){ - if (str.str[i] == '.') break; - } - ++i; - return(make_string(str.str+i, str.size-i)); -} - -API_EXPORT FSTRING_LINK b32_4tech -remove_extension(String *str)/* -DOC(This call attemps to delete a file extension off the end of a filename. -This call returns non-zero on success.) */{ - b32_4tech result = 0; - i32_4tech i; - for (i = str->size - 1; i >= 0; --i){ - if (str->str[i] == '.') break; - } - if (i >= 0){ - result = 1; - str->size = i + 1; - } - return(result); -} - -API_EXPORT FSTRING_LINK b32_4tech -remove_last_folder(String *str)/* -DOC(This call attemps to delete a folder or filename off the end of a path string. -This call returns non-zero on success.) */{ - b32_4tech result = 0; - i32_4tech end = reverse_seek_slash_pos(*str, 1); - if (end >= 0){ - result = 1; - str->size = end + 1; - } - return(result); -} - -CPP_NAME(string_set_match) -API_EXPORT FSTRING_LINK b32_4tech -string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index)/* -DOC_PARAM(str_set, The str_set parameter may be an array of any type. It should point at the String in the first element of the array.) -DOC_PARAM(count, The item_size parameter should describe the "stride" from one String to the next, in other words it should be the size of one element of the array.) -DOC_PARAM(count, The count parameter specifies the number of elements in the str_set array.) -DOC_PARAM(str, The str parameter specifies the string to match against the str_set.) -DOC_PARAM(match_index, If this call succeeds match_index is filled with the index into str_set where the match occurred.) -DOC(This call tries to see if str matches any of the strings in str_set. If there is a match the call succeeds and returns non-zero. The matching rule is equivalent to the matching rule for match.) -DOC_SEE(match) */{ - b32_4tech result = 0; - i32_4tech i = 0; - u8_4tech *ptr = (u8_4tech*)str_set; - for (; i < count; ++i, ptr += item_size){ - if (match_ss(*(String*)ptr, str)){ - *match_index = i; - result = 1; - break; - } - } - return(result); -} - -API_EXPORT FSTRING_LINK b32_4tech -string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_index)/* -DOC_PARAM(str_set, The str_set parameter is an array of String structs specifying matchable strings.) -DOC_PARAM(count, The count parameter specifies the number of String structs in the str_set array.) -DOC_PARAM(str, The str parameter specifies the string to match against the str_set.) -DOC_PARAM(match_index, If this call succeeds match_index is filled with the index into str_set where the match occurred.) -DOC(This call tries to see if str matches any of the strings in str_set. If there is a match the call succeeds and returns non-zero. The matching rule is equivalent to the matching rule for match.) -DOC_SEE(match) */{ - b32_4tech result = string_set_match_table(str_set, sizeof(String), count, str, match_index); - return(result); -} - -API_EXPORT FSTRING_LINK String -get_first_double_line(String source)/* -DOC_PARAM(source, the source string accross which a 'double line' iteration will occur) -DOC_RETURN(The returned value is the first 'double line' in the source string.) -DOC(A 'double line' is a string of characters delimited by two new line characters. This call begins an iteration over all the double lines in the given source string.) -DOC_SEE(get_next_double_line) -*/{ - String line = {}; - i32_4tech pos0 = find_substr_s(source, 0, make_lit_string("\n\n")); - i32_4tech pos1 = find_substr_s(source, 0, make_lit_string("\r\n\r\n")); - if (pos1 < pos0){ - pos0 = pos1; - } - line = substr(source, 0, pos0); - return(line); -} - -API_EXPORT FSTRING_LINK String -get_next_double_line(String source, String line)/* -DOC_PARAM(source, the source string accross which the 'double line' iteration is occurring) -DOC_PARAM(line, the value returned from the previous call of get_first_double_line or get_next_double_line) -DOC_RETURN(The returned value is the first 'double line' in the source string.) -DOC_SEE(get_first_double_line) -*/{ - String next = {}; - i32_4tech pos = (i32_4tech)(line.str - source.str) + line.size; - i32_4tech start = 0, pos0 = 0, pos1 = 0; - - if (pos < source.size){ - //Assert(source.str[pos] == '\n' || source.str[pos] == '\r'); - start = pos + 1; - - if (start < source.size){ - pos0 = find_substr_s(source, start, make_lit_string("\n\n")); - pos1 = find_substr_s(source, start, make_lit_string("\r\n\r\n")); - if (pos1 < pos0){ - pos0 = pos1; - } - next = substr(source, start, pos0 - start); - } - } - - return(next); -} - -API_EXPORT FSTRING_LINK String -get_next_word(String source, String prev_word)/* -DOC_PARAM(source, the source string accross which the 'word' iteration is occurring) -DOC_PARAM(line, the value returned from the previous call of get_first_word or get_next_word) -DOC_RETURN(The returned value is the first 'word' in the source string.) -DOC_SEE(get_first_word) -*/{ - - String word = {}; - i32_4tech pos0 = (i32_4tech)(prev_word.str - source.str) + prev_word.size; - i32_4tech pos1 = 0; - char c = 0; - - for (; pos0 < source.size; ++pos0){ - c = source.str[pos0]; - if (!(char_is_whitespace(c) || c == '(' || c == ')')){ - break; - } - } - - if (pos0 < source.size){ - for (pos1 = pos0; pos1 < source.size; ++pos1){ - c = source.str[pos1]; - if (char_is_whitespace(c) || c == '(' || c == ')'){ - break; - } - } - - word = substr(source, pos0, pos1 - pos0); - } - - return(word); -} - -API_EXPORT FSTRING_LINK String -get_first_word(String source)/* -DOC_PARAM(source, the source string accross which a 'word' iteration will occur) -DOC_RETURN(The returned value is the first 'word' in the source string.) -DOC(A 'word' is a string of characters delimited by whitespace or parentheses. This call begins an iteration over all the double lines in the given source string.) -DOC_SEE(get_next_word) -*/{ - String start_str = make_string(source.str, 0); - String word = get_next_word(source, start_str); - return(word); -} - -API_EXPORT FSTRING_LINK String -string_push(Partition *part, i32_4tech size)/* -DOC_PARAM(part, A partition on which the string will be allocated.) -DOC_PARAM(size, The number of bytes to allocated for the new string.) -DOC_RETURN(If successfull returns an empty string with capacity equal to the size parameter, otherwise returns a null string.)*/{ - String result = {}; - if (size > 0){ - result.str = push_array(part, char, size); - if (result.str != 0){ - result.memory_size = size; - } - } - return(result); -} - -API_EXPORT FSTRING_LINK String -string_push_copy(Partition *part, String str)/* -DOC_PARAM(part, A partition on which the string will be allocated.) -DOC_PARAM(str, The source string to copy into the new string. The copy includes a null terminator whther or not the source does.) -DOC_RETURN(If successfull returns a string copy of str, otherwise returns a null string.)*/{ - String result = {}; - if (str.str != 0){ - result.str = push_array(part, char, str.size + 1); - if (result.str != 0){ - result.memory_size = str.size + 1; - copy(&result, str); - result.str[result.size] = 0; - } - } - return(result); -} - -// TODO(allen): eliminate this. -#ifndef FSTRING_EXPERIMENTAL -#define FSTRING_EXPERIMENTAL - -// NOTE(allen): experimental section, things below here are -// not promoted to public API level yet. - -typedef struct Absolutes{ - String a[8]; - i32_4tech count; -} Absolutes; - -static void -get_absolutes(String name, Absolutes *absolutes, b32_4tech implicit_first, b32_4tech implicit_last){ - if (name.size != 0){ - i32_4tech count = 0; - i32_4tech max = (sizeof(absolutes->a)/sizeof(*absolutes->a)) - 1; - if (implicit_last) --max; - - String str; - str.str = name.str; - str.size = 0; - str.memory_size = 0; - b32_4tech prev_was_wild = 0; - - if (implicit_first){ - absolutes->a[count++] = str; - prev_was_wild = 1; - } - - i32_4tech i; - for (i = 0; i < name.size; ++i){ - if (name.str[i] == '*' && count < max){ - if (!prev_was_wild){ - str.memory_size = str.size; - absolutes->a[count++] = str; - str.size = 0; - } - str.str = name.str + i + 1; - prev_was_wild = 1; - } - else{ - ++str.size; - prev_was_wild = 0; - } - } - - str.memory_size = str.size; - absolutes->a[count++] = str; - - if (implicit_last){ - str.size = 0; - str.memory_size = 0; - absolutes->a[count++] = str; - } - - absolutes->count = count; - } - else{ - absolutes->count = 0; - } -} - -static b32_4tech -wildcard_match_c(Absolutes *absolutes, char *x, i32_4tech case_sensitive){ - b32_4tech r = 1; - - if (absolutes->count > 0){ - String *a = absolutes->a; - - b32_4tech (*match_func)(char*, String); - b32_4tech (*match_part_func)(char*, String); - - if (case_sensitive){ - match_func = match_cs; - match_part_func = match_part_cs; - } - else{ - match_func = match_insensitive_cs; - match_part_func = match_part_insensitive_cs; - } - - if (absolutes->count == 1){ - r = match_func(x, *a); - } - else{ - if (!match_part_func(x, *a)){ - r = 0; - } - else{ - String *max = a + absolutes->count - 1; - x += a->size; - ++a; - while (a < max){ - if (*x == 0){ - r = 0; - break; - } - if (match_part_func(x, *a)){ - x += a->size; - ++a; - } - else{ - ++x; - } - } - if (r && a->size > 0){ - r = 0; - while (*x != 0){ - if (match_part_func(x, *a) && *(x + a->size) == 0){ - r = 1; - break; - } - else{ - ++x; - } - } - } - } - } - } - return(r); -} - -static b32_4tech -wildcard_match_s(Absolutes *absolutes, String x, i32_4tech case_sensitive){ - terminate_with_null(&x); - return(wildcard_match_c(absolutes, x.str, case_sensitive)); -} - -#endif - -#if defined(FSTRING_IMPLEMENTATION) -#undef FSTRING_IMPLEMENTATION -#define FSTRING_IMPL_GUARD -#endif - -#if !defined(FSTRING_GUARD) -#define FSTRING_GUARD -#endif - -// BOTTOM - diff --git a/things_ive_broken.txt b/things_ive_broken.txt new file mode 100644 index 00000000..93a99d0e --- /dev/null +++ b/things_ive_broken.txt @@ -0,0 +1,21 @@ +defined(IS_CL) +defined(IS_GCC) +defined(IS_WINDOWS) +defined(IS_LINUX) +defined(IS_MAC) +FTECH_32_BIT +FTECH_64_BIT +Temp_Memory_Arena +begin_temp_memory +end_temp_memory +arena_release_all +Lister_Activation_Function_Type + +global_part +create_or_switch_to_buffer_by_name + +get_build_directory +standard_build_search +execute_standard_build + +open_all_files_in_directory_with_extension \ No newline at end of file