diff --git a/4coder_API/app_functions.h b/4coder_API/app_functions.h index 357ef1f1..5f1ab6f7 100644 --- a/4coder_API/app_functions.h +++ b/4coder_API/app_functions.h @@ -1,18 +1,18 @@ struct Application_Links; #define EXEC_COMMAND_SIG(n) bool32 n(Application_Links *app, Command_ID command_id) #define EXEC_SYSTEM_COMMAND_SIG(n) bool32 n(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags) -#define CLIPBOARD_POST_SIG(n) void n(Application_Links *app, int32_t clipboard_id, char *str, size_t len) -#define CLIPBOARD_COUNT_SIG(n) uint32_t n(Application_Links *app, uint32_t clipboard_id) -#define CLIPBOARD_INDEX_SIG(n) size_t n(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len) +#define CLIPBOARD_POST_SIG(n) void n(Application_Links *app, int32_t clipboard_id, char *str, int32_t len) +#define CLIPBOARD_COUNT_SIG(n) int32_t n(Application_Links *app, int32_t clipboard_id) +#define CLIPBOARD_INDEX_SIG(n) int32_t n(Application_Links *app, int32_t clipboard_id, int32_t item_index, char *out, int32_t len) #define GET_BUFFER_COUNT_SIG(n) int32_t n(Application_Links *app) #define GET_BUFFER_FIRST_SIG(n) Buffer_Summary n(Application_Links *app, Access_Flag access) #define GET_BUFFER_NEXT_SIG(n) void n(Application_Links *app, Buffer_Summary *buffer, Access_Flag access) #define GET_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, Buffer_ID buffer_id, Access_Flag access) #define GET_BUFFER_BY_NAME_SIG(n) Buffer_Summary n(Application_Links *app, char *name, int32_t len, Access_Flag access) -#define BUFFER_READ_RANGE_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, char *out) -#define BUFFER_REPLACE_RANGE_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, char *str, size_t len) +#define BUFFER_READ_RANGE_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *out) +#define BUFFER_REPLACE_RANGE_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *str, int32_t len) #define BUFFER_COMPUTE_CURSOR_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Buffer_Seek seek, Partial_Cursor *cursor_out) -#define BUFFER_BATCH_EDIT_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, char *str, size_t str_len, Buffer_Edit *edits, uint32_t edit_count, Buffer_Batch_Edit_Type type) +#define BUFFER_BATCH_EDIT_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, char *str, int32_t str_len, Buffer_Edit *edits, int32_t edit_count, Buffer_Batch_Edit_Type type) #define BUFFER_ADD_MARKERS_SIG(n) Marker_Handle n(Application_Links *app, Buffer_Summary *buffer, uint32_t marker_count) #define BUFFER_SET_MARKERS_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Marker_Handle marker, uint32_t first_marker_index, uint32_t marker_count, Marker *source_markers) #define BUFFER_GET_MARKERS_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Marker_Handle marker, uint32_t first_marker_index, uint32_t marker_count, Marker *markers_out) @@ -20,8 +20,8 @@ struct Application_Links; #define BUFFER_GET_SETTING_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t *value_out) #define BUFFER_SET_SETTING_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t value) #define BUFFER_TOKEN_COUNT_SIG(n) int32_t n(Application_Links *app, Buffer_Summary *buffer) -#define BUFFER_READ_TOKENS_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, size_t start_token, size_t end_token, Cpp_Token *tokens_out) -#define BUFFER_GET_TOKEN_INDEX_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, size_t pos, Cpp_Get_Token_Result *get_result) +#define BUFFER_READ_TOKENS_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out) +#define BUFFER_GET_TOKEN_INDEX_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Get_Token_Result *get_result) #define BEGIN_BUFFER_CREATION_SIG(n) bool32 n(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags) #define BUFFER_CREATION_NAME_SIG(n) bool32 n(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags) #define END_BUFFER_CREATION_SIG(n) Buffer_Summary n(Application_Links *app, Buffer_Creation_Data *data) @@ -41,9 +41,9 @@ struct Application_Links; #define VIEW_SET_CURSOR_SIG(n) bool32 n(Application_Links *app, View_Summary *view, Buffer_Seek seek, bool32 set_preferred_x) #define VIEW_SET_SCROLL_SIG(n) bool32 n(Application_Links *app, View_Summary *view, GUI_Scroll_Vars scroll) #define VIEW_SET_MARK_SIG(n) bool32 n(Application_Links *app, View_Summary *view, Buffer_Seek seek) -#define VIEW_SET_HIGHLIGHT_SIG(n) bool32 n(Application_Links *app, View_Summary *view, size_t start, size_t end, bool32 turn_on) +#define VIEW_SET_HIGHLIGHT_SIG(n) bool32 n(Application_Links *app, View_Summary *view, int32_t start, int32_t end, bool32 turn_on) #define VIEW_SET_BUFFER_SIG(n) bool32 n(Application_Links *app, View_Summary *view, Buffer_ID buffer_id, Set_Buffer_Flag flags) -#define VIEW_POST_FADE_SIG(n) bool32 n(Application_Links *app, View_Summary *view, float seconds, size_t start, size_t end, int_color color) +#define VIEW_POST_FADE_SIG(n) bool32 n(Application_Links *app, View_Summary *view, float seconds, int32_t start, int32_t end, int_color color) #define GET_USER_INPUT_SIG(n) User_Input n(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type) #define GET_COMMAND_INPUT_SIG(n) User_Input n(Application_Links *app) #define GET_MOUSE_STATE_SIG(n) Mouse_State n(Application_Links *app) @@ -60,9 +60,9 @@ struct Application_Links; #define GET_FILE_LIST_SIG(n) File_List n(Application_Links *app, char *dir, int32_t len) #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, int16_t up_key, int16_t down_key) -#define MEMORY_ALLOCATE_SIG(n) void* n(Application_Links *app, size_t size) -#define MEMORY_SET_PROTECTION_SIG(n) bool32 n(Application_Links *app, void *ptr, size_t size, Memory_Protect_Flags flags) -#define MEMORY_FREE_SIG(n) void n(Application_Links *app, void *ptr, size_t size) +#define MEMORY_ALLOCATE_SIG(n) void* n(Application_Links *app, int32_t size) +#define MEMORY_SET_PROTECTION_SIG(n) bool32 n(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags) +#define MEMORY_FREE_SIG(n) void n(Application_Links *app, void *ptr, int32_t size) #define FILE_EXISTS_SIG(n) bool32 n(Application_Links *app, char *filename, int32_t len) #define DIRECTORY_CD_SIG(n) bool32 n(Application_Links *app, char *dir, int32_t *len, int32_t capacity, char *rel_path, int32_t rel_len) #define GET_4ED_PATH_SIG(n) int32_t n(Application_Links *app, char *out, int32_t capacity) @@ -369,18 +369,18 @@ app_links->send_exit_signal_ = Send_Exit_Signal;} while(false) #if defined(ALLOW_DEP_4CODER) static inline bool32 exec_command(Application_Links *app, Command_ID command_id){return(app->exec_command(app, command_id));} static inline bool32 exec_system_command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags){return(app->exec_system_command(app, view, buffer, path, path_len, command, command_len, flags));} -static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, size_t len){(app->clipboard_post(app, clipboard_id, str, len));} -static inline uint32_t clipboard_count(Application_Links *app, uint32_t clipboard_id){return(app->clipboard_count(app, clipboard_id));} -static inline size_t clipboard_index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len){return(app->clipboard_index(app, clipboard_id, item_index, out, len));} +static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, int32_t len){(app->clipboard_post(app, clipboard_id, str, len));} +static inline int32_t clipboard_count(Application_Links *app, int32_t clipboard_id){return(app->clipboard_count(app, clipboard_id));} +static inline int32_t clipboard_index(Application_Links *app, int32_t clipboard_id, int32_t item_index, char *out, int32_t len){return(app->clipboard_index(app, clipboard_id, item_index, out, len));} static inline int32_t get_buffer_count(Application_Links *app){return(app->get_buffer_count(app));} static inline Buffer_Summary get_buffer_first(Application_Links *app, Access_Flag access){return(app->get_buffer_first(app, access));} static inline void get_buffer_next(Application_Links *app, Buffer_Summary *buffer, Access_Flag access){(app->get_buffer_next(app, buffer, access));} static inline Buffer_Summary get_buffer(Application_Links *app, Buffer_ID buffer_id, Access_Flag access){return(app->get_buffer(app, buffer_id, access));} static inline Buffer_Summary get_buffer_by_name(Application_Links *app, char *name, int32_t len, Access_Flag access){return(app->get_buffer_by_name(app, name, len, access));} -static inline bool32 buffer_read_range(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, char *out){return(app->buffer_read_range(app, buffer, start, end, out));} -static inline bool32 buffer_replace_range(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, char *str, size_t len){return(app->buffer_replace_range(app, buffer, start, end, str, len));} +static inline bool32 buffer_read_range(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *out){return(app->buffer_read_range(app, buffer, start, end, out));} +static inline bool32 buffer_replace_range(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *str, int32_t len){return(app->buffer_replace_range(app, buffer, start, end, str, len));} static inline bool32 buffer_compute_cursor(Application_Links *app, Buffer_Summary *buffer, Buffer_Seek seek, Partial_Cursor *cursor_out){return(app->buffer_compute_cursor(app, buffer, seek, cursor_out));} -static inline bool32 buffer_batch_edit(Application_Links *app, Buffer_Summary *buffer, char *str, size_t str_len, Buffer_Edit *edits, uint32_t edit_count, Buffer_Batch_Edit_Type type){return(app->buffer_batch_edit(app, buffer, str, str_len, edits, edit_count, type));} +static inline bool32 buffer_batch_edit(Application_Links *app, Buffer_Summary *buffer, char *str, int32_t str_len, Buffer_Edit *edits, int32_t edit_count, Buffer_Batch_Edit_Type type){return(app->buffer_batch_edit(app, buffer, str, str_len, edits, edit_count, type));} static inline Marker_Handle buffer_add_markers(Application_Links *app, Buffer_Summary *buffer, uint32_t marker_count){return(app->buffer_add_markers(app, buffer, marker_count));} static inline bool32 buffer_set_markers(Application_Links *app, Buffer_Summary *buffer, Marker_Handle marker, uint32_t first_marker_index, uint32_t marker_count, Marker *source_markers){return(app->buffer_set_markers(app, buffer, marker, first_marker_index, marker_count, source_markers));} static inline bool32 buffer_get_markers(Application_Links *app, Buffer_Summary *buffer, Marker_Handle marker, uint32_t first_marker_index, uint32_t marker_count, Marker *markers_out){return(app->buffer_get_markers(app, buffer, marker, first_marker_index, marker_count, markers_out));} @@ -388,8 +388,8 @@ static inline bool32 buffer_remove_markers(Application_Links *app, Buffer_Summar static inline bool32 buffer_get_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t *value_out){return(app->buffer_get_setting(app, buffer, setting, value_out));} static inline bool32 buffer_set_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t value){return(app->buffer_set_setting(app, buffer, setting, value));} static inline int32_t buffer_token_count(Application_Links *app, Buffer_Summary *buffer){return(app->buffer_token_count(app, buffer));} -static inline bool32 buffer_read_tokens(Application_Links *app, Buffer_Summary *buffer, size_t start_token, size_t end_token, Cpp_Token *tokens_out){return(app->buffer_read_tokens(app, buffer, start_token, end_token, tokens_out));} -static inline bool32 buffer_get_token_index(Application_Links *app, Buffer_Summary *buffer, size_t pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index(app, buffer, pos, get_result));} +static inline bool32 buffer_read_tokens(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out){return(app->buffer_read_tokens(app, buffer, start_token, end_token, tokens_out));} +static inline bool32 buffer_get_token_index(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index(app, buffer, pos, get_result));} static inline bool32 begin_buffer_creation(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags){return(app->begin_buffer_creation(app, data, flags));} static inline bool32 buffer_creation_name(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags){return(app->buffer_creation_name(app, data, filename, filename_len, flags));} static inline Buffer_Summary end_buffer_creation(Application_Links *app, Buffer_Creation_Data *data){return(app->end_buffer_creation(app, data));} @@ -409,9 +409,9 @@ static inline bool32 view_compute_cursor(Application_Links *app, View_Summary *v static inline bool32 view_set_cursor(Application_Links *app, View_Summary *view, Buffer_Seek seek, bool32 set_preferred_x){return(app->view_set_cursor(app, view, seek, set_preferred_x));} static inline bool32 view_set_scroll(Application_Links *app, View_Summary *view, GUI_Scroll_Vars scroll){return(app->view_set_scroll(app, view, scroll));} static inline bool32 view_set_mark(Application_Links *app, View_Summary *view, Buffer_Seek seek){return(app->view_set_mark(app, view, seek));} -static inline bool32 view_set_highlight(Application_Links *app, View_Summary *view, size_t start, size_t end, bool32 turn_on){return(app->view_set_highlight(app, view, start, end, turn_on));} +static inline bool32 view_set_highlight(Application_Links *app, View_Summary *view, int32_t start, int32_t end, bool32 turn_on){return(app->view_set_highlight(app, view, start, end, turn_on));} static inline bool32 view_set_buffer(Application_Links *app, View_Summary *view, Buffer_ID buffer_id, Set_Buffer_Flag flags){return(app->view_set_buffer(app, view, buffer_id, flags));} -static inline bool32 view_post_fade(Application_Links *app, View_Summary *view, float seconds, size_t start, size_t end, int_color color){return(app->view_post_fade(app, view, seconds, start, end, color));} +static inline bool32 view_post_fade(Application_Links *app, View_Summary *view, float seconds, int32_t start, int32_t end, int_color color){return(app->view_post_fade(app, view, seconds, start, end, color));} static inline User_Input get_user_input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type){return(app->get_user_input(app, get_type, abort_type));} static inline User_Input get_command_input(Application_Links *app){return(app->get_command_input(app));} static inline Mouse_State get_mouse_state(Application_Links *app){return(app->get_mouse_state(app));} @@ -428,9 +428,9 @@ static inline int32_t directory_get_hot(Application_Links *app, char *out, int32 static inline File_List get_file_list(Application_Links *app, char *dir, int32_t len){return(app->get_file_list(app, dir, len));} static inline void free_file_list(Application_Links *app, File_List list){(app->free_file_list(app, list));} static inline void set_gui_up_down_keys(Application_Links *app, int16_t up_key, int16_t down_key){(app->set_gui_up_down_keys(app, up_key, down_key));} -static inline void* memory_allocate(Application_Links *app, size_t size){return(app->memory_allocate(app, size));} -static inline bool32 memory_set_protection(Application_Links *app, void *ptr, size_t size, Memory_Protect_Flags flags){return(app->memory_set_protection(app, ptr, size, flags));} -static inline void memory_free(Application_Links *app, void *ptr, size_t size){(app->memory_free(app, ptr, size));} +static inline void* memory_allocate(Application_Links *app, int32_t size){return(app->memory_allocate(app, size));} +static inline bool32 memory_set_protection(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags){return(app->memory_set_protection(app, ptr, size, flags));} +static inline void memory_free(Application_Links *app, void *ptr, int32_t size){(app->memory_free(app, ptr, size));} static inline bool32 file_exists(Application_Links *app, char *filename, int32_t len){return(app->file_exists(app, filename, len));} static inline bool32 directory_cd(Application_Links *app, char *dir, int32_t *len, int32_t capacity, char *rel_path, int32_t rel_len){return(app->directory_cd(app, dir, len, capacity, rel_path, rel_len));} static inline int32_t get_4ed_path(Application_Links *app, char *out, int32_t capacity){return(app->get_4ed_path(app, out, capacity));} @@ -441,18 +441,18 @@ static inline void send_exit_signal(Application_Links *app){(app->send_exit_sign #else static inline bool32 exec_command(Application_Links *app, Command_ID command_id){return(app->exec_command_(app, command_id));} static inline bool32 exec_system_command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags){return(app->exec_system_command_(app, view, buffer, path, path_len, command, command_len, flags));} -static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, size_t len){(app->clipboard_post_(app, clipboard_id, str, len));} -static inline uint32_t clipboard_count(Application_Links *app, uint32_t clipboard_id){return(app->clipboard_count_(app, clipboard_id));} -static inline size_t clipboard_index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len){return(app->clipboard_index_(app, clipboard_id, item_index, out, len));} +static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, int32_t len){(app->clipboard_post_(app, clipboard_id, str, len));} +static inline int32_t clipboard_count(Application_Links *app, int32_t clipboard_id){return(app->clipboard_count_(app, clipboard_id));} +static inline int32_t clipboard_index(Application_Links *app, int32_t clipboard_id, int32_t item_index, char *out, int32_t len){return(app->clipboard_index_(app, clipboard_id, item_index, out, len));} static inline int32_t get_buffer_count(Application_Links *app){return(app->get_buffer_count_(app));} static inline Buffer_Summary get_buffer_first(Application_Links *app, Access_Flag access){return(app->get_buffer_first_(app, access));} static inline void get_buffer_next(Application_Links *app, Buffer_Summary *buffer, Access_Flag access){(app->get_buffer_next_(app, buffer, access));} static inline Buffer_Summary get_buffer(Application_Links *app, Buffer_ID buffer_id, Access_Flag access){return(app->get_buffer_(app, buffer_id, access));} static inline Buffer_Summary get_buffer_by_name(Application_Links *app, char *name, int32_t len, Access_Flag access){return(app->get_buffer_by_name_(app, name, len, access));} -static inline bool32 buffer_read_range(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, char *out){return(app->buffer_read_range_(app, buffer, start, end, out));} -static inline bool32 buffer_replace_range(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, char *str, size_t len){return(app->buffer_replace_range_(app, buffer, start, end, str, len));} +static inline bool32 buffer_read_range(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *out){return(app->buffer_read_range_(app, buffer, start, end, out));} +static inline bool32 buffer_replace_range(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *str, int32_t len){return(app->buffer_replace_range_(app, buffer, start, end, str, len));} static inline bool32 buffer_compute_cursor(Application_Links *app, Buffer_Summary *buffer, Buffer_Seek seek, Partial_Cursor *cursor_out){return(app->buffer_compute_cursor_(app, buffer, seek, cursor_out));} -static inline bool32 buffer_batch_edit(Application_Links *app, Buffer_Summary *buffer, char *str, size_t str_len, Buffer_Edit *edits, uint32_t edit_count, Buffer_Batch_Edit_Type type){return(app->buffer_batch_edit_(app, buffer, str, str_len, edits, edit_count, type));} +static inline bool32 buffer_batch_edit(Application_Links *app, Buffer_Summary *buffer, char *str, int32_t str_len, Buffer_Edit *edits, int32_t edit_count, Buffer_Batch_Edit_Type type){return(app->buffer_batch_edit_(app, buffer, str, str_len, edits, edit_count, type));} static inline Marker_Handle buffer_add_markers(Application_Links *app, Buffer_Summary *buffer, uint32_t marker_count){return(app->buffer_add_markers_(app, buffer, marker_count));} static inline bool32 buffer_set_markers(Application_Links *app, Buffer_Summary *buffer, Marker_Handle marker, uint32_t first_marker_index, uint32_t marker_count, Marker *source_markers){return(app->buffer_set_markers_(app, buffer, marker, first_marker_index, marker_count, source_markers));} static inline bool32 buffer_get_markers(Application_Links *app, Buffer_Summary *buffer, Marker_Handle marker, uint32_t first_marker_index, uint32_t marker_count, Marker *markers_out){return(app->buffer_get_markers_(app, buffer, marker, first_marker_index, marker_count, markers_out));} @@ -460,8 +460,8 @@ static inline bool32 buffer_remove_markers(Application_Links *app, Buffer_Summar static inline bool32 buffer_get_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t *value_out){return(app->buffer_get_setting_(app, buffer, setting, value_out));} static inline bool32 buffer_set_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t value){return(app->buffer_set_setting_(app, buffer, setting, value));} static inline int32_t buffer_token_count(Application_Links *app, Buffer_Summary *buffer){return(app->buffer_token_count_(app, buffer));} -static inline bool32 buffer_read_tokens(Application_Links *app, Buffer_Summary *buffer, size_t start_token, size_t end_token, Cpp_Token *tokens_out){return(app->buffer_read_tokens_(app, buffer, start_token, end_token, tokens_out));} -static inline bool32 buffer_get_token_index(Application_Links *app, Buffer_Summary *buffer, size_t pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index_(app, buffer, pos, get_result));} +static inline bool32 buffer_read_tokens(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out){return(app->buffer_read_tokens_(app, buffer, start_token, end_token, tokens_out));} +static inline bool32 buffer_get_token_index(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index_(app, buffer, pos, get_result));} static inline bool32 begin_buffer_creation(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags){return(app->begin_buffer_creation_(app, data, flags));} static inline bool32 buffer_creation_name(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags){return(app->buffer_creation_name_(app, data, filename, filename_len, flags));} static inline Buffer_Summary end_buffer_creation(Application_Links *app, Buffer_Creation_Data *data){return(app->end_buffer_creation_(app, data));} @@ -481,9 +481,9 @@ static inline bool32 view_compute_cursor(Application_Links *app, View_Summary *v static inline bool32 view_set_cursor(Application_Links *app, View_Summary *view, Buffer_Seek seek, bool32 set_preferred_x){return(app->view_set_cursor_(app, view, seek, set_preferred_x));} static inline bool32 view_set_scroll(Application_Links *app, View_Summary *view, GUI_Scroll_Vars scroll){return(app->view_set_scroll_(app, view, scroll));} static inline bool32 view_set_mark(Application_Links *app, View_Summary *view, Buffer_Seek seek){return(app->view_set_mark_(app, view, seek));} -static inline bool32 view_set_highlight(Application_Links *app, View_Summary *view, size_t start, size_t end, bool32 turn_on){return(app->view_set_highlight_(app, view, start, end, turn_on));} +static inline bool32 view_set_highlight(Application_Links *app, View_Summary *view, int32_t start, int32_t end, bool32 turn_on){return(app->view_set_highlight_(app, view, start, end, turn_on));} static inline bool32 view_set_buffer(Application_Links *app, View_Summary *view, Buffer_ID buffer_id, Set_Buffer_Flag flags){return(app->view_set_buffer_(app, view, buffer_id, flags));} -static inline bool32 view_post_fade(Application_Links *app, View_Summary *view, float seconds, size_t start, size_t end, int_color color){return(app->view_post_fade_(app, view, seconds, start, end, color));} +static inline bool32 view_post_fade(Application_Links *app, View_Summary *view, float seconds, int32_t start, int32_t end, int_color color){return(app->view_post_fade_(app, view, seconds, start, end, color));} static inline User_Input get_user_input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type){return(app->get_user_input_(app, get_type, abort_type));} static inline User_Input get_command_input(Application_Links *app){return(app->get_command_input_(app));} static inline Mouse_State get_mouse_state(Application_Links *app){return(app->get_mouse_state_(app));} @@ -500,9 +500,9 @@ static inline int32_t directory_get_hot(Application_Links *app, char *out, int32 static inline File_List get_file_list(Application_Links *app, char *dir, int32_t len){return(app->get_file_list_(app, dir, len));} static inline void free_file_list(Application_Links *app, File_List list){(app->free_file_list_(app, list));} static inline void set_gui_up_down_keys(Application_Links *app, int16_t up_key, int16_t down_key){(app->set_gui_up_down_keys_(app, up_key, down_key));} -static inline void* memory_allocate(Application_Links *app, size_t size){return(app->memory_allocate_(app, size));} -static inline bool32 memory_set_protection(Application_Links *app, void *ptr, size_t size, Memory_Protect_Flags flags){return(app->memory_set_protection_(app, ptr, size, flags));} -static inline void memory_free(Application_Links *app, void *ptr, size_t size){(app->memory_free_(app, ptr, size));} +static inline void* memory_allocate(Application_Links *app, int32_t size){return(app->memory_allocate_(app, size));} +static inline bool32 memory_set_protection(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags){return(app->memory_set_protection_(app, ptr, size, flags));} +static inline void memory_free(Application_Links *app, void *ptr, int32_t size){(app->memory_free_(app, ptr, size));} static inline bool32 file_exists(Application_Links *app, char *filename, int32_t len){return(app->file_exists_(app, filename, len));} static inline bool32 directory_cd(Application_Links *app, char *dir, int32_t *len, int32_t capacity, char *rel_path, int32_t rel_len){return(app->directory_cd_(app, dir, len, capacity, rel_path, rel_len));} static inline int32_t get_4ed_path(Application_Links *app, char *out, int32_t capacity){return(app->get_4ed_path_(app, out, capacity));} diff --git a/4coder_API/types.h b/4coder_API/types.h index b168b18c..6d9a3d6f 100644 --- a/4coder_API/types.h +++ b/4coder_API/types.h @@ -399,15 +399,15 @@ Throughout the API ranges are thought of in the form [min,max) where max is "one UNION Range{ STRUCT{ /* DOC(This is the smaller value in the range, it is also the 'start'.) */ - size_t min; + int32_t min; /* DOC(This is the larger value in the range, it is also the 'end'.) */ - size_t max; + int32_t max; }; STRUCT{ /* DOC(This is the start of the range, it is also the 'min'.) */ - size_t start; + int32_t start; /* DOC(This is the end of the range, it is also the 'max'.) */ - size_t end; + int32_t end; }; }; @@ -431,9 +431,9 @@ STRUCT File_List{ /* DOC(This field is an array of File_Info structs.) */ File_Info *infos; /* DOC(This field specifies the number of struts in the info array.) */ - int32_t count; + uint32_t count; /* DOC(This field is for internal use.) */ - int32_t block_size; + uint32_t block_size; }; /* DOC(Buffer_Identifier acts as a loosely typed description of a buffer that can either be a name or an id.) */ @@ -482,9 +482,7 @@ ENUM(int32_t, Buffer_Seek_Type){ buffer_seek_unwrapped_xy, /* DOC(This value indicates line-character positioning. These coordinates are 1 based to match standard line numbering.) */ - buffer_seek_line_char, - /* DOC(This value indicates line-character positioning, but with characters counted from the end of the line instead of the beginning, so that 1 is the last character of the line.) */ - buffer_seek_line_reverse_char, + buffer_seek_line_char }; /* DOC(Buffer_Seek describes the destination of a seek operation. There are helpers for concisely creating Buffer_Seek structs. They can be found in 4coder_buffer_types.h.) @@ -496,7 +494,7 @@ STRUCT Buffer_Seek{ UNION{ STRUCT { /* DOC(The pos field specified the pos when the seek is in absolute position.) */ - size_t pos; + int32_t pos; }; STRUCT { /* DOC(For xy coordinate seeks, rounding down means that any x in the box of the character lands on that character. For instance when clicking rounding down is the user's expected behavior. Not rounding down means that the right hand portion of the character's box, which is closer to the next character, will land on that next character. The unrounded behavior is the expected behavior when moving vertically and keeping the preferred x.) */ @@ -508,9 +506,9 @@ STRUCT Buffer_Seek{ }; STRUCT { /* DOC(The line number of a line-character type seek.) */ - size_t line; + int32_t line; /* DOC(The character number of a line-character type seek.) */ - size_t character; + int32_t character; }; }; }; @@ -519,15 +517,15 @@ STRUCT Buffer_Seek{ DOC_SEE(4coder_Buffer_Positioning_System) */ STRUCT Full_Cursor{ /* DOC(This field contains the cursor's position in absolute byte index positioning.) */ - size_t pos; + int32_t pos; /* DOC(This field contains the cursor's position in apparent character index positioning.) */ - size_t character_pos; + int32_t character_pos; /* DOC(This field contains the number of the line where the cursor is located. This field is one based.) */ - size_t line; + int32_t line; /* DOC(This field contains the number of the character from the beginninf of the line where the cursor is located. This field is one based.) */ - size_t character; + int32_t character; /* DOC(This field contains the number of the line where the cursor is located, taking the line wrapping into account. This field is one based.) */ - size_t wrap_line; + int32_t wrap_line; /* DOC(This field contains the x position measured with unwrapped lines.) */ float unwrapped_x; /* DOC(This field contains the y position measured with unwrapped lines.) */ @@ -542,24 +540,24 @@ STRUCT Full_Cursor{ DOC_SEE(4coder_Buffer_Positioning_System) */ STRUCT Partial_Cursor{ /* DOC(This field contains the cursor's position in absolute byte index positioning.) */ - size_t pos; + int32_t pos; /* DOC(This field contains the number of the character from the beginninf of the line where the cursor is located. This field is one based.) */ - size_t line; + int32_t line; /* DOC(This field contains the number of the column where the cursor is located. This field is one based.) */ - size_t character; + int32_t character; }; /* DOC(Buffer_Edit describes a range of a buffer and string to replace that range. A Buffer_Edit has to be paired with a string that contains the actual text that will be replaced into the buffer.) */ STRUCT Buffer_Edit{ /* DOC(The str_start field specifies the first character in the accompanying string that corresponds with this edit.) */ - size_t str_start; + int32_t str_start; /* DOC(The len field specifies the length of the string being written into the buffer.) */ - size_t len; + int32_t len; /* DOC(The start field specifies the start of the range in the buffer to replace in absolute position.) */ - size_t start; + int32_t start; /* DOC(The end field specifies one past the end of the range in the buffer to replace in absolute position.) */ - size_t end; + int32_t end; }; /* DOC(Buffer_Summary acts as a handle to a buffer and describes the state of the buffer.) @@ -616,7 +614,7 @@ DOC_SEE(buffer_add_markers) */ STRUCT Marker{ /* DOC(The current position of the marker measure in absolute byte positioning coordinates.) */ - size_t pos; + int32_t pos; /* DOC(When a marker is inside a range that gets edited, by default the marker 'leans_left' which means it goes to the beginning of the edited range. If the field lean_right is set to true, the marker will lean right with edits and will go to the end of edited range.) */ bool32 lean_right; }; @@ -637,15 +635,6 @@ STRUCT i32_Rect{ GLOBAL_VAR i32_Rect null_i32_rect = {0}; -STRUCT pos_Rect{ - size_t x0; - size_t y0; - size_t x1; - size_t y1; -}; - -GLOBAL_VAR pos_Rect null_pos_rect = {0}; - STRUCT f32_Rect{ float x0; float y0; @@ -735,12 +724,12 @@ STRUCT Buffer_Batch_Edit{ /* DOC(The pointer to the edit string buffer.) */ char *str; /* DOC(The length of the edit string buffer.) */ - size_t str_len; + int32_t str_len; /* DOC(The array of edits to be applied.) */ Buffer_Edit *edits; /* DOC(The number of edits in the array.) */ - uint32_t edit_count; + int32_t edit_count; }; diff --git a/4coder_API/version.h b/4coder_API/version.h index 496d6f8e..67f7e71c 100644 --- a/4coder_API/version.h +++ b/4coder_API/version.h @@ -2,6 +2,7 @@ #define MINOR 0 #define PATCH 18 +// string #define VN__(a,b,c) #a"."#b"."#c #define VN_(a,b,c) VN__(a,b,c) #define VERSION_NUMBER VN_(MAJOR,MINOR,PATCH) @@ -14,3 +15,17 @@ #endif #define VERSION VERSION_STRING VERSION_TYPE + +// long string +#define L_VN__(a,b,c) L#a L"." L#b L"." L#c +#define L_VN_(a,b,c) L_VN__(a,b,c) +#define L_VERSION_NUMBER L_VN_(MAJOR,MINOR,PATCH) +#define L_VERSION_STRING L"alpha " L_VERSION_NUMBER + +#if defined(FRED_SUPER) +#define L_VERSION_TYPE L" super!" +#else +#define L_VERSION_TYPE +#endif + +#define L_VERSION L_VERSION_STRING L_VERSION_TYPE diff --git a/4coder_auto_indent.cpp b/4coder_auto_indent.cpp index 079e15aa..9845364c 100644 --- a/4coder_auto_indent.cpp +++ b/4coder_auto_indent.cpp @@ -28,29 +28,31 @@ TYPE: 'drop-in-command-pack' // struct Hard_Start_Result{ - size_t char_pos; + int32_t char_pos; int32_t indent_pos; - bool32 all_whitespace; - bool32 all_space; + int32_t all_whitespace; + int32_t all_space; }; static Hard_Start_Result -buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, size_t line_start, int32_t tab_width){ +buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, int32_t line_start, int32_t tab_width){ Hard_Start_Result result = {0}; + char data_chunk[1024]; + Stream_Chunk stream = {0}; + char c; + + tab_width -= 1; + result.all_space = 1; result.indent_pos = 0; result.char_pos = line_start; - tab_width -= 1; - - char data_chunk[1024]; - Stream_Chunk stream = {0}; stream.add_null = 1; if (init_stream_chunk(&stream, app, buffer, line_start, data_chunk, sizeof(data_chunk))){ int32_t still_looping = 1; do{ - for (; result.char_pos < (size_t)stream.end; ++result.char_pos){ - char c = stream.data[result.char_pos]; + for (; result.char_pos < stream.end; ++result.char_pos){ + c = stream.data[result.char_pos]; if (c == '\n' || c == 0){ result.all_whitespace = 1; @@ -86,25 +88,26 @@ struct Indent_Options{ }; static Buffer_Batch_Edit -make_batch_from_indent_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line_start, size_t line_end, int32_t *indent_marks, Indent_Options opts){ +make_batch_from_indent_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line_start, int32_t line_end, int32_t *indent_marks, Indent_Options opts){ Buffer_Batch_Edit result = {0}; - size_t edit_max = line_end - line_start; - uint32_t edit_count = 0; + int32_t edit_max = line_end - line_start; + int32_t edit_count = 0; Buffer_Edit *edits = push_array(part, Buffer_Edit, edit_max); char *str_base = (char*)part->base + part->pos; - size_t str_size = 0; + int32_t str_size = 0; // NOTE(allen): Shift the array so that line_i can just operate in // it's natural value range. indent_marks -= line_start; - for (size_t line_i = line_start; line_i < line_end; ++line_i){ - size_t line_start_pos = buffer_get_line_start(app, buffer, line_i); - Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, line_start_pos, opts.tab_width); + for (int32_t line_i = line_start; line_i < line_end; ++line_i){ + int32_t line_start_pos = buffer_get_line_start(app, buffer, line_i); + Hard_Start_Result hard_start = + buffer_find_hard_start(app, buffer, line_start_pos, opts.tab_width); int32_t correct_indentation = indent_marks[line_i]; if (hard_start.all_whitespace && opts.empty_blank_lines){ @@ -156,12 +159,13 @@ make_batch_from_indent_marks(Application_Links *app, Partition *part, Buffer_Sum } static void -set_line_indents(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line_start, size_t line_end, int32_t *indent_marks, Indent_Options opts){ +set_line_indents(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line_start, int32_t line_end, int32_t *indent_marks, Indent_Options opts){ Buffer_Batch_Edit batch = make_batch_from_indent_marks(app, part, buffer, line_start, line_end, indent_marks, opts); if (batch.edit_count > 0){ - buffer_batch_edit(app, buffer, batch.str, batch.str_len, batch.edits, batch.edit_count, BatchEdit_PreserveTokens); + buffer_batch_edit(app, buffer, batch.str, batch.str_len, + batch.edits, batch.edit_count, BatchEdit_PreserveTokens); } } @@ -192,7 +196,7 @@ seek_matching_token_backwards(Cpp_Token_Array tokens, Cpp_Token *token, Cpp_Toke } static Cpp_Token* -find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t line_start, int32_t tab_width, int32_t *current_indent_out){ +find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line_start, int32_t tab_width, int32_t *current_indent_out){ Cpp_Token *token = get_first_token_at_line(app, buffer, tokens, line_start); if (token == 0 && tokens.count == 0){ @@ -220,8 +224,8 @@ find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Arra int32_t current_indent = 0; int32_t found_safe_start_position = 0; do{ - size_t line = buffer_get_line_index(app, buffer, token->start); - size_t start = buffer_get_line_start(app, buffer, line); + int32_t line = buffer_get_line_index(app, buffer, token->start); + int32_t start = buffer_get_line_start(app, buffer, line); Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, start, tab_width); current_indent = hard_start.indent_pos; @@ -294,30 +298,32 @@ struct Indent_Parse_State{ }; static int32_t* -get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t line_start, size_t line_end, bool32 exact_align, int32_t tab_width){ +get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line_start, int32_t line_end, bool32 exact_align, int32_t tab_width){ - size_t indent_mark_count = line_end - line_start; + int32_t indent_mark_count = line_end - line_start; int32_t *indent_marks = push_array(part, int32_t, indent_mark_count); // Shift the array so line_index works correctly. indent_marks -= line_start; + // Decide where to start indentation parsing. Indent_Parse_State indent = {0}; - Cpp_Token *token_ptr = find_anchor_token(app, buffer, tokens, line_start, tab_width, &indent.current_indent); + Cpp_Token *token_ptr = find_anchor_token(app, buffer, tokens, line_start, + tab_width, &indent.current_indent); if (token_ptr == 0){ - for (size_t line_index = line_start; line_index < line_end; ++line_index){ + for (int32_t line_index = line_start; line_index < line_end; ++line_index){ indent_marks[line_index] = 0; } } else{ - size_t line_index = buffer_get_line_index(app, buffer, token_ptr->start); + int32_t line_index = buffer_get_line_index(app, buffer, token_ptr->start); if (line_index > line_start){ line_index = line_start; } - size_t next_line_start_pos = buffer_get_line_start(app, buffer, line_index+1); + int32_t next_line_start_pos = buffer_get_line_start(app, buffer, line_index+1); switch (token_ptr->type){ case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += tab_width; break; @@ -347,8 +353,8 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b { int32_t previous_indent = indent.previous_line_indent; - size_t this_line_start = buffer_get_line_start(app, buffer, line_index); - size_t next_line_start = buffer_get_line_start(app, buffer, line_index+1); + int32_t this_line_start = buffer_get_line_start(app, buffer, line_index); + int32_t next_line_start = buffer_get_line_start(app, buffer, line_index+1); bool32 did_special_behavior = false; @@ -364,7 +370,7 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b this_indent = previous_indent; } else{ - uint32_t line_pos = (uint32_t)(hard_start.char_pos - this_line_start); + int32_t line_pos = hard_start.char_pos - this_line_start; this_indent = line_pos + indent.comment_shift; if (this_indent < 0){ this_indent = 0; @@ -456,24 +462,24 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b case CPP_TOKEN_COMMENT: { - size_t line = buffer_get_line_index(app, buffer, token.start); - size_t start = buffer_get_line_start(app, buffer, line); - int32_t char_pos = (int32_t)(token.start - start); - indent.comment_shift = (indent.current_indent - char_pos); - indent.previous_comment_indent = char_pos; + int32_t line = buffer_get_line_index(app, buffer, token.start); + int32_t start = buffer_get_line_start(app, buffer, line); + + indent.comment_shift = (indent.current_indent - (token.start - start)); + indent.previous_comment_indent = (token.start - start); }break; case CPP_TOKEN_PARENTHESE_OPEN: if (!(token.flags & CPP_TFLAG_PP_BODY)){ if (indent.paren_nesting < ArrayCount(indent.paren_anchor_indent)){ - size_t line = buffer_get_line_index(app, buffer, token.start); - size_t start = buffer_get_line_start(app, buffer, line); - int32_t char_pos = (int32_t)(token.start - start); + int32_t line = buffer_get_line_index(app, buffer, token.start); + int32_t start = buffer_get_line_start(app, buffer, line); + int32_t char_pos = token.start - start; Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, start, tab_width); - int32_t line_pos = (int32_t)(hard_start.char_pos - start); + int32_t line_pos = hard_start.char_pos - start; indent.paren_anchor_indent[indent.paren_nesting] = char_pos - line_pos + indent.previous_line_indent + 1; @@ -499,23 +505,27 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b } static void -get_indent_lines_minimum(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, size_t end_pos, size_t *line_start_out, size_t *line_end_out){ - size_t line_start = buffer_get_line_index(app, buffer, start_pos); - size_t line_end = buffer_get_line_index(app, buffer, end_pos) + 1; +get_indent_lines_minimum(Application_Links *app, Buffer_Summary *buffer, + int32_t start_pos, int32_t end_pos, + int32_t *line_start_out, int32_t *line_end_out){ + int32_t line_start = buffer_get_line_index(app, buffer, start_pos); + int32_t line_end = buffer_get_line_index(app, buffer, end_pos) + 1; *line_start_out = line_start; *line_end_out = line_end; } static void -get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t start_pos, size_t end_pos, size_t *line_start_out, size_t *line_end_out){ - size_t line_start = buffer_get_line_index(app, buffer, start_pos); - size_t line_end = buffer_get_line_index(app, buffer, end_pos); +get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, + int32_t start_pos, int32_t end_pos, + int32_t *line_start_out, int32_t *line_end_out){ + int32_t line_start = buffer_get_line_index(app, buffer, start_pos); + int32_t line_end = buffer_get_line_index(app, buffer, end_pos); for (;line_start > 0;){ - size_t line_start_pos = 0; + int32_t line_start_pos = 0; Cpp_Token *token = get_first_token_at_line(app, buffer, tokens, line_start, &line_start_pos); - if (token != 0 && token->start < line_start_pos){ + if (token && token->start < line_start_pos){ line_start = buffer_get_line_index(app, buffer, token->start); } else{ @@ -524,7 +534,7 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cp } for (;line_end+1 < buffer->line_count;){ - size_t next_line_start_pos = 0; + int32_t next_line_start_pos = 0; Cpp_Token *token = get_first_token_at_line(app, buffer, tokens, line_end+1, &next_line_start_pos); if (token && token->start < next_line_start_pos){ line_end = buffer_get_line_index(app, buffer, token->start+token->size); @@ -545,11 +555,12 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cp } static bool32 -buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t start, size_t end, int32_t tab_width, Auto_Indent_Flag flags){ +buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buffer, + int32_t start, int32_t end, int32_t tab_width, Auto_Indent_Flag flags){ - bool32 result = false; + bool32 result = 0; if (buffer->exists && buffer->tokens_are_ready){ - result = true; + result = 1; Temp_Memory temp = begin_temp_memory(part); @@ -562,7 +573,7 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buff // Stage 2: Decide where the first and last lines are. // The lines in the range [line_start,line_end) will be indented. - size_t line_start = 0, line_end = 0; + int32_t line_start = 0, line_end = 0; if (flags & AutoIndent_FullTokens){ get_indent_lines_whole_tokens(app, buffer, tokens, start, end, &line_start, &line_end); } @@ -574,7 +585,8 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buff // Get an array representing how much each line in // the range [line_start,line_end) should be indented. int32_t *indent_marks = - get_indentation_marks(app, part, buffer, tokens, line_start, line_end, (flags & AutoIndent_ExactAlignBlock), tab_width); + get_indentation_marks(app, part, buffer, tokens, line_start, line_end, + (flags & AutoIndent_ExactAlignBlock), tab_width); // Stage 4: Set the Line Indents Indent_Options opts = {0}; @@ -591,7 +603,8 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buff } static bool32 -buffer_auto_indent(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, int32_t tab_width, Auto_Indent_Flag flags){ +buffer_auto_indent(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, + int32_t tab_width, Auto_Indent_Flag flags){ bool32 result = buffer_auto_indent(app, &global_part, buffer, start, end, tab_width, flags); return(result); } diff --git a/4coder_base_commands.cpp b/4coder_base_commands.cpp index b47837d4..d85c0616 100644 --- a/4coder_base_commands.cpp +++ b/4coder_base_commands.cpp @@ -33,7 +33,7 @@ CUSTOM_COMMAND_SIG(write_character){ if (length != 0){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos = view.cursor.pos; + int32_t pos = view.cursor.pos; Marker next_cursor_marker = {0}; next_cursor_marker.pos = character_pos_to_pos(app, &view, &buffer, view.cursor.character_pos); @@ -56,12 +56,11 @@ CUSTOM_COMMAND_SIG(delete_char){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - Buffer_Seek seek = seek_character_pos(view.cursor.character_pos+1); - Full_Cursor cursor; - view_compute_cursor(app, &view, seek, &cursor); + int32_t start = view.cursor.pos; - size_t start = view.cursor.pos; - size_t end = cursor.pos; + Full_Cursor cursor; + view_compute_cursor(app, &view, seek_character_pos(view.cursor.character_pos+1), &cursor); + int32_t end = cursor.pos; if (0 <= start && start < buffer.size){ buffer_replace_range(app, &buffer, start, end, 0, 0); @@ -73,17 +72,15 @@ CUSTOM_COMMAND_SIG(backspace_char){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - Buffer_Seek seek = seek_character_pos(view.cursor.character_pos-1); - Full_Cursor cursor; - view_compute_cursor(app, &view, seek, &cursor); + int32_t end = view.cursor.pos; - size_t end = view.cursor.pos; - size_t start = cursor.pos; + Full_Cursor cursor; + view_compute_cursor(app, &view, seek_character_pos(view.cursor.character_pos-1), &cursor); + int32_t start = cursor.pos; if (0 < end && end <= buffer.size){ buffer_replace_range(app, &buffer, start, end, 0, 0); - seek = seek_character_pos(view.cursor.character_pos-1); - view_set_cursor(app, &view, seek, true); + view_set_cursor(app, &view, seek_character_pos(view.cursor.character_pos-1), true); } } @@ -97,8 +94,8 @@ CUSTOM_COMMAND_SIG(set_mark){ CUSTOM_COMMAND_SIG(cursor_mark_swap){ View_Summary view = get_active_view(app, AccessProtected); - size_t cursor = view.cursor.pos; - size_t mark = view.mark.pos; + int32_t cursor = view.cursor.pos; + int32_t mark = view.mark.pos; view_set_cursor(app, &view, seek_pos(mark), true); view_set_mark(app, &view, seek_pos(cursor)); @@ -250,14 +247,14 @@ CUSTOM_COMMAND_SIG(page_down){ CUSTOM_COMMAND_SIG(move_left){ uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); - size_t new_pos = view.cursor.character_pos - 1; + int32_t new_pos = view.cursor.character_pos - 1; view_set_cursor(app, &view, seek_character_pos(new_pos), 1); } CUSTOM_COMMAND_SIG(move_right){ uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); - size_t new_pos = view.cursor.character_pos + 1; + int32_t new_pos = view.cursor.character_pos + 1; view_set_cursor(app, &view, seek_character_pos(new_pos), 1); } @@ -277,7 +274,7 @@ CUSTOM_COMMAND_SIG(seek_whitespace_up){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t new_pos = buffer_seek_whitespace_up(app, &buffer, view.cursor.pos); + int32_t new_pos = buffer_seek_whitespace_up(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -286,7 +283,7 @@ CUSTOM_COMMAND_SIG(seek_whitespace_down){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t new_pos = buffer_seek_whitespace_down(app, &buffer, view.cursor.pos); + int32_t new_pos = buffer_seek_whitespace_down(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -295,7 +292,7 @@ CUSTOM_COMMAND_SIG(seek_end_of_textual_line){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t new_pos = seek_line_end(app, &buffer, view.cursor.pos); + int32_t new_pos = seek_line_end(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -304,7 +301,7 @@ CUSTOM_COMMAND_SIG(seek_beginning_of_textual_line){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t new_pos = seek_line_beginning(app, &buffer, view.cursor.pos); + int32_t new_pos = seek_line_beginning(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -350,7 +347,7 @@ CUSTOM_COMMAND_SIG(to_uppercase){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen); Range range = get_range(&view); - size_t size = range.max - range.min; + int32_t size = range.max - range.min; if (size <= app->memory_size){ char *mem = (char*)app->memory; @@ -368,7 +365,7 @@ CUSTOM_COMMAND_SIG(to_lowercase){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen); Range range = get_range(&view); - size_t size = range.max - range.min; + int32_t size = range.max - range.min; if (size <= app->memory_size){ char *mem = (char*)app->memory; @@ -568,7 +565,7 @@ CUSTOM_COMMAND_SIG(search); CUSTOM_COMMAND_SIG(reverse_search); static void -isearch(Application_Links *app, bool32 start_reversed){ +isearch(Application_Links *app, int32_t start_reversed){ uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); @@ -579,10 +576,10 @@ isearch(Application_Links *app, bool32 start_reversed){ Query_Bar bar = {0}; if (start_query_bar(app, &bar, 0) == 0) return; - bool32 reverse = start_reversed; - size_t pos = view.cursor.pos; - size_t start_pos = pos; - size_t first_pos = pos; + int32_t reverse = start_reversed; + int32_t pos = view.cursor.pos; + int32_t start_pos = pos; + int32_t first_pos = pos; Range match = make_range(pos, pos); char bar_string_space[256]; @@ -645,16 +642,16 @@ isearch(Application_Links *app, bool32 start_reversed){ } if (in.key.keycode != key_back){ - char *str = bar.string.str; - size_t str_size = bar.string.size; - size_t new_pos = 0; + int32_t new_pos; if (reverse){ - buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1, 0, str, str_size, &new_pos); + buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1, 0, + bar.string.str, bar.string.size, &new_pos); if (new_pos >= 0){ if (step_backward){ pos = new_pos; start_pos = new_pos; - buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1, 0, str, str_size, &new_pos); + buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1, 0, + bar.string.str, bar.string.size, &new_pos); if (new_pos < 0) new_pos = start_pos; } match.start = new_pos; @@ -662,13 +659,14 @@ isearch(Application_Links *app, bool32 start_reversed){ } } else{ - buffer_seek_string_insensitive_forward(app, &buffer, start_pos + 1, 0, str, str_size, &new_pos); + buffer_seek_string_insensitive_forward(app, &buffer, start_pos + 1, 0, + bar.string.str, bar.string.size, &new_pos); if (new_pos < buffer.size){ if (step_forward){ pos = new_pos; start_pos = new_pos; buffer_seek_string_insensitive_forward(app, &buffer, start_pos + 1, 0, - str, str_size, &new_pos); + bar.string.str, bar.string.size, &new_pos); if (new_pos >= buffer.size) new_pos = start_pos; } match.start = new_pos; @@ -723,8 +721,9 @@ CUSTOM_COMMAND_SIG(replace_in_range){ Range range = get_range(&view); - size_t pos = range.min; - size_t new_pos = 0; + int32_t pos, new_pos; + pos = range.min; + buffer_seek_string_forward(app, &buffer, pos, 0, r.str, r.size, &new_pos); while (new_pos + r.size <= range.end){ @@ -752,21 +751,25 @@ CUSTOM_COMMAND_SIG(query_replace){ if (!query_user_string(app, &with)) return; - String r = replace.string; - String w = with.string; + String r, w; + r = replace.string; + w = with.string; Query_Bar bar; + Buffer_Summary buffer; + View_Summary view; + int32_t pos, new_pos; + bar.prompt = make_lit_string("Replace? (y)es, (n)ext, (esc)\n"); bar.string = null_string; start_query_bar(app, &bar, 0); uint32_t access = AccessOpen; - View_Summary view = get_active_view(app, access); - Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); + view = get_active_view(app, access); + buffer = get_buffer(app, view.buffer_id, access); - size_t pos = view.cursor.pos; - size_t new_pos = 0; + pos = view.cursor.pos; buffer_seek_string_forward(app, &buffer, pos, 0, r.str, r.size, &new_pos); User_Input in = {0}; diff --git a/4coder_clipboard.cpp b/4coder_clipboard.cpp index b0dfbf6a..56e13c01 100644 --- a/4coder_clipboard.cpp +++ b/4coder_clipboard.cpp @@ -14,14 +14,14 @@ TYPE: 'drop-in-command-pack' #include "4coder_helper/4coder_helper.h" static bool32 -clipboard_copy(Application_Links *app, size_t start, size_t end, Buffer_Summary *buffer_out, uint32_t access){ +clipboard_copy(Application_Links *app, int32_t start, int32_t end, Buffer_Summary *buffer_out, uint32_t access){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); bool32 result = 0; if (buffer.exists){ if (0 <= start && start <= end && end <= buffer.size){ - size_t size = (end - start); + int32_t size = (end - start); char *str = (char*)app->memory; if (size <= app->memory_size){ @@ -36,16 +36,14 @@ clipboard_copy(Application_Links *app, size_t start, size_t end, Buffer_Summary return(result); } -static bool32 -clipboard_cut(Application_Links *app, size_t start, size_t end, Buffer_Summary *buffer_out, uint32_t access){ +static int32_t +clipboard_cut(Application_Links *app, int32_t start, int32_t end, Buffer_Summary *buffer_out, uint32_t access){ Buffer_Summary buffer = {0}; - bool32 result = false; + int32_t result = false; if (clipboard_copy(app, start, end, &buffer, access)){ buffer_replace_range(app, &buffer, start, end, 0, 0); - if (buffer_out){ - *buffer_out = buffer; - } + if (buffer_out){*buffer_out = buffer;} } return(result); @@ -76,7 +74,7 @@ CUSTOM_COMMAND_SIG(paste){ int32_t paste_index = 0; view_paste_index[view.view_id].index = paste_index; - size_t len = clipboard_index(app, 0, paste_index, 0, 0); + int32_t len = clipboard_index(app, 0, paste_index, 0, 0); char *str = 0; if (len <= app->memory_size){ @@ -87,7 +85,7 @@ CUSTOM_COMMAND_SIG(paste){ clipboard_index(app, 0, paste_index, str, len); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos = view.cursor.pos; + int32_t pos = view.cursor.pos; buffer_replace_range(app, &buffer, pos, pos, str, len); view_set_mark(app, &view, seek_pos(pos)); view_set_cursor(app, &view, seek_pos(pos + len), true); @@ -113,7 +111,7 @@ CUSTOM_COMMAND_SIG(paste_next){ int32_t paste_index = view_paste_index[view.view_id].index + 1; view_paste_index[view.view_id].index = paste_index; - size_t len = clipboard_index(app, 0, paste_index, 0, 0); + int32_t len = clipboard_index(app, 0, paste_index, 0, 0); char *str = 0; if (len <= app->memory_size){ @@ -125,7 +123,7 @@ CUSTOM_COMMAND_SIG(paste_next){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); Range range = get_range(&view); - size_t pos = range.min; + int32_t pos = range.min; buffer_replace_range(app, &buffer, range.min, range.max, str, len); view_set_cursor(app, &view, seek_pos(pos + len), true); diff --git a/4coder_default_framework.h b/4coder_default_framework.h index 8d7afe16..d039ca8e 100644 --- a/4coder_default_framework.h +++ b/4coder_default_framework.h @@ -322,16 +322,16 @@ struct Config_Item{ struct Config_Array_Reader{ Cpp_Token_Array array; char *mem; - uint32_t i; - uint32_t val_array_end; + int32_t i; + int32_t val_array_end; bool32 good; }; static Cpp_Token -read_config_token(Cpp_Token_Array array, uint32_t *i_ptr){ +read_config_token(Cpp_Token_Array array, int32_t *i_ptr){ Cpp_Token token = {0}; - uint32_t i = *i_ptr; + int32_t i = *i_ptr; for (; i < array.count; ++i){ Cpp_Token comment_token = array.tokens[i]; @@ -350,10 +350,10 @@ read_config_token(Cpp_Token_Array array, uint32_t *i_ptr){ } static Config_Line -read_config_line(Cpp_Token_Array array, uint32_t *i_ptr){ +read_config_line(Cpp_Token_Array array, int32_t *i_ptr){ Config_Line config_line = {0}; - uint32_t i = *i_ptr; + int32_t i = *i_ptr; config_line.id_token = read_config_token(array, &i); if (config_line.id_token.type == CPP_TOKEN_IDENTIFIER){ @@ -723,7 +723,7 @@ process_config_file(Application_Links *app){ int32_t new_wrap_width = default_wrap_width; int32_t new_min_base_width = default_min_base_width; - for (uint32_t i = 0; i < array.count; ++i){ + for (int32_t i = 0; i < array.count; ++i){ Config_Line config_line = read_config_line(array, &i); if (config_line.read_success){ diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 28e17112..45a9aaa7 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -42,9 +42,9 @@ TYPE: 'major-system-include' // Seeks Using Default Framework Memory // -static size_t -buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags){ - size_t result = buffer_boundary_seek(app, buffer, &global_part, start_pos, seek_forward, flags); +static int32_t +buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags){ + int32_t result = buffer_boundary_seek(app, buffer, &global_part, start_pos, seek_forward, flags); return(result); } @@ -53,7 +53,7 @@ basic_seek(Application_Links *app, int32_t seek_type, uint32_t flags){ uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos = buffer_boundary_seek(app, &buffer, view.cursor.pos, seek_type, flags); + int32_t pos = buffer_boundary_seek(app, &buffer, view.cursor.pos, seek_type, flags); view_set_cursor(app, &view, seek_pos(pos), true); } @@ -85,10 +85,12 @@ CUSTOM_COMMAND_SIG(backspace_word){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); if (buffer.exists){ - size_t pos2 = view.cursor.pos; + int32_t pos2 = 0, pos1 = 0; + + pos2 = view.cursor.pos; exec_command(app, seek_alphanumeric_left); refresh_view(app, &view); - size_t pos1 = view.cursor.pos; + pos1 = view.cursor.pos; buffer_replace_range(app, &buffer, pos1, pos2, 0, 0); } @@ -101,10 +103,12 @@ CUSTOM_COMMAND_SIG(delete_word){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); if (buffer.exists){ - size_t pos1 = view.cursor.pos; + int32_t pos2 = 0, pos1 = 0; + + pos1 = view.cursor.pos; exec_command(app, seek_alphanumeric_right); refresh_view(app, &view); - size_t pos2 = view.cursor.pos; + pos2 = view.cursor.pos; buffer_replace_range(app, &buffer, pos1, pos2, 0, 0); } @@ -112,11 +116,12 @@ CUSTOM_COMMAND_SIG(delete_word){ CUSTOM_COMMAND_SIG(snipe_token_or_word){ uint32_t access = AccessOpen; + View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos1 = buffer_boundary_seek(app, &buffer, view.cursor.pos, 0, BoundaryToken | BoundaryWhitespace); - size_t pos2 = buffer_boundary_seek(app, &buffer, pos1, 1, BoundaryToken | BoundaryWhitespace); + int32_t pos1 = buffer_boundary_seek(app, &buffer, view.cursor.pos, 0, BoundaryToken | BoundaryWhitespace); + int32_t pos2 = buffer_boundary_seek(app, &buffer, pos1, 1, BoundaryToken | BoundaryWhitespace); Range range = make_range(pos1, pos2); buffer_replace_range(app, &buffer, range.start, range.end, 0, 0); @@ -141,7 +146,7 @@ CUSTOM_COMMAND_SIG(duplicate_line){ ++line_string.memory_size; append_s_char(&line_string, '\n'); - size_t pos = buffer_get_line_end(app, &buffer, view.cursor.line) + 1; + int32_t pos = buffer_get_line_end(app, &buffer, view.cursor.line) + 1; buffer_replace_range(app, &buffer, pos, pos, line_string.str, line_string.size); end_temp_memory(temp); @@ -154,8 +159,8 @@ CUSTOM_COMMAND_SIG(delete_line){ Partition *part = &global_part; Temp_Memory temp = begin_temp_memory(part); - size_t start = buffer_get_line_start(app, &buffer, view.cursor.line); - size_t end = buffer_get_line_end(app, &buffer, view.cursor.line) + 1; + int32_t start = buffer_get_line_start(app, &buffer, view.cursor.line); + int32_t end = buffer_get_line_end(app, &buffer, view.cursor.line) + 1; buffer_replace_range(app, &buffer, start, end, 0, 0); @@ -201,7 +206,7 @@ long_braces(Application_Links *app, char *text, int32_t size){ uint32_t access = AccessOpen; View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos = view.cursor.pos; + int32_t pos = view.cursor.pos; buffer_replace_range(app, &buffer, pos, pos, text, size); view_set_cursor(app, &view, seek_pos(pos + 2), true); @@ -333,13 +338,13 @@ file_name_in_quotes(Application_Links *app, String *file_name){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); if (buffer.file_name != 0){ - size_t pos = view.cursor.pos; - size_t start = 0, end = 0; + int32_t pos = view.cursor.pos; + int32_t start = 0, end = 0; buffer_seek_delimiter_forward(app, &buffer, pos, '"', &end); buffer_seek_delimiter_backward(app, &buffer, pos, '"', &start); ++start; - size_t size = end - start; + int32_t size = end - start; char short_file_name[128]; // NOTE(allen): This check is necessary because buffer_read_range @@ -349,7 +354,7 @@ file_name_in_quotes(Application_Links *app, String *file_name){ result = true; copy_ss(file_name, make_string(buffer.file_name, buffer.file_name_len)); remove_last_folder(file_name); - append_ss(file_name, make_string(short_file_name, (int32_t)size)); + append_ss(file_name, make_string(short_file_name, size)); } } } diff --git a/4coder_function_list.cpp b/4coder_function_list.cpp index d617723c..618fcf59 100644 --- a/4coder_function_list.cpp +++ b/4coder_function_list.cpp @@ -59,8 +59,8 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff Partition extra_memory_ = partition_sub_part(part, (4<<10)); Partition *extra_memory = &extra_memory_; char *str = (char*)partition_current(part); - size_t part_size = 0; - size_t size = 0; + int32_t part_size = 0; + int32_t size = 0; static const int32_t token_chunk_size = 512; Cpp_Token token_chunk[token_chunk_size]; @@ -217,7 +217,7 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff } if (delete_space_before){ - size_t pos = extra_memory->pos - 1; + int32_t pos = extra_memory->pos - 1; char *base = ((char*)(extra_memory->base)); if (pos >= 0 && base[pos] == ' '){ extra_memory->pos = pos; @@ -242,13 +242,13 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff finish_print:; { - size_t sig_size = extra_memory->pos; - String sig = make_string(extra_memory->base, (int32_t)sig_size); + int32_t sig_size = extra_memory->pos; + String sig = make_string(extra_memory->base, sig_size); - size_t line_number = buffer_get_line_index(app, buffer, open_paren_pos); - size_t line_number_len = int_to_str_size((int32_t)line_number); + int32_t line_number = buffer_get_line_index(app, buffer, open_paren_pos); + int32_t line_number_len = int_to_str_size(line_number); - size_t append_len = buffer_name.size + 1 + line_number_len + 1 + 1 + sig_size + 1; + int32_t append_len = buffer_name.size + 1 + line_number_len + 1 + 1 + sig_size + 1; char *out_space = push_array(part, char, append_len); if (out_space == 0){ @@ -263,10 +263,10 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff } part_size += append_len; - String out = make_string(out_space, 0, (int32_t)append_len); + String out = make_string(out_space, 0, append_len); append(&out, buffer_name); append(&out, ':'); - append_int_to_str(&out, (int32_t)line_number); + append_int_to_str(&out, line_number); append(&out, ':'); append(&out, ' '); append(&out, sig); diff --git a/4coder_helper/4coder_helper.h b/4coder_helper/4coder_helper.h index 7fb8cd15..d8e48b38 100644 --- a/4coder_helper/4coder_helper.h +++ b/4coder_helper/4coder_helper.h @@ -148,7 +148,7 @@ query_user_number(Application_Links *app, Query_Bar *bar){ } static char -buffer_get_char(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +buffer_get_char(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char result = ' '; *buffer = get_buffer(app, buffer->buffer_id, AccessAll); if (pos < buffer->size){ @@ -188,7 +188,7 @@ create_buffer(Application_Links *app, char *filename, int32_t filename_len, Buff } static Range -make_range(size_t p1, size_t p2){ +make_range(int32_t p1, int32_t p2){ Range range; if (p1 < p2){ range.min = p1; @@ -212,9 +212,9 @@ adjust_all_buffer_wrap_widths(Application_Links *app, int32_t wrap_width, int32_ } // TODO(allen): Setup buffer seeking to do character_pos and get View_Summary out of this parameter list. -static size_t -character_pos_to_pos(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, size_t character_pos){ - size_t result = 0; +static int32_t +character_pos_to_pos(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, int32_t character_pos){ + int32_t result = 0; Full_Cursor cursor = {0}; if (view_compute_cursor(app, view, seek_character_pos(character_pos), &cursor)){ result = cursor.pos; @@ -223,8 +223,8 @@ character_pos_to_pos(Application_Links *app, View_Summary *view, Buffer_Summary } struct Buffer_Rect{ - size_t char0, line0; - size_t char1, line1; + int32_t char0, line0; + int32_t char1, line1; }; #ifndef Swap @@ -242,35 +242,35 @@ get_rect(View_Summary *view){ rect.line1 = view->cursor.line; if (rect.line0 > rect.line1){ - Swap(size_t, rect.line0, rect.line1); + Swap(int32_t, rect.line0, rect.line1); } if (rect.char0 > rect.char1){ - Swap(size_t, rect.char0, rect.char1); + Swap(int32_t, rect.char0, rect.char1); } return(rect); } -static pos_Rect +static i32_Rect get_line_x_rect(View_Summary *view){ - pos_Rect rect = {0}; + i32_Rect rect = {0}; if (view->unwrapped_lines){ - rect.x0 = (size_t)view->mark.unwrapped_x; - rect.x1 = (size_t)view->cursor.unwrapped_x; + rect.x0 = (int32_t)view->mark.unwrapped_x; + rect.x1 = (int32_t)view->cursor.unwrapped_x; } else{ - rect.x0 = (size_t)view->mark.wrapped_x; - rect.x1 = (size_t)view->cursor.wrapped_x; + rect.x0 = (int32_t)view->mark.wrapped_x; + rect.x1 = (int32_t)view->cursor.wrapped_x; } rect.y0 = view->mark.line; rect.y1 = view->cursor.line; if (rect.y0 > rect.y1){ - Swap(size_t, rect.y0, rect.y1); + Swap(int32_t, rect.y0, rect.y1); } if (rect.x0 > rect.x1){ - Swap(size_t, rect.x0, rect.x1); + Swap(int32_t, rect.x0, rect.x1); } return(rect); diff --git a/4coder_helper/4coder_jump_parsing.h b/4coder_helper/4coder_jump_parsing.h index d37de476..85d80933 100644 --- a/4coder_helper/4coder_jump_parsing.h +++ b/4coder_helper/4coder_jump_parsing.h @@ -41,20 +41,20 @@ ms_style_verify(String line, int32_t paren_pos){ } static int32_t -parse_jump_location(String line, Name_Based_Jump_Location *location, int32_t skip_sub_errors, size_t *colon_char){ - bool32 result = false; +parse_jump_location(String line, Name_Based_Jump_Location *location, int32_t skip_sub_errors, int32_t *colon_char){ + int32_t result = false; int32_t whitespace_length = 0; String original_line = line; line = skip_chop_whitespace(line, &whitespace_length); int32_t colon_pos = 0; - bool32 is_ms_style = false; + int32_t is_ms_style = 0; int32_t paren_pos = find_s_char(line, 0, ')'); while (!is_ms_style && paren_pos < line.size){ if (ms_style_verify(line, paren_pos)){ - is_ms_style = true; + is_ms_style = 1; colon_pos = find_s_char(line, paren_pos, ':'); if (colon_pos < line.size){ String location_str = substr(line, 0, colon_pos); @@ -152,14 +152,14 @@ parse_jump_location(String line, Name_Based_Jump_Location *location, int32_t ski return(result); } -static bool32 -parse_jump_from_buffer_line(Application_Links *app, Partition *part, int32_t buffer_id, size_t line, int32_t skip_sub_errors, Name_Based_Jump_Location *location){ +static int32_t +parse_jump_from_buffer_line(Application_Links *app, Partition *part, int32_t buffer_id, int32_t line, int32_t skip_sub_errors, Name_Based_Jump_Location *location){ - bool32 result = false; + int32_t result = false; String line_str = {0}; Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll); if (read_line(app, part, &buffer, line, &line_str)){ - size_t colon_char = 0; + int32_t colon_char = 0; if (parse_jump_location(line_str, location, skip_sub_errors, &colon_char)){ result = true; } diff --git a/4coder_helper/4coder_long_seek.h b/4coder_helper/4coder_long_seek.h index 831334e7..e625c903 100644 --- a/4coder_helper/4coder_long_seek.h +++ b/4coder_helper/4coder_long_seek.h @@ -15,17 +15,20 @@ // Whitespace Based Seeks // -static size_t -seek_line_end(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +seek_line_end(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char chunk[1024]; - size_t chunk_size = sizeof(chunk); + int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; + int32_t still_looping; + char at_pos; + if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ - bool32 still_looping = true; + still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ - char at_pos = stream.data[pos]; + for (; pos < stream.end; ++pos){ + at_pos = stream.data[pos]; if (at_pos == '\n'){ goto double_break; } @@ -42,18 +45,21 @@ seek_line_end(Application_Links *app, Buffer_Summary *buffer, size_t pos){ return(pos); } -static size_t -seek_line_beginning(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +seek_line_beginning(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char chunk[1024]; - size_t chunk_size = sizeof(chunk); + int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; + int32_t still_looping; + char at_pos; + --pos; if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ - bool32 still_looping = false; + still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ - char at_pos = stream.data[pos]; + for (; pos >= stream.start; --pos){ + at_pos = stream.data[pos]; if (at_pos == '\n'){ goto double_break; } @@ -77,15 +83,15 @@ static void move_past_lead_whitespace(Application_Links *app, View_Summary *view, Buffer_Summary *buffer){ refresh_view(app, view); + int32_t new_pos = seek_line_beginning(app, buffer, view->cursor.pos); char space[1024]; Stream_Chunk chunk = {0}; + int32_t still_looping = false; - size_t new_pos = seek_line_beginning(app, buffer, view->cursor.pos); - size_t i = new_pos; + int32_t i = new_pos; if (init_stream_chunk(&chunk, app, buffer, i, space, sizeof(space))){ - bool32 still_looping = false; do{ - for (; i < (size_t)chunk.end; ++i){ + for (; i < chunk.end; ++i){ char at_pos = chunk.data[i]; if (at_pos == '\n' || !char_is_whitespace(at_pos)){ goto break2; @@ -101,20 +107,22 @@ move_past_lead_whitespace(Application_Links *app, View_Summary *view, Buffer_Sum } } -static size_t -buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char chunk[1024]; - size_t chunk_size = sizeof(chunk); + int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; + char at_pos; + --pos; if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ // Step 1: Find the first non-whitespace character // behind the current position. - bool32 still_looping = true; + int32_t still_looping = 1; while (still_looping){ - for (; pos >= (size_t)stream.start; --pos){ - char at_pos = stream.data[pos]; + for (; pos >= stream.start; --pos){ + at_pos = stream.data[pos]; if (!char_is_whitespace(at_pos)){ goto double_break_1; } @@ -130,8 +138,8 @@ buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, size_t // the next '\n' int32_t no_hard = false; while (still_looping){ - for (; pos >= (size_t)stream.start; --pos){ - char at_pos = stream.data[pos]; + for (; pos >= stream.start; --pos){ + at_pos = stream.data[pos]; if (at_pos == '\n'){ if (no_hard){ goto double_break_2; @@ -156,19 +164,24 @@ buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, size_t return(pos); } -static size_t -buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char chunk[1024]; - size_t chunk_size = sizeof(chunk); + int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; + int32_t no_hard; + int32_t prev_endline; + int32_t still_looping; + char at_pos; + if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ // step 1: find the first non-whitespace character // ahead of the current position. - bool32 still_looping = true; + still_looping = true; do{ - for (; pos < (size_t)stream.end; ++pos){ - char at_pos = stream.data[pos]; + for (; pos < stream.end; ++pos){ + at_pos = stream.data[pos]; if (!char_is_whitespace(at_pos)){ goto double_break_1; } @@ -182,12 +195,11 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, size // the prev_endline value. if another '\n' is found // with non-whitespace then the previous line was // all whitespace. - bool32 no_hard = false; - bool32 was_at_end = true; - size_t prev_endline = 0; + no_hard = false; + prev_endline = -1; while(still_looping){ - for (; pos < (size_t)stream.end; ++pos){ - char at_pos = stream.data[pos]; + for (; pos < stream.end; ++pos){ + at_pos = stream.data[pos]; if (at_pos == '\n'){ if (no_hard){ goto double_break_2; @@ -195,7 +207,6 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, size else{ no_hard = true; prev_endline = pos; - was_at_end = false; } } else if (!char_is_whitespace(at_pos)){ @@ -206,7 +217,7 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, size } double_break_2:; - if (was_at_end || prev_endline+1 >= buffer->size){ + if (prev_endline == -1 || prev_endline+1 >= buffer->size){ pos = buffer->size; } else{ @@ -216,8 +227,8 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, size return(pos); } -static size_t -buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -226,7 +237,7 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, siz bool32 still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < stream.end; ++pos){ if (!char_is_whitespace(stream.data[pos])){ goto double_break1; } @@ -237,7 +248,7 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, siz still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < stream.end; ++pos){ if (char_is_whitespace(stream.data[pos])){ goto double_break2; } @@ -250,8 +261,8 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, siz return(pos); } -static size_t -buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -262,7 +273,7 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, size bool32 still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= stream.start; --pos){ if (!char_is_whitespace(stream.data[pos])){ goto double_break1; } @@ -273,7 +284,7 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, size still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= stream.start; --pos){ if (char_is_whitespace(stream.data[pos])){ ++pos; goto double_break2; @@ -295,8 +306,8 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, size // Boundary Type Seeks // -static size_t -buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -305,7 +316,7 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, s bool32 still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < stream.end; ++pos){ if (char_is_alpha_numeric_true(stream.data[pos])){ goto double_break1; } @@ -316,7 +327,7 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, s still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < stream.end; ++pos){ if (!char_is_alpha_numeric_true(stream.data[pos])){ goto double_break2; } @@ -329,8 +340,8 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, s return(pos); } -static size_t -buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -341,7 +352,7 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, si bool32 still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= stream.start; --pos){ if (char_is_alpha_numeric_true(stream.data[pos])){ goto double_break1; } @@ -352,7 +363,7 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, si still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= stream.start; --pos){ if (!char_is_alpha_numeric_true(stream.data[pos])){ ++pos; goto double_break2; @@ -370,8 +381,8 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, si return(pos); } -static size_t -buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t an_pos){ +static int32_t +buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t an_pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -386,7 +397,7 @@ buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, si bool32 still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < stream.end; ++pos){ c = stream.data[pos]; if (char_is_upper(c) && char_is_lower(pc)){ goto double_break1; @@ -405,8 +416,8 @@ buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, si return(pos); } -static size_t -buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t an_pos){ +static int32_t +buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t an_pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -419,7 +430,7 @@ buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, siz bool32 still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= stream.start; --pos){ c = stream.data[pos]; if (char_is_upper(c) && char_is_lower(pc)){ goto double_break1; @@ -438,22 +449,22 @@ buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, siz return(pos); } -static size_t -buffer_seek_alphanumeric_or_camel_right(Application_Links *app, Buffer_Summary *buffer, size_t pos){ - size_t an_pos = buffer_seek_alphanumeric_right(app, buffer, pos); - size_t result = buffer_seek_range_camel_right(app, buffer, pos, an_pos); +static int32_t +buffer_seek_alphanumeric_or_camel_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ + int32_t an_pos = buffer_seek_alphanumeric_right(app, buffer, pos); + int32_t result = buffer_seek_range_camel_right(app, buffer, pos, an_pos); return(result); } -static size_t -buffer_seek_alphanumeric_or_camel_left(Application_Links *app, Buffer_Summary *buffer, size_t pos){ - size_t an_pos = buffer_seek_alphanumeric_left(app, buffer, pos); - size_t result = buffer_seek_range_camel_left(app, buffer, pos, an_pos); +static int32_t +buffer_seek_alphanumeric_or_camel_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ + int32_t an_pos = buffer_seek_alphanumeric_left(app, buffer, pos); + int32_t result = buffer_seek_range_camel_left(app, buffer, pos, an_pos); return(result); } -static size_t -seek_token_left(Cpp_Token_Array *tokens, size_t pos){ +static int32_t +seek_token_left(Cpp_Token_Array *tokens, int32_t pos){ Cpp_Get_Token_Result get = cpp_get_token(*tokens, pos); if (get.token_index == -1){ get.token_index = 0; @@ -467,19 +478,17 @@ seek_token_left(Cpp_Token_Array *tokens, size_t pos){ return(token->start); } -static size_t -seek_token_right(Cpp_Token_Array *tokens, size_t pos){ +static int32_t +seek_token_right(Cpp_Token_Array *tokens, int32_t pos){ Cpp_Get_Token_Result get = cpp_get_token(*tokens, pos); if (get.in_whitespace){ ++get.token_index; } - uint32_t target_token_index = (uint32_t)(get.token_index); - - if (target_token_index >= tokens->count){ - target_token_index = tokens->count-1; + if (get.token_index >= tokens->count){ + get.token_index = tokens->count-1; } - Cpp_Token *token = tokens->tokens + target_token_index; + Cpp_Token *token = tokens->tokens + get.token_index; return(token->start + token->size); } @@ -497,26 +506,28 @@ buffer_get_all_tokens(Application_Links *app, Partition *part, Buffer_Summary *b return(array); } -static size_t -buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Partition *part, size_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags)/* +static int32_t +buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Partition *part, int32_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags)/* DOC_PARAM(buffer, The buffer parameter specifies the buffer through which to seek.) DOC_PARAM(start_pos, The beginning position of the seek is specified by start_pos measured in absolute position.) DOC_PARAM(seek_forward, If this parameter is non-zero it indicates that the seek should move foward through the buffer.) DOC_PARAM(flags, This field specifies the types of boundaries at which the seek should stop.) -DOC_RETURN(This call returns the absolute position where the seek stopped. If the seek goes below 0 the returned value is -1. If the seek goes past the end the returned value is the size of the buffer.) +DOC_RETURN(This call returns the absolute position where the seek stopped. +If the seek goes below 0 the returned value is -1. +If the seek goes past the end the returned value is the size of the buffer.) DOC_SEE(Seek_Boundary_Flag) DOC_SEE(4coder_Buffer_Positioning_System) */{ - size_t result = 0; + int32_t result = 0; // TODO(allen): reduce duplication? Temp_Memory temp = begin_temp_memory(part); if (buffer->exists){ - size_t pos[4]; - size_t size = buffer->size; - size_t new_pos = 0; + int32_t pos[4]; + int32_t size = buffer->size; + int32_t new_pos = 0; if (start_pos < 0){ start_pos = 0; @@ -612,8 +623,8 @@ DOC_SEE(4coder_Buffer_Positioning_System) // Character Seeks // -static void -buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, size_t pos, char delim, size_t *result){ +void +buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, char delim, int32_t *result){ if (buffer->exists){ char chunk[1024]; int32_t size = sizeof(chunk); @@ -622,7 +633,7 @@ buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, si if (init_stream_chunk(&stream, app, buffer, pos, chunk, size)){ int32_t still_looping = 1; do{ - for(; pos < (size_t)stream.end; ++pos){ + for(; pos < stream.end; ++pos){ char at_pos = stream.data[pos]; if (at_pos == delim){ *result = pos; @@ -640,7 +651,7 @@ buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, si } static void -buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, size_t pos, char delim, size_t *result){ +buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, char delim, int32_t *result){ if (buffer->exists){ char chunk[1024]; int32_t size = sizeof(chunk); @@ -649,7 +660,7 @@ buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, s if (init_stream_chunk(&stream, app, buffer, pos, chunk, size)){ int32_t still_looping = 1; do{ - for(; pos >= (size_t)stream.start; --pos){ + for(; pos >= stream.start; --pos){ char at_pos = stream.data[pos]; if (at_pos == delim){ *result = pos; @@ -677,7 +688,7 @@ buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, s // 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_Summary *buffer, size_t pos, size_t end, char *str, size_t size, size_t *result){ +buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t end, char *str, int32_t size, int32_t *result){ char read_buffer[512]; if (buffer->size > end){ @@ -690,19 +701,19 @@ buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, size_ if (size > 0 && size <= sizeof(read_buffer)){ if (buffer->exists){ String read_str = make_fixed_width_string(read_buffer); - String needle_str = make_string(str, (int32_t)size); + String needle_str = make_string(str, size); char first_char = str[0]; - read_str.size = (int32_t)size; + read_str.size = size; char chunk[1024]; Stream_Chunk stream = {0}; stream.max_end = end; if (init_stream_chunk(&stream, app, buffer, pos, chunk, sizeof(chunk))){ - bool32 still_looping = 1; + int32_t still_looping = 1; do{ - for(; pos < (size_t)stream.end; ++pos){ + for(; pos < stream.end; ++pos){ char at_pos = stream.data[pos]; if (at_pos == first_char){ buffer_read_range(app, buffer, pos, pos+size, read_buffer); @@ -732,17 +743,17 @@ buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, size_ // 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_Summary *buffer, size_t pos, size_t min, char *str, size_t size, size_t *result){ +buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t min, char *str, int32_t size, int32_t *result){ char read_buffer[512]; *result = min-1; if (size > 0 && size <= sizeof(read_buffer)){ if (buffer->exists){ String read_str = make_fixed_width_string(read_buffer); - String needle_str = make_string(str, (int32_t)size); + String needle_str = make_string(str, size); char first_char = str[0]; - read_str.size = (int32_t)size; + read_str.size = size; char chunk[1024]; Stream_Chunk stream = {0}; @@ -751,7 +762,7 @@ buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, size if (init_stream_chunk(&stream, app, buffer, pos, chunk, sizeof(chunk))){ int32_t still_looping = 1; do{ - for(; pos >= (size_t)stream.start; --pos){ + for(; pos >= stream.start; --pos){ char at_pos = stream.data[pos]; if (at_pos == first_char){ buffer_read_range(app, buffer, pos, pos+size, read_buffer); @@ -774,7 +785,7 @@ buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, size // 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_Summary *buffer, size_t pos, size_t end, char *str, size_t size, size_t *result){ +buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t end, char *str, int32_t size, int32_t *result){ char read_buffer[512]; char chunk[1024]; int32_t chunk_size = sizeof(chunk); @@ -788,29 +799,32 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *b *result = end; } - if (size > 0 && size <= sizeof(read_buffer) && buffer->exists){ - String read_str = make_fixed_width_string(read_buffer); - String needle_str = make_string(str, (int32_t)size); - char first_char = char_to_upper(str[0]); - - read_str.size = (int32_t)size; - - if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ - bool32 still_looping = true; - do{ - for(; pos < (size_t)stream.end; ++pos){ - char at_pos = char_to_upper(stream.data[pos]); - if (at_pos == first_char){ - buffer_read_range(app, buffer, pos, pos+size, read_buffer); - if (match_insensitive_ss(needle_str, read_str)){ - *result = pos; - goto finished; + if (size > 0 && size <= sizeof(read_buffer)){ + if (buffer->exists){ + String read_str = make_fixed_width_string(read_buffer); + String needle_str = make_string(str, size); + char first_char = char_to_upper(str[0]); + + read_str.size = size; + + if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ + int32_t still_looping = 1; + do{ + for(; pos < stream.end; ++pos){ + char at_pos = char_to_upper(stream.data[pos]); + if (at_pos == first_char){ + buffer_read_range(app, buffer, pos, pos+size, read_buffer); + if (match_insensitive_ss(needle_str, read_str)){ + *result = pos; + goto finished; + } } } - } - still_looping = forward_stream_chunk(&stream); - }while (still_looping); + still_looping = forward_stream_chunk(&stream); + }while (still_looping); + } } + finished:; } } @@ -819,7 +833,7 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *b // 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_Summary *buffer, size_t pos, size_t min, char *str, size_t size, size_t *result){ +buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t min, char *str, int32_t size, int32_t *result){ char read_buffer[512]; char chunk[1024]; int32_t chunk_size = sizeof(chunk); @@ -827,29 +841,32 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary * stream.min_start = min; *result = min-1; - if (size > 0 && size <= sizeof(read_buffer) && buffer->exists){ - String read_str = make_fixed_width_string(read_buffer); - String needle_str = make_string(str, (int32_t)size); - char first_char = char_to_upper(str[0]); - - read_str.size = (int32_t)size; - - if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ - int32_t still_looping = 1; - do{ - for(; pos >= (size_t)stream.start; --pos){ - char at_pos = char_to_upper(stream.data[pos]); - if (at_pos == first_char){ - buffer_read_range(app, buffer, pos, pos+size, read_buffer); - if (match_insensitive_ss(needle_str, read_str)){ - *result = pos; - goto finished; + if (size > 0 && size <= sizeof(read_buffer)){ + if (buffer->exists){ + String read_str = make_fixed_width_string(read_buffer); + String needle_str = make_string(str, size); + char first_char = char_to_upper(str[0]); + + read_str.size = size; + + if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ + int32_t still_looping = 1; + do{ + for(; pos >= stream.start; --pos){ + char at_pos = char_to_upper(stream.data[pos]); + if (at_pos == first_char){ + buffer_read_range(app, buffer, pos, pos+size, read_buffer); + if (match_insensitive_ss(needle_str, read_str)){ + *result = pos; + goto finished; + } } } - } - still_looping = backward_stream_chunk(&stream); - }while (still_looping); + still_looping = backward_stream_chunk(&stream); + }while (still_looping); + } } + finished:; } } @@ -859,25 +876,23 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary * // Buffer Line Positioning // -static bool32 -read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line, String *str){ - bool32 success = false; - - Buffer_Seek seek_begin = seek_line_char(line, 1); - Buffer_Seek seek_end = seek_line_reverse_char(line, 1); +static int32_t +read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line, String *str){ Partial_Cursor begin = {0}; Partial_Cursor end = {0}; - if (buffer_compute_cursor(app, buffer, seek_begin, &begin)){ - if (begin.line == line){ - if (buffer_compute_cursor(app, buffer, seek_end, &end)){ + int32_t success = 0; + + if (buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &begin)){ + if (buffer_compute_cursor(app, buffer, seek_line_char(line, -1), &end)){ + if (begin.line == line){ if (0 <= begin.pos && begin.pos <= end.pos && end.pos <= buffer->size){ - size_t size = (end.pos - begin.pos); - *str = make_string(push_array(part, char, size+1), (int32_t)(size+1)); + int32_t size = (end.pos - begin.pos); + *str = make_string(push_array(part, char, size+1), size+1); if (str->str){ - success = true; + success = 1; buffer_read_range(app, buffer, begin.pos, end.pos, str->str); - str->size = (int32_t)size; + str->size = size; terminate_with_null(str); } } @@ -888,10 +903,10 @@ read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_ return(success); } -static size_t -buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, size_t line){ +static int32_t +buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, int32_t line){ Partial_Cursor partial_cursor; - size_t result = buffer->size; + int32_t result = buffer->size; if (line <= buffer->line_count){ buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &partial_cursor); result = partial_cursor.pos; @@ -899,39 +914,36 @@ buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, size_t lin return(result); } -static size_t -buffer_get_line_end(Application_Links *app, Buffer_Summary *buffer, size_t line){ +static int32_t +buffer_get_line_end(Application_Links *app, Buffer_Summary *buffer, int32_t line){ Partial_Cursor partial_cursor; - size_t result = buffer->size; + int32_t result = buffer->size; if (line <= buffer->line_count){ - buffer_compute_cursor(app, buffer, seek_line_reverse_char(line, 1), &partial_cursor); + buffer_compute_cursor(app, buffer, seek_line_char(line, -1), &partial_cursor); result = partial_cursor.pos; } return(result); } static bool32 -buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, size_t line){ +buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, int32_t line){ Partial_Cursor start, end; bool32 result = 0; if (line <= buffer->line_count){ - Buffer_Seek seek_start = seek_line_char(line, 1); - Buffer_Seek seek_end = seek_line_reverse_char(line, 1); + buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &start); + buffer_compute_cursor(app, buffer, seek_line_char(line, -1), &end); - buffer_compute_cursor(app, buffer, seek_start, &start); - buffer_compute_cursor(app, buffer, seek_end, &end); - - static const size_t chunk_size = 1024; + static const int32_t chunk_size = 1024; char chunk[chunk_size]; Stream_Chunk stream = {0}; - size_t i = start.pos; + int32_t i = start.pos; stream.max_end = end.pos; result = true; if (init_stream_chunk(&stream, app, buffer, i, chunk, chunk_size)){ bool32 still_looping = false; do{ - for (;i < (size_t)stream.end; ++i){ + for (;i < stream.end; ++i){ char c = stream.data[i]; if (!(c == ' ' || c == '\t' || c == '\r' || c == '\v' || c == '\n')){ result = false; @@ -946,30 +958,29 @@ buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, size_t line return(result); } -static size_t -buffer_get_line_index(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_get_line_index(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ Partial_Cursor partial_cursor; buffer_compute_cursor(app, buffer, seek_pos(pos), &partial_cursor); return(partial_cursor.line); } static Cpp_Token* -get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t line, size_t *line_start_out = 0){ - size_t line_start = buffer_get_line_start(app, buffer, line); - Cpp_Get_Token_Result get = cpp_get_token(tokens, line_start); +get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line, int32_t *line_start_out = 0){ + int32_t line_start = buffer_get_line_start(app, buffer, line); + Cpp_Get_Token_Result get_token = cpp_get_token(tokens, line_start); - if (get.in_whitespace){ - get.token_index += 1; + if (get_token.in_whitespace){ + get_token.token_index += 1; } - uint32_t target_token_index = (uint32_t)(get.token_index); - if (line_start_out != 0){ + if (line_start_out){ *line_start_out = line_start; } Cpp_Token *result = 0; - if (target_token_index < tokens.count){ - result = tokens.tokens + target_token_index; + if (get_token.token_index < tokens.count){ + result = tokens.tokens + get_token.token_index; } return(result); diff --git a/4coder_helper/4coder_seek_types.h b/4coder_helper/4coder_seek_types.h index 2d2e8a58..f5e8738e 100644 --- a/4coder_helper/4coder_seek_types.h +++ b/4coder_helper/4coder_seek_types.h @@ -13,7 +13,7 @@ #define FRED_BUFFER_TYPES_H static Buffer_Seek -seek_pos(size_t pos){ +seek_pos(int32_t pos){ Buffer_Seek result; result.type = buffer_seek_pos; result.pos = pos; @@ -21,7 +21,7 @@ seek_pos(size_t pos){ } static Buffer_Seek -seek_character_pos(size_t pos){ +seek_character_pos(int32_t pos){ Buffer_Seek result; result.type = buffer_seek_character_pos; result.pos = pos; @@ -29,7 +29,7 @@ seek_character_pos(size_t pos){ } static Buffer_Seek -seek_wrapped_xy(float x, float y, bool32 round_down){ +seek_wrapped_xy(float x, float y, int32_t round_down){ Buffer_Seek result; result.type = buffer_seek_wrapped_xy; result.x = x; @@ -39,7 +39,7 @@ seek_wrapped_xy(float x, float y, bool32 round_down){ } static Buffer_Seek -seek_unwrapped_xy(float x, float y, bool32 round_down){ +seek_unwrapped_xy(float x, float y, int32_t round_down){ Buffer_Seek result; result.type = buffer_seek_unwrapped_xy; result.x = x; @@ -59,7 +59,7 @@ seek_xy(float x, float y, bool32 round_down, bool32 unwrapped){ } static Buffer_Seek -seek_line_char(size_t line, size_t character){ +seek_line_char(int32_t line, int32_t character){ Buffer_Seek result; result.type = buffer_seek_line_char; result.line = line; @@ -67,15 +67,6 @@ seek_line_char(size_t line, size_t character){ return(result); } -static Buffer_Seek -seek_line_reverse_char(size_t line, size_t character){ - Buffer_Seek result; - result.type = buffer_seek_line_reverse_char; - result.line = line; - result.character = character; - return(result); -} - #endif // BOTTOM diff --git a/4coder_helper/4coder_streaming.h b/4coder_helper/4coder_streaming.h index 3317d13e..ac3bc849 100644 --- a/4coder_helper/4coder_streaming.h +++ b/4coder_helper/4coder_streaming.h @@ -9,32 +9,31 @@ #include "4coder_helper/4coder_helper.h" -// TODO(allen): Rewrite the backward seek to get this on size_t instead of int64_t. struct Stream_Chunk{ Application_Links *app; Buffer_Summary *buffer; char *base_data; - int64_t start, end; - int64_t min_start, max_end; - int64_t data_size; + int32_t start, end; + int32_t min_start, max_end; bool32 add_null; + uint32_t data_size; char *data; }; -static uint64_t -round_down(uint64_t x, uint64_t b){ - uint64_t r = 0; +static int32_t +round_down(int32_t x, int32_t b){ + int32_t r = 0; if (x >= 0){ r = x - (x % b); } return(r); } -static uint64_t -round_up(uint64_t x, uint64_t b){ - uint64_t r = 0; +static int32_t +round_up(int32_t x, int32_t b){ + int32_t r = 0; if (x >= 0){ r = x - (x % b) + b; } @@ -42,7 +41,8 @@ round_up(uint64_t x, uint64_t b){ } static bool32 -init_stream_chunk(Stream_Chunk *chunk, Application_Links *app, Buffer_Summary *buffer, size_t pos, char *data, size_t size){ +init_stream_chunk(Stream_Chunk *chunk, Application_Links *app, Buffer_Summary *buffer, + int32_t pos, char *data, uint32_t size){ bool32 result = 0; refresh_buffer(app, buffer); @@ -153,12 +153,12 @@ struct Stream_Tokens{ Cpp_Token *base_tokens; Cpp_Token *tokens; - int64_t start, end; - int64_t count, token_count; + int32_t start, end; + int32_t count, token_count; }; static bool32 -init_stream_tokens(Stream_Tokens *stream, Application_Links *app, Buffer_Summary *buffer, size_t pos, Cpp_Token *data, size_t count){ +init_stream_tokens(Stream_Tokens *stream, Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Token *data, int32_t count){ bool32 result = 0; refresh_buffer(app, buffer); @@ -168,9 +168,9 @@ init_stream_tokens(Stream_Tokens *stream, Application_Links *app, Buffer_Summary stream->app = app; stream->buffer = buffer; stream->base_tokens = data; - stream->count = (int64_t)count; - stream->start = (int64_t)round_down(pos, count); - stream->end = (int64_t)round_up(pos, count); + stream->count = count; + stream->start = round_down(pos, count); + stream->end = round_up(pos, count); stream->token_count = token_count; if (stream->start < 0){ diff --git a/4coder_jump_parsing.cpp b/4coder_jump_parsing.cpp index 3071c786..c2248760 100644 --- a/4coder_jump_parsing.cpp +++ b/4coder_jump_parsing.cpp @@ -22,7 +22,10 @@ CUSTOM_COMMAND_SIG(goto_jump_at_cursor){ View_Summary view = get_active_view(app, AccessProtected); Name_Based_Jump_Location location = {0}; - if (parse_jump_from_buffer_line(app, &global_part, view.buffer_id, view.cursor.line, false, &location)){ + if (parse_jump_from_buffer_line(app, &global_part, + view.buffer_id, view.cursor.line, false, + &location)){ + exec_command(app, change_active_panel); view = get_active_view(app, AccessAll); jump_to_location(app, &view, &location); @@ -36,13 +39,13 @@ CUSTOM_COMMAND_SIG(goto_jump_at_cursor){ // Error Jumping // -static bool32 -seek_next_jump_in_buffer(Application_Links *app, Partition *part, int32_t buffer_id, size_t first_line, bool32 skip_sub_errors, int32_t direction, size_t *line_out, size_t *colon_index_out, Name_Based_Jump_Location *location_out){ +static int32_t +seek_next_jump_in_buffer(Application_Links *app, Partition *part, int32_t buffer_id, int32_t first_line, bool32 skip_sub_errors, int32_t direction, int32_t *line_out, int32_t *colon_index_out, Name_Based_Jump_Location *location_out){ Assert(direction == 1 || direction == -1); - bool32 result = false; - size_t line = first_line; + int32_t result = false; + int32_t line = first_line; String line_str = {0}; Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll); for (;;){ @@ -83,12 +86,12 @@ convert_name_based_to_id_based(Application_Links *app, Name_Based_Jump_Location } static int32_t -seek_next_jump_in_view(Application_Links *app, Partition *part, View_Summary *view, bool32 skip_sub_errors, int32_t direction, size_t *line_out, size_t *colon_index_out, Name_Based_Jump_Location *location_out){ +seek_next_jump_in_view(Application_Links *app, Partition *part, View_Summary *view, int32_t skip_sub_errors, int32_t direction, int32_t *line_out, int32_t *colon_index_out, Name_Based_Jump_Location *location_out){ int32_t result = false; Name_Based_Jump_Location location = {0}; - size_t line = view->cursor.line; - size_t colon_index = 0; + int32_t line = view->cursor.line; + int32_t colon_index = 0; if (seek_next_jump_in_buffer(app, part, view->buffer_id, line+direction, skip_sub_errors, direction, &line, &colon_index, &location)){ result = true; *line_out = line; @@ -111,13 +114,13 @@ skip_this_jump(ID_Based_Jump_Location prev, ID_Based_Jump_Location jump){ return(result); } -static bool32 -advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_Summary *view, int32_t skip_repeats, bool32 skip_sub_error, int32_t direction, Name_Based_Jump_Location *location_out){ - bool32 result = true; +static int32_t +advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_Summary *view, int32_t skip_repeats, int32_t skip_sub_error, int32_t direction, Name_Based_Jump_Location *location_out){ + int32_t result = true; Name_Based_Jump_Location location = {0}; ID_Based_Jump_Location jump = {0}; - size_t line = 0, colon_index = 0; + int32_t line = 0, colon_index = 0; do{ Temp_Memory temp = begin_temp_memory(part); diff --git a/4coder_lib/4coder_mem.h b/4coder_lib/4coder_mem.h index c798c6d6..69ce0e1b 100644 --- a/4coder_lib/4coder_mem.h +++ b/4coder_lib/4coder_mem.h @@ -44,23 +44,23 @@ typedef int32_t b32_4tech; struct Partition{ char *base; - umem_4tech pos; - umem_4tech max; + i32_4tech pos; + i32_4tech max; }; struct Temp_Memory{ void *handle; - umem_4tech pos; + i32_4tech pos; }; struct Tail_Temp_Partition{ Partition part; void *handle; - umem_4tech old_max; + i32_4tech old_max; }; inline Partition -make_part(void *memory, umem_4tech size){ +make_part(void *memory, i32_4tech size){ Partition partition; partition.base = (char*)memory; partition.pos = 0; @@ -69,7 +69,7 @@ make_part(void *memory, umem_4tech size){ } inline void* -partition_allocate(Partition *data, umem_4tech size){ +partition_allocate(Partition *data, i32_4tech size){ void *ret = 0; if (size > 0 && data->pos + size <= data->max){ ret = data->base + data->pos; @@ -79,7 +79,14 @@ partition_allocate(Partition *data, umem_4tech size){ } inline void -partition_align(Partition *data, umem_4tech boundary){ +partition_reduce(Partition *data, i32_4tech size){ + if (size > 0 && size <= data->pos){ + data->pos -= size; + } +} + +inline void +partition_align(Partition *data, u32_4tech boundary){ --boundary; data->pos = (data->pos + boundary) & (~boundary); } @@ -89,7 +96,7 @@ partition_current(Partition *data){ return(data->base + data->pos); } -inline umem_4tech +inline i32_4tech partition_remaining(Partition *data){ return(data->max - data->pos); } @@ -122,7 +129,7 @@ end_temp_memory(Temp_Memory temp){ } inline Tail_Temp_Partition -begin_tail_part(Partition *data, umem_4tech size){ +begin_tail_part(Partition *data, i32_4tech size){ Tail_Temp_Partition result = {0}; if (data->pos + size <= data->max){ result.handle = data; @@ -157,9 +164,9 @@ struct Bubble{ Bubble *next; Bubble *prev2; Bubble *next2; - size_t size; + i32_4tech size; u32_4tech flags; - u8_4tech _unused_[20 - sizeof(size_t)]; + u32_4tech _unused_[4]; }; struct General_Memory{ @@ -214,8 +221,8 @@ general_sentinel_init(Bubble *bubble){ #define BUBBLE_MIN_SIZE 1024 static void -general_memory_attempt_split(General_Memory *general, Bubble *bubble, size_t wanted_size){ - size_t remaining_size = bubble->size - wanted_size; +general_memory_attempt_split(General_Memory *general, Bubble *bubble, i32_4tech wanted_size){ + i32_4tech remaining_size = bubble->size - wanted_size; if (remaining_size >= BUBBLE_MIN_SIZE){ bubble->size = wanted_size; Bubble *new_bubble = (Bubble*)((char*)(bubble + 1) + wanted_size); @@ -284,7 +291,7 @@ general_memory_check(General_Memory *general){} #endif static void* -general_memory_allocate(General_Memory *general, size_t size){ +general_memory_allocate(General_Memory *general, i32_4tech size){ void *result = 0; if (size < BUBBLE_MIN_SIZE) size = BUBBLE_MIN_SIZE; for (Bubble *bubble = general->free_sentinel.next2; @@ -320,10 +327,10 @@ general_memory_free(General_Memory *general, void *memory){ } static void* -general_memory_reallocate(General_Memory *general, void *old, size_t old_size, size_t size){ +general_memory_reallocate(General_Memory *general, void *old, i32_4tech old_size, i32_4tech size){ void *result = old; Bubble *bubble = ((Bubble*)old) - 1; - size_t additional_space = size - bubble->size; + i32_4tech additional_space = size - bubble->size; if (additional_space > 0){ Bubble *next = bubble->next; if (!(next->flags & MEM_BUBBLE_USED) && @@ -341,7 +348,7 @@ general_memory_reallocate(General_Memory *general, void *old, size_t old_size, s } inline void* -general_memory_reallocate_nocopy(General_Memory *general, void *old, size_t size){ +general_memory_reallocate_nocopy(General_Memory *general, void *old, i32_4tech size){ void *result = general_memory_reallocate(general, old, 0, size); return(result); } diff --git a/4coder_lib/4coder_table.h b/4coder_lib/4coder_table.h index 044306e0..17e9bce4 100644 --- a/4coder_lib/4coder_table.h +++ b/4coder_lib/4coder_table.h @@ -52,20 +52,20 @@ typedef i32_4tech Compare_Function(void *key, void *item, void *arg); struct Table{ u32_4tech *hash_array; char *data_array; - u32_4tech count, max; - u32_4tech item_size; + i32_4tech count, max; + i32_4tech item_size; }; -static umem_4tech -table_required_mem_size(u32_4tech table_size, u32_4tech item_size){ - u32_4tech hash_size = ((table_size * sizeof(u32_4tech)) + 7) & ~7; - umem_4tech mem_size = hash_size + table_size * 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; return(mem_size); } static void -table_init_memory(Table *table, void *memory, u32_4tech table_size, u32_4tech item_size){ - umem_4tech hash_size = table_size * sizeof(u32_4tech); +table_init_memory(Table *table, void *memory, i32_4tech table_size, i32_4tech item_size){ + i32_4tech hash_size = table_size * sizeof(u32_4tech); hash_size = (hash_size + 7) & ~7; table->hash_array = (u32_4tech*)memory; @@ -90,8 +90,8 @@ table_add(Table *table, void *item, void *arg, Hash_Function *hash_func, Compare Assert(table->count * 8 < table->max * 7); u32_4tech hash = (hash_func(item, arg) | TableHashMin); - u32_4tech i = hash % table->max; - u32_4tech start = i; + i32_4tech i = hash % table->max; + i32_4tech start = i; u32_4tech *inspect = table->hash_array + i; while (*inspect >= TableHashMin){ @@ -120,8 +120,8 @@ table_find_pos(Table *table, void *search_key, void *arg, i32_4tech *pos, i32_4t Assert((table->count - 1) * 8 < table->max * 7); u32_4tech hash = (hash_func(search_key, arg) | TableHashMin); - u32_4tech i = hash % table->max; - u32_4tech start = i; + i32_4tech i = hash % table->max; + i32_4tech start = i; u32_4tech *inspect = table->hash_array + i; while (*inspect != TableHashEmpty){ @@ -254,17 +254,18 @@ tbl_offset_string_compare(void *a, void *b, void *arg){ struct String_Space{ char *space; - u32_4tech pos; - u32_4tech new_pos; - u32_4tech max; + i32_4tech pos; + i32_4tech new_pos; + i32_4tech max; }; static Offset_String -strspace_append(String_Space *space, char *str, u32_4tech len){ +strspace_append(String_Space *space, char *str, i32_4tech len){ Offset_String result = {}; if (space->new_pos + len <= space->max){ result.offset = space->new_pos; result.size = len; + memcpy(space->space + space->new_pos, str, len); space->new_pos = space->pos + len; } diff --git a/4coder_lib/4coder_utf8.h b/4coder_lib/4coder_utf8.h index 76d6580d..0cb1495f 100644 --- a/4coder_lib/4coder_utf8.h +++ b/4coder_lib/4coder_utf8.h @@ -40,6 +40,20 @@ typedef int32_t b32_4tech; #endif // standard preamble end +static u32_4tech cp_min_by_utf8_length[] = { + 0x0, + 0x0, + 0x80, + 0x800, + 0x10000, +}; + +static u32_4tech surrogate_min = 0xD800; +static u32_4tech surrogate_max = 0xDFFF; + +static u32_4tech nonchar_min = 0xFDD0; +static u32_4tech nonchar_max = 0xFDEF; + static b32_4tech codepoint_is_whitespace(u32_4tech codepoint){ b32_4tech result = false; @@ -53,16 +67,16 @@ static u32_4tech utf8_to_u32_length_unchecked(u8_4tech *buffer, u32_4tech *length_out){ u32_4tech result = 0; - if (buffer[0] <= 0x7F){ + if (buffer[0] < 0x80){ result = (u32_4tech)buffer[0]; *length_out = 1; } - else if (buffer[0] <= 0xE0){ + else if (buffer[0] < 0xE0){ result = ((u32_4tech)((buffer[0])&0x1F)) << 6; result |= ((u32_4tech)((buffer[1])&0x3F)); *length_out = 2; } - else if (buffer[0] <= 0xF0){ + 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)); @@ -76,6 +90,11 @@ utf8_to_u32_length_unchecked(u8_4tech *buffer, u32_4tech *length_out){ *length_out = 4; } + if (result < cp_min_by_utf8_length[*length_out] || (result >= surrogate_min && result <= surrogate_max)){ + result = 0; + *length_out = 0; + } + return(result); } @@ -104,9 +123,12 @@ utf8_to_u32(u8_4tech **buffer_ptr, u8_4tech *end){ else if (buffer[0] < 0xF0){ length = 3; } - else{ + else if (buffer[0] < 0xF8){ length = 4; } + else{ + length = 0; + } for (u32_4tech i = 1; i < length; ++i){ if ((buffer[i] & 0xC0) != 0x80){ @@ -145,6 +167,11 @@ utf8_to_u32(u8_4tech **buffer_ptr, u8_4tech *end){ }break; } + if (result < cp_min_by_utf8_length[length] || (result >= surrogate_min && result <= surrogate_max)){ + result = 0; + length = 0; + } + *buffer_ptr = buffer + length; } else{ @@ -171,7 +198,7 @@ u32_to_utf8_unchecked(u32_4tech codepoint, u8_4tech *buffer, u32_4tech *length_o buffer[2] = (u8_4tech)(0x80 | (codepoint & 0x3F)); *length_out = 3; } - else{ + else if (codepoint <= 0x10FFFF){ codepoint &= 0x001FFFFF; buffer[0] = (u8_4tech)(0xF0 | (codepoint >> 18)); buffer[1] = (u8_4tech)(0x80 | ((codepoint >> 12) & 0x3F)); @@ -179,6 +206,9 @@ u32_to_utf8_unchecked(u32_4tech codepoint, u8_4tech *buffer, u32_4tech *length_o buffer[3] = (u8_4tech)(0x80 | (codepoint & 0x3F)); *length_out = 4; } + else{ + *length_out = 0; + } } static umem_4tech @@ -198,11 +228,11 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * u32_4tech codepoint = 0; u32_4tech utf8_size = 0; - if (s[0] <= 0x7F){ + if (s[0] < 0x80){ codepoint = (u32_4tech)s[0]; utf8_size = 1; } - else if (s[0] <= 0xE0){ + else if (s[0] < 0xE0){ if (limit <= 1){ *error = true; break; @@ -212,7 +242,7 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * codepoint |= ((u32_4tech)((s[1])&0x3F)); utf8_size = 2; } - else if (s[0] <= 0xF0){ + else if (s[0] < 0xF0){ if (limit <= 2){ *error = true; break; @@ -223,7 +253,7 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * codepoint |= ((u32_4tech)((s[2])&0x3F)); utf8_size = 3; } - else{ + else if (s[0] < 0xF8){ if (limit > 3){ *error = true; break; @@ -235,6 +265,15 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * codepoint |= ((u32_4tech)((s[3])&0x3F)); utf8_size = 4; } + else{ + *error = true; + break; + } + + if (codepoint < cp_min_by_utf8_length[utf8_size]){ + *error = true; + break; + } s += utf8_size; limit -= utf8_size; @@ -281,10 +320,10 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * 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 + max_chars; + u16_4tech *s_end = s + length; u8_4tech *d = dst; - u8_4tech *d_end = d + length; + u8_4tech *d_end = d + max_chars; umem_4tech limit = length; umem_4tech needed_max = 0; diff --git a/4coder_project_commands.cpp b/4coder_project_commands.cpp index 97d77ffe..8a7c2459 100644 --- a/4coder_project_commands.cpp +++ b/4coder_project_commands.cpp @@ -50,7 +50,7 @@ static void close_all_files_with_extension(Application_Links *app, Partition *scratch_part, char **extension_list, int32_t extension_count){ Temp_Memory temp = begin_temp_memory(scratch_part); - size_t buffers_to_close_max = partition_remaining(scratch_part)/sizeof(int32_t); + int32_t buffers_to_close_max = partition_remaining(scratch_part)/sizeof(int32_t); int32_t *buffers_to_close = push_array(scratch_part, int32_t, buffers_to_close_max); int32_t buffers_to_close_count = 0; @@ -102,7 +102,7 @@ open_all_files_with_extension_internal(Application_Links *app, String dir, char File_List list = get_file_list(app, dir.str, dir.size); int32_t dir_size = dir.size; - for (int32_t i = 0; i < list.count; ++i){ + for (uint32_t i = 0; i < list.count; ++i){ File_Info *info = list.infos + i; if (info->folder){ if (recursive){ @@ -225,7 +225,7 @@ CUSTOM_COMMAND_SIG(load_project){ } // Read the settings from project.4coder - for (uint32_t i = 0; i < array.count; ++i){ + for (int32_t i = 0; i < array.count; ++i){ Config_Line config_line = read_config_line(array, &i); if (config_line.read_success){ Config_Item item = get_config_item(config_line, mem, array); @@ -344,7 +344,7 @@ CUSTOM_COMMAND_SIG(load_project){ if (read_bool){ if (config_bool_var(array_item, 0, 0, dest_bool)){ - if (dest_bool){ + if (*dest_bool){ append(&msg, "true, "); } else{ diff --git a/4coder_search.cpp b/4coder_search.cpp index e5c76b48..d6669ad4 100644 --- a/4coder_search.cpp +++ b/4coder_search.cpp @@ -40,10 +40,10 @@ struct Search_Range{ int32_t type; uint32_t flags; int32_t buffer; - size_t start; - size_t size; - size_t mid_start; - size_t mid_size; + int32_t start; + int32_t size; + int32_t mid_start; + int32_t mid_size; }; struct Search_Set{ @@ -54,29 +54,29 @@ struct Search_Set{ struct Search_Iter{ String word; - size_t pos; - size_t back_pos; - size_t i; - bool32 range_initialized; + int32_t pos; + int32_t back_pos; + int32_t i; + int32_t range_initialized; }; struct Search_Match{ Buffer_Summary buffer; - size_t start; - size_t end; - bool32 found_match; + int32_t start; + int32_t end; + int32_t found_match; }; static void -search_iter_init(General_Memory *general, Search_Iter *iter, size_t size){ - size_t str_max = size*2; +search_iter_init(General_Memory *general, Search_Iter *iter, int32_t size){ + int32_t str_max = size*2; if (iter->word.str == 0){ iter->word.str = (char*)general_memory_allocate(general, str_max); - iter->word.memory_size = (int32_t)str_max; + iter->word.memory_size = str_max; } else if (iter->word.memory_size < size){ iter->word.str = (char*)general_memory_reallocate_nocopy(general, iter->word.str, str_max); - iter->word.memory_size = (int32_t)str_max; + iter->word.memory_size = str_max; } iter->i = 0; iter->range_initialized = 0; @@ -91,8 +91,8 @@ search_set_init(General_Memory *general, Search_Set *set, int32_t range_count){ set->max = max; } else if (set->max < range_count){ - size_t mem_size = sizeof(Search_Range)*max;; - set->ranges = (Search_Range*)general_memory_reallocate_nocopy(general, set->ranges, mem_size); + set->ranges = (Search_Range*)general_memory_reallocate_nocopy( + general, set->ranges, sizeof(Search_Range)*max); set->max = max; } @@ -100,9 +100,9 @@ search_set_init(General_Memory *general, Search_Set *set, int32_t range_count){ } static void -search_hits_table_alloc(General_Memory *general, Table *hits, uint32_t table_size){ +search_hits_table_alloc(General_Memory *general, Table *hits, int32_t table_size){ void *mem = 0; - size_t mem_size = table_required_mem_size(table_size, sizeof(Offset_String)); + int32_t mem_size = table_required_mem_size(table_size, sizeof(Offset_String)); if (hits->hash_array == 0){ mem = general_memory_allocate(general, mem_size); } @@ -113,12 +113,12 @@ search_hits_table_alloc(General_Memory *general, Table *hits, uint32_t table_siz } static void -search_hits_init(General_Memory *general, Table *hits, String_Space *str, uint32_t table_size, uint32_t str_size){ +search_hits_init(General_Memory *general, Table *hits, String_Space *str, int32_t table_size, int32_t str_size){ if (hits->hash_array == 0){ search_hits_table_alloc(general, hits, table_size); } else{ - size_t mem_size = table_required_mem_size(table_size, sizeof(Offset_String)); + int32_t mem_size = table_required_mem_size(table_size, sizeof(Offset_String)); void *mem = general_memory_reallocate_nocopy(general, hits->hash_array, mem_size); table_init_memory(hits, mem, table_size, sizeof(Offset_String)); } @@ -137,18 +137,19 @@ search_hits_init(General_Memory *general, Table *hits, String_Space *str, uint32 } static int32_t -search_hit_add(General_Memory *general, Table *hits, String_Space *space, char *str, uint32_t len){ +search_hit_add(General_Memory *general, Table *hits, String_Space *space, char *str, int32_t len){ int32_t result = false; Assert(len != 0); Offset_String ostring = strspace_append(space, str, len); if (ostring.size == 0){ - uint32_t new_size = space->max*2; + int32_t new_size = space->max*2; if (new_size < space->max + len){ new_size = space->max + len; } - space->space = (char*)general_memory_reallocate(general, space->space, space->new_pos, new_size); + space->space = (char*)general_memory_reallocate( + general, space->space, space->new_pos, new_size); ostring = strspace_append(space, str, len); } @@ -174,14 +175,14 @@ search_hit_add(General_Memory *general, Table *hits, String_Space *space, char * return(result); } -static size_t -buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char space[1024]; Stream_Chunk chunk = {0}; if (init_stream_chunk(&chunk, app, buffer, pos, space, sizeof(space))){ - bool32 still_looping = true; + int32_t still_looping = true; do{ - for (; pos < (size_t)chunk.end; ++pos){ + for (; pos < chunk.end; ++pos){ char at_pos = chunk.data[pos]; if (!char_is_alpha_numeric(at_pos)) goto double_break; } @@ -207,13 +208,13 @@ enum{ }; static int32_t -match_check(Application_Links *app, Search_Range *range, size_t *pos, Search_Match *result_ptr, String word){ +match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Match *result_ptr, String word){ int32_t found_match = FindResult_None; Search_Match result = *result_ptr; - size_t end_pos = range->start + range->size; + int32_t end_pos = range->start + range->size; - uint32_t type = (range->flags & SearchFlag_MatchMask); + int32_t type = (range->flags & SearchFlag_MatchMask); switch (type){ case SearchFlag_MatchWholeWord: @@ -250,7 +251,9 @@ match_check(Application_Links *app, Search_Range *range, size_t *pos, Search_Mat { char prev = buffer_get_char(app, &result.buffer, result.start - 1); if (!char_is_alpha_numeric(prev)){ - result.end =buffer_seek_alpha_numeric_end(app, &result.buffer, result.start); + result.end = + buffer_seek_alpha_numeric_end( + app, &result.buffer, result.start); if (result.end <= end_pos){ result.found_match = true; @@ -281,14 +284,14 @@ match_check(Application_Links *app, Search_Range *range, size_t *pos, Search_Mat } static int32_t -search_front_to_back_step(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ +search_front_to_back_step(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; Search_Match result = *result_ptr; - size_t end_pos = range->start + range->size; + int32_t end_pos = range->start + range->size; if (*pos + word.size < end_pos){ - size_t start_pos = *pos; + int32_t start_pos = *pos; if (start_pos < range->start){ start_pos = range->start; } @@ -296,11 +299,8 @@ search_front_to_back_step(Application_Links *app, Search_Range *range, String wo int32_t case_insensitive = (range->flags & SearchFlag_CaseInsensitive); result.buffer = get_buffer(app, range->buffer, AccessAll); - - char *word_str = word.str; - size_t word_size = (size_t)word.size; if (case_insensitive){ - buffer_seek_string_insensitive_forward(app, &result.buffer, start_pos, end_pos, word_str, word_size, &result.start); + buffer_seek_string_insensitive_forward(app, &result.buffer, start_pos, end_pos, word.str, word.size, &result.start); } else{ buffer_seek_string_forward(app, &result.buffer, start_pos, end_pos, word.str, word.size, &result.start); @@ -329,7 +329,7 @@ search_front_to_back_step(Application_Links *app, Search_Range *range, String wo } static int32_t -search_front_to_back(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ +search_front_to_back(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; for (;found_match == FindResult_None;){ found_match = search_front_to_back_step(app, range, word, pos, result_ptr); @@ -338,13 +338,13 @@ search_front_to_back(Application_Links *app, Search_Range *range, String word, s } static int32_t -search_back_to_front_step(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ +search_back_to_front_step(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; Search_Match result = *result_ptr; if (*pos > range->start){ - size_t start_pos = *pos; + int32_t start_pos = *pos; result.buffer = get_buffer(app, range->buffer, AccessAll); buffer_seek_string_backward(app, &result.buffer, @@ -374,7 +374,7 @@ search_back_to_front_step(Application_Links *app, Search_Range *range, String wo } static int32_t -search_back_to_front(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ +search_back_to_front(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; for (;found_match == FindResult_None;){ found_match = search_back_to_front_step(app, range, word, pos, result_ptr); @@ -412,12 +412,20 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){ switch (range->type){ case SearchRange_FrontToBack: { - find_result = search_front_to_back(app, range, iter.word, &iter.pos, &result); + find_result = + search_front_to_back(app, range, + iter.word, + &iter.pos, + &result); }break; case SearchRange_BackToFront: { - find_result = search_back_to_front(app, range, iter.word, &iter.back_pos, &result); + find_result = + search_back_to_front(app, range, + iter.word, + &iter.back_pos, + &result); }break; case SearchRange_Wave: @@ -429,20 +437,26 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){ int32_t backward_result = FindResult_PastEnd; if (iter.pos < range->start + range->size){ - forward_result = search_front_to_back(app, range, iter.word, &iter.pos, &forward_match); + forward_result = search_front_to_back(app, range, + iter.word, + &iter.pos, + &forward_match); } if (iter.back_pos > range->start){ - backward_result = search_back_to_front(app, range, iter.word, &iter.back_pos, &backward_match); + backward_result = search_back_to_front(app, range, + iter.word, + &iter.back_pos, + &backward_match); } if (forward_result == FindResult_FoundMatch){ if (backward_result == FindResult_FoundMatch){ find_result = FindResult_FoundMatch; - size_t forward_start = range->mid_start + range->mid_size; - size_t forward_distance = forward_match.start - forward_start; - size_t backward_distance = range->mid_start - backward_match.end; + 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); if (backward_distance < forward_distance){ iter.pos = forward_match.start; @@ -575,8 +589,8 @@ generic_search_all_buffers(Application_Links *app, General_Memory *general, Part file_len = match.buffer.buffer_name_len; } - int32_t line_num_len = int_to_str_size((int32_t)word_pos.line); - int32_t column_num_len = int_to_str_size((int32_t)word_pos.character); + int32_t line_num_len = int_to_str_size(word_pos.line); + int32_t column_num_len = int_to_str_size(word_pos.character); Temp_Memory line_temp = begin_temp_memory(&line_part); String line_str = {0}; @@ -603,9 +617,9 @@ generic_search_all_buffers(Application_Links *app, General_Memory *general, Part String out_line = make_string_cap(spare, 0, str_len); append_ss(&out_line, make_string(file_name, file_len)); append_s_char(&out_line, ':'); - append_int_to_str(&out_line, (int32_t)word_pos.line); + append_int_to_str(&out_line, word_pos.line); append_s_char(&out_line, ':'); - append_int_to_str(&out_line, (int32_t)word_pos.character); + 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); @@ -713,9 +727,9 @@ struct Word_Complete_State{ Search_Iter iter; Table hits; String_Space str; - size_t word_start; - size_t word_end; - bool32 initialized; + int32_t word_start; + int32_t word_end; + int32_t initialized; }; static Word_Complete_State complete_state = {0}; @@ -737,13 +751,14 @@ CUSTOM_COMMAND_SIG(word_complete){ do_init = true; } - size_t word_end = 0; - size_t word_start = 0; - size_t cursor_pos = 0; - size_t size = 0; + int32_t word_end = 0; + int32_t word_start = 0; + int32_t cursor_pos = 0; + int32_t size = 0; if (do_init){ - // NOTE(allen): Get the range where the partial word is written. + // NOTE(allen): Get the range where the + // partial word is written. word_end = view.cursor.pos; word_start = word_end; cursor_pos = word_end - 1; @@ -753,7 +768,7 @@ CUSTOM_COMMAND_SIG(word_complete){ if (init_stream_chunk(&chunk, app, &buffer, cursor_pos, space, sizeof(space))){ int32_t still_looping = true; do{ - for (; cursor_pos >= (size_t)chunk.start; --cursor_pos){ + for (; cursor_pos >= chunk.start; --cursor_pos){ char c = chunk.data[cursor_pos]; if (char_is_alpha(c)){ word_start = cursor_pos; @@ -774,12 +789,13 @@ CUSTOM_COMMAND_SIG(word_complete){ return; } - // NOTE(allen): Initialize the search iterator with the partial word. + // NOTE(allen): Initialize the search iterator + // with the partial word. complete_state.initialized = true; search_iter_init(&global_general, &complete_state.iter, size); buffer_read_range(app, &buffer, word_start, word_end, complete_state.iter.word.str); - complete_state.iter.word.size = (int32_t)size; + complete_state.iter.word.size = size; // NOTE(allen): Initialize the set of ranges to be searched. int32_t buffer_count = get_buffer_count(app); @@ -810,8 +826,11 @@ CUSTOM_COMMAND_SIG(word_complete){ complete_state.set.count = j; // NOTE(allen): Initialize the search hit table. - search_hits_init(&global_general, &complete_state.hits, &complete_state.str, 100, (4 << 10)); - search_hit_add(&global_general, &complete_state.hits, &complete_state.str, complete_state.iter.word.str, complete_state.iter.word.size); + search_hits_init(&global_general, &complete_state.hits, &complete_state.str, + 100, (4 << 10)); + search_hit_add(&global_general, &complete_state.hits, &complete_state.str, + complete_state.iter.word.str, + complete_state.iter.word.size); complete_state.word_start = word_start; complete_state.word_end = word_end; @@ -825,20 +844,26 @@ CUSTOM_COMMAND_SIG(word_complete){ // NOTE(allen): Iterate through matches. if (size > 0){ for (;;){ - uint32_t match_size = 0; - Search_Match match = search_next_match(app, &complete_state.set, &complete_state.iter); + int32_t match_size = 0; + Search_Match match = + search_next_match(app, &complete_state.set, + &complete_state.iter); if (match.found_match){ - match_size = (uint32_t)(match.end - match.start); + match_size = match.end - match.start; Temp_Memory temp = begin_temp_memory(&global_part); char *spare = push_array(&global_part, char, match_size); - buffer_read_range(app, &match.buffer, match.start, match.end, spare); + buffer_read_range(app, &match.buffer, + match.start, match.end, spare); - if (search_hit_add(&global_general, &complete_state.hits, &complete_state.str, spare, match_size)){ - buffer_replace_range(app, &buffer, word_start, word_end, spare, match_size); - Buffer_Seek seek = seek_pos(word_start + match_size); - view_set_cursor(app, &view, seek, true); + if (search_hit_add(&global_general, &complete_state.hits, &complete_state.str, + spare, match_size)){ + buffer_replace_range(app, &buffer, word_start, word_end, + 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; diff --git a/4cpp/4cpp_lexer.h b/4cpp/4cpp_lexer.h index 5c57ec9e..473c1d15 100644 --- a/4cpp/4cpp_lexer.h +++ b/4cpp/4cpp_lexer.h @@ -42,9 +42,6 @@ typedef int32_t b32_4tech; #endif // standard preamble end -#include "4cpp_lexer_types.h" -#include "4cpp_lexer_tables.c" - // 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:; } @@ -54,6 +51,9 @@ typedef int32_t b32_4tech; # define FCPP_LINK static #endif +#include "4cpp_lexer_types.h" +#include "4cpp_lexer_tables.c" + // TODO(allen): revisit this keyword data declaration system struct String_And_Flag{ char *str; @@ -191,7 +191,7 @@ static String_And_Flag keywords[] = { static i32_4tech keywords_count = sizeof(keywords)/sizeof(keywords[0]); API_EXPORT FCPP_LINK Cpp_Get_Token_Result -cpp_get_token(Cpp_Token_Array array, umem_4tech pos)/* +cpp_get_token(Cpp_Token_Array array, i32_4tech 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.) @@ -206,14 +206,14 @@ DOC_SEE(Cpp_Get_Token_Result) i32_4tech first = 0; i32_4tech count = array.count; i32_4tech last = count; + i32_4tech this_start = 0, next_start = 0; if (count > 0){ for (;;){ result.token_index = (first + last)/2; token = token_array + result.token_index; - u32_4tech this_start = token->start; - u32_4tech next_start = 0; + this_start = token->start; if (result.token_index + 1 < count){ next_start = (token + 1)->start; @@ -221,7 +221,6 @@ DOC_SEE(Cpp_Get_Token_Result) else{ next_start = this_start + token->size; } - if (this_start <= pos && pos < next_start){ break; } @@ -231,7 +230,6 @@ DOC_SEE(Cpp_Get_Token_Result) else{ first = result.token_index + 1; } - if (first == last){ result.token_index = first; break; @@ -309,7 +307,7 @@ cpp_pp_directive_to_state(Cpp_Token_Type type){ } FCPP_LINK b32_4tech -cpp__match(char *a, u32_4tech a_len, char *b, u32_4tech b_len){ +cpp__match(char *a, i32_4tech a_len, char *b, i32_4tech b_len){ b32_4tech result = false; if (a_len == b_len){ char *a_end = a + a_len; @@ -325,7 +323,7 @@ cpp__match(char *a, u32_4tech a_len, char *b, u32_4tech b_len){ } FCPP_LINK b32_4tech -cpp__table_match(String_And_Flag *table, i32_4tech count, char *s, u32_4tech len, i32_4tech *index_out){ +cpp__table_match(String_And_Flag *table, i32_4tech count, char *s, i32_4tech len, i32_4tech *index_out){ b32_4tech result = false; String_And_Flag *entry = table; *index_out = -1; @@ -340,7 +338,7 @@ cpp__table_match(String_And_Flag *table, i32_4tech count, char *s, u32_4tech len } FCPP_LINK Cpp_Lex_Result -cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, u32_4tech size, Cpp_Token_Array *token_array_out){ +cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech size, Cpp_Token_Array *token_array_out){ Cpp_Lex_Data S = *S_ptr; Cpp_Token *out_tokens = token_array_out->tokens; @@ -349,7 +347,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, u32_4tech s u8_4tech c = 0; - u32_4tech end_pos = size + S.chunk_pos; + i32_4tech end_pos = size + S.chunk_pos; chunk -= S.chunk_pos; switch (S.__pc__){ @@ -970,7 +968,7 @@ cpp_lex_nonalloc_null_end_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech } FCPP_LINK Cpp_Lex_Result -cpp_lex_nonalloc_no_null_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, u32_4tech size, u32_4tech full_size, +cpp_lex_nonalloc_no_null_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech size, i32_4tech full_size, Cpp_Token_Array *token_array_out){ Cpp_Lex_Result result = 0; if (S_ptr->pos >= full_size){ @@ -1141,7 +1139,7 @@ cpp_shift_token_starts(Cpp_Token_Array *array, i32_4tech from_token_i, i32_4tech } FCPP_LINK Cpp_Token -cpp_index_array(Cpp_Token_Array *array, i32_4tech file_size, u32_4tech index){ +cpp_index_array(Cpp_Token_Array *array, i32_4tech file_size, i32_4tech index){ Cpp_Token result; if (index < array->count){ result = array->tokens[index]; @@ -1157,11 +1155,16 @@ cpp_index_array(Cpp_Token_Array *array, i32_4tech file_size, u32_4tech index){ } API_EXPORT FCPP_LINK Cpp_Relex_Range -cpp_get_relex_range(Cpp_Token_Array *array, u32_4tech start_pos, u32_4tech end_pos) +cpp_get_relex_range(Cpp_Token_Array *array, i32_4tech start_pos, i32_4tech 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.) -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.) -DOC_PARAM(end_pos, The end position of the edited region of the file. In particular, end_pos is the first character after the edited region not effected by the edit. Thus if the edited region contained one character end_pos - start_pos should equal 1. The start and end points are based on the edited region of the file before the edit.) +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.) +DOC_PARAM(end_pos, The end position of the edited region of the file. +In particular, end_pos is the first character after the edited region not effected by the edit. +Thus if the edited region contained one character end_pos - start_pos should equal 1. +The start and end points are based on the edited region of the file before the edit.) */{ Cpp_Relex_Range range = {0}; Cpp_Get_Token_Result get_result = {0}; @@ -1185,18 +1188,27 @@ DOC_PARAM(end_pos, The end position of the edited region of the file. In particu } API_EXPORT FCPP_LINK Cpp_Relex_Data -cpp_relex_init(Cpp_Token_Array *array, u32_4tech start_pos, u32_4tech end_pos, i32_4tech character_shift_amount) +cpp_relex_init(Cpp_Token_Array *array, i32_4tech start_pos, i32_4tech end_pos, i32_4tech character_shift_amount) /* -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.) -DOC_PARAM(end_pos, The end position of the edited region of the file. In particular, end_pos is the first character after the edited region not effected by the edit. Thus if the edited region contained one character end_pos - start_pos should equal 1. The start and end points are based on the edited region of the file before the edit.) +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.) +DOC_PARAM(end_pos, The end position of the edited region of the file. +In particular, end_pos is the first character after the edited region not effected by the edit. +Thus if the edited region contained one character end_pos - start_pos should equal 1. +The start and end points are based on the edited region of the file before the edit.) DOC_PARAM(character_shift_amount, The shift in the characters after the edited region.) DOC_RETURN(Returns a partially initialized relex state.) -DOC(This call does the first setup step of initializing a relex state. To finish initializing the relex state you must tell the state about the positioning of the first chunk it will be fed. There are two methods of doing this, the direct method is with cpp_relex_declare_first_chunk_position, the method that is often more convenient is with cpp_relex_is_start_chunk. If the file is not chunked the second step of initialization can be skipped.) +DOC(This call does the first setup step of initializing a relex state. To finish initializing the relex state +you must tell the state about the positioning of the first chunk it will be fed. There are two methods of doing +this, the direct method is with cpp_relex_declare_first_chunk_position, the method that is often more convenient +is with cpp_relex_is_start_chunk. If the file is not chunked the second step of initialization can be skipped.) DOC_SEE(cpp_relex_declare_first_chunk_position) DOC_SEE(cpp_relex_is_start_chunk) + */{ Cpp_Relex_Data state = {0}; @@ -1524,7 +1536,7 @@ DOC_SEE(cpp_make_token_array) } API_EXPORT FCPP_LINK void -cpp_resize_token_array(Cpp_Token_Array *token_array, u32_4tech new_max)/* +cpp_resize_token_array(Cpp_Token_Array *token_array, i32_4tech 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.) diff --git a/4cpp/4cpp_lexer_types.h b/4cpp/4cpp_lexer_types.h index 4c597489..f53b3b26 100644 --- a/4cpp/4cpp_lexer_types.h +++ b/4cpp/4cpp_lexer_types.h @@ -1,7 +1,7 @@ // TOP -#if !defined(FCPP_LEXER_TYPES_INC) +#ifndef FCPP_LEXER_TYPES_INC #define FCPP_LEXER_TYPES_INC #ifndef ENUM @@ -237,10 +237,10 @@ STRUCT Cpp_Token{ Cpp_Token_Type type; /* DOC(The start field indicates the index of the first character of this token's lexeme.) */ - uint32_t start; + int32_t start; /* DOC(The size field indicates the number of bytes in this token's lexeme.) */ - uint32_t size; + int32_t size; /* DOC(The state_flags should not be used outside of the lexer's implementation.) */ uint16_t state_flags; @@ -273,10 +273,10 @@ STRUCT Cpp_Token_Array{ Cpp_Token *tokens; /* DOC(The count field counts how many tokens in the array are currently used.) */ - uint32_t count; + int32_t count; /* DOC(The max_count field specifies the maximum size the count field may grow to before the tokens array is out of space.) */ - uint32_t max_count; + int32_t max_count; }; static Cpp_Token_Array null_cpp_token_array = {0}; @@ -288,13 +288,13 @@ STRUCT Cpp_Get_Token_Result{ int32_t token_index; /* DOC(The in_whitespace field is true when the query position was actually in whitespace after the result token.) */ - uint32_t in_whitespace; + int32_t in_whitespace; /* DOC(If the token_index refers to an actual token, this is the start value of the token. Otherwise this is zero.) */ - uint32_t token_start; + int32_t token_start; /* DOC(If the token_index refers to an actual token, this is the start+size value of the token. Otherwise this is zero.) */ - uint32_t token_end; + int32_t token_end; }; /* DOC(Cpp_Relex_Range is the return result of the cpp_get_relex_range call.) @@ -321,12 +321,12 @@ DOC_SEE(cpp_lex_data_init) HIDE_MEMBERS() */ STRUCT Cpp_Lex_Data{ char tb[32]; - uint32_t tb_pos; - uint32_t token_start; + int32_t tb_pos; + int32_t token_start; - uint32_t pos; - uint32_t pos_overide; - uint32_t chunk_pos; + int32_t pos; + int32_t pos_overide; + int32_t chunk_pos; Cpp_Lex_FSM fsm; uint8_t white_done; @@ -361,10 +361,10 @@ STRUCT Cpp_Relex_Data{ Cpp_Token end_token; - uint32_t relex_start_position; - uint32_t start_token_index; - uint32_t end_token_index; - uint32_t original_end_token_index; + int32_t relex_start_position; + int32_t start_token_index; + int32_t end_token_index; + int32_t original_end_token_index; int32_t character_shift_amount; diff --git a/4ed.cpp b/4ed.cpp index 54cb706b..08cf2a1c 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -343,8 +343,8 @@ COMMAND_DECL(reopen){ General_Memory *general = &models->mem.general; File_Edit_Positions edit_poss[16]; - umem line_number[16]; - umem column_number[16]; + int32_t line_number[16]; + int32_t column_number[16]; View *vptrs[16]; i32 vptr_count = 0; for (View_Iter iter = file_view_iter_init(&models->layout, file, 0); @@ -364,8 +364,8 @@ COMMAND_DECL(reopen){ for (i32 i = 0; i < vptr_count; ++i){ view_set_file(system, vptrs[i], file, models); - umem line = line_number[i]; - umem character = column_number[i]; + int32_t line = line_number[i]; + int32_t character = column_number[i]; *vptrs[i]->edit_pos = edit_poss[i]; Full_Cursor cursor = view_compute_cursor(system, vptrs[i], seek_line_char(line, character), 0); @@ -488,14 +488,14 @@ case_change_range(System_Functions *system, Mem_Options *mem, View *view, Editin file_update_history_before_edit(mem, file, step, 0, hist_normal); u8 *data = (u8*)file->state.buffer.data; - for (umem i = range.start; i < range.end; ++i){ + for (i32 i = range.start; i < range.end; ++i){ if (data[i] >= a && data[i] <= z){ data[i] += char_delta; } } if (file->state.token_array.tokens){ - file_relex_parallel(system, mem, file, (u32)range.start, (u32)range.end, 0); + file_relex_parallel(system, mem, file, range.start, range.end, 0); } } } @@ -1552,7 +1552,7 @@ update_cli_handle_with_file(System_Functions *system, Models *models, CLI_Handle system->cli_begin_update(cli); if (system->cli_update_step(cli, dest, max, &amount)){ - amount = (u32)eol_in_place_convert_in(dest, amount); + amount = eol_in_place_convert_in(dest, amount); output_file_append(system, models, file, make_string(dest, amount), cursor_at_end); result = 1; } @@ -1591,7 +1591,7 @@ App_Step_Sig(app_step){ if (clipboard.str){ String *dest =working_set_next_clipboard_string(&models->mem.general, &models->working_set, clipboard.size); - dest->size = (i32)eol_convert_in(dest->str, clipboard.str, clipboard.size); + dest->size = eol_convert_in(dest->str, clipboard.str, clipboard.size); } // NOTE(allen): check files are up to date @@ -2503,16 +2503,16 @@ App_Step_Sig(app_step){ layout_compute_absolute_positions(&models->layout, absolute_positions); mouse_position = (divider->v_divider)?(mx):(my); layout_get_min_max(&models->layout, divider, absolute_positions, &min, &max); - absolute_positions[div_id] = clamp_i32(min, mouse_position, max); + absolute_positions[div_id] = clamp(min, mouse_position, max); layout_update_all_positions(&models->layout, absolute_positions); } else{ if (divider->v_divider){ - mouse_position = clamp_i32(0, mx, models->layout.full_width); + mouse_position = clamp(0, mx, models->layout.full_width); } else{ - mouse_position = clamp_i32(0, my, models->layout.full_height); + mouse_position = clamp(0, my, models->layout.full_height); } divider->pos = layout_compute_position(&models->layout, divider, mouse_position); } diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index f5f62908..8617d859 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -347,12 +347,17 @@ DOC_SEE(Command_Line_Interface_Flag) } API_EXPORT void -Clipboard_Post(Application_Links *app, int32_t clipboard_id, char *str, size_t len) +Clipboard_Post(Application_Links *app, int32_t clipboard_id, char *str, int32_t len) /* 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.) DOC_PARAM(len, The len parameter specifies the length of the str string.) -DOC(Stores the string str in the clipboard initially with index 0. Also reports the copy to the operating system, so that it may be pasted into other applications.) +DOC +( +Stores the string str in the clipboard initially with index 0. +Also reports the copy to the operating system, so that it may +be pasted into other applications. +) DOC_SEE(The_4coder_Clipboard) */{ Command_Data *cmd = (Command_Data*)app->cmd_context; @@ -361,13 +366,13 @@ DOC_SEE(The_4coder_Clipboard) General_Memory *general = &models->mem.general; Working_Set *working = &models->working_set; - String *dest = working_set_next_clipboard_string(general, working, (u32)len); - copy_ss(dest, make_string(str, (i32)len)); + String *dest = working_set_next_clipboard_string(general, working, len); + copy_ss(dest, make_string(str, len)); system->post_clipboard(*dest); } -API_EXPORT uint32_t -Clipboard_Count(Application_Links *app, uint32_t clipboard_id) +API_EXPORT int32_t +Clipboard_Count(Application_Links *app, int32_t clipboard_id) /* DOC_PARAM(clipboard_id, This parameter is set up to prepare for future features, it should always be 0 for now.) DOC(This call returns the number of items in the clipboard.) @@ -375,12 +380,12 @@ DOC_SEE(The_4coder_Clipboard) */{ Command_Data *cmd = (Command_Data*)app->cmd_context; Working_Set *working = &cmd->models->working_set; - uint32_t count = working->clipboard_size; + int32_t count = working->clipboard_size; return(count); } -API_EXPORT size_t -Clipboard_Index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len) +API_EXPORT int32_t +Clipboard_Index(Application_Links *app, int32_t clipboard_id, int32_t item_index, char *out, int32_t len) /* 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.) @@ -395,12 +400,12 @@ DOC_SEE(The_4coder_Clipboard) Command_Data *cmd = (Command_Data*)app->cmd_context; Working_Set *working = &cmd->models->working_set; - size_t size = 0; + int32_t size = 0; String *str = working_set_clipboard_index(working, item_index); if (str){ size = str->size; if (out){ - String out_str = make_string_cap(out, 0, (i32)len); + String out_str = make_string_cap(out, 0, len); copy_ss(&out_str, *str); } } @@ -545,7 +550,7 @@ DOC_SEE(Access_Flag) } API_EXPORT bool32 -Buffer_Read_Range(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, char *out) +Buffer_Read_Range(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *out) /* DOC_PARAM(buffer, This parameter specifies the buffer to read.) DOC_PARAM(start, This parameter specifies absolute position of the first character in the read range.) @@ -580,7 +585,7 @@ DOC_SEE(4coder_Buffer_Positioning_System) } API_EXPORT bool32 -Buffer_Replace_Range(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, char *str, size_t len) +Buffer_Replace_Range(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *str, int32_t len) /* 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.) @@ -588,22 +593,32 @@ DOC_PARAM(end, This parameter specifies the absolute position of the the charact DOC_PARAM(str, This parameter specifies the the string to write into the range; it need not be null terminated.) DOC_PARAM(len, This parameter specifies the length of the str string.) DOC_RETURN(This call returns non-zero if the replacement succeeds.) -DOC(If this call succeeds it deletes the range from start to end and writes str in the same position. If end == start then this call is equivalent to inserting the string at start. If len == 0 this call is equivalent to deleteing the range from start to end. +DOC +( +If this call succeeds it deletes the range from start to end +and writes str in the same position. If end == start then +this call is equivalent to inserting the string at start. +If len == 0 this call is equivalent to deleteing the range +from start to end. -This call fails if the buffer does not exist, or if the replace range is not within the bounds of the buffer.) +This call fails if the buffer does not exist, or if the replace +range is not within the bounds of the buffer. +) DOC_SEE(4coder_Buffer_Positioning_System) */{ Command_Data *cmd = (Command_Data*)app->cmd_context; Editing_File *file = imp_get_file(cmd, buffer); bool32 result = false; + int32_t size = 0; if (file){ - u32 size = buffer_size(&file->state.buffer); + size = buffer_size(&file->state.buffer); if (0 <= start && start <= end && end <= size){ result = true; - file_replace_range(cmd->system, cmd->models, file, (u32)start, (u32)end, str, (u32)len); + file_replace_range(cmd->system, cmd->models, + file, start, end, str, len); } fill_buffer_summary(buffer, file, cmd); } @@ -641,7 +656,7 @@ DOC_SEE(Partial_Cursor) } API_EXPORT bool32 -Buffer_Batch_Edit(Application_Links *app, Buffer_Summary *buffer, char *str, size_t str_len, Buffer_Edit *edits, uint32_t edit_count, Buffer_Batch_Edit_Type type) +Buffer_Batch_Edit(Application_Links *app, Buffer_Summary *buffer, char *str, int32_t str_len, Buffer_Edit *edits, int32_t edit_count, Buffer_Batch_Edit_Type type) /* DOC_PARAM(buffer, The buffer on which to apply the batch of edits.) DOC_PARAM(str, This parameter provides all of the source string for the edits in the batch.) @@ -670,9 +685,9 @@ DOC_SEE(Buffer_Batch_Edit_Type) Assert(inverse_edits); char *inv_str = (char*)part->base + part->pos; - umem inv_str_max = part->max - part->pos; + int32_t inv_str_max = part->max - part->pos; - Edit_Spec spec = file_compute_edit(mem, file, edits, str, str_len, inverse_edits, inv_str, (u32)inv_str_max, (u32)edit_count, type); + Edit_Spec spec = file_compute_edit(mem, file, edits, str, str_len, inverse_edits, inv_str, inv_str_max, edit_count, type); file_do_batch_edit(system, models, file, spec, hist_normal, type); @@ -995,7 +1010,7 @@ If the buffer does not exist or if it is not a lexed buffer, the return is zero. } API_EXPORT bool32 -Buffer_Read_Tokens(Application_Links *app, Buffer_Summary *buffer, size_t start_token, size_t end_token, Cpp_Token *tokens_out) +Buffer_Read_Tokens(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out) /* DOC_PARAM(buffer, Specifies the buffer from which to read tokens.) DOC_PARAM(first_token, Specifies the index of the first token to read.) @@ -1022,7 +1037,7 @@ The number of output tokens will be end_token - start_token.) } API_EXPORT bool32 -Buffer_Get_Token_Index(Application_Links *app, Buffer_Summary *buffer, size_t pos, Cpp_Get_Token_Result *get_result) +Buffer_Get_Token_Index(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Get_Token_Result *get_result) /* DOC_PARAM(buffer, The buffer from which to get a token.) DOC_PARAM(pos, The position in the buffer in absolute coordinates.) @@ -1816,26 +1831,32 @@ DOC_SEE(Buffer_Seek) } API_EXPORT bool32 -View_Set_Highlight(Application_Links *app, View_Summary *view, size_t start, size_t end, bool32 turn_on)/* +View_Set_Highlight(Application_Links *app, View_Summary *view, int32_t start, int32_t end, bool32 turn_on)/* DOC_PARAM(view, The view parameter specifies the view in which to set the highlight.) DOC_PARAM(start, This parameter specifies the absolute position of the first character of the highlight range.) DOC_PARAM(end, This parameter specifies the absolute position of the character one past the end of the highlight range.) DOC_PARAM(turn_on, This parameter indicates whether the highlight is being turned on or off.) DOC_RETURN(This call returns non-zero on success.) -DOC(The highlight is mutually exclusive to the cursor. When the turn_on parameter is set to true the highlight will be shown and the cursor will be hidden. After that either setting the cursor with view_set_cursor or calling view_set_highlight and the turn_on set to false, will switch back to showing the cursor.) +DOC +( +The highlight is mutually exclusive to the cursor. When the turn_on parameter +is set to true the highlight will be shown and the cursor will be hidden. After +that either setting the cursor with view_set_cursor or calling view_set_highlight +and the turn_on set to false, will switch back to showing the cursor. +) */{ Command_Data *cmd = (Command_Data*)app->cmd_context; System_Functions *system = cmd->system; View *vptr = imp_get_view(cmd, view); bool32 result = false; - if (vptr != 0){ + if (vptr){ result = true; if (turn_on){ view_set_temp_highlight(system, vptr, start, end); } else{ - vptr->file_data.show_temp_highlight = false; + vptr->file_data.show_temp_highlight = 0; } fill_view_summary(system, view, vptr, cmd); } @@ -1879,7 +1900,7 @@ DOC_SEE(Set_Buffer_Flag) } API_EXPORT bool32 -View_Post_Fade(Application_Links *app, View_Summary *view, float seconds, size_t start, size_t end, int_color color) +View_Post_Fade(Application_Links *app, View_Summary *view, float seconds, int32_t start, int32_t end, int_color color) /* DOC_PARAM(view, The view parameter specifies the view onto which the fade effect shall be posted.) DOC_PARAM(seconds, This parameter specifies the number of seconds the fade effect should last.) @@ -1893,10 +1914,13 @@ DOC_SEE(int_color) View *vptr = imp_get_view(cmd, view); bool32 result = false; - size_t size = end - start; - if (vptr != 0 && size > 0){ - result = true; - view_post_paste_effect(vptr, seconds, (u32)start, (u32)size, color | 0xFF000000); + + int32_t size = end - start; + if (vptr){ + if (size > 0){ + result = true; + view_post_paste_effect(vptr, seconds, start, size, color | 0xFF000000); + } } return(result); @@ -2263,7 +2287,7 @@ DOC(This is a temporary ad-hoc solution to allow some customization of the behav } API_EXPORT void* -Memory_Allocate(Application_Links *app, size_t size) +Memory_Allocate(Application_Links *app, int32_t size) /* DOC_PARAM(size, The size in bytes of the block that should be returned.) DOC(This calls to a low level OS allocator which means it is best used for infrequent, large allocations. The size of the block must be remembered if it will be freed or if it's mem protection status will be changed.) @@ -2276,7 +2300,7 @@ DOC_SEE(memory_free) } API_EXPORT bool32 -Memory_Set_Protection(Application_Links *app, void *ptr, size_t size, Memory_Protect_Flags flags) +Memory_Set_Protection(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags) /* DOC_PARAM(ptr, The base of the block on which to set memory protection flags.) DOC_PARAM(size, The size that was originally used to allocate this block.) @@ -2292,7 +2316,7 @@ DOC_SEE(Memory_Protect_Flags) } API_EXPORT void -Memory_Free(Application_Links *app, void *ptr, size_t size) +Memory_Free(Application_Links *app, void *ptr, int32_t size) /* DOC_PARAM(mem, The base of a block to free.) DOC_PARAM(size, The size that was originally used to allocate this block.) diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index 1743cdda..88b699cc 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -62,7 +62,7 @@ #include "4ed_file_view.cpp" #include "4ed.cpp" -#include "font/4coder_font_static_functions.cpp" +#include "4ed_font_static_functions.cpp" // BOTTOM diff --git a/4ed_buffer.cpp b/4ed_buffer.cpp index 2c2868c7..75163296 100644 --- a/4ed_buffer.cpp +++ b/4ed_buffer.cpp @@ -13,16 +13,16 @@ // Buffer low level operations // -#include "font/4coder_font_data.h" +#include "4ed_font_data.h" #include "4coder_helper/4coder_seek_types.h" typedef struct Cursor_With_Index{ - umem pos; + i32 pos; i32 index; } Cursor_With_Index; inline void -write_cursor_with_index(Cursor_With_Index *positions, i32 *count, umem pos){ +write_cursor_with_index(Cursor_With_Index *positions, i32 *count, i32 pos){ positions[(*count)].index = *count; positions[(*count)].pos = pos; ++(*count); @@ -33,7 +33,7 @@ write_cursor_with_index(Cursor_With_Index *positions, i32 *count, umem pos){ internal void buffer_quick_sort_cursors(Cursor_With_Index *positions, i32 start, i32 pivot){ i32 mid = start; - umem pivot_pos = positions[pivot].pos; + i32 pivot_pos = positions[pivot].pos; for (i32 i = mid; i < pivot; ++i){ if (positions[i].pos < pivot_pos){ CursorSwap__(positions[mid], positions[i]); @@ -100,15 +100,15 @@ buffer_update_cursors(Cursor_With_Index *sorted_positions, i32 count, i32 start, } } -internal b32 -buffer_batch_debug_sort_check(Buffer_Edit *sorted_edits, u32 edit_count){ - b32 result = true; - +internal i32 +buffer_batch_debug_sort_check(Buffer_Edit *sorted_edits, i32 edit_count){ Buffer_Edit *edit = sorted_edits; - size_t start_point = 0; - for (u32 i = 0; i < edit_count; ++i, ++edit){ + i32 i = 0, start_point = 0; + i32 result = 1; + + for (i = 0; i < edit_count; ++i, ++edit){ if (start_point > edit->start){ - result = false; break; + result = 0; break; } start_point = (edit->end < edit->start + 1)?(edit->start + 1):(edit->end); } @@ -117,18 +117,13 @@ buffer_batch_debug_sort_check(Buffer_Edit *sorted_edits, u32 edit_count){ } internal i32 -buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, u32 edit_count){ - Buffer_Edit *edit = sorted_edits; +buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, i32 edit_count){ + i32 i = 0; i32 shift_total = 0, shift_max = 0; - for (u32 i = 0; i < edit_count; ++i, ++edit){ - umem target_length = edit->end - edit->start; - umem edit_length = edit->len; - if (edit_length > target_length){ - shift_total += (i32)(edit_length - target_length); - } - else{ - shift_total -= (i32)(target_length - edit_length); - } + + Buffer_Edit *edit = sorted_edits; + for (i = 0; i < edit_count; ++i, ++edit){ + shift_total += (edit->len - (edit->end - edit->start)); if (shift_total > shift_max){ shift_max = shift_total; } @@ -147,50 +142,36 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, if (lean_right){ for (; edit < end_edit && position < end_position; ++edit){ - umem start = edit->start; - umem end = edit->end; + i32 start = edit->start; + i32 end = edit->end; for (; position->pos < start && position < end_position; ++position){ position->pos += shift_amount; } - umem new_end = start + edit->len + shift_amount; + i32 new_end = start + edit->len + shift_amount; for (; position->pos <= end && position < end_position; ++position){ position->pos = new_end; } - umem target_length = end - start; - umem edit_length = edit->len; - if (edit_length > target_length){ - shift_amount += (i32)(edit_length - target_length); - } - else{ - shift_amount -= (i32)(target_length - edit_length); - } + shift_amount += (edit->len - (end - start)); } } else{ for (; edit < end_edit && position < end_position; ++edit){ - umem start = edit->start; - umem end = edit->end; + i32 start = edit->start; + i32 end = edit->end; for (; position->pos < start && position < end_position; ++position){ position->pos += shift_amount; } - umem new_end = start + shift_amount; + i32 new_end = start + shift_amount; for (; position->pos <= end && position < end_position; ++position){ position->pos = new_end; } - umem target_length = end - start; - umem edit_length = edit->len; - if (edit_length > target_length){ - shift_amount += (i32)(edit_length - target_length); - } - else{ - shift_amount -= (i32)(target_length - edit_length); - } + shift_amount += (edit->len - (end - start)); } } @@ -199,14 +180,7 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, } for (; edit < end_edit; ++edit){ - umem target_length = edit->end - edit->start; - umem edit_length = edit->len; - if (edit_length > target_length){ - shift_amount += (i32)(edit_length - target_length); - } - else{ - shift_amount -= (i32)(target_length - edit_length); - } + shift_amount += (edit->len - (edit->end - edit->start)); } return(shift_amount); @@ -214,9 +188,9 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, ////////////////////////////////////// -internal umem -eol_convert_in(char *dest, char *src, umem size){ - umem i = 0, j = 0, k = 0; +internal i32 +eol_convert_in(char *dest, char *src, i32 size){ + i32 i = 0, j = 0, k = 0; for (; j < size && src[j] != '\r'; ++j); memcpy(dest, src, j); @@ -238,9 +212,9 @@ eol_convert_in(char *dest, char *src, umem size){ return(j); } -internal umem -eol_in_place_convert_in(char *data, umem size){ - umem i = 0, j = 0, k = 0; +internal i32 +eol_in_place_convert_in(char *data, i32 size){ + i32 i = 0, j = 0, k = 0; for (; j < size && data[j] != '\r'; ++j); @@ -262,10 +236,10 @@ eol_in_place_convert_in(char *data, umem size){ } // TODO(allen): iterative memory check? -internal b32 -eol_convert_out(char *dest, umem max, char *src, umem size, umem *size_out){ - b32 result = true; - umem i = 0, j = 0; +internal i32 +eol_convert_out(char *dest, i32 max, char *src, i32 size, i32 *size_out){ + i32 result = 1; + i32 i = 0, j = 0; for (; i < size; ++i, ++j){ if (src[i] == '\n'){ @@ -273,9 +247,7 @@ eol_convert_out(char *dest, umem max, char *src, umem size, umem *size_out){ ++j; dest[j] = '\n'; } - else{ - dest[j] = src[i]; - } + else dest[j] = src[i]; } *size_out = j; @@ -283,10 +255,10 @@ eol_convert_out(char *dest, umem max, char *src, umem size, umem *size_out){ } // TODO(allen): iterative memory check? -internal b32 -eol_in_place_convert_out(char *data, umem size, umem max, umem *size_out){ - b32 result = true; - umem i = 0; +internal i32 +eol_in_place_convert_out(char *data, i32 size, i32 max, i32 *size_out){ + i32 result = 1; + i32 i = 0; for (; i < size; ++i){ if (data[i] == '\n'){ @@ -309,38 +281,32 @@ eol_in_place_convert_out(char *data, umem size, umem max, umem *size_out){ typedef struct Gap_Buffer{ char *data; - umem size1; - umem gap_size; - umem size2; - umem max; + i32 size1; + i32 gap_size; + i32 size2; + i32 max; - u32 *line_starts; - u32 line_count; - u32 line_max; + i32 *line_starts; + i32 line_count; + i32 line_max; } Gap_Buffer; -inline b32 +inline i32 buffer_good(Gap_Buffer *buffer){ - b32 good = (buffer->data != 0); + i32 good = (buffer->data != 0); return(good); } -inline umem -buffer_size_umem(Gap_Buffer *buffer){ - umem size = buffer->size1 + buffer->size2; - return(size); -} - -inline u32 +inline i32 buffer_size(Gap_Buffer *buffer){ - umem size = buffer->size1 + buffer->size2; - return(u32)(size); + i32 size = buffer->size1 + buffer->size2; + return(size); } typedef struct Gap_Buffer_Init{ Gap_Buffer *buffer; char *data; - umem size; + i32 size; } Gap_Buffer_Init; internal Gap_Buffer_Init @@ -352,38 +318,36 @@ buffer_begin_init(Gap_Buffer *buffer, char *data, i32 size){ return(init); } -internal b32 +internal i32 buffer_init_need_more(Gap_Buffer_Init *init){ - b32 result = true; - if (init->buffer->data){ - result = false; - } + i32 result = 1; + if (init->buffer->data) result = 0; return(result); } -internal umem +internal i32 buffer_init_page_size(Gap_Buffer_Init *init){ - umem result = init->size * 2; + i32 result = init->size * 2; return(result); } internal void -buffer_init_provide_page(Gap_Buffer_Init *init, void *page, umem page_size){ +buffer_init_provide_page(Gap_Buffer_Init *init, void *page, i32 page_size){ Gap_Buffer *buffer = init->buffer; buffer->data = (char*)page; buffer->max = page_size; } internal b32 -buffer_end_init(Gap_Buffer_Init *init, void *scratch, umem scratch_size){ +buffer_end_init(Gap_Buffer_Init *init, void *scratch, i32 scratch_size){ Gap_Buffer *buffer = init->buffer; b32 result = false; if (buffer->data && buffer->max >= init->size){ - umem size = init->size; - umem size2 = size*2; - umem osize1 = size - size2; - umem size1 = osize1; + i32 size = init->size; + i32 size2 = size >> 1; + i32 osize1 = size - size2; + i32 size1 = osize1; if (size1 > 0){ size1 = eol_convert_in(buffer->data, init->data, size1); @@ -406,17 +370,18 @@ buffer_end_init(Gap_Buffer_Init *init, void *scratch, umem scratch_size){ typedef struct Gap_Buffer_Stream{ Gap_Buffer *buffer; char *data; - umem end; - umem absolute_end; - b32 separated; + i32 end; + i32 separated; + i32 absolute_end; + b32 use_termination_character; char terminator; } Gap_Buffer_Stream; static Gap_Buffer_Stream null_buffer_stream = {0}; internal b32 -buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, umem start, umem end){ - b32 result = false; +buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, i32 start, i32 end){ + b32 result = 0; if (0 <= start && start < end && end <= buffer->size1 + buffer->size2){ stream->buffer = buffer; @@ -424,15 +389,15 @@ buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, umem start, if (start < buffer->size1){ if (buffer->size1 < end){ - stream->separated = true; + stream->separated = 1; } else{ - stream->separated = false; + stream->separated = 0; } stream->data = buffer->data; } else{ - stream->separated = false; + stream->separated = 0; stream->data = buffer->data + buffer->gap_size; } @@ -447,17 +412,17 @@ buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, umem start, stream->end = stream->absolute_end; } - result = true; + result = 1; } - if (!result){ + if (result == 0){ if (stream->use_termination_character){ stream->buffer = buffer; stream->absolute_end = end; - stream->use_termination_character = false; + stream->use_termination_character = 0; stream->data = (&stream->terminator) - buffer->size1 - buffer->size2; stream->end = stream->absolute_end + 1; - result = true; + result = 1; } } @@ -466,103 +431,91 @@ buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, umem start, internal b32 buffer_stringify_next(Gap_Buffer_Stream *stream){ - b32 result = false; + b32 result = 0; Gap_Buffer *buffer = stream->buffer; if (stream->separated){ stream->data = buffer->data + buffer->gap_size; stream->end = stream->absolute_end; - stream->separated = false; - result = true; + stream->separated = 0; + result = 1; } - if (!result){ + if (result == 0){ if (stream->use_termination_character){ - stream->use_termination_character = false; + stream->use_termination_character = 0; stream->data = (&stream->terminator) - buffer->size1 - buffer->size2; stream->end = stream->absolute_end + 1; - result = true; + result = 1; } } return(result); } -internal b32 -buffer_replace_range(Gap_Buffer *buffer, u32 start, u32 end, char *str, u32 len, i32 *shift_amount, void *scratch, umem scratch_memory, umem *request_amount){ +internal i32 +buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len, i32 *shift_amount, + void *scratch, i32 scratch_memory, i32 *request_amount){ char *data = buffer->data; - u32 size = buffer_size(buffer); - b32 result = false; + i32 size = buffer_size(buffer); + i32 result = 0; + i32 move_size = 0; assert(0 <= start); assert(start <= end); assert(end <= size); - umem target_length = end - start; - - if (target_length <= max_i32 && len <= max_i32){ - if (len >= target_length){ - *shift_amount = (i32)(len - target_length); + *shift_amount = (len - (end - start)); + if (*shift_amount + size <= buffer->max){ + if (end < buffer->size1){ + move_size = buffer->size1 - end; + memmove(data + buffer->size1 + buffer->gap_size - move_size, data + end, move_size); + buffer->size1 -= move_size; + buffer->size2 += move_size; } - else{ - *shift_amount = -(i32)(target_length - len); + if (start > buffer->size1){ + move_size = start - buffer->size1; + memmove(data + buffer->size1, data + buffer->size1 + buffer->gap_size, move_size); + buffer->size1 += move_size; + buffer->size2 -= move_size; } - if (*shift_amount + size <= buffer->max){ - umem move_size = 0; - if (end < buffer->size1){ - move_size = buffer->size1 - end; - memmove(data + buffer->size1 + buffer->gap_size - move_size, data + end, move_size); - buffer->size1 -= move_size; - buffer->size2 += move_size; - } - if (start > buffer->size1){ - move_size = start - buffer->size1; - memmove(data + buffer->size1, data + buffer->size1 + buffer->gap_size, move_size); - buffer->size1 += move_size; - buffer->size2 -= move_size; - } - - memcpy(data + start, str, len); - buffer->size2 = size - end; - buffer->size1 = start + len; - buffer->gap_size -= *shift_amount; - - assert(buffer->size1 + buffer->size2 == size + *shift_amount); - assert(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max); - } - else{ - *request_amount = l_round_up_umem(2*(*shift_amount + size), KB(4)); - result = true; - } + memcpy(data + start, str, len); + buffer->size2 = size - end; + buffer->size1 = start + len; + buffer->gap_size -= *shift_amount; + + assert(buffer->size1 + buffer->size2 == size + *shift_amount); + assert(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max); + } + else{ + *request_amount = l_round_up_i32(2*(*shift_amount + size), 4 << 10); + result = 1; } return(result); } typedef struct Buffer_Batch_State{ - u32 i; + i32 i; i32 shift_total; } Buffer_Batch_State; -// TODO(allen): Now that we are just using Gap_Buffer we could afford to improve this for the Gap_Buffer's behavior. -internal b32 -buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, char *strings, u32 edit_count, void *scratch, umem scratch_size, umem *request_amount){ +// TODO(allen): Now that we are just using Gap_Buffer we could afford to improve +// this for the Gap_Buffer's behavior. +internal i32 +buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, char *strings, i32 edit_count, void *scratch, i32 scratch_size, i32 *request_amount){ Buffer_Edit *edit = 0; - u32 i = state->i; + i32 i = state->i; i32 shift_total = state->shift_total; i32 shift_amount = 0; - b32 result = false; + i32 result = 0; edit = sorted_edits + i; for (; i < edit_count; ++i, ++edit){ - u32 start = (u32)(edit->start + shift_total); - u32 end = (u32)(edit->end + shift_total); - u32 len = (u32)(edit->len); - - result = buffer_replace_range(buffer, start, end, strings + edit->str_start, len, &shift_amount, scratch, scratch_size, request_amount); - if (result){ - break; - } + result = buffer_replace_range(buffer, edit->start + shift_total, edit->end + shift_total, + strings + edit->str_start, edit->len, &shift_amount, + scratch, scratch_size, request_amount); + if (result) break; shift_total += shift_amount; } @@ -573,10 +526,10 @@ buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edi } internal void* -buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, umem new_max){ +buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, i32 new_max){ void *result = buffer->data; - umem size = buffer_size_umem(buffer); - umem new_gap_size = new_max - size; + i32 size = buffer_size(buffer); + i32 new_gap_size = new_max - size; assert(new_max >= size); @@ -595,14 +548,14 @@ buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, umem new_max){ // inline void -buffer_stringify(Gap_Buffer *buffer, umem start, umem end, char *out){ +buffer_stringify(Gap_Buffer *buffer, i32 start, i32 end, char *out){ Gap_Buffer_Stream stream = {0}; - umem i = start; + i32 i = start; if (buffer_stringify_loop(&stream, buffer, i, end)){ - b32 still_looping = false; + b32 still_looping = 0; do{ - umem size = stream.end - i; + i32 size = stream.end - i; memcpy(out, stream.data + i, size); i = stream.end; out += size; @@ -611,20 +564,20 @@ buffer_stringify(Gap_Buffer *buffer, umem start, umem end, char *out){ } } -internal umem -buffer_convert_out(Gap_Buffer *buffer, char *dest, umem max){ +internal i32 +buffer_convert_out(Gap_Buffer *buffer, char *dest, i32 max){ Gap_Buffer_Stream stream = {0}; - u32 size = buffer_size(buffer); + i32 i = 0; + i32 size = buffer_size(buffer); assert(size + buffer->line_count <= max); - umem pos = 0; + i32 pos = 0; if (buffer_stringify_loop(&stream, buffer, 0, size)){ - umem i = 0; - b32 still_looping = false; + b32 still_looping = 0; do{ - umem chunk_size = stream.end - i; - umem out_size = 0; - b32 result = eol_convert_out(dest + pos, max - pos, stream.data + i, chunk_size, &out_size); + i32 chunk_size = stream.end - i; + i32 out_size = 0; + i32 result = eol_convert_out(dest + pos, max - pos, stream.data + i, chunk_size, &out_size); assert(result); i = stream.end; pos += out_size; @@ -635,11 +588,11 @@ buffer_convert_out(Gap_Buffer *buffer, char *dest, umem max){ return(pos); } -internal u32 -buffer_count_newlines(Gap_Buffer *buffer, u32 start, u32 end){ +internal i32 +buffer_count_newlines(Gap_Buffer *buffer, i32 start, i32 end){ Gap_Buffer_Stream stream = {0}; - u32 i = start; - u32 count = 0; + i32 i = start; + i32 count = 0; assert(0 <= start); assert(start <= end); @@ -659,22 +612,22 @@ buffer_count_newlines(Gap_Buffer *buffer, u32 start, u32 end){ } typedef struct Buffer_Measure_Starts{ - u32 i; - u32 count; - u32 start; + i32 i; + i32 count; + i32 start; } Buffer_Measure_Starts; // TODO(allen): Rewrite this with a duff routine // Also make it so that the array goes one past the end // and stores the size in the extra spot. -internal b32 +internal i32 buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){ Gap_Buffer_Stream stream = {0}; - u32 size = (u32)buffer_size(buffer); - u32 start = state->start, i = state->i; - u32 *start_ptr = buffer->line_starts + state->count; - u32 *start_end = buffer->line_starts + buffer->line_max; - b32 result = true; + i32 size = buffer_size(buffer); + i32 start = state->start, i = state->i; + i32 *start_ptr = buffer->line_starts + state->count; + i32 *start_end = buffer->line_starts + buffer->line_max; + i32 result = 1; if (buffer_stringify_loop(&stream, buffer, i, size)){ b32 still_looping = 0; @@ -693,12 +646,14 @@ buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){ still_looping = buffer_stringify_next(&stream); }while(still_looping); } + assert(i == size); + if (start_ptr == start_end){ goto buffer_measure_starts_widths_end; } *start_ptr++ = start; - result = false; + result = 0; buffer_measure_starts_widths_end:; state->i = i; @@ -713,19 +668,22 @@ buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){ } internal void -buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, u32 *character_starts, i32 mode, b32 virtual_white){ +buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, i32 *character_starts, i32 mode, i32 virtual_white){ assert(mode == 0); Gap_Buffer_Stream stream = {0}; + i32 i = 0; + i32 size = buffer_size(buffer); - u32 line_index = 0; - u32 character_index = 0; + i32 line_index = 0; + i32 character_index = 0; + + b32 skipping_whitespace = 0; character_starts[line_index++] = character_index; - b32 skipping_whitespace = false; if (virtual_white){ - skipping_whitespace = true; + skipping_whitespace = 1; } Translation_State tran = {0}; @@ -733,11 +691,8 @@ buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap stream.use_termination_character = 1; stream.terminator = '\n'; - - umem size = buffer_size(buffer); - umem i = 0; if (buffer_stringify_loop(&stream, buffer, i, size)){ - b32 still_looping = false; + b32 still_looping = 0; do{ for (; i < stream.end; ++i){ u8 ch = (u8)stream.data[i]; @@ -751,12 +706,12 @@ buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap ++character_index; character_starts[line_index++] = character_index; if (virtual_white){ - skipping_whitespace = true; + skipping_whitespace = 1; } } else if (behavior.do_codepoint_advance || behavior.do_number_advance){ if (ch != ' ' && ch != '\t'){ - skipping_whitespace = false; + skipping_whitespace = 0; } if (!skipping_whitespace){ @@ -781,16 +736,16 @@ enum{ struct Buffer_Layout_Stop{ u32 status; - u32 line_index; - u32 wrap_line_index; - u32 pos; - u32 next_line_pos; + i32 line_index; + i32 wrap_line_index; + i32 pos; + i32 next_line_pos; f32 x; }; struct Buffer_Measure_Wrap_Params{ Gap_Buffer *buffer; - u32 *wrap_line_index; + i32 *wrap_line_index; System_Functions *system; Render_Font *font; b32 virtual_white; @@ -798,18 +753,18 @@ struct Buffer_Measure_Wrap_Params{ struct Buffer_Measure_Wrap_State{ Gap_Buffer_Stream stream; - u32 i; - u32 size; + i32 i; + i32 size; b32 still_looping; - u32 line_index; + i32 line_index; - u32 current_wrap_index; + i32 current_wrap_index; f32 current_adv; f32 x; - u32 wrap_unit_end; b32 skipping_whitespace; + i32 wrap_unit_end; b32 did_wrap; b32 first_of_the_line; @@ -828,7 +783,7 @@ struct Buffer_Measure_Wrap_State{ #define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); } internal Buffer_Layout_Stop -buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Params params, f32 line_shift, b32 do_wrap, u32 wrap_unit_end){ +buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Params params, f32 line_shift, b32 do_wrap, i32 wrap_unit_end){ Buffer_Measure_Wrap_State S = *S_ptr; Buffer_Layout_Stop S_stop; @@ -839,7 +794,7 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para DrCase(4); } - S.size = (u32)buffer_size(params.buffer); + S.size = buffer_size(params.buffer); if (params.virtual_white){ S_stop.status = BLStatus_NeedLineShift; @@ -903,11 +858,11 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para } S.did_wrap = false; - if (S.i >= S.wrap_unit_end){ + if (S.step.i >= S.wrap_unit_end){ S_stop.status = BLStatus_NeedWrapDetermination; S_stop.line_index = S.line_index - 1; S_stop.wrap_line_index = S.current_wrap_index; - S_stop.pos = S.i; + S_stop.pos = S.step.i; S_stop.x = S.x; DrYield(4, S_stop); @@ -921,7 +876,7 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para S_stop.status = BLStatus_NeedWrapLineShift; S_stop.line_index = S.line_index - 1; S_stop.wrap_line_index = S.current_wrap_index; - S_stop.pos = S.i; + S_stop.pos = S.step.i; DrYield(3, S_stop); } @@ -956,20 +911,20 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para #undef DrReturn internal void -buffer_remeasure_starts(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 line_shift, i32 text_shift){ - u32 *starts = buffer->line_starts; - u32 line_count = buffer->line_count; +buffer_remeasure_starts(Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 line_shift, i32 text_shift){ + i32 *starts = buffer->line_starts; + i32 line_count = buffer->line_count; - assert(0 <= start_line); - assert(start_line <= end_line); - assert(end_line < line_count); + assert(0 <= line_start); + assert(line_start <= line_end); + assert(line_end < line_count); assert(line_count + line_shift <= buffer->line_max); - ++end_line; + ++line_end; // Adjust if (text_shift != 0){ - u32 line_i = end_line; + i32 line_i = line_end; starts += line_i; for (; line_i < line_count; ++line_i, ++starts){ *starts += text_shift; @@ -978,24 +933,24 @@ buffer_remeasure_starts(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li } // Shift - u32 new_line_count = line_count; - u32 new_end_line = end_line; + i32 new_line_count = line_count; + i32 new_line_end = line_end; if (line_shift != 0){ new_line_count += line_shift; - new_end_line += line_shift; + new_line_end += line_shift; - memmove(starts + end_line + line_shift, starts + end_line, - sizeof(i32)*(line_count - end_line)); + memmove(starts + line_end + line_shift, starts + line_end, + sizeof(i32)*(line_count - line_end)); } // Iteration data (yikes! Need better loop system) Gap_Buffer_Stream stream = {0}; - u32 size = buffer_size(buffer); - u32 char_i = starts[start_line]; - u32 line_i = start_line; + i32 size = buffer_size(buffer); + i32 char_i = starts[line_start]; + i32 line_i = line_start; // Line start measurement - u32 start = char_i; + i32 start = char_i; if (buffer_stringify_loop(&stream, buffer, char_i, size)){ b32 still_looping = 0; @@ -1008,8 +963,9 @@ buffer_remeasure_starts(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li ++line_i; start = char_i + 1; - // TODO(allen): I would like to know that I am not guessing here, so let's try to turn the && into an Assert. - if (line_i >= new_end_line && (line_i >= new_line_count || start == starts[line_i])){ + // TODO(allen): I would like to know that I am not guessing here, + // so let's try to turn the && into an Assert. + if (line_i >= new_line_end && (line_i >= new_line_count || start == starts[line_i])){ goto buffer_remeasure_starts_end; } } @@ -1029,40 +985,41 @@ buffer_remeasure_starts(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li } internal void -buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 line_shift, u32 *character_starts, i32 mode, b32 virtual_whitespace){ +buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 line_shift, i32 *character_starts, i32 mode, i32 virtual_whitespace){ assert(mode == 0); - u32 new_line_count = buffer->line_count; + i32 new_line_count = buffer->line_count; - assert(0 <= start_line); - assert(start_line <= end_line); - assert(end_line < new_line_count - line_shift); + assert(0 <= line_start); + assert(line_start <= line_end); + assert(line_end < new_line_count - line_shift); - ++end_line; + ++line_end; // Shift - u32 line_count = new_line_count; - u32 new_end_line = end_line; + i32 line_count = new_line_count; + i32 new_line_end = line_end; if (line_shift != 0){ line_count -= line_shift; - new_end_line += line_shift; + new_line_end += line_shift; - memmove(character_starts + end_line + line_shift, character_starts + end_line, sizeof(i32)*(line_count - end_line + 1)); + memmove(character_starts + line_end + line_shift, character_starts + line_end, sizeof(i32)*(line_count - line_end + 1)); } // Iteration data Gap_Buffer_Stream stream = {0}; - u32 size = buffer_size(buffer); - u32 char_i = buffer->line_starts[start_line]; - u32 line_i = start_line; + i32 size = buffer_size(buffer); + i32 char_i = buffer->line_starts[line_start]; + i32 line_i = line_start; // Character measurement - u32 last_char_start = character_starts[line_i]; - u32 current_char_start = last_char_start; + i32 last_char_start = character_starts[line_i]; + i32 current_char_start = last_char_start; + + b32 skipping_whitespace = 0; - b32 skipping_whitespace = false; if (virtual_whitespace){ - skipping_whitespace = true; + skipping_whitespace = 1; } // Translation @@ -1089,7 +1046,7 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G skipping_whitespace = 1; } - if (line_i >= new_end_line){ + if (line_i >= new_line_end){ goto buffer_remeasure_character_starts_end; } } @@ -1107,20 +1064,14 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G still_looping = buffer_stringify_next(&stream); }while(still_looping); } - assert(line_i >= new_end_line); + + assert(line_i >= new_line_end); + buffer_remeasure_character_starts_end:; // Adjust - if (line_i <= new_end_line){ - u32 old_value = character_starts[line_i]; - u32 new_value = current_char_start; - i32 character_shift = 0; - if (new_value > old_value){ - character_shift = (i32)(new_value - old_value); - } - else{ - character_shift = -(i32)(old_value - new_value); - } + if (line_i <= new_line_end){ + i32 character_shift = current_char_start - character_starts[line_i]; if (character_shift != 0){ character_starts += line_i; @@ -1132,30 +1083,31 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G } internal void -buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 line_shift, f32 *wraps, f32 font_height, f32 *adv, f32 max_width){ - umem new_line_count = buffer->line_count; +buffer_remeasure_wrap_y(Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 line_shift, + f32 *wraps, f32 font_height, f32 *adv, f32 max_width){ + i32 new_line_count = buffer->line_count; - assert(0 <= start_line); - assert(start_line <= end_line); - assert(end_line < new_line_count - line_shift); + assert(0 <= line_start); + assert(line_start <= line_end); + assert(line_end < new_line_count - line_shift); - ++end_line; + ++line_end; // Shift - umem line_count = new_line_count; - umem new_end_line = end_line; + i32 line_count = new_line_count; + i32 new_line_end = line_end; if (line_shift != 0){ line_count -= line_shift; - new_end_line += line_shift; + new_line_end += line_shift; - memmove(wraps + end_line + line_shift, wraps + end_line, sizeof(i32)*(line_count - end_line + 1)); + memmove(wraps + line_end + line_shift, wraps + line_end, sizeof(i32)*(line_count - line_end + 1)); } // Iteration data (yikes! Need better loop system) Gap_Buffer_Stream stream = {0}; - umem size = buffer_size(buffer); - umem char_i = buffer->line_starts[start_line]; - umem line_i = start_line; + i32 size = buffer_size(buffer); + i32 char_i = buffer->line_starts[line_start]; + i32 line_i = line_start; // Line wrap measurement f32 last_wrap = wraps[line_i]; @@ -1163,7 +1115,7 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 f32 x = 0.f; if (buffer_stringify_loop(&stream, buffer, char_i, size)){ - b32 still_looping = false; + b32 still_looping = 0; do{ for (; char_i < stream.end; ++char_i){ u8 ch = (u8)stream.data[char_i]; @@ -1176,7 +1128,7 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 x = 0.f; // TODO(allen): I would like to know that I am not guessing here. - if (line_i >= new_end_line){ + if (line_i >= new_line_end){ goto buffer_remeasure_wraps_end; } } @@ -1200,7 +1152,7 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 buffer_remeasure_wraps_end:; // Adjust - if (line_i <= new_end_line){ + if (line_i <= new_line_end){ f32 y_shift = current_wrap - wraps[line_i]; if (y_shift != 0){ @@ -1212,10 +1164,15 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 } } -internal u32 -binary_search(u32 *array, u32 value, u32 l_bound, u32 u_bound){ - value = clamp_bottom(0, value); - u32 start = l_bound, end = u_bound, i = 0; +internal i32 +binary_search(i32 *array, i32 value, i32 l_bound, i32 u_bound){ + i32 start = l_bound, end = u_bound; + i32 i = 0; + + if (value < 0){ + value = 0; + } + for (;;){ i = (start + end) >> 1; if (array[i] < value){ @@ -1233,48 +1190,54 @@ binary_search(u32 *array, u32 value, u32 l_bound, u32 u_bound){ break; } } + return(i); } -inline u32 -buffer_get_line_index_range(Gap_Buffer *buffer, u32 pos, u32 l_bound, u32 u_bound){ +inline i32 +buffer_get_line_index_range(Gap_Buffer *buffer, i32 pos, i32 l_bound, i32 u_bound){ assert(0 <= l_bound); assert(l_bound <= u_bound); assert(u_bound <= buffer->line_count); assert(buffer->line_starts != 0); - u32 i = binary_search(buffer->line_starts, pos, l_bound, u_bound); + i32 i = binary_search(buffer->line_starts, pos, l_bound, u_bound); return(i); } -inline u32 -buffer_get_line_index(Gap_Buffer *buffer, u32 pos){ - u32 result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); +inline i32 +buffer_get_line_index(Gap_Buffer *buffer, i32 pos){ + i32 result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); return(result); } -inline u32 -buffer_get_line_index_from_character_pos(u32 *character_starts, u32 pos, u32 l_bound, u32 u_bound){ - u32 i = binary_search(character_starts, pos, l_bound, u_bound); +inline i32 +buffer_get_line_index_from_character_pos(i32 *character_starts, i32 pos, i32 l_bound, i32 u_bound){ + i32 i = binary_search(character_starts, pos, l_bound, u_bound); return(i); } -inline u32 -buffer_get_line_index_from_wrapped_y(u32 *wrap_line_index, f32 y, i32 line_height, u32 l_bound, u32 u_bound){ - u32 wrap_index = floor32(y/line_height); - u32 i = binary_search(wrap_line_index, wrap_index, l_bound, u_bound); +inline i32 +buffer_get_line_index_from_wrapped_y(i32 *wrap_line_index, f32 y, i32 line_height, i32 l_bound, i32 u_bound){ + i32 wrap_index = floor32(y/line_height); + i32 i = binary_search(wrap_line_index, wrap_index, l_bound, u_bound); return(i); } internal Partial_Cursor -buffer_partial_from_pos(Gap_Buffer *buffer, umem pos){ +buffer_partial_from_pos(Gap_Buffer *buffer, i32 pos){ Partial_Cursor result = {0}; - u32 size = buffer_size(buffer); - pos = clamp_umem(0, pos, size); + int32_t size = buffer_size(buffer); + if (pos > size){ + pos = size; + } + if (pos < 0){ + pos = 0; + } - u32 line_index = buffer_get_line_index_range(buffer, (u32)pos, 0, (u32)buffer->line_count); + i32 line_index = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); result.pos = pos; result.line = line_index+1; result.character = pos - buffer->line_starts[line_index] + 1; @@ -1283,10 +1246,10 @@ buffer_partial_from_pos(Gap_Buffer *buffer, umem pos){ } internal Partial_Cursor -buffer_partial_from_line_character(Gap_Buffer *buffer, umem line, umem character, b32 reversed){ +buffer_partial_from_line_character(Gap_Buffer *buffer, i32 line, i32 character){ Partial_Cursor result = {0}; - umem line_index = line - 1; + i32 line_index = line - 1; if (line_index >= buffer->line_count){ line_index = buffer->line_count - 1; } @@ -1294,37 +1257,35 @@ buffer_partial_from_line_character(Gap_Buffer *buffer, umem line, umem character line_index = 0; } - umem size = buffer_size(buffer); + i32 size = buffer_size(buffer); - umem this_start = buffer->line_starts[line_index]; - umem max_character = (size-this_start) + 1; + i32 this_start = buffer->line_starts[line_index]; + i32 max_character = (size-this_start) + 1; if (line_index+1 < buffer->line_count){ - umem next_start = buffer->line_starts[line_index+1]; + i32 next_start = buffer->line_starts[line_index+1]; max_character = (next_start-this_start); } - umem adjusted_pos = 0; + i32 adjusted_pos = 0; if (character > 0){ - if (reversed){ - if (character > max_character){ - adjusted_pos = 0; - } - else{ - adjusted_pos = max_character + character; - } + if (character > max_character){ + adjusted_pos = max_character - 1; } else{ - if (character > max_character){ - adjusted_pos = max_character - 1; - } - else{ - adjusted_pos = character - 1; - } + adjusted_pos = character - 1; } } else if (character == 0){ adjusted_pos = 0; } + else{ + if (-character > max_character){ + adjusted_pos = 0; + } + else{ + adjusted_pos = max_character + character; + } + } result.pos = this_start + adjusted_pos; result.line = line_index + 1; @@ -1338,8 +1299,8 @@ struct Buffer_Cursor_Seek_Params{ Buffer_Seek seek; System_Functions *system; Render_Font *font; - u32 *wrap_line_index; - u32 *character_starts; + i32 *wrap_line_index; + i32 *character_starts; b32 virtual_white; b32 return_hint; Full_Cursor *cursor_out; @@ -1352,9 +1313,9 @@ struct Buffer_Cursor_Seek_State{ Gap_Buffer_Stream stream; b32 still_looping; - u32 i; - u32 size; - u32 wrap_unit_end; + i32 i; + i32 size; + i32 wrap_unit_end; b32 first_of_the_line; b32 xy_seek; @@ -1378,7 +1339,7 @@ struct Buffer_Cursor_Seek_State{ #define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); } internal Buffer_Layout_Stop -buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params params, f32 line_shift, b32 do_wrap, u32 wrap_unit_end){ +buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params params, f32 line_shift, b32 do_wrap, i32 wrap_unit_end){ Buffer_Cursor_Seek_State S = *S_ptr; Buffer_Layout_Stop S_stop; @@ -1392,40 +1353,37 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa S.font_height = font_get_height(params.font); S.xy_seek = (params.seek.type == buffer_seek_wrapped_xy || params.seek.type == buffer_seek_unwrapped_xy); - S.size = (u32)buffer_size(params.buffer); + S.size = buffer_size(params.buffer); // Get cursor hint { - u32 line_index = 0; + i32 line_index = 0; switch (params.seek.type){ case buffer_seek_pos: { - params.seek.pos = clamp_u32(0, (u32)params.seek.pos, S.size); + params.seek.pos = clamp(0, params.seek.pos, S.size); - line_index = buffer_get_line_index(params.buffer, (u32)params.seek.pos); + line_index = buffer_get_line_index(params.buffer, params.seek.pos); }break; case buffer_seek_character_pos: { - u32 line_count = params.buffer->line_count; - u32 max_character = params.character_starts[line_count] - 1; - params.seek.pos = clamp_u32(0, (u32)params.seek.pos, max_character); + i32 line_count = params.buffer->line_count; + i32 max_character = params.character_starts[line_count] - 1; + params.seek.pos = clamp(0, params.seek.pos, max_character); - u32 *char_starts = params.character_starts; - - u32 pos = (u32)params.seek.pos; - line_index = buffer_get_line_index_from_character_pos(char_starts, pos, 0, line_count); + line_index = buffer_get_line_index_from_character_pos(params.character_starts, params.seek.pos, 0, params.buffer->line_count); }break; case buffer_seek_line_char: { - line_index = (u32)params.seek.line - 1; + line_index = params.seek.line - 1; line_index = clamp_bottom(0, line_index); }break; case buffer_seek_unwrapped_xy: { - line_index = (u32)(params.seek.y / S.font_height); + line_index = (i32)(params.seek.y / S.font_height); line_index = clamp_bottom(0, line_index); }break; @@ -1437,7 +1395,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa default: InvalidCodePath; } - umem safe_line_index = line_index; + i32 safe_line_index = line_index; if (line_index >= params.buffer->line_count){ safe_line_index = params.buffer->line_count-1; } @@ -1445,7 +1403,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa // Build the cursor hint S.next_cursor.pos = params.buffer->line_starts[safe_line_index]; S.next_cursor.character_pos = params.character_starts[safe_line_index]; - S.next_cursor.line = line_index + 1; + S.next_cursor.line = safe_line_index + 1; S.next_cursor.character = 1; S.next_cursor.wrap_line = params.wrap_line_index[safe_line_index] + 1; S.next_cursor.unwrapped_y = (f32)(safe_line_index * S.font_height); @@ -1459,8 +1417,8 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa // non-virtual character of the line. if (params.virtual_white){ S_stop.status = BLStatus_NeedLineShift; - S_stop.line_index = (u32)(S.next_cursor.line-1); - S_stop.wrap_line_index = (u32)(S.next_cursor.wrap_line-1); + S_stop.line_index = S.next_cursor.line-1; + S_stop.wrap_line_index = S.next_cursor.wrap_line-1; DrYield(1, S_stop); S.next_cursor.unwrapped_x += line_shift; @@ -1536,7 +1494,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa } // Main seek loop - S.i = (u32)S.next_cursor.pos; + S.i = S.next_cursor.pos; S.stream = null_buffer_stream; S.stream.use_termination_character = 1; @@ -1569,8 +1527,8 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa if (params.virtual_white){ S_stop.status = BLStatus_NeedLineShift; - S_stop.line_index = (u32)(S.next_cursor.line-1); - S_stop.wrap_line_index = (u32)(S.next_cursor.wrap_line-1); + S_stop.line_index = S.next_cursor.line-1; + S_stop.wrap_line_index = S.next_cursor.wrap_line-1; DrYield(2, S_stop); } @@ -1588,9 +1546,9 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa if (S.step.i >= S.wrap_unit_end){ S_stop.status = BLStatus_NeedWrapDetermination; - S_stop.line_index = (u32)(S.next_cursor.line-1); - S_stop.wrap_line_index = (u32)(S.next_cursor.wrap_line-1); - S_stop.pos = (u32)(S.step.i); + S_stop.line_index = S.next_cursor.line-1; + S_stop.wrap_line_index = S.next_cursor.wrap_line-1; + S_stop.pos = S.step.i; S_stop.x = S.next_cursor.wrapped_x; DrYield(4, S_stop); @@ -1602,8 +1560,8 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa ++S.next_cursor.wrap_line; if (params.virtual_white){ S_stop.status = BLStatus_NeedWrapLineShift; - S_stop.line_index = (u32)(S.next_cursor.line-1); - S_stop.wrap_line_index = (u32)(S.next_cursor.wrap_line-1); + S_stop.line_index = S.next_cursor.line-1; + S_stop.wrap_line_index = S.next_cursor.wrap_line-1; DrYield(3, S_stop); } @@ -1703,9 +1661,11 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa #undef DrReturn internal void -buffer_invert_edit_shift(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, u32 *str_pos, u32 max, i32 shift_amount){ - u32 pos = *str_pos; - u32 len = (u32)(edit.end - edit.start); +buffer_invert_edit_shift(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, + i32 *str_pos, i32 max, i32 shift_amount){ + i32 pos = *str_pos; + i32 len = edit.end - edit.start; + assert(pos >= 0); assert(pos + len <= max); *str_pos = pos + len; @@ -1717,40 +1677,34 @@ buffer_invert_edit_shift(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inve } inline void -buffer_invert_edit(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, u32 *str_pos, u32 max){ +buffer_invert_edit(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, + i32 *str_pos, i32 max){ buffer_invert_edit_shift(buffer, edit, inverse, strings, str_pos, max, 0); } typedef struct Buffer_Invert_Batch{ - umem i; + i32 i; i32 shift_amount; - u32 len; + i32 len; } Buffer_Invert_Batch; -internal b32 -buffer_invert_batch(Buffer_Invert_Batch *state, Gap_Buffer *buffer, Buffer_Edit *edits, u32 count, Buffer_Edit *inverse, char *strings, u32 *str_pos, u32 max){ +internal i32 +buffer_invert_batch(Buffer_Invert_Batch *state, Gap_Buffer *buffer, Buffer_Edit *edits, i32 count, + Buffer_Edit *inverse, char *strings, i32 *str_pos, i32 max){ i32 shift_amount = state->shift_amount; - umem i = state->i; + i32 i = state->i; Buffer_Edit *edit = edits + i; Buffer_Edit *inv_edit = inverse + i; - b32 result = false; + i32 result = 0; for (; i < count; ++i, ++edit, ++inv_edit){ if (*str_pos + edit->end - edit->start <= max){ buffer_invert_edit_shift(buffer, *edit, inv_edit, strings, str_pos, max, shift_amount); - - umem target_length = edit->end - edit->start; - umem edit_length = edit->len; - if (edit_length > target_length){ - shift_amount += (i32)(edit_length - target_length); - } - else{ - shift_amount -= (i32)(target_length - edit_length); - } + shift_amount += (edit->len - (edit->end - edit->start)); } else{ - result = true; - state->len = (u32)(edit->end - edit->start); + result = 1; + state->len = edit->end - edit->start; } } @@ -1766,7 +1720,7 @@ enum Buffer_Render_Flag{ }; typedef struct Buffer_Render_Item{ - umem index; + i32 index; u32 codepoint; u32 flags; f32 x0, y0; @@ -1784,7 +1738,8 @@ typedef struct Render_Item_Write{ } Render_Item_Write; inline Render_Item_Write -write_render_item(Render_Item_Write write, umem index, u32 codepoint, u32 flags){ +write_render_item(Render_Item_Write write, i32 index, u32 codepoint, u32 flags){ + f32 ch_width = font_get_glyph_advance(write.system, write.font, codepoint); if (write.x <= write.x_max && write.x + ch_width >= write.x_min){ @@ -1807,8 +1762,8 @@ write_render_item(Render_Item_Write write, umem index, u32 codepoint, u32 flags) struct Buffer_Render_Params{ Gap_Buffer *buffer; Buffer_Render_Item *items; - u32 max; - u32 *count; + i32 max; + i32 *count; f32 port_x; f32 port_y; f32 clip_w; @@ -1827,8 +1782,8 @@ struct Buffer_Render_Params{ struct Buffer_Render_State{ Gap_Buffer_Stream stream; b32 still_looping; - umem i; - umem size; + i32 i; + i32 size; f32 shift_x; f32 shift_y; @@ -1838,11 +1793,11 @@ struct Buffer_Render_State{ Render_Item_Write write; f32 byte_advance; - umem line; - umem wrap_line; - umem wrap_unit_end; + i32 line; + i32 wrap_line; b32 skipping_whitespace; b32 first_of_the_line; + i32 wrap_unit_end; Translation_State tran; Translation_Emits emits; @@ -1888,8 +1843,8 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 if (params.virtual_white){ S_stop.status = BLStatus_NeedLineShift; - S_stop.line_index = (u32)(S.line); - S_stop.wrap_line_index = (u32)(S.wrap_line); + S_stop.line_index = S.line; + S_stop.wrap_line_index = S.wrap_line; DrYield(1, S_stop); } @@ -1923,9 +1878,9 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 if (!S.behavior.do_newline && S.step.i >= S.wrap_unit_end){ S_stop.status = BLStatus_NeedWrapDetermination; - S_stop.line_index = (u32)(S.line); - S_stop.wrap_line_index = (u32)(S.wrap_line); - S_stop.pos = (u32)(S.step.i); + S_stop.line_index = S.line; + S_stop.wrap_line_index = S.wrap_line; + S_stop.pos = S.step.i; S_stop.x = S.write.x - S.shift_x; DrYield(4, S_stop); @@ -1934,8 +1889,8 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 if (do_wrap && !S.first_of_the_line){ if (params.virtual_white){ S_stop.status = BLStatus_NeedWrapLineShift; - S_stop.line_index = (u32)(S.line); - S_stop.wrap_line_index = (u32)(S.wrap_line + 1); + S_stop.line_index = S.line; + S_stop.wrap_line_index = S.wrap_line + 1; DrYield(2, S_stop); } @@ -1973,8 +1928,8 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 if (params.virtual_white){ S_stop.status = BLStatus_NeedLineShift; - S_stop.line_index = (u32)(S.line+1); - S_stop.wrap_line_index = (u32)(S.wrap_line+1); + S_stop.line_index = S.line+1; + S_stop.wrap_line_index = S.wrap_line+1; DrYield(3, S_stop); S.skipping_whitespace = 1; @@ -1995,7 +1950,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 } if (!S.skipping_whitespace){ - umem I = S.step.i; + u32 I = S.step.i; switch (n){ case '\r': { @@ -2023,7 +1978,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 } else if (S.behavior.do_number_advance){ u8 n = (u8)S.step.value; - umem I = S.step.i; + u32 I = S.step.i; S.skipping_whitespace = false; S.ch_width = S.byte_advance; diff --git a/4ed_buffer_model.h b/4ed_buffer_model.h index a9abc718..86431e3c 100644 --- a/4ed_buffer_model.h +++ b/4ed_buffer_model.h @@ -15,7 +15,7 @@ struct Buffer_Model_Step{ u32 type; u32 value; - umem i; + i32 i; u32 byte_length; }; diff --git a/4ed_file.cpp b/4ed_file.cpp index 7e407e53..6543dbcc 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -21,7 +21,7 @@ enum Edit_Pos_Set_Type{ struct File_Edit_Positions{ GUI_Scroll_Vars scroll; Full_Cursor cursor; - umem mark; + i32 mark; f32 preferred_x; i32 scroll_i; i32 last_set_type; @@ -54,7 +54,7 @@ edit_pos_set_scroll(File_Edit_Positions *edit_pos, GUI_Scroll_Vars scroll){ // struct Text_Effect{ - u32 start, end; + i32 start, end; u32 color; f32 seconds_down, seconds_max; }; @@ -109,20 +109,20 @@ global_const Editing_File_Settings null_editing_file_settings = {0}; struct Editing_File_State{ Gap_Buffer buffer; - u32 *wrap_line_index; - u32 wrap_max; + i32 *wrap_line_index; + i32 wrap_max; - u32 *character_starts; - u32 character_start_max; + i32 *character_starts; + i32 character_start_max; f32 *line_indents; - u32 line_indent_max; + i32 line_indent_max; - u32 wrap_line_count; + i32 wrap_line_count; - u32 *wrap_positions; - u32 wrap_position_count; - u32 wrap_position_max; + i32 *wrap_positions; + i32 wrap_position_count; + i32 wrap_position_max; Undo_Data undo; @@ -385,14 +385,14 @@ edit_pos_get_new(Editing_File *file, i32 index){ // inline Partial_Cursor -file_compute_cursor_from_pos(Editing_File *file, umem pos){ +file_compute_cursor_from_pos(Editing_File *file, i32 pos){ Partial_Cursor result = buffer_partial_from_pos(&file->state.buffer, pos); return(result); } inline Partial_Cursor -file_compute_cursor_from_line_character(Editing_File *file, umem line, umem character, b32 reversed){ - Partial_Cursor result = buffer_partial_from_line_character(&file->state.buffer, line, character, reversed); +file_compute_cursor_from_line_character(Editing_File *file, i32 line, i32 character){ + Partial_Cursor result = buffer_partial_from_line_character(&file->state.buffer, line, character); return(result); } @@ -407,12 +407,7 @@ file_compute_partial_cursor(Editing_File *file, Buffer_Seek seek, Partial_Cursor case buffer_seek_line_char: { - *cursor = file_compute_cursor_from_line_character(file, seek.line, seek.character, true); - }break; - - case buffer_seek_line_reverse_char: - { - *cursor = file_compute_cursor_from_line_character(file, seek.line, seek.character, false); + *cursor = file_compute_cursor_from_line_character(file, seek.line, seek.character); }break; default: diff --git a/4ed_file_track.h b/4ed_file_track.h index 698f29fb..c09ef694 100644 --- a/4ed_file_track.h +++ b/4ed_file_track.h @@ -31,7 +31,7 @@ enum{ }; FILE_TRACK_LINK File_Track_Result -init_track_system(File_Track_System *system, Partition *scratch, void *table_memory, umem table_memory_size, void *listener_memory, umem listener_memory_size); +init_track_system(File_Track_System *system, Partition *scratch, void *table_memory, i32 table_memory_size, void *listener_memory, i32 listener_memory_size); FILE_TRACK_LINK File_Track_Result add_listener(File_Track_System *system, Partition *scratch, u8 *filename); @@ -40,13 +40,13 @@ FILE_TRACK_LINK File_Track_Result remove_listener(File_Track_System *system, Partition *scratch, u8 *filename); FILE_TRACK_LINK File_Track_Result -move_track_system(File_Track_System *system, Partition *scratch, void *mem, umem size); +move_track_system(File_Track_System *system, Partition *scratch, void *mem, i32 size); FILE_TRACK_LINK File_Track_Result -expand_track_system_listeners(File_Track_System *system, Partition *scratch, void *mem, umem size); +expand_track_system_listeners(File_Track_System *system, Partition *scratch, void *mem, i32 size); FILE_TRACK_LINK File_Track_Result -get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, umem max); +get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 max, i32 *size); FILE_TRACK_LINK File_Track_Result shut_down_track_system(File_Track_System *system, Partition *scratch); diff --git a/4ed_file_track_general.cpp b/4ed_file_track_general.cpp index 3ba45809..0d156cc1 100644 --- a/4ed_file_track_general.cpp +++ b/4ed_file_track_general.cpp @@ -12,7 +12,6 @@ typedef struct{ u32 id[4]; } File_Index; -global_const File_Index null_file_index = {0}; typedef u32 rptr32; @@ -26,7 +25,7 @@ typedef struct { global_const File_Track_Entry null_file_track_entry = {0}; typedef struct { - umem size; + i32 size; u32 tracked_count; u32 max; rptr32 file_table; @@ -37,6 +36,14 @@ typedef struct DLL_Node { struct DLL_Node *prev; } DLL_Node; + + +internal File_Index +zero_file_index(){ + File_Index a = {0}; + return(a); +} + internal i32 file_hash_is_zero(File_Index a){ return ((a.id[0] == 0) && @@ -175,18 +182,18 @@ internal_free_slot(File_Track_Tables *tables, File_Track_Entry *entry){ --tables->tracked_count; } -internal b32 -enough_memory_to_init_table(umem table_memory_size){ - b32 result = (sizeof(File_Track_Tables) + FILE_ENTRY_COST*8 <= table_memory_size); +internal i32 +enough_memory_to_init_table(i32 table_memory_size){ + i32 result = (sizeof(File_Track_Tables) + FILE_ENTRY_COST*8 <= table_memory_size); return(result); } internal void -init_table_memory(File_Track_Tables *tables, umem table_memory_size){ +init_table_memory(File_Track_Tables *tables, i32 table_memory_size){ tables->size = table_memory_size; tables->tracked_count = 0; - u32 max_number_of_entries = (u32)(table_memory_size - sizeof(*tables)) / FILE_ENTRY_COST; + i32 max_number_of_entries = (table_memory_size - sizeof(*tables)) / FILE_ENTRY_COST; tables->file_table = sizeof(*tables); tables->max = max_number_of_entries; @@ -194,7 +201,7 @@ init_table_memory(File_Track_Tables *tables, umem table_memory_size){ internal File_Track_Result move_table_memory(File_Track_Tables *original_tables, - void *mem, umem size){ + void *mem, i32 size){ File_Track_Result result = FileTrack_Good; if (original_tables->size < size){ @@ -205,7 +212,7 @@ move_table_memory(File_Track_Tables *original_tables, tables->size = size; i32 likely_entry_size = FILE_ENTRY_COST; - u32 max_number_of_entries = (u32)(size - sizeof(*tables)) / likely_entry_size; + i32 max_number_of_entries = (size - sizeof(*tables)) / likely_entry_size; tables->file_table = sizeof(*tables); tables->max = max_number_of_entries; diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 0e3c5b2f..ee96d513 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -146,7 +146,7 @@ struct File_Viewing_Data{ Editing_File *file; Full_Cursor temp_highlight; - umem temp_highlight_end_pos; + i32 temp_highlight_end_pos; b32 show_temp_highlight; b32 show_whitespace; @@ -289,9 +289,9 @@ view_file_height(View *view){ return (result); } -inline size_t +inline i32 view_get_cursor_pos(View *view){ - size_t result = 0; + i32 result = 0; if (view->file_data.show_temp_highlight){ result = view->file_data.temp_highlight.pos; } @@ -402,14 +402,14 @@ view_compute_cursor(System_Functions *system, View *view, Buffer_Seek seek, b32 Buffer_Cursor_Seek_State state = {0}; Buffer_Layout_Stop stop = {0}; - umem size = buffer_size(params.buffer); + i32 size = buffer_size(params.buffer); f32 line_shift = 0.f; - u32 wrap_unit_end = 0; - u32 wrap_array_index = 0; + b32 do_wrap = 0; + i32 wrap_unit_end = 0; - b32 do_wrap = false; - b32 first_wrap_determination = true; + b32 first_wrap_determination = 1; + i32 wrap_array_index = 0; do{ stop = buffer_cursor_seek(&state, params, line_shift, do_wrap, wrap_unit_end); @@ -478,13 +478,15 @@ view_compute_max_target_y(i32 lowest_line, i32 line_height, f32 view_height){ internal i32 file_compute_lowest_line(Editing_File *file, f32 font_height){ i32 lowest_line = 0; + Gap_Buffer *buffer = &file->state.buffer; if (file->settings.unwrapped_lines){ - lowest_line = (i32)(buffer->line_count); + lowest_line = buffer->line_count; } else{ - lowest_line = (i32)(file->state.wrap_line_index[buffer->line_count]); + lowest_line = file->state.wrap_line_index[buffer->line_count]; } + return(lowest_line); } @@ -529,7 +531,7 @@ view_move_view_to_cursor(View *view, GUI_Scroll_Vars *scroll, b32 center_view){ } } - target_y = clamp_i32(0, target_y, max_y); + target_y = clamp(0, target_y, max_y); if (cursor_x >= target_x + max_x){ target_x = ceil32(cursor_x - max_x/2); @@ -619,7 +621,7 @@ view_set_cursor_and_scroll(View *view, Full_Cursor cursor, b32 set_preferred_x, } inline void -view_set_temp_highlight(System_Functions *system, View *view, umem pos, umem end_pos){ +view_set_temp_highlight(System_Functions *system, View *view, i32 pos, i32 end_pos){ view->file_data.temp_highlight = view_compute_cursor(system, view, seek_pos(pos), 0); view->file_data.temp_highlight_end_pos = end_pos; view->file_data.show_temp_highlight = 1; @@ -741,8 +743,9 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, models->hook_save_file(&models->app_links, file->id.id); } - umem max = 0, size = 0; + i32 max = 0, size = 0; b32 dos_write_mode = file->settings.dos_write_mode; + char *data = 0; Gap_Buffer *buffer = &file->state.buffer; if (dos_write_mode){ @@ -752,9 +755,8 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, max = buffer_size(buffer); } - Temp_Memory temp = begin_temp_memory(&mem->part); - char *data = 0; b32 used_general = 0; + Temp_Memory temp = begin_temp_memory(&mem->part); char empty = 0; if (max == 0){ data = ∅ @@ -849,14 +851,14 @@ enum{ internal i32 file_grow_starts_as_needed(General_Memory *general, Gap_Buffer *buffer, i32 additional_lines){ b32 result = GROW_NOT_NEEDED; - u32 max = buffer->line_max; - u32 count = buffer->line_count; - u32 target_lines = count + additional_lines; + i32 max = buffer->line_max; + i32 count = buffer->line_count; + i32 target_lines = count + additional_lines; if (target_lines > max || max == 0){ - max = l_round_up_u32(target_lines + max, KB(1)); + max = l_round_up_i32(target_lines + max, KB(1)); - u32 *new_lines = (u32*)general_memory_reallocate(general, buffer->line_starts, sizeof(u32)*count, sizeof(u32)*max); + i32 *new_lines = (i32*)general_memory_reallocate(general, buffer->line_starts, sizeof(i32)*count, sizeof(f32)*max); if (new_lines){ result = GROW_SUCCESS; @@ -877,7 +879,7 @@ file_update_cursor_positions(System_Functions *system, Models *models, Editing_F for (View_Iter iter = file_view_iter_init(layout, file, 0); file_view_iter_good(iter); iter = file_view_iter_next(iter)){ - umem pos = view_get_cursor_pos(iter.view); + i32 pos = view_get_cursor_pos(iter.view); if (!iter.view->file_data.show_temp_highlight){ Full_Cursor cursor = view_compute_cursor(system, iter.view, seek_pos(pos), 0); @@ -896,20 +898,20 @@ file_update_cursor_positions(System_Functions *system, Models *models, Editing_F internal void file_measure_starts(General_Memory *general, Gap_Buffer *buffer){ if (!buffer->line_starts){ - u32 max = buffer->line_max = KB(1); - buffer->line_starts = (u32*)general_memory_allocate(general, max*sizeof(u32)); - TentativeAssert(buffer->line_starts != 0); + i32 max = buffer->line_max = KB(1); + buffer->line_starts = (i32*)general_memory_allocate(general, max*sizeof(i32)); + TentativeAssert(buffer->line_starts); // TODO(allen): when unable to allocate? } Buffer_Measure_Starts state = {0}; while (buffer_measure_starts(&state, buffer)){ - u32 count = state.count; - u32 max = buffer->line_max; + i32 count = state.count; + i32 max = buffer->line_max; max = ((max + 1) << 1); { - u32 *new_lines = (u32*)general_memory_reallocate(general, buffer->line_starts, sizeof(u32)*count, sizeof(u32)*max); + i32 *new_lines = (i32*)general_memory_reallocate(general, buffer->line_starts, sizeof(i32)*count, sizeof(i32)*max); // TODO(allen): when unable to grow? TentativeAssert(new_lines); @@ -919,18 +921,19 @@ file_measure_starts(General_Memory *general, Gap_Buffer *buffer){ } } -// NOTE(allen): These calls assumes that the buffer's line starts are already correct, and that the buffer's line_count is correct. +// NOTE(allen): These calls assumes that the buffer's line starts are already correct, +// and that the buffer's line_count is correct. internal void -file_allocate_metadata_as_needed(General_Memory *general, Gap_Buffer *buffer, void **mem, u32 *mem_max_count, u32 count, u32 item_size){ +file_allocate_metadata_as_needed(General_Memory *general, Gap_Buffer *buffer, void **mem, i32 *mem_max_count, i32 count, i32 item_size){ if (*mem == 0){ - u32 max = ((count+1)*2); + i32 max = ((count+1)*2); max = (max+(0x3FF))&(~(0x3FF)); *mem = general_memory_allocate(general, max*item_size); *mem_max_count = max; } else if (*mem_max_count < count){ - u32 old_max = *mem_max_count; - u32 max = ((count+1)*2); + i32 old_max = *mem_max_count; + i32 max = ((count+1)*2); max = (max+(0x3FF))&(~(0x3FF)); void *new_mem = general_memory_reallocate(general, *mem, item_size*old_max, item_size*max); @@ -943,7 +946,7 @@ file_allocate_metadata_as_needed(General_Memory *general, Gap_Buffer *buffer, vo inline void file_allocate_character_starts_as_needed(General_Memory *general, Editing_File *file){ - file_allocate_metadata_as_needed(general, &file->state.buffer, (void**)&file->state.character_starts, &file->state.character_start_max, file->state.buffer.line_count, sizeof(u32)); + file_allocate_metadata_as_needed(general, &file->state.buffer, (void**)&file->state.character_starts, &file->state. character_start_max, file->state.buffer.line_count, sizeof(i32)); } internal void @@ -989,16 +992,16 @@ struct Code_Wrap_State{ b32 in_pp_body; Code_Wrap_X plane_wrap_x; - u32 *line_starts; - u32 line_index; - u32 next_line_start; + i32 *line_starts; + i32 line_index; + i32 next_line_start; f32 x; b32 consume_newline; Gap_Buffer_Stream stream; - umem size; - umem i; + i32 size; + i32 i; Render_Font *font; f32 tab_indent_amount; @@ -1052,8 +1055,8 @@ wrap_state_set_top(Code_Wrap_State *state, f32 line_shift){ } struct Code_Wrap_Step{ - umem position_start; - umem position_end; + i32 position_start; + i32 position_end; f32 start_x; f32 final_x; @@ -1064,7 +1067,7 @@ struct Code_Wrap_Step{ internal Code_Wrap_Step wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_State *state, i32 fixed_end_point){ Code_Wrap_Step result = {0}; - umem i = state->i; + i32 i = state->i; result.position_start = i; @@ -1110,7 +1113,7 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_ end = fixed_end_point; } - i = clamp_top(i, line_start); + i = clamp_bottom(i, line_start); if (i == line_start){ skipping_whitespace = true; @@ -1391,7 +1394,7 @@ struct Wrap_Current_Shift{ }; internal Wrap_Current_Shift -get_current_shift(Code_Wrap_State *wrap_state, u32 next_line_start){ +get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start){ Wrap_Current_Shift result = {0}; result.shift = wrap_state->wrap_x.paren_nesting[wrap_state->wrap_x.paren_safe_top]; @@ -1473,9 +1476,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, Buffer_Layout_Stop stop = {0}; f32 edge_tolerance = 50.f; - if (edge_tolerance > width){ - edge_tolerance = width; - } + edge_tolerance = clamp_top(edge_tolerance, 50.f); f32 current_line_shift = 0.f; b32 do_wrap = 0; @@ -1498,9 +1499,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, potential_marks = push_array(part, Potential_Wrap_Indent_Pair, floor32(width)); - umem remaining = partition_remaining(part); - umem pair_size = sizeof(Wrap_Indent_Pair); - max_wrap_indent_mark = (i32)(remaining/pair_size); + max_wrap_indent_mark = partition_remaining(part)/sizeof(Wrap_Indent_Pair); wrap_indent_marks = push_array(part, Wrap_Indent_Pair, max_wrap_indent_mark); } @@ -1528,41 +1527,54 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, } } else{ + Translation_State tran = {0}; + Translation_Emits emits = {0}; Gap_Buffer_Stream stream = {0}; i32 word_stage = 0; i32 i = stop.pos; f32 x = stop.x; f32 self_x = 0; + i32 wrap_end_result = size; if (buffer_stringify_loop(&stream, params.buffer, i, size)){ b32 still_looping = 0; do{ for (; i < stream.end; ++i){ - u8 ch = stream.data[i]; + { + u8 ch = stream.data[i]; + translating_fully_process_byte(system, font, &tran, ch, i, size, &emits); + } - switch (word_stage){ - case 0: - { - if (char_is_whitespace(ch)){ - word_stage = 1; - } - else{ - f32 adv = font_get_glyph_advance(params.system, params.font, ch); - - x += adv; - self_x += adv; - if (self_x > width){ + for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){ + TRANSLATION_DECL_GET_STEP(step, behavior, J, emits); + + u32 codepoint = step.value; + switch (word_stage){ + case 0: + { + if (codepoint_is_whitespace(codepoint)){ + word_stage = 1; + } + else{ + f32 adv = font_get_glyph_advance(params.system, params.font, codepoint); + + x += adv; + self_x += adv; + if (self_x > width){ + wrap_end_result = step.i; + goto doublebreak; + } + } + }break; + + case 1: + { + if (!codepoint_is_whitespace(codepoint)){ + wrap_end_result = step.i; goto doublebreak; } - } - }break; - - case 1: - { - if (!char_is_whitespace(ch)){ - goto doublebreak; - } - }break; + }break; + } } } still_looping = buffer_stringify_next(&stream); @@ -1570,7 +1582,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, } doublebreak:; - wrap_unit_end = i; + wrap_unit_end = wrap_end_result; if (x > width){ do_wrap = 1; file_allocate_wrap_positions_as_needed(general, file, wrap_position_index); @@ -1589,7 +1601,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, if (use_tokens){ Code_Wrap_State original_wrap_state = wrap_state; - u32 next_line_start = buffer_size(params.buffer); + i32 next_line_start = buffer_size(params.buffer); if (stop.line_index+1 < params.buffer->line_count){ next_line_start = params.buffer->line_starts[stop.line_index+1]; } @@ -1607,7 +1619,6 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, Wrap_Current_Shift current_shift = get_current_shift(&wrap_state, next_line_start); - if (current_shift.adjust_top_to_this){ wrap_state_set_top(&wrap_state, current_shift.shift); } @@ -1625,12 +1636,16 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, if (wrap_state.token_ptr->type == CPP_TOKEN_COMMENT || wrap_state.token_ptr->type == CPP_TOKEN_STRING_CONSTANT){ + i32 i = wrap_state.token_ptr->start; + i32 end_i = i + wrap_state.token_ptr->size; - u32 i = wrap_state.token_ptr->start; - u32 end_i = i + wrap_state.token_ptr->size; + if (i < wrap_state.i){ + i = wrap_state.i; + } - i = clamp_bottom((u32)wrap_state.i, i); - end_i = clamp_top(end_i, (u32)wrap_state.next_line_start); + if (end_i > wrap_state.next_line_start){ + end_i = wrap_state.next_line_start; + } f32 x = wrap_state.x; @@ -1639,6 +1654,8 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, step.this_token = wrap_state.token_ptr; Gap_Buffer_Stream stream = {0}; + Translation_State tran = {0}; + Translation_Emits emits = {0}; Potential_Wrap_Indent_Pair potential_wrap = {0}; potential_wrap.wrap_position = i; @@ -1652,10 +1669,16 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, while(still_looping){ for (; i < stream.end; ++i){ - u8 ch = stream.data[i]; + { + u8 ch = stream.data[i]; + translating_fully_process_byte(system, font, &tran, ch, i, end_i, &emits); + } - if (!char_is_whitespace(ch)){ - goto doublebreak_stage_vspace; + for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){ + TRANSLATION_DECL_GET_STEP(buffer_step, behav, J, emits); + if (!codepoint_is_whitespace(buffer_step.value)){ + goto doublebreak_stage_vspace; + } } } still_looping = buffer_stringify_next(&stream); @@ -1663,19 +1686,29 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, doublebreak_stage_vspace:; do{ + i32 pos_end_i = end_i; while (still_looping){ for (; i < stream.end; ++i){ - u8 ch = stream.data[i]; - - if (char_is_whitespace(ch)){ - goto doublebreak_stage1; + { + u8 ch = stream.data[i]; + translating_fully_process_byte(system, font, &tran, ch, i, end_i, &emits); } - f32 adv = font_get_glyph_advance(params.system, params.font, ch); - x += adv; - if (!first_word && x > current_width){ - emit_comment_position = 1; - goto doublebreak_stage1; + for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){ + TRANSLATION_DECL_GET_STEP(buffer_step, behav, J, emits); + if (codepoint_is_whitespace(buffer_step.value)){ + pos_end_i = buffer_step.i; + goto doublebreak_stage1; + } + + f32 adv = font_get_glyph_advance(params.system, params.font, buffer_step.value); + x += adv; + + if (!first_word && x > current_width){ + pos_end_i = buffer_step.i; + emit_comment_position = true; + goto doublebreak_stage1; + } } } still_looping = buffer_stringify_next(&stream); @@ -1684,29 +1717,35 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, first_word = 0; if (emit_comment_position){ - step.position_end = i; + step.position_end = pos_end_i; step.final_x = x; goto finished_comment_split; } while(still_looping){ for (; i < stream.end; ++i){ - u8 ch = stream.data[i]; - - if (!char_is_whitespace(ch)){ - goto doublebreak_stage2; + { + u8 ch = stream.data[i]; + translating_fully_process_byte(system, font, &tran, ch, i, end_i, &emits); } - - f32 adv = font_get_glyph_advance(params.system, params.font, ch); - - x += adv; + for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){ + TRANSLATION_DECL_GET_STEP(buffer_step, behav, J, emits); + + if (!codepoint_is_whitespace(buffer_step.value)){ + pos_end_i = buffer_step.i; + goto doublebreak_stage2; + } + + f32 adv = font_get_glyph_advance(params.system, params.font, buffer_step.value); + x += adv; + } } still_looping = buffer_stringify_next(&stream); } doublebreak_stage2:; - potential_wrap.wrap_position = i; + potential_wrap.wrap_position = pos_end_i; potential_wrap.wrap_x = x; }while(still_looping); } @@ -1729,12 +1768,12 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, current_shift = get_current_shift(&wrap_state, next_line_start); - b32 next_token_is_on_line = false; + b32 next_token_is_on_line = 0; if (wrap_state.token_ptr->start < next_line_start){ - next_token_is_on_line = true; + next_token_is_on_line = 1; } - u32 next_wrap_position = (u32)step.position_end; + i32 next_wrap_position = step.position_end; f32 wrap_x = step.final_x; if (wrap_state.token_ptr->start > step.position_start && next_wrap_position < wrap_state.token_ptr->start && next_token_is_on_line){ next_wrap_position = wrap_state.token_ptr->start; @@ -1923,6 +1962,8 @@ file_set_min_base_width(System_Functions *system, Models *models, Editing_File * internal void file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String val, b8 read_only = 0){ + + //Font_Set *font_set = models->font_set; General_Memory *general = &models->mem.general; Partition *part = &models->mem.part; Open_File_Hook_Function *hook_open_file = models->hook_open_file; @@ -1931,8 +1972,8 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * file->state = null_editing_file_state; Gap_Buffer_Init init = buffer_begin_init(&file->state.buffer, val.str, val.size); for (; buffer_init_need_more(&init); ){ - umem page_size = buffer_init_page_size(&init); - page_size = l_round_up_umem(page_size, KB(4)); + i32 page_size = buffer_init_page_size(&init); + page_size = l_round_up_i32(page_size, KB(4)); if (page_size < KB(4)){ page_size = KB(4); } @@ -1940,12 +1981,12 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * buffer_init_provide_page(&init, data, page_size); } - umem scratch_size = partition_remaining(part); + i32 scratch_size = partition_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); - if (buffer_size(&file->state.buffer) < (u32)val.size){ + if (buffer_size(&file->state.buffer) < val.size){ file->settings.dos_write_mode = 1; } file_synchronize_times(system, file); @@ -2045,10 +2086,11 @@ Job_Callback_Sig(job_full_lex){ General_Memory *general = (General_Memory*)data[1]; Gap_Buffer *buffer = &file->state.buffer; - u32 text_size = buffer_size(buffer); - u32 aligned_buffer_size = (text_size + 3)&(~3); + i32 text_size = buffer_size(buffer); - while (memory->size < (umem)aligned_buffer_size){ + i32 aligned_buffer_size = (text_size + 3)&(~3); + + while (memory->size < aligned_buffer_size){ system->grow_thread_memory(memory); } @@ -2063,7 +2105,7 @@ Job_Callback_Sig(job_full_lex){ // TODO(allen): deduplicate this against relex char *chunks[3]; - umem chunk_sizes[3]; + i32 chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2078,10 +2120,10 @@ Job_Callback_Sig(job_full_lex){ do{ char *chunk = chunks[chunk_index]; - umem chunk_size = chunk_sizes[chunk_index]; + i32 chunk_size = chunk_sizes[chunk_index]; i32 result = - cpp_lex_step(&lex, chunk, (i32)chunk_size, text_size, &tokens, 2048); + cpp_lex_step(&lex, chunk, chunk_size, text_size, &tokens, 2048); switch (result){ case LexResult_NeedChunk: ++chunk_index; break; @@ -2192,10 +2234,10 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ Gap_Buffer *buffer = &file->state.buffer; i32 text_size = buffer_size(buffer); - umem mem_size = partition_remaining(part); + i32 mem_size = partition_remaining(part); Cpp_Token_Array tokens; - tokens.max_count = (u32)(mem_size / sizeof(Cpp_Token)); + tokens.max_count = mem_size / sizeof(Cpp_Token); tokens.count = 0; tokens.tokens = push_array(part, Cpp_Token, tokens.max_count); @@ -2205,7 +2247,7 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ // TODO(allen): deduplicate this against relex char *chunks[3]; - umem chunk_sizes[3]; + i32 chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2222,9 +2264,9 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ do{ char *chunk = chunks[chunk_index]; - umem chunk_size = chunk_sizes[chunk_index]; + i32 chunk_size = chunk_sizes[chunk_index]; - i32 result = cpp_lex_step(&lex, chunk, (i32)chunk_size, text_size, &tokens, NO_OUT_LIMIT); + i32 result = cpp_lex_step(&lex, chunk, chunk_size, text_size, &tokens, NO_OUT_LIMIT); switch (result){ case LexResult_NeedChunk: ++chunk_index; break; @@ -2281,7 +2323,7 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ } internal b32 -file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *file, u32 start_i, u32 end_i, i32 shift_amount){ +file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, i32 shift_amount){ General_Memory *general = &mem->general; Partition *part = &mem->part; @@ -2313,7 +2355,7 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi Cpp_Relex_Data state = cpp_relex_init(array, start_i, end_i, shift_amount); char *chunks[3]; - umem chunk_sizes[3]; + i32 chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2326,16 +2368,17 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi i32 chunk_index = 0; char *chunk = chunks[chunk_index]; - umem chunk_size = chunk_sizes[chunk_index]; + i32 chunk_size = chunk_sizes[chunk_index]; - while (!cpp_relex_is_start_chunk(&state, chunk, (i32)chunk_size)){ + while (!cpp_relex_is_start_chunk(&state, chunk, chunk_size)){ ++chunk_index; chunk = chunks[chunk_index]; chunk_size = chunk_sizes[chunk_index]; } for(;;){ - Cpp_Lex_Result lex_result =cpp_relex_step(&state, chunk, (i32)chunk_size, size, array, &relex_array); + Cpp_Lex_Result lex_result = + cpp_relex_step(&state, chunk, chunk_size, size, array, &relex_array); switch (lex_result){ case LexResult_NeedChunk: @@ -2355,7 +2398,7 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi doublebreak:; if (inline_lex){ - u32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array); + 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)); array->tokens = (Cpp_Token*) @@ -2421,13 +2464,10 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, Gap_Buffer *buffer = &file->state.buffer; Cpp_Token_Array *array = &file->state.token_array; - umem remaining = partition_remaining(part); - umem token_size = sizeof(Cpp_Token); - Temp_Memory temp = begin_temp_memory(part); Cpp_Token_Array relex_array; relex_array.count = 0; - relex_array.max_count = (u32)(remaining/token_size); + relex_array.max_count = partition_remaining(part) / sizeof(Cpp_Token); relex_array.tokens = push_array(part, Cpp_Token, relex_array.max_count); i32 size = buffer_size(buffer); @@ -2435,7 +2475,7 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, Cpp_Relex_Data state = cpp_relex_init(array, start_i, end_i, shift_amount); char *chunks[3]; - umem chunk_sizes[3]; + i32 chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2446,18 +2486,18 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, chunks[2] = 0; chunk_sizes[2] = 0; - umem chunk_index = 0; + i32 chunk_index = 0; char *chunk = chunks[chunk_index]; - umem chunk_size = chunk_sizes[chunk_index]; + i32 chunk_size = chunk_sizes[chunk_index]; - while (!cpp_relex_is_start_chunk(&state, chunk, (i32)chunk_size)){ + while (!cpp_relex_is_start_chunk(&state, chunk, chunk_size)){ ++chunk_index; chunk = chunks[chunk_index]; chunk_size = chunk_sizes[chunk_index]; } for(;;){ - Cpp_Lex_Result lex_result = cpp_relex_step(&state, chunk, (i32)chunk_size, size, array, &relex_array); + Cpp_Lex_Result lex_result = cpp_relex_step(&state, chunk, chunk_size, size, array, &relex_array); switch (lex_result){ case LexResult_NeedChunk: @@ -2474,7 +2514,7 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, doublebreak:; i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array); - if ((u32)new_count > array->max_count){ + if (new_count > array->max_count){ i32 new_max = l_round_up_i32(new_count, KB(1)); array->tokens = (Cpp_Token*)general_memory_reallocate(general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token)); array->max_count = new_max; @@ -2488,10 +2528,10 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, } internal void -undo_stack_grow_string(General_Memory *general, Edit_Stack *stack, umem extra_size){ - u32 old_max = stack->max; +undo_stack_grow_string(General_Memory *general, Edit_Stack *stack, i32 extra_size){ + i32 old_max = stack->max; u8 *old_str = stack->strings; - u32 new_max = old_max*2 + (u32)(extra_size); + i32 new_max = old_max*2 + extra_size; u8 *new_str = (u8*)general_memory_reallocate(general, old_str, old_max, new_max); stack->strings = new_str; stack->max = new_max; @@ -2508,27 +2548,27 @@ undo_stack_grow_edits(General_Memory *general, Edit_Stack *stack){ } internal void -child_stack_grow_string(General_Memory *general, Small_Edit_Stack *stack, umem extra_size){ - umem old_max = stack->max; +child_stack_grow_string(General_Memory *general, Small_Edit_Stack *stack, i32 extra_size){ + i32 old_max = stack->max; u8 *old_str = stack->strings; - umem new_max = old_max*2 + extra_size; + i32 new_max = old_max*2 + extra_size; u8 *new_str = (u8*)general_memory_reallocate(general, old_str, old_max, new_max); stack->strings = new_str; - stack->max = (u32)new_max; + stack->max = new_max; } internal void -child_stack_grow_edits(General_Memory *general, Small_Edit_Stack *stack, umem amount){ - umem old_max = stack->edit_max; +child_stack_grow_edits(General_Memory *general, Small_Edit_Stack *stack, i32 amount){ + i32 old_max = stack->edit_max; Buffer_Edit *old_eds = stack->edits; - umem new_max = old_max*2 + amount; + i32 new_max = old_max*2 + amount; Buffer_Edit *new_eds = (Buffer_Edit*)general_memory_reallocate(general, old_eds, old_max*sizeof(Buffer_Edit), new_max*sizeof(Buffer_Edit)); stack->edits = new_eds; - stack->edit_max = (u32)new_max; + stack->edit_max = new_max; } internal i32 -undo_children_push(General_Memory *general, Small_Edit_Stack *children, Buffer_Edit *edits, u32 edit_count, u8 *strings, umem string_size){ +undo_children_push(General_Memory *general, Small_Edit_Stack *children, Buffer_Edit *edits, i32 edit_count, u8 *strings, i32 string_size){ i32 result = children->edit_count; if (children->edit_count + edit_count > children->edit_max){ child_stack_grow_edits(general, children, edit_count); @@ -2543,12 +2583,12 @@ undo_children_push(General_Memory *general, Small_Edit_Stack *children, Buffer_E Buffer_Edit *edit = children->edits + children->edit_count; i32 start_pos = children->size; - for (u32 i = 0; i < edit_count; ++i, ++edit){ + for (i32 i = 0; i < edit_count; ++i, ++edit){ edit->str_start += start_pos; } children->edit_count += edit_count; - children->size += (u32)string_size; + children->size += string_size; return result; } @@ -2628,7 +2668,7 @@ undo_stack_pop(Edit_Stack *stack){ if (stack->edit_count > 0){ Edit_Step *edit = stack->edits + (--stack->edit_count); if (edit->child_count == 0){ - stack->size -= (u32)edit->edit.len; + stack->size -= edit->edit.len; } } } @@ -2671,7 +2711,7 @@ file_post_redo(General_Memory *general, Editing_File *file, Edit_Step step){ } inline void -file_post_history_block(Editing_File *file, u32 pos){ +file_post_history_block(Editing_File *file, i32 pos){ Assert(file->state.undo.history_head_block < pos); Assert(pos < file->state.undo.history.edit_count); @@ -2780,7 +2820,7 @@ view_cursor_move(View *view, Full_Cursor cursor){ } inline void -view_cursor_move(System_Functions *system, View *view, umem pos){ +view_cursor_move(System_Functions *system, View *view, i32 pos){ Full_Cursor cursor = view_compute_cursor(system, view, seek_pos(pos), 0); view_cursor_move(view, cursor); } @@ -2942,8 +2982,8 @@ file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step if (restore_redos){ Edit_Step *redo_start = redo_end; - u32 steps_of_redo = 0; - u32 strings_of_redo = 0; + i32 steps_of_redo = 0; + i32 strings_of_redo = 0; { i32 undo_count = 0; while (redo_start->type == ED_REDO || redo_start->type == ED_UNDO){ @@ -2953,7 +2993,7 @@ file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step } else{ ++steps_of_redo; - strings_of_redo += (u32)redo_start->edit.len; + strings_of_redo += redo_start->edit.len; } } else{ @@ -2967,15 +3007,11 @@ file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step ++redo_start; ++redo_end; - if (file->state.undo.redo.edit_count + steps_of_redo > file->state.undo.redo.edit_max){ - + if (file->state.undo.redo.edit_count + steps_of_redo > file->state.undo.redo.edit_max) undo_stack_grow_edits(general, &file->state.undo.redo); - } - if (file->state.undo.redo.size + strings_of_redo > file->state.undo.redo.max){ - + if (file->state.undo.redo.size + strings_of_redo > file->state.undo.redo.max) undo_stack_grow_string(general, &file->state.undo.redo, strings_of_redo); - } u8 *str_src = file->state.undo.history.strings + redo_end->edit.str_start; u8 *str_dest_base = file->state.undo.redo.strings; @@ -2985,8 +3021,8 @@ file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step Edit_Step *edit_dest = file->state.undo.redo.edits + file->state.undo.redo.edit_count + steps_of_redo; { - u32 undo_count = 0; - for (u32 i = 0; i < steps_of_redo;){ + i32 undo_count = 0; + for (i32 i = 0; i < steps_of_redo;){ --edit_src; str_src -= edit_src->edit.len; if (edit_src->type == ED_REDO){ @@ -2999,7 +3035,7 @@ file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step --edit_dest; *edit_dest = *edit_src; - str_redo_pos -= (u32)edit_dest->edit.len; + str_redo_pos -= edit_dest->edit.len; edit_dest->edit.str_start = str_redo_pos; memcpy(str_dest_base + str_redo_pos, str_src, edit_dest->edit.len); @@ -3157,13 +3193,13 @@ file_edit_cursor_fix(System_Functions *system, Models *models, Editing_File *fil if (view->file_data.file == file){ Assert(view->edit_pos); - umem cursor_pos = cursors[cursor_count++].pos; + i32 cursor_pos = cursors[cursor_count++].pos; Full_Cursor new_cursor = view_compute_cursor(system, view, seek_pos(cursor_pos), 0); GUI_Scroll_Vars scroll = view->edit_pos->scroll; view->edit_pos->mark = cursors[cursor_count++].pos; - i32 new_scroll_i = (i32)cursors[cursor_count++].pos; + i32 new_scroll_i = cursors[cursor_count++].pos; if (view->edit_pos->scroll_i != new_scroll_i){ view->edit_pos->scroll_i = new_scroll_i; @@ -3219,14 +3255,14 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file Partition *part = &mem->part; char *str = (char*)spec.str; - u32 start = (u32)spec.step.edit.start; - u32 end = (u32)spec.step.edit.end; - u32 str_len = (u32)spec.step.edit.len; + i32 start = spec.step.edit.start; + i32 end = spec.step.edit.end; + i32 str_len = spec.step.edit.len; - umem scratch_size = partition_remaining(part); + i32 scratch_size = partition_remaining(part); Assert(scratch_size > 0); - umem request_amount = 0; + i32 request_amount = 0; Assert(end <= buffer_size(&file->state.buffer)); while (buffer_replace_range(&file->state.buffer, start, end, str, str_len, &shift_amount, part->base + part->pos, scratch_size, &request_amount)){ void *new_data = 0; @@ -3281,7 +3317,8 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file } internal void -file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, Edit_Spec spec, History_Mode history_mode, i32 batch_type){ +file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, + Edit_Spec spec, History_Mode history_mode, i32 batch_type){ Mem_Options *mem = &models->mem; General_Memory *general = &mem->general; @@ -3301,9 +3338,9 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, Assert(spec.step.first_child < file->state.undo.children.edit_count); Assert(batch_size >= 0); - u32 scratch_size = (u32)partition_remaining(part); - Buffer_Batch_State state = {0}; - umem request_amount = 0; + i32 scratch_size = partition_remaining(part); + Buffer_Batch_State state = {}; + i32 request_amount = 0; while (buffer_batch_edit_step(&state, &file->state.buffer, batch, (char*)str_base, batch_size, part->base + part->pos, scratch_size, &request_amount)){ @@ -3329,10 +3366,10 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, Buffer_Edit *last_edit = batch + batch_size - 1; if (!file->settings.virtual_white){ - file_relex_parallel(system, mem, file, (u32)first_edit->start, (u32)last_edit->end, shift_total); + file_relex_parallel(system, mem, file, first_edit->start, last_edit->end, shift_total); } else{ - file_relex_serial(mem, file, (u32)first_edit->start, (u32)last_edit->end, shift_total); + file_relex_serial(mem, file, first_edit->start, last_edit->end, shift_total); } } }break; @@ -3354,27 +3391,13 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, for (; token < end_token; ++token){ original = *token; for (; edit < end_edit && edit->start <= original.start; ++edit){ - umem target_length = edit->end - edit->start; - umem edit_length = edit->len; - if (edit_length > target_length){ - local_shift = (i32)(edit_length - target_length); - } - else{ - local_shift = -(i32)(target_length - edit_length); - } + local_shift = (edit->len - (edit->end - edit->start)); shift_amount += local_shift; } token->start += shift_amount; local_shift = 0; for (; edit < end_edit && edit->start < original.start + original.size; ++edit){ - umem target_length = edit->end - edit->start; - umem edit_length = edit->len; - if (edit_length > target_length){ - local_shift = (i32)(edit_length - target_length); - } - else{ - local_shift = -(i32)(target_length - edit_length); - } + local_shift += (edit->len - (edit->end - edit->start)); } token->size += local_shift; shift_amount += local_shift; @@ -3432,7 +3455,7 @@ view_replace_range(System_Functions *system, Models *models, View *view, } inline void -view_post_paste_effect(View *view, f32 seconds, u32 start, u32 size, u32 color){ +view_post_paste_effect(View *view, f32 seconds, i32 start, i32 size, u32 color){ Editing_File *file = view->file_data.file; file->state.paste_effect.start = start; @@ -3454,7 +3477,7 @@ main_style(Models *models){ internal void apply_history_edit(System_Functions *system, Models *models, Editing_File *file, View *view, Edit_Stack *stack, Edit_Step step, History_Mode history_mode){ - Edit_Spec spec = {0}; + Edit_Spec spec = {}; spec.step = step; if (step.child_count == 0){ @@ -3468,7 +3491,7 @@ apply_history_edit(System_Functions *system, Models *models, Editing_File *file, view->edit_pos->mark = view->edit_pos->cursor.pos; Style *style = main_style(models); - view_post_paste_effect(view, 0.333f, (u32)step.edit.start, (u32)step.edit.len, style->main.undo_color); + view_post_paste_effect(view, 0.333f, step.edit.start, step.edit.len, style->main.undo_color); } } else{ @@ -3499,11 +3522,11 @@ view_history_step(System_Functions *system, Models *models, View *view, History_ Assert(file); Assert(view->edit_pos); - b32 do_history_step = false; + b32 do_history_step = 0; Edit_Step step = {}; if (history_mode == hist_backward){ if (file->state.undo.edit_history_cursor > 0){ - do_history_step = true; + do_history_step = 1; step = file->state.undo.history.edits[--file->state.undo.edit_history_cursor]; } } @@ -3511,9 +3534,9 @@ view_history_step(System_Functions *system, Models *models, View *view, History_ if (file->state.undo.edit_history_cursor < file->state.undo.history.edit_count){ Assert(((file->state.undo.history.edit_count - file->state.undo.edit_history_cursor) & 1) == 0); step = file->state.undo.history.edits[--file->state.undo.history.edit_count]; - file->state.undo.history.size -= (u32)step.edit.len; + file->state.undo.history.size -= step.edit.len; ++file->state.undo.edit_history_cursor; - do_history_step = true; + do_history_step = 1; } } @@ -3525,7 +3548,7 @@ view_history_step(System_Functions *system, Models *models, View *view, History_ } internal String* -working_set_next_clipboard_string(General_Memory *general, Working_Set *working, u32 str_size){ +working_set_next_clipboard_string(General_Memory *general, Working_Set *working, i32 str_size){ String *result = 0; i32 clipboard_current = working->clipboard_current; if (working->clipboard_size == 0){ @@ -3594,22 +3617,22 @@ working_set_clipboard_roll_down(Working_Set *working){ internal void clipboard_copy(System_Functions *system, General_Memory *general, Working_Set *working, Range range, Editing_File *file){ - umem size = range.end - range.start; - String *dest = working_set_next_clipboard_string(general, working, (u32)size); + i32 size = range.end - range.start; + String *dest = working_set_next_clipboard_string(general, working, size); buffer_stringify(&file->state.buffer, range.start, range.end, dest->str); - dest->size = (i32)size; + dest->size = size; system->post_clipboard(*dest); } internal Edit_Spec -file_compute_edit(Mem_Options *mem, Editing_File *file, Buffer_Edit *edits, char *str_base, umem str_size, Buffer_Edit *inverse_array, char *inv_str, u32 inv_max, u32 edit_count, i32 batch_type){ +file_compute_edit(Mem_Options *mem, Editing_File *file, Buffer_Edit *edits, char *str_base, i32 str_size, Buffer_Edit *inverse_array, char *inv_str, i32 inv_max, i32 edit_count, i32 batch_type){ General_Memory *general = &mem->general; - u32 inv_str_pos = 0; + i32 inv_str_pos = 0; Buffer_Invert_Batch state = {}; if (buffer_invert_batch(&state, &file->state.buffer, edits, edit_count, inverse_array, inv_str, &inv_str_pos, inv_max)){ - InvalidCodePath; + Assert(0); } i32 first_child = undo_children_push(general, &file->state.undo.children, edits, edit_count, (u8*)(str_base), str_size); @@ -4474,7 +4497,8 @@ show_gui_line(GUI_Target *target, String *string, i32 indent_level, i32 h_align, } internal void -show_gui_int(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message, i32 x){ +show_gui_int(GUI_Target *target, String *string, + i32 indent_level, i32 h_align, char *message, i32 x){ string->size = 0; append_label(string, indent_level, message); append_padding(string, '-', h_align); @@ -4484,7 +4508,8 @@ show_gui_int(GUI_Target *target, String *string, i32 indent_level, i32 h_align, } internal void -show_gui_u64(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message, u64 x){ +show_gui_u64(GUI_Target *target, String *string, + i32 indent_level, i32 h_align, char *message, u64 x){ string->size = 0; append_label(string, indent_level, message); append_padding(string, '-', h_align); @@ -4494,17 +4519,8 @@ show_gui_u64(GUI_Target *target, String *string, i32 indent_level, i32 h_align, } internal void -show_gui_umem(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message, umem x){ - string->size = 0; - append_label(string, indent_level, message); - append_padding(string, '-', h_align); - append_s_char(string, ' '); - append_u64_to_str(string, x); - gui_do_text_field(target, *string, null_string); -} - -internal void -show_gui_int_int(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message, i32 x, i32 m){ +show_gui_int_int(GUI_Target *target, String *string, + i32 indent_level, i32 h_align, char *message, i32 x, i32 m){ string->size = 0; append_label(string, indent_level, message); append_padding(string, '-', h_align); @@ -4554,11 +4570,13 @@ show_gui_scroll(GUI_Target *target, String *string, } internal void -show_gui_cursor(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message,Full_Cursor cursor){ - show_gui_line (target, string, indent_level , 0, message, 0); - show_gui_umem (target, string, indent_level+1, h_align, " pos ", cursor.pos); - show_gui_umem (target, string, indent_level+1, h_align, " line ", cursor.line); - show_gui_umem (target, string, indent_level+1, h_align, " column ", cursor.character); +show_gui_cursor(GUI_Target *target, String *string, + i32 indent_level, i32 h_align, char *message, + Full_Cursor cursor){ + show_gui_line (target, string, indent_level, 0, message, 0); + show_gui_int (target, string, indent_level+1, h_align, " pos ", cursor.pos); + show_gui_int (target, string, indent_level+1, h_align, " line ", cursor.line); + show_gui_int (target, string, indent_level+1, h_align, " column ", cursor.character); show_gui_float(target, string, indent_level+1, h_align, " unwrapped_x ", cursor.unwrapped_x); show_gui_float(target, string, indent_level+1, h_align, " unwrapped_y ", cursor.unwrapped_y); show_gui_float(target, string, indent_level+1, h_align, " wrapped_x ", cursor.wrapped_x); @@ -5380,9 +5398,9 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su string.size = 0; append_ss(&string, make_lit_string("part memory: ")); - append_int_to_str(&string, (i32)part->pos); + append_int_to_str(&string, part->pos); append_s_char(&string, '/'); - append_int_to_str(&string, (i32)part->max); + append_int_to_str(&string, part->max); gui_do_text_field(target, string, empty_str); #if !defined(FED_DEBUG_MEM_H) @@ -5397,7 +5415,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su append_ss(&string, make_lit_string(" free: ")); } - append_int_to_str(&string, (i32)bubble->size); + append_int_to_str(&string, bubble->size); append_padding(&string, ' ', 40); gui_do_text_field(target, string, empty_str); } @@ -5470,7 +5488,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su #define SHOW_GUI_INT(n, h, str, v) show_gui_int(target, &string, n, h, " " str " ", v) #define SHOW_GUI_INT_INT(n, h, str, v, m) show_gui_int_int(target, &string, n, h, " " str " ", v, m) #define SHOW_GUI_U64(n, h, str, v) show_gui_u64(target, &string, n, h, " " str " ", v) -#define SHOW_GUI_UMEM(n, h, str, v) show_gui_umem(target, &string, n, h, " " str " ", v) #define SHOW_GUI_ID(n, h, str, v) show_gui_id(target, &string, n, h, " " str, v) #define SHOW_GUI_FLOAT(n, h, str, v) show_gui_float(target, &string, n, h, " " str " ", v) #define SHOW_GUI_BOOL(n, h, str, v) do { if (v) { show_gui_line(target, &string, n, h, " " str " ", "true"); }\ @@ -5510,8 +5527,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su SHOW_GUI_LINE(1, "file data:"); SHOW_GUI_BOOL(2, h_align, "has file", view_ptr->file_data.file); SHOW_GUI_BOOL(2, h_align, "show temp highlight", view_ptr->file_data.show_temp_highlight); - SHOW_GUI_UMEM(2, h_align, "start temp highlight", view_ptr->file_data.temp_highlight.pos); - SHOW_GUI_UMEM(2, h_align, "end temp highlight", view_ptr->file_data.temp_highlight_end_pos); + SHOW_GUI_INT (2, h_align, "start temp highlight", view_ptr->file_data.temp_highlight.pos); + SHOW_GUI_INT (2, h_align, "end temp highlight", view_ptr->file_data.temp_highlight_end_pos); SHOW_GUI_BOOL(2, h_align, "show whitespace", view_ptr->file_data.show_whitespace); SHOW_GUI_BOOL(2, h_align, "locked", view_ptr->file_data.file_locked); @@ -5529,7 +5546,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su SHOW_GUI_BLANK (2); SHOW_GUI_CURSOR(2, h_align, "cursor:", edit_pos->cursor); SHOW_GUI_BLANK (2); - SHOW_GUI_UMEM (2, h_align, "mark", edit_pos->mark); + SHOW_GUI_INT (2, h_align, "mark", edit_pos->mark); SHOW_GUI_FLOAT (2, h_align, "preferred_x", edit_pos->preferred_x); SHOW_GUI_INT (2, h_align, "scroll_i", edit_pos->scroll_i); } @@ -5543,7 +5560,9 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su SHOW_GUI_BLANK (0); SHOW_GUI_LINE (1, "gui target"); - SHOW_GUI_INT_INT(2, h_align, "gui partition", (int32_t)view_ptr->gui_target.push.pos, (int32_t)view_ptr->gui_target.push.max); + SHOW_GUI_INT_INT(2, h_align, "gui partition", + view_ptr->gui_target.push.pos, + view_ptr->gui_target.push.max); SHOW_GUI_BLANK (2); SHOW_GUI_ID (2, h_align, "active", view_ptr->gui_target.active); @@ -5679,7 +5698,7 @@ do_step_file_view(System_Functions *system, View *view, i32_Rect rect, b32 is_ac GUI_Target *target = &view->gui_target; GUI_Interpret_Result interpret_result = {0}; - vars.target_y = clamp_i32(0, vars.target_y, max_y); + vars.target_y = clamp(0, vars.target_y, max_y); result.vars = vars; result.region = region; @@ -5812,7 +5831,7 @@ do_step_file_view(System_Functions *system, View *view, i32_Rect rect, b32 is_ac if (gui_id_eq(target->mouse_hot, id)){ v = unlerp(gui_session.scroll_top, (f32)my, gui_session.scroll_bottom); - v = clamp_f32(0.f, v, 1.f); + v = clamp(0.f, v, 1.f); result.vars.target_y = round32(lerp(0.f, v, (f32)max_y)); gui_activate_scrolling(target); @@ -5827,7 +5846,7 @@ do_step_file_view(System_Functions *system, View *view, i32_Rect rect, b32 is_ac result.vars.target_y += user_input->mouse.wheel*target->delta; result.vars.target_y = - clamp_i32(0, result.vars.target_y, max_y); + clamp(0, result.vars.target_y, max_y); gui_activate_scrolling(target); result.is_animating = 1; } @@ -5927,9 +5946,7 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act f32 left_side_space = 0; - umem remaining = partition_remaining(part); - umem render_item_size = sizeof(Buffer_Render_Item); - u32 max = (u32)(remaining / render_item_size); + i32 max = partition_remaining(part) / sizeof(Buffer_Render_Item); Buffer_Render_Item *items = push_array(part, Buffer_Render_Item, max); Font_ID font_id = file->settings.font_id; @@ -5951,9 +5968,9 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act render_cursor = view_compute_cursor(system, view, seek_unwrapped_xy(0, scroll_y, 0), 1); } - view->edit_pos->scroll_i = (i32)render_cursor.pos; + view->edit_pos->scroll_i = render_cursor.pos; - u32 count = 0; + i32 count = 0; { b32 wrapped = !file->settings.unwrapped_lines; @@ -5980,11 +5997,11 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act Buffer_Layout_Stop stop = {0}; f32 line_shift = 0.f; - b32 do_wrap = false; - u32 wrap_unit_end = 0; + b32 do_wrap = 0; + i32 wrap_unit_end = 0; - b32 first_wrap_determination = true; - u32 wrap_array_index = 0; + b32 first_wrap_determination = 1; + i32 wrap_array_index = 0; do{ stop = buffer_render_data(&state, params, line_shift, do_wrap, wrap_unit_end); @@ -6021,22 +6038,22 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act }while(stop.status != BLStatus_Finished); } - u32 cursor_begin = 0, cursor_end = 0; + i32 cursor_begin = 0, cursor_end = 0; u32 cursor_color = 0, at_cursor_color = 0; if (view->file_data.show_temp_highlight){ - cursor_begin = (u32)view->file_data.temp_highlight.pos; - cursor_end = (u32)view->file_data.temp_highlight_end_pos; + cursor_begin = view->file_data.temp_highlight.pos; + cursor_end = view->file_data.temp_highlight_end_pos; cursor_color = style->main.highlight_color; at_cursor_color = style->main.at_highlight_color; } else{ - cursor_begin = (u32)view->edit_pos->cursor.pos; + cursor_begin = view->edit_pos->cursor.pos; cursor_end = cursor_begin + 1; cursor_color = style->main.cursor_color; at_cursor_color = style->main.at_cursor_color; } - u32 token_i = 0; + i32 token_i = 0; u32 main_color = style->main.default_color; u32 special_color = style->main.special_character_color; u32 ghost_color = style->main.ghost_character_color; @@ -6049,12 +6066,12 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act u32 mark_color = style->main.mark_color; Buffer_Render_Item *item = items; Buffer_Render_Item *item_end = item + count; - umem prev_ind = max_umem; + i32 prev_ind = -1; u32 highlight_color = 0; u32 highlight_this_color = 0; for (; item < item_end; ++item){ - umem ind = item->index; + i32 ind = item->index; highlight_this_color = 0; if (tokens_use && ind != prev_ind){ Cpp_Token current_token = token_array.tokens[token_i-1]; @@ -6234,9 +6251,9 @@ draw_file_bar(System_Functions *system, Render_Target *target, View *view, Editi char bar_space[526]; String bar_text = make_fixed_width_string(bar_space); append_ss (&bar_text, make_lit_string(" L#")); - append_int_to_str(&bar_text, (int32_t)view->edit_pos->cursor.line); + append_int_to_str(&bar_text, view->edit_pos->cursor.line); append_ss (&bar_text, make_lit_string(" C#")); - append_int_to_str(&bar_text, (int32_t)view->edit_pos->cursor.character); + append_int_to_str(&bar_text, view->edit_pos->cursor.character); append_ss(&bar_text, make_lit_string(" -")); diff --git a/font/4coder_font_data.h b/4ed_font_data.h similarity index 100% rename from font/4coder_font_data.h rename to 4ed_font_data.h diff --git a/font/4coder_font_interface.h b/4ed_font_interface.h similarity index 100% rename from font/4coder_font_interface.h rename to 4ed_font_interface.h diff --git a/font/4coder_font_interface_to_os.h b/4ed_font_interface_to_os.h similarity index 100% rename from font/4coder_font_interface_to_os.h rename to 4ed_font_interface_to_os.h diff --git a/font/4coder_font_static_functions.cpp b/4ed_font_static_functions.cpp similarity index 99% rename from font/4coder_font_static_functions.cpp rename to 4ed_font_static_functions.cpp index 32dfdc3a..c65cd2f4 100644 --- a/font/4coder_font_static_functions.cpp +++ b/4ed_font_static_functions.cpp @@ -9,7 +9,7 @@ // TOP -#include "4coder_font_data.h" +#include "4ed_font_data.h" internal f32 font_get_byte_advance(Render_Font *font){ diff --git a/4ed_layout.cpp b/4ed_layout.cpp index 6dd8dcd0..4fa49eec 100644 --- a/4ed_layout.cpp +++ b/4ed_layout.cpp @@ -504,16 +504,16 @@ layout_update_pos_step(Editing_Layout *layout, i32 divider_id, i32_Rect rect, i3 i32 pos = abs_pos[divider_id]; i32_Rect r1 = rect, r2 = rect; f32 lpos = unlerp((f32)p0, (f32)pos, (f32)p1); - lpos = clamp_f32(0.f, lpos, 1.f); + lpos = clamp(0.f, lpos, 1.f); div->pos = lpos; if (div->v_divider){ - pos = clamp_i32(r1.x0, pos, r2.x1); + pos = clamp(r1.x0, pos, r2.x1); r1.x1 = pos; r2.x0 = pos; } else{ - pos = clamp_i32(r1.y0, pos, r2.y1); + pos = clamp(r1.y0, pos, r2.y1); r1.y1 = pos; r2.y0 = pos; } diff --git a/4ed_math.h b/4ed_math.h index 04fb1a01..9f3df328 100644 --- a/4ed_math.h +++ b/4ed_math.h @@ -432,28 +432,21 @@ unlerp(f32 a, f32 x, f32 b){ } inline f32 -clamp_f32(f32 a, f32 n, f32 z){ +clamp(f32 a, f32 n, f32 z){ if (n < a) n = a; else if (n > z) n = z; return (n); } inline i32 -clamp_i32(i32 a, i32 n, i32 z){ +clamp(i32 a, i32 n, i32 z){ if (n < a) n = a; else if (n > z) n = z; return (n); } inline u32 -clamp_u32(u32 a, u32 n, u32 z){ - if (n < a) n = a; - else if (n > z) n = z; - return (n); -} - -inline umem -clamp_umem(umem a, umem n, umem z){ +clamp(u32 a, u32 n, u32 z){ if (n < a) n = a; else if (n > z) n = z; return (n); diff --git a/4ed_system.h b/4ed_system.h index e2f12321..6481c9b6 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -12,7 +12,7 @@ #if !defined(FCODER_SYSTEM_INTERFACE_H) #define FCODER_SYSTEM_INTERFACE_H -#include "font/4coder_font_interface.h" +#include "4ed_font_interface.h" // types struct Plat_Handle{ @@ -47,7 +47,7 @@ typedef Sys_Load_File_Sig(System_Load_File); #define Sys_Load_Close_Sig(name) b32 name(Plat_Handle handle) typedef Sys_Load_Close_Sig(System_Load_Close); -#define Sys_Save_File_Sig(name) b32 name(char *filename, char *buffer, umem size) +#define Sys_Save_File_Sig(name) b32 name(char *filename, char *buffer, u32 size) typedef Sys_Save_File_Sig(System_Save_File); // file changes @@ -169,7 +169,8 @@ struct Full_Job_Data{ struct Unbounded_Work_Queue{ Full_Job_Data *jobs; - u32 count, max, skip; + i32 count, max, skip; + u32 next_job_id; }; diff --git a/4ed_system_shared.cpp b/4ed_system_shared.cpp index e3fd92c3..1818a941 100644 --- a/4ed_system_shared.cpp +++ b/4ed_system_shared.cpp @@ -12,8 +12,6 @@ #if !defined(FCODER_SYSTEM_SHARED_CPP) #define FCODER_SYSTEM_SHARED_CPP -#include "font/4coder_font_data.h" - // // Standard implementation of file system stuff based on the file track layer. // @@ -21,14 +19,14 @@ internal void init_shared_vars(){ umem scratch_size = KB(128); - void *scratch_memory = system_get_memory(scratch_size); - shared_vars.scratch = make_part(scratch_memory, scratch_size); + void *scratch_memory = system_memory_allocate(scratch_size); + shared_vars.scratch = make_part(scratch_memory, (i32)scratch_size); shared_vars.track_table_size = KB(16); - shared_vars.track_table = system_get_memory(shared_vars.track_table_size); + shared_vars.track_table = system_memory_allocate(shared_vars.track_table_size); shared_vars.track_node_size = KB(16); - void *track_nodes = system_get_memory(shared_vars.track_node_size); + void *track_nodes = system_memory_allocate(shared_vars.track_node_size); i32 track_result = init_track_system(&shared_vars.track, &shared_vars.scratch, shared_vars.track_table, shared_vars.track_table_size, track_nodes, shared_vars.track_node_size); @@ -45,9 +43,9 @@ handle_track_out_of_memory(i32 val){ case FileTrack_OutOfTableMemory: { u32 new_table_size = shared_vars.track_table_size*2; - void *new_table = system_get_memory(new_table_size); + void *new_table = system_memory_allocate(new_table_size); move_track_system(&shared_vars.track, &shared_vars.scratch, new_table, new_table_size); - system_free_memory(shared_vars.track_table); + system_memory_free(shared_vars.track_table, shared_vars.track_table_size); shared_vars.track_table_size = new_table_size; shared_vars.track_table = new_table; }break; @@ -55,7 +53,7 @@ handle_track_out_of_memory(i32 val){ case FileTrack_OutOfListenerMemory: { shared_vars.track_node_size *= 2; - void *node_expansion = system_get_memory(shared_vars.track_node_size); + void *node_expansion = system_memory_allocate(shared_vars.track_node_size); expand_track_system_listeners(&shared_vars.track, &shared_vars.scratch, node_expansion, shared_vars.track_node_size); }break; @@ -67,13 +65,13 @@ handle_track_out_of_memory(i32 val){ internal Sys_Add_Listener_Sig(system_add_listener){ - b32 result = 0; + b32 result = false; for (;;){ - i32 track_result = add_listener(&shared_vars.track, &shared_vars.scratch, filename); + i32 track_result = add_listener(&shared_vars.track, &shared_vars.scratch, (u8*)filename); if (handle_track_out_of_memory(track_result)){ if (track_result == FileTrack_Good){ - result = 1; + result = true; } break; } @@ -84,10 +82,10 @@ Sys_Add_Listener_Sig(system_add_listener){ internal Sys_Remove_Listener_Sig(system_remove_listener){ - i32 result = 0; - i32 track_result = remove_listener(&shared_vars.track, &shared_vars.scratch, filename); + b32 result = false; + i32 track_result = remove_listener(&shared_vars.track, &shared_vars.scratch, (u8*)filename); if (track_result == FileTrack_Good){ - result = 1; + result = true; } return(result); } @@ -97,7 +95,7 @@ Sys_Get_File_Change_Sig(system_get_file_change){ b32 result = false; i32 size = 0; - i32 get_result = get_change_event(&shared_vars.track, &shared_vars.scratch, buffer, max, &size); + i32 get_result = get_change_event(&shared_vars.track, &shared_vars.scratch, (u8*)buffer, max, &size); *required_size = size; *mem_too_small = false; @@ -127,14 +125,14 @@ sysshared_load_file(char *filename){ result.got_file = 1; if (size > 0){ result.size = size; - result.data = (char*)system_get_memory(size+1); + result.data = (char*)system_memory_allocate(size+1); if (!result.data){ result = null_file_data; } else{ if (!system_load_file(handle, result.data, size)){ - system_free_memory(result.data); + system_memory_free(result.data, size+1); result = null_file_data; } } @@ -148,21 +146,19 @@ sysshared_load_file(char *filename){ internal b32 usable_ascii(char c){ - b32 result = 1; + b32 result = true; if ((c < ' ' || c > '~') && c != '\n' && c != '\r' && c != '\t'){ - result = 0; + result = false; } return(result); } internal void sysshared_filter_real_files(char **files, i32 *file_count){ - i32 i, j; - i32 end; - - end = *file_count; - for (i = 0, j = 0; i < end; ++i){ - if (system_file_can_be_made(files[i])){ + i32 end = *file_count; + i32 i = 0, j = 0; + for (; i < end; ++i){ + if (system_file_can_be_made((u8*)files[i])){ files[j] = files[i]; ++j; } @@ -172,7 +168,7 @@ sysshared_filter_real_files(char **files, i32 *file_count){ internal Partition sysshared_scratch_partition(i32 size){ - void *data = system_get_memory(size); + void *data = system_memory_allocate((umem)size); Partition part = make_part(data, size); return(part); } @@ -182,10 +178,11 @@ sysshared_partition_grow(Partition *part, i32 new_size){ void *data = 0; if (new_size > part->max){ // TODO(allen): attempt to grow in place by just acquiring next vpages?! - data = system_get_memory(new_size); + data = system_memory_allocate((umem)new_size); memcpy(data, part->base, part->pos); - system_free_memory(part->base); + system_memory_free(part->base, part->max); part->base = (char*)data; + part->max = new_size; } } @@ -706,6 +703,14 @@ font_load(System_Functions *system, Partition *part, Render_Font *font, i32 pt_s FT_Request_Size(face, &size); // set size & metrics + char *name = face->family_name; + u32 name_len = 0; + for (;name[name_len];++name_len); + name_len = clamp_top(name_len, sizeof(font->name)-1); + memcpy(font->name, name, name_len); + font->name[name_len] = 0; + font->name_len = name_len; + font->ascent = ceil32 (face->size->metrics.ascender / 64.0f); font->descent = floor32 (face->size->metrics.descender / 64.0f); font->advance = ceil32 (face->size->metrics.max_advance / 64.0f); @@ -765,28 +770,30 @@ system_set_page(System_Functions *system, Partition *part, Render_Font *font, Gl } internal void -system_set_font(System_Functions *system, Partition *part, Render_Font *font, String filename, String name, u32 pt_size, b32 use_hinting){ +system_set_font(System_Functions *system, Partition *part, Render_Font *font, char *filename, u32 pt_size, b32 use_hinting){ memset(font, 0, sizeof(*font)); - copy_partial_cs(font->filename, sizeof(font->filename)-1, filename); - font->filename_len = filename.size; - font->filename[font->filename_len] = 0; - copy_partial_cs(font->name, sizeof(font->name)-1, name); - font->name_len = name.size; - font->name[font->name_len] = 0; + u32 filename_len = 0; + for (;filename[filename_len];++filename_len); - if (part->base == 0){ - *part = sysshared_scratch_partition(MB(8)); - } - - b32 success = false; - for (u32 R = 0; R < 3; ++R){ - success = font_load(system, part, font, pt_size, use_hinting); - if (success){ - break; + if (filename_len <= sizeof(font->filename)-1){ + memcpy(font->filename, filename, filename_len); + font->filename[filename_len] = 0; + font->filename_len = filename_len; + + if (part->base == 0){ + *part = sysshared_scratch_partition(MB(8)); } - else{ - sysshared_partition_double(part); + + b32 success = false; + for (u32 R = 0; R < 3; ++R){ + success = font_load(system, part, font, pt_size, use_hinting); + if (success){ + break; + } + else{ + sysshared_partition_double(part); + } } } } diff --git a/4ed_system_shared.h b/4ed_system_shared.h index 404493b0..cb7edab5 100644 --- a/4ed_system_shared.h +++ b/4ed_system_shared.h @@ -9,7 +9,10 @@ // TOP -// TODO(allen): Find a new name/classification for this. +// NOTE(allen): This serves as a list of functions to implement +// in addition to those in 4ed_system.h These are not exposed to +// the application code, but system_shared.cpp +// rely on the functions listed here. #if !defined(FRED_SYSTEM_SHARED_H) #define FRED_SYSTEM_SHARED_H @@ -21,13 +24,11 @@ struct File_Data{ }; global File_Data null_file_data = {0}; -#define Sys_File_Can_Be_Made_Sig(name) b32 name(char *filename) -internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made); - +#define Sys_File_Can_Be_Made_Sig(name) b32 name(u8 *filename) #define Sys_Get_Binary_Path_Sig(name) i32 name(String *out) -internal Sys_Get_Binary_Path_Sig(system_get_binary_path); -///////////////////////////////////// +internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made); +internal Sys_Get_Binary_Path_Sig(system_get_binary_path); struct Shared_Vars{ File_Track_System track; diff --git a/4ed_translation.cpp b/4ed_translation.cpp index e5318d80..11aa4251 100644 --- a/4ed_translation.cpp +++ b/4ed_translation.cpp @@ -13,7 +13,7 @@ struct Translation_State{ u8 fill_buffer[4]; - umem fill_start_i; + u32 fill_start_i; u8 fill_i; u8 fill_expected; }; @@ -44,16 +44,17 @@ struct Translation_Emits{ u32 step_count; }; -#define SINGLE_BYTE_ERROR_CLASS max_u8 +#define ERROR_BYTE (max_u8-1) +#define CONTINUATION_BYTE max_u8 internal void -translating_consume_byte(Translation_State *tran, u8 ch, umem i, umem size, Translation_Byte_Description *desc_out){ +translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Byte_Description *desc_out){ desc_out->byte_class = 0; - if ((ch >= ' ' && ch < 0x7F) || ch == '\t' || ch == '\n' || ch == '\r'){ + if (ch < 0x80){ desc_out->byte_class = 1; } else if (ch < 0xC0){ - desc_out->byte_class = SINGLE_BYTE_ERROR_CLASS; + desc_out->byte_class = CONTINUATION_BYTE; } else if (ch < 0xE0){ desc_out->byte_class = 2; @@ -61,9 +62,12 @@ translating_consume_byte(Translation_State *tran, u8 ch, umem i, umem size, Tran else if (ch < 0xF0){ desc_out->byte_class = 3; } - else{ + else if (ch < 0xF8){ desc_out->byte_class = 4; } + else{ + desc_out->byte_class = ERROR_BYTE; + } desc_out->prelim_emit_type = BufferModelUnit_None; desc_out->last_byte_handler = TranLBH_None; @@ -75,7 +79,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, umem i, umem size, Tran if (desc_out->byte_class == 1){ desc_out->prelim_emit_type = BufferModelUnit_Codepoint; } - else if (desc_out->byte_class == 0 || desc_out->byte_class == SINGLE_BYTE_ERROR_CLASS){ + else if (desc_out->byte_class == 0 || desc_out->byte_class == CONTINUATION_BYTE || desc_out->byte_class == ERROR_BYTE){ desc_out->prelim_emit_type = BufferModelUnit_Numbers; } else{ @@ -83,7 +87,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, umem i, umem size, Tran } } else{ - if (desc_out->byte_class == SINGLE_BYTE_ERROR_CLASS){ + if (desc_out->byte_class == CONTINUATION_BYTE){ tran->fill_buffer[tran->fill_i] = ch; ++tran->fill_i; @@ -138,15 +142,25 @@ translating_select_emit_rule_with_font(System_Functions *system, Render_Font *fo type_out->codepoint_length = 0; if (desc.prelim_emit_type == BufferModelUnit_Codepoint){ u32 cp = utf8_to_u32_length_unchecked(tran->fill_buffer, &type_out->codepoint_length); - type_out->codepoint = cp; - if (!font_can_render(system, font, cp)){ + if (type_out->codepoint_length != 0){ + if ((cp >= nonchar_min && cp <= nonchar_max) || ((cp & 0xFFFF) >= 0xFFFE)){ + type_out->emit_type = BufferModelUnit_Numbers; + } + else{ + type_out->codepoint = cp; + if (!font_can_render(system, font, cp)){ + type_out->emit_type = BufferModelUnit_Numbers; + } + } + } + else{ type_out->emit_type = BufferModelUnit_Numbers; } } } internal void -translating_generate_emits(Translation_State *tran, Translation_Emit_Rule emit_rule, u8 ch, umem i, Translation_Emits *emits_out){ +translating_generate_emits(Translation_State *tran, Translation_Emit_Rule emit_rule, u8 ch, u32 i, Translation_Emits *emits_out){ emits_out->step_count = 0; switch (emit_rule.emit_type){ default: goto skip_all; @@ -199,7 +213,7 @@ translating_generate_emits(Translation_State *tran, Translation_Emit_Rule emit_r } internal void -translating_fully_process_byte(System_Functions *system, Render_Font *font, Translation_State *tran, u8 ch, umem i, umem size, Translation_Emits *emits_out){ +translating_fully_process_byte(System_Functions *system, Render_Font *font, Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Emits *emits_out){ Translation_Byte_Description description = {0}; translating_consume_byte(tran, ch, i, size, &description); Translation_Emit_Rule emit_rule = {0}; diff --git a/4ed_undo.cpp b/4ed_undo.cpp index 98d32c05..f0e416b1 100644 --- a/4ed_undo.cpp +++ b/4ed_undo.cpp @@ -26,33 +26,33 @@ struct Edit_Step{ struct{ b32 can_merge; Buffer_Edit edit; - u32 next_block; - u32 prev_block; + i32 next_block; + i32 prev_block; }; struct{ - u32 first_child; - u32 inverse_first_child; - u32 inverse_child_count; - u32 special_type; + i32 first_child; + i32 inverse_first_child; + i32 inverse_child_count; + i32 special_type; }; }; - u32 child_count; + i32 child_count; }; struct Edit_Stack{ u8 *strings; - u32 size, max; + i32 size, max; Edit_Step *edits; - u32 edit_count, edit_max; + i32 edit_count, edit_max; }; struct Small_Edit_Stack{ u8 *strings; - u32 size, max; + i32 size, max; Buffer_Edit *edits; - u32 edit_count, edit_max; + i32 edit_count, edit_max; }; struct Undo_Data{ @@ -61,9 +61,8 @@ struct Undo_Data{ Edit_Stack history; Small_Edit_Stack children; - u32 history_block_count; - u32 history_head_block; - u32 edit_history_cursor; + i32 history_block_count, history_head_block; + i32 edit_history_cursor; b32 current_block_normal; }; diff --git a/4ed_working_set.cpp b/4ed_working_set.cpp index 55dca405..4150c39f 100644 --- a/4ed_working_set.cpp +++ b/4ed_working_set.cpp @@ -204,7 +204,7 @@ working_set_init(Working_Set *working_set, Partition *partition, General_Memory { i32 item_size = sizeof(File_Name_Entry); i32 table_size = working_set->file_max; - umem mem_size = table_required_mem_size(table_size, item_size); + i32 mem_size = table_required_mem_size(table_size, item_size); void *mem = general_memory_allocate(general, mem_size); memset(mem, 0, mem_size); table_init_memory(&working_set->canon_table, mem, table_size, item_size); @@ -212,9 +212,9 @@ working_set_init(Working_Set *working_set, Partition *partition, General_Memory // NOTE(allen): init name table { - u32 item_size = sizeof(File_Name_Entry); - u32 table_size = working_set->file_max; - umem mem_size = table_required_mem_size(table_size, item_size); + i32 item_size = sizeof(File_Name_Entry); + i32 table_size = working_set->file_max; + i32 mem_size = table_required_mem_size(table_size, item_size); void *mem = general_memory_allocate(general, mem_size); memset(mem, 0, mem_size); table_init_memory(&working_set->name_table, mem, table_size, item_size); @@ -225,8 +225,8 @@ inline void working_set__grow_if_needed(Table *table, General_Memory *general, void *arg, Hash_Function *hash_func, Compare_Function *comp_func){ if (table_at_capacity(table)){ Table btable = {0}; - u32 new_max = table->max * 2; - umem mem_size = table_required_mem_size(new_max, table->item_size); + i32 new_max = table->max * 2; + i32 mem_size = table_required_mem_size(new_max, table->item_size); void *mem = general_memory_allocate(general, mem_size); table_init_memory(&btable, mem, new_max, table->item_size); table_clear(&btable); diff --git a/4tech_defines.h b/4tech_defines.h index f11c18a2..2365626c 100644 --- a/4tech_defines.h +++ b/4tech_defines.h @@ -8,6 +8,7 @@ Created 21.01.2017 (dd.mm.yyyy) #if !defined(FTECH_DEFINES) #define FTECH_DEFINES + #include typedef int8_t i8; @@ -23,7 +24,6 @@ typedef uint64_t u64; typedef i8 b8; typedef i32 b32; -// TODO(allen): Find a real way to detect 32 bit ness. #if defined(FTECH_32_BIT) typedef u32 umem; typedef i32 imem; @@ -87,10 +87,6 @@ inline u32 l_round_up_u32(u32 x, u32 b){ return( ((x)+(b)-1) - (((x)+(b)-1)%(b)) ); } -inline umem l_round_up_umem(umem x, umem b){ - return( ((x)+(b)-1) - (((x)+(b)-1)%(b)) ); -} - inline u32 round_up_pot_u32(u32 x){ --x; x |= x >> 1; @@ -135,18 +131,6 @@ inline u32 round_up_pot_u32(u32 x){ #define min_u32 ((u32)0) #define min_u64 ((u64)0) -#if defined(FTECH_32_BIT) -#define max_imem max_i64 -#define min_imem min_i64 -#define max_umem max_u64 -#define min_umem min_u64 -#else -#define max_imem max_i32 -#define min_imem min_i32 -#define max_umem max_u32 -#define min_umem min_u32 -#endif - #define Bit_0 (1 << 0) #define Bit_1 (1 << 1) #define Bit_2 (1 << 2) diff --git a/font/4coder_font_internal.cpp b/font/4coder_font_internal.cpp deleted file mode 100644 index a8e66e65..00000000 --- a/font/4coder_font_internal.cpp +++ /dev/null @@ -1,493 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 10.03.2017 - * - * Where I save crappy old font stuff. - * - */ - -// TOP - -#include "font/4coder_font_data.h" - -struct Font_Table_Entry{ - u32 hash; - String name; - Font_ID font_id; -}; - -struct Font_Info{ - Render_Font *font; - String filename; - String name; - i32 pt_size; -}; - -struct Font_Slot{ - Font_Slot *next, *prev; - Font_ID font_id; - u8 padding[6]; -}; -global_const Font_Slot null_font_slot = {0}; - -#define Font_Load_Sig(name)\ -i32 name(Render_Font *font_out, char *filename, char *fontname, i32 pt_size, i32 tab_width, b32 store_texture) -typedef Font_Load_Sig(Font_Load); - -#define Font_Load_Page_Sig(name)\ -i32 name(Render_Font *font, Glyph_Page *page, char *filename, i32 pt_size, i32 tab_width) -typedef Font_Load_Page_Sig(Font_Load_Page); - -#define Release_Font_Sig(name) void name(Render_Font *font) -typedef Release_Font_Sig(Release_Font); - -struct Font_Set{ - Font_Info *info; - Font_Table_Entry *entries; - u32 count, max; - - void *font_block; - Font_Slot free_slots; - Font_Slot used_slots; - - Font_Load *font_load; - Font_Load_Page *font_load_page; - Release_Font *release_font; - - b8 *font_used_flags; - Font_ID used_this_frame; - Font_ID live_max; -}; - -inline Font_Info* -get_font_info(Font_Set *set, Font_ID font_id){ - Font_Info *result = set->info + font_id - 1; - return(result); -} - -internal void -font_set_begin_render(Font_Set *font_set){ - font_set->used_this_frame = 0; - memset(font_set->font_used_flags, 0, font_set->max); -} - -inline u32 -font_hash(String name){ - u32 x = 5381; - char *p = name.str; - for (i32 i = 0; i < name.size; ++i, ++p){ - x = ((x << 5) + x) ^ (*p); - } - return(x); -} - -inline void -font__insert(Font_Slot *pos, Font_Slot *slot){ - Font_Slot *nex; - nex = pos->next; - - slot->next = nex; - slot->prev = pos; - nex->prev = slot; - pos->next = slot; -} - -inline void -font__remove(Font_Slot *slot){ - Font_Slot *n, *p; - n = slot->next; - p = slot->prev; - - p->next = n; - n->prev = p; -} - -internal void -font_set_init(Font_Set *set, Partition *partition, i32 max, Font_ID live_max){ - partition_align(partition, 8); - set->info = push_array(partition, Font_Info, max); - partition_align(partition, 8); - set->entries = push_array(partition, Font_Table_Entry, max); - set->count = 0; - set->max = max; - - partition_align(partition, 8); - set->font_block = push_block(partition, live_max*(sizeof(Render_Font) + sizeof(Font_Slot))); - - set->free_slots = null_font_slot; - set->used_slots = null_font_slot; - - dll_init_sentinel(&set->free_slots); - dll_init_sentinel(&set->used_slots); - - char *ptr = (char*)set->font_block; - for (i32 i = 0; i < live_max; ++i){ - dll_insert(&set->free_slots, (Font_Slot*)ptr); - ptr += sizeof(Font_Slot) + sizeof(Render_Font); - } - - set->font_used_flags = push_array(partition, b8, max); - set->live_max = live_max; -} - -internal b32 -font_set_can_add(Font_Set *set){ - b32 result = 0; - if (set->count*8 < set->max*7) result = 1; - return(result); -} - -internal void -font_set_add_hash(Font_Set *set, String name, Font_ID font_id){ - Font_Table_Entry entry; - entry.hash = font_hash(name); - entry.name = name; - entry.font_id = font_id; - - u32 i = entry.hash % set->max; - u32 j = i - 1; - if (i <= 1) j += set->max; - - for (; i != j; ++i){ - if (i == set->max) i = 0; - if (set->entries[i].font_id == 0){ - set->entries[i] = entry; - break; - } - } - - Assert(i != j); -} - -inline b32 -font_set_can_load(Font_Set *set){ - b32 result = (set->free_slots.next != &set->free_slots); - return(result); -} - -internal void -font_set_load(Font_Set *set, Font_ID font_id){ - Font_Info *info = get_font_info(set, font_id); - Font_Slot *slot = set->free_slots.next; - Assert(slot != &set->free_slots); - font__remove(slot); - font__insert(&set->used_slots, slot); - - Render_Font *font = (Render_Font*)(slot + 1); - set->font_load(font, info->filename.str, info->name.str, info->pt_size, 4, true); - info->font = font; - slot->font_id = font_id; -} - -internal void -font_set_evict_lru(Font_Set *set){ - Font_Slot *slot = set->used_slots.prev; - Assert(slot != &set->used_slots); - - Font_ID font_id = slot->font_id; - Font_Info *info = get_font_info(set, font_id); - Assert(((Font_Slot*)info->font) - 1 == slot); - - set->release_font(info->font); - - info->font = 0; - slot->font_id = 0; - font__remove(slot); - font__insert(&set->free_slots, slot); -} - -internal void -font_set_use(Font_Set *set, Font_ID font_id){ - b8 already_used = set->font_used_flags[font_id-1]; - - if (!already_used){ - if (set->used_this_frame < set->live_max){ - ++set->used_this_frame; - set->font_used_flags[font_id-1] = 1; - already_used = 1; - } - } - - if (already_used){ - // TODO(allen): optimize if you don't mind!!!! - Font_Info *info = get_font_info(set, font_id); - Font_Slot *slot; - if (info->font == 0){ - if (!font_set_can_load(set)){ - font_set_evict_lru(set); - } - font_set_load(set, font_id); - } - slot = ((Font_Slot*)info->font) - 1; - - font__remove(slot); - font__insert(&set->used_slots, slot); - } -} - -internal b32 -font_set_add(Font_Set *set, String filename, String name, i32 pt_size){ - b32 result = false; - if (font_set_can_add(set)){ - Render_Font dummy_font = {0}; - Font_ID font_id = (i16)(++set->count); - Font_Info *info = get_font_info(set, font_id); - info->filename = filename; - info->name = name; - info->pt_size = pt_size; - set->font_load(&dummy_font, info->filename.str, info->name.str, info->pt_size, 4, false); - - font_set_add_hash(set, name, font_id); - - if (font_set_can_load(set)){ - font_set_load(set, font_id); - } - - result = true; - } - return(result); -} - -internal b32 -font_set_find_pos(Font_Set *set, String name, u32 *position){ - u32 hash = font_hash(name); - u32 i = hash % set->max; - u32 j = i - 1; - if (j <= 1){ - j += set->max; - } - - b32 result = 0; - for (; i != j; ++i){ - if (i == set->max){ - i = 0; - } - - Font_Table_Entry *entry = set->entries + i; - if (entry->hash == hash){ - if (match_ss(name, entry->name)){ - result = 1; - *position = i; - break; - } - } - } - - return(result); -} - -internal b32 -font_set_get_name(Font_Set *set, Font_ID font_id, String *name){ - Font_Info *info = get_font_info(set, font_id); - b32 result = copy_checked_ss(name, info->name); - return(result); -} - -internal b32 -font_set_extract(Font_Set *set, String name, Font_ID *font_id){ - u32 position; - b32 result = font_set_find_pos(set, name, &position); - if (result){ - *font_id = set->entries[position].font_id; - } - return(result); -} - -////////////////////////////////// - -internal b32 -get_codepoint_can_render(Render_Font *font, u32 codepoint){ - b32 exists = false; - if (codepoint < 0x10FFFF){ - exists = true; - } - return(exists); -} - -struct Codepoint_Indexes{ - b32 exists; - u32 page_number; - u32 glyph_index; -}; - -internal Codepoint_Indexes -get_codepoint_page_number(Render_Font *font, u32 codepoint){ - Codepoint_Indexes result = {0}; - u32 page_number = (codepoint >> 8); - if (page_number <= 0x10FF){ - result.exists = true; - result.page_number = page_number; - result.glyph_index = (codepoint & 0x000000FF); - } - return(result); -} - -#define MAX_PAGE_COUNT (u32)(0x1100) -#define GLYPH_PAGE_EMPTY ((Glyph_Page*)(0)) -#define GLYPH_PAGE_DELETED ((Glyph_Page*)(max_u64)) -#define IS_REAL_FONT_PAGE(p) (((p) != GLYPH_PAGE_EMPTY) && ((p) != GLYPH_PAGE_DELETED)) - -internal Glyph_Page** -font_lookup_page(Render_Font *font, u32 page_number, b32 find_empty_slot){ - Glyph_Page **result = 0; - if (font->page_max > 0){ - u32 first_index = page_number % font->page_max; - - u32 range_count = 0; - u32 ranges[4]; - if (first_index == 0){ - ranges[0] = 0; - ranges[1] = font->page_max; - range_count = 2; - } - else{ - ranges[0] = first_index; - ranges[1] = font->page_max; - ranges[2] = 0; - ranges[3] = first_index; - range_count = 4; - } - - if (find_empty_slot){ - for(u32 j = 0; j < range_count; j += 2){ - u32 start = ranges[j]; - u32 stop = ranges[j+1]; - for (u32 i = start; i < stop; ++i){ - Glyph_Page *ptr = font->pages[i]; - if (ptr == GLYPH_PAGE_EMPTY || ptr == GLYPH_PAGE_DELETED){ - result = &font->pages[i]; - goto break2; - } - if (ptr->page_number == page_number){ - goto break2; - } - } - } - } - else{ - for(u32 j = 0; j < range_count; j += 2){ - u32 start = ranges[j]; - u32 stop = ranges[j+1]; - for (u32 i = start; i < stop; ++i){ - Glyph_Page *ptr = font->pages[i]; - if (ptr == GLYPH_PAGE_EMPTY){ - goto break2; - } - if (ptr != GLYPH_PAGE_DELETED){ - if (ptr->page_number == page_number){ - result = &font->pages[i]; - goto break2; - } - } - } - } - } - break2:; - } - return(result); -} - -internal Glyph_Page* -font_get_or_make_page(Render_Font *font, u32 page_number){ - Glyph_Page *page = 0; - if (page_number <= 0x10FF){ - Glyph_Page **page_ptr = font_lookup_page(font, page_number, false); - page = 0; - if (page_ptr != 0){ - page = *page_ptr; - } - - if (page == 0){ - u32 new_count = 1; - if (font->page_max < MAX_PAGE_COUNT && (font->page_count+new_count)*3 < font->page_max*2){ - u32 new_page_max = (font->page_count+new_count)*3; - new_page_max = clamp_top(new_page_max, MAX_PAGE_COUNT); - Glyph_Page **new_pages = (Glyph_Page**)ALLOCATE(new_page_max * sizeof(Glyph_Page*)); - - u32 old_page_max = font->page_max; - Glyph_Page **pages = font->pages; - for (u32 i = 0; i < old_page_max; ++i){ - Glyph_Page *current_page = pages[i]; - if (current_page != GLYPH_PAGE_EMPTY && current_page != GLYPH_PAGE_DELETED){ - Glyph_Page **dest = font_lookup_page(font, current_page->page_number, true); - Assert(dest != 0); - *dest = current_page; - } - } - - FREE(font->pages); - font->pages = new_pages; - font->page_max = new_page_max; - } - - Glyph_Page *new_page = (Glyph_Page*)ALLOCATE(sizeof(Glyph_Page)); - Glyph_Page **dest = font_lookup_page(font, page_number, true); - *dest = new_page; - ++font->page_count; - - //set->font_load_page(font, new_page, ); - } - } - return(page); -} - -internal void -get_codepoint_memory(Render_Font *font, u32 codepoint, Glyph_Bounds **bounds_mem_out, f32 **advance_mem_out){ - Glyph_Bounds *bounds = 0; - f32 *advance = 0; - - if (get_codepoint_can_render(font, codepoint)){ - Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); - Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); - bounds = &page->glyphs[indexes.glyph_index]; - advance = &page->advance[indexes.glyph_index]; - } - - *bounds_mem_out = bounds; - *advance_mem_out = advance; -} - -internal b32 -get_codepoint_glyph_data(Render_Font *font, u32 codepoint, Glyph_Data *data_out){ - b32 success = false; - if (get_codepoint_can_render(font, codepoint)){ - Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); - Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); - data_out->bounds = page->glyphs[indexes.glyph_index]; - data_out->tex = page->tex; - data_out->tex_width = page->tex_width; - data_out->tex_height = page->tex_height; - success = true; - } - return(success); -} - -internal f32 -get_codepoint_advance(Render_Font *font, u32 codepoint){ - f32 advance = (f32)font->advance; - if (get_codepoint_can_render(font, codepoint)){ - Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); - Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); - advance = page->advance[indexes.glyph_index]; - } - return(advance); -} - -internal b32 -set_codepoint_advance(Render_Font *font, u32 codepoint, f32 value){ - b32 success = false; - if (get_codepoint_can_render(font, codepoint)){ - Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); - Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); - page->advance[indexes.glyph_index] = value; - success = true; - } - return(success); -} - -// BOTTOM - - - - diff --git a/internal_4coder_tests.cpp b/internal_4coder_tests.cpp deleted file mode 100644 index fe65facc..00000000 --- a/internal_4coder_tests.cpp +++ /dev/null @@ -1,247 +0,0 @@ -/* - -A series of stress tests to more quickly verify that 4coder isn't totally -broken before I release in the future... "unit tests" perhaps, although -I guess I don't know what the "units" are... probably just "tests". - -Allen Webster -18.07.2016 - -*/ - -// TOP - -#define LOTS_OF_FILES "w:/4ed/data/lots_of_files" -#define TEST_FILES "w:/4ed/data/test" - -#include "4coder_default_include.cpp" - -#if 0 -#include -#include - -#include -#pragma intrinsic(__rdtsc) - -typedef uint64_t DWORD64; - -#define TEST_TIME_B(m) DWORD64 time_start = __rdtsc(), time_max = m; (void)(time_start), (void)(time_max) -#define TEST_TIME_E() DWORD64 time_total = __rdtsc() - time_start; if (time_total > time_max) {assert(!"failed timing");} -#define TEST_TIME_M(m) m = (float)(__rdtsc() - time_start) / time_max - -// NOTE(allen): This testing system only verifies that everything works -// without crashing and without blowing through a fair time budget. -// These tests do not verify the correctness of the output. - -CUSTOM_COMMAND_SIG(load_lots_of_files){ - // NOTE(allen): This timing restriction is based on 4GHz and 60fps - // 4G / 60 ~= 70M Reserving most of that time for rendering and hopefully idling - // I set the goal of 10M for all tests. - TEST_TIME_B(10000000); - - File_List list = get_file_list(app, literal(LOTS_OF_FILES)); - File_Info *info = list.infos; - - char space[1024]; - String str = make_fixed_width_string(space); - append_ss(&str, make_lit_string(LOTS_OF_FILES)); - append_s_char(&str, '/'); - int32_t size = str.size; - - for (int32_t i = 0; i < list.count; ++i, ++info){ - if (!info->folder){ - append_ss(&str, make_string(info->filename, info->filename_len)); - Buffer_Summary buffer = create_buffer(app, str.str, str.size, - BufferCreate_Background); - assert(buffer.size != 0); - str.size = size; - } - } - - free_file_list(app, list); - - // TODO(allen): Pass this time test! - //TEST_TIME_E(); -} - -CUSTOM_COMMAND_SIG(reopen_test){ - // NOTE(allen): This is set to roughly one percent of the frame budget - // based on 4GHz and 60fps - TEST_TIME_B(700000); - - Buffer_Summary buffer = create_buffer(app, literal(TEST_FILES "/basic.cpp"), 0); - View_Summary view = get_active_view(app, AccessAll); - view_set_buffer(app, &view, buffer.buffer_id, 0); - - exec_command(app, cmdid_reopen); - - // TODO(allen): Pass this time test! - //TEST_TIME_E(); -} - -CUSTOM_COMMAND_SIG(generate_stop_spots_test_data){ - Buffer_Summary buffer = create_buffer(app, literal(LOTS_OF_FILES "/4ed.cpp"), 0); - View_Summary view = get_active_view(app, AccessAll); - view_set_buffer(app, &view, buffer.buffer_id, 0); - - FILE *file = fopen(TEST_FILES "/stop_spots_data", "wb"); - - if (file){ - Partial_Cursor curs; - int32_t pos; - - buffer_compute_cursor(app, &buffer, seek_line_char(316, 29), &curs); - fwrite(&curs.pos, 4, 1, file); - - for (int32_t i = 0; i < 10; ++i){ - Query_Bar bar = {0}; - bar.prompt = make_lit_string("Do something to continue the test"); - if (start_query_bar(app, &bar, 0)){ - get_user_input(app, EventAll, EventAll); - } - refresh_buffer(app, &buffer); - if (buffer.tokens_are_ready){ - break; - } - } - - static Seek_Boundary_Flag flag_set[] = { - BoundaryWhitespace, - BoundaryToken, - BoundaryAlphanumeric, - BoundaryCamelCase, - BoundaryWhitespace | BoundaryToken, - BoundaryWhitespace | BoundaryAlphanumeric, - BoundaryToken | BoundaryCamelCase, - }; - - for (int32_t flag_i = 0; flag_i < ArrayCount(flag_set); ++flag_i){ - for (int32_t seek_forward = 0; seek_forward <= 1; ++seek_forward){ - pos = curs.pos; - for (int32_t i = 0; i < 100; ++i){ - pos = buffer_boundary_seek(app, &buffer, pos, seek_forward, flag_set[flag_i]); - fwrite(&pos, 4, 1, file); - } - } - } - - fclose(file); - } -} - -static void -fcheck(int32_t x, FILE *file){ - int32_t x0 = 0; - fread(&x0, 4, 1, file); - Assert(x == x0); -} - -CUSTOM_COMMAND_SIG(stop_spots_test){ - Buffer_Summary buffer = create_buffer(app, literal(LOTS_OF_FILES "/4ed.cpp"), 0); - View_Summary view = get_active_view(app, AccessAll); - view_set_buffer(app, &view, buffer.buffer_id, 0); - - FILE *file = fopen(TEST_FILES "/stop_spots_data", "rb"); - - if (file){ - Partial_Cursor curs; - int32_t pos; - - buffer_compute_cursor(app, &buffer, seek_line_char(316, 29), &curs); - fcheck(curs.pos, file); - - for (int32_t i = 0; i < 10; ++i){ - Query_Bar bar = {0}; - bar.prompt = make_lit_string("Do something to continue the test"); - if (start_query_bar(app, &bar, 0)){ - get_user_input(app, EventAll, EventAll); - } - refresh_buffer(app, &buffer); - if (buffer.tokens_are_ready){ - break; - } - } - - static Seek_Boundary_Flag flag_set[] = { - BoundaryWhitespace, - BoundaryToken, - BoundaryAlphanumeric, - BoundaryCamelCase, - BoundaryWhitespace | BoundaryToken, - BoundaryWhitespace | BoundaryAlphanumeric, - BoundaryToken | BoundaryCamelCase, - }; - - for (int32_t flag_i = 0; flag_i < ArrayCount(flag_set); ++flag_i){ - for (int32_t seek_forward = 0; seek_forward <= 1; ++seek_forward){ - pos = curs.pos; - for (int32_t i = 0; i < 100; ++i){ - pos = buffer_boundary_seek(app, &buffer, pos, seek_forward, flag_set[flag_i]); - fcheck(pos, file); - } - } - } - - fclose(file); - } -} - -CUSTOM_COMMAND_SIG(load_unicode_file){ - Buffer_Summary buffer = create_buffer(app, literal(TEST_FILES "/mod_markov.c"), 0); - View_Summary view = get_active_view(app, AccessAll); - view_set_buffer(app, &view, buffer.buffer_id, 0); - - view_set_cursor(app, &view, seek_line_char(230, 25), 1); -} - -CUSTOM_COMMAND_SIG(edit_giant_file){ - Buffer_Summary buffer = create_buffer(app, literal(TEST_FILES "/test_large.cpp"), 0); - View_Summary view = get_active_view(app, AccessAll); - view_set_buffer(app, &view, buffer.buffer_id, 0); - view_set_cursor(app, &view, seek_line_char(230, 25), 1); - - for (int32_t i = 0; i < 600; ++i){ - Query_Bar bar = {0}; - bar.prompt = make_lit_string("Do something to continue the test"); - if (start_query_bar(app, &bar, 0)){ - get_user_input(app, EventAll, EventAll); - } - end_query_bar(app, &bar, 0); - refresh_buffer(app, &buffer); - if (buffer.tokens_are_ready){ - break; - } - } - - buffer_replace_range(app, &buffer, 2000, 2000, - literal("{\n//Not important at all\n}\n")); - buffer_auto_indent(app, &buffer, 2000, 2100, 4, 0); -} - -CUSTOM_COMMAND_SIG(run_all_tests){ - exec_command(app, load_lots_of_files); - exec_command(app, reopen_test); - exec_command(app, stop_spots_test); - exec_command(app, load_unicode_file); - exec_command(app, edit_giant_file); -} -#endif - -static void -test_get_bindings(Bind_Helper *context){ - -#if 0 - begin_map(context, mapid_global); - bind(context, key_f3, MDFR_NONE, run_all_tests); - end_map(context); -#endif - -} - -#define BIND_4CODER_TESTS(context) test_get_bindings(context) - -#include "power/4coder_experiments.cpp" - - -// BOTTOM - diff --git a/linux_release_compat.c b/linux_release_compat.c index 6722c636..5dafb8f4 100644 --- a/linux_release_compat.c +++ b/linux_release_compat.c @@ -1,10 +1,12 @@ #include -// Link to the memcpy symbol with version 2.2.5 instead of the newer 2.14 one since they are functionaly equivalent, but using the old one allows 4coder to run on older distros without glibc >= 2.14 +// Link to the memcpy symbol with version 2.2.5 instead of the newer 2.14 one +// since they are functionaly equivalent, but using the old one allows 4coder +// to run on older distros without glibc >= 2.14 extern "C" { - asm (".symver memcpy, memcpy@GLIBC_2.2.5"); - void *__wrap_memcpy(void *dest, const void *src, size_t n){ - return memcpy(dest, src, n); - } +asm (".symver memcpy, memcpy@GLIBC_2.2.5"); +void *__wrap_memcpy(void *dest, const void *src, size_t n){ + return memcpy(dest, src, n); +} } diff --git a/meta/build.cpp b/meta/build.cpp index 5e49fb7a..9a25bc92 100644 --- a/meta/build.cpp +++ b/meta/build.cpp @@ -164,6 +164,10 @@ build_cl(u32 flags, char *code_path, char *code_file, char *out_path, char *out_ build_ap(line, CL_OPTS); } + if (flags & X86){ + build_ap(line, "/DFTECH_32_BIT"); + } + if (flags & INCLUDES){ build_ap(line, CL_INCLUDES); } @@ -433,11 +437,7 @@ do_buildsuper(char *cdir, i32 custom_option, u32 flags){ case Custom_Experiments: { -#if defined(IS_WINDOWS) - copy_sc(&str, "../code/internal_4coder_tests.cpp"); -#else copy_sc(&str, "../code/power/4coder_experiments.cpp"); -#endif }break; case Custom_Casey: diff --git a/meta/meta_parser.cpp b/meta/meta_parser.cpp index 347dc2e9..0c0f618d 100644 --- a/meta/meta_parser.cpp +++ b/meta/meta_parser.cpp @@ -886,7 +886,7 @@ static Argument_Breakdown parameter_parse(Partition *part, char *data, Cpp_Token *args_start_token, Cpp_Token *args_end_token){ int32_t arg_index = 0; Cpp_Token *arg_token = args_start_token + 1; - uint32_t param_string_start = arg_token->start; + int32_t param_string_start = arg_token->start; int32_t arg_count = 1; arg_token = args_start_token; diff --git a/meta/out_context.cpp b/meta/out_context.cpp index 8350c36e..cb72b558 100644 --- a/meta/out_context.cpp +++ b/meta/out_context.cpp @@ -81,7 +81,7 @@ do_file_copy(Partition *part, char *src_file, char *dst_dir, char *dst_file){ terminate_with_null(&str); Temp_Memory temp = begin_temp_memory(part); - size_t mem_size = partition_remaining(part); + int32_t mem_size = partition_remaining(part); void *mem = push_block(part, mem_size); FILE *in = fopen(src_file, "rb"); if (in){ @@ -89,17 +89,17 @@ do_file_copy(Partition *part, char *src_file, char *dst_dir, char *dst_file){ int32_t file_size = ftell(in); if (mem_size >= file_size){ - fseek(in, 0, SEEK_SET); - fread(mem, 1, file_size, in); - - FILE *out = fopen(dst, "wb"); - if (out){ - fwrite(mem, 1, file_size, out); - fclose(out); - success = 1; - } + fseek(in, 0, SEEK_SET); + fread(mem, 1, file_size, in); + + FILE *out = fopen(dst, "wb"); + if (out){ + fwrite(mem, 1, file_size, out); + fclose(out); + success = 1; } - + } + fclose(in); } end_temp_memory(temp); diff --git a/power/4coder_experiments.cpp b/power/4coder_experiments.cpp index a1ea1720..b9c941f9 100644 --- a/power/4coder_experiments.cpp +++ b/power/4coder_experiments.cpp @@ -23,7 +23,7 @@ TYPE: 'build-target' #include static float -get_line_y(Application_Links *app, View_Summary *view, size_t line){ +get_line_y(Application_Links *app, View_Summary *view, int32_t line){ Full_Cursor cursor = {0}; view_compute_cursor(app, view, seek_line_char(line, 1), &cursor); float y = cursor.wrapped_y; @@ -37,30 +37,26 @@ CUSTOM_COMMAND_SIG(kill_rect){ View_Summary view = get_active_view(app, AccessOpen); Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen); - pos_Rect rect = get_line_x_rect(&view); + i32_Rect rect = get_line_x_rect(&view); bool32 unwrapped = view.unwrapped_lines; - int32_t line_count = (int32_t)(rect.y1 - rect.y0 + 1); - for (int32_t line_i = line_count; line_i >= 0; --line_i){ - size_t line = rect.y0 + line_i; - size_t start = 0; - size_t end = 0; + for (int32_t line = rect.y1; line >= rect.y0; --line){ + int32_t start = 0; + int32_t end = 0; - bool32 success = true; + bool32 success = 1; Full_Cursor cursor = {0}; float y = get_line_y(app, &view, line); if (success){ - Buffer_Seek seek = seek_xy((float)rect.x0, y, 0, unwrapped); - success = view_compute_cursor(app, &view, seek, &cursor); + success = view_compute_cursor(app, &view, seek_xy((float)rect.x0, y, 0, unwrapped), &cursor); } start = cursor.pos; if (success){ - Buffer_Seek seek = seek_xy((float)rect.x0, y, 0, unwrapped); - success = view_compute_cursor(app, &view, seek, &cursor); + success = view_compute_cursor(app, &view, seek_xy((float)rect.x1, y, 0, unwrapped), &cursor); } end = cursor.pos; @@ -71,19 +67,16 @@ CUSTOM_COMMAND_SIG(kill_rect){ } static void -pad_buffer_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line, char padchar, size_t target){ +pad_buffer_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line, char padchar, int32_t target){ Partial_Cursor start = {0}; Partial_Cursor end = {0}; - Buffer_Seek seek_start = seek_line_char(line, 1); - Buffer_Seek seek_end = seek_line_reverse_char(line, 1); - - if (buffer_compute_cursor(app, buffer, seek_start, &start)){ - if (start.line == line){ - if (buffer_compute_cursor(app, buffer, seek_end, &end)){ + if (buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &start)){ + 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); - size_t size = target - (end.character-1); + int32_t size = target - (end.character-1); char *str = push_array(part, char, size); memset(str, ' ', size); buffer_replace_range(app, buffer, end.pos, end.pos, str, size); @@ -137,14 +130,14 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ Buffer_Rect rect = get_rect(&view); - size_t start_line = view.cursor.line; - size_t pos = view.cursor.character-1; + int32_t start_line = view.cursor.line; + int32_t pos = view.cursor.character-1; - for (size_t i = rect.line0; i <= rect.line1; ++i){ + for (int32_t i = rect.line0; i <= rect.line1; ++i){ pad_buffer_line(app, &global_part, &buffer, i, ' ', pos); } - int32_t line_count = (int32_t)(rect.line1 - rect.line0 + 1); + int32_t line_count = rect.line1 - rect.line0 + 1; for (;;){ User_Input in = get_user_input(app, EventOnAnyKey, EventOnEsc | EventOnButton); @@ -157,12 +150,10 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ Buffer_Edit *edit = push_array(part, Buffer_Edit, line_count); Buffer_Edit *edits = edit; - for (int32_t i = 0; i <= line_count; ++i){ - size_t line = i + rect.line0; + for (int32_t i = rect.line0; i <= rect.line1; ++i){ Partial_Cursor cursor = {0}; - Buffer_Seek seek = seek_line_char(line, pos+1); - if (buffer_compute_cursor(app, &buffer, seek, &cursor)){ + if (buffer_compute_cursor(app, &buffer, seek_line_char(i, pos+1), &cursor)){ edit->str_start = 0; edit->len = 1; edit->start = cursor.pos; @@ -187,12 +178,10 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ Buffer_Edit *edit = push_array(part, Buffer_Edit, line_count); Buffer_Edit *edits = edit; - for (int32_t i = 0; i <= line_count; ++i){ - size_t line = i + rect.line0; + for (int32_t i = rect.line0; i <= rect.line1; ++i){ Partial_Cursor cursor = {0}; - Buffer_Seek seek = seek_line_char(line, pos+1); - if (buffer_compute_cursor(app, &buffer, seek, &cursor)){ + if (buffer_compute_cursor(app, &buffer, seek_line_char(i, pos+1), &cursor)){ edit->str_start = 0; edit->len = 0; edit->start = cursor.pos-1; @@ -227,11 +216,11 @@ enum{ }; static bool32 -find_scope_top(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ +find_scope_top(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - size_t position = 0; + int32_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index; @@ -287,11 +276,11 @@ find_scope_top(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, } static bool32 -find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ +find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - size_t position = 0; + int32_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index+1; @@ -348,11 +337,11 @@ find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, size_t start_p } static bool32 -find_next_scope(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ +find_next_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - size_t position = 0; + int32_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index+1; @@ -428,11 +417,11 @@ find_next_scope(Application_Links *app, Buffer_Summary *buffer, size_t start_pos } static bool32 -find_prev_scope(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ +find_prev_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - size_t position = 0; + int32_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index-1; @@ -507,7 +496,7 @@ find_prev_scope(Application_Links *app, Buffer_Summary *buffer, size_t start_pos } static void -view_set_to_region(Application_Links *app, View_Summary *view, size_t major_pos, size_t minor_pos, float normalized_threshold){ +view_set_to_region(Application_Links *app, View_Summary *view, int32_t major_pos, int32_t minor_pos, float normalized_threshold){ Range range = make_range(major_pos, minor_pos); bool32 bottom_major = false; if (major_pos == range.max){ @@ -562,8 +551,8 @@ CUSTOM_COMMAND_SIG(highlight_surrounding_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_scope_top(app, &buffer, start_pos, FindScope_Parent, &top)){ view_set_cursor(app, &view, seek_pos(top), true); if (find_scope_bottom(app, &buffer, start_pos, FindScope_Parent | FindScope_EndOfToken, &bottom)){ @@ -582,8 +571,8 @@ CUSTOM_COMMAND_SIG(highlight_first_child_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_next_scope(app, &buffer, start_pos, 0, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -598,8 +587,8 @@ CUSTOM_COMMAND_SIG(highlight_next_sibling_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_next_scope(app, &buffer, start_pos, FindScope_NextSibling, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -614,8 +603,8 @@ CUSTOM_COMMAND_SIG(highlight_prev_sibling_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_prev_scope(app, &buffer, start_pos, FindScope_NextSibling, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -630,8 +619,8 @@ CUSTOM_COMMAND_SIG(highlight_next_scope_absolute){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_next_scope(app, &buffer, start_pos, 0, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -646,8 +635,8 @@ CUSTOM_COMMAND_SIG(highlight_prev_scope_absolute){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_prev_scope(app, &buffer, start_pos, 0, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -671,6 +660,7 @@ CUSTOM_COMMAND_SIG(place_in_scope){ range.max = buffer_get_line_end(app, &buffer, lines.max); bool32 do_full = false; + if (lines.min < lines.max){ do_full = true; } @@ -697,11 +687,11 @@ CUSTOM_COMMAND_SIG(place_in_scope){ --max_adjustment; } - size_t min_pos = range.min + min_adjustment; - size_t max_pos = range.max + max_adjustment; + int32_t min_pos = range.min + min_adjustment; + int32_t max_pos = range.max + max_adjustment; - size_t cursor_pos = min_pos; - size_t mark_pos = max_pos; + int32_t cursor_pos = min_pos; + int32_t mark_pos = max_pos; if (view.cursor.pos > view.mark.pos){ cursor_pos = max_pos; @@ -735,11 +725,13 @@ CUSTOM_COMMAND_SIG(delete_current_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t top = view.cursor.pos; - size_t bottom = view.mark.pos; + int32_t top = view.cursor.pos; + int32_t bottom = view.mark.pos; if (top > bottom){ - Swap(size_t, top, bottom); + int32_t x = top; + top = bottom; + bottom = x; } if (buffer_get_char(app, &buffer, top) == '{' && buffer_get_char(app, &buffer, bottom-1) == '}'){ @@ -948,10 +940,10 @@ parse_statement_down(Application_Links *app, Statement_Parser *parser, Cpp_Token } static bool32 -find_whole_statement_down(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t *start_out, size_t *end_out){ +find_whole_statement_down(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t *start_out, int32_t *end_out){ bool32 result = false; - size_t start = pos; - size_t end = start; + int32_t start = pos; + int32_t end = start; Cpp_Get_Token_Result get_result = {0}; @@ -990,11 +982,13 @@ CUSTOM_COMMAND_SIG(scope_absorb_down){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t top = view.cursor.pos; - size_t bottom = view.mark.pos; + int32_t top = view.cursor.pos; + int32_t bottom = view.mark.pos; if (top > bottom){ - Swap(size_t, top, bottom); + int32_t x = top; + top = bottom; + bottom = x; } Partition *part = &global_part; @@ -1006,8 +1000,7 @@ CUSTOM_COMMAND_SIG(scope_absorb_down){ char *string_space = push_array(part, char, range.end - range.start); buffer_read_range(app, &buffer, range.start, range.end, string_space); - int32_t string_length = (int32_t)(range.end - range.start); - String string = make_string(string_space, string_length); + String string = make_string(string_space, range.end - range.start); string = skip_chop_whitespace(string); int32_t newline_count = 0; @@ -1123,10 +1116,8 @@ CUSTOM_COMMAND_SIG(rename_parameter){ String replace_string = with.string; Buffer_Edit *edits = (Buffer_Edit*)partition_current(part); - size_t remaining = partition_remaining(part); - size_t edit_size = sizeof(Buffer_Edit); - uint32_t edit_max = (uint32_t)(remaining/edit_size); - uint32_t edit_count = 0; + int32_t edit_max = (partition_remaining(part))/sizeof(Buffer_Edit); + int32_t edit_count = 0; if (edit_max >= 1){ Buffer_Edit edit; @@ -1149,7 +1140,7 @@ CUSTOM_COMMAND_SIG(rename_parameter){ switch (token_ptr->type){ case CPP_TOKEN_IDENTIFIER: { - if (token_ptr->size == (uint32_t)old_lexeme.size){ + 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; @@ -1262,8 +1253,7 @@ CUSTOM_COMMAND_SIG(write_explicit_enum_values){ Buffer_Edit *edits = push_array(part, Buffer_Edit, count_estimate); char *string_base = (char*)partition_current(part); - uint32_t remaining = (uint32_t)partition_remaining(part); - String string = make_string(string_base, 0, remaining); + String string = make_string(string_base, 0, partition_remaining(part)); closed_correctly = false; still_looping = false; diff --git a/power/4coder_miblo_numbers.cpp b/power/4coder_miblo_numbers.cpp index fc2197e1..803e9dad 100644 --- a/power/4coder_miblo_numbers.cpp +++ b/power/4coder_miblo_numbers.cpp @@ -14,9 +14,9 @@ TYPE: 'drop-in-command-pack' #include "4coder_helper/4coder_helper.h" #include "4coder_helper/4coder_streaming.h" -static bool32 -get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, size_t *numeric_start, size_t *numeric_end){ - bool32 result = false; +static int32_t +get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, int32_t *numeric_start, int32_t *numeric_end){ + int32_t result = 0; char current = buffer_get_char(app, buffer, start_pos); @@ -25,16 +25,16 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, siz int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; - size_t pos = start_pos; + int32_t pos = start_pos; - size_t pos1 = 0; - size_t pos2 = 0; + int32_t pos1 = 0; + int32_t pos2 = 0; if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){ int32_t still_looping = 1; while (still_looping){ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= stream.start; --pos){ char at_pos = stream.data[pos]; if (!char_is_numeric(at_pos)){ ++pos; @@ -50,7 +50,7 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, siz still_looping = 1; while (still_looping){ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < stream.end; ++pos){ char at_pos = stream.data[pos]; if (!char_is_numeric(at_pos)){ goto double_break_2; @@ -61,7 +61,7 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, siz double_break_2:; pos2 = pos; - result = true; + result = 1; *numeric_start = pos1; *numeric_end = pos2; } @@ -72,19 +72,18 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, siz } struct Miblo_Number_Info{ - size_t start, end; + int32_t start, end; int32_t x; }; -static bool32 -get_numeric_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t pos, Miblo_Number_Info *info){ - bool32 result = false; +static int32_t +get_numeric_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Miblo_Number_Info *info){ + int32_t result = 0; - size_t numeric_start = 0, numeric_end = 0; + int32_t numeric_start = 0, numeric_end = 0; if (get_numeric_string_at_cursor(app, buffer, pos, &numeric_start, &numeric_end)){ - int32_t string_length = (int32_t)(numeric_end - numeric_start); char numeric_string[1024]; - String str = make_string(numeric_string, string_length, sizeof(numeric_string)); + 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); @@ -94,7 +93,7 @@ get_numeric_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t pos info->start = numeric_start; info->end = numeric_end; info->x = x; - result = true; + result = 1; } } @@ -132,9 +131,9 @@ CUSTOM_COMMAND_SIG(miblo_decrement_basic){ // NOTE(allen): miblo time stamp format // (h+:)?m?m:ss -static bool32 -get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, size_t *timestamp_start, size_t *timestamp_end){ - bool32 result = false; +static int32_t +get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, int32_t *timestamp_start, int32_t *timestamp_end){ + int32_t result = 0; char current = buffer_get_char(app, buffer, start_pos); @@ -143,16 +142,16 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, s int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; - size_t pos = start_pos; + int32_t pos = start_pos; - size_t pos1 = 0; - size_t pos2 = 0; + int32_t pos1 = 0; + int32_t pos2 = 0; if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){ int32_t still_looping = 1; while (still_looping){ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= stream.start; --pos){ char at_pos = stream.data[pos]; if (!(char_is_numeric(at_pos) || at_pos == ':')){ ++pos; @@ -168,7 +167,7 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, s still_looping = 1; while (still_looping){ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < stream.end; ++pos){ char at_pos = stream.data[pos]; if (!(char_is_numeric(at_pos) || at_pos == ':')){ goto double_break_2; @@ -179,7 +178,7 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, s double_break_2:; pos2 = pos; - result = true; + result = 1; *timestamp_start = pos1; *timestamp_end = pos2; } @@ -272,19 +271,18 @@ timestamp_to_str(String *dest, Miblo_Timestamp t){ } struct Miblo_Timestamp_Info{ - size_t start, end; + int32_t start, end; Miblo_Timestamp time; }; -static bool32 -get_timestamp_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t pos, Miblo_Timestamp_Info *info){ - bool32 result = false; +static int32_t +get_timestamp_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Miblo_Timestamp_Info *info){ + int32_t result = 0; - size_t timestamp_start = 0, timestamp_end = 0; + int32_t timestamp_start = 0, timestamp_end = 0; if (get_timestamp_string_at_cursor(app, buffer, pos, ×tamp_start, ×tamp_end)){ - int32_t string_length = (int32_t)(timestamp_end - timestamp_start); char timestamp_string[1024]; - String str = make_string(timestamp_string, string_length, sizeof(timestamp_string)); + 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); @@ -298,10 +296,10 @@ get_timestamp_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t p if (count_colons == 1 || count_colons == 2){ Miblo_Timestamp t = {0}; - bool32 success = false; + int32_t success = 0; - size_t i = 0; - size_t number_start[3], number_end[3]; + int32_t i = 0; + int32_t number_start[3], number_end[3]; for (int32_t k = 0; k < 3; ++k){ number_start[k] = i; for (; i <= str.size; ++i){ @@ -317,42 +315,27 @@ get_timestamp_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t p } if (count_colons == 2){ + t.hour = str_to_int(make_string(str.str + number_start[0], number_end[0] - number_start[0])); - int32_t number_length = (int32_t)(number_end[0] - number_start[0]); - String number_string = make_string(str.str + number_start[0], number_length); - t.hour = str_to_int(number_string); - - number_length = (int32_t)(number_end[1] - number_start[1]); - if (number_length == 2){ + if (number_end[1] - number_start[1] == 2){ - number_string = make_string(str.str + number_start[1], number_length); - t.minute = str_to_int(number_string); + t.minute = str_to_int(make_string(str.str + number_start[1], number_end[1] - number_start[1])); - number_length = (int32_t)(number_end[2] - number_start[2]); - if (number_length == 2){ + 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])); - number_string = make_string(str.str + number_start[2], number_length); - t.second = str_to_int(number_string); - - success = true; + success = 1; } } } else{ - - int32_t number_length = (int32_t)(number_end[0] - number_start[0]); - if (number_length == 2 || number_length == 1){ + 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 number_string = make_string(str.str + number_start[0], number_length); - t.minute = str_to_int(number_string); - - number_length = (int32_t)(number_end[1] - number_start[1]); - if (number_length == 2){ + 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])); - number_string = make_string(str.str + number_start[1], number_length); - t.second = str_to_int(number_string); - - success = true; + success = 1; } } } @@ -361,7 +344,7 @@ get_timestamp_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t p info->start = timestamp_start; info->end = timestamp_end; info->time = t; - result = true; + result = 1; } } } diff --git a/string/4coder_string_build_num.txt b/string/4coder_string_build_num.txt index 3c4899bf..f89e02d7 100644 --- a/string/4coder_string_build_num.txt +++ b/string/4coder_string_build_num.txt @@ -1,5 +1,5 @@ 1 0 -68 +69 diff --git a/string/_4coder_string.ctm b/string/_4coder_string.ctm index 77f6a743..459c3aff 100644 Binary files a/string/_4coder_string.ctm and b/string/_4coder_string.ctm differ diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 390c2446..bd230e49 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -71,10 +71,11 @@ ////////////////////////////// -#include "4ed_file_track.h" -#include "4ed_system_shared.h" +#include "win32_utf8.h" -#include "win32_4ed_file_track.cpp" +#include "4ed_file_track.h" +#include "4ed_font_interface_to_os.h" +#include "4ed_system_shared.h" // // Win32_Vars structs @@ -184,6 +185,9 @@ typedef struct Win32_Vars{ HCURSOR cursor_arrow; HCURSOR cursor_leftright; HCURSOR cursor_updown; + + u8 *clip_buffer; + u32 clip_max; String clipboard_contents; b32 next_clipboard_is_self; DWORD clipboard_sequence; @@ -283,14 +287,6 @@ Sys_Memory_Free_Sig(system_memory_free){ VirtualFree(ptr, 0, MEM_RELEASE); } -#define Win32GetMemory(size) system_memory_allocate(size) -#define Win32FreeMemory(ptr) system_memory_free(ptr) - -#define Win32ScratchPartition sysshared_scratch_partition -#define Win32ScratchPartitionGrow sysshared_partition_grow -#define Win32ScratchPartitionDouble sysshared_partition_double - - // // Multithreading // @@ -331,7 +327,7 @@ JobThreadProc(LPVOID lpParameter){ if (thread_memory->size == 0){ i32 new_size = KB(64); - thread_memory->data = Win32GetMemory(new_size); + thread_memory->data = system_memory_allocate(new_size); thread_memory->size = new_size; } @@ -380,7 +376,7 @@ JobThreadProc(LPVOID lpParameter){ internal void initialize_unbounded_queue(Unbounded_Work_Queue *source_queue){ - u32 max = 512; + i32 max = 512; source_queue->jobs = (Full_Job_Data*)system_memory_allocate(max*sizeof(Full_Job_Data)); source_queue->count = 0; source_queue->max = max; @@ -491,9 +487,8 @@ Sys_Post_Job_Sig(system_post_job){ u32 result = queue->next_job_id++; while (queue->count >= queue->max){ - i32 new_max = queue->max*2; - Full_Job_Data *new_jobs = (Full_Job_Data*) - system_memory_allocate(new_max*sizeof(Full_Job_Data)); + u32 new_max = queue->max*2; + Full_Job_Data *new_jobs = (Full_Job_Data*)system_memory_allocate(new_max*sizeof(Full_Job_Data)); memcpy(new_jobs, queue->jobs, queue->count); @@ -717,28 +712,12 @@ Sys_Yield_Coroutine_Sig(system_yield_coroutine){ internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made){ + HANDLE file = CreateFile_utf8(filename, FILE_APPEND_DATA, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); b32 result = false; - - Partition *scratch = &shared_vars.scratch; - Temp_Memory temp = begin_temp_memory(scratch); - umem len = str_size(filename); - umem max = (len+1)*2; - u16 *filename_16 = push_array(scratch, u16, max); - - b32 error = false; - utf8_to_utf16_minimal_checking(filename_16, max, filename, len, &error); - - if (!error){ - HANDLE file = CreateFile((LPCWSTR)filename_16, FILE_APPEND_DATA, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - - if (file != 0 && file != INVALID_HANDLE_VALUE){ - result = true; - CloseHandle(file); - } + if (file != 0 && file != INVALID_HANDLE_VALUE){ + CloseHandle(file); + result = true; } - - end_temp_memory(temp); - return(result); } @@ -751,14 +730,14 @@ Sys_Set_File_List_Sig(system_set_file_list){ append_sc(&dir, directory); terminate_with_null(&dir); - HANDLE dir_handle = CreateFile(dir.str, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + HANDLE dir_handle = CreateFile_utf8((u8*)dir.str, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir_handle != INVALID_HANDLE_VALUE){ - DWORD final_length = GetFinalPathNameByHandle(dir_handle, dir_space, sizeof(dir_space), 0); + DWORD final_length = GetFinalPathNameByHandle_utf8(dir_handle, (u8*)dir_space, sizeof(dir_space), 0); CloseHandle(dir_handle); if (final_length < sizeof(dir_space)){ - char *c_str_dir = dir_space; + u8 *c_str_dir = (u8*)dir_space; final_length -= 4; memmove(c_str_dir, c_str_dir+4, final_length); @@ -783,17 +762,18 @@ Sys_Set_File_List_Sig(system_set_file_list){ } WIN32_FIND_DATA find_data; - HANDLE search = FindFirstFile(c_str_dir, &find_data); + HANDLE search = FindFirstFile_utf8(c_str_dir, &find_data); if (search != INVALID_HANDLE_VALUE){ - i32 character_count = 0; - i32 file_count = 0; + u32 character_count = 0; + u32 file_count = 0; BOOL more_files = true; do{ - if (!match_cs(find_data.cFileName, make_lit_string(".")) && - !match_cs(find_data.cFileName, make_lit_string(".."))){ + b32 nav_dir = + (find_data.cFileName[0] == '.' && find_data.cFileName[1] == 0) ||(find_data.cFileName[0] == '.' && find_data.cFileName[1] == '.' && find_data.cFileName[2] == 0); + if (!nav_dir){ ++file_count; - i32 size = 0; + u32 size = 0; for(;find_data.cFileName[size];++size); character_count += size + 1; } @@ -801,41 +781,57 @@ Sys_Set_File_List_Sig(system_set_file_list){ }while(more_files); FindClose(search); - i32 required_size = character_count + file_count * sizeof(File_Info); + u32 remaining_size = character_count*2; + u32 required_size = remaining_size + file_count*sizeof(File_Info); if (file_list->block_size < required_size){ - system_free_memory(file_list->block); - file_list->block = system_get_memory(required_size); + system_memory_free(file_list->block, 0); + file_list->block = system_memory_allocate(required_size); file_list->block_size = required_size; } file_list->infos = (File_Info*)file_list->block; - char *name = (char*)(file_list->infos + file_count); + u8 *name = (u8*)(file_list->infos + file_count); + u32 corrected_file_count = 0; if (file_list->block != 0){ - search = FindFirstFile(c_str_dir, &find_data); + search = FindFirstFile_utf8(c_str_dir, &find_data); if (search != INVALID_HANDLE_VALUE){ File_Info *info = file_list->infos; more_files = true; do{ - if (!match_cs(find_data.cFileName, make_lit_string(".")) && - !match_cs(find_data.cFileName, make_lit_string(".."))){ + b32 nav_dir = + (find_data.cFileName[0] == '.' && find_data.cFileName[1] == 0) ||(find_data.cFileName[0] == '.' && find_data.cFileName[1] == '.' && find_data.cFileName[2] == 0); + + if (!nav_dir){ info->folder = (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; - info->filename = name; + info->filename = (char*)name; - i32 length = copy_fast_unsafe_cc(name, find_data.cFileName); - name += length; + u16 *src = (u16*)find_data.cFileName; + u32 src_len = 0; + for (;src[src_len];++src_len); - info->filename_len = length; - *name++ = 0; - String fname = make_string_cap(info->filename, info->filename_len, info->filename_len+1); - replace_char(&fname, '\\', '/'); - ++info; + u8 *dst = name; + u32 max = remaining_size-1; + + b32 error = false; + u32 length = (u32)utf16_to_utf8_minimal_checking(dst, max, src, src_len, &error); + + if (length <= max && !error){ + name += length; + + info->filename_len = length; + *name++ = 0; + String fname = make_string_cap(info->filename, length, length+1); + replace_char(&fname, '\\', '/'); + ++info; + ++corrected_file_count; + } } more_files = FindNextFile(search, &find_data); }while(more_files); FindClose(search); - file_list->count = file_count; + file_list->count = corrected_file_count; clear_list = false; } } @@ -845,7 +841,7 @@ Sys_Set_File_List_Sig(system_set_file_list){ } if (clear_list){ - Win32FreeMemory(file_list->block); + system_memory_free(file_list->block, 0); file_list->block = 0; file_list->block_size = 0; file_list->infos = 0; @@ -862,10 +858,10 @@ win32_canonical_ascii_name(char *src, u32 len, char *dst, u32 max){ memcpy(src_space, src, len); src_space[len] = 0; - HANDLE file = CreateFile(src_space, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + HANDLE file = CreateFile_utf8((u8*)src_space, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ - DWORD final_length = GetFinalPathNameByHandle(file, dst, max, 0); + DWORD final_length = GetFinalPathNameByHandle_utf8(file, (u8*)dst, max, 0); if (final_length < max && final_length >= 4){ if (dst[final_length-1] == 0){ @@ -887,10 +883,10 @@ win32_canonical_ascii_name(char *src, u32 len, char *dst, u32 max){ memcpy(src_space, path_str.str, path_str.size); src_space[path_str.size] = 0; - HANDLE dir = CreateFile(src_space, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + HANDLE dir = CreateFile_utf8((u8*)src_space, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir != INVALID_HANDLE_VALUE){ - DWORD final_length = GetFinalPathNameByHandle(dir, dst, max, 0); + DWORD final_length = GetFinalPathNameByHandle_utf8(dir, (u8*)dst, max, 0); if (final_length < max && final_length >= 4){ if (dst[final_length-1] == 0){ @@ -921,12 +917,12 @@ Sys_Get_Canonical_Sig(system_get_canonical){ internal Sys_Load_Handle_Sig(system_load_handle){ - b32 result = 0; - HANDLE file = CreateFile(filename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + b32 result = false; + HANDLE file = CreateFile_utf8((u8*)filename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ *(HANDLE*)handle_out = file; - result = 1; + result = true; } return(result); @@ -975,14 +971,14 @@ Sys_Load_Close_Sig(system_load_close){ internal Sys_Save_File_Sig(system_save_file){ - b32 result = 0; - HANDLE file = CreateFile(filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + b32 result = false; + HANDLE file = CreateFile_utf8((u8*)filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ DWORD written_total = 0; DWORD written_size = 0; - result = 1; + result = true; while (written_total < size){ if (!WriteFile(file, buffer + written_total, size - written_total, &written_size, 0)){ @@ -1006,14 +1002,14 @@ Sys_Now_Time_Sig(system_now_time){ internal b32 Win32DirectoryExists(char *path){ - DWORD attrib = GetFileAttributes(path); - return (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY)); + DWORD attrib = GetFileAttributes_utf8((u8*)path); + return(attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY)); } internal Sys_Get_Binary_Path_Sig(system_get_binary_path){ i32 result = 0; - i32 size = GetModuleFileName(0, out->str, out->memory_size); + i32 size = GetModuleFileName_utf8(0, (u8*)out->str, out->memory_size); if (size < out->memory_size-1){ out->size = size; remove_last_folder(out); @@ -1035,8 +1031,7 @@ Sys_File_Exists_Sig(system_file_exists){ copy_ss(&full_filename, make_string(filename, len)); terminate_with_null(&full_filename); - file = CreateFile(full_filename.str, GENERIC_READ, 0, 0, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + file = CreateFile_utf8((u8*)full_filename.str, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ CloseHandle(file); @@ -1128,6 +1123,7 @@ Win32ToggleFullscreen(void){ } } + // // Clipboard // @@ -1150,20 +1146,41 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){ } internal b32 -Win32ReadClipboardContents(){ - b32 result = 0; +win32_read_clipboard_contents(){ + b32 result = false; - if (IsClipboardFormatAvailable(CF_TEXT)){ - result = 1; + if (IsClipboardFormatAvailable(CF_UNICODETEXT)){ + result = true; if (OpenClipboard(win32vars.window_handle)){ - HANDLE clip_data; - clip_data = GetClipboardData(CF_TEXT); - if (clip_data){ - win32vars.clipboard_contents.str = (char*)GlobalLock(clip_data); - if (win32vars.clipboard_contents.str){ - win32vars.clipboard_contents.size = str_size((char*)win32vars.clipboard_contents.str); + HANDLE clip_data = GetClipboardData(CF_UNICODETEXT); + if (clip_data != 0){ + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u16 *clip_16 = (u16*)GlobalLock(clip_data); + + if (clip_16 != 0){ + u32 clip_16_len = 0; + for(;clip_16[clip_16_len];++clip_16_len); + + // TODO(allen): Extend the buffer if it is too small. + b32 error = false; + u32 clip_8_len = (u32)utf16_to_utf8_minimal_checking(win32vars.clip_buffer, win32vars.clip_max-1, clip_16, clip_16_len, &error); + + if (clip_8_len < win32vars.clip_max && !error){ + win32vars.clip_buffer[clip_8_len] = 0; + + win32vars.clipboard_contents = make_string_cap(win32vars.clip_buffer, clip_8_len, win32vars.clip_max); + } + GlobalUnlock(clip_data); } + + if (win32vars.clipboard_contents.str){ + win32vars.clipboard_contents.size = str_size((char*)win32vars.clipboard_contents.str); + } + + end_temp_memory(temp); } CloseClipboard(); } @@ -1210,10 +1227,7 @@ Sys_CLI_Call_Sig(system_cli_call){ PROCESS_INFORMATION info = {}; Assert(sizeof(Plat_Handle) >= sizeof(HANDLE)); - if (CreateProcess(cmd, command_line, - 0, 0, TRUE, 0, - env_variables, path, - &startup, &info)){ + if (CreateProcess_utf8((u8*)cmd, (u8*)command_line, 0, 0, TRUE, 0, env_variables, (u8*)path, &startup, &info)){ success = 1; CloseHandle(info.hThread); *(HANDLE*)&cli_out->proc = info.hProcess; @@ -1371,31 +1385,31 @@ Sys_Send_Exit_Signal_Sig(system_send_exit_signal){ win32vars.send_exit_signal = 1; } -#include "4ed_system_shared.cpp" - // // Linkage to Custom and Application // internal b32 Win32LoadAppCode(){ - b32 result = 0; + b32 result = false; App_Get_Functions *get_funcs = 0; win32vars.app_code = LoadLibraryA("4ed_app.dll"); if (win32vars.app_code){ - get_funcs = (App_Get_Functions*) - GetProcAddress(win32vars.app_code, "app_get_functions"); + get_funcs = (App_Get_Functions*)GetProcAddress(win32vars.app_code, "app_get_functions"); } if (get_funcs){ - result = 1; - win32vars.app = get_funcs(); + result = true; + win32vars.app = get_funcs(); } - return result; + return(result); } +#include "4ed_font_data.h" +#include "4ed_system_shared.cpp" + internal void Win32LoadSystemCode(){ win32vars.system.set_file_list = system_set_file_list; @@ -1819,7 +1833,7 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ case WM_MOUSEWHEEL: { win32vars.got_useful_event = 1; - Font_ID rotation = GET_WHEEL_DELTA_WPARAM(wParam); + i32 rotation = GET_WHEEL_DELTA_WPARAM(wParam); if (rotation > 0){ win32vars.input_chunk.trans.mouse_wheel = 1; } @@ -2008,7 +2022,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS memory_vars.user_memory = VirtualAlloc(base, memory_vars.target_memory_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); win32vars.target.max = MB(1); - win32vars.target.push_buffer = (char*)system_get_memory(win32vars.target.max); + win32vars.target.push_buffer = (char*)system_memory_allocate(win32vars.target.max); if (memory_vars.vars_memory == 0 || memory_vars.target_memory == 0 || memory_vars.user_memory == 0 || win32vars.target.push_buffer == 0){ exit(1); @@ -2036,8 +2050,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // DWORD required = (GetCurrentDirectory(0, 0)*4) + 1; - char *current_directory_mem = (char*)system_get_memory(required); - DWORD written = GetCurrentDirectory(required, current_directory_mem); + u8 *current_directory_mem = (u8*)system_memory_allocate(required); + DWORD written = GetCurrentDirectory_utf8(required, current_directory_mem); String current_directory = make_string_cap(current_directory_mem, written, required); terminate_with_null(¤t_directory); @@ -2077,15 +2091,14 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS if (win32vars.custom_api.get_alpha_4coder_version == 0 || win32vars.custom_api.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){ - MessageBox(0,"Error: The application and custom version numbers don't match.\n", "Error",0); + MessageBox_utf8(0, (u8*)"Error: The application and custom version numbers don't match.\n", (u8*)"Error",0); exit(1); } - win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*) - GetProcAddress(win32vars.custom, "get_bindings"); + win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)GetProcAddress(win32vars.custom, "get_bindings"); } if (win32vars.custom_api.get_bindings == 0){ - MessageBox(0,"Error: The custom dll is missing.\n", "Error",0); + MessageBox_utf8(0, (u8*)"Error: The custom dll is missing.\n", (u8*)"Error", 0); exit(1); } @@ -2101,8 +2114,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS window_class.style = CS_HREDRAW|CS_VREDRAW; window_class.lpfnWndProc = (WNDPROC)(Win32Callback); window_class.hInstance = hInstance; - window_class.lpszClassName = "4coder-win32-wndclass"; - window_class.hIcon = LoadIcon(hInstance, "main"); + window_class.lpszClassName = L"4coder-win32-wndclass"; + window_class.hIcon = LoadIcon(hInstance, L"main"); if (!RegisterClass(&window_class)){ exit(1); @@ -2123,8 +2136,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // TODO(allen): non-fatal diagnostics } -#define WINDOW_NAME "4coder-window: " VERSION - i32 window_x = CW_USEDEFAULT; i32 window_y = CW_USEDEFAULT; @@ -2138,6 +2149,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS window_style |= WS_MAXIMIZE; } +#define WINDOW_NAME L"4coder-window: " L_VERSION + win32vars.window_handle = CreateWindow(window_class.lpszClassName, WINDOW_NAME, window_style, window_x, window_y, window_rect.right - window_rect.left, window_rect.bottom - window_rect.top, 0, 0, hInstance, 0); if (win32vars.window_handle == 0){ @@ -2175,6 +2188,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // Misc System Initializations // + win32vars.clip_max = KB(16); + win32vars.clip_buffer = (u8*)system_memory_allocate(win32vars.clip_max); + win32vars.clipboard_sequence = GetClipboardSequenceNumber(); if (win32vars.clipboard_sequence == 0){ system_post_clipboard(make_lit_string("")); @@ -2187,7 +2203,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } } else{ - Win32ReadClipboardContents(); + win32_read_clipboard_contents(); } Win32KeycodeInit(); @@ -2212,7 +2228,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS win32vars.app.init(&win32vars.system, &win32vars.target, &memory_vars, win32vars.clipboard_contents, current_directory, win32vars.custom_api); - system_free_memory(current_directory.str); + system_memory_free(current_directory.str, 0); b32 keep_playing = 1; win32vars.first = 1; @@ -2368,7 +2384,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS win32vars.next_clipboard_is_self = 0; } else{ - Win32ReadClipboardContents(); + win32_read_clipboard_contents(); } } } @@ -2452,10 +2468,11 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS return(0); } -#include "font/4coder_font_static_functions.cpp" - #include "win32_4ed_fonts.cpp" -//#include "win32_4ed_file_track.cpp" + +#include "win32_4ed_file_track.cpp" +#include "4ed_font_static_functions.cpp" +#include "win32_utf8.cpp" #if 0 // NOTE(allen): In case I want to switch back to a console diff --git a/win32_4ed_file_track.cpp b/win32_4ed_file_track.cpp index d0b03d3d..d48e9f8f 100644 --- a/win32_4ed_file_track.cpp +++ b/win32_4ed_file_track.cpp @@ -44,7 +44,7 @@ typedef struct { #define to_tables(v) ((File_Track_Tables*)(v->tables)) FILE_TRACK_LINK File_Track_Result -init_track_system(File_Track_System *system, Partition *scratch, void *table_memory, umem table_memory_size, void *listener_memory, umem listener_memory_size){ +init_track_system(File_Track_System *system, Partition *scratch, void *table_memory, i32 table_memory_size, void *listener_memory, i32 listener_memory_size){ File_Track_Result result = FileTrack_MemoryTooSmall; Win32_File_Track_Vars *vars = to_vars(system); @@ -63,9 +63,8 @@ init_track_system(File_Track_System *system, Partition *scratch, void *table_mem init_sentinel_node(&vars->free_sentinel); Win32_Directory_Listener_Node *listener = (Win32_Directory_Listener_Node*)listener_memory; - umem node_size = sizeof(Win32_Directory_Listener_Node); - u32 count = (u32)(listener_memory_size / node_size); - for (u32 i = 0; i < count; ++i, ++listener){ + i32 count = listener_memory_size / sizeof(Win32_Directory_Listener_Node); + for (i32 i = 0; i < count; ++i, ++listener){ insert_node(&vars->free_sentinel, &listener->node); } } @@ -82,20 +81,19 @@ init_track_system(File_Track_System *system, Partition *scratch, void *table_mem return(result); } -internal umem -internal_utf8_file_to_utf16_parent(u16 *out, u32 max, u8 *name){ +internal i32 +internal_get_parent_name(u8 *out, i32 max, u8 *name){ u8 *ptr = name; for (; *ptr != 0; ++ptr); - umem len = (umem)(ptr - name); + i32 len = (i32)(ptr - name); // TODO(allen): make this system real Assert(len < max); - umem slash_i = len-1; + i32 slash_i = len-1; for (;slash_i > 0 && name[slash_i] != '\\' && name[slash_i] != '/';--slash_i); - b32 error = false; - slash_i = utf8_to_utf16_minimal_checking(out, max-1, name, len, &error); + for (i32 i = 0; i < slash_i; ++i) out[i] = name[i]; out[slash_i] = 0; return(slash_i); @@ -131,11 +129,10 @@ add_listener(File_Track_System *system, Partition *scratch, u8 *filename){ { File_Track_Tables *tables = to_tables(vars); - // TODO(allen): make this real! - u16 dir_name[1024]; - internal_utf8_file_to_utf16_parent(dir_name, ArrayCount(dir_name), filename); + u8 dir_name[1024]; + internal_get_parent_name(dir_name, ArrayCount(dir_name), filename); - HANDLE dir = CreateFile((LPCWSTR)dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + HANDLE dir = CreateFile_utf8(dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir != INVALID_HANDLE_VALUE){ BY_HANDLE_FILE_INFORMATION dir_info = {0}; @@ -214,10 +211,10 @@ remove_listener(File_Track_System *system, Partition *scratch, u8 *filename){ File_Track_Tables *tables = to_tables(vars); // TODO(allen): make this real! - u16 dir_name[1024]; - internal_utf8_file_to_utf16_parent(dir_name, ArrayCount(dir_name), filename); + u8 dir_name[1024]; + internal_get_parent_name(dir_name, ArrayCount(dir_name), filename); - HANDLE dir = CreateFile((LPCWSTR)dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + HANDLE dir = CreateFile_utf8(dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir != INVALID_HANDLE_VALUE){ BY_HANDLE_FILE_INFORMATION dir_info = {0}; @@ -255,7 +252,7 @@ remove_listener(File_Track_System *system, Partition *scratch, u8 *filename){ } FILE_TRACK_LINK File_Track_Result -move_track_system(File_Track_System *system, Partition *scratch, void *mem, umem size){ +move_track_system(File_Track_System *system, Partition *scratch, void *mem, i32 size){ File_Track_Result result = FileTrack_Good; Win32_File_Track_Vars *vars = to_vars(system); @@ -271,7 +268,7 @@ move_track_system(File_Track_System *system, Partition *scratch, void *mem, umem } FILE_TRACK_LINK File_Track_Result -expand_track_system_listeners(File_Track_System *system, Partition *scratch, void *mem, umem size){ +expand_track_system_listeners(File_Track_System *system, Partition *scratch, void *mem, i32 size){ File_Track_Result result = FileTrack_Good; Win32_File_Track_Vars *vars = to_vars(system); @@ -279,9 +276,8 @@ expand_track_system_listeners(File_Track_System *system, Partition *scratch, voi if (sizeof(Win32_Directory_Listener_Node) <= size){ Win32_Directory_Listener_Node *listener = (Win32_Directory_Listener_Node*)mem; - umem node_size = sizeof(Win32_Directory_Listener_Node); - u32 count = (u32)(size / node_size); - for (u32 i = 0; i < count; ++i, ++listener){ + i32 count = size / sizeof(Win32_Directory_Listener_Node); + for (i32 i = 0; i < count; ++i, ++listener){ insert_node(&vars->free_sentinel, &listener->node); } } @@ -295,7 +291,7 @@ expand_track_system_listeners(File_Track_System *system, Partition *scratch, voi } FILE_TRACK_LINK File_Track_Result -get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 max, umem *size){ +get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 max, i32 *size){ File_Track_Result result = FileTrack_NoMoreEvents; Win32_File_Track_Vars *vars = to_vars(system); @@ -303,19 +299,17 @@ get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 local_persist DWORD offset = 0; local_persist Win32_Directory_Listener listener = {0}; - Temp_Memory temp = begin_temp_memory(scratch); - EnterCriticalSection(&vars->table_lock); OVERLAPPED *overlapped = 0; DWORD length = 0; ULONG_PTR key = 0; - b32 has_result = false; + b32 has_result = 0; if (has_buffered_event){ has_buffered_event = 0; - has_result = true; + has_result = 1; } else{ if (GetQueuedCompletionStatus(vars->iocp, &length, &key, &overlapped, 0)){ @@ -328,7 +322,7 @@ get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 ReadDirectoryChangesW(listener_ptr->dir, listener_ptr->result, sizeof(listener_ptr->result), 1, FLAGS, 0, &listener_ptr->overlapped, 0); offset = 0; - has_result = true; + has_result = 1; } } @@ -336,42 +330,41 @@ get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 FILE_NOTIFY_INFORMATION *info = (FILE_NOTIFY_INFORMATION*)(listener.result + offset); i32 len = info->FileNameLength / 2; - i32 dir_len = GetFinalPathNameByHandle(listener.dir, 0, 0, FILE_NAME_NORMALIZED); + i32 dir_len = GetFinalPathNameByHandle_utf8(listener.dir, 0, 0, FILE_NAME_NORMALIZED); i32 req_size = dir_len + 1 + len; + *size = req_size; + + // TODO(allen): This check isn't really right, it should rely on the result from GetFinalPathNameByHandle_utf8. if (req_size < max){ - u16 *buffer_16 = push_array(scratch, u16, req_size+1); - i32 pos = GetFinalPathNameByHandle(listener.dir, (LPWSTR)buffer_16, max, FILE_NAME_NORMALIZED); + i32 pos = GetFinalPathNameByHandle_utf8(listener.dir, buffer, max, FILE_NAME_NORMALIZED); + buffer[pos++] = '\\'; - b32 convert_error = false; - umem buffer_size = utf16_to_utf8_minimal_checking(buffer, max-1, buffer_16, pos, &convert_error); - - if (buffer_size > max-1){ - result = FileTrack_MemoryTooSmall; + for (i32 i = 0; i < len; ++i, ++pos){ + buffer[pos] = (char)info->FileName[i]; } - else if (!convert_error){ - buffer[buffer_size++] = '\\'; - - if (buffer[0] == '\\'){ - for (i32 i = 0; i+4 < buffer_size; ++i){ - buffer[i] = buffer[i+4]; - } - buffer_size -= 4; + + if (buffer[0] == '\\'){ + for (i32 i = 0; i+4 < pos; ++i){ + buffer[i] = buffer[i+4]; } - *size = buffer_size; - result = FileTrack_Good; - } - else{ - result = FileTrack_FileSystemError; + *size -= 4; } + + result = FileTrack_Good; } else{ - // TODO(allen): Need some way to stash this result so that if the user comes back with more memory we can give them the change notification they missed. + // TODO(allen): Need some way to stash this result so that if the + // user comes back with more memory we can give them the change + // notification they missed. result = FileTrack_MemoryTooSmall; } if (info->NextEntryOffset != 0){ - // TODO(allen): We're not ready to handle this yet. For now I am breaking. In the future, if there are more results we should stash them and return them in future calls. + // TODO(allen): We're not ready to handle this yet. + // For now I am breaking. In the future, if there + // are more results we should stash them and return + // them in future calls. offset += info->NextEntryOffset; has_buffered_event = 1; } @@ -379,8 +372,6 @@ get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 LeaveCriticalSection(&vars->table_lock); - end_temp_memory(temp); - return(result); } diff --git a/win32_4ed_fonts.cpp b/win32_4ed_fonts.cpp index 3b50b8f3..e9671a72 100644 --- a/win32_4ed_fonts.cpp +++ b/win32_4ed_fonts.cpp @@ -10,13 +10,13 @@ // TOP #include "4ed_system_shared.h" -#include "font/4coder_font_interface.h" -#include "font/4coder_font_interface_to_os.h" -#include "font/4coder_font_data.h" +#include "4ed_font_interface.h" +#include "4ed_font_interface_to_os.h" +#include "4ed_font_data.h" struct Win32_Fonts{ Partition part; - Render_Font fonts[5]; + Render_Font fonts[32]; u32 font_count; }; @@ -24,7 +24,7 @@ global Win32_Fonts win32_fonts = {0}; internal Sys_Font_Get_Count_Sig(system_font_get_count){ - return(5); + return(win32_fonts.font_count); } internal @@ -87,6 +87,9 @@ Sys_Font_Free_Sig(system_font_free){ internal Sys_Font_Init_Sig(system_font_init){ + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + font->get_count = system_font_get_count; font->get_ids_by_index = system_font_get_ids_by_index; font->get_name_by_index = system_font_get_name_by_index; @@ -98,36 +101,114 @@ Sys_Font_Init_Sig(system_font_init){ font_size = clamp_bottom(8, font_size); - struct Font_Setup{ +#if 0 + struct TEST_DATA{ char *c_filename; i32 filename_len; char *c_name; i32 name_len; - u32 pt_size; }; - Font_Setup font_setup[] = { - {literal("LiberationSans-Regular.ttf"), literal("Liberation Sans"), font_size}, - {literal("liberation-mono.ttf"), literal("Liberation Mono"), font_size}, - {literal("Hack-Regular.ttf"), literal("Hack"), font_size}, - {literal("CutiveMono-Regular.ttf"), literal("Cutive Mono"), font_size}, - {literal("Inconsolata-Regular.ttf"), literal("Inconsolata"), font_size}, + TEST_DATA TEST_SETUP[] = { + {literal("fonts/LiberationSans-Regular.ttf"), literal("Liberation Sans"), }, + {literal("fonts/liberation-mono.ttf"), literal("Liberation Mono"), }, + {literal("fonts/Hack-Regular.ttf"), literal("Hack"), }, + {literal("fonts/CutiveMono-Regular.ttf"), literal("Cutive Mono"), }, + {literal("fonts/Inconsolata-Regular.ttf"), literal("Inconsolata"), }, }; - u32 font_count = Min(ArrayCount(win32_fonts.fonts), ArrayCount(font_setup)); - for (u32 i = 0; i < font_count; ++i){ - String filename = make_string(font_setup[i].c_filename, font_setup[i].filename_len); - String name = make_string(font_setup[i].c_name, font_setup[i].name_len); - u32 pt_size = font_setup[i].pt_size; - Render_Font *render_font = &win32_fonts.fonts[i]; + u32 TEST_COUNT = ArrayCount(TEST_SETUP); + for (u32 i = 0; i < TEST_COUNT; ++i){ + if (first_setup == 0){ + head_setup = push_struct(scratch, Font_Setup); + first_setup = head_setup; + } + else{ + head_setup->next_font = push_struct(scratch, Font_Setup); + head_setup = head_setup->next_font; + } - char full_filename_space[256]; - String full_filename = make_fixed_width_string(full_filename_space); - sysshared_to_binary_path(&full_filename, filename.str); + TEST_DATA *TEST = &TEST_SETUP[i]; - system_set_font(&win32vars.system, &win32_fonts.part, render_font, full_filename, name, pt_size, use_hinting); + head_setup->c_filename = push_array(scratch, char, TEST->filename_len+1); + memcpy(head_setup->c_filename, TEST->c_filename, TEST->filename_len+1); + head_setup->filename_len = TEST->filename_len; + + head_setup->c_name = push_array(scratch, char, TEST->name_len+1); + memcpy(head_setup->c_name, TEST->c_name, TEST->name_len+1); + head_setup->name_len = TEST->name_len; + + partition_align(scratch, 8); + } +#endif + + struct Font_Setup{ + Font_Setup *next_font; + char *c_filename; + }; + + Font_Setup *first_setup = 0; + Font_Setup *head_setup = 0; + + u32 dir_max = KB(32); + u8 *directory = push_array(scratch, u8, dir_max); + DWORD dir_len = GetModuleFileName_utf8(0, directory, dir_max-1); + Assert(dir_len < dir_max); + + { + String dir_str = make_string_cap(directory, dir_len, dir_max); + remove_last_folder(&dir_str); + set_last_folder_sc(&dir_str, "fonts", '\\'); + terminate_with_null(&dir_str); + dir_len = dir_str.size; } - win32_fonts.font_count = font_count; + partition_reduce(scratch, dir_max - dir_len - 1); + partition_align(scratch, 8); + + File_List file_list = {0}; + system_set_file_list(&file_list, (char*)directory, 0, 0, 0); + + for (u32 i = 0; i < file_list.count; ++i){ + File_Info *info = &file_list.infos[i]; + if (first_setup == 0){ + first_setup = push_struct(scratch, Font_Setup); + head_setup = first_setup; + } + else{ + head_setup->next_font = push_struct(scratch, Font_Setup); + head_setup = head_setup->next_font; + } + head_setup->next_font = 0; + + char *filename = info->filename; + u32 len = 0; + for (;filename[len];++len); + + head_setup->c_filename = push_array(scratch, char, dir_len+len+1); + memcpy(head_setup->c_filename, directory, dir_len); + memcpy(head_setup->c_filename + dir_len, filename, len+1); + + partition_align(scratch, 8); + } + + system_set_file_list(&file_list, 0, 0, 0, 0); + + u32 font_count_max = ArrayCount(win32_fonts.fonts); + u32 font_count = 0; + u32 i = 0; + for (Font_Setup *ptr = first_setup; ptr != 0; ptr = ptr->next_font, ++i){ + if (i < font_count_max){ + Render_Font *render_font = &win32_fonts.fonts[i]; + + system_set_font(&win32vars.system, &win32_fonts.part, render_font, ptr->c_filename, font_size, use_hinting); + } + + ++font_count; + } + + win32_fonts.font_count = clamp_top(font_count, font_count_max); + + end_temp_memory(temp); } // BOTTOM diff --git a/win32_utf8.cpp b/win32_utf8.cpp new file mode 100644 index 00000000..a11d963f --- /dev/null +++ b/win32_utf8.cpp @@ -0,0 +1,258 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 23.03.2017 + * + * UTF8 versions of WIN32 calls. + * + */ + +// TOP + +#if !defined(FRED_WIN32_UTF8_CPP) +#define FRED_WIN32_UTF8_CPP + +internal HANDLE +CreateFile_utf8(u8 *name, DWORD access, DWORD share, LPSECURITY_ATTRIBUTES security, DWORD creation, DWORD flags, HANDLE template_file){ + HANDLE result = INVALID_HANDLE_VALUE; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 len = 0; + for (;name[len];++len); + u32 name_16_max = (len+1)*2; + u16 *name_16 = push_array(scratch, u16, name_16_max); + + b32 convert_error = false; + u32 name_16_len = (u32)utf8_to_utf16_minimal_checking(name_16, name_16_max-1, name, len, &convert_error); + + if (!convert_error){ + name_16[name_16_len] = 0; + result = CreateFileW((LPWSTR)name_16, access, share, security, creation, flags, template_file); + } + + end_temp_memory(temp); + + return(result); +} + +internal DWORD +GetFinalPathNameByHandle_utf8(HANDLE file, u8 *file_path_out, DWORD path_max, DWORD flags){ + DWORD result = 0; + + if (file_path_out == 0){ + result = GetFinalPathNameByHandleW(file, 0, 0, flags); + } + else{ + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 path_16_max = KB(32); + u16 *path_16 = push_array(scratch, u16, path_16_max); + + DWORD length_16 = GetFinalPathNameByHandleW(file, (LPWSTR)path_16, path_16_max, flags); + + if (length_16 != 0 && length_16 < path_16_max){ + b32 convert_error = false; + u32 path_8_len = (u32)utf16_to_utf8_minimal_checking(file_path_out, path_max-1, path_16, length_16, &convert_error); + if (path_8_len < path_max && !convert_error){ + file_path_out[path_8_len] = 0; + result = path_8_len; + } + } + + end_temp_memory(temp); + } + + return(result); +} + +internal HANDLE +FindFirstFile_utf8(u8 *name, LPWIN32_FIND_DATA find_data){ + HANDLE result = INVALID_HANDLE_VALUE; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 len = 0; + for (;name[len];++len); + u32 name_16_max = (len+1)*2; + u16 *name_16 = push_array(scratch, u16, name_16_max); + + b32 convert_error = false; + u32 name_16_len = (u32)utf8_to_utf16_minimal_checking(name_16, name_16_max-1, name, len, &convert_error); + + if (name_16_len < name_16_max && !convert_error){ + name_16[name_16_len] = 0; + result = FindFirstFileW((LPWSTR)name_16, find_data); + } + + end_temp_memory(temp); + + return(result); +} + +internal DWORD +GetFileAttributes_utf8(u8 *name){ + DWORD result = 0; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 len = 0; + for (;name[len];++len); + u32 name_16_max = (len+1)*2; + u16 *name_16 = push_array(scratch, u16, name_16_max); + + b32 convert_error = false; + u32 name_16_len = (u32)utf8_to_utf16_minimal_checking(name_16, name_16_max-1, name, len, &convert_error); + + if (name_16_len < name_16_max && !convert_error){ + name_16[name_16_len] = 0; + result = GetFileAttributesW((LPWSTR)name_16); + } + + end_temp_memory(temp); + + return(result); +} + +internal DWORD +GetModuleFileName_utf8(HMODULE module, u8 *file_out, DWORD max){ + DWORD result = 0; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(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); + + if (max > 0){ + b32 convert_error = false; + u32 file_8_len = (u32)utf16_to_utf8_minimal_checking(file_out, max-1, file_16, file_16_len, &convert_error); + result = file_8_len; + if (convert_error || file_8_len >= max){ + result = 0; + } + } + + end_temp_memory(temp); + + return(result); +} + +internal BOOL +CreateProcess_utf8(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; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 app_name_len = 0; + for (;app_name[app_name_len];++app_name_len); + + u32 command_len = 0; + for (;command[command_len];++command_len); + + u32 curdir_len = 0; + for (;curdir[curdir_len];++curdir_len); + + u32 app_name_16_max = (app_name_len+1)*2; + u32 command_16_max = (command_len+1)*2; + u32 curdir_16_max = (curdir_len+1)*2; + + u16 *app_name_16 = push_array(scratch, u16, app_name_16_max); + u16 *command_16 = push_array(scratch, u16, command_16_max); + u16 *curdir_16 = push_array(scratch, u16, curdir_16_max); + + b32 error = false; + u32 app_name_16_len = (u32)utf8_to_utf16_minimal_checking(app_name_16, app_name_16_max-1, app_name, app_name_len, &error); + + if (app_name_16_len < app_name_16_max && !error){ + u32 command_16_len = (u32)utf8_to_utf16_minimal_checking(command_16, command_16_max-1, command, command_len, &error); + + if (command_16_len < command_16_max && !error){ + u32 curdir_16_len = (u32)utf8_to_utf16_minimal_checking(curdir_16, curdir_16_max-1, curdir, curdir_len, &error); + + app_name_16[app_name_16_len] = 0; + command_16[command_16_len] = 0; + curdir_16[curdir_16_len] = 0; + + result = CreateProcessW((LPWSTR)app_name_16, (LPWSTR)command_16, security, thread, inherit_handles, creation, environment, (LPWSTR)curdir_16, startup, process); + } + } + + end_temp_memory(temp); + + return(result); +} + +internal DWORD +GetCurrentDirectory_utf8(DWORD max, u8 *buffer){ + DWORD result = 0; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 buffer_16_max = KB(40); + u16 *buffer_16 = push_array(scratch, u16, buffer_16_max); + + DWORD buffer_16_len = GetCurrentDirectoryW(buffer_16_max, (LPWSTR)buffer_16); + + b32 error = false; + u32 buffer_8_len = (u32)utf16_to_utf8_minimal_checking(buffer, max-1, buffer_16, buffer_16_len, &error); + + if (buffer_8_len < max && !error){ + buffer[buffer_8_len] = 0; + result = buffer_8_len; + } + + end_temp_memory(temp); + + return(result); +} + +internal int +MessageBox_utf8(HWND owner, u8 *text, u8 *caption, UINT type){ + int result = 0; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 text_len = 0; + for(;text[text_len];++text_len); + + u32 caption_len = 0; + for(;caption[caption_len];++caption_len); + + u32 text_16_max = (text_len+1)*2; + u32 caption_16_max = (caption_len+1)*2; + + u16 *text_16 = push_array(scratch, u16, text_16_max); + u16 *caption_16 = push_array(scratch, u16, caption_16_max); + + b32 error = false; + u32 text_16_len = (u32)utf8_to_utf16_minimal_checking(text_16, text_16_max-1, text, text_len, &error); + + if (text_16_len < text_16_max && !error){ + u32 caption_16_len = (u32)utf8_to_utf16_minimal_checking(caption_16, caption_16_max-1, caption, caption_len, &error); + + if (text_16_len < text_16_max && !error){ + text_16[text_16_len] = 0; + caption_16[caption_16_len] = 0; + MessageBoxW(owner, (LPWSTR)text_16, (LPWSTR)caption_16, type); + } + } + + end_temp_memory(temp); + + return(result); +} + +#endif + +// BOTTOM + diff --git a/win32_utf8.h b/win32_utf8.h new file mode 100644 index 00000000..b94d663e --- /dev/null +++ b/win32_utf8.h @@ -0,0 +1,42 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 23.03.2017 + * + * UTF8 versions of WIN32 calls. + * + */ + +// TOP + +#if !defined(FRED_WIN32_UTF8_H) +#define FRED_WIN32_UTF8_H + +internal HANDLE +CreateFile_utf8(u8 *name, DWORD access, DWORD share, LPSECURITY_ATTRIBUTES security, DWORD creation, DWORD flags, HANDLE template_file); + +internal DWORD +GetFinalPathNameByHandle_utf8(HANDLE file, u8 *file_path_out, DWORD path_max, DWORD flags); + +internal HANDLE +FindFirstFile_utf8(u8 *name, LPWIN32_FIND_DATA find_data); + +internal DWORD +GetFileAttributes_utf8(u8 *name); + +internal DWORD +GetModuleFileName_utf8(HMODULE module, u8 *file_out, DWORD max); + +internal BOOL +CreateProcess_utf8(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(DWORD max, u8 *buffer); + +internal int +MessageBox_utf8(HWND owner, u8 *text, u8 *caption, UINT type); + +#endif + +// BOTTOM +