diff --git a/4coder_API/4coder_types.h b/4coder_API/4coder_types.h index c5e1bc84..48bf6c23 100644 --- a/4coder_API/4coder_types.h +++ b/4coder_API/4coder_types.h @@ -450,17 +450,31 @@ STRUCT Parser_String_And_Type{ /* DOC(Microsecond_Time_Stamp is a typedef of an unsigned 64 bit integer used to signify that the value is an arbitrary for a moment in time.) */ TYPEDEF u64 Microsecond_Time_Stamp; +ENUM(u32, File_Attribute_Flag){ + FileAttribute_IsDirectory = 1, +}; + +STRUCT File_Attributes{ + u64 size; + u64 last_write_time; + File_Attribute_Flag flags; +}; + /* DOC(File_Info describes the name and type of a file.) DOC_SEE(File_List) */ STRUCT File_Info{ + // TODO(allen): Can we replace file_name this with the updated string type? + // This will be API breaking in a way I can't easily wrap, but it's probably the + // right long term thing to do... Think more later. /* DOC(This field is a null terminated string specifying the name of the file.) */ char *filename; /* DOC(This field specifies the length of the filename string not counting the null terminator.) */ i32 filename_len; /* DOC(This field indicates that the description is for a folder not a file.) */ b32 folder; + // TODO(allen): Can we just stick File_Attributes in here? Or at least File_Attribute_Flag? }; /* DOC(File_List is a list of File_Info structs.) @@ -624,11 +638,6 @@ STRUCT Range_Partial_Cursor{ }; }; -STRUCT File_Attributes{ - u64 size; - u64 last_write_time; -}; - /* DOC(A markers is a location in a buffer that, once placed, is effected by edits the same way characters are effected. In particular if an edit occurs in a location in the buffer before a marker, the marker is shifted forward or backward so that it remains on the same character.) DOC_SEE(buffer_add_markers) diff --git a/4coder_api_transition_30_31.cpp b/4coder_api_transition_30_31.cpp index 0f5170c8..0a4cee45 100644 --- a/4coder_api_transition_30_31.cpp +++ b/4coder_api_transition_30_31.cpp @@ -595,12 +595,38 @@ static b32 directory_cd(Application_Links *app, char *dir, i32 *len, i32 capacity, char *rel_path, i32 rel_len){ 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; + b32 result = false; + if (relative_path.size > 0){ + if (string_match(relative_path, string_u8_litexpr("."))){ + new_directory = directory; + result = true; + } + else if (string_match(relative_path, string_u8_litexpr(".."))){ + directory = string_remove_last_folder(directory); + if (file_exists(app, (char*)directory.str, (i32)directory.size)){ + new_directory = directory; + result = true; + } + } + else{ + new_directory = string_u8_pushf(scratch, "%.*s/%.*s", + string_expand(directory), + string_expand(relative_path)); + if (file_exists(app, (char*)new_directory.str, (i32)new_directory.size)){ + result = true; + } + } + } + + if (result){ + i32 new_len = clamp_top((i32)new_directory.size, capacity); + block_copy(dir, new_directory.str, new_len); + *len = new_len; + } + return(result); } diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 2224b8c3..47e65c7c 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -7,11 +7,14 @@ #if !defined(FCODER_DEFAULT_INCLUDE_CPP) #define FCODER_DEFAULT_INCLUDE_CPP -// NOTE(allen): Define USE_OLD_STYLE_JUMPS before 4coder_default_include.cpp to get -// the direct jumps (instead of sticky jumps). +// NOTE(allen): Defines before 4coder_default_include.cpp: +// USE_OLD_STYLE_JUMPS -> use "old style" direct jumps instead of sticky jumps +// REMOVE_TRANSITION_HELPER_31 -> does not include the transition helpers for the API changes in 4.0.31 +// REMOVE_OLD_STRING -> does not include the old 4coder_string.h library. +// NOTE: You may only remove "old string" if you first remove the transition helper. -#define REMOVE_OLD_STRING #define REMOVE_TRANSITION_HELPER_31 +#define REMOVE_OLD_STRING #include "4coder_API/4coder_custom.h" diff --git a/4coder_generated/app_functions.h b/4coder_generated/app_functions.h index 8ed76c67..33f6778d 100644 --- a/4coder_generated/app_functions.h +++ b/4coder_generated/app_functions.h @@ -154,7 +154,6 @@ struct Application_Links; #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_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) @@ -338,7 +337,6 @@ typedef MEMORY_ALLOCATE_SIG(Memory_Allocate_Function); typedef MEMORY_SET_PROTECTION_SIG(Memory_Set_Protection_Function); typedef MEMORY_FREE_SIG(Memory_Free_Function); typedef FILE_GET_ATTRIBUTES_SIG(File_Get_Attributes_Function); -typedef DIRECTORY_CD_SIG(Directory_CD_Function); typedef GET_4ED_PATH_SIG(Get_4ed_Path_Function); typedef SHOW_MOUSE_CURSOR_SIG(Show_Mouse_Cursor_Function); typedef SET_EDIT_FINISHED_HOOK_REPEAT_SPEED_SIG(Set_Edit_Finished_Hook_Repeat_Speed_Function); @@ -524,7 +522,6 @@ Memory_Allocate_Function *memory_allocate; Memory_Set_Protection_Function *memory_set_protection; Memory_Free_Function *memory_free; File_Get_Attributes_Function *file_get_attributes; -Directory_CD_Function *directory_cd; Get_4ed_Path_Function *get_4ed_path; Show_Mouse_Cursor_Function *show_mouse_cursor; Set_Edit_Finished_Hook_Repeat_Speed_Function *set_edit_finished_hook_repeat_speed; @@ -709,7 +706,6 @@ Memory_Allocate_Function *memory_allocate_; Memory_Set_Protection_Function *memory_set_protection_; Memory_Free_Function *memory_free_; File_Get_Attributes_Function *file_get_attributes_; -Directory_CD_Function *directory_cd_; Get_4ed_Path_Function *get_4ed_path_; Show_Mouse_Cursor_Function *show_mouse_cursor_; Set_Edit_Finished_Hook_Repeat_Speed_Function *set_edit_finished_hook_repeat_speed_; @@ -902,7 +898,6 @@ app_links->memory_allocate_ = Memory_Allocate;\ app_links->memory_set_protection_ = Memory_Set_Protection;\ app_links->memory_free_ = Memory_Free;\ app_links->file_get_attributes_ = File_Get_Attributes;\ -app_links->directory_cd_ = Directory_CD;\ app_links->get_4ed_path_ = Get_4ed_Path;\ app_links->show_mouse_cursor_ = Show_Mouse_Cursor;\ app_links->set_edit_finished_hook_repeat_speed_ = Set_Edit_Finished_Hook_Repeat_Speed;\ @@ -1087,7 +1082,6 @@ static void* memory_allocate(Application_Links *app, i32 size){return(app->memor 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_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));} @@ -1272,7 +1266,6 @@ static void* memory_allocate(Application_Links *app, i32 size){return(app->memor 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_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));} diff --git a/4coder_generated/command_metadata.h b/4coder_generated/command_metadata.h index bc28bfa3..bb5a3a91 100644 --- a/4coder_generated/command_metadata.h +++ b/4coder_generated/command_metadata.h @@ -447,11 +447,11 @@ static Command_Metadata fcoder_metacmd_table[234] = { { 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(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, 1316 }, +{ 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, 1323 }, +{ 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, 1329 }, +{ 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, 1335 }, +{ 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, 1350 }, { 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 }, diff --git a/4coder_helper.cpp b/4coder_helper.cpp index 7537a1ea..c2a16d24 100644 --- a/4coder_helper.cpp +++ b/4coder_helper.cpp @@ -630,7 +630,6 @@ kill_buffer(Application_Links *app, Buffer_Identifier identifier, View_ID gui_vi 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); } return(result); @@ -1199,6 +1198,22 @@ file_exists(Application_Links *app, String_Const_u8 file_name){ return(attributes.last_write_time > 0); } +static b32 +file_exists_and_is_file(Application_Links *app, String_Const_u8 file_name){ + File_Attributes attributes = {}; + file_get_attributes(app, file_name, &attributes); + return(attributes.last_write_time > 0 && + !HasFlag(attributes.flags, FileAttribute_IsDirectory)); +} + +static b32 +file_exists_and_is_folder(Application_Links *app, String_Const_u8 file_name){ + File_Attributes attributes = {}; + file_get_attributes(app, file_name, &attributes); + return(attributes.last_write_time > 0 && + HasFlag(attributes.flags, FileAttribute_IsDirectory)); +} + static Data dump_file_handle(Arena *arena, FILE *file){ Data result = {}; diff --git a/4coder_project_commands.cpp b/4coder_project_commands.cpp index 83570c42..87fe0148 100644 --- a/4coder_project_commands.cpp +++ b/4coder_project_commands.cpp @@ -1159,7 +1159,7 @@ project_generate_project_4coder_file(Arena *scratch, String_Const_u8 script_path 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); + fprintf(out, "project_name = \"%.*s\";\n", string_expand(binary_file)); fprintf(out, "patterns = {\n"); fprintf(out, "\"*.c\",\n"); fprintf(out, "\"*.cpp\",\n"); @@ -1186,20 +1186,14 @@ project_generate_project_4coder_file(Arena *scratch, String_Const_u8 script_path fprintf(out, "command_list = {\n"); fprintf(out, " { .name = \"build\",\n"); fprintf(out, " .out = \"*compilation*\", .footer_panel = true, .save_dirty_files = true,\n"); - fprintf(out, " .cmd = { { \"%.*s.bat\" , .os = \"win\" },\n", - script_file.size, script_file.str); - fprintf(out, " { \"./%.*s.sh\", .os = \"linux\" },\n", - script_file.size, script_file.str); - fprintf(out, " { \"./%.*s.sh\", .os = \"mac\" }, }, },\n", - script_file.size, script_file.str); + fprintf(out, " .cmd = { { \"%.*s.bat\" , .os = \"win\" },\n", string_expand(script_file)); + fprintf(out, " { \"./%.*s.sh\", .os = \"linux\" },\n", string_expand(script_file)); + fprintf(out, " { \"./%.*s.sh\", .os = \"mac\" }, }, },\n", string_expand(script_file)); fprintf(out, " { .name = \"run\",\n"); fprintf(out, " .out = \"*run*\", .footer_panel = false, .save_dirty_files = false,\n"); - fprintf(out, " .cmd = { { \"%.*s\\\\%.*s\", .os = \"win\" },\n", - od_win.size, od_win.str, bf_win.size, bf_win.str); - fprintf(out, " { \"%.*s/%.*s\" , .os = \"linux\" },\n", - od.size, od.str, bf.size, bf.str); - fprintf(out, " { \"%.*s/%.*s\" , .os = \"mac\" }, }, },\n", - od.size, od.str, bf.size, bf.str); + fprintf(out, " .cmd = { { \"%.*s\\\\%.*s\", .os = \"win\" },\n", string_expand(od_win), string_expand(bf_win)); + fprintf(out, " { \"%.*s/%.*s\" , .os = \"linux\" },\n", string_expand(od), string_expand(bf)); + fprintf(out, " { \"%.*s/%.*s\" , .os = \"mac\" }, }, },\n", string_expand(od), string_expand(bf)); fprintf(out, "};\n"); fprintf(out, "fkey_command[1] = \"build\";\n"); diff --git a/4ed.cpp b/4ed.cpp index 04e3f092..ba258738 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -55,11 +55,11 @@ app_resume_coroutine(System_Functions *system, Application_Links *app, Coroutine } internal void -output_file_append(System_Functions *system, Models *models, Editing_File *file, String value){ +output_file_append(Models *models, Editing_File *file, String_Const_u8 value){ if (!file->is_dummy){ i32 end = buffer_size(&file->state.buffer); Edit_Behaviors behaviors = {}; - edit_single(system, models, file, make_range(end), value, behaviors); + edit_single(models->system, models, file, make_range(end), value, behaviors); } } @@ -553,7 +553,8 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings, if (arg[0] == '-' && arg[1] == '-'){ char *long_arg_name = arg+2; - if (match_cc(long_arg_name, "custom")){ + if (string_match(SCu8(long_arg_name), + string_u8_litexpr("custom"))){ mode = CLMode_Custom; continue; } @@ -605,7 +606,7 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings, case CLAct_InitialFilePosition: { if (i < argc){ - settings->initial_line = str_to_int_c(argv[i]); + settings->initial_line = (i32)string_to_integer(SCu8(argv[i]), 10); } action = CLAct_Nothing; }break; @@ -615,8 +616,8 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings, if (i + 1 < argc){ plat_settings->set_window_size = true; - i32 w = str_to_int_c(argv[i]); - i32 h = str_to_int_c(argv[i+1]); + i32 w = (i32)string_to_integer(SCu8(argv[i]), 10); + i32 h = (i32)string_to_integer(SCu8(argv[i + 1]), 10); if (w > 0){ plat_settings->window_w = w; } @@ -641,8 +642,8 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings, if (i + 1 < argc){ plat_settings->set_window_pos = true; - i32 x = str_to_int_c(argv[i]); - i32 y = str_to_int_c(argv[i+1]); + i32 x = (i32)string_to_integer(SCu8(argv[i]), 10); + i32 y = (i32)string_to_integer(SCu8(argv[i + 1]), 10); if (x > 0){ plat_settings->window_x = x; } @@ -665,7 +666,7 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings, case CLAct_FontSize: { if (i < argc){ - plat_settings->font_size = str_to_int_c(argv[i]); + plat_settings->font_size = (i32)string_to_integer(SCu8(argv[i]), 10); settings->font_size = plat_settings->font_size; } action = CLAct_Nothing; @@ -933,11 +934,7 @@ App_Init_Sig(app_init){ models->has_new_title = true; models->title_capacity = KB(4); 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); - terminate_with_null(&builder); - } + block_copy(models->title_space, WINDOW_NAME, sizeof(WINDOW_NAME)); // NOTE(allen): init system context models->system = system; @@ -1083,18 +1080,16 @@ App_Step_Sig(app_step){ if (system->cli_update_step(cli, dest, max, &amount)){ if (file != 0 && amount > 0){ amount = eol_in_place_convert_in(dest, amount); - output_file_append(system, models, file, make_string(dest, amount)); + output_file_append(models, file, SCu8(dest, amount)); edited_file = true; } } if (system->cli_end_update(cli)){ if (file != 0){ - char str_space[256]; - String str = make_fixed_width_string(str_space); - append(&str, make_lit_string("exited with code ")); - append_int_to_str(&str, cli->exit); - output_file_append(system, models, file, str); + String_Const_u8 str = string_u8_pushf(scratch, "exited with code %d", + cli->exit); + output_file_append(models, file, str); edited_file = true; } processes_to_free[processes_to_free_count++] = child_process; diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 21ee5f7f..452c9a01 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -388,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_old_from_new(string), behaviors); + edit_single(models->system, models, file, range, string, behaviors); result = true; } } @@ -2982,7 +2982,7 @@ 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, string_old_from_new(message)); + output_file_append(models, file, message); file_cursor_to_end(models->system, models, file); result = true; } @@ -3244,8 +3244,8 @@ Global_History_Edit_Group_End(Application_Links *app){ internal void font_pointers_to_face_description(Font_Pointers font, Face_Description *description){ Font_Metrics *metrics = font.metrics; - i32 len = str_size(metrics->name); - memcpy(description->font.name, metrics->name, len); + umem len = cstring_length(metrics->name); + block_copy(description->font.name, metrics->name, len); Font_Settings *settings = font.settings; description->font.in_local_font_folder = settings->stub.in_font_folder; @@ -3260,6 +3260,7 @@ internal b32 face_description_to_settings(System_Functions *system, Face_Description description, Font_Settings *settings){ b32 success = false; + String_Const_u8 desc_name = SCu8(description.font.name); if (description.font.in_local_font_folder){ i32 count = system->font.get_loadable_count(); for (i32 i = 0; i < count; ++i){ @@ -3271,9 +3272,10 @@ face_description_to_settings(System_Functions *system, Face_Description descript break; } - if (match(make_string(loadable.display_name, loadable.display_len), description.font.name)){ + String_Const_u8 loadable_name = SCu8(loadable.display_name, loadable.display_len); + if (string_match(loadable_name, desc_name)){ success = true; - memcpy(&settings->stub, &loadable.stub, sizeof(settings->stub)); + block_copy_struct(&settings->stub, &loadable.stub); break; } } @@ -3284,7 +3286,7 @@ face_description_to_settings(System_Functions *system, Face_Description descript settings->stub.load_from_path = false; settings->stub.in_font_folder = false; - settings->stub.len = str_size(description.font.name); + settings->stub.len = (i32)cstring_length(description.font.name); memcpy(settings->stub.name, description.font.name, settings->stub.len + 1); } @@ -3685,42 +3687,6 @@ File_Get_Attributes(Application_Links *app, String_Const_u8 file_name, File_Attr 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_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.) -DOC_PARAM(capacity, This parameter specifies the maximum size of the dir string.) -DOC_PARAM(rel_path, This parameter specifies the path to change to, may include '.' or '..'; it need not be null terminated.) -DOC_PARAM(rel_len, This parameter specifies the length of the rel_path string.) -DOC_RETURN(This call returns non-zero if the call succeeds.) -DOC( -This call succeeds if the new directory exists and it fits inside the dir buffer. If the call succeeds the dir buffer is filled with the new directory and len is overwritten with the length of the new string in the 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; - 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, Arena *out, String_Const_u8 *path_out) @@ -4287,7 +4253,7 @@ Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 s check->flags &= ~FoundString_Sensitive; } - if(char_to_lower(a) != char_to_lower(b)) + if(character_to_lower(a) != character_to_lower(b)) { valid = false; break; @@ -4302,7 +4268,7 @@ Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 s full = full && (trailing_char_at < size); if(full) { - if(char_is_alpha_numeric(data[trailing_char_at]) || (data[trailing_char_at] == '_')) + if(character_is_alpha_numeric(data[trailing_char_at])) { check->flags &= ~FoundString_CleanEdges; } @@ -4356,7 +4322,7 @@ Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 s exact_matched = 0; } - if(char_to_lower(a) != char_to_lower(b)) + if(character_to_lower(a) != character_to_lower(b)) { lower_matched = false; break; @@ -4391,7 +4357,7 @@ Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 s if(full) { - if(char_is_alpha_numeric(data[trailing_char_at]) || (data[trailing_char_at] == '_')) + if(character_is_alpha_numeric(data[trailing_char_at])) { found->flags &= ~FoundString_CleanEdges; } @@ -4412,7 +4378,7 @@ Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 s } } - if(char_is_alpha(data[at]) || (data[at] == '_')) + if(character_is_alpha(data[at])) { clean_edegs = 0; } diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index ef3d6597..eb653308 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -9,7 +9,7 @@ // TOP -//#define REMOVE_OLD_STRING +#define REMOVE_OLD_STRING // TODO(allen): get away from string.h #include @@ -21,6 +21,7 @@ #include "4ed_system.h" #include "4coder_base_types.cpp" +#include "4coder_stringf.cpp" #include "4coder_app_links_allocator.cpp" #include "4coder_lib/4coder_arena.cpp" diff --git a/4ed_edit.cpp b/4ed_edit.cpp index e21cf70e..6335c9aa 100644 --- a/4ed_edit.cpp +++ b/4ed_edit.cpp @@ -229,10 +229,10 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E } internal void -edit_single(System_Functions *system, Models *models, Editing_File *file, Range range, String string, Edit_Behaviors behaviors){ +edit_single(System_Functions *system, Models *models, Editing_File *file, Range range, String_Const_u8 string, Edit_Behaviors behaviors){ Edit edit = {}; - edit.str = string.str; - edit.length = string.size; + edit.str = (char*)string.str; + edit.length = (i32)string.size; edit.range = range; @@ -323,14 +323,14 @@ edit_batch(System_Functions *system, Models *models, Editing_File *file, char *s Buffer_Edit *one_past_last = edits + edit_count; i32 shift = 0; for (;edit_in < one_past_last; edit_in += 1){ - String insert_string = make_string(str + edit_in->str_start, edit_in->len); - Range edit_range = {edit_in->start, edit_in->end}; + String_Const_u8 insert_string = SCu8(str + edit_in->str_start, edit_in->len); + Range edit_range = make_range(edit_in->start, edit_in->end); edit_range.first += shift; edit_range.one_past_last += shift; i32 size = buffer_size(&file->state.buffer); if (0 <= edit_range.first && edit_range.first <= edit_range.one_past_last && edit_range.one_past_last <= size){ edit_single(system, models, file, edit_range, insert_string, behaviors); - shift += replace_range_compute_shift(edit_range, insert_string.size); + shift += replace_range_compute_shift(edit_range, (i32)insert_string.size); } else{ result = false; @@ -362,8 +362,8 @@ edit__apply_record_forward(System_Functions *system, Models *models, Editing_Fil switch (record->kind){ case RecordKind_Single: { - String str = make_string(record->single.str_forward, record->single.length_forward); - Range range = {record->single.first, record->single.first + record->single.length_backward}; + String_Const_u8 str = SCu8(record->single.str_forward, record->single.length_forward); + Range range = make_range(record->single.first, record->single.first + record->single.length_backward); edit_single(system, models, file, range, str, behaviors_prototype); }break; @@ -393,8 +393,8 @@ edit__apply_record_backward(System_Functions *system, Models *models, Editing_Fi switch (record->kind){ case RecordKind_Single: { - String str = make_string(record->single.str_backward, record->single.length_backward); - Range range = {record->single.first, record->single.first + record->single.length_forward}; + String_Const_u8 str = SCu8(record->single.str_backward, record->single.length_backward); + Range range = make_range(record->single.first, record->single.first + record->single.length_forward); edit_single(system, models, file, range, str, behaviors_prototype); }break; @@ -566,7 +566,7 @@ create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags) i32 size = buffer_size(&file->state.buffer); if (size > 0){ Edit_Behaviors behaviors = {}; - edit_single(system, models, file, make_range(0, size), make_lit_string(""), behaviors); + edit_single(system, models, file, make_range(0, size), string_u8_litexpr(""), behaviors); if (has_canon_name){ buffer_is_for_new_file = true; } diff --git a/4ed_system.h b/4ed_system.h index 0814e184..9984657c 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -208,6 +208,8 @@ typedef Sys_Memory_Set_Protection_Sig(System_Memory_Set_Protection); typedef Sys_Memory_Free_Sig(System_Memory_Free); // file system + +// TODO(allen): eliminate #define Sys_Directory_CD_Sig(name) b32 name(char *dir, i32 *len, i32 cap, char *rel_path, i32 rel_len) typedef Sys_Directory_CD_Sig(System_Directory_CD); @@ -284,6 +286,7 @@ struct System_Functions{ System_Memory_Set_Protection *memory_set_protection; System_Memory_Free *memory_free; + // TODO(allen): eliminate System_Directory_CD *directory_cd; System_Get_Current_Path *get_current_path; System_Get_4ed_Path *get_4ed_path; diff --git a/platform_all/4ed_link_system_functions.cpp b/platform_all/4ed_link_system_functions.cpp index 83ab30f8..0782fca3 100644 --- a/platform_all/4ed_link_system_functions.cpp +++ b/platform_all/4ed_link_system_functions.cpp @@ -57,6 +57,7 @@ link_system_code(){ SYSLINK(memory_set_protection); SYSLINK(memory_free); + // TODO(allen): eliminate SYSLINK(directory_cd); SYSLINK(get_current_path); SYSLINK(get_4ed_path); diff --git a/platform_all/4ed_shared_file_handling.cpp b/platform_all/4ed_shared_file_handling.cpp index 9d336634..25994f89 100644 --- a/platform_all/4ed_shared_file_handling.cpp +++ b/platform_all/4ed_shared_file_handling.cpp @@ -9,6 +9,7 @@ // TOP +// TODO(allen): eliminate internal Sys_Directory_CD_Sig(system_directory_cd){ String directory = make_string_cap(dir, *len, cap); diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index 319723e3..2e96a2fe 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -1068,7 +1068,7 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){ win32vars.clip_post.size = str.size; } else{ - LOGF("Failed to allocate buffer for clipboard post (%d)\n", str.size + 1); + LOGF("Failed to allocate buffer for clipboard post (%d)\n", (i32)str.size + 1); } } diff --git a/platform_win32/win32_4ed_functions.cpp b/platform_win32/win32_4ed_functions.cpp index a4310796..77fc850f 100644 --- a/platform_win32/win32_4ed_functions.cpp +++ b/platform_win32/win32_4ed_functions.cpp @@ -339,6 +339,13 @@ Sys_Get_Canonical_Sig(system_get_canonical){ return(result); } +internal File_Attribute_Flag +win32_convert_file_attribute_flags(DWORD dwFileAttributes){ + File_Attribute_Flag result = {}; + MovFlag(dwFileAttributes, FILE_ATTRIBUTE_DIRECTORY, result, FileAttribute_IsDirectory); + return(result); +} + internal File_Attributes win32_file_attributes_from_HANDLE(HANDLE file){ BY_HANDLE_FILE_INFORMATION info = {}; @@ -346,6 +353,7 @@ win32_file_attributes_from_HANDLE(HANDLE file){ File_Attributes result = {}; result.size = ((u64)info.nFileSizeHigh << 32LL) | ((u64)info.nFileSizeLow); result.last_write_time = ((u64)info.ftLastWriteTime.dwHighDateTime << 32LL) | ((u64)info.ftLastWriteTime.dwLowDateTime); + result.flags = win32_convert_file_attribute_flags(info.dwFileAttributes); return(result); } @@ -356,6 +364,7 @@ Sys_Quick_File_Attributes_Sig(system_quick_file_attributes){ if (GetFileAttributesEx_utf8String(&shared_vars.scratch, file_name, GetFileExInfoStandard, &info)){ result.size = ((u64)info.nFileSizeHigh << 32LL) | ((u64)info.nFileSizeLow); result.last_write_time = ((u64)info.ftLastWriteTime.dwHighDateTime << 32LL) | ((u64)info.ftLastWriteTime.dwLowDateTime); + result.flags = win32_convert_file_attribute_flags(info.dwFileAttributes); } return(result); }