Merge branch 'master' of https://bitbucket.org/4coder/4coder
commit
a78f653c80
|
@ -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));}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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){
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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){
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
22
4ed.cpp
22
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);
|
||||
}
|
||||
|
|
|
@ -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.)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
763
4ed_buffer.cpp
763
4ed_buffer.cpp
File diff suppressed because it is too large
Load Diff
|
@ -15,7 +15,7 @@
|
|||
struct Buffer_Model_Step{
|
||||
u32 type;
|
||||
u32 value;
|
||||
umem i;
|
||||
i32 i;
|
||||
u32 byte_length;
|
||||
};
|
||||
|
||||
|
|
35
4ed_file.cpp
35
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:
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,7 +9,7 @@
|
|||
|
||||
// TOP
|
||||
|
||||
#include "4coder_font_data.h"
|
||||
#include "4ed_font_data.h"
|
||||
|
||||
internal f32
|
||||
font_get_byte_advance(Render_Font *font){
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
13
4ed_math.h
13
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);
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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};
|
||||
|
|
27
4ed_undo.cpp
27
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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -8,6 +8,7 @@ Created 21.01.2017 (dd.mm.yyyy)
|
|||
|
||||
#if !defined(FTECH_DEFINES)
|
||||
#define FTECH_DEFINES
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
|
@ -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 <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <intrin.h>
|
||||
#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
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
#include <string.h>
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -23,7 +23,7 @@ TYPE: 'build-target'
|
|||
#include <string.h>
|
||||
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
1
|
||||
0
|
||||
68
|
||||
69
|
||||
|
||||
|
||||
|
|
Binary file not shown.
251
win32_4ed.cpp
251
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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue