Revert "Converting to proper use of umem everywhere (kind of went off on a tanget there :D)"

This reverts commit fe7c0fe47e.
master
Allen Webster 2017-03-23 15:16:39 -04:00
parent 51b59d31d1
commit f9d2414281
29 changed files with 533 additions and 531 deletions

View File

@ -10,9 +10,9 @@ struct Application_Links;
#define GET_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, Buffer_ID buffer_id, 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 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, int32_t start, int32_t end, char *out) #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, size_t start, size_t end, char *str, size_t len) #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_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_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_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) #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)
@ -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 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 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 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_ALLOCATE_SIG(n) void* n(Application_Links *app, int32_t size)
#define MEMORY_SET_PROTECTION_SIG(n) bool32 n(Application_Links *app, void *ptr, size_t size, Memory_Protect_Flags flags) #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, size_t size) #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 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 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) #define GET_4ED_PATH_SIG(n) int32_t n(Application_Links *app, char *out, int32_t capacity)
@ -378,9 +378,9 @@ static inline void get_buffer_next(Application_Links *app, Buffer_Summary *buffe
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(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 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, int32_t start, int32_t end, char *out){return(app->buffer_read_range(app, buffer, start, end, out));} 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, 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_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_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 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_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));} 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));}
@ -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 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 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 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 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, size_t size, Memory_Protect_Flags flags){return(app->memory_set_protection(app, ptr, size, flags));} 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, size_t size){(app->memory_free(app, ptr, size));} 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 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 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));} static inline int32_t get_4ed_path(Application_Links *app, char *out, int32_t capacity){return(app->get_4ed_path(app, out, capacity));}
@ -450,9 +450,9 @@ static inline void get_buffer_next(Application_Links *app, Buffer_Summary *buffe
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(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 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, int32_t start, int32_t end, char *out){return(app->buffer_read_range_(app, buffer, start, end, out));} 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, 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_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_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 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_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));} 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));}
@ -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 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 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 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 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, size_t size, Memory_Protect_Flags flags){return(app->memory_set_protection_(app, ptr, size, flags));} 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, size_t size){(app->memory_free_(app, ptr, size));} 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 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 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));} static inline int32_t get_4ed_path(Application_Links *app, char *out, int32_t capacity){return(app->get_4ed_path_(app, out, capacity));}

View File

@ -494,7 +494,7 @@ STRUCT Buffer_Seek{
UNION{ UNION{
STRUCT { STRUCT {
/* DOC(The pos field specified the pos when the seek is in absolute position.) */ /* DOC(The pos field specified the pos when the seek is in absolute position.) */
size_t pos; int32_t pos;
}; };
STRUCT { 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.) */ /* 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.) */
@ -506,9 +506,9 @@ STRUCT Buffer_Seek{
}; };
STRUCT { STRUCT {
/* DOC(The line number of a line-character type seek.) */ /* 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.) */ /* DOC(The character number of a line-character type seek.) */
size_t character; int32_t character;
}; };
}; };
}; };
@ -517,15 +517,15 @@ STRUCT Buffer_Seek{
DOC_SEE(4coder_Buffer_Positioning_System) */ DOC_SEE(4coder_Buffer_Positioning_System) */
STRUCT Full_Cursor{ STRUCT Full_Cursor{
/* DOC(This field contains the cursor's position in absolute byte index positioning.) */ /* 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.) */ /* 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.) */ /* 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.) */ /* 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.) */ /* 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.) */ /* DOC(This field contains the x position measured with unwrapped lines.) */
float unwrapped_x; float unwrapped_x;
/* DOC(This field contains the y position measured with unwrapped lines.) */ /* DOC(This field contains the y position measured with unwrapped lines.) */
@ -540,24 +540,24 @@ STRUCT Full_Cursor{
DOC_SEE(4coder_Buffer_Positioning_System) */ DOC_SEE(4coder_Buffer_Positioning_System) */
STRUCT Partial_Cursor{ STRUCT Partial_Cursor{
/* DOC(This field contains the cursor's position in absolute byte index positioning.) */ /* 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 /* 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.) */ 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.) */ /* 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.) */ /* 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{ STRUCT Buffer_Edit{
/* DOC(The str_start field specifies the first character in the accompanying string that corresponds with this 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.) */ /* 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.) */ /* 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.) */ /* 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.) /* DOC(Buffer_Summary acts as a handle to a buffer and describes the state of the buffer.)
@ -635,15 +635,6 @@ STRUCT i32_Rect{
GLOBAL_VAR i32_Rect null_i32_rect = {0}; 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{ STRUCT f32_Rect{
float x0; float x0;
float y0; float y0;

View File

@ -323,7 +323,7 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b
line_index = line_start; line_index = line_start;
} }
uint32_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){ switch (token_ptr->type){
case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += tab_width; break; case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += tab_width; break;
@ -353,8 +353,8 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b
{ {
int32_t previous_indent = indent.previous_line_indent; int32_t previous_indent = indent.previous_line_indent;
uint32_t this_line_start = buffer_get_line_start(app, buffer, line_index); int32_t this_line_start = buffer_get_line_start(app, buffer, line_index);
uint32_t next_line_start = buffer_get_line_start(app, buffer, line_index+1); int32_t next_line_start = buffer_get_line_start(app, buffer, line_index+1);
bool32 did_special_behavior = false; bool32 did_special_behavior = false;
@ -523,9 +523,9 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cp
int32_t line_end = buffer_get_line_index(app, buffer, end_pos); int32_t line_end = buffer_get_line_index(app, buffer, end_pos);
for (;line_start > 0;){ for (;line_start > 0;){
uint32_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); 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); line_start = buffer_get_line_index(app, buffer, token->start);
} }
else{ else{
@ -534,7 +534,7 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cp
} }
for (;line_end+1 < buffer->line_count;){ for (;line_end+1 < buffer->line_count;){
uint32_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); 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){ if (token && token->start < next_line_start_pos){
line_end = buffer_get_line_index(app, buffer, token->start+token->size); line_end = buffer_get_line_index(app, buffer, token->start+token->size);

View File

@ -322,16 +322,16 @@ struct Config_Item{
struct Config_Array_Reader{ struct Config_Array_Reader{
Cpp_Token_Array array; Cpp_Token_Array array;
char *mem; char *mem;
uint32_t i; int32_t i;
uint32_t val_array_end; int32_t val_array_end;
bool32 good; bool32 good;
}; };
static Cpp_Token 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}; Cpp_Token token = {0};
uint32_t i = *i_ptr; int32_t i = *i_ptr;
for (; i < array.count; ++i){ for (; i < array.count; ++i){
Cpp_Token comment_token = array.tokens[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 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}; Config_Line config_line = {0};
uint32_t i = *i_ptr; int32_t i = *i_ptr;
config_line.id_token = read_config_token(array, &i); config_line.id_token = read_config_token(array, &i);
if (config_line.id_token.type == CPP_TOKEN_IDENTIFIER){ 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_wrap_width = default_wrap_width;
int32_t new_min_base_width = default_min_base_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); Config_Line config_line = read_config_line(array, &i);
if (config_line.read_success){ if (config_line.read_success){

View File

@ -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_ = partition_sub_part(part, (4<<10));
Partition *extra_memory = &extra_memory_; Partition *extra_memory = &extra_memory_;
char *str = (char*)partition_current(part); char *str = (char*)partition_current(part);
size_t part_size = 0; int32_t part_size = 0;
size_t size = 0; int32_t size = 0;
static const int32_t token_chunk_size = 512; static const int32_t token_chunk_size = 512;
Cpp_Token token_chunk[token_chunk_size]; 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){ if (delete_space_before){
size_t pos = extra_memory->pos - 1; int32_t pos = extra_memory->pos - 1;
char *base = ((char*)(extra_memory->base)); char *base = ((char*)(extra_memory->base));
if (pos >= 0 && base[pos] == ' '){ if (pos >= 0 && base[pos] == ' '){
extra_memory->pos = pos; extra_memory->pos = pos;
@ -242,13 +242,13 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff
finish_print:; finish_print:;
{ {
size_t sig_size = extra_memory->pos; int32_t sig_size = extra_memory->pos;
String sig = make_string(extra_memory->base, (int32_t)sig_size); String sig = make_string(extra_memory->base, sig_size);
int32_t line_number = buffer_get_line_index(app, buffer, open_paren_pos); int32_t line_number = buffer_get_line_index(app, buffer, open_paren_pos);
int32_t line_number_len = int_to_str_size(line_number); 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); char *out_space = push_array(part, char, append_len);
if (out_space == 0){ if (out_space == 0){
@ -263,7 +263,7 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff
} }
part_size += append_len; 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, buffer_name);
append(&out, ':'); append(&out, ':');
append_int_to_str(&out, line_number); append_int_to_str(&out, line_number);

View File

@ -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. // TODO(allen): Setup buffer seeking to do character_pos and get View_Summary out of this parameter list.
static size_t static int32_t
character_pos_to_pos(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, size_t character_pos){ character_pos_to_pos(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, int32_t character_pos){
size_t result = 0; int32_t result = 0;
Full_Cursor cursor = {0}; Full_Cursor cursor = {0};
if (view_compute_cursor(app, view, seek_character_pos(character_pos), &cursor)){ if (view_compute_cursor(app, view, seek_character_pos(character_pos), &cursor)){
result = cursor.pos; result = cursor.pos;
@ -223,8 +223,8 @@ character_pos_to_pos(Application_Links *app, View_Summary *view, Buffer_Summary
} }
struct Buffer_Rect{ struct Buffer_Rect{
size_t char0, line0; int32_t char0, line0;
size_t char1, line1; int32_t char1, line1;
}; };
#ifndef Swap #ifndef Swap
@ -242,26 +242,26 @@ get_rect(View_Summary *view){
rect.line1 = view->cursor.line; rect.line1 = view->cursor.line;
if (rect.line0 > rect.line1){ if (rect.line0 > rect.line1){
Swap(size_t, rect.line0, rect.line1); Swap(int32_t, rect.line0, rect.line1);
} }
if (rect.char0 > rect.char1){ if (rect.char0 > rect.char1){
Swap(size_t, rect.char0, rect.char1); Swap(int32_t, rect.char0, rect.char1);
} }
return(rect); return(rect);
} }
static pos_Rect static i32_Rect
get_line_x_rect(View_Summary *view){ get_line_x_rect(View_Summary *view){
pos_Rect rect = {0}; i32_Rect rect = {0};
if (view->unwrapped_lines){ if (view->unwrapped_lines){
rect.x0 = (size_t)view->mark.unwrapped_x; rect.x0 = (int32_t)view->mark.unwrapped_x;
rect.x1 = (size_t)view->cursor.unwrapped_x; rect.x1 = (int32_t)view->cursor.unwrapped_x;
} }
else{ else{
rect.x0 = (size_t)view->mark.wrapped_x; rect.x0 = (int32_t)view->mark.wrapped_x;
rect.x1 = (size_t)view->cursor.wrapped_x; rect.x1 = (int32_t)view->cursor.wrapped_x;
} }
rect.y0 = view->mark.line; rect.y0 = view->mark.line;
rect.y1 = view->cursor.line; rect.y1 = view->cursor.line;

View File

@ -464,7 +464,7 @@ buffer_seek_alphanumeric_or_camel_left(Application_Links *app, Buffer_Summary *b
} }
static int32_t static int32_t
seek_token_left(Cpp_Token_Array *tokens, uint32_t pos){ seek_token_left(Cpp_Token_Array *tokens, int32_t pos){
Cpp_Get_Token_Result get = cpp_get_token(*tokens, pos); Cpp_Get_Token_Result get = cpp_get_token(*tokens, pos);
if (get.token_index == -1){ if (get.token_index == -1){
get.token_index = 0; get.token_index = 0;
@ -479,18 +479,16 @@ seek_token_left(Cpp_Token_Array *tokens, uint32_t pos){
} }
static int32_t static int32_t
seek_token_right(Cpp_Token_Array *tokens, uint32_t pos){ seek_token_right(Cpp_Token_Array *tokens, int32_t pos){
Cpp_Get_Token_Result get = cpp_get_token(*tokens, pos); Cpp_Get_Token_Result get = cpp_get_token(*tokens, pos);
if (get.in_whitespace){ if (get.in_whitespace){
++get.token_index; ++get.token_index;
} }
uint32_t target_token_index = (uint32_t)(get.token_index); if (get.token_index >= tokens->count){
get.token_index = tokens->count-1;
if (target_token_index >= tokens->count){
target_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); return(token->start + token->size);
} }
@ -968,22 +966,21 @@ buffer_get_line_index(Application_Links *app, Buffer_Summary *buffer, int32_t po
} }
static Cpp_Token* static Cpp_Token*
get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line, uint32_t *line_start_out = 0){ 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); int32_t line_start = buffer_get_line_start(app, buffer, line);
Cpp_Get_Token_Result get = cpp_get_token(tokens, line_start); Cpp_Get_Token_Result get_token = cpp_get_token(tokens, line_start);
if (get.in_whitespace){ if (get_token.in_whitespace){
get.token_index += 1; get_token.token_index += 1;
} }
uint32_t target_token_index = (uint32_t)(get.token_index);
if (line_start_out){ if (line_start_out){
*line_start_out = line_start; *line_start_out = line_start;
} }
Cpp_Token *result = 0; Cpp_Token *result = 0;
if (target_token_index < tokens.count){ if (get_token.token_index < tokens.count){
result = tokens.tokens + target_token_index; result = tokens.tokens + get_token.token_index;
} }
return(result); return(result);

View File

@ -13,7 +13,7 @@
#define FRED_BUFFER_TYPES_H #define FRED_BUFFER_TYPES_H
static Buffer_Seek static Buffer_Seek
seek_pos(size_t pos){ seek_pos(int32_t pos){
Buffer_Seek result; Buffer_Seek result;
result.type = buffer_seek_pos; result.type = buffer_seek_pos;
result.pos = pos; result.pos = pos;
@ -21,7 +21,7 @@ seek_pos(size_t pos){
} }
static Buffer_Seek static Buffer_Seek
seek_character_pos(size_t pos){ seek_character_pos(int32_t pos){
Buffer_Seek result; Buffer_Seek result;
result.type = buffer_seek_character_pos; result.type = buffer_seek_character_pos;
result.pos = pos; result.pos = pos;
@ -29,7 +29,7 @@ seek_character_pos(size_t pos){
} }
static Buffer_Seek 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; Buffer_Seek result;
result.type = buffer_seek_wrapped_xy; result.type = buffer_seek_wrapped_xy;
result.x = x; result.x = x;
@ -39,7 +39,7 @@ seek_wrapped_xy(float x, float y, bool32 round_down){
} }
static Buffer_Seek 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; Buffer_Seek result;
result.type = buffer_seek_unwrapped_xy; result.type = buffer_seek_unwrapped_xy;
result.x = x; result.x = x;
@ -59,7 +59,7 @@ seek_xy(float x, float y, bool32 round_down, bool32 unwrapped){
} }
static Buffer_Seek static Buffer_Seek
seek_line_char(size_t line, size_t character){ seek_line_char(int32_t line, int32_t character){
Buffer_Seek result; Buffer_Seek result;
result.type = buffer_seek_line_char; result.type = buffer_seek_line_char;
result.line = line; result.line = line;

View File

@ -44,23 +44,23 @@ typedef int32_t b32_4tech;
struct Partition{ struct Partition{
char *base; char *base;
umem_4tech pos; i32_4tech pos;
umem_4tech max; i32_4tech max;
}; };
struct Temp_Memory{ struct Temp_Memory{
void *handle; void *handle;
umem_4tech pos; i32_4tech pos;
}; };
struct Tail_Temp_Partition{ struct Tail_Temp_Partition{
Partition part; Partition part;
void *handle; void *handle;
umem_4tech old_max; i32_4tech old_max;
}; };
inline Partition inline Partition
make_part(void *memory, umem_4tech size){ make_part(void *memory, i32_4tech size){
Partition partition; Partition partition;
partition.base = (char*)memory; partition.base = (char*)memory;
partition.pos = 0; partition.pos = 0;
@ -69,7 +69,7 @@ make_part(void *memory, umem_4tech size){
} }
inline void* inline void*
partition_allocate(Partition *data, umem_4tech size){ partition_allocate(Partition *data, i32_4tech size){
void *ret = 0; void *ret = 0;
if (size > 0 && data->pos + size <= data->max){ if (size > 0 && data->pos + size <= data->max){
ret = data->base + data->pos; ret = data->base + data->pos;
@ -79,7 +79,7 @@ partition_allocate(Partition *data, umem_4tech size){
} }
inline void inline void
partition_align(Partition *data, umem_4tech boundary){ partition_align(Partition *data, u32_4tech boundary){
--boundary; --boundary;
data->pos = (data->pos + boundary) & (~boundary); data->pos = (data->pos + boundary) & (~boundary);
} }
@ -89,7 +89,7 @@ partition_current(Partition *data){
return(data->base + data->pos); return(data->base + data->pos);
} }
inline umem_4tech inline i32_4tech
partition_remaining(Partition *data){ partition_remaining(Partition *data){
return(data->max - data->pos); return(data->max - data->pos);
} }
@ -122,7 +122,7 @@ end_temp_memory(Temp_Memory temp){
} }
inline Tail_Temp_Partition 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}; Tail_Temp_Partition result = {0};
if (data->pos + size <= data->max){ if (data->pos + size <= data->max){
result.handle = data; result.handle = data;

View File

@ -50,7 +50,7 @@ static void
close_all_files_with_extension(Application_Links *app, Partition *scratch_part, char **extension_list, int32_t extension_count){ 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); 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 = push_array(scratch_part, int32_t, buffers_to_close_max);
int32_t buffers_to_close_count = 0; int32_t buffers_to_close_count = 0;
@ -225,7 +225,7 @@ CUSTOM_COMMAND_SIG(load_project){
} }
// Read the settings from project.4coder // 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); Config_Line config_line = read_config_line(array, &i);
if (config_line.read_success){ if (config_line.read_success){
Config_Item item = get_config_item(config_line, mem, array); Config_Item item = get_config_item(config_line, mem, array);

View File

@ -42,9 +42,6 @@ typedef int32_t b32_4tech;
#endif #endif
// standard preamble end // standard preamble end
#include "4cpp_lexer_types.h"
#include "4cpp_lexer_tables.c"
// duff-routine defines // duff-routine defines
#define DfrCase(PC) case PC: goto resumespot_##PC #define DfrCase(PC) case PC: goto resumespot_##PC
#define DfrYield(PC, n) { *S_ptr = S; S_ptr->__pc__ = PC; return(n); 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 # define FCPP_LINK static
#endif #endif
#include "4cpp_lexer_types.h"
#include "4cpp_lexer_tables.c"
// TODO(allen): revisit this keyword data declaration system // TODO(allen): revisit this keyword data declaration system
struct String_And_Flag{ struct String_And_Flag{
char *str; char *str;
@ -191,7 +191,7 @@ static String_And_Flag keywords[] = {
static i32_4tech keywords_count = sizeof(keywords)/sizeof(keywords[0]); static i32_4tech keywords_count = sizeof(keywords)/sizeof(keywords[0]);
API_EXPORT FCPP_LINK Cpp_Get_Token_Result API_EXPORT FCPP_LINK Cpp_Get_Token_Result
cpp_get_token(Cpp_Token_Array array, u32_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(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_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.) 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 first = 0;
i32_4tech count = array.count; i32_4tech count = array.count;
i32_4tech last = count; i32_4tech last = count;
i32_4tech this_start = 0, next_start = 0;
if (count > 0){ if (count > 0){
for (;;){ for (;;){
result.token_index = (first + last)/2; result.token_index = (first + last)/2;
token = token_array + result.token_index; token = token_array + result.token_index;
u32_4tech this_start = token->start; this_start = token->start;
u32_4tech next_start = 0;
if (result.token_index + 1 < count){ if (result.token_index + 1 < count){
next_start = (token + 1)->start; next_start = (token + 1)->start;
@ -221,7 +221,6 @@ DOC_SEE(Cpp_Get_Token_Result)
else{ else{
next_start = this_start + token->size; next_start = this_start + token->size;
} }
if (this_start <= pos && pos < next_start){ if (this_start <= pos && pos < next_start){
break; break;
} }
@ -231,7 +230,6 @@ DOC_SEE(Cpp_Get_Token_Result)
else{ else{
first = result.token_index + 1; first = result.token_index + 1;
} }
if (first == last){ if (first == last){
result.token_index = first; result.token_index = first;
break; break;
@ -309,7 +307,7 @@ cpp_pp_directive_to_state(Cpp_Token_Type type){
} }
FCPP_LINK b32_4tech 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; b32_4tech result = false;
if (a_len == b_len){ if (a_len == b_len){
char *a_end = a + a_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 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; b32_4tech result = false;
String_And_Flag *entry = table; String_And_Flag *entry = table;
*index_out = -1; *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 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_Lex_Data S = *S_ptr;
Cpp_Token *out_tokens = token_array_out->tokens; 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; u8_4tech c = 0;
u32_4tech end_pos = size + S.chunk_pos; i32_4tech end_pos = size + S.chunk_pos;
chunk -= S.chunk_pos; chunk -= S.chunk_pos;
switch (S.__pc__){ 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 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_Token_Array *token_array_out){
Cpp_Lex_Result result = 0; Cpp_Lex_Result result = 0;
if (S_ptr->pos >= full_size){ 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 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; Cpp_Token result;
if (index < array->count){ if (index < array->count){
result = array->tokens[index]; 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 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(array, A pointer to the token array that will be modified by the relex,
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.) this array should already contain the tokens for the previous state of the file.)
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(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_Relex_Range range = {0};
Cpp_Get_Token_Result get_result = {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 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(array, A pointer to the token array that will be modified by the relex,
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.) this array should already contain the tokens for the previous state of the file.)
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(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_PARAM(character_shift_amount, The shift in the characters after the edited region.)
DOC_RETURN(Returns a partially initialized relex state.) 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_declare_first_chunk_position)
DOC_SEE(cpp_relex_is_start_chunk) DOC_SEE(cpp_relex_is_start_chunk)
*/{ */{
Cpp_Relex_Data state = {0}; Cpp_Relex_Data state = {0};
@ -1524,7 +1536,7 @@ DOC_SEE(cpp_make_token_array)
} }
API_EXPORT FCPP_LINK void 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(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 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.) than the current size of the array the operation is ignored.)

View File

@ -1,7 +1,7 @@
// TOP // TOP
#if !defined(FCPP_LEXER_TYPES_INC) #ifndef FCPP_LEXER_TYPES_INC
#define FCPP_LEXER_TYPES_INC #define FCPP_LEXER_TYPES_INC
#ifndef ENUM #ifndef ENUM
@ -237,10 +237,10 @@ STRUCT Cpp_Token{
Cpp_Token_Type type; Cpp_Token_Type type;
/* DOC(The start field indicates the index of the first character of this token's lexeme.) */ /* 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.) */ /* 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.) */ /* DOC(The state_flags should not be used outside of the lexer's implementation.) */
uint16_t state_flags; uint16_t state_flags;
@ -273,10 +273,10 @@ STRUCT Cpp_Token_Array{
Cpp_Token *tokens; Cpp_Token *tokens;
/* DOC(The count field counts how many tokens in the array are currently used.) */ /* 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.) */ /* 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}; static Cpp_Token_Array null_cpp_token_array = {0};
@ -288,13 +288,13 @@ STRUCT Cpp_Get_Token_Result{
int32_t token_index; int32_t token_index;
/* DOC(The in_whitespace field is true when the query position was actually in whitespace after the result token.) */ /* 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.) */ /* 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.) */ /* 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.) /* 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() */ HIDE_MEMBERS() */
STRUCT Cpp_Lex_Data{ STRUCT Cpp_Lex_Data{
char tb[32]; char tb[32];
uint32_t tb_pos; int32_t tb_pos;
uint32_t token_start; int32_t token_start;
uint32_t pos; int32_t pos;
uint32_t pos_overide; int32_t pos_overide;
uint32_t chunk_pos; int32_t chunk_pos;
Cpp_Lex_FSM fsm; Cpp_Lex_FSM fsm;
uint8_t white_done; uint8_t white_done;
@ -361,10 +361,10 @@ STRUCT Cpp_Relex_Data{
Cpp_Token end_token; Cpp_Token end_token;
uint32_t relex_start_position; int32_t relex_start_position;
uint32_t start_token_index; int32_t start_token_index;
uint32_t end_token_index; int32_t end_token_index;
uint32_t original_end_token_index; int32_t original_end_token_index;
int32_t character_shift_amount; int32_t character_shift_amount;

View File

@ -585,7 +585,7 @@ DOC_SEE(4coder_Buffer_Positioning_System)
} }
API_EXPORT bool32 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(buffer, This parameter specifies the buffer to edit.)
DOC_PARAM(start, This parameter specifies absolute position of the first character in the replace range.) DOC_PARAM(start, This parameter specifies absolute position of the first character in the replace range.)
@ -656,7 +656,7 @@ DOC_SEE(Partial_Cursor)
} }
API_EXPORT bool32 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(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.) DOC_PARAM(str, This parameter provides all of the source string for the edits in the batch.)
@ -2287,7 +2287,7 @@ DOC(This is a temporary ad-hoc solution to allow some customization of the behav
} }
API_EXPORT void* 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_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.) 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.)
@ -2300,7 +2300,7 @@ DOC_SEE(memory_free)
} }
API_EXPORT bool32 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(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.) DOC_PARAM(size, The size that was originally used to allocate this block.)
@ -2316,7 +2316,7 @@ DOC_SEE(Memory_Protect_Flags)
} }
API_EXPORT void 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(mem, The base of a block to free.)
DOC_PARAM(size, The size that was originally used to allocate this block.) DOC_PARAM(size, The size that was originally used to allocate this block.)

View File

@ -188,9 +188,9 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count,
////////////////////////////////////// //////////////////////////////////////
internal umem internal i32
eol_convert_in(char *dest, char *src, umem size){ eol_convert_in(char *dest, char *src, i32 size){
umem i = 0, j = 0, k = 0; i32 i = 0, j = 0, k = 0;
for (; j < size && src[j] != '\r'; ++j); for (; j < size && src[j] != '\r'; ++j);
memcpy(dest, src, j); memcpy(dest, src, j);
@ -212,9 +212,9 @@ eol_convert_in(char *dest, char *src, umem size){
return(j); return(j);
} }
internal umem internal i32
eol_in_place_convert_in(char *data, umem size){ eol_in_place_convert_in(char *data, i32 size){
umem i = 0, j = 0, k = 0; i32 i = 0, j = 0, k = 0;
for (; j < size && data[j] != '\r'; ++j); for (; j < size && data[j] != '\r'; ++j);
@ -236,10 +236,10 @@ eol_in_place_convert_in(char *data, umem size){
} }
// TODO(allen): iterative memory check? // TODO(allen): iterative memory check?
internal b32 internal i32
eol_convert_out(char *dest, umem max, char *src, umem size, umem *size_out){ eol_convert_out(char *dest, i32 max, char *src, i32 size, i32 *size_out){
b32 result = true; i32 result = 1;
umem i = 0, j = 0; i32 i = 0, j = 0;
for (; i < size; ++i, ++j){ for (; i < size; ++i, ++j){
if (src[i] == '\n'){ if (src[i] == '\n'){
@ -247,9 +247,7 @@ eol_convert_out(char *dest, umem max, char *src, umem size, umem *size_out){
++j; ++j;
dest[j] = '\n'; dest[j] = '\n';
} }
else{ else dest[j] = src[i];
dest[j] = src[i];
}
} }
*size_out = j; *size_out = j;
@ -257,10 +255,10 @@ eol_convert_out(char *dest, umem max, char *src, umem size, umem *size_out){
} }
// TODO(allen): iterative memory check? // TODO(allen): iterative memory check?
internal b32 internal i32
eol_in_place_convert_out(char *data, umem size, umem max, umem *size_out){ eol_in_place_convert_out(char *data, i32 size, i32 max, i32 *size_out){
b32 result = true; i32 result = 1;
umem i = 0; i32 i = 0;
for (; i < size; ++i){ for (; i < size; ++i){
if (data[i] == '\n'){ if (data[i] == '\n'){
@ -283,32 +281,32 @@ eol_in_place_convert_out(char *data, umem size, umem max, umem *size_out){
typedef struct Gap_Buffer{ typedef struct Gap_Buffer{
char *data; char *data;
umem size1; i32 size1;
umem gap_size; i32 gap_size;
umem size2; i32 size2;
umem max; i32 max;
umem *line_starts; i32 *line_starts;
umem line_count; i32 line_count;
umem line_max; i32 line_max;
} Gap_Buffer; } Gap_Buffer;
inline b32 inline i32
buffer_good(Gap_Buffer *buffer){ buffer_good(Gap_Buffer *buffer){
b32 good = (buffer->data != 0); i32 good = (buffer->data != 0);
return(good); return(good);
} }
inline umem inline i32
buffer_size(Gap_Buffer *buffer){ buffer_size(Gap_Buffer *buffer){
umem size = buffer->size1 + buffer->size2; i32 size = buffer->size1 + buffer->size2;
return(size); return(size);
} }
typedef struct Gap_Buffer_Init{ typedef struct Gap_Buffer_Init{
Gap_Buffer *buffer; Gap_Buffer *buffer;
char *data; char *data;
umem size; i32 size;
} Gap_Buffer_Init; } Gap_Buffer_Init;
internal Gap_Buffer_Init internal Gap_Buffer_Init
@ -320,18 +318,16 @@ buffer_begin_init(Gap_Buffer *buffer, char *data, i32 size){
return(init); return(init);
} }
internal b32 internal i32
buffer_init_need_more(Gap_Buffer_Init *init){ buffer_init_need_more(Gap_Buffer_Init *init){
b32 result = true; i32 result = 1;
if (init->buffer->data){ if (init->buffer->data) result = 0;
result = false;
}
return(result); return(result);
} }
internal umem internal i32
buffer_init_page_size(Gap_Buffer_Init *init){ buffer_init_page_size(Gap_Buffer_Init *init){
umem result = init->size * 2; i32 result = init->size * 2;
return(result); return(result);
} }
@ -343,15 +339,15 @@ buffer_init_provide_page(Gap_Buffer_Init *init, void *page, i32 page_size){
} }
internal b32 internal b32
buffer_end_init(Gap_Buffer_Init *init, void *scratch, umem scratch_size){ buffer_end_init(Gap_Buffer_Init *init, void *scratch, i32 scratch_size){
Gap_Buffer *buffer = init->buffer; Gap_Buffer *buffer = init->buffer;
b32 result = false; b32 result = false;
if (buffer->data && buffer->max >= init->size){ if (buffer->data && buffer->max >= init->size){
umem size = init->size; i32 size = init->size;
umem size2 = size*2; i32 size2 = size >> 1;
umem osize1 = size - size2; i32 osize1 = size - size2;
umem size1 = osize1; i32 size1 = osize1;
if (size1 > 0){ if (size1 > 0){
size1 = eol_convert_in(buffer->data, init->data, size1); size1 = eol_convert_in(buffer->data, init->data, size1);
@ -374,17 +370,18 @@ buffer_end_init(Gap_Buffer_Init *init, void *scratch, umem scratch_size){
typedef struct Gap_Buffer_Stream{ typedef struct Gap_Buffer_Stream{
Gap_Buffer *buffer; Gap_Buffer *buffer;
char *data; char *data;
umem end; i32 end;
umem absolute_end; i32 separated;
b32 separated; i32 absolute_end;
b32 use_termination_character; b32 use_termination_character;
char terminator; char terminator;
} Gap_Buffer_Stream; } Gap_Buffer_Stream;
static Gap_Buffer_Stream null_buffer_stream = {0}; static Gap_Buffer_Stream null_buffer_stream = {0};
internal b32 internal b32
buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, umem start, umem end){ buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, i32 start, i32 end){
b32 result = false; b32 result = 0;
if (0 <= start && start < end && end <= buffer->size1 + buffer->size2){ if (0 <= start && start < end && end <= buffer->size1 + buffer->size2){
stream->buffer = buffer; stream->buffer = buffer;
@ -392,15 +389,15 @@ buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, umem start,
if (start < buffer->size1){ if (start < buffer->size1){
if (buffer->size1 < end){ if (buffer->size1 < end){
stream->separated = true; stream->separated = 1;
} }
else{ else{
stream->separated = false; stream->separated = 0;
} }
stream->data = buffer->data; stream->data = buffer->data;
} }
else{ else{
stream->separated = false; stream->separated = 0;
stream->data = buffer->data + buffer->gap_size; stream->data = buffer->data + buffer->gap_size;
} }
@ -415,17 +412,17 @@ buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, umem start,
stream->end = stream->absolute_end; stream->end = stream->absolute_end;
} }
result = true; result = 1;
} }
if (!result){ if (result == 0){
if (stream->use_termination_character){ if (stream->use_termination_character){
stream->buffer = buffer; stream->buffer = buffer;
stream->absolute_end = end; stream->absolute_end = end;
stream->use_termination_character = false; stream->use_termination_character = 0;
stream->data = (&stream->terminator) - buffer->size1 - buffer->size2; stream->data = (&stream->terminator) - buffer->size1 - buffer->size2;
stream->end = stream->absolute_end + 1; stream->end = stream->absolute_end + 1;
result = true; result = 1;
} }
} }
@ -434,99 +431,91 @@ buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, umem start,
internal b32 internal b32
buffer_stringify_next(Gap_Buffer_Stream *stream){ buffer_stringify_next(Gap_Buffer_Stream *stream){
b32 result = false; b32 result = 0;
Gap_Buffer *buffer = stream->buffer; Gap_Buffer *buffer = stream->buffer;
if (stream->separated){ if (stream->separated){
stream->data = buffer->data + buffer->gap_size; stream->data = buffer->data + buffer->gap_size;
stream->end = stream->absolute_end; stream->end = stream->absolute_end;
stream->separated = false; stream->separated = 0;
result = true; result = 1;
} }
if (!result){ if (result == 0){
if (stream->use_termination_character){ if (stream->use_termination_character){
stream->use_termination_character = false; stream->use_termination_character = 0;
stream->data = (&stream->terminator) - buffer->size1 - buffer->size2; stream->data = (&stream->terminator) - buffer->size1 - buffer->size2;
stream->end = stream->absolute_end + 1; stream->end = stream->absolute_end + 1;
result = true; result = 1;
} }
} }
return(result); return(result);
} }
internal b32 internal i32
buffer_replace_range(Gap_Buffer *buffer, umem start, umem end, char *str, umem len, i32 *shift_amount, void *scratch, umem scratch_memory, umem *request_amount){ buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len, i32 *shift_amount,
void *scratch, i32 scratch_memory, i32 *request_amount){
char *data = buffer->data; char *data = buffer->data;
umem size = buffer_size(buffer); i32 size = buffer_size(buffer);
b32 result = false; i32 result = 0;
i32 move_size = 0;
assert(0 <= start); assert(0 <= start);
assert(start <= end); assert(start <= end);
assert(end <= size); assert(end <= size);
umem target_length = end - start; *shift_amount = (len - (end - start));
if (*shift_amount + size <= buffer->max){
if (target_length <= max_i32 && len <= max_i32){ if (end < buffer->size1){
if (len >= target_length){ move_size = buffer->size1 - end;
*shift_amount = (i32)(len - target_length); memmove(data + buffer->size1 + buffer->gap_size - move_size, data + end, move_size);
buffer->size1 -= move_size;
buffer->size2 += move_size;
} }
else{ if (start > buffer->size1){
*shift_amount = -(i32)(target_length - len); move_size = start - buffer->size1;
memmove(data + buffer->size1, data + buffer->size1 + buffer->gap_size, move_size);
buffer->size1 += move_size;
buffer->size2 -= move_size;
} }
if (*shift_amount + size <= buffer->max){ memcpy(data + start, str, len);
umem move_size = 0; buffer->size2 = size - end;
if (end < buffer->size1){ buffer->size1 = start + len;
move_size = buffer->size1 - end; buffer->gap_size -= *shift_amount;
memmove(data + buffer->size1 + buffer->gap_size - move_size, data + end, move_size);
buffer->size1 -= move_size; assert(buffer->size1 + buffer->size2 == size + *shift_amount);
buffer->size2 += move_size; assert(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max);
} }
if (start > buffer->size1){ else{
move_size = start - buffer->size1; *request_amount = l_round_up_i32(2*(*shift_amount + size), 4 << 10);
memmove(data + buffer->size1, data + buffer->size1 + buffer->gap_size, move_size); result = 1;
buffer->size1 += move_size;
buffer->size2 -= move_size;
}
memcpy(data + start, str, len);
buffer->size2 = size - end;
buffer->size1 = start + len;
buffer->gap_size -= *shift_amount;
assert(buffer->size1 + buffer->size2 == size + *shift_amount);
assert(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max);
}
else{
*request_amount = l_round_up_umem(2*(*shift_amount + size), KB(4));
result = true;
}
} }
return(result); return(result);
} }
typedef struct Buffer_Batch_State{ typedef struct Buffer_Batch_State{
umem i; i32 i;
i32 shift_total; i32 shift_total;
} Buffer_Batch_State; } Buffer_Batch_State;
// TODO(allen): Now that we are just using Gap_Buffer we could afford to improve this for the Gap_Buffer's behavior. // TODO(allen): Now that we are just using Gap_Buffer we could afford to improve
internal b32 // this for the Gap_Buffer's behavior.
buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, char *strings, u32 edit_count, void *scratch, umem scratch_size, umem *request_amount){ internal i32
buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, char *strings, i32 edit_count, void *scratch, i32 scratch_size, i32 *request_amount){
Buffer_Edit *edit = 0; Buffer_Edit *edit = 0;
umem i = state->i; i32 i = state->i;
i32 shift_total = state->shift_total; i32 shift_total = state->shift_total;
i32 shift_amount = 0; i32 shift_amount = 0;
b32 result = false; i32 result = 0;
edit = sorted_edits + i; edit = sorted_edits + i;
for (; i < edit_count; ++i, ++edit){ for (; i < edit_count; ++i, ++edit){
result = buffer_replace_range(buffer, edit->start + shift_total, edit->end + shift_total, strings + edit->str_start, edit->len, &shift_amount, scratch, scratch_size, request_amount); result = buffer_replace_range(buffer, edit->start + shift_total, edit->end + shift_total,
if (result){ strings + edit->str_start, edit->len, &shift_amount,
break; scratch, scratch_size, request_amount);
} if (result) break;
shift_total += shift_amount; shift_total += shift_amount;
} }
@ -537,10 +526,10 @@ buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edi
} }
internal void* internal void*
buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, umem new_max){ buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, i32 new_max){
void *result = buffer->data; void *result = buffer->data;
umem size = buffer_size(buffer); i32 size = buffer_size(buffer);
umem new_gap_size = new_max - size; i32 new_gap_size = new_max - size;
assert(new_max >= size); assert(new_max >= size);
@ -559,14 +548,14 @@ buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, umem new_max){
// //
inline void inline void
buffer_stringify(Gap_Buffer *buffer, umem start, umem end, char *out){ buffer_stringify(Gap_Buffer *buffer, i32 start, i32 end, char *out){
Gap_Buffer_Stream stream = {0}; Gap_Buffer_Stream stream = {0};
umem i = start; i32 i = start;
if (buffer_stringify_loop(&stream, buffer, i, end)){ if (buffer_stringify_loop(&stream, buffer, i, end)){
b32 still_looping = false; b32 still_looping = 0;
do{ do{
umem size = stream.end - i; i32 size = stream.end - i;
memcpy(out, stream.data + i, size); memcpy(out, stream.data + i, size);
i = stream.end; i = stream.end;
out += size; out += size;
@ -575,19 +564,19 @@ buffer_stringify(Gap_Buffer *buffer, umem start, umem end, char *out){
} }
} }
internal umem internal i32
buffer_convert_out(Gap_Buffer *buffer, char *dest, umem max){ buffer_convert_out(Gap_Buffer *buffer, char *dest, i32 max){
Gap_Buffer_Stream stream = {0}; Gap_Buffer_Stream stream = {0};
umem size = buffer_size(buffer); i32 i = 0;
i32 size = buffer_size(buffer);
assert(size + buffer->line_count <= max); assert(size + buffer->line_count <= max);
umem pos = 0; i32 pos = 0;
if (buffer_stringify_loop(&stream, buffer, 0, size)){ if (buffer_stringify_loop(&stream, buffer, 0, size)){
umem i = 0; b32 still_looping = 0;
b32 still_looping = false;
do{ do{
umem chunk_size = stream.end - i; i32 chunk_size = stream.end - i;
umem out_size = 0; i32 out_size = 0;
i32 result = eol_convert_out(dest + pos, max - pos, stream.data + i, chunk_size, &out_size); i32 result = eol_convert_out(dest + pos, max - pos, stream.data + i, chunk_size, &out_size);
assert(result); assert(result);
i = stream.end; i = stream.end;
@ -623,22 +612,22 @@ buffer_count_newlines(Gap_Buffer *buffer, i32 start, i32 end){
} }
typedef struct Buffer_Measure_Starts{ typedef struct Buffer_Measure_Starts{
umem i; i32 i;
umem count; i32 count;
umem start; i32 start;
} Buffer_Measure_Starts; } Buffer_Measure_Starts;
// TODO(allen): Rewrite this with a duff routine // TODO(allen): Rewrite this with a duff routine
// Also make it so that the array goes one past the end // Also make it so that the array goes one past the end
// and stores the size in the extra spot. // and stores the size in the extra spot.
internal b32 internal i32
buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){ buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){
Gap_Buffer_Stream stream = {0}; Gap_Buffer_Stream stream = {0};
umem size = buffer_size(buffer); i32 size = buffer_size(buffer);
umem start = state->start, i = state->i; i32 start = state->start, i = state->i;
umem *start_ptr = buffer->line_starts + state->count; i32 *start_ptr = buffer->line_starts + state->count;
umem *start_end = buffer->line_starts + buffer->line_max; i32 *start_end = buffer->line_starts + buffer->line_max;
b32 result = true; i32 result = 1;
if (buffer_stringify_loop(&stream, buffer, i, size)){ if (buffer_stringify_loop(&stream, buffer, i, size)){
b32 still_looping = 0; b32 still_looping = 0;
@ -657,12 +646,14 @@ buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){
still_looping = buffer_stringify_next(&stream); still_looping = buffer_stringify_next(&stream);
}while(still_looping); }while(still_looping);
} }
assert(i == size); assert(i == size);
if (start_ptr == start_end){ if (start_ptr == start_end){
goto buffer_measure_starts_widths_end; goto buffer_measure_starts_widths_end;
} }
*start_ptr++ = start; *start_ptr++ = start;
result = false; result = 0;
buffer_measure_starts_widths_end:; buffer_measure_starts_widths_end:;
state->i = i; state->i = i;
@ -677,19 +668,22 @@ buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){
} }
internal void internal void
buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, umem *character_starts, i32 mode, b32 virtual_white){ buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, i32 *character_starts, i32 mode, i32 virtual_white){
assert(mode == 0); assert(mode == 0);
Gap_Buffer_Stream stream = {0}; Gap_Buffer_Stream stream = {0};
i32 i = 0;
i32 size = buffer_size(buffer);
umem line_index = 0; i32 line_index = 0;
umem character_index = 0; i32 character_index = 0;
b32 skipping_whitespace = 0;
character_starts[line_index++] = character_index; character_starts[line_index++] = character_index;
b32 skipping_whitespace = false;
if (virtual_white){ if (virtual_white){
skipping_whitespace = true; skipping_whitespace = 1;
} }
Translation_State tran = {0}; Translation_State tran = {0};
@ -697,11 +691,8 @@ buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap
stream.use_termination_character = 1; stream.use_termination_character = 1;
stream.terminator = '\n'; stream.terminator = '\n';
umem size = buffer_size(buffer);
umem i = 0;
if (buffer_stringify_loop(&stream, buffer, i, size)){ if (buffer_stringify_loop(&stream, buffer, i, size)){
b32 still_looping = false; b32 still_looping = 0;
do{ do{
for (; i < stream.end; ++i){ for (; i < stream.end; ++i){
u8 ch = (u8)stream.data[i]; u8 ch = (u8)stream.data[i];
@ -715,12 +706,12 @@ buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap
++character_index; ++character_index;
character_starts[line_index++] = character_index; character_starts[line_index++] = character_index;
if (virtual_white){ if (virtual_white){
skipping_whitespace = true; skipping_whitespace = 1;
} }
} }
else if (behavior.do_codepoint_advance || behavior.do_number_advance){ else if (behavior.do_codepoint_advance || behavior.do_number_advance){
if (ch != ' ' && ch != '\t'){ if (ch != ' ' && ch != '\t'){
skipping_whitespace = false; skipping_whitespace = 0;
} }
if (!skipping_whitespace){ if (!skipping_whitespace){
@ -747,8 +738,8 @@ struct Buffer_Layout_Stop{
u32 status; u32 status;
i32 line_index; i32 line_index;
i32 wrap_line_index; i32 wrap_line_index;
umem pos; i32 pos;
umem next_line_pos; i32 next_line_pos;
f32 x; f32 x;
}; };
@ -762,8 +753,8 @@ struct Buffer_Measure_Wrap_Params{
struct Buffer_Measure_Wrap_State{ struct Buffer_Measure_Wrap_State{
Gap_Buffer_Stream stream; Gap_Buffer_Stream stream;
umem i; i32 i;
umem size; i32 size;
b32 still_looping; b32 still_looping;
i32 line_index; i32 line_index;
@ -920,20 +911,20 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para
#undef DrReturn #undef DrReturn
internal void internal void
buffer_remeasure_starts(Gap_Buffer *buffer, umem start_line, umem end_line, i32 line_shift, i32 text_shift){ buffer_remeasure_starts(Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 line_shift, i32 text_shift){
umem *starts = buffer->line_starts; i32 *starts = buffer->line_starts;
umem line_count = buffer->line_count; i32 line_count = buffer->line_count;
assert(0 <= start_line); assert(0 <= line_start);
assert(start_line <= end_line); assert(line_start <= line_end);
assert(end_line < line_count); assert(line_end < line_count);
assert(line_count + line_shift <= buffer->line_max); assert(line_count + line_shift <= buffer->line_max);
++end_line; ++line_end;
// Adjust // Adjust
if (text_shift != 0){ if (text_shift != 0){
umem line_i = end_line; i32 line_i = line_end;
starts += line_i; starts += line_i;
for (; line_i < line_count; ++line_i, ++starts){ for (; line_i < line_count; ++line_i, ++starts){
*starts += text_shift; *starts += text_shift;
@ -942,24 +933,24 @@ buffer_remeasure_starts(Gap_Buffer *buffer, umem start_line, umem end_line, i32
} }
// Shift // Shift
umem new_line_count = line_count; i32 new_line_count = line_count;
umem new_end_line = end_line; i32 new_line_end = line_end;
if (line_shift != 0){ if (line_shift != 0){
new_line_count += line_shift; new_line_count += line_shift;
new_end_line += line_shift; new_line_end += line_shift;
memmove(starts + end_line + line_shift, starts + end_line, memmove(starts + line_end + line_shift, starts + line_end,
sizeof(i32)*(line_count - end_line)); sizeof(i32)*(line_count - line_end));
} }
// Iteration data (yikes! Need better loop system) // Iteration data (yikes! Need better loop system)
Gap_Buffer_Stream stream = {0}; Gap_Buffer_Stream stream = {0};
umem size = buffer_size(buffer); i32 size = buffer_size(buffer);
umem char_i = starts[start_line]; i32 char_i = starts[line_start];
umem line_i = start_line; i32 line_i = line_start;
// Line start measurement // Line start measurement
umem start = char_i; i32 start = char_i;
if (buffer_stringify_loop(&stream, buffer, char_i, size)){ if (buffer_stringify_loop(&stream, buffer, char_i, size)){
b32 still_looping = 0; b32 still_looping = 0;
@ -972,8 +963,9 @@ buffer_remeasure_starts(Gap_Buffer *buffer, umem start_line, umem end_line, i32
++line_i; ++line_i;
start = char_i + 1; start = char_i + 1;
// TODO(allen): I would like to know that I am not guessing here, so let's try to turn the && into an Assert. // TODO(allen): I would like to know that I am not guessing here,
if (line_i >= new_end_line && (line_i >= new_line_count || start == starts[line_i])){ // so let's try to turn the && into an Assert.
if (line_i >= new_line_end && (line_i >= new_line_count || start == starts[line_i])){
goto buffer_remeasure_starts_end; goto buffer_remeasure_starts_end;
} }
} }
@ -993,40 +985,41 @@ buffer_remeasure_starts(Gap_Buffer *buffer, umem start_line, umem end_line, i32
} }
internal void internal void
buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, umem start_line, umem end_line, i32 line_shift, umem *character_starts, i32 mode, b32 virtual_whitespace){ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 line_shift, i32 *character_starts, i32 mode, i32 virtual_whitespace){
assert(mode == 0); assert(mode == 0);
umem new_line_count = buffer->line_count; i32 new_line_count = buffer->line_count;
assert(0 <= start_line); assert(0 <= line_start);
assert(start_line <= end_line); assert(line_start <= line_end);
assert(end_line < new_line_count - line_shift); assert(line_end < new_line_count - line_shift);
++end_line; ++line_end;
// Shift // Shift
umem line_count = new_line_count; i32 line_count = new_line_count;
umem new_end_line = end_line; i32 new_line_end = line_end;
if (line_shift != 0){ if (line_shift != 0){
line_count -= line_shift; line_count -= line_shift;
new_end_line += line_shift; new_line_end += line_shift;
memmove(character_starts + end_line + line_shift, character_starts + end_line, sizeof(i32)*(line_count - end_line + 1)); memmove(character_starts + line_end + line_shift, character_starts + line_end, sizeof(i32)*(line_count - line_end + 1));
} }
// Iteration data // Iteration data
Gap_Buffer_Stream stream = {0}; Gap_Buffer_Stream stream = {0};
umem size = buffer_size(buffer); i32 size = buffer_size(buffer);
umem char_i = buffer->line_starts[start_line]; i32 char_i = buffer->line_starts[line_start];
umem line_i = start_line; i32 line_i = line_start;
// Character measurement // Character measurement
umem last_char_start = character_starts[line_i]; i32 last_char_start = character_starts[line_i];
umem current_char_start = last_char_start; i32 current_char_start = last_char_start;
b32 skipping_whitespace = 0;
b32 skipping_whitespace = false;
if (virtual_whitespace){ if (virtual_whitespace){
skipping_whitespace = true; skipping_whitespace = 1;
} }
// Translation // Translation
@ -1053,7 +1046,7 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G
skipping_whitespace = 1; skipping_whitespace = 1;
} }
if (line_i >= new_end_line){ if (line_i >= new_line_end){
goto buffer_remeasure_character_starts_end; goto buffer_remeasure_character_starts_end;
} }
} }
@ -1071,20 +1064,14 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G
still_looping = buffer_stringify_next(&stream); still_looping = buffer_stringify_next(&stream);
}while(still_looping); }while(still_looping);
} }
assert(line_i >= new_end_line);
assert(line_i >= new_line_end);
buffer_remeasure_character_starts_end:; buffer_remeasure_character_starts_end:;
// Adjust // Adjust
if (line_i <= new_end_line){ if (line_i <= new_line_end){
umem old_value = character_starts[line_i]; i32 character_shift = current_char_start - character_starts[line_i];
umem new_value = current_char_start;
i32 character_shift = 0;
if (new_value > old_value){
character_shift = (i32)(new_value - old_value);
}
else{
character_shift = -(i32)(old_value - new_value);
}
if (character_shift != 0){ if (character_shift != 0){
character_starts += line_i; character_starts += line_i;
@ -1096,30 +1083,31 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G
} }
internal void internal void
buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 line_shift, f32 *wraps, f32 font_height, f32 *adv, f32 max_width){ buffer_remeasure_wrap_y(Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 line_shift,
umem new_line_count = buffer->line_count; f32 *wraps, f32 font_height, f32 *adv, f32 max_width){
i32 new_line_count = buffer->line_count;
assert(0 <= start_line); assert(0 <= line_start);
assert(start_line <= end_line); assert(line_start <= line_end);
assert(end_line < new_line_count - line_shift); assert(line_end < new_line_count - line_shift);
++end_line; ++line_end;
// Shift // Shift
umem line_count = new_line_count; i32 line_count = new_line_count;
umem new_end_line = end_line; i32 new_line_end = line_end;
if (line_shift != 0){ if (line_shift != 0){
line_count -= line_shift; line_count -= line_shift;
new_end_line += line_shift; new_line_end += line_shift;
memmove(wraps + end_line + line_shift, wraps + end_line, sizeof(i32)*(line_count - end_line + 1)); memmove(wraps + line_end + line_shift, wraps + line_end, sizeof(i32)*(line_count - line_end + 1));
} }
// Iteration data (yikes! Need better loop system) // Iteration data (yikes! Need better loop system)
Gap_Buffer_Stream stream = {0}; Gap_Buffer_Stream stream = {0};
umem size = buffer_size(buffer); i32 size = buffer_size(buffer);
umem char_i = buffer->line_starts[start_line]; i32 char_i = buffer->line_starts[line_start];
umem line_i = start_line; i32 line_i = line_start;
// Line wrap measurement // Line wrap measurement
f32 last_wrap = wraps[line_i]; f32 last_wrap = wraps[line_i];
@ -1127,7 +1115,7 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32
f32 x = 0.f; f32 x = 0.f;
if (buffer_stringify_loop(&stream, buffer, char_i, size)){ if (buffer_stringify_loop(&stream, buffer, char_i, size)){
b32 still_looping = false; b32 still_looping = 0;
do{ do{
for (; char_i < stream.end; ++char_i){ for (; char_i < stream.end; ++char_i){
u8 ch = (u8)stream.data[char_i]; u8 ch = (u8)stream.data[char_i];
@ -1140,7 +1128,7 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32
x = 0.f; x = 0.f;
// TODO(allen): I would like to know that I am not guessing here. // TODO(allen): I would like to know that I am not guessing here.
if (line_i >= new_end_line){ if (line_i >= new_line_end){
goto buffer_remeasure_wraps_end; goto buffer_remeasure_wraps_end;
} }
} }
@ -1164,7 +1152,7 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32
buffer_remeasure_wraps_end:; buffer_remeasure_wraps_end:;
// Adjust // Adjust
if (line_i <= new_end_line){ if (line_i <= new_line_end){
f32 y_shift = current_wrap - wraps[line_i]; f32 y_shift = current_wrap - wraps[line_i];
if (y_shift != 0){ if (y_shift != 0){
@ -1176,10 +1164,15 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32
} }
} }
internal umem internal i32
binary_search(umem *array, umem value, umem l_bound, umem u_bound){ binary_search(i32 *array, i32 value, i32 l_bound, i32 u_bound){
value = clamp_bottom(0, value); i32 start = l_bound, end = u_bound;
umem start = l_bound, end = u_bound, i = 0; i32 i = 0;
if (value < 0){
value = 0;
}
for (;;){ for (;;){
i = (start + end) >> 1; i = (start + end) >> 1;
if (array[i] < value){ if (array[i] < value){
@ -1197,48 +1190,54 @@ binary_search(umem *array, umem value, umem l_bound, umem u_bound){
break; break;
} }
} }
return(i); return(i);
} }
inline umem inline i32
buffer_get_line_index_range(Gap_Buffer *buffer, umem pos, umem l_bound, umem u_bound){ buffer_get_line_index_range(Gap_Buffer *buffer, i32 pos, i32 l_bound, i32 u_bound){
assert(0 <= l_bound); assert(0 <= l_bound);
assert(l_bound <= u_bound); assert(l_bound <= u_bound);
assert(u_bound <= buffer->line_count); assert(u_bound <= buffer->line_count);
assert(buffer->line_starts != 0); assert(buffer->line_starts != 0);
umem i = binary_search(buffer->line_starts, pos, l_bound, u_bound); i32 i = binary_search(buffer->line_starts, pos, l_bound, u_bound);
return(i); return(i);
} }
inline umem inline i32
buffer_get_line_index(Gap_Buffer *buffer, umem pos){ buffer_get_line_index(Gap_Buffer *buffer, i32 pos){
umem result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); i32 result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count);
return(result); return(result);
} }
inline umem inline i32
buffer_get_line_index_from_character_pos(umem *character_starts, umem pos, umem l_bound, umem u_bound){ buffer_get_line_index_from_character_pos(i32 *character_starts, i32 pos, i32 l_bound, i32 u_bound){
umem i = binary_search(character_starts, pos, l_bound, u_bound); i32 i = binary_search(character_starts, pos, l_bound, u_bound);
return(i); return(i);
} }
inline umem inline i32
buffer_get_line_index_from_wrapped_y(umem *wrap_line_index, f32 y, umem line_height, umem l_bound, umem u_bound){ buffer_get_line_index_from_wrapped_y(i32 *wrap_line_index, f32 y, i32 line_height, i32 l_bound, i32 u_bound){
umem wrap_index = floor32(y/line_height); i32 wrap_index = floor32(y/line_height);
umem i = binary_search(wrap_line_index, wrap_index, l_bound, u_bound); i32 i = binary_search(wrap_line_index, wrap_index, l_bound, u_bound);
return(i); return(i);
} }
internal Partial_Cursor internal Partial_Cursor
buffer_partial_from_pos(Gap_Buffer *buffer, umem pos){ buffer_partial_from_pos(Gap_Buffer *buffer, i32 pos){
Partial_Cursor result = {0}; Partial_Cursor result = {0};
umem size = buffer_size(buffer); int32_t size = buffer_size(buffer);
pos = clamp_umem(0, pos, size); if (pos > size){
pos = size;
}
if (pos < 0){
pos = 0;
}
umem line_index = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); i32 line_index = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count);
result.pos = pos; result.pos = pos;
result.line = line_index+1; result.line = line_index+1;
result.character = pos - buffer->line_starts[line_index] + 1; result.character = pos - buffer->line_starts[line_index] + 1;
@ -1721,7 +1720,7 @@ enum Buffer_Render_Flag{
}; };
typedef struct Buffer_Render_Item{ typedef struct Buffer_Render_Item{
umem index; i32 index;
u32 codepoint; u32 codepoint;
u32 flags; u32 flags;
f32 x0, y0; f32 x0, y0;
@ -1739,7 +1738,8 @@ typedef struct Render_Item_Write{
} Render_Item_Write; } Render_Item_Write;
inline Render_Item_Write inline Render_Item_Write
write_render_item(Render_Item_Write write, umem index, u32 codepoint, u32 flags){ write_render_item(Render_Item_Write write, i32 index, u32 codepoint, u32 flags){
f32 ch_width = font_get_glyph_advance(write.system, write.font, codepoint); f32 ch_width = font_get_glyph_advance(write.system, write.font, codepoint);
if (write.x <= write.x_max && write.x + ch_width >= write.x_min){ if (write.x <= write.x_max && write.x + ch_width >= write.x_min){
@ -1950,7 +1950,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32
} }
if (!S.skipping_whitespace){ if (!S.skipping_whitespace){
umem I = S.step.i; u32 I = S.step.i;
switch (n){ switch (n){
case '\r': case '\r':
{ {
@ -1978,7 +1978,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32
} }
else if (S.behavior.do_number_advance){ else if (S.behavior.do_number_advance){
u8 n = (u8)S.step.value; u8 n = (u8)S.step.value;
umem I = S.step.i; u32 I = S.step.i;
S.skipping_whitespace = false; S.skipping_whitespace = false;
S.ch_width = S.byte_advance; S.ch_width = S.byte_advance;

View File

@ -15,7 +15,7 @@
struct Buffer_Model_Step{ struct Buffer_Model_Step{
u32 type; u32 type;
u32 value; u32 value;
umem i; i32 i;
u32 byte_length; u32 byte_length;
}; };

View File

@ -31,7 +31,7 @@ enum{
}; };
FILE_TRACK_LINK File_Track_Result 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 FILE_TRACK_LINK File_Track_Result
add_listener(File_Track_System *system, Partition *scratch, u8 *filename); 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); remove_listener(File_Track_System *system, Partition *scratch, u8 *filename);
FILE_TRACK_LINK File_Track_Result 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 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 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);
FILE_TRACK_LINK File_Track_Result FILE_TRACK_LINK File_Track_Result
shut_down_track_system(File_Track_System *system, Partition *scratch); shut_down_track_system(File_Track_System *system, Partition *scratch);

View File

@ -12,7 +12,6 @@
typedef struct{ typedef struct{
u32 id[4]; u32 id[4];
} File_Index; } File_Index;
global_const File_Index null_file_index = {0};
typedef u32 rptr32; typedef u32 rptr32;
@ -26,7 +25,7 @@ typedef struct {
global_const File_Track_Entry null_file_track_entry = {0}; global_const File_Track_Entry null_file_track_entry = {0};
typedef struct { typedef struct {
umem size; i32 size;
u32 tracked_count; u32 tracked_count;
u32 max; u32 max;
rptr32 file_table; rptr32 file_table;
@ -37,6 +36,14 @@ typedef struct DLL_Node {
struct DLL_Node *prev; struct DLL_Node *prev;
} DLL_Node; } DLL_Node;
internal File_Index
zero_file_index(){
File_Index a = {0};
return(a);
}
internal i32 internal i32
file_hash_is_zero(File_Index a){ file_hash_is_zero(File_Index a){
return ((a.id[0] == 0) && return ((a.id[0] == 0) &&
@ -175,18 +182,18 @@ internal_free_slot(File_Track_Tables *tables, File_Track_Entry *entry){
--tables->tracked_count; --tables->tracked_count;
} }
internal b32 internal i32
enough_memory_to_init_table(umem table_memory_size){ enough_memory_to_init_table(i32 table_memory_size){
b32 result = (sizeof(File_Track_Tables) + FILE_ENTRY_COST*8 <= table_memory_size); i32 result = (sizeof(File_Track_Tables) + FILE_ENTRY_COST*8 <= table_memory_size);
return(result); return(result);
} }
internal void 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->size = table_memory_size;
tables->tracked_count = 0; 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->file_table = sizeof(*tables);
tables->max = max_number_of_entries; 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 internal File_Track_Result
move_table_memory(File_Track_Tables *original_tables, move_table_memory(File_Track_Tables *original_tables,
void *mem, umem size){ void *mem, i32 size){
File_Track_Result result = FileTrack_Good; File_Track_Result result = FileTrack_Good;
if (original_tables->size < size){ if (original_tables->size < size){
@ -205,7 +212,7 @@ move_table_memory(File_Track_Tables *original_tables,
tables->size = size; tables->size = size;
i32 likely_entry_size = FILE_ENTRY_COST; 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->file_table = sizeof(*tables);
tables->max = max_number_of_entries; tables->max = max_number_of_entries;

View File

@ -1000,8 +1000,8 @@ struct Code_Wrap_State{
b32 consume_newline; b32 consume_newline;
Gap_Buffer_Stream stream; Gap_Buffer_Stream stream;
umem size; i32 size;
umem i; i32 i;
Render_Font *font; Render_Font *font;
f32 tab_indent_amount; f32 tab_indent_amount;
@ -1055,8 +1055,8 @@ wrap_state_set_top(Code_Wrap_State *state, f32 line_shift){
} }
struct Code_Wrap_Step{ struct Code_Wrap_Step{
umem position_start; i32 position_start;
umem position_end; i32 position_end;
f32 start_x; f32 start_x;
f32 final_x; f32 final_x;
@ -1067,7 +1067,7 @@ struct Code_Wrap_Step{
internal Code_Wrap_Step internal Code_Wrap_Step
wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_State *state, i32 fixed_end_point){ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_State *state, i32 fixed_end_point){
Code_Wrap_Step result = {0}; Code_Wrap_Step result = {0};
umem i = state->i; i32 i = state->i;
result.position_start = i; result.position_start = i;
@ -1501,9 +1501,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
potential_marks = push_array(part, Potential_Wrap_Indent_Pair, floor32(width)); potential_marks = push_array(part, Potential_Wrap_Indent_Pair, floor32(width));
umem remaining = partition_remaining(part); max_wrap_indent_mark = partition_remaining(part)/sizeof(Wrap_Indent_Pair);
umem pair_size = sizeof(Wrap_Indent_Pair);
max_wrap_indent_mark = (i32)(remaining/pair_size);
wrap_indent_marks = push_array(part, Wrap_Indent_Pair, max_wrap_indent_mark); wrap_indent_marks = push_array(part, Wrap_Indent_Pair, max_wrap_indent_mark);
} }
@ -1949,7 +1947,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File *
buffer_init_provide_page(&init, data, page_size); buffer_init_provide_page(&init, data, page_size);
} }
umem scratch_size = partition_remaining(part); i32 scratch_size = partition_remaining(part);
Assert(scratch_size > 0); Assert(scratch_size > 0);
b32 init_success = buffer_end_init(&init, part->base + part->pos, scratch_size); b32 init_success = buffer_end_init(&init, part->base + part->pos, scratch_size);
AllowLocal(init_success); Assert(init_success); AllowLocal(init_success); Assert(init_success);
@ -2202,10 +2200,10 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){
Gap_Buffer *buffer = &file->state.buffer; Gap_Buffer *buffer = &file->state.buffer;
i32 text_size = buffer_size(buffer); i32 text_size = buffer_size(buffer);
umem mem_size = partition_remaining(part); i32 mem_size = partition_remaining(part);
Cpp_Token_Array tokens; Cpp_Token_Array tokens;
tokens.max_count = (u32)(mem_size / sizeof(Cpp_Token)); tokens.max_count = mem_size / sizeof(Cpp_Token);
tokens.count = 0; tokens.count = 0;
tokens.tokens = push_array(part, Cpp_Token, tokens.max_count); tokens.tokens = push_array(part, Cpp_Token, tokens.max_count);

View File

@ -452,13 +452,6 @@ clamp(u32 a, u32 n, u32 z){
return (n); return (n);
} }
inline umem
clamp_umem(umem a, umem n, umem z){
if (n < a) n = a;
else if (n > z) n = z;
return (n);
}
#define clamp_top(a,b) Min(a,b) #define clamp_top(a,b) Min(a,b)
#define clamp_bottom(a,b) Max(a,b) #define clamp_bottom(a,b) Max(a,b)

View File

@ -169,7 +169,8 @@ struct Full_Job_Data{
struct Unbounded_Work_Queue{ struct Unbounded_Work_Queue{
Full_Job_Data *jobs; Full_Job_Data *jobs;
u32 count, max, skip; i32 count, max, skip;
u32 next_job_id; u32 next_job_id;
}; };
@ -203,13 +204,13 @@ typedef Sys_Acquire_Lock_Sig(System_Acquire_Lock);
typedef Sys_Release_Lock_Sig(System_Release_Lock); typedef Sys_Release_Lock_Sig(System_Release_Lock);
// needed for custom layer // needed for custom layer
#define Sys_Memory_Allocate_Sig(name) void* name(umem size) #define Sys_Memory_Allocate_Sig(name) void* name(i32 size)
typedef Sys_Memory_Allocate_Sig(System_Memory_Allocate); typedef Sys_Memory_Allocate_Sig(System_Memory_Allocate);
#define Sys_Memory_Set_Protection_Sig(name) bool32 name(void *ptr, umem size, u32 flags) #define Sys_Memory_Set_Protection_Sig(name) bool32 name(void *ptr, i32 size, u32 flags)
typedef Sys_Memory_Set_Protection_Sig(System_Memory_Set_Protection); typedef Sys_Memory_Set_Protection_Sig(System_Memory_Set_Protection);
#define Sys_Memory_Free_Sig(name) void name(void *ptr, umem size) #define Sys_Memory_Free_Sig(name) void name(void *ptr, i32 size)
typedef Sys_Memory_Free_Sig(System_Memory_Free); typedef Sys_Memory_Free_Sig(System_Memory_Free);
#define Sys_File_Exists_Sig(name) b32 name(char *filename, i32 len) #define Sys_File_Exists_Sig(name) b32 name(char *filename, i32 len)

View File

@ -18,6 +18,17 @@
// Standard implementation of file system stuff based on the file track layer. // Standard implementation of file system stuff based on the file track layer.
// //
struct Shared_Vars{
File_Track_System track;
void *track_table;
u32 track_table_size;
u32 track_node_size;
Partition scratch;
};
global Shared_Vars shared_vars;
internal void internal void
init_shared_vars(){ init_shared_vars(){
umem scratch_size = KB(128); umem scratch_size = KB(128);

View File

@ -9,7 +9,10 @@
// TOP // 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) #if !defined(FRED_SYSTEM_SHARED_H)
#define FRED_SYSTEM_SHARED_H #define FRED_SYSTEM_SHARED_H
@ -21,24 +24,17 @@ struct File_Data{
}; };
global File_Data null_file_data = {0}; global File_Data null_file_data = {0};
#define Sys_Get_Memory_Sig(name) void* name(i32 size, i32 line_number, char *file_name)
#define Sys_Free_Memory_Sig(name) void name(void *block)
#define Sys_File_Can_Be_Made_Sig(name) b32 name(char *filename) #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_Get_Binary_Path_Sig(name) i32 name(String *out) #define Sys_Get_Binary_Path_Sig(name) i32 name(String *out)
internal Sys_Get_Memory_Sig(system_get_memory_);
internal Sys_Free_Memory_Sig(system_free_memory);
internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made);
internal Sys_Get_Binary_Path_Sig(system_get_binary_path); internal Sys_Get_Binary_Path_Sig(system_get_binary_path);
///////////////////////////////////// #define system_get_memory(size) system_get_memory_((size), __LINE__, __FILE__)
struct Shared_Vars{
File_Track_System track;
void *track_table;
u32 track_table_size;
u32 track_node_size;
Partition scratch;
};
global Shared_Vars shared_vars;
#endif #endif

View File

@ -13,7 +13,7 @@
struct Translation_State{ struct Translation_State{
u8 fill_buffer[4]; u8 fill_buffer[4];
umem fill_start_i; u32 fill_start_i;
u8 fill_i; u8 fill_i;
u8 fill_expected; u8 fill_expected;
}; };
@ -47,7 +47,7 @@ struct Translation_Emits{
#define SINGLE_BYTE_ERROR_CLASS max_u8 #define SINGLE_BYTE_ERROR_CLASS max_u8
internal void 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; desc_out->byte_class = 0;
if ((ch >= ' ' && ch < 0x7F) || ch == '\t' || ch == '\n' || ch == '\r'){ if ((ch >= ' ' && ch < 0x7F) || ch == '\t' || ch == '\n' || ch == '\r'){
desc_out->byte_class = 1; desc_out->byte_class = 1;
@ -146,7 +146,7 @@ translating_select_emit_rule_with_font(System_Functions *system, Render_Font *fo
} }
internal void 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; emits_out->step_count = 0;
switch (emit_rule.emit_type){ switch (emit_rule.emit_type){
default: goto skip_all; default: goto skip_all;
@ -199,7 +199,7 @@ translating_generate_emits(Translation_State *tran, Translation_Emit_Rule emit_r
} }
internal void 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}; Translation_Byte_Description description = {0};
translating_consume_byte(tran, ch, i, size, &description); translating_consume_byte(tran, ch, i, size, &description);
Translation_Emit_Rule emit_rule = {0}; Translation_Emit_Rule emit_rule = {0};

View File

@ -87,10 +87,6 @@ inline u32 l_round_up_u32(u32 x, u32 b){
return( ((x)+(b)-1) - (((x)+(b)-1)%(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){ inline u32 round_up_pot_u32(u32 x){
--x; --x;
x |= x >> 1; x |= x >> 1;

View File

@ -886,7 +886,7 @@ static Argument_Breakdown
parameter_parse(Partition *part, char *data, Cpp_Token *args_start_token, Cpp_Token *args_end_token){ parameter_parse(Partition *part, char *data, Cpp_Token *args_start_token, Cpp_Token *args_end_token){
int32_t arg_index = 0; int32_t arg_index = 0;
Cpp_Token *arg_token = args_start_token + 1; 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; int32_t arg_count = 1;
arg_token = args_start_token; arg_token = args_start_token;

View File

@ -81,7 +81,7 @@ do_file_copy(Partition *part, char *src_file, char *dst_dir, char *dst_file){
terminate_with_null(&str); terminate_with_null(&str);
Temp_Memory temp = begin_temp_memory(part); 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); void *mem = push_block(part, mem_size);
FILE *in = fopen(src_file, "rb"); FILE *in = fopen(src_file, "rb");
if (in){ 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); int32_t file_size = ftell(in);
if (mem_size >= file_size){ if (mem_size >= file_size){
fseek(in, 0, SEEK_SET); fseek(in, 0, SEEK_SET);
fread(mem, 1, file_size, in); fread(mem, 1, file_size, in);
FILE *out = fopen(dst, "wb"); FILE *out = fopen(dst, "wb");
if (out){ if (out){
fwrite(mem, 1, file_size, out); fwrite(mem, 1, file_size, out);
fclose(out); fclose(out);
success = 1; success = 1;
}
} }
}
fclose(in); fclose(in);
} }
end_temp_memory(temp); end_temp_memory(temp);

View File

@ -1116,10 +1116,8 @@ CUSTOM_COMMAND_SIG(rename_parameter){
String replace_string = with.string; String replace_string = with.string;
Buffer_Edit *edits = (Buffer_Edit*)partition_current(part); Buffer_Edit *edits = (Buffer_Edit*)partition_current(part);
size_t remaining = partition_remaining(part); int32_t edit_max = (partition_remaining(part))/sizeof(Buffer_Edit);
size_t edit_size = sizeof(Buffer_Edit); int32_t edit_count = 0;
uint32_t edit_max = (uint32_t)(remaining/edit_size);
uint32_t edit_count = 0;
if (edit_max >= 1){ if (edit_max >= 1){
Buffer_Edit edit; Buffer_Edit edit;
@ -1142,7 +1140,7 @@ CUSTOM_COMMAND_SIG(rename_parameter){
switch (token_ptr->type){ switch (token_ptr->type){
case CPP_TOKEN_IDENTIFIER: 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]; char other_lexeme_base[128];
String other_lexeme = make_fixed_width_string(other_lexeme_base); String other_lexeme = make_fixed_width_string(other_lexeme_base);
other_lexeme.size = old_lexeme.size; other_lexeme.size = old_lexeme.size;
@ -1255,8 +1253,7 @@ CUSTOM_COMMAND_SIG(write_explicit_enum_values){
Buffer_Edit *edits = push_array(part, Buffer_Edit, count_estimate); Buffer_Edit *edits = push_array(part, Buffer_Edit, count_estimate);
char *string_base = (char*)partition_current(part); char *string_base = (char*)partition_current(part);
uint32_t remaining = (uint32_t)partition_remaining(part); String string = make_string(string_base, 0, partition_remaining(part));
String string = make_string(string_base, 0, remaining);
closed_correctly = false; closed_correctly = false;
still_looping = false; still_looping = false;

View File

@ -283,13 +283,40 @@ Sys_Memory_Free_Sig(system_memory_free){
VirtualFree(ptr, 0, MEM_RELEASE); VirtualFree(ptr, 0, MEM_RELEASE);
} }
#define Win32GetMemory(size) system_memory_allocate(size) // TODO(allen): delete
#define Win32FreeMemory(ptr) system_memory_free(ptr) internal
Sys_Get_Memory_Sig(system_get_memory_){
void *ptr = 0;
if (size > 0){
ptr = VirtualAlloc(0, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
}
return(ptr);
}
// TODO(allen): delete
internal
Sys_Free_Memory_Sig(system_free_memory){
if (block){
VirtualFree(block, 0, MEM_RELEASE);
}
}
#define Win32GetMemory(size) system_get_memory_(size, __LINE__, __FILE__)
#define Win32FreeMemory(ptr) system_free_memory(ptr)
#define Win32ScratchPartition sysshared_scratch_partition #define Win32ScratchPartition sysshared_scratch_partition
#define Win32ScratchPartitionGrow sysshared_partition_grow #define Win32ScratchPartitionGrow sysshared_partition_grow
#define Win32ScratchPartitionDouble sysshared_partition_double #define Win32ScratchPartitionDouble sysshared_partition_double
#if 0
#if FRED_INTERNAL
internal void
INTERNAL_system_debug_message(char *message){
OutputDebugStringW(message);
}
#endif
#endif
// //
// Multithreading // Multithreading
@ -380,8 +407,8 @@ JobThreadProc(LPVOID lpParameter){
internal void internal void
initialize_unbounded_queue(Unbounded_Work_Queue *source_queue){ 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->jobs = (Full_Job_Data*)system_get_memory(max*sizeof(Full_Job_Data));
source_queue->count = 0; source_queue->count = 0;
source_queue->max = max; source_queue->max = max;
source_queue->skip = 0; source_queue->skip = 0;
@ -493,11 +520,11 @@ Sys_Post_Job_Sig(system_post_job){
while (queue->count >= queue->max){ while (queue->count >= queue->max){
i32 new_max = queue->max*2; i32 new_max = queue->max*2;
Full_Job_Data *new_jobs = (Full_Job_Data*) Full_Job_Data *new_jobs = (Full_Job_Data*)
system_memory_allocate(new_max*sizeof(Full_Job_Data)); system_get_memory(new_max*sizeof(Full_Job_Data));
memcpy(new_jobs, queue->jobs, queue->count); memcpy(new_jobs, queue->jobs, queue->count);
system_memory_free(queue->jobs, 0); system_free_memory(queue->jobs);
queue->jobs = new_jobs; queue->jobs = new_jobs;
queue->max = new_max; queue->max = new_max;
@ -587,11 +614,11 @@ Sys_Grow_Thread_Memory_Sig(system_grow_thread_memory){
void *old_data = memory->data; void *old_data = memory->data;
i32 old_size = memory->size; i32 old_size = memory->size;
i32 new_size = l_round_up_i32(memory->size*2, KB(4)); i32 new_size = l_round_up_i32(memory->size*2, KB(4));
memory->data = system_memory_allocate(new_size); memory->data = system_get_memory(new_size);
memory->size = new_size; memory->size = new_size;
if (old_data){ if (old_data){
memcpy(memory->data, old_data, old_size); memcpy(memory->data, old_data, old_size);
system_memory_free(old_data, 0); system_free_memory(old_data);
} }
system_release_lock(CANCEL_LOCK0 + memory->id - 1); system_release_lock(CANCEL_LOCK0 + memory->id - 1);
} }
@ -717,29 +744,15 @@ Sys_Yield_Coroutine_Sig(system_yield_coroutine){
internal internal
Sys_File_Can_Be_Made_Sig(system_file_can_be_made){ Sys_File_Can_Be_Made_Sig(system_file_can_be_made){
b32 result = false; HANDLE file = CreateFile((char*)filename, FILE_APPEND_DATA, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
Partition *scratch = &shared_vars.scratch; if (!file || file == INVALID_HANDLE_VALUE){
Temp_Memory temp = begin_temp_memory(scratch); return 0;
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);
}
} }
end_temp_memory(temp); CloseHandle(file);
return(result); return(1);
} }
internal internal
@ -1373,6 +1386,8 @@ Sys_Send_Exit_Signal_Sig(system_send_exit_signal){
#include "4ed_system_shared.cpp" #include "4ed_system_shared.cpp"
#include "win32_4ed_fonts.cpp"
// //
// Linkage to Custom and Application // Linkage to Custom and Application
// //
@ -2454,9 +2469,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
#include "font/4coder_font_static_functions.cpp" #include "font/4coder_font_static_functions.cpp"
#include "win32_4ed_fonts.cpp"
//#include "win32_4ed_file_track.cpp"
#if 0 #if 0
// NOTE(allen): In case I want to switch back to a console // NOTE(allen): In case I want to switch back to a console
// application at some point. // application at some point.

View File

@ -44,7 +44,7 @@ typedef struct {
#define to_tables(v) ((File_Track_Tables*)(v->tables)) #define to_tables(v) ((File_Track_Tables*)(v->tables))
FILE_TRACK_LINK File_Track_Result 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; File_Track_Result result = FileTrack_MemoryTooSmall;
Win32_File_Track_Vars *vars = to_vars(system); 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); init_sentinel_node(&vars->free_sentinel);
Win32_Directory_Listener_Node *listener = (Win32_Directory_Listener_Node*)listener_memory; Win32_Directory_Listener_Node *listener = (Win32_Directory_Listener_Node*)listener_memory;
umem node_size = sizeof(Win32_Directory_Listener_Node); i32 count = listener_memory_size / sizeof(Win32_Directory_Listener_Node);
u32 count = (u32)(listener_memory_size / node_size); for (i32 i = 0; i < count; ++i, ++listener){
for (u32 i = 0; i < count; ++i, ++listener){
insert_node(&vars->free_sentinel, &listener->node); insert_node(&vars->free_sentinel, &listener->node);
} }
} }
@ -255,7 +254,7 @@ remove_listener(File_Track_System *system, Partition *scratch, u8 *filename){
} }
FILE_TRACK_LINK File_Track_Result 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; File_Track_Result result = FileTrack_Good;
Win32_File_Track_Vars *vars = to_vars(system); Win32_File_Track_Vars *vars = to_vars(system);
@ -271,7 +270,7 @@ move_track_system(File_Track_System *system, Partition *scratch, void *mem, umem
} }
FILE_TRACK_LINK File_Track_Result 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; File_Track_Result result = FileTrack_Good;
Win32_File_Track_Vars *vars = to_vars(system); Win32_File_Track_Vars *vars = to_vars(system);
@ -279,9 +278,8 @@ expand_track_system_listeners(File_Track_System *system, Partition *scratch, voi
if (sizeof(Win32_Directory_Listener_Node) <= size){ if (sizeof(Win32_Directory_Listener_Node) <= size){
Win32_Directory_Listener_Node *listener = (Win32_Directory_Listener_Node*)mem; Win32_Directory_Listener_Node *listener = (Win32_Directory_Listener_Node*)mem;
umem node_size = sizeof(Win32_Directory_Listener_Node); i32 count = size / sizeof(Win32_Directory_Listener_Node);
u32 count = (u32)(size / node_size); for (i32 i = 0; i < count; ++i, ++listener){
for (u32 i = 0; i < count; ++i, ++listener){
insert_node(&vars->free_sentinel, &listener->node); insert_node(&vars->free_sentinel, &listener->node);
} }
} }
@ -295,7 +293,7 @@ expand_track_system_listeners(File_Track_System *system, Partition *scratch, voi
} }
FILE_TRACK_LINK File_Track_Result 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; File_Track_Result result = FileTrack_NoMoreEvents;
Win32_File_Track_Vars *vars = to_vars(system); Win32_File_Track_Vars *vars = to_vars(system);
@ -303,19 +301,17 @@ get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32
local_persist DWORD offset = 0; local_persist DWORD offset = 0;
local_persist Win32_Directory_Listener listener = {0}; local_persist Win32_Directory_Listener listener = {0};
Temp_Memory temp = begin_temp_memory(scratch);
EnterCriticalSection(&vars->table_lock); EnterCriticalSection(&vars->table_lock);
OVERLAPPED *overlapped = 0; OVERLAPPED *overlapped = 0;
DWORD length = 0; DWORD length = 0;
ULONG_PTR key = 0; ULONG_PTR key = 0;
b32 has_result = false; b32 has_result = 0;
if (has_buffered_event){ if (has_buffered_event){
has_buffered_event = 0; has_buffered_event = 0;
has_result = true; has_result = 1;
} }
else{ else{
if (GetQueuedCompletionStatus(vars->iocp, &length, &key, &overlapped, 0)){ if (GetQueuedCompletionStatus(vars->iocp, &length, &key, &overlapped, 0)){
@ -328,7 +324,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); ReadDirectoryChangesW(listener_ptr->dir, listener_ptr->result, sizeof(listener_ptr->result), 1, FLAGS, 0, &listener_ptr->overlapped, 0);
offset = 0; offset = 0;
has_result = true; has_result = 1;
} }
} }
@ -339,39 +335,36 @@ get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32
i32 dir_len = GetFinalPathNameByHandle(listener.dir, 0, 0, FILE_NAME_NORMALIZED); i32 dir_len = GetFinalPathNameByHandle(listener.dir, 0, 0, FILE_NAME_NORMALIZED);
i32 req_size = dir_len + 1 + len; i32 req_size = dir_len + 1 + len;
*size = req_size;
if (req_size < max){ if (req_size < max){
u16 *buffer_16 = push_array(scratch, u16, req_size+1); i32 pos = GetFinalPathNameByHandle(listener.dir, buffer, max, FILE_NAME_NORMALIZED);
i32 pos = GetFinalPathNameByHandle(listener.dir, (LPWSTR)buffer_16, max, FILE_NAME_NORMALIZED); buffer[pos++] = '\\';
b32 convert_error = false; for (i32 i = 0; i < len; ++i, ++pos){
umem buffer_size = utf16_to_utf8_minimal_checking(buffer, max-1, buffer_16, pos, &convert_error); buffer[pos] = (char)info->FileName[i];
if (buffer_size > max-1){
result = FileTrack_MemoryTooSmall;
} }
else if (!convert_error){
buffer[buffer_size++] = '\\'; if (buffer[0] == '\\'){
for (i32 i = 0; i+4 < pos; ++i){
if (buffer[0] == '\\'){ buffer[i] = buffer[i+4];
for (i32 i = 0; i+4 < buffer_size; ++i){
buffer[i] = buffer[i+4];
}
buffer_size -= 4;
} }
*size = buffer_size; *size -= 4;
result = FileTrack_Good;
}
else{
result = FileTrack_FileSystemError;
} }
result = FileTrack_Good;
} }
else{ 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; result = FileTrack_MemoryTooSmall;
} }
if (info->NextEntryOffset != 0){ 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; offset += info->NextEntryOffset;
has_buffered_event = 1; has_buffered_event = 1;
} }
@ -379,8 +372,6 @@ get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32
LeaveCriticalSection(&vars->table_lock); LeaveCriticalSection(&vars->table_lock);
end_temp_memory(temp);
return(result); return(result);
} }