From 3006d5425c24d21ef792f4bb81ccded4ef7167ab Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 20 Mar 2017 11:55:46 -0400 Subject: [PATCH 01/17] working on the windows layer utf8 <-> utf16 stuff --- win32_4ed.cpp | 180 +++++++++++++++++++++------------------ win32_4ed_file_track.cpp | 4 +- 2 files changed, 101 insertions(+), 83 deletions(-) diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 390c2446..b2bd7a69 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -726,7 +726,7 @@ Sys_File_Can_Be_Made_Sig(system_file_can_be_made){ u16 *filename_16 = push_array(scratch, u16, max); b32 error = false; - utf8_to_utf16_minimal_checking(filename_16, max, filename, len, &error); + utf8_to_utf16_minimal_checking(filename_16, max, (u8*)filename, len, &error); if (!error){ HANDLE file = CreateFile((LPCWSTR)filename_16, FILE_APPEND_DATA, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); @@ -746,102 +746,120 @@ internal Sys_Set_File_List_Sig(system_set_file_list){ b32 clear_list = true; if (directory != 0){ + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + char dir_space[MAX_PATH + 32]; String dir = make_string_cap(dir_space, 0, MAX_PATH + 32); append_sc(&dir, directory); terminate_with_null(&dir); - HANDLE dir_handle = CreateFile(dir.str, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + umem filename_16_max = (dir.size+1)*2; + u16 *filename_16 = push_array(scratch, u16, filename_16_max); + b32 convert_error = false; + umem length = utf8_to_utf16_minimal_checking(filename_16, filename_16_max-1, (u8*)dir.str, dir.size, &convert_error); - if (dir_handle != INVALID_HANDLE_VALUE){ - DWORD final_length = GetFinalPathNameByHandle(dir_handle, dir_space, sizeof(dir_space), 0); - CloseHandle(dir_handle); + if (!convert_error){ + filename_16[length] = 0; - if (final_length < sizeof(dir_space)){ - char *c_str_dir = dir_space; + HANDLE dir_handle = CreateFile((LPWSTR)filename_16, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + + if (dir_handle != INVALID_HANDLE_VALUE){ + DWORD final_length = GetFinalPathNameByHandle(dir_handle, (LPWSTR)filename_16, (DWORD)filename_16_max, 0); + CloseHandle(dir_handle); - final_length -= 4; - memmove(c_str_dir, c_str_dir+4, final_length); - c_str_dir[final_length] = '\\'; - c_str_dir[final_length+1] = '*'; - c_str_dir[final_length+2] = 0; - - if (canon_directory_out != 0){ - if (final_length+1 < canon_directory_max){ - memcpy(canon_directory_out, c_str_dir, final_length); - if (canon_directory_out[final_length-1] != '\\'){ - canon_directory_out[final_length++] = '\\'; - } - canon_directory_out[final_length] = 0; - *canon_directory_size_out = final_length; - } - else{ - u32 length = copy_fast_unsafe_cc(canon_directory_out, directory); - canon_directory_out[length] = 0; - *canon_directory_size_out = length; - } - } - - WIN32_FIND_DATA find_data; - HANDLE search = FindFirstFile(c_str_dir, &find_data); - - if (search != INVALID_HANDLE_VALUE){ - i32 character_count = 0; - i32 file_count = 0; - BOOL more_files = true; - do{ - if (!match_cs(find_data.cFileName, make_lit_string(".")) && - !match_cs(find_data.cFileName, make_lit_string(".."))){ - ++file_count; - i32 size = 0; - for(;find_data.cFileName[size];++size); - character_count += size + 1; - } - more_files = FindNextFile(search, &find_data); - }while(more_files); - FindClose(search); + if (final_length < sizeof(dir_space)){ + final_length -= 4; + memmove(filename_16, filename_16+4, final_length*sizeof(*filename_16)); + filename_16[final_length] = '\\'; + filename_16[final_length+1] = '*'; + filename_16[final_length+2] = 0; - i32 required_size = character_count + file_count * sizeof(File_Info); - if (file_list->block_size < required_size){ - system_free_memory(file_list->block); - file_list->block = system_get_memory(required_size); - file_list->block_size = required_size; - } - - file_list->infos = (File_Info*)file_list->block; - char *name = (char*)(file_list->infos + file_count); - if (file_list->block != 0){ - search = FindFirstFile(c_str_dir, &find_data); + if (canon_directory_out != 0){ + umem out_length = utf16_to_utf8_minimal_checking((u8*)canon_directory_out, canon_directory_max-1, filename_16, final_length, &convert_error); - if (search != INVALID_HANDLE_VALUE){ - File_Info *info = file_list->infos; - more_files = true; - do{ - if (!match_cs(find_data.cFileName, make_lit_string(".")) && - !match_cs(find_data.cFileName, make_lit_string(".."))){ - info->folder = (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; - info->filename = name; - - i32 length = copy_fast_unsafe_cc(name, find_data.cFileName); - name += length; - - info->filename_len = length; - *name++ = 0; - String fname = make_string_cap(info->filename, info->filename_len, info->filename_len+1); - replace_char(&fname, '\\', '/'); - ++info; - } - more_files = FindNextFile(search, &find_data); - }while(more_files); - FindClose(search); + if (!convert_error){ + if (canon_directory_out[out_length-1] != '\\'){ + canon_directory_out[out_length++] = '\\'; + } + canon_directory_out[out_length] = 0; + *canon_directory_size_out = (u32)out_length; + } + else{ + u32 length = copy_fast_unsafe_cc(canon_directory_out, directory); + canon_directory_out[length] = 0; + *canon_directory_size_out = length; + } + } + + WIN32_FIND_DATA find_data; + HANDLE search = FindFirstFile((LPWSTR)filename_16, &find_data); + + if (search != INVALID_HANDLE_VALUE){ + u32 character_count = 0; + u32 file_count = 0; + BOOL more_files = true; + do{ + if (!(find_data.cFileName[0] == '.' && find_data.cFileName[1] == 0) && + !(find_data.cFileName[0] == '.' && find_data.cFileName[1] == '.' && find_data.cFileName[2] == 0)){ + ++file_count; + u32 size = 0; + for(;find_data.cFileName[size];++size); + character_count += size + 1; + } + more_files = FindNextFile(search, &find_data); + }while(more_files); + FindClose(search); + + u32 required_size = character_count*2 + file_count * sizeof(File_Info); + if (file_list->block_size < (i32)required_size){ + system_memory_free(file_list->block, 0); + file_list->block = system_memory_allocate(required_size); + file_list->block_size = required_size; + } + + file_list->infos = (File_Info*)file_list->block; + char *name = (char*)(file_list->infos + file_count); + if (file_list->block != 0){ + search = FindFirstFile((LPWSTR)filename_16, &find_data); - file_list->count = file_count; - clear_list = false; + if (search != INVALID_HANDLE_VALUE){ + File_Info *info = file_list->infos; + more_files = true; + do{ + if (!(find_data.cFileName[0] == '.' && find_data.cFileName[1] == 0) && + !(find_data.cFileName[0] == '.' && find_data.cFileName[1] == '.' && find_data.cFileName[2] == 0)){ + info->folder = (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; + info->filename = name; + + //u32 length = copy_fast_unsafe_cc(name, find_data.cFileName); + u32 size = 0; + for(;find_data.cFileName[size];++size); + umem length = utf16_to_utf8_minimal_checking(info->filename, remaining_size, file_data.cFileName, size, &convert_error); + if (!convert_error){ + name += length; + + info->filename_len = length; + *name++ = 0; + String fname = make_string_cap(info->filename, info->filename_len, info->filename_len+1); + replace_char(&fname, '\\', '/'); + ++info; + } + } + more_files = FindNextFile(search, &find_data); + }while(more_files); + FindClose(search); + + file_list->count = file_count; + clear_list = false; + } } } } } } + + end_temp_memory(temp); } if (clear_list){ diff --git a/win32_4ed_file_track.cpp b/win32_4ed_file_track.cpp index d0b03d3d..1794ec72 100644 --- a/win32_4ed_file_track.cpp +++ b/win32_4ed_file_track.cpp @@ -135,7 +135,7 @@ add_listener(File_Track_System *system, Partition *scratch, u8 *filename){ u16 dir_name[1024]; internal_utf8_file_to_utf16_parent(dir_name, ArrayCount(dir_name), filename); - HANDLE dir = CreateFile((LPCWSTR)dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + HANDLE dir = CreateFile((LPWSTR)dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir != INVALID_HANDLE_VALUE){ BY_HANDLE_FILE_INFORMATION dir_info = {0}; @@ -217,7 +217,7 @@ remove_listener(File_Track_System *system, Partition *scratch, u8 *filename){ u16 dir_name[1024]; internal_utf8_file_to_utf16_parent(dir_name, ArrayCount(dir_name), filename); - HANDLE dir = CreateFile((LPCWSTR)dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + HANDLE dir = CreateFile((LPWSTR)dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir != INVALID_HANDLE_VALUE){ BY_HANDLE_FILE_INFORMATION dir_info = {0}; From c7b1328cabb55c65eea6f3225708e74500675f1d Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Wed, 22 Mar 2017 22:17:17 -0400 Subject: [PATCH 02/17] progress converting the platform layer over --- 4coder_API/types.h | 10 +- 4coder_project_commands.cpp | 6 +- 4ed.cpp | 2 +- 4ed_api_implementation.cpp | 10 +- 4ed_buffer.cpp | 210 ++++++++++++++++----------------- 4ed_buffer_model.h | 2 +- 4ed_file.cpp | 12 +- 4ed_file_view.cpp | 183 ++++++++++++++--------------- 4ed_hot_directory.cpp | 2 +- 4ed_system.h | 8 +- 4ed_translation.cpp | 8 +- 4ed_working_set.cpp | 2 +- pens_arena.cpp | 14 --- power/4coder_experiments.cpp | 7 +- win32_4ed.cpp | 220 ++++++++++++++++++++++++++--------- 15 files changed, 383 insertions(+), 313 deletions(-) delete mode 100644 pens_arena.cpp diff --git a/4coder_API/types.h b/4coder_API/types.h index b168b18c..380d619a 100644 --- a/4coder_API/types.h +++ b/4coder_API/types.h @@ -417,11 +417,11 @@ DOC_SEE(File_List) */ STRUCT File_Info{ /* DOC(This field is a null terminated string specifying the name of the file.) */ - char *filename; + uint8_t *filename; /* DOC(This field specifies the length of the filename string not counting the null terminator.) */ - int32_t filename_len; + uint32_t filename_len; /* DOC(This field indicates that the description is for a folder not a file.) */ - int32_t folder; + bool32 folder; }; /* DOC(File_List is a list of File_Info structs.) */ @@ -431,9 +431,9 @@ STRUCT File_List{ /* DOC(This field is an array of File_Info structs.) */ File_Info *infos; /* DOC(This field specifies the number of struts in the info array.) */ - int32_t count; + uint32_t count; /* DOC(This field is for internal use.) */ - int32_t block_size; + uint32_t block_size; }; /* DOC(Buffer_Identifier acts as a loosely typed description of a buffer that can either be a name or an id.) */ diff --git a/4coder_project_commands.cpp b/4coder_project_commands.cpp index 97d77ffe..d7d8b66c 100644 --- a/4coder_project_commands.cpp +++ b/4coder_project_commands.cpp @@ -102,12 +102,12 @@ open_all_files_with_extension_internal(Application_Links *app, String dir, char File_List list = get_file_list(app, dir.str, dir.size); int32_t dir_size = dir.size; - for (int32_t i = 0; i < list.count; ++i){ + for (uint32_t i = 0; i < list.count; ++i){ File_Info *info = list.infos + i; if (info->folder){ if (recursive){ dir.size = dir_size; - append(&dir, info->filename); + append(&dir, (char*)info->filename); append(&dir, "/"); open_all_files_with_extension_internal(app, dir, extension_list, extension_count, recursive); } @@ -130,7 +130,7 @@ open_all_files_with_extension_internal(Application_Links *app, String dir, char if (is_match){ dir.size = dir_size; - append(&dir, info->filename); + append(&dir, (char*)info->filename); create_buffer(app, dir.str, dir.size, 0); } } diff --git a/4ed.cpp b/4ed.cpp index 54cb706b..929a0586 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -452,7 +452,7 @@ COMMAND_DECL(toggle_line_wrap){ else{ file->settings.unwrapped_lines = 1; } - view_cursor_move(system, view, view->edit_pos->cursor.pos); + view_cursor_move(system, view, (u32)view->edit_pos->cursor.pos); view_set_relative_scrolling(view, scrolling); } diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index f5f62908..d23b4b24 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -571,7 +571,7 @@ DOC_SEE(4coder_Buffer_Positioning_System) size = buffer_size(&file->state.buffer); if (0 <= start && start <= end && end <= size){ result = true; - buffer_stringify(&file->state.buffer, start, end, out); + buffer_stringify(&file->state.buffer, (u32)start, (u32)end, out); } fill_buffer_summary(buffer, file, cmd); } @@ -672,7 +672,7 @@ DOC_SEE(Buffer_Batch_Edit_Type) char *inv_str = (char*)part->base + part->pos; umem inv_str_max = part->max - part->pos; - Edit_Spec spec = file_compute_edit(mem, file, edits, str, str_len, inverse_edits, inv_str, (u32)inv_str_max, (u32)edit_count, type); + Edit_Spec spec = file_compute_edit(mem, file, edits, str, (u32)str_len, inverse_edits, inv_str, (u32)inv_str_max, (u32)edit_count, type); file_do_batch_edit(system, models, file, spec, hist_normal, type); @@ -1802,11 +1802,11 @@ DOC_SEE(Buffer_Seek) if (seek.type != buffer_seek_pos){ result = true; cursor = view_compute_cursor(system, vptr, seek, 0); - vptr->edit_pos->mark = cursor.pos; + vptr->edit_pos->mark = (u32)cursor.pos; } else{ result = true; - vptr->edit_pos->mark = seek.pos; + vptr->edit_pos->mark = (u32)seek.pos; } fill_view_summary(system, view, vptr, cmd); } @@ -1832,7 +1832,7 @@ DOC(The highlight is mutually exclusive to the cursor. When the turn_on paramet if (vptr != 0){ result = true; if (turn_on){ - view_set_temp_highlight(system, vptr, start, end); + view_set_temp_highlight(system, vptr, (u32)start, (u32)end); } else{ vptr->file_data.show_temp_highlight = false; diff --git a/4ed_buffer.cpp b/4ed_buffer.cpp index 2c2868c7..421f04ef 100644 --- a/4ed_buffer.cpp +++ b/4ed_buffer.cpp @@ -17,12 +17,12 @@ #include "4coder_helper/4coder_seek_types.h" typedef struct Cursor_With_Index{ - umem pos; + u32 pos; i32 index; } Cursor_With_Index; inline void -write_cursor_with_index(Cursor_With_Index *positions, i32 *count, umem pos){ +write_cursor_with_index(Cursor_With_Index *positions, u32 *count, u32 pos){ positions[(*count)].index = *count; positions[(*count)].pos = pos; ++(*count); @@ -33,7 +33,7 @@ write_cursor_with_index(Cursor_With_Index *positions, i32 *count, umem pos){ internal void buffer_quick_sort_cursors(Cursor_With_Index *positions, i32 start, i32 pivot){ i32 mid = start; - umem pivot_pos = positions[pivot].pos; + u32 pivot_pos = positions[pivot].pos; for (i32 i = mid; i < pivot; ++i){ if (positions[i].pos < pivot_pos){ CursorSwap__(positions[mid], positions[i]); @@ -78,7 +78,7 @@ buffer_unsort_cursors(Cursor_With_Index *positions, i32 count){ } internal void -buffer_update_cursors(Cursor_With_Index *sorted_positions, i32 count, i32 start, i32 end, i32 len, b32 lean_right){ +buffer_update_cursors(Cursor_With_Index *sorted_positions, u32 count, u32 start, u32 end, u32 len, b32 lean_right){ i32 shift_amount = (len - (end - start)); Cursor_With_Index *position = sorted_positions + count - 1; @@ -121,8 +121,8 @@ buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, u32 edit_count){ Buffer_Edit *edit = sorted_edits; i32 shift_total = 0, shift_max = 0; for (u32 i = 0; i < edit_count; ++i, ++edit){ - umem target_length = edit->end - edit->start; - umem edit_length = edit->len; + u32 target_length = (u32)(edit->end - edit->start); + u32 edit_length = (u32)edit->len; if (edit_length > target_length){ shift_total += (i32)(edit_length - target_length); } @@ -138,7 +138,7 @@ buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, u32 edit_count){ } internal i32 -buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, Buffer_Edit *sorted_edits, i32 edit_count, b32 lean_right){ +buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, u32 count, Buffer_Edit *sorted_edits, u32 edit_count, b32 lean_right){ Cursor_With_Index *position = sorted_positions; Cursor_With_Index *end_position = sorted_positions + count; Buffer_Edit *edit = sorted_edits; @@ -147,20 +147,20 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, if (lean_right){ for (; edit < end_edit && position < end_position; ++edit){ - umem start = edit->start; - umem end = edit->end; + u32 start = (u32)edit->start; + u32 end = (u32)edit->end; for (; position->pos < start && position < end_position; ++position){ position->pos += shift_amount; } - umem new_end = start + edit->len + shift_amount; + u32 new_end = start + (u32)edit->len + shift_amount; for (; position->pos <= end && position < end_position; ++position){ position->pos = new_end; } - umem target_length = end - start; - umem edit_length = edit->len; + u32 target_length = end - start; + u32 edit_length = (u32)edit->len; if (edit_length > target_length){ shift_amount += (i32)(edit_length - target_length); } @@ -171,20 +171,20 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, } else{ for (; edit < end_edit && position < end_position; ++edit){ - umem start = edit->start; - umem end = edit->end; + u32 start = (u32)edit->start; + u32 end = (u32)edit->end; for (; position->pos < start && position < end_position; ++position){ position->pos += shift_amount; } - umem new_end = start + shift_amount; + u32 new_end = start + shift_amount; for (; position->pos <= end && position < end_position; ++position){ position->pos = new_end; } - umem target_length = end - start; - umem edit_length = edit->len; + u32 target_length = end - start; + u32 edit_length = (u32)edit->len; if (edit_length > target_length){ shift_amount += (i32)(edit_length - target_length); } @@ -199,8 +199,8 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, } for (; edit < end_edit; ++edit){ - umem target_length = edit->end - edit->start; - umem edit_length = edit->len; + u32 target_length = (u32)(edit->end - edit->start); + u32 edit_length = (u32)edit->len; if (edit_length > target_length){ shift_amount += (i32)(edit_length - target_length); } @@ -214,9 +214,9 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, ////////////////////////////////////// -internal umem -eol_convert_in(char *dest, char *src, umem size){ - umem i = 0, j = 0, k = 0; +internal u32 +eol_convert_in(char *dest, char *src, u32 size){ + u32 i = 0, j = 0, k = 0; for (; j < size && src[j] != '\r'; ++j); memcpy(dest, src, j); @@ -238,9 +238,9 @@ eol_convert_in(char *dest, char *src, umem size){ return(j); } -internal umem -eol_in_place_convert_in(char *data, umem size){ - umem i = 0, j = 0, k = 0; +internal u32 +eol_in_place_convert_in(char *data, u32 size){ + u32 i = 0, j = 0, k = 0; for (; j < size && data[j] != '\r'; ++j); @@ -263,9 +263,9 @@ eol_in_place_convert_in(char *data, umem size){ // TODO(allen): iterative memory check? internal b32 -eol_convert_out(char *dest, umem max, char *src, umem size, umem *size_out){ +eol_convert_out(char *dest, u32 max, char *src, u32 size, u32 *size_out){ b32 result = true; - umem i = 0, j = 0; + u32 i = 0, j = 0; for (; i < size; ++i, ++j){ if (src[i] == '\n'){ @@ -284,9 +284,9 @@ eol_convert_out(char *dest, umem max, char *src, umem size, umem *size_out){ // TODO(allen): iterative memory check? internal b32 -eol_in_place_convert_out(char *data, umem size, umem max, umem *size_out){ +eol_in_place_convert_out(char *data, u32 size, u32 max, u32 *size_out){ b32 result = true; - umem i = 0; + u32 i = 0; for (; i < size; ++i){ if (data[i] == '\n'){ @@ -309,10 +309,10 @@ eol_in_place_convert_out(char *data, umem size, umem max, umem *size_out){ typedef struct Gap_Buffer{ char *data; - umem size1; - umem gap_size; - umem size2; - umem max; + u32 size1; + u32 gap_size; + u32 size2; + u32 max; u32 *line_starts; u32 line_count; @@ -325,22 +325,16 @@ buffer_good(Gap_Buffer *buffer){ return(good); } -inline umem -buffer_size_umem(Gap_Buffer *buffer){ - umem size = buffer->size1 + buffer->size2; - return(size); -} - inline u32 buffer_size(Gap_Buffer *buffer){ - umem size = buffer->size1 + buffer->size2; - return(u32)(size); + u32 size = buffer->size1 + buffer->size2; + return(size); } typedef struct Gap_Buffer_Init{ Gap_Buffer *buffer; char *data; - umem size; + u32 size; } Gap_Buffer_Init; internal Gap_Buffer_Init @@ -361,29 +355,29 @@ buffer_init_need_more(Gap_Buffer_Init *init){ return(result); } -internal umem +internal u32 buffer_init_page_size(Gap_Buffer_Init *init){ - umem result = init->size * 2; + u32 result = init->size * 2; return(result); } internal void -buffer_init_provide_page(Gap_Buffer_Init *init, void *page, umem page_size){ +buffer_init_provide_page(Gap_Buffer_Init *init, void *page, u32 page_size){ Gap_Buffer *buffer = init->buffer; buffer->data = (char*)page; buffer->max = page_size; } internal b32 -buffer_end_init(Gap_Buffer_Init *init, void *scratch, umem scratch_size){ +buffer_end_init(Gap_Buffer_Init *init, void *scratch, u32 scratch_size){ Gap_Buffer *buffer = init->buffer; b32 result = false; if (buffer->data && buffer->max >= init->size){ - umem size = init->size; - umem size2 = size*2; - umem osize1 = size - size2; - umem size1 = osize1; + u32 size = init->size; + u32 size2 = size*2; + u32 osize1 = size - size2; + u32 size1 = osize1; if (size1 > 0){ size1 = eol_convert_in(buffer->data, init->data, size1); @@ -406,8 +400,8 @@ buffer_end_init(Gap_Buffer_Init *init, void *scratch, umem scratch_size){ typedef struct Gap_Buffer_Stream{ Gap_Buffer *buffer; char *data; - umem end; - umem absolute_end; + u32 end; + u32 absolute_end; b32 separated; b32 use_termination_character; char terminator; @@ -415,7 +409,7 @@ typedef struct Gap_Buffer_Stream{ static Gap_Buffer_Stream null_buffer_stream = {0}; internal b32 -buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, umem start, umem end){ +buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, u32 start, u32 end){ b32 result = false; if (0 <= start && start < end && end <= buffer->size1 + buffer->size2){ @@ -488,7 +482,7 @@ buffer_stringify_next(Gap_Buffer_Stream *stream){ } internal b32 -buffer_replace_range(Gap_Buffer *buffer, u32 start, u32 end, char *str, u32 len, i32 *shift_amount, void *scratch, umem scratch_memory, umem *request_amount){ +buffer_replace_range(Gap_Buffer *buffer, u32 start, u32 end, char *str, u32 len, i32 *shift_amount, void *scratch, u32 scratch_memory, u32 *request_amount){ char *data = buffer->data; u32 size = buffer_size(buffer); b32 result = false; @@ -497,7 +491,7 @@ buffer_replace_range(Gap_Buffer *buffer, u32 start, u32 end, char *str, u32 len, assert(start <= end); assert(end <= size); - umem target_length = end - start; + u32 target_length = end - start; if (target_length <= max_i32 && len <= max_i32){ if (len >= target_length){ @@ -508,7 +502,7 @@ buffer_replace_range(Gap_Buffer *buffer, u32 start, u32 end, char *str, u32 len, } if (*shift_amount + size <= buffer->max){ - umem move_size = 0; + u32 move_size = 0; if (end < buffer->size1){ move_size = buffer->size1 - end; memmove(data + buffer->size1 + buffer->gap_size - move_size, data + end, move_size); @@ -531,7 +525,7 @@ buffer_replace_range(Gap_Buffer *buffer, u32 start, u32 end, char *str, u32 len, assert(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max); } else{ - *request_amount = l_round_up_umem(2*(*shift_amount + size), KB(4)); + *request_amount = l_round_up_u32(2*(*shift_amount + size), KB(4)); result = true; } } @@ -546,7 +540,7 @@ typedef struct Buffer_Batch_State{ // TODO(allen): Now that we are just using Gap_Buffer we could afford to improve this for the Gap_Buffer's behavior. internal b32 -buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, char *strings, u32 edit_count, void *scratch, umem scratch_size, umem *request_amount){ +buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, char *strings, u32 edit_count, void *scratch, u32 scratch_size, u32 *request_amount){ Buffer_Edit *edit = 0; u32 i = state->i; i32 shift_total = state->shift_total; @@ -573,10 +567,10 @@ buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edi } internal void* -buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, umem new_max){ +buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, u32 new_max){ void *result = buffer->data; - umem size = buffer_size_umem(buffer); - umem new_gap_size = new_max - size; + u32 size = buffer_size(buffer); + u32 new_gap_size = new_max - size; assert(new_max >= size); @@ -595,14 +589,14 @@ buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, umem new_max){ // inline void -buffer_stringify(Gap_Buffer *buffer, umem start, umem end, char *out){ +buffer_stringify(Gap_Buffer *buffer, u32 start, u32 end, char *out){ Gap_Buffer_Stream stream = {0}; - umem i = start; + u32 i = start; if (buffer_stringify_loop(&stream, buffer, i, end)){ b32 still_looping = false; do{ - umem size = stream.end - i; + u32 size = stream.end - i; memcpy(out, stream.data + i, size); i = stream.end; out += size; @@ -611,19 +605,19 @@ buffer_stringify(Gap_Buffer *buffer, umem start, umem end, char *out){ } } -internal umem -buffer_convert_out(Gap_Buffer *buffer, char *dest, umem max){ +internal u32 +buffer_convert_out(Gap_Buffer *buffer, char *dest, u32 max){ Gap_Buffer_Stream stream = {0}; u32 size = buffer_size(buffer); assert(size + buffer->line_count <= max); - umem pos = 0; + u32 pos = 0; if (buffer_stringify_loop(&stream, buffer, 0, size)){ - umem i = 0; + u32 i = 0; b32 still_looping = false; do{ - umem chunk_size = stream.end - i; - umem out_size = 0; + u32 chunk_size = stream.end - i; + u32 out_size = 0; b32 result = eol_convert_out(dest + pos, max - pos, stream.data + i, chunk_size, &out_size); assert(result); i = stream.end; @@ -734,8 +728,8 @@ buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap stream.use_termination_character = 1; stream.terminator = '\n'; - umem size = buffer_size(buffer); - umem i = 0; + u32 size = buffer_size(buffer); + u32 i = 0; if (buffer_stringify_loop(&stream, buffer, i, size)){ b32 still_looping = false; do{ @@ -1132,8 +1126,8 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G } internal void -buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 line_shift, f32 *wraps, f32 font_height, f32 *adv, f32 max_width){ - umem new_line_count = buffer->line_count; +buffer_remeasure_wrap_y(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 line_shift, f32 *wraps, f32 font_height, f32 *adv, f32 max_width){ + u32 new_line_count = buffer->line_count; assert(0 <= start_line); assert(start_line <= end_line); @@ -1142,8 +1136,8 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 ++end_line; // Shift - umem line_count = new_line_count; - umem new_end_line = end_line; + u32 line_count = new_line_count; + u32 new_end_line = end_line; if (line_shift != 0){ line_count -= line_shift; new_end_line += line_shift; @@ -1153,9 +1147,9 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 // Iteration data (yikes! Need better loop system) Gap_Buffer_Stream stream = {0}; - umem size = buffer_size(buffer); - umem char_i = buffer->line_starts[start_line]; - umem line_i = start_line; + u32 size = buffer_size(buffer); + u32 char_i = buffer->line_starts[start_line]; + u32 line_i = start_line; // Line wrap measurement f32 last_wrap = wraps[line_i]; @@ -1268,11 +1262,11 @@ buffer_get_line_index_from_wrapped_y(u32 *wrap_line_index, f32 y, i32 line_heigh } internal Partial_Cursor -buffer_partial_from_pos(Gap_Buffer *buffer, umem pos){ +buffer_partial_from_pos(Gap_Buffer *buffer, u32 pos){ Partial_Cursor result = {0}; u32 size = buffer_size(buffer); - pos = clamp_umem(0, pos, size); + pos = clamp_u32(0, pos, size); u32 line_index = buffer_get_line_index_range(buffer, (u32)pos, 0, (u32)buffer->line_count); result.pos = pos; @@ -1283,10 +1277,10 @@ buffer_partial_from_pos(Gap_Buffer *buffer, umem pos){ } internal Partial_Cursor -buffer_partial_from_line_character(Gap_Buffer *buffer, umem line, umem character, b32 reversed){ +buffer_partial_from_line_character(Gap_Buffer *buffer, u32 line, u32 character, b32 reversed){ Partial_Cursor result = {0}; - umem line_index = line - 1; + u32 line_index = line - 1; if (line_index >= buffer->line_count){ line_index = buffer->line_count - 1; } @@ -1294,16 +1288,16 @@ buffer_partial_from_line_character(Gap_Buffer *buffer, umem line, umem character line_index = 0; } - umem size = buffer_size(buffer); + u32 size = buffer_size(buffer); - umem this_start = buffer->line_starts[line_index]; - umem max_character = (size-this_start) + 1; + u32 this_start = buffer->line_starts[line_index]; + u32 max_character = (size-this_start) + 1; if (line_index+1 < buffer->line_count){ - umem next_start = buffer->line_starts[line_index+1]; + u32 next_start = buffer->line_starts[line_index+1]; max_character = (next_start-this_start); } - umem adjusted_pos = 0; + u32 adjusted_pos = 0; if (character > 0){ if (reversed){ if (character > max_character){ @@ -1437,7 +1431,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa default: InvalidCodePath; } - umem safe_line_index = line_index; + u32 safe_line_index = line_index; if (line_index >= params.buffer->line_count){ safe_line_index = params.buffer->line_count-1; } @@ -1466,9 +1460,9 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa S.next_cursor.unwrapped_x += line_shift; S.next_cursor.wrapped_x += line_shift; - S.stream.use_termination_character = 1; + S.stream.use_termination_character = true; S.stream.terminator = '\n'; - if (buffer_stringify_loop(&S.stream, params.buffer, S.next_cursor.pos, S.size)){ + if (buffer_stringify_loop(&S.stream, params.buffer, (u32)S.next_cursor.pos, S.size)){ do{ for (; S.next_cursor.pos < S.stream.end; ++S.next_cursor.pos){ u8 ch = (u8)S.stream.data[S.next_cursor.pos]; @@ -1713,7 +1707,7 @@ buffer_invert_edit_shift(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inve inverse->len = len; inverse->start = edit.start + shift_amount; inverse->end = edit.start + edit.len + shift_amount; - buffer_stringify(buffer, edit.start, edit.end, strings + pos); + buffer_stringify(buffer, (u32)edit.start, (u32)edit.end, strings + pos); } inline void @@ -1722,7 +1716,7 @@ buffer_invert_edit(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inverse, c } typedef struct Buffer_Invert_Batch{ - umem i; + u32 i; i32 shift_amount; u32 len; } Buffer_Invert_Batch; @@ -1730,7 +1724,7 @@ typedef struct Buffer_Invert_Batch{ internal b32 buffer_invert_batch(Buffer_Invert_Batch *state, Gap_Buffer *buffer, Buffer_Edit *edits, u32 count, Buffer_Edit *inverse, char *strings, u32 *str_pos, u32 max){ i32 shift_amount = state->shift_amount; - umem i = state->i; + u32 i = state->i; Buffer_Edit *edit = edits + i; Buffer_Edit *inv_edit = inverse + i; b32 result = false; @@ -1739,8 +1733,8 @@ buffer_invert_batch(Buffer_Invert_Batch *state, Gap_Buffer *buffer, Buffer_Edit if (*str_pos + edit->end - edit->start <= max){ buffer_invert_edit_shift(buffer, *edit, inv_edit, strings, str_pos, max, shift_amount); - umem target_length = edit->end - edit->start; - umem edit_length = edit->len; + u32 target_length = (u32)(edit->end - edit->start); + u32 edit_length = (u32)edit->len; if (edit_length > target_length){ shift_amount += (i32)(edit_length - target_length); } @@ -1766,7 +1760,7 @@ enum Buffer_Render_Flag{ }; typedef struct Buffer_Render_Item{ - umem index; + u32 index; u32 codepoint; u32 flags; f32 x0, y0; @@ -1784,7 +1778,7 @@ typedef struct Render_Item_Write{ } Render_Item_Write; inline Render_Item_Write -write_render_item(Render_Item_Write write, umem index, u32 codepoint, u32 flags){ +write_render_item(Render_Item_Write write, u32 index, u32 codepoint, u32 flags){ f32 ch_width = font_get_glyph_advance(write.system, write.font, codepoint); if (write.x <= write.x_max && write.x + ch_width >= write.x_min){ @@ -1827,8 +1821,8 @@ struct Buffer_Render_Params{ struct Buffer_Render_State{ Gap_Buffer_Stream stream; b32 still_looping; - umem i; - umem size; + u32 i; + u32 size; f32 shift_x; f32 shift_y; @@ -1838,9 +1832,9 @@ struct Buffer_Render_State{ Render_Item_Write write; f32 byte_advance; - umem line; - umem wrap_line; - umem wrap_unit_end; + u32 line; + u32 wrap_line; + u32 wrap_unit_end; b32 skipping_whitespace; b32 first_of_the_line; @@ -1883,8 +1877,8 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 S.shift_y += params.start_cursor.unwrapped_y; } - S.line = params.start_cursor.line - 1; - S.wrap_line = params.start_cursor.wrap_line - 1; + S.line = (u32)params.start_cursor.line - 1; + S.wrap_line = (u32)params.start_cursor.wrap_line - 1; if (params.virtual_white){ S_stop.status = BLStatus_NeedLineShift; @@ -1909,7 +1903,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 } S.first_of_the_line = 1; - S.i = params.start_cursor.pos; + S.i = (u32)params.start_cursor.pos; if (buffer_stringify_loop(&S.stream, params.buffer, S.i, S.size)){ do{ for (; S.i < S.stream.end; ++S.i){ @@ -1995,7 +1989,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 } if (!S.skipping_whitespace){ - umem I = S.step.i; + u32 I = S.step.i; switch (n){ case '\r': { @@ -2023,7 +2017,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 } else if (S.behavior.do_number_advance){ u8 n = (u8)S.step.value; - umem I = S.step.i; + u32 I = S.step.i; S.skipping_whitespace = false; S.ch_width = S.byte_advance; diff --git a/4ed_buffer_model.h b/4ed_buffer_model.h index a9abc718..7f7df32a 100644 --- a/4ed_buffer_model.h +++ b/4ed_buffer_model.h @@ -15,7 +15,7 @@ struct Buffer_Model_Step{ u32 type; u32 value; - umem i; + u32 i; u32 byte_length; }; diff --git a/4ed_file.cpp b/4ed_file.cpp index 7e407e53..c2778da9 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -21,7 +21,7 @@ enum Edit_Pos_Set_Type{ struct File_Edit_Positions{ GUI_Scroll_Vars scroll; Full_Cursor cursor; - umem mark; + u32 mark; f32 preferred_x; i32 scroll_i; i32 last_set_type; @@ -385,13 +385,13 @@ edit_pos_get_new(Editing_File *file, i32 index){ // inline Partial_Cursor -file_compute_cursor_from_pos(Editing_File *file, umem pos){ +file_compute_cursor_from_pos(Editing_File *file, u32 pos){ Partial_Cursor result = buffer_partial_from_pos(&file->state.buffer, pos); return(result); } inline Partial_Cursor -file_compute_cursor_from_line_character(Editing_File *file, umem line, umem character, b32 reversed){ +file_compute_cursor_from_line_character(Editing_File *file, u32 line, u32 character, b32 reversed){ Partial_Cursor result = buffer_partial_from_line_character(&file->state.buffer, line, character, reversed); return(result); } @@ -402,17 +402,17 @@ file_compute_partial_cursor(Editing_File *file, Buffer_Seek seek, Partial_Cursor switch (seek.type){ case buffer_seek_pos: { - *cursor = file_compute_cursor_from_pos(file, seek.pos); + *cursor = file_compute_cursor_from_pos(file, (u32)seek.pos); }break; case buffer_seek_line_char: { - *cursor = file_compute_cursor_from_line_character(file, seek.line, seek.character, true); + *cursor = file_compute_cursor_from_line_character(file, (u32)seek.line, (u32)seek.character, true); }break; case buffer_seek_line_reverse_char: { - *cursor = file_compute_cursor_from_line_character(file, seek.line, seek.character, false); + *cursor = file_compute_cursor_from_line_character(file, (u32)seek.line, (u32)seek.character, false); }break; default: diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 0e3c5b2f..be69bfbd 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -146,7 +146,7 @@ struct File_Viewing_Data{ Editing_File *file; Full_Cursor temp_highlight; - umem temp_highlight_end_pos; + u32 temp_highlight_end_pos; b32 show_temp_highlight; b32 show_whitespace; @@ -289,14 +289,14 @@ view_file_height(View *view){ return (result); } -inline size_t +inline u32 view_get_cursor_pos(View *view){ - size_t result = 0; + u32 result = 0; if (view->file_data.show_temp_highlight){ - result = view->file_data.temp_highlight.pos; + result = (u32)view->file_data.temp_highlight.pos; } else if (view->edit_pos){ - result = view->edit_pos->cursor.pos; + result = (u32)view->edit_pos->cursor.pos; } return(result); } @@ -402,7 +402,7 @@ view_compute_cursor(System_Functions *system, View *view, Buffer_Seek seek, b32 Buffer_Cursor_Seek_State state = {0}; Buffer_Layout_Stop stop = {0}; - umem size = buffer_size(params.buffer); + u32 size = buffer_size(params.buffer); f32 line_shift = 0.f; u32 wrap_unit_end = 0; @@ -619,7 +619,7 @@ view_set_cursor_and_scroll(View *view, Full_Cursor cursor, b32 set_preferred_x, } inline void -view_set_temp_highlight(System_Functions *system, View *view, umem pos, umem end_pos){ +view_set_temp_highlight(System_Functions *system, View *view, u32 pos, u32 end_pos){ view->file_data.temp_highlight = view_compute_cursor(system, view, seek_pos(pos), 0); view->file_data.temp_highlight_end_pos = end_pos; view->file_data.show_temp_highlight = 1; @@ -741,7 +741,7 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, models->hook_save_file(&models->app_links, file->id.id); } - umem max = 0, size = 0; + u32 max = 0, size = 0; b32 dos_write_mode = file->settings.dos_write_mode; Gap_Buffer *buffer = &file->state.buffer; @@ -779,7 +779,7 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, if (!using_actual_filename && file->canon.name.str != 0){ char space[512]; u32 length = str_size(filename); - system->get_canonical(filename, length, space, sizeof(space)); + system->get_canonical((u8*)filename, length, (u8*)space, sizeof(space)); char *source_path = file->canon.name.str; if (match(space, source_path)){ @@ -877,7 +877,7 @@ file_update_cursor_positions(System_Functions *system, Models *models, Editing_F for (View_Iter iter = file_view_iter_init(layout, file, 0); file_view_iter_good(iter); iter = file_view_iter_next(iter)){ - umem pos = view_get_cursor_pos(iter.view); + u32 pos = view_get_cursor_pos(iter.view); if (!iter.view->file_data.show_temp_highlight){ Full_Cursor cursor = view_compute_cursor(system, iter.view, seek_pos(pos), 0); @@ -997,8 +997,8 @@ struct Code_Wrap_State{ b32 consume_newline; Gap_Buffer_Stream stream; - umem size; - umem i; + u32 size; + u32 i; Render_Font *font; f32 tab_indent_amount; @@ -1052,8 +1052,8 @@ wrap_state_set_top(Code_Wrap_State *state, f32 line_shift){ } struct Code_Wrap_Step{ - umem position_start; - umem position_end; + u32 position_start; + u32 position_end; f32 start_x; f32 final_x; @@ -1062,9 +1062,9 @@ struct Code_Wrap_Step{ }; internal Code_Wrap_Step -wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_State *state, i32 fixed_end_point){ +wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_State *state, u32 fixed_end_point){ Code_Wrap_Step result = {0}; - umem i = state->i; + u32 i = state->i; result.position_start = i; @@ -1102,9 +1102,9 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_ state->next_line_start = state->line_starts[state->line_index + 1]; } - i32 line_start = state->line_starts[state->line_index]; + u32 line_start = state->line_starts[state->line_index]; b32 still_looping = 0; - i32 end = state->token_ptr->start + state->token_ptr->size; + u32 end = state->token_ptr->start + state->token_ptr->size; if (fixed_end_point >= 0 && end > fixed_end_point){ end = fixed_end_point; @@ -1234,7 +1234,7 @@ struct Wrap_Indent_Pair{ }; struct Potential_Wrap_Indent_Pair{ - i32 wrap_position; + u32 wrap_position; f32 line_shift; f32 wrap_x; @@ -1498,8 +1498,8 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, potential_marks = push_array(part, Potential_Wrap_Indent_Pair, floor32(width)); - umem remaining = partition_remaining(part); - umem pair_size = sizeof(Wrap_Indent_Pair); + u32 remaining = (u32)partition_remaining(part); + u32 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); } @@ -1530,8 +1530,8 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, else{ Gap_Buffer_Stream stream = {0}; - i32 word_stage = 0; - i32 i = stop.pos; + u32 word_stage = 0; + u32 i = stop.pos; f32 x = stop.x; f32 self_x = 0; if (buffer_stringify_loop(&stream, params.buffer, i, size)){ @@ -1826,7 +1826,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, } } - i32 wrap_position = potential_marks[best_i].wrap_position; + u32 wrap_position = potential_marks[best_i].wrap_position; f32 line_shift = potential_marks[best_i].line_shift; b32 adjust_top_to_this = potential_marks[best_i].adjust_top_to_this; wrap_indent_marks[real_count].wrap_position = wrap_position; @@ -1931,8 +1931,8 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * file->state = null_editing_file_state; Gap_Buffer_Init init = buffer_begin_init(&file->state.buffer, val.str, val.size); for (; buffer_init_need_more(&init); ){ - umem page_size = buffer_init_page_size(&init); - page_size = l_round_up_umem(page_size, KB(4)); + u32 page_size = buffer_init_page_size(&init); + page_size = l_round_up_u32(page_size, KB(4)); if (page_size < KB(4)){ page_size = KB(4); } @@ -1940,7 +1940,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * buffer_init_provide_page(&init, data, page_size); } - umem scratch_size = partition_remaining(part); + u32 scratch_size = (u32)partition_remaining(part); Assert(scratch_size > 0); b32 init_success = buffer_end_init(&init, part->base + part->pos, scratch_size); AllowLocal(init_success); Assert(init_success); @@ -2048,7 +2048,7 @@ Job_Callback_Sig(job_full_lex){ u32 text_size = buffer_size(buffer); u32 aligned_buffer_size = (text_size + 3)&(~3); - while (memory->size < (umem)aligned_buffer_size){ + while (memory->size < aligned_buffer_size){ system->grow_thread_memory(memory); } @@ -2063,7 +2063,7 @@ Job_Callback_Sig(job_full_lex){ // TODO(allen): deduplicate this against relex char *chunks[3]; - umem chunk_sizes[3]; + u32 chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2078,7 +2078,7 @@ Job_Callback_Sig(job_full_lex){ do{ char *chunk = chunks[chunk_index]; - umem chunk_size = chunk_sizes[chunk_index]; + u32 chunk_size = chunk_sizes[chunk_index]; i32 result = cpp_lex_step(&lex, chunk, (i32)chunk_size, text_size, &tokens, 2048); @@ -2192,7 +2192,7 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ Gap_Buffer *buffer = &file->state.buffer; i32 text_size = buffer_size(buffer); - umem mem_size = partition_remaining(part); + u32 mem_size = (u32)partition_remaining(part); Cpp_Token_Array tokens; tokens.max_count = (u32)(mem_size / sizeof(Cpp_Token)); @@ -2205,7 +2205,7 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ // TODO(allen): deduplicate this against relex char *chunks[3]; - umem chunk_sizes[3]; + u32 chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2222,7 +2222,7 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ do{ char *chunk = chunks[chunk_index]; - umem chunk_size = chunk_sizes[chunk_index]; + u32 chunk_size = chunk_sizes[chunk_index]; i32 result = cpp_lex_step(&lex, chunk, (i32)chunk_size, text_size, &tokens, NO_OUT_LIMIT); @@ -2313,7 +2313,7 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi Cpp_Relex_Data state = cpp_relex_init(array, start_i, end_i, shift_amount); char *chunks[3]; - umem chunk_sizes[3]; + u32 chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2326,7 +2326,7 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi i32 chunk_index = 0; char *chunk = chunks[chunk_index]; - umem chunk_size = chunk_sizes[chunk_index]; + u32 chunk_size = chunk_sizes[chunk_index]; while (!cpp_relex_is_start_chunk(&state, chunk, (i32)chunk_size)){ ++chunk_index; @@ -2421,8 +2421,8 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, Gap_Buffer *buffer = &file->state.buffer; Cpp_Token_Array *array = &file->state.token_array; - umem remaining = partition_remaining(part); - umem token_size = sizeof(Cpp_Token); + u32 remaining = (u32)partition_remaining(part); + u32 token_size = sizeof(Cpp_Token); Temp_Memory temp = begin_temp_memory(part); Cpp_Token_Array relex_array; @@ -2435,7 +2435,7 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, Cpp_Relex_Data state = cpp_relex_init(array, start_i, end_i, shift_amount); char *chunks[3]; - umem chunk_sizes[3]; + u32 chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2446,9 +2446,9 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, chunks[2] = 0; chunk_sizes[2] = 0; - umem chunk_index = 0; + u32 chunk_index = 0; char *chunk = chunks[chunk_index]; - umem chunk_size = chunk_sizes[chunk_index]; + u32 chunk_size = chunk_sizes[chunk_index]; while (!cpp_relex_is_start_chunk(&state, chunk, (i32)chunk_size)){ ++chunk_index; @@ -2488,7 +2488,7 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, } internal void -undo_stack_grow_string(General_Memory *general, Edit_Stack *stack, umem extra_size){ +undo_stack_grow_string(General_Memory *general, Edit_Stack *stack, u32 extra_size){ u32 old_max = stack->max; u8 *old_str = stack->strings; u32 new_max = old_max*2 + (u32)(extra_size); @@ -2508,27 +2508,27 @@ undo_stack_grow_edits(General_Memory *general, Edit_Stack *stack){ } internal void -child_stack_grow_string(General_Memory *general, Small_Edit_Stack *stack, umem extra_size){ - umem old_max = stack->max; +child_stack_grow_string(General_Memory *general, Small_Edit_Stack *stack, u32 extra_size){ + u32 old_max = stack->max; u8 *old_str = stack->strings; - umem new_max = old_max*2 + extra_size; + u32 new_max = old_max*2 + extra_size; u8 *new_str = (u8*)general_memory_reallocate(general, old_str, old_max, new_max); stack->strings = new_str; stack->max = (u32)new_max; } internal void -child_stack_grow_edits(General_Memory *general, Small_Edit_Stack *stack, umem amount){ - umem old_max = stack->edit_max; +child_stack_grow_edits(General_Memory *general, Small_Edit_Stack *stack, u32 amount){ + u32 old_max = stack->edit_max; Buffer_Edit *old_eds = stack->edits; - umem new_max = old_max*2 + amount; + u32 new_max = old_max*2 + amount; Buffer_Edit *new_eds = (Buffer_Edit*)general_memory_reallocate(general, old_eds, old_max*sizeof(Buffer_Edit), new_max*sizeof(Buffer_Edit)); stack->edits = new_eds; stack->edit_max = (u32)new_max; } internal i32 -undo_children_push(General_Memory *general, Small_Edit_Stack *children, Buffer_Edit *edits, u32 edit_count, u8 *strings, umem string_size){ +undo_children_push(General_Memory *general, Small_Edit_Stack *children, Buffer_Edit *edits, u32 edit_count, u8 *strings, u32 string_size){ i32 result = children->edit_count; if (children->edit_count + edit_count > children->edit_max){ child_stack_grow_edits(general, children, edit_count); @@ -2570,7 +2570,7 @@ file_post_undo(General_Memory *general, Editing_File *file, Edit_Step step, b32 if (step.child_count == 0){ if (step.edit.end - step.edit.start + undo->size > undo->max){ - undo_stack_grow_string(general, undo, step.edit.end - step.edit.start); + undo_stack_grow_string(general, undo, (u32)(step.edit.end - step.edit.start)); } Buffer_Edit inv; @@ -2639,7 +2639,7 @@ file_post_redo(General_Memory *general, Editing_File *file, Edit_Step step){ if (step.child_count == 0){ if (step.edit.end - step.edit.start + redo->size > redo->max){ - undo_stack_grow_string(general, redo, step.edit.end - step.edit.start); + undo_stack_grow_string(general, redo, (u32)(step.edit.end - step.edit.start)); } Buffer_Edit inv; @@ -2707,7 +2707,7 @@ file_post_history(General_Memory *general, Editing_File *file, Edit_Step step, b if (step.child_count == 0){ if (step.edit.end - step.edit.start + history->size > history->max){ - undo_stack_grow_string(general, history, step.edit.end - step.edit.start); + undo_stack_grow_string(general, history, (u32)(step.edit.end - step.edit.start)); } Buffer_Edit inv; @@ -2780,7 +2780,7 @@ view_cursor_move(View *view, Full_Cursor cursor){ } inline void -view_cursor_move(System_Functions *system, View *view, umem pos){ +view_cursor_move(System_Functions *system, View *view, u32 pos){ Full_Cursor cursor = view_compute_cursor(system, view, seek_pos(pos), 0); view_cursor_move(view, cursor); } @@ -3106,8 +3106,8 @@ file_edit_cursor_fix(System_Functions *system, Models *models, Editing_File *fil Cursor_With_Index *r_cursors = push_array(part, Cursor_With_Index, cursor_max); Assert(cursors != 0); - i32 cursor_count = 0; - i32 r_cursor_count = 0; + u32 cursor_count = 0; + u32 r_cursor_count = 0; View *view = 0; Panel *panel = 0, *used_panels = &layout->used_sentinel; @@ -3115,9 +3115,9 @@ file_edit_cursor_fix(System_Functions *system, Models *models, Editing_File *fil view = panel->view; if (view->file_data.file == file){ Assert(view->edit_pos); - write_cursor_with_index(cursors, &cursor_count, view->edit_pos->cursor.pos); - write_cursor_with_index(cursors, &cursor_count, view->edit_pos->mark); - write_cursor_with_index(cursors, &cursor_count, view->edit_pos->scroll_i); + write_cursor_with_index(cursors, &cursor_count, (u32)view->edit_pos->cursor.pos); + write_cursor_with_index(cursors, &cursor_count, (u32)view->edit_pos->mark); + write_cursor_with_index(cursors, &cursor_count, (u32)view->edit_pos->scroll_i); } } @@ -3128,10 +3128,10 @@ file_edit_cursor_fix(System_Functions *system, Models *models, Editing_File *fil Marker *markers = &marker_it->marker_0; for (u32 i = 0; i < count; ++i){ if (markers[i].lean_right){ - write_cursor_with_index(r_cursors, &r_cursor_count, markers[i].pos); + write_cursor_with_index(r_cursors, &r_cursor_count, (u32)markers[i].pos); } else{ - write_cursor_with_index(cursors, &cursor_count, markers[i].pos); + write_cursor_with_index(cursors, &cursor_count, (u32)markers[i].pos); } } } @@ -3157,7 +3157,7 @@ file_edit_cursor_fix(System_Functions *system, Models *models, Editing_File *fil if (view->file_data.file == file){ Assert(view->edit_pos); - umem cursor_pos = cursors[cursor_count++].pos; + u32 cursor_pos = cursors[cursor_count++].pos; Full_Cursor new_cursor = view_compute_cursor(system, view, seek_pos(cursor_pos), 0); GUI_Scroll_Vars scroll = view->edit_pos->scroll; @@ -3223,10 +3223,10 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file u32 end = (u32)spec.step.edit.end; u32 str_len = (u32)spec.step.edit.len; - umem scratch_size = partition_remaining(part); + u32 scratch_size = (u32)partition_remaining(part); Assert(scratch_size > 0); - umem request_amount = 0; + u32 request_amount = 0; Assert(end <= buffer_size(&file->state.buffer)); while (buffer_replace_range(&file->state.buffer, start, end, str, str_len, &shift_amount, part->base + part->pos, scratch_size, &request_amount)){ void *new_data = 0; @@ -3303,7 +3303,7 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, u32 scratch_size = (u32)partition_remaining(part); Buffer_Batch_State state = {0}; - umem request_amount = 0; + u32 request_amount = 0; while (buffer_batch_edit_step(&state, &file->state.buffer, batch, (char*)str_base, batch_size, part->base + part->pos, scratch_size, &request_amount)){ @@ -3354,8 +3354,8 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, for (; token < end_token; ++token){ original = *token; for (; edit < end_edit && edit->start <= original.start; ++edit){ - umem target_length = edit->end - edit->start; - umem edit_length = edit->len; + u32 target_length = (u32)(edit->end - edit->start); + u32 edit_length = (u32)edit->len; if (edit_length > target_length){ local_shift = (i32)(edit_length - target_length); } @@ -3367,8 +3367,8 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, token->start += shift_amount; local_shift = 0; for (; edit < end_edit && edit->start < original.start + original.size; ++edit){ - umem target_length = edit->end - edit->start; - umem edit_length = edit->len; + u32 target_length = (u32)(edit->end - edit->start); + u32 edit_length = (u32)edit->len; if (edit_length > target_length){ local_shift = (i32)(edit_length - target_length); } @@ -3464,8 +3464,8 @@ apply_history_edit(System_Functions *system, Models *models, Editing_File *file, file_do_single_edit(system, models, file, spec, history_mode); if (view){ - view_cursor_move(system, view, step.edit.start + step.edit.len); - view->edit_pos->mark = view->edit_pos->cursor.pos; + view_cursor_move(system, view, (u32)(step.edit.start + step.edit.len)); + view->edit_pos->mark = (u32)view->edit_pos->cursor.pos; Style *style = main_style(models); view_post_paste_effect(view, 0.333f, (u32)step.edit.start, (u32)step.edit.len, style->main.undo_color); @@ -3594,15 +3594,15 @@ working_set_clipboard_roll_down(Working_Set *working){ internal void clipboard_copy(System_Functions *system, General_Memory *general, Working_Set *working, Range range, Editing_File *file){ - umem size = range.end - range.start; + u32 size = (u32)(range.end - range.start); String *dest = working_set_next_clipboard_string(general, working, (u32)size); - buffer_stringify(&file->state.buffer, range.start, range.end, dest->str); + buffer_stringify(&file->state.buffer, (u32)range.start, (u32)range.end, dest->str); dest->size = (i32)size; system->post_clipboard(*dest); } internal Edit_Spec -file_compute_edit(Mem_Options *mem, Editing_File *file, Buffer_Edit *edits, char *str_base, umem str_size, Buffer_Edit *inverse_array, char *inv_str, u32 inv_max, u32 edit_count, i32 batch_type){ +file_compute_edit(Mem_Options *mem, Editing_File *file, Buffer_Edit *edits, char *str_base, u32 str_size, Buffer_Edit *inverse_array, char *inv_str, u32 inv_max, u32 edit_count, i32 batch_type){ General_Memory *general = &mem->general; u32 inv_str_pos = 0; @@ -4260,7 +4260,7 @@ get_exhaustive_info(System_Functions *system, Working_Set *working_set, Exhausti result.info = loop->infos + i; loop->full_path.size = loop->r; - append_sc(&loop->full_path, result.info->filename); + append_sc(&loop->full_path, (char*)result.info->filename); terminate_with_null(&loop->full_path); Editing_File *file = working_set_canon_contains(working_set, loop->full_path); @@ -4493,16 +4493,6 @@ show_gui_u64(GUI_Target *target, String *string, i32 indent_level, i32 h_align, gui_do_text_field(target, *string, null_string); } -internal void -show_gui_umem(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message, umem x){ - string->size = 0; - append_label(string, indent_level, message); - append_padding(string, '-', h_align); - append_s_char(string, ' '); - append_u64_to_str(string, x); - gui_do_text_field(target, *string, null_string); -} - internal void show_gui_int_int(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message, i32 x, i32 m){ string->size = 0; @@ -4556,9 +4546,9 @@ show_gui_scroll(GUI_Target *target, String *string, internal void show_gui_cursor(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message,Full_Cursor cursor){ show_gui_line (target, string, indent_level , 0, message, 0); - show_gui_umem (target, string, indent_level+1, h_align, " pos ", cursor.pos); - show_gui_umem (target, string, indent_level+1, h_align, " line ", cursor.line); - show_gui_umem (target, string, indent_level+1, h_align, " column ", cursor.character); + show_gui_u64 (target, string, indent_level+1, h_align, " pos ", cursor.pos); + show_gui_u64 (target, string, indent_level+1, h_align, " line ", cursor.line); + show_gui_u64 (target, string, indent_level+1, h_align, " column ", cursor.character); show_gui_float(target, string, indent_level+1, h_align, " unwrapped_x ", cursor.unwrapped_x); show_gui_float(target, string, indent_level+1, h_align, " unwrapped_y ", cursor.unwrapped_y); show_gui_float(target, string, indent_level+1, h_align, " wrapped_x ", cursor.wrapped_x); @@ -4993,13 +4983,13 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su if (file_info.name_match){ id.id[0] = (u64)(file_info.info); - char *str = file_info.info->filename; + char *str = (char*)file_info.info->filename; i32 len = file_info.info->filename_len; String filename = make_string_cap(str, len, len + 1); if (gui_do_file_option(target, id, filename, file_info.is_folder, file_info.message)){ if (file_info.is_folder){ - set_last_folder_sc(&hdir->string, file_info.info->filename, '/'); + set_last_folder_sc(&hdir->string, (char*)file_info.info->filename, '/'); do_new_directory = 1; } @@ -5470,7 +5460,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su #define SHOW_GUI_INT(n, h, str, v) show_gui_int(target, &string, n, h, " " str " ", v) #define SHOW_GUI_INT_INT(n, h, str, v, m) show_gui_int_int(target, &string, n, h, " " str " ", v, m) #define SHOW_GUI_U64(n, h, str, v) show_gui_u64(target, &string, n, h, " " str " ", v) -#define SHOW_GUI_UMEM(n, h, str, v) show_gui_umem(target, &string, n, h, " " str " ", v) #define SHOW_GUI_ID(n, h, str, v) show_gui_id(target, &string, n, h, " " str, v) #define SHOW_GUI_FLOAT(n, h, str, v) show_gui_float(target, &string, n, h, " " str " ", v) #define SHOW_GUI_BOOL(n, h, str, v) do { if (v) { show_gui_line(target, &string, n, h, " " str " ", "true"); }\ @@ -5510,8 +5499,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su SHOW_GUI_LINE(1, "file data:"); SHOW_GUI_BOOL(2, h_align, "has file", view_ptr->file_data.file); SHOW_GUI_BOOL(2, h_align, "show temp highlight", view_ptr->file_data.show_temp_highlight); - SHOW_GUI_UMEM(2, h_align, "start temp highlight", view_ptr->file_data.temp_highlight.pos); - SHOW_GUI_UMEM(2, h_align, "end temp highlight", view_ptr->file_data.temp_highlight_end_pos); + SHOW_GUI_U64(2, h_align, "start temp highlight", view_ptr->file_data.temp_highlight.pos); + SHOW_GUI_U64(2, h_align, "end temp highlight", view_ptr->file_data.temp_highlight_end_pos); SHOW_GUI_BOOL(2, h_align, "show whitespace", view_ptr->file_data.show_whitespace); SHOW_GUI_BOOL(2, h_align, "locked", view_ptr->file_data.file_locked); @@ -5529,7 +5518,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su SHOW_GUI_BLANK (2); SHOW_GUI_CURSOR(2, h_align, "cursor:", edit_pos->cursor); SHOW_GUI_BLANK (2); - SHOW_GUI_UMEM (2, h_align, "mark", edit_pos->mark); + SHOW_GUI_U64 (2, h_align, "mark", edit_pos->mark); SHOW_GUI_FLOAT (2, h_align, "preferred_x", edit_pos->preferred_x); SHOW_GUI_INT (2, h_align, "scroll_i", edit_pos->scroll_i); } @@ -5927,9 +5916,9 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act f32 left_side_space = 0; - umem remaining = partition_remaining(part); - umem render_item_size = sizeof(Buffer_Render_Item); - u32 max = (u32)(remaining / render_item_size); + u32 remaining = (u32)partition_remaining(part); + u32 render_item_size = sizeof(Buffer_Render_Item); + u32 max = remaining / render_item_size; Buffer_Render_Item *items = push_array(part, Buffer_Render_Item, max); Font_ID font_id = file->settings.font_id; @@ -6049,12 +6038,12 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act u32 mark_color = style->main.mark_color; Buffer_Render_Item *item = items; Buffer_Render_Item *item_end = item + count; - umem prev_ind = max_umem; + u32 prev_ind = max_u32; u32 highlight_color = 0; u32 highlight_this_color = 0; for (; item < item_end; ++item){ - umem ind = item->index; + u32 ind = item->index; highlight_this_color = 0; if (tokens_use && ind != prev_ind){ Cpp_Token current_token = token_array.tokens[token_i-1]; diff --git a/4ed_hot_directory.cpp b/4ed_hot_directory.cpp index 889bb6f4..070cde47 100644 --- a/4ed_hot_directory.cpp +++ b/4ed_hot_directory.cpp @@ -34,7 +34,7 @@ hot_directory_quick_partition(File_Info *infos, i32 start, i32 pivot){ i32 comp = 0; comp = p->folder - a->folder; if (comp == 0){ - comp = compare_cc(a->filename, p->filename); + comp = compare_cc((char*)a->filename, (char*)p->filename); } if (comp < 0){ Swap(File_Info, *a, infos[start]); diff --git a/4ed_system.h b/4ed_system.h index e2f12321..89025f84 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -31,7 +31,7 @@ handle_equal(Plat_Handle a, Plat_Handle b){ #define Sys_Set_File_List_Sig(name) void name(File_List *file_list, char *directory, char *canon_directory_out, u32 *canon_directory_size_out, u32 canon_directory_max) typedef Sys_Set_File_List_Sig(System_Set_File_List); -#define Sys_Get_Canonical_Sig(name) u32 name(char *filename, u32 len, char *buffer, u32 max) +#define Sys_Get_Canonical_Sig(name) u32 name(u8 *src, u32 len, u8 *dst, u32 max) typedef Sys_Get_Canonical_Sig(System_Get_Canonical); // file load/save @@ -47,7 +47,7 @@ typedef Sys_Load_File_Sig(System_Load_File); #define Sys_Load_Close_Sig(name) b32 name(Plat_Handle handle) typedef Sys_Load_Close_Sig(System_Load_Close); -#define Sys_Save_File_Sig(name) b32 name(char *filename, char *buffer, umem size) +#define Sys_Save_File_Sig(name) b32 name(char *filename, char *buffer, u32 size) typedef Sys_Save_File_Sig(System_Save_File); // file changes @@ -136,8 +136,8 @@ enum Thread_Group_ID{ struct Thread_Memory{ void *data; - i32 size; - i32 id; + u32 size; + u32 id; }; inline Thread_Memory thread_memory_zero(){ diff --git a/4ed_translation.cpp b/4ed_translation.cpp index e5318d80..259240c0 100644 --- a/4ed_translation.cpp +++ b/4ed_translation.cpp @@ -13,7 +13,7 @@ struct Translation_State{ u8 fill_buffer[4]; - umem fill_start_i; + u32 fill_start_i; u8 fill_i; u8 fill_expected; }; @@ -47,7 +47,7 @@ struct Translation_Emits{ #define SINGLE_BYTE_ERROR_CLASS max_u8 internal void -translating_consume_byte(Translation_State *tran, u8 ch, umem i, umem size, Translation_Byte_Description *desc_out){ +translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Byte_Description *desc_out){ desc_out->byte_class = 0; if ((ch >= ' ' && ch < 0x7F) || ch == '\t' || ch == '\n' || ch == '\r'){ desc_out->byte_class = 1; @@ -146,7 +146,7 @@ translating_select_emit_rule_with_font(System_Functions *system, Render_Font *fo } internal void -translating_generate_emits(Translation_State *tran, Translation_Emit_Rule emit_rule, u8 ch, umem i, Translation_Emits *emits_out){ +translating_generate_emits(Translation_State *tran, Translation_Emit_Rule emit_rule, u8 ch, u32 i, Translation_Emits *emits_out){ emits_out->step_count = 0; switch (emit_rule.emit_type){ default: goto skip_all; @@ -199,7 +199,7 @@ translating_generate_emits(Translation_State *tran, Translation_Emit_Rule emit_r } internal void -translating_fully_process_byte(System_Functions *system, Render_Font *font, Translation_State *tran, u8 ch, umem i, umem size, Translation_Emits *emits_out){ +translating_fully_process_byte(System_Functions *system, Render_Font *font, Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Emits *emits_out){ Translation_Byte_Description description = {0}; translating_consume_byte(tran, ch, i, size, &description); Translation_Emit_Rule emit_rule = {0}; diff --git a/4ed_working_set.cpp b/4ed_working_set.cpp index 55dca405..cd1019d6 100644 --- a/4ed_working_set.cpp +++ b/4ed_working_set.cpp @@ -360,7 +360,7 @@ internal b32 get_canon_name(System_Functions *system, Editing_File_Canon_Name *canon_name, String filename){ canon_name->name = make_fixed_width_string(canon_name->name_); - canon_name->name.size = system->get_canonical(filename.str, filename.size, canon_name->name.str, canon_name->name.memory_size); + canon_name->name.size = system->get_canonical((u8*)filename.str, filename.size, (u8*)canon_name->name.str, canon_name->name.memory_size); terminate_with_null(&canon_name->name); b32 result = (canon_name->name.size != 0); diff --git a/pens_arena.cpp b/pens_arena.cpp deleted file mode 100644 index 1f6c46f8..00000000 --- a/pens_arena.cpp +++ /dev/null @@ -1,14 +0,0 @@ -/* -Build target for the 'pens' project. -By Allen Webster -Created 09.01.2017 (dd.mm.yyyy) -*/ - -// TOP - -struct Arena{ - -}; - -// BOTTOM - diff --git a/power/4coder_experiments.cpp b/power/4coder_experiments.cpp index a1ea1720..8092a03a 100644 --- a/power/4coder_experiments.cpp +++ b/power/4coder_experiments.cpp @@ -1409,11 +1409,8 @@ get_bindings(void *data, int32_t size){ bind(context, 'k', MDFR_ALT, kill_rect); bind(context, ' ', MDFR_ALT | MDFR_CTRL, multi_line_edit); - bind(context, key_page_up, MDFR_ALT, miblo_increment_time_stamp); - bind(context, key_page_down, MDFR_ALT, miblo_decrement_time_stamp); - - bind(context, key_home, MDFR_ALT, miblo_increment_time_stamp_minute); - bind(context, key_end, MDFR_ALT, miblo_decrement_time_stamp_minute); + bind(context, key_page_up, MDFR_ALT, miblo_increment_basic); + bind(context, key_page_down, MDFR_ALT, miblo_decrement_basic); end_map(context); diff --git a/win32_4ed.cpp b/win32_4ed.cpp index b2bd7a69..d97ed6a7 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -284,7 +284,7 @@ Sys_Memory_Free_Sig(system_memory_free){ } #define Win32GetMemory(size) system_memory_allocate(size) -#define Win32FreeMemory(ptr) system_memory_free(ptr) +#define Win32FreeMemory(ptr) system_memory_free(ptr, 0) #define Win32ScratchPartition sysshared_scratch_partition #define Win32ScratchPartitionGrow sysshared_partition_grow @@ -721,14 +721,17 @@ Sys_File_Can_Be_Made_Sig(system_file_can_be_made){ Partition *scratch = &shared_vars.scratch; Temp_Memory temp = begin_temp_memory(scratch); - umem len = str_size(filename); - umem max = (len+1)*2; - u16 *filename_16 = push_array(scratch, u16, max); + u32 len = str_size(filename); + u32 filename_16_max = (len+1)*2; + u16 *filename_16 = push_array(scratch, u16, filename_16_max); - b32 error = false; - utf8_to_utf16_minimal_checking(filename_16, max, (u8*)filename, len, &error); + b32 convert_error = false; + u32 filename_16_len = (u32)utf8_to_utf16_minimal_checking(filename_16, filename_16_max-1, (u8*)filename, len, &convert_error); + filename_16[filename_16_len] = 0;; - if (!error){ + if (!convert_error){ + filename_16[filename_16_len] = 0; + HANDLE file = CreateFile((LPCWSTR)filename_16, FILE_APPEND_DATA, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (file != 0 && file != INVALID_HANDLE_VALUE){ @@ -813,13 +816,14 @@ Sys_Set_File_List_Sig(system_set_file_list){ u32 required_size = character_count*2 + file_count * sizeof(File_Info); if (file_list->block_size < (i32)required_size){ - system_memory_free(file_list->block, 0); + Win32FreeMemory(file_list->block); file_list->block = system_memory_allocate(required_size); file_list->block_size = required_size; } + umem remaining_size = required_size; file_list->infos = (File_Info*)file_list->block; - char *name = (char*)(file_list->infos + file_count); + u8 *name = (u8*)(file_list->infos + file_count); if (file_list->block != 0){ search = FindFirstFile((LPWSTR)filename_16, &find_data); @@ -832,14 +836,15 @@ Sys_Set_File_List_Sig(system_set_file_list){ info->folder = (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; info->filename = name; - //u32 length = copy_fast_unsafe_cc(name, find_data.cFileName); u32 size = 0; for(;find_data.cFileName[size];++size); - umem length = utf16_to_utf8_minimal_checking(info->filename, remaining_size, file_data.cFileName, size, &convert_error); + umem length = utf16_to_utf8_minimal_checking(info->filename, remaining_size, (u16*)find_data.cFileName, size, &convert_error); + if (!convert_error){ name += length; + remaining_size += length; - info->filename_len = length; + info->filename_len = (u32)length; *name++ = 0; String fname = make_string_cap(info->filename, info->filename_len, info->filename_len+1); replace_char(&fname, '\\', '/'); @@ -872,43 +877,54 @@ Sys_Set_File_List_Sig(system_set_file_list){ } internal u32 -win32_canonical_ascii_name(char *src, u32 len, char *dst, u32 max){ +win32_canonical_name(u16 *src, u32 len, u16 *dst, u32 max){ u32 result = 0; - char src_space[MAX_PATH + 32]; - if (len < sizeof(src_space) && len >= 2 && ((src[0] >= 'a' && src[0] <= 'z') || (src[0] >= 'A' && src[0] <= 'Z')) && src[1] == ':'){ - memcpy(src_space, src, len); - src_space[len] = 0; + if (len >= 2 && ((src[0] >= 'a' && src[0] <= 'z') || (src[0] >= 'A' && src[0] <= 'Z')) && src[1] == ':'){ - HANDLE file = CreateFile(src_space, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + HANDLE file = CreateFile((LPWSTR)src, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ - DWORD final_length = GetFinalPathNameByHandle(file, dst, max, 0); + DWORD final_length = GetFinalPathNameByHandle(file, (LPWSTR)dst, max, 0); if (final_length < max && final_length >= 4){ if (dst[final_length-1] == 0){ --final_length; } final_length -= 4; - memmove(dst, dst+4, final_length); + memmove(dst, dst+4, final_length*sizeof(u16)); dst[final_length] = 0; - result = final_length; + result = (u32)final_length; } CloseHandle(file); } else{ - String src_str = make_string(src, len); - String path_str = path_of_directory(src_str); - String front_str = front_of_directory(src_str); + //String src_str = make_string(src, len); + //String path_str = path_of_directory(src_str); + //String front_str = front_of_directory(src_str); - memcpy(src_space, path_str.str, path_str.size); - src_space[path_str.size] = 0; + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); - HANDLE dir = CreateFile(src_space, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + u16 *path_src = push_array(scratch, u16, len+1); + memcpy(path_src, src, len*sizeof(u16)); + u32 path_end = len; + for (u32 j = len; j > 0; --j){ + if (path_src[j] == '/' || path_src[j] == '\\'){ + path_end = j+1; + break; + } + } + path_src[path_end] = 0; + + u32 front_size = len - path_end; + u16 *front_src = path_src + path_end; + + HANDLE dir = CreateFile((LPWSTR)src, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir != INVALID_HANDLE_VALUE){ - DWORD final_length = GetFinalPathNameByHandle(dir, dst, max, 0); + DWORD final_length = GetFinalPathNameByHandle(dir, (LPWSTR)dst, max, 0); if (final_length < max && final_length >= 4){ if (dst[final_length-1] == 0){ @@ -917,15 +933,18 @@ win32_canonical_ascii_name(char *src, u32 len, char *dst, u32 max){ final_length -= 4; memmove(dst, dst+4, final_length); dst[final_length++] = '\\'; - memcpy(dst + final_length, front_str.str, front_str.size); - final_length += front_str.size; + memcpy(dst + final_length, front_src, front_size); + final_length += front_size; dst[final_length] = 0; - result = final_length; + result = (u32)final_length; } CloseHandle(dir); } + + end_temp_memory(temp); } + } return(result); @@ -933,20 +952,57 @@ win32_canonical_ascii_name(char *src, u32 len, char *dst, u32 max){ internal Sys_Get_Canonical_Sig(system_get_canonical){ - u32 result = win32_canonical_ascii_name(filename, len, buffer, max); + u32 result = 0; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 src_16_max = (len+1)*2; + u16 *src_16 = push_array(scratch, u16, src_16_max); + + u32 dst_16_max = (max+1)*2; + u16 *dst_16 = push_array(scratch, u16, dst_16_max); + + b32 convert_error = false; + u32 src_16_len = (u32)utf8_to_utf16_minimal_checking(src_16, src_16_max-1, src, len, &convert_error); + src_16[src_16_len] = 0; + + if (!convert_error){ + u32 dst_16_len = win32_canonical_name(src_16, src_16_len, dst_16, dst_16_max); + + result = (u32)utf16_to_utf8_minimal_checking(dst, max-1, dst_16, dst_16_len, &convert_error); + if (!convert_error){ + dst[result] = 0; + } + else{ + result = 0; + } + } + + end_temp_memory(temp); return(result); } internal Sys_Load_Handle_Sig(system_load_handle){ - b32 result = 0; - HANDLE file = CreateFile(filename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + b32 result = false; + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 len = 0; + for (;filename[len];++len); + + u32 filename_16_max = (len+1)*2; + u16 *filename_16 = push_array(scratch, u16, filename_16_max); + + HANDLE file = CreateFile((LPWSTR)filename_16, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ *(HANDLE*)handle_out = file; - result = 1; + result = true; } + end_temp_memory(temp); return(result); } @@ -983,36 +1039,52 @@ Sys_Load_File_Sig(system_load_file){ internal Sys_Load_Close_Sig(system_load_close){ - b32 result = 0; + b32 result = false; HANDLE file = *(HANDLE*)(&handle); if (CloseHandle(file)){ - result = 1; + result = true; } return(result); } internal Sys_Save_File_Sig(system_save_file){ - b32 result = 0; - HANDLE file = CreateFile(filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + b32 result = false; + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); - if (file != INVALID_HANDLE_VALUE){ - DWORD written_total = 0; - DWORD written_size = 0; + u32 len = 0; + for (;filename[len];++len); + + u32 filename_16_max = (len+1)*2; + u16 *filename_16 = push_array(scratch, u16, filename_16_max); + + b32 convert_error = false; + u32 filename_16_len = (u32)utf8_to_utf16_minimal_checking(filename_16, filename_16_max-1, (u8*)filename, len, &convert_error); + + if (!convert_error){ + filename_16[filename_16_len] = 0; - result = 1; - - while (written_total < size){ - if (!WriteFile(file, buffer + written_total, size - written_total, &written_size, 0)){ - result = 0; - break; + HANDLE file = CreateFile((LPWSTR)filename_16, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + if (file != INVALID_HANDLE_VALUE){ + DWORD written_total = 0; + DWORD written_size = 0; + + result = true; + + while (written_total < size){ + if (!WriteFile(file, buffer + written_total, size - written_total, &written_size, 0)){ + result = false; + break; + } + written_total += written_size; } - written_total += written_size; + + CloseHandle(file); } - - CloseHandle(file); } + end_temp_memory(temp); return(result); } @@ -1023,21 +1095,54 @@ Sys_Now_Time_Sig(system_now_time){ } internal b32 -Win32DirectoryExists(char *path){ - DWORD attrib = GetFileAttributes(path); - return (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY)); +Win32DirectoryExists(u8 *path){ + b32 result = false; + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 len = 0; + for(;path[len];++len); + + u32 path_16_max = (len+1)*2; + u16 *path_16 = push_array(scratch, u16, path_16_max); + + b32 convert_error = false; + u32 path_16_len = (u32)utf8_to_utf16_minimal_checking(path_16, path_16_max-1, path, len, &convert_error); + + if (!convert_error){ + path_16[path_16_len] = 0; + + DWORD attrib = GetFileAttributes((LPWSTR)path_16); + result = (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY)); + } + + end_temp_memory(temp); + return(result); } internal Sys_Get_Binary_Path_Sig(system_get_binary_path){ i32 result = 0; - i32 size = GetModuleFileName(0, out->str, out->memory_size); - if (size < out->memory_size-1){ + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 filename_16_max = (out->memory_size+1)*2; + u16 *filename_16 = push_array(scratch, u16, filename_16_max); + + u32 length_16 = GetModuleFileName(0, (LPWSTR)filename_16, filename_16_max); + + b32 convert_error = false; + u32 size = (u32)utf16_to_utf8_minimal_checking((u8*)out->str, out->memory_size-1, filename_16, length_16, &convert_error); + + if (!convert_error){ out->size = size; remove_last_folder(out); terminate_with_null(out); result = out->size; } + + end_temp_memory(temp); return(result); } @@ -1053,8 +1158,7 @@ Sys_File_Exists_Sig(system_file_exists){ copy_ss(&full_filename, make_string(filename, len)); terminate_with_null(&full_filename); - file = CreateFile(full_filename.str, GENERIC_READ, 0, 0, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + file = CreateFile(full_filename.str, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ CloseHandle(file); From c492bfdb4ef7bb62feba2eb66271a973bbfc1d59 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 23 Mar 2017 15:08:08 -0400 Subject: [PATCH 03/17] finished platform layer, it's fucked, rolling back --- 4coder_API/app_functions.h | 12 +- 4coder_API/types.h | 50 +-- 4coder_API/version.h | 16 + 4coder_auto_indent.cpp | 68 ++-- 4coder_base_commands.cpp | 48 +-- 4coder_clipboard.cpp | 25 +- 4coder_default_include.cpp | 20 +- 4coder_helper/4coder_helper.h | 30 +- 4coder_helper/4coder_jump_parsing.h | 6 +- 4coder_helper/4coder_long_seek.h | 180 +++++----- 4coder_helper/4coder_seek_types.h | 8 +- 4coder_jump_parsing.cpp | 12 +- 4coder_lib/4coder_table.h | 2 +- 4coder_lib/4coder_utf8.h | 4 +- 4coder_search.cpp | 70 ++-- 4cpp/4cpp_lexer.h | 6 +- 4cpp/4cpp_lexer_types.h | 18 +- 4ed.cpp | 14 +- 4ed_api_implementation.cpp | 8 +- 4ed_app_target.cpp | 2 +- 4ed_buffer.cpp | 227 +++++++------ 4ed_buffer_model.h | 4 +- 4ed_file.cpp | 22 +- 4ed_file_track.h | 2 +- 4ed_file_view.cpp | 93 +++--- 4ed_font_data.h | 59 ++++ 4ed_font_interface.h | 76 +++++ 4ed_font_interface_to_os.h | 23 ++ 4ed_font_internal.cpp | 493 ++++++++++++++++++++++++++++ 4ed_font_static_functions.cpp | 198 +++++++++++ 4ed_system.h | 6 +- 4ed_system_shared.cpp | 55 ++-- meta/meta_parser.cpp | 2 +- power/4coder_experiments.cpp | 98 +++--- power/4coder_miblo_numbers.cpp | 28 +- win32_4ed.cpp | 122 +++++-- win32_4ed_file_track.cpp | 4 +- win32_4ed_fonts.cpp | 6 +- 38 files changed, 1513 insertions(+), 604 deletions(-) create mode 100644 4ed_font_data.h create mode 100644 4ed_font_interface.h create mode 100644 4ed_font_interface_to_os.h create mode 100644 4ed_font_internal.cpp create mode 100644 4ed_font_static_functions.cpp diff --git a/4coder_API/app_functions.h b/4coder_API/app_functions.h index 357ef1f1..6828bd20 100644 --- a/4coder_API/app_functions.h +++ b/4coder_API/app_functions.h @@ -1,9 +1,9 @@ struct Application_Links; #define EXEC_COMMAND_SIG(n) bool32 n(Application_Links *app, Command_ID command_id) #define EXEC_SYSTEM_COMMAND_SIG(n) bool32 n(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags) -#define CLIPBOARD_POST_SIG(n) void n(Application_Links *app, int32_t clipboard_id, char *str, size_t len) +#define CLIPBOARD_POST_SIG(n) void n(Application_Links *app, int32_t clipboard_id, char *str, uint32_t len) #define CLIPBOARD_COUNT_SIG(n) uint32_t n(Application_Links *app, uint32_t clipboard_id) -#define CLIPBOARD_INDEX_SIG(n) size_t n(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len) +#define CLIPBOARD_INDEX_SIG(n) uint32_t n(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, uint32_t len) #define GET_BUFFER_COUNT_SIG(n) int32_t n(Application_Links *app) #define GET_BUFFER_FIRST_SIG(n) Buffer_Summary n(Application_Links *app, Access_Flag access) #define GET_BUFFER_NEXT_SIG(n) void n(Application_Links *app, Buffer_Summary *buffer, Access_Flag access) @@ -369,9 +369,9 @@ app_links->send_exit_signal_ = Send_Exit_Signal;} while(false) #if defined(ALLOW_DEP_4CODER) static inline bool32 exec_command(Application_Links *app, Command_ID command_id){return(app->exec_command(app, command_id));} static inline bool32 exec_system_command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags){return(app->exec_system_command(app, view, buffer, path, path_len, command, command_len, flags));} -static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, size_t len){(app->clipboard_post(app, clipboard_id, str, len));} +static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, uint32_t len){(app->clipboard_post(app, clipboard_id, str, len));} static inline uint32_t clipboard_count(Application_Links *app, uint32_t clipboard_id){return(app->clipboard_count(app, clipboard_id));} -static inline size_t clipboard_index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len){return(app->clipboard_index(app, clipboard_id, item_index, out, len));} +static inline uint32_t clipboard_index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, uint32_t len){return(app->clipboard_index(app, clipboard_id, item_index, out, len));} static inline int32_t get_buffer_count(Application_Links *app){return(app->get_buffer_count(app));} static inline Buffer_Summary get_buffer_first(Application_Links *app, Access_Flag access){return(app->get_buffer_first(app, access));} static inline void get_buffer_next(Application_Links *app, Buffer_Summary *buffer, Access_Flag access){(app->get_buffer_next(app, buffer, access));} @@ -441,9 +441,9 @@ static inline void send_exit_signal(Application_Links *app){(app->send_exit_sign #else static inline bool32 exec_command(Application_Links *app, Command_ID command_id){return(app->exec_command_(app, command_id));} static inline bool32 exec_system_command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags){return(app->exec_system_command_(app, view, buffer, path, path_len, command, command_len, flags));} -static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, size_t len){(app->clipboard_post_(app, clipboard_id, str, len));} +static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, uint32_t len){(app->clipboard_post_(app, clipboard_id, str, len));} static inline uint32_t clipboard_count(Application_Links *app, uint32_t clipboard_id){return(app->clipboard_count_(app, clipboard_id));} -static inline size_t clipboard_index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len){return(app->clipboard_index_(app, clipboard_id, item_index, out, len));} +static inline uint32_t clipboard_index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, uint32_t len){return(app->clipboard_index_(app, clipboard_id, item_index, out, len));} static inline int32_t get_buffer_count(Application_Links *app){return(app->get_buffer_count_(app));} static inline Buffer_Summary get_buffer_first(Application_Links *app, Access_Flag access){return(app->get_buffer_first_(app, access));} static inline void get_buffer_next(Application_Links *app, Buffer_Summary *buffer, Access_Flag access){(app->get_buffer_next_(app, buffer, access));} diff --git a/4coder_API/types.h b/4coder_API/types.h index 380d619a..abee807d 100644 --- a/4coder_API/types.h +++ b/4coder_API/types.h @@ -399,15 +399,15 @@ Throughout the API ranges are thought of in the form [min,max) where max is "one UNION Range{ STRUCT{ /* DOC(This is the smaller value in the range, it is also the 'start'.) */ - size_t min; + int32_t min; /* DOC(This is the larger value in the range, it is also the 'end'.) */ - size_t max; + int32_t max; }; STRUCT{ /* DOC(This is the start of the range, it is also the 'min'.) */ - size_t start; + int32_t start; /* DOC(This is the end of the range, it is also the 'max'.) */ - size_t end; + int32_t end; }; }; @@ -496,7 +496,7 @@ STRUCT Buffer_Seek{ UNION{ STRUCT { /* DOC(The pos field specified the pos when the seek is in absolute position.) */ - size_t pos; + int32_t pos; }; STRUCT { /* DOC(For xy coordinate seeks, rounding down means that any x in the box of the character lands on that character. For instance when clicking rounding down is the user's expected behavior. Not rounding down means that the right hand portion of the character's box, which is closer to the next character, will land on that next character. The unrounded behavior is the expected behavior when moving vertically and keeping the preferred x.) */ @@ -508,9 +508,9 @@ STRUCT Buffer_Seek{ }; STRUCT { /* DOC(The line number of a line-character type seek.) */ - size_t line; + int32_t line; /* DOC(The character number of a line-character type seek.) */ - size_t character; + int32_t character; }; }; }; @@ -519,15 +519,15 @@ STRUCT Buffer_Seek{ DOC_SEE(4coder_Buffer_Positioning_System) */ STRUCT Full_Cursor{ /* DOC(This field contains the cursor's position in absolute byte index positioning.) */ - size_t pos; + int32_t pos; /* DOC(This field contains the cursor's position in apparent character index positioning.) */ - size_t character_pos; + int32_t character_pos; /* DOC(This field contains the number of the line where the cursor is located. This field is one based.) */ - size_t line; + int32_t line; /* DOC(This field contains the number of the character from the beginninf of the line where the cursor is located. This field is one based.) */ - size_t character; + int32_t character; /* DOC(This field contains the number of the line where the cursor is located, taking the line wrapping into account. This field is one based.) */ - size_t wrap_line; + int32_t wrap_line; /* DOC(This field contains the x position measured with unwrapped lines.) */ float unwrapped_x; /* DOC(This field contains the y position measured with unwrapped lines.) */ @@ -542,24 +542,24 @@ STRUCT Full_Cursor{ DOC_SEE(4coder_Buffer_Positioning_System) */ STRUCT Partial_Cursor{ /* DOC(This field contains the cursor's position in absolute byte index positioning.) */ - size_t pos; + int32_t pos; /* DOC(This field contains the number of the character from the beginninf of the line where the cursor is located. This field is one based.) */ - size_t line; + int32_t line; /* DOC(This field contains the number of the column where the cursor is located. This field is one based.) */ - size_t character; + int32_t character; }; /* DOC(Buffer_Edit describes a range of a buffer and string to replace that range. A Buffer_Edit has to be paired with a string that contains the actual text that will be replaced into the buffer.) */ STRUCT Buffer_Edit{ /* DOC(The str_start field specifies the first character in the accompanying string that corresponds with this edit.) */ - size_t str_start; + int32_t str_start; /* DOC(The len field specifies the length of the string being written into the buffer.) */ - size_t len; + int32_t len; /* DOC(The start field specifies the start of the range in the buffer to replace in absolute position.) */ - size_t start; + int32_t start; /* DOC(The end field specifies one past the end of the range in the buffer to replace in absolute position.) */ - size_t end; + int32_t end; }; /* DOC(Buffer_Summary acts as a handle to a buffer and describes the state of the buffer.) @@ -616,7 +616,7 @@ DOC_SEE(buffer_add_markers) */ STRUCT Marker{ /* DOC(The current position of the marker measure in absolute byte positioning coordinates.) */ - size_t pos; + int32_t pos; /* DOC(When a marker is inside a range that gets edited, by default the marker 'leans_left' which means it goes to the beginning of the edited range. If the field lean_right is set to true, the marker will lean right with edits and will go to the end of edited range.) */ bool32 lean_right; }; @@ -638,10 +638,10 @@ STRUCT i32_Rect{ GLOBAL_VAR i32_Rect null_i32_rect = {0}; STRUCT pos_Rect{ - size_t x0; - size_t y0; - size_t x1; - size_t y1; + int32_t x0; + int32_t y0; + int32_t x1; + int32_t y1; }; GLOBAL_VAR pos_Rect null_pos_rect = {0}; @@ -735,7 +735,7 @@ STRUCT Buffer_Batch_Edit{ /* DOC(The pointer to the edit string buffer.) */ char *str; /* DOC(The length of the edit string buffer.) */ - size_t str_len; + int32_t str_len; /* DOC(The array of edits to be applied.) */ Buffer_Edit *edits; diff --git a/4coder_API/version.h b/4coder_API/version.h index 496d6f8e..46e15982 100644 --- a/4coder_API/version.h +++ b/4coder_API/version.h @@ -2,6 +2,7 @@ #define MINOR 0 #define PATCH 18 +// strings #define VN__(a,b,c) #a"."#b"."#c #define VN_(a,b,c) VN__(a,b,c) #define VERSION_NUMBER VN_(MAJOR,MINOR,PATCH) @@ -14,3 +15,18 @@ #endif #define VERSION VERSION_STRING VERSION_TYPE + +// long strings +#define L_VN__(a,b,c) L#a L"." L#b L"." L#c +#define L_VN_(a,b,c) L_VN__(a,b,c) +#define L_VERSION_NUMBER L_VN_(MAJOR, MINOR, PATCH) +#define L_VERSION_STRING L"alpha " L_VERSION_NUMBER + +#if defined(FRED_SUPER) +#define L_VERSION_TYPE L" super!" +#else +#define L_VERSION_TYPE +#endif + +#define L_VERSION L_VERSION_STRING L_VERSION_TYPE + diff --git a/4coder_auto_indent.cpp b/4coder_auto_indent.cpp index 079e15aa..7f40b38e 100644 --- a/4coder_auto_indent.cpp +++ b/4coder_auto_indent.cpp @@ -28,14 +28,14 @@ TYPE: 'drop-in-command-pack' // struct Hard_Start_Result{ - size_t char_pos; + int32_t char_pos; int32_t indent_pos; bool32 all_whitespace; bool32 all_space; }; static Hard_Start_Result -buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, size_t line_start, int32_t tab_width){ +buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, int32_t line_start, int32_t tab_width){ Hard_Start_Result result = {0}; result.all_space = 1; result.indent_pos = 0; @@ -49,7 +49,7 @@ buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, size_t li if (init_stream_chunk(&stream, app, buffer, line_start, data_chunk, sizeof(data_chunk))){ int32_t still_looping = 1; do{ - for (; result.char_pos < (size_t)stream.end; ++result.char_pos){ + for (; result.char_pos < stream.end; ++result.char_pos){ char c = stream.data[result.char_pos]; if (c == '\n' || c == 0){ @@ -86,24 +86,24 @@ struct Indent_Options{ }; static Buffer_Batch_Edit -make_batch_from_indent_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line_start, size_t line_end, int32_t *indent_marks, Indent_Options opts){ +make_batch_from_indent_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line_start, int32_t line_end, int32_t *indent_marks, Indent_Options opts){ Buffer_Batch_Edit result = {0}; - size_t edit_max = line_end - line_start; + uint32_t edit_max = line_end - line_start; uint32_t edit_count = 0; Buffer_Edit *edits = push_array(part, Buffer_Edit, edit_max); char *str_base = (char*)part->base + part->pos; - size_t str_size = 0; + int32_t str_size = 0; // NOTE(allen): Shift the array so that line_i can just operate in // it's natural value range. indent_marks -= line_start; - for (size_t line_i = line_start; line_i < line_end; ++line_i){ - size_t line_start_pos = buffer_get_line_start(app, buffer, line_i); + for (int32_t line_i = line_start; line_i < line_end; ++line_i){ + int32_t line_start_pos = buffer_get_line_start(app, buffer, line_i); Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, line_start_pos, opts.tab_width); int32_t correct_indentation = indent_marks[line_i]; @@ -156,7 +156,7 @@ make_batch_from_indent_marks(Application_Links *app, Partition *part, Buffer_Sum } static void -set_line_indents(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line_start, size_t line_end, int32_t *indent_marks, Indent_Options opts){ +set_line_indents(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line_start, int32_t line_end, int32_t *indent_marks, Indent_Options opts){ Buffer_Batch_Edit batch = make_batch_from_indent_marks(app, part, buffer, line_start, line_end, indent_marks, opts); @@ -192,7 +192,7 @@ seek_matching_token_backwards(Cpp_Token_Array tokens, Cpp_Token *token, Cpp_Toke } static Cpp_Token* -find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t line_start, int32_t tab_width, int32_t *current_indent_out){ +find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line_start, int32_t tab_width, int32_t *current_indent_out){ Cpp_Token *token = get_first_token_at_line(app, buffer, tokens, line_start); if (token == 0 && tokens.count == 0){ @@ -220,8 +220,8 @@ find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Arra int32_t current_indent = 0; int32_t found_safe_start_position = 0; do{ - size_t line = buffer_get_line_index(app, buffer, token->start); - size_t start = buffer_get_line_start(app, buffer, line); + int32_t line = buffer_get_line_index(app, buffer, token->start); + int32_t start = buffer_get_line_start(app, buffer, line); Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, start, tab_width); current_indent = hard_start.indent_pos; @@ -294,9 +294,9 @@ struct Indent_Parse_State{ }; static int32_t* -get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t line_start, size_t line_end, bool32 exact_align, int32_t tab_width){ +get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line_start, int32_t line_end, bool32 exact_align, int32_t tab_width){ - size_t indent_mark_count = line_end - line_start; + int32_t indent_mark_count = line_end - line_start; int32_t *indent_marks = push_array(part, int32_t, indent_mark_count); // Shift the array so line_index works correctly. indent_marks -= line_start; @@ -306,18 +306,18 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b Cpp_Token *token_ptr = find_anchor_token(app, buffer, tokens, line_start, tab_width, &indent.current_indent); if (token_ptr == 0){ - for (size_t line_index = line_start; line_index < line_end; ++line_index){ + for (int32_t line_index = line_start; line_index < line_end; ++line_index){ indent_marks[line_index] = 0; } } else{ - size_t line_index = buffer_get_line_index(app, buffer, token_ptr->start); + int32_t line_index = buffer_get_line_index(app, buffer, token_ptr->start); if (line_index > line_start){ line_index = line_start; } - size_t next_line_start_pos = buffer_get_line_start(app, buffer, line_index+1); + int32_t next_line_start_pos = buffer_get_line_start(app, buffer, line_index+1); switch (token_ptr->type){ case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += tab_width; break; @@ -347,8 +347,8 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b { int32_t previous_indent = indent.previous_line_indent; - size_t this_line_start = buffer_get_line_start(app, buffer, line_index); - size_t next_line_start = buffer_get_line_start(app, buffer, line_index+1); + int32_t this_line_start = buffer_get_line_start(app, buffer, line_index); + int32_t next_line_start = buffer_get_line_start(app, buffer, line_index+1); bool32 did_special_behavior = false; @@ -456,8 +456,8 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b case CPP_TOKEN_COMMENT: { - size_t line = buffer_get_line_index(app, buffer, token.start); - size_t start = buffer_get_line_start(app, buffer, line); + int32_t line = buffer_get_line_index(app, buffer, token.start); + int32_t start = buffer_get_line_start(app, buffer, line); int32_t char_pos = (int32_t)(token.start - start); indent.comment_shift = (indent.current_indent - char_pos); indent.previous_comment_indent = char_pos; @@ -466,8 +466,8 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b case CPP_TOKEN_PARENTHESE_OPEN: if (!(token.flags & CPP_TFLAG_PP_BODY)){ if (indent.paren_nesting < ArrayCount(indent.paren_anchor_indent)){ - size_t line = buffer_get_line_index(app, buffer, token.start); - size_t start = buffer_get_line_start(app, buffer, line); + int32_t line = buffer_get_line_index(app, buffer, token.start); + int32_t start = buffer_get_line_start(app, buffer, line); int32_t char_pos = (int32_t)(token.start - start); Hard_Start_Result hard_start = @@ -499,21 +499,21 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b } static void -get_indent_lines_minimum(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, size_t end_pos, size_t *line_start_out, size_t *line_end_out){ - size_t line_start = buffer_get_line_index(app, buffer, start_pos); - size_t line_end = buffer_get_line_index(app, buffer, end_pos) + 1; +get_indent_lines_minimum(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, int32_t end_pos, int32_t *line_start_out, int32_t *line_end_out){ + int32_t line_start = buffer_get_line_index(app, buffer, start_pos); + int32_t line_end = buffer_get_line_index(app, buffer, end_pos) + 1; *line_start_out = line_start; *line_end_out = line_end; } static void -get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t start_pos, size_t end_pos, size_t *line_start_out, size_t *line_end_out){ - size_t line_start = buffer_get_line_index(app, buffer, start_pos); - size_t line_end = buffer_get_line_index(app, buffer, end_pos); +get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t start_pos, int32_t end_pos, int32_t *line_start_out, int32_t *line_end_out){ + int32_t line_start = buffer_get_line_index(app, buffer, start_pos); + int32_t line_end = buffer_get_line_index(app, buffer, end_pos); for (;line_start > 0;){ - size_t line_start_pos = 0; + int32_t line_start_pos = 0; Cpp_Token *token = get_first_token_at_line(app, buffer, tokens, line_start, &line_start_pos); if (token != 0 && token->start < line_start_pos){ line_start = buffer_get_line_index(app, buffer, token->start); @@ -524,7 +524,7 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cp } for (;line_end+1 < buffer->line_count;){ - size_t next_line_start_pos = 0; + int32_t next_line_start_pos = 0; Cpp_Token *token = get_first_token_at_line(app, buffer, tokens, line_end+1, &next_line_start_pos); if (token && token->start < next_line_start_pos){ line_end = buffer_get_line_index(app, buffer, token->start+token->size); @@ -545,7 +545,7 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cp } static bool32 -buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t start, size_t end, int32_t tab_width, Auto_Indent_Flag flags){ +buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t start, int32_t end, int32_t tab_width, Auto_Indent_Flag flags){ bool32 result = false; if (buffer->exists && buffer->tokens_are_ready){ @@ -562,7 +562,7 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buff // Stage 2: Decide where the first and last lines are. // The lines in the range [line_start,line_end) will be indented. - size_t line_start = 0, line_end = 0; + int32_t line_start = 0, line_end = 0; if (flags & AutoIndent_FullTokens){ get_indent_lines_whole_tokens(app, buffer, tokens, start, end, &line_start, &line_end); } @@ -591,7 +591,7 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buff } static bool32 -buffer_auto_indent(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, int32_t tab_width, Auto_Indent_Flag flags){ +buffer_auto_indent(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, int32_t tab_width, Auto_Indent_Flag flags){ bool32 result = buffer_auto_indent(app, &global_part, buffer, start, end, tab_width, flags); return(result); } diff --git a/4coder_base_commands.cpp b/4coder_base_commands.cpp index b47837d4..f0216d07 100644 --- a/4coder_base_commands.cpp +++ b/4coder_base_commands.cpp @@ -33,7 +33,7 @@ CUSTOM_COMMAND_SIG(write_character){ if (length != 0){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos = view.cursor.pos; + int32_t pos = view.cursor.pos; Marker next_cursor_marker = {0}; next_cursor_marker.pos = character_pos_to_pos(app, &view, &buffer, view.cursor.character_pos); @@ -60,8 +60,8 @@ CUSTOM_COMMAND_SIG(delete_char){ Full_Cursor cursor; view_compute_cursor(app, &view, seek, &cursor); - size_t start = view.cursor.pos; - size_t end = cursor.pos; + int32_t start = view.cursor.pos; + int32_t end = cursor.pos; if (0 <= start && start < buffer.size){ buffer_replace_range(app, &buffer, start, end, 0, 0); @@ -77,8 +77,8 @@ CUSTOM_COMMAND_SIG(backspace_char){ Full_Cursor cursor; view_compute_cursor(app, &view, seek, &cursor); - size_t end = view.cursor.pos; - size_t start = cursor.pos; + int32_t end = view.cursor.pos; + int32_t start = cursor.pos; if (0 < end && end <= buffer.size){ buffer_replace_range(app, &buffer, start, end, 0, 0); @@ -97,8 +97,8 @@ CUSTOM_COMMAND_SIG(set_mark){ CUSTOM_COMMAND_SIG(cursor_mark_swap){ View_Summary view = get_active_view(app, AccessProtected); - size_t cursor = view.cursor.pos; - size_t mark = view.mark.pos; + int32_t cursor = view.cursor.pos; + int32_t mark = view.mark.pos; view_set_cursor(app, &view, seek_pos(mark), true); view_set_mark(app, &view, seek_pos(cursor)); @@ -250,14 +250,14 @@ CUSTOM_COMMAND_SIG(page_down){ CUSTOM_COMMAND_SIG(move_left){ uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); - size_t new_pos = view.cursor.character_pos - 1; + int32_t new_pos = view.cursor.character_pos - 1; view_set_cursor(app, &view, seek_character_pos(new_pos), 1); } CUSTOM_COMMAND_SIG(move_right){ uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); - size_t new_pos = view.cursor.character_pos + 1; + int32_t new_pos = view.cursor.character_pos + 1; view_set_cursor(app, &view, seek_character_pos(new_pos), 1); } @@ -277,7 +277,7 @@ CUSTOM_COMMAND_SIG(seek_whitespace_up){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t new_pos = buffer_seek_whitespace_up(app, &buffer, view.cursor.pos); + int32_t new_pos = buffer_seek_whitespace_up(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -286,7 +286,7 @@ CUSTOM_COMMAND_SIG(seek_whitespace_down){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t new_pos = buffer_seek_whitespace_down(app, &buffer, view.cursor.pos); + int32_t new_pos = buffer_seek_whitespace_down(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -295,7 +295,7 @@ CUSTOM_COMMAND_SIG(seek_end_of_textual_line){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t new_pos = seek_line_end(app, &buffer, view.cursor.pos); + int32_t new_pos = seek_line_end(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -304,7 +304,7 @@ CUSTOM_COMMAND_SIG(seek_beginning_of_textual_line){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t new_pos = seek_line_beginning(app, &buffer, view.cursor.pos); + int32_t new_pos = seek_line_beginning(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -350,7 +350,7 @@ CUSTOM_COMMAND_SIG(to_uppercase){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen); Range range = get_range(&view); - size_t size = range.max - range.min; + int32_t size = range.max - range.min; if (size <= app->memory_size){ char *mem = (char*)app->memory; @@ -368,7 +368,7 @@ CUSTOM_COMMAND_SIG(to_lowercase){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen); Range range = get_range(&view); - size_t size = range.max - range.min; + int32_t size = range.max - range.min; if (size <= app->memory_size){ char *mem = (char*)app->memory; @@ -580,9 +580,9 @@ isearch(Application_Links *app, bool32 start_reversed){ if (start_query_bar(app, &bar, 0) == 0) return; bool32 reverse = start_reversed; - size_t pos = view.cursor.pos; - size_t start_pos = pos; - size_t first_pos = pos; + int32_t pos = view.cursor.pos; + int32_t start_pos = pos; + int32_t first_pos = pos; Range match = make_range(pos, pos); char bar_string_space[256]; @@ -646,8 +646,8 @@ isearch(Application_Links *app, bool32 start_reversed){ if (in.key.keycode != key_back){ char *str = bar.string.str; - size_t str_size = bar.string.size; - size_t new_pos = 0; + int32_t str_size = bar.string.size; + int32_t new_pos = 0; if (reverse){ buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1, 0, str, str_size, &new_pos); if (new_pos >= 0){ @@ -723,8 +723,8 @@ CUSTOM_COMMAND_SIG(replace_in_range){ Range range = get_range(&view); - size_t pos = range.min; - size_t new_pos = 0; + int32_t pos = range.min; + int32_t new_pos = 0; buffer_seek_string_forward(app, &buffer, pos, 0, r.str, r.size, &new_pos); while (new_pos + r.size <= range.end){ @@ -765,8 +765,8 @@ CUSTOM_COMMAND_SIG(query_replace){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos = view.cursor.pos; - size_t new_pos = 0; + int32_t pos = view.cursor.pos; + int32_t new_pos = 0; buffer_seek_string_forward(app, &buffer, pos, 0, r.str, r.size, &new_pos); User_Input in = {0}; diff --git a/4coder_clipboard.cpp b/4coder_clipboard.cpp index b0dfbf6a..8c03a3bd 100644 --- a/4coder_clipboard.cpp +++ b/4coder_clipboard.cpp @@ -14,21 +14,21 @@ TYPE: 'drop-in-command-pack' #include "4coder_helper/4coder_helper.h" static bool32 -clipboard_copy(Application_Links *app, size_t start, size_t end, Buffer_Summary *buffer_out, uint32_t access){ +clipboard_copy(Application_Links *app, int32_t start, int32_t end, Buffer_Summary *buffer_out, uint32_t access){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - bool32 result = 0; + bool32 result = false; if (buffer.exists){ if (0 <= start && start <= end && end <= buffer.size){ - size_t size = (end - start); + uint32_t size = (end - start); char *str = (char*)app->memory; - if (size <= app->memory_size){ + if (size <= (uint32_t)app->memory_size){ buffer_read_range(app, &buffer, start, end, str); clipboard_post(app, 0, str, size); if (buffer_out){*buffer_out = buffer;} - result = 1; + result = true; } } } @@ -37,7 +37,7 @@ clipboard_copy(Application_Links *app, size_t start, size_t end, Buffer_Summary } static bool32 -clipboard_cut(Application_Links *app, size_t start, size_t end, Buffer_Summary *buffer_out, uint32_t access){ +clipboard_cut(Application_Links *app, int32_t start, int32_t end, Buffer_Summary *buffer_out, uint32_t access){ Buffer_Summary buffer = {0}; bool32 result = false; @@ -76,10 +76,9 @@ CUSTOM_COMMAND_SIG(paste){ int32_t paste_index = 0; view_paste_index[view.view_id].index = paste_index; - size_t len = clipboard_index(app, 0, paste_index, 0, 0); + uint32_t len = clipboard_index(app, 0, paste_index, 0, 0); char *str = 0; - - if (len <= app->memory_size){ + if (len <= (uint32_t)app->memory_size){ str = (char*)app->memory; } @@ -87,7 +86,7 @@ CUSTOM_COMMAND_SIG(paste){ clipboard_index(app, 0, paste_index, str, len); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos = view.cursor.pos; + int32_t pos = view.cursor.pos; buffer_replace_range(app, &buffer, pos, pos, str, len); view_set_mark(app, &view, seek_pos(pos)); view_set_cursor(app, &view, seek_pos(pos + len), true); @@ -113,10 +112,10 @@ CUSTOM_COMMAND_SIG(paste_next){ int32_t paste_index = view_paste_index[view.view_id].index + 1; view_paste_index[view.view_id].index = paste_index; - size_t len = clipboard_index(app, 0, paste_index, 0, 0); + uint32_t len = clipboard_index(app, 0, paste_index, 0, 0); char *str = 0; - if (len <= app->memory_size){ + if (len <= (uint32_t)app->memory_size){ str = (char*)app->memory; } @@ -125,7 +124,7 @@ CUSTOM_COMMAND_SIG(paste_next){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); Range range = get_range(&view); - size_t pos = range.min; + int32_t pos = range.min; buffer_replace_range(app, &buffer, range.min, range.max, str, len); view_set_cursor(app, &view, seek_pos(pos + len), true); diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 28e17112..84dba8f7 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -42,9 +42,9 @@ TYPE: 'major-system-include' // Seeks Using Default Framework Memory // -static size_t -buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags){ - size_t result = buffer_boundary_seek(app, buffer, &global_part, start_pos, seek_forward, flags); +static int32_t +buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags){ + int32_t result = buffer_boundary_seek(app, buffer, &global_part, start_pos, seek_forward, flags); return(result); } @@ -53,7 +53,7 @@ basic_seek(Application_Links *app, int32_t seek_type, uint32_t flags){ uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos = buffer_boundary_seek(app, &buffer, view.cursor.pos, seek_type, flags); + int32_t pos = buffer_boundary_seek(app, &buffer, view.cursor.pos, seek_type, flags); view_set_cursor(app, &view, seek_pos(pos), true); } @@ -115,8 +115,8 @@ CUSTOM_COMMAND_SIG(snipe_token_or_word){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos1 = buffer_boundary_seek(app, &buffer, view.cursor.pos, 0, BoundaryToken | BoundaryWhitespace); - size_t pos2 = buffer_boundary_seek(app, &buffer, pos1, 1, BoundaryToken | BoundaryWhitespace); + int32_t pos1 = buffer_boundary_seek(app, &buffer, view.cursor.pos, 0, BoundaryToken | BoundaryWhitespace); + int32_t pos2 = buffer_boundary_seek(app, &buffer, pos1, 1, BoundaryToken | BoundaryWhitespace); Range range = make_range(pos1, pos2); buffer_replace_range(app, &buffer, range.start, range.end, 0, 0); @@ -201,7 +201,7 @@ long_braces(Application_Links *app, char *text, int32_t size){ uint32_t access = AccessOpen; View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos = view.cursor.pos; + int32_t pos = view.cursor.pos; buffer_replace_range(app, &buffer, pos, pos, text, size); view_set_cursor(app, &view, seek_pos(pos + 2), true); @@ -333,13 +333,13 @@ file_name_in_quotes(Application_Links *app, String *file_name){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); if (buffer.file_name != 0){ - size_t pos = view.cursor.pos; - size_t start = 0, end = 0; + int32_t pos = view.cursor.pos; + int32_t start = 0, end = 0; buffer_seek_delimiter_forward(app, &buffer, pos, '"', &end); buffer_seek_delimiter_backward(app, &buffer, pos, '"', &start); ++start; - size_t size = end - start; + int32_t size = end - start; char short_file_name[128]; // NOTE(allen): This check is necessary because buffer_read_range diff --git a/4coder_helper/4coder_helper.h b/4coder_helper/4coder_helper.h index 7fb8cd15..fc13c55b 100644 --- a/4coder_helper/4coder_helper.h +++ b/4coder_helper/4coder_helper.h @@ -148,7 +148,7 @@ query_user_number(Application_Links *app, Query_Bar *bar){ } static char -buffer_get_char(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +buffer_get_char(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char result = ' '; *buffer = get_buffer(app, buffer->buffer_id, AccessAll); if (pos < buffer->size){ @@ -188,7 +188,7 @@ create_buffer(Application_Links *app, char *filename, int32_t filename_len, Buff } static Range -make_range(size_t p1, size_t p2){ +make_range(int32_t p1, int32_t p2){ Range range; if (p1 < p2){ range.min = p1; @@ -212,9 +212,9 @@ adjust_all_buffer_wrap_widths(Application_Links *app, int32_t wrap_width, int32_ } // TODO(allen): Setup buffer seeking to do character_pos and get View_Summary out of this parameter list. -static size_t -character_pos_to_pos(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, size_t character_pos){ - size_t result = 0; +static int32_t +character_pos_to_pos(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, int32_t character_pos){ + int32_t result = 0; Full_Cursor cursor = {0}; if (view_compute_cursor(app, view, seek_character_pos(character_pos), &cursor)){ result = cursor.pos; @@ -223,8 +223,8 @@ character_pos_to_pos(Application_Links *app, View_Summary *view, Buffer_Summary } struct Buffer_Rect{ - size_t char0, line0; - size_t char1, line1; + int32_t char0, line0; + int32_t char1, line1; }; #ifndef Swap @@ -242,10 +242,10 @@ get_rect(View_Summary *view){ rect.line1 = view->cursor.line; if (rect.line0 > rect.line1){ - Swap(size_t, rect.line0, rect.line1); + Swap(int32_t, rect.line0, rect.line1); } if (rect.char0 > rect.char1){ - Swap(size_t, rect.char0, rect.char1); + Swap(int32_t, rect.char0, rect.char1); } return(rect); @@ -256,21 +256,21 @@ get_line_x_rect(View_Summary *view){ pos_Rect rect = {0}; if (view->unwrapped_lines){ - rect.x0 = (size_t)view->mark.unwrapped_x; - rect.x1 = (size_t)view->cursor.unwrapped_x; + rect.x0 = (int32_t)view->mark.unwrapped_x; + rect.x1 = (int32_t)view->cursor.unwrapped_x; } else{ - rect.x0 = (size_t)view->mark.wrapped_x; - rect.x1 = (size_t)view->cursor.wrapped_x; + rect.x0 = (int32_t)view->mark.wrapped_x; + rect.x1 = (int32_t)view->cursor.wrapped_x; } rect.y0 = view->mark.line; rect.y1 = view->cursor.line; if (rect.y0 > rect.y1){ - Swap(size_t, rect.y0, rect.y1); + Swap(int32_t, rect.y0, rect.y1); } if (rect.x0 > rect.x1){ - Swap(size_t, rect.x0, rect.x1); + Swap(int32_t, rect.x0, rect.x1); } return(rect); diff --git a/4coder_helper/4coder_jump_parsing.h b/4coder_helper/4coder_jump_parsing.h index d37de476..548ce9bd 100644 --- a/4coder_helper/4coder_jump_parsing.h +++ b/4coder_helper/4coder_jump_parsing.h @@ -41,7 +41,7 @@ ms_style_verify(String line, int32_t paren_pos){ } static int32_t -parse_jump_location(String line, Name_Based_Jump_Location *location, int32_t skip_sub_errors, size_t *colon_char){ +parse_jump_location(String line, Name_Based_Jump_Location *location, int32_t skip_sub_errors, int32_t *colon_char){ bool32 result = false; int32_t whitespace_length = 0; @@ -153,13 +153,13 @@ parse_jump_location(String line, Name_Based_Jump_Location *location, int32_t ski } static bool32 -parse_jump_from_buffer_line(Application_Links *app, Partition *part, int32_t buffer_id, size_t line, int32_t skip_sub_errors, Name_Based_Jump_Location *location){ +parse_jump_from_buffer_line(Application_Links *app, Partition *part, int32_t buffer_id, int32_t line, int32_t skip_sub_errors, Name_Based_Jump_Location *location){ bool32 result = false; String line_str = {0}; Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll); if (read_line(app, part, &buffer, line, &line_str)){ - size_t colon_char = 0; + int32_t colon_char = 0; if (parse_jump_location(line_str, location, skip_sub_errors, &colon_char)){ result = true; } diff --git a/4coder_helper/4coder_long_seek.h b/4coder_helper/4coder_long_seek.h index 831334e7..f7148db7 100644 --- a/4coder_helper/4coder_long_seek.h +++ b/4coder_helper/4coder_long_seek.h @@ -15,16 +15,16 @@ // Whitespace Based Seeks // -static size_t -seek_line_end(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +seek_line_end(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char chunk[1024]; - size_t chunk_size = sizeof(chunk); + int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ bool32 still_looping = true; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < (int32_t)stream.end; ++pos){ char at_pos = stream.data[pos]; if (at_pos == '\n'){ goto double_break; @@ -42,17 +42,17 @@ seek_line_end(Application_Links *app, Buffer_Summary *buffer, size_t pos){ return(pos); } -static size_t -seek_line_beginning(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +seek_line_beginning(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char chunk[1024]; - size_t chunk_size = sizeof(chunk); + int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; --pos; if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ bool32 still_looping = false; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= (int32_t)stream.start; --pos){ char at_pos = stream.data[pos]; if (at_pos == '\n'){ goto double_break; @@ -80,12 +80,12 @@ move_past_lead_whitespace(Application_Links *app, View_Summary *view, Buffer_Sum char space[1024]; Stream_Chunk chunk = {0}; - size_t new_pos = seek_line_beginning(app, buffer, view->cursor.pos); - size_t i = new_pos; + int32_t new_pos = seek_line_beginning(app, buffer, view->cursor.pos); + int32_t i = new_pos; if (init_stream_chunk(&chunk, app, buffer, i, space, sizeof(space))){ bool32 still_looping = false; do{ - for (; i < (size_t)chunk.end; ++i){ + for (; i < (int32_t)chunk.end; ++i){ char at_pos = chunk.data[i]; if (at_pos == '\n' || !char_is_whitespace(at_pos)){ goto break2; @@ -101,10 +101,10 @@ move_past_lead_whitespace(Application_Links *app, View_Summary *view, Buffer_Sum } } -static size_t -buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char chunk[1024]; - size_t chunk_size = sizeof(chunk); + int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; --pos; @@ -113,7 +113,7 @@ buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, size_t // behind the current position. bool32 still_looping = true; while (still_looping){ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= (int32_t)stream.start; --pos){ char at_pos = stream.data[pos]; if (!char_is_whitespace(at_pos)){ goto double_break_1; @@ -130,7 +130,7 @@ buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, size_t // the next '\n' int32_t no_hard = false; while (still_looping){ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= (int32_t)stream.start; --pos){ char at_pos = stream.data[pos]; if (at_pos == '\n'){ if (no_hard){ @@ -156,10 +156,10 @@ buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, size_t return(pos); } -static size_t -buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char chunk[1024]; - size_t chunk_size = sizeof(chunk); + int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ @@ -167,7 +167,7 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, size // ahead of the current position. bool32 still_looping = true; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < (int32_t)stream.end; ++pos){ char at_pos = stream.data[pos]; if (!char_is_whitespace(at_pos)){ goto double_break_1; @@ -184,9 +184,9 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, size // all whitespace. bool32 no_hard = false; bool32 was_at_end = true; - size_t prev_endline = 0; + int32_t prev_endline = 0; while(still_looping){ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < (int32_t)stream.end; ++pos){ char at_pos = stream.data[pos]; if (at_pos == '\n'){ if (no_hard){ @@ -216,8 +216,8 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, size return(pos); } -static size_t -buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -226,7 +226,7 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, siz bool32 still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < (int32_t)stream.end; ++pos){ if (!char_is_whitespace(stream.data[pos])){ goto double_break1; } @@ -237,7 +237,7 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, siz still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < (int32_t)stream.end; ++pos){ if (char_is_whitespace(stream.data[pos])){ goto double_break2; } @@ -250,8 +250,8 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, siz return(pos); } -static size_t -buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -262,7 +262,7 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, size bool32 still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= (int32_t)stream.start; --pos){ if (!char_is_whitespace(stream.data[pos])){ goto double_break1; } @@ -273,7 +273,7 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, size still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= (int32_t)stream.start; --pos){ if (char_is_whitespace(stream.data[pos])){ ++pos; goto double_break2; @@ -295,8 +295,8 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, size // Boundary Type Seeks // -static size_t -buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -305,7 +305,7 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, s bool32 still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < (int32_t)stream.end; ++pos){ if (char_is_alpha_numeric_true(stream.data[pos])){ goto double_break1; } @@ -316,7 +316,7 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, s still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < (int32_t)stream.end; ++pos){ if (!char_is_alpha_numeric_true(stream.data[pos])){ goto double_break2; } @@ -329,8 +329,8 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, s return(pos); } -static size_t -buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -341,7 +341,7 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, si bool32 still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= (int32_t)stream.start; --pos){ if (char_is_alpha_numeric_true(stream.data[pos])){ goto double_break1; } @@ -352,7 +352,7 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, si still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= (int32_t)stream.start; --pos){ if (!char_is_alpha_numeric_true(stream.data[pos])){ ++pos; goto double_break2; @@ -370,8 +370,8 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, si return(pos); } -static size_t -buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t an_pos){ +static int32_t +buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t an_pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -386,7 +386,7 @@ buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, si bool32 still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < (int32_t)stream.end; ++pos){ c = stream.data[pos]; if (char_is_upper(c) && char_is_lower(pc)){ goto double_break1; @@ -405,8 +405,8 @@ buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, si return(pos); } -static size_t -buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t an_pos){ +static int32_t +buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t an_pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -419,7 +419,7 @@ buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, siz bool32 still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= (int32_t)stream.start; --pos){ c = stream.data[pos]; if (char_is_upper(c) && char_is_lower(pc)){ goto double_break1; @@ -438,22 +438,22 @@ buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, siz return(pos); } -static size_t -buffer_seek_alphanumeric_or_camel_right(Application_Links *app, Buffer_Summary *buffer, size_t pos){ - size_t an_pos = buffer_seek_alphanumeric_right(app, buffer, pos); - size_t result = buffer_seek_range_camel_right(app, buffer, pos, an_pos); +static int32_t +buffer_seek_alphanumeric_or_camel_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ + int32_t an_pos = buffer_seek_alphanumeric_right(app, buffer, pos); + int32_t result = buffer_seek_range_camel_right(app, buffer, pos, an_pos); return(result); } -static size_t -buffer_seek_alphanumeric_or_camel_left(Application_Links *app, Buffer_Summary *buffer, size_t pos){ - size_t an_pos = buffer_seek_alphanumeric_left(app, buffer, pos); - size_t result = buffer_seek_range_camel_left(app, buffer, pos, an_pos); +static int32_t +buffer_seek_alphanumeric_or_camel_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ + int32_t an_pos = buffer_seek_alphanumeric_left(app, buffer, pos); + int32_t result = buffer_seek_range_camel_left(app, buffer, pos, an_pos); return(result); } -static size_t -seek_token_left(Cpp_Token_Array *tokens, size_t pos){ +static int32_t +seek_token_left(Cpp_Token_Array *tokens, int32_t pos){ Cpp_Get_Token_Result get = cpp_get_token(*tokens, pos); if (get.token_index == -1){ get.token_index = 0; @@ -467,8 +467,8 @@ seek_token_left(Cpp_Token_Array *tokens, size_t pos){ return(token->start); } -static size_t -seek_token_right(Cpp_Token_Array *tokens, size_t pos){ +static int32_t +seek_token_right(Cpp_Token_Array *tokens, int32_t pos){ Cpp_Get_Token_Result get = cpp_get_token(*tokens, pos); if (get.in_whitespace){ ++get.token_index; @@ -497,8 +497,8 @@ buffer_get_all_tokens(Application_Links *app, Partition *part, Buffer_Summary *b return(array); } -static size_t -buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Partition *part, size_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags)/* +static int32_t +buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Partition *part, int32_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags)/* DOC_PARAM(buffer, The buffer parameter specifies the buffer through which to seek.) DOC_PARAM(start_pos, The beginning position of the seek is specified by start_pos measured in absolute position.) DOC_PARAM(seek_forward, If this parameter is non-zero it indicates that the seek should move foward through the buffer.) @@ -509,14 +509,14 @@ DOC_RETURN(This call returns the absolute position where the seek stopped. If th DOC_SEE(Seek_Boundary_Flag) DOC_SEE(4coder_Buffer_Positioning_System) */{ - size_t result = 0; + int32_t result = 0; // TODO(allen): reduce duplication? Temp_Memory temp = begin_temp_memory(part); if (buffer->exists){ - size_t pos[4]; - size_t size = buffer->size; - size_t new_pos = 0; + int32_t pos[4]; + int32_t size = buffer->size; + int32_t new_pos = 0; if (start_pos < 0){ start_pos = 0; @@ -613,7 +613,7 @@ DOC_SEE(4coder_Buffer_Positioning_System) // static void -buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, size_t pos, char delim, size_t *result){ +buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, char delim, int32_t *result){ if (buffer->exists){ char chunk[1024]; int32_t size = sizeof(chunk); @@ -622,7 +622,7 @@ buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, si if (init_stream_chunk(&stream, app, buffer, pos, chunk, size)){ int32_t still_looping = 1; do{ - for(; pos < (size_t)stream.end; ++pos){ + for(; pos < (int32_t)stream.end; ++pos){ char at_pos = stream.data[pos]; if (at_pos == delim){ *result = pos; @@ -640,7 +640,7 @@ buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, si } static void -buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, size_t pos, char delim, size_t *result){ +buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, char delim, int32_t *result){ if (buffer->exists){ char chunk[1024]; int32_t size = sizeof(chunk); @@ -649,7 +649,7 @@ buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, s if (init_stream_chunk(&stream, app, buffer, pos, chunk, size)){ int32_t still_looping = 1; do{ - for(; pos >= (size_t)stream.start; --pos){ + for(; pos >= (int32_t)stream.start; --pos){ char at_pos = stream.data[pos]; if (at_pos == delim){ *result = pos; @@ -677,7 +677,7 @@ buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, s // You can push it up or do something more clever by just // replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t end, char *str, size_t size, size_t *result){ +buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t end, char *str, int32_t size, int32_t *result){ char read_buffer[512]; if (buffer->size > end){ @@ -702,7 +702,7 @@ buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, size_ if (init_stream_chunk(&stream, app, buffer, pos, chunk, sizeof(chunk))){ bool32 still_looping = 1; do{ - for(; pos < (size_t)stream.end; ++pos){ + for(; pos < (int32_t)stream.end; ++pos){ char at_pos = stream.data[pos]; if (at_pos == first_char){ buffer_read_range(app, buffer, pos, pos+size, read_buffer); @@ -732,7 +732,7 @@ buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, size_ // You can push it up or do something more clever by just // replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t min, char *str, size_t size, size_t *result){ +buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t min, char *str, int32_t size, int32_t *result){ char read_buffer[512]; *result = min-1; @@ -751,7 +751,7 @@ buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, size if (init_stream_chunk(&stream, app, buffer, pos, chunk, sizeof(chunk))){ int32_t still_looping = 1; do{ - for(; pos >= (size_t)stream.start; --pos){ + for(; pos >= (int32_t)stream.start; --pos){ char at_pos = stream.data[pos]; if (at_pos == first_char){ buffer_read_range(app, buffer, pos, pos+size, read_buffer); @@ -774,7 +774,7 @@ buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, size // You can push it up or do something more clever by just // replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t end, char *str, size_t size, size_t *result){ +buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t end, char *str, int32_t size, int32_t *result){ char read_buffer[512]; char chunk[1024]; int32_t chunk_size = sizeof(chunk); @@ -798,7 +798,7 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *b if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ bool32 still_looping = true; do{ - for(; pos < (size_t)stream.end; ++pos){ + for(; pos < (int32_t)stream.end; ++pos){ char at_pos = char_to_upper(stream.data[pos]); if (at_pos == first_char){ buffer_read_range(app, buffer, pos, pos+size, read_buffer); @@ -819,7 +819,7 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *b // You can push it up or do something more clever by just // replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t min, char *str, size_t size, size_t *result){ +buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t min, char *str, int32_t size, int32_t *result){ char read_buffer[512]; char chunk[1024]; int32_t chunk_size = sizeof(chunk); @@ -837,7 +837,7 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary * if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ int32_t still_looping = 1; do{ - for(; pos >= (size_t)stream.start; --pos){ + for(; pos >= (int32_t)stream.start; --pos){ char at_pos = char_to_upper(stream.data[pos]); if (at_pos == first_char){ buffer_read_range(app, buffer, pos, pos+size, read_buffer); @@ -860,7 +860,7 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary * // static bool32 -read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line, String *str){ +read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line, String *str){ bool32 success = false; Buffer_Seek seek_begin = seek_line_char(line, 1); @@ -872,7 +872,7 @@ read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_ if (begin.line == line){ if (buffer_compute_cursor(app, buffer, seek_end, &end)){ if (0 <= begin.pos && begin.pos <= end.pos && end.pos <= buffer->size){ - size_t size = (end.pos - begin.pos); + int32_t size = (end.pos - begin.pos); *str = make_string(push_array(part, char, size+1), (int32_t)(size+1)); if (str->str){ success = true; @@ -888,10 +888,10 @@ read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_ return(success); } -static size_t -buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, size_t line){ +static int32_t +buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, int32_t line){ Partial_Cursor partial_cursor; - size_t result = buffer->size; + int32_t result = buffer->size; if (line <= buffer->line_count){ buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &partial_cursor); result = partial_cursor.pos; @@ -899,10 +899,10 @@ buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, size_t lin return(result); } -static size_t -buffer_get_line_end(Application_Links *app, Buffer_Summary *buffer, size_t line){ +static int32_t +buffer_get_line_end(Application_Links *app, Buffer_Summary *buffer, int32_t line){ Partial_Cursor partial_cursor; - size_t result = buffer->size; + int32_t result = buffer->size; if (line <= buffer->line_count){ buffer_compute_cursor(app, buffer, seek_line_reverse_char(line, 1), &partial_cursor); result = partial_cursor.pos; @@ -911,7 +911,7 @@ buffer_get_line_end(Application_Links *app, Buffer_Summary *buffer, size_t line) } static bool32 -buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, size_t line){ +buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, int32_t line){ Partial_Cursor start, end; bool32 result = 0; if (line <= buffer->line_count){ @@ -921,17 +921,17 @@ buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, size_t line buffer_compute_cursor(app, buffer, seek_start, &start); buffer_compute_cursor(app, buffer, seek_end, &end); - static const size_t chunk_size = 1024; + static const int32_t chunk_size = 1024; char chunk[chunk_size]; Stream_Chunk stream = {0}; - size_t i = start.pos; + int32_t i = start.pos; stream.max_end = end.pos; result = true; if (init_stream_chunk(&stream, app, buffer, i, chunk, chunk_size)){ bool32 still_looping = false; do{ - for (;i < (size_t)stream.end; ++i){ + for (;i < (int32_t)stream.end; ++i){ char c = stream.data[i]; if (!(c == ' ' || c == '\t' || c == '\r' || c == '\v' || c == '\n')){ result = false; @@ -946,16 +946,16 @@ buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, size_t line return(result); } -static size_t -buffer_get_line_index(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_get_line_index(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ Partial_Cursor partial_cursor; buffer_compute_cursor(app, buffer, seek_pos(pos), &partial_cursor); return(partial_cursor.line); } static Cpp_Token* -get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t line, size_t *line_start_out = 0){ - size_t line_start = buffer_get_line_start(app, buffer, line); +get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line, int32_t *line_start_out = 0){ + int32_t line_start = buffer_get_line_start(app, buffer, line); Cpp_Get_Token_Result get = cpp_get_token(tokens, line_start); if (get.in_whitespace){ diff --git a/4coder_helper/4coder_seek_types.h b/4coder_helper/4coder_seek_types.h index 2d2e8a58..f6c61586 100644 --- a/4coder_helper/4coder_seek_types.h +++ b/4coder_helper/4coder_seek_types.h @@ -13,7 +13,7 @@ #define FRED_BUFFER_TYPES_H static Buffer_Seek -seek_pos(size_t pos){ +seek_pos(int32_t pos){ Buffer_Seek result; result.type = buffer_seek_pos; result.pos = pos; @@ -21,7 +21,7 @@ seek_pos(size_t pos){ } static Buffer_Seek -seek_character_pos(size_t pos){ +seek_character_pos(int32_t pos){ Buffer_Seek result; result.type = buffer_seek_character_pos; result.pos = pos; @@ -59,7 +59,7 @@ seek_xy(float x, float y, bool32 round_down, bool32 unwrapped){ } static Buffer_Seek -seek_line_char(size_t line, size_t character){ +seek_line_char(int32_t line, int32_t character){ Buffer_Seek result; result.type = buffer_seek_line_char; result.line = line; @@ -68,7 +68,7 @@ seek_line_char(size_t line, size_t character){ } static Buffer_Seek -seek_line_reverse_char(size_t line, size_t character){ +seek_line_reverse_char(int32_t line, int32_t character){ Buffer_Seek result; result.type = buffer_seek_line_reverse_char; result.line = line; diff --git a/4coder_jump_parsing.cpp b/4coder_jump_parsing.cpp index 3071c786..902334fb 100644 --- a/4coder_jump_parsing.cpp +++ b/4coder_jump_parsing.cpp @@ -37,12 +37,12 @@ CUSTOM_COMMAND_SIG(goto_jump_at_cursor){ // static bool32 -seek_next_jump_in_buffer(Application_Links *app, Partition *part, int32_t buffer_id, size_t first_line, bool32 skip_sub_errors, int32_t direction, size_t *line_out, size_t *colon_index_out, Name_Based_Jump_Location *location_out){ +seek_next_jump_in_buffer(Application_Links *app, Partition *part, int32_t buffer_id, int32_t first_line, bool32 skip_sub_errors, int32_t direction, int32_t *line_out, int32_t *colon_index_out, Name_Based_Jump_Location *location_out){ Assert(direction == 1 || direction == -1); bool32 result = false; - size_t line = first_line; + int32_t line = first_line; String line_str = {0}; Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll); for (;;){ @@ -83,12 +83,12 @@ convert_name_based_to_id_based(Application_Links *app, Name_Based_Jump_Location } static int32_t -seek_next_jump_in_view(Application_Links *app, Partition *part, View_Summary *view, bool32 skip_sub_errors, int32_t direction, size_t *line_out, size_t *colon_index_out, Name_Based_Jump_Location *location_out){ +seek_next_jump_in_view(Application_Links *app, Partition *part, View_Summary *view, bool32 skip_sub_errors, int32_t direction, int32_t *line_out, int32_t *colon_index_out, Name_Based_Jump_Location *location_out){ int32_t result = false; Name_Based_Jump_Location location = {0}; - size_t line = view->cursor.line; - size_t colon_index = 0; + int32_t line = view->cursor.line; + int32_t colon_index = 0; if (seek_next_jump_in_buffer(app, part, view->buffer_id, line+direction, skip_sub_errors, direction, &line, &colon_index, &location)){ result = true; *line_out = line; @@ -117,7 +117,7 @@ advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_Summar Name_Based_Jump_Location location = {0}; ID_Based_Jump_Location jump = {0}; - size_t line = 0, colon_index = 0; + int32_t line = 0, colon_index = 0; do{ Temp_Memory temp = begin_temp_memory(part); diff --git a/4coder_lib/4coder_table.h b/4coder_lib/4coder_table.h index 044306e0..9efb9019 100644 --- a/4coder_lib/4coder_table.h +++ b/4coder_lib/4coder_table.h @@ -117,7 +117,7 @@ table_add(Table *table, void *item, void *arg, Hash_Function *hash_func, Compare static i32_4tech table_find_pos(Table *table, void *search_key, void *arg, i32_4tech *pos, i32_4tech *index, Hash_Function *hash_func, Compare_Function *comp_func){ - Assert((table->count - 1) * 8 < table->max * 7); + Assert(((table->count!=0)?(table->count - 1):0) * 8 < table->max * 7); u32_4tech hash = (hash_func(search_key, arg) | TableHashMin); u32_4tech i = hash % table->max; diff --git a/4coder_lib/4coder_utf8.h b/4coder_lib/4coder_utf8.h index 76d6580d..7d20a7e6 100644 --- a/4coder_lib/4coder_utf8.h +++ b/4coder_lib/4coder_utf8.h @@ -281,10 +281,10 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * static umem_4tech utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *src, umem_4tech length, b32_4tech *error){ u16_4tech *s = src; - u16_4tech *s_end = s + max_chars; + u16_4tech *s_end = s + length; u8_4tech *d = dst; - u8_4tech *d_end = d + length; + u8_4tech *d_end = d + max_chars; umem_4tech limit = length; umem_4tech needed_max = 0; diff --git a/4coder_search.cpp b/4coder_search.cpp index e5c76b48..694e6f84 100644 --- a/4coder_search.cpp +++ b/4coder_search.cpp @@ -40,10 +40,10 @@ struct Search_Range{ int32_t type; uint32_t flags; int32_t buffer; - size_t start; - size_t size; - size_t mid_start; - size_t mid_size; + int32_t start; + int32_t size; + int32_t mid_start; + int32_t mid_size; }; struct Search_Set{ @@ -54,22 +54,22 @@ struct Search_Set{ struct Search_Iter{ String word; - size_t pos; - size_t back_pos; - size_t i; + int32_t pos; + int32_t back_pos; + int32_t i; bool32 range_initialized; }; struct Search_Match{ Buffer_Summary buffer; - size_t start; - size_t end; + int32_t start; + int32_t end; bool32 found_match; }; static void -search_iter_init(General_Memory *general, Search_Iter *iter, size_t size){ - size_t str_max = size*2; +search_iter_init(General_Memory *general, Search_Iter *iter, int32_t size){ + int32_t str_max = size*2; if (iter->word.str == 0){ iter->word.str = (char*)general_memory_allocate(general, str_max); iter->word.memory_size = (int32_t)str_max; @@ -91,7 +91,7 @@ search_set_init(General_Memory *general, Search_Set *set, int32_t range_count){ set->max = max; } else if (set->max < range_count){ - size_t mem_size = sizeof(Search_Range)*max;; + int32_t mem_size = sizeof(Search_Range)*max;; set->ranges = (Search_Range*)general_memory_reallocate_nocopy(general, set->ranges, mem_size); set->max = max; } @@ -174,14 +174,14 @@ search_hit_add(General_Memory *general, Table *hits, String_Space *space, char * return(result); } -static size_t -buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char space[1024]; Stream_Chunk chunk = {0}; if (init_stream_chunk(&chunk, app, buffer, pos, space, sizeof(space))){ bool32 still_looping = true; do{ - for (; pos < (size_t)chunk.end; ++pos){ + for (; pos < (int32_t)chunk.end; ++pos){ char at_pos = chunk.data[pos]; if (!char_is_alpha_numeric(at_pos)) goto double_break; } @@ -207,11 +207,11 @@ enum{ }; static int32_t -match_check(Application_Links *app, Search_Range *range, size_t *pos, Search_Match *result_ptr, String word){ +match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Match *result_ptr, String word){ int32_t found_match = FindResult_None; Search_Match result = *result_ptr; - size_t end_pos = range->start + range->size; + int32_t end_pos = range->start + range->size; uint32_t type = (range->flags & SearchFlag_MatchMask); @@ -281,14 +281,14 @@ match_check(Application_Links *app, Search_Range *range, size_t *pos, Search_Mat } static int32_t -search_front_to_back_step(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ +search_front_to_back_step(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; Search_Match result = *result_ptr; - size_t end_pos = range->start + range->size; + int32_t end_pos = range->start + range->size; if (*pos + word.size < end_pos){ - size_t start_pos = *pos; + int32_t start_pos = *pos; if (start_pos < range->start){ start_pos = range->start; } @@ -298,7 +298,7 @@ search_front_to_back_step(Application_Links *app, Search_Range *range, String wo result.buffer = get_buffer(app, range->buffer, AccessAll); char *word_str = word.str; - size_t word_size = (size_t)word.size; + int32_t word_size = (int32_t)word.size; if (case_insensitive){ buffer_seek_string_insensitive_forward(app, &result.buffer, start_pos, end_pos, word_str, word_size, &result.start); } @@ -329,7 +329,7 @@ search_front_to_back_step(Application_Links *app, Search_Range *range, String wo } static int32_t -search_front_to_back(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ +search_front_to_back(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; for (;found_match == FindResult_None;){ found_match = search_front_to_back_step(app, range, word, pos, result_ptr); @@ -338,13 +338,13 @@ search_front_to_back(Application_Links *app, Search_Range *range, String word, s } static int32_t -search_back_to_front_step(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ +search_back_to_front_step(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; Search_Match result = *result_ptr; if (*pos > range->start){ - size_t start_pos = *pos; + int32_t start_pos = *pos; result.buffer = get_buffer(app, range->buffer, AccessAll); buffer_seek_string_backward(app, &result.buffer, @@ -374,7 +374,7 @@ search_back_to_front_step(Application_Links *app, Search_Range *range, String wo } static int32_t -search_back_to_front(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ +search_back_to_front(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; for (;found_match == FindResult_None;){ found_match = search_back_to_front_step(app, range, word, pos, result_ptr); @@ -440,9 +440,9 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){ if (backward_result == FindResult_FoundMatch){ find_result = FindResult_FoundMatch; - size_t forward_start = range->mid_start + range->mid_size; - size_t forward_distance = forward_match.start - forward_start; - size_t backward_distance = range->mid_start - backward_match.end; + int32_t forward_start = range->mid_start + range->mid_size; + int32_t forward_distance = forward_match.start - forward_start; + int32_t backward_distance = range->mid_start - backward_match.end; if (backward_distance < forward_distance){ iter.pos = forward_match.start; @@ -713,8 +713,8 @@ struct Word_Complete_State{ Search_Iter iter; Table hits; String_Space str; - size_t word_start; - size_t word_end; + int32_t word_start; + int32_t word_end; bool32 initialized; }; @@ -737,10 +737,10 @@ CUSTOM_COMMAND_SIG(word_complete){ do_init = true; } - size_t word_end = 0; - size_t word_start = 0; - size_t cursor_pos = 0; - size_t size = 0; + int32_t word_end = 0; + int32_t word_start = 0; + int32_t cursor_pos = 0; + int32_t size = 0; if (do_init){ // NOTE(allen): Get the range where the partial word is written. @@ -753,7 +753,7 @@ CUSTOM_COMMAND_SIG(word_complete){ if (init_stream_chunk(&chunk, app, &buffer, cursor_pos, space, sizeof(space))){ int32_t still_looping = true; do{ - for (; cursor_pos >= (size_t)chunk.start; --cursor_pos){ + for (; cursor_pos >= (int32_t)chunk.start; --cursor_pos){ char c = chunk.data[cursor_pos]; if (char_is_alpha(c)){ word_start = cursor_pos; diff --git a/4cpp/4cpp_lexer.h b/4cpp/4cpp_lexer.h index 5c57ec9e..56e977bb 100644 --- a/4cpp/4cpp_lexer.h +++ b/4cpp/4cpp_lexer.h @@ -349,7 +349,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, u32_4tech s u8_4tech c = 0; - u32_4tech end_pos = size + S.chunk_pos; + i32_4tech end_pos = size + S.chunk_pos; chunk -= S.chunk_pos; switch (S.__pc__){ @@ -970,7 +970,7 @@ cpp_lex_nonalloc_null_end_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech } FCPP_LINK Cpp_Lex_Result -cpp_lex_nonalloc_no_null_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, u32_4tech size, u32_4tech full_size, +cpp_lex_nonalloc_no_null_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech size, i32_4tech full_size, Cpp_Token_Array *token_array_out){ Cpp_Lex_Result result = 0; if (S_ptr->pos >= full_size){ @@ -1157,7 +1157,7 @@ cpp_index_array(Cpp_Token_Array *array, i32_4tech file_size, u32_4tech index){ } API_EXPORT FCPP_LINK Cpp_Relex_Range -cpp_get_relex_range(Cpp_Token_Array *array, u32_4tech start_pos, u32_4tech end_pos) +cpp_get_relex_range(Cpp_Token_Array *array, i32_4tech start_pos, i32_4tech end_pos) /* DOC_PARAM(array, A pointer to the token array that will be modified by the relex, this array should already contain the tokens for the previous state of the file.) DOC_PARAM(start_pos, The start position of the edited region of the file. The start and end points are based on the edited region of the file before the edit.) diff --git a/4cpp/4cpp_lexer_types.h b/4cpp/4cpp_lexer_types.h index 4c597489..6c45b7b5 100644 --- a/4cpp/4cpp_lexer_types.h +++ b/4cpp/4cpp_lexer_types.h @@ -237,10 +237,10 @@ STRUCT Cpp_Token{ Cpp_Token_Type type; /* DOC(The start field indicates the index of the first character of this token's lexeme.) */ - uint32_t start; + int32_t start; /* DOC(The size field indicates the number of bytes in this token's lexeme.) */ - uint32_t size; + int32_t size; /* DOC(The state_flags should not be used outside of the lexer's implementation.) */ uint16_t state_flags; @@ -291,10 +291,10 @@ STRUCT Cpp_Get_Token_Result{ uint32_t in_whitespace; /* DOC(If the token_index refers to an actual token, this is the start value of the token. Otherwise this is zero.) */ - uint32_t token_start; + int32_t token_start; /* DOC(If the token_index refers to an actual token, this is the start+size value of the token. Otherwise this is zero.) */ - uint32_t token_end; + int32_t token_end; }; /* DOC(Cpp_Relex_Range is the return result of the cpp_get_relex_range call.) @@ -321,12 +321,12 @@ DOC_SEE(cpp_lex_data_init) HIDE_MEMBERS() */ STRUCT Cpp_Lex_Data{ char tb[32]; - uint32_t tb_pos; - uint32_t token_start; + int32_t tb_pos; + int32_t token_start; - uint32_t pos; - uint32_t pos_overide; - uint32_t chunk_pos; + int32_t pos; + int32_t pos_overide; + int32_t chunk_pos; Cpp_Lex_FSM fsm; uint8_t white_done; diff --git a/4ed.cpp b/4ed.cpp index 929a0586..bb4f4865 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -343,8 +343,8 @@ COMMAND_DECL(reopen){ General_Memory *general = &models->mem.general; File_Edit_Positions edit_poss[16]; - umem line_number[16]; - umem column_number[16]; + i32 line_number[16]; + i32 column_number[16]; View *vptrs[16]; i32 vptr_count = 0; for (View_Iter iter = file_view_iter_init(&models->layout, file, 0); @@ -364,8 +364,8 @@ COMMAND_DECL(reopen){ for (i32 i = 0; i < vptr_count; ++i){ view_set_file(system, vptrs[i], file, models); - umem line = line_number[i]; - umem character = column_number[i]; + i32 line = line_number[i]; + i32 character = column_number[i]; *vptrs[i]->edit_pos = edit_poss[i]; Full_Cursor cursor = view_compute_cursor(system, vptrs[i], seek_line_char(line, character), 0); @@ -1597,8 +1597,8 @@ App_Step_Sig(app_step){ // NOTE(allen): check files are up to date { b32 mem_too_small = 0; - i32 size = 0; - i32 buffer_size = KB(32); + umem size = 0; + umem buffer_size = KB(32); Partition *part = &models->mem.part; Temp_Memory temp = begin_temp_memory(part); @@ -1612,7 +1612,7 @@ App_Step_Sig(app_step){ for (;system->get_file_change(buffer, buffer_size, &mem_too_small, &size);){ Assert(!mem_too_small); Editing_File_Canon_Name canon; - if (get_canon_name(system, &canon, make_string(buffer, size))){ + if (get_canon_name(system, &canon, make_string(buffer, (i32)size))){ Editing_File *file = working_set_canon_contains(working_set, canon.name); if (file){ if (file->state.ignore_behind_os == 0){ diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index d23b4b24..41a35d9f 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -347,7 +347,7 @@ DOC_SEE(Command_Line_Interface_Flag) } API_EXPORT void -Clipboard_Post(Application_Links *app, int32_t clipboard_id, char *str, size_t len) +Clipboard_Post(Application_Links *app, int32_t clipboard_id, char *str, uint32_t len) /* DOC_PARAM(clipboard_id, This parameter is set up to prepare for future features, it should always be 0 for now.) DOC_PARAM(str, The str parameter specifies the string to be posted to the clipboard, it need not be null terminated.) @@ -379,8 +379,8 @@ DOC_SEE(The_4coder_Clipboard) return(count); } -API_EXPORT size_t -Clipboard_Index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len) +API_EXPORT uint32_t +Clipboard_Index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, uint32_t len) /* DOC_PARAM(clipboard_id, This parameter is set up to prepare for future features, it should always be 0 for now.) DOC_PARAM(item_index, This parameter specifies which item to read, 0 is the most recent copy, 1 is the second most recent copy, etc.) @@ -395,7 +395,7 @@ DOC_SEE(The_4coder_Clipboard) Command_Data *cmd = (Command_Data*)app->cmd_context; Working_Set *working = &cmd->models->working_set; - size_t size = 0; + u32 size = 0; String *str = working_set_clipboard_index(working, item_index); if (str){ size = str->size; diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index 1743cdda..88b699cc 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -62,7 +62,7 @@ #include "4ed_file_view.cpp" #include "4ed.cpp" -#include "font/4coder_font_static_functions.cpp" +#include "4ed_font_static_functions.cpp" // BOTTOM diff --git a/4ed_buffer.cpp b/4ed_buffer.cpp index 421f04ef..6c38bafa 100644 --- a/4ed_buffer.cpp +++ b/4ed_buffer.cpp @@ -13,7 +13,7 @@ // Buffer low level operations // -#include "font/4coder_font_data.h" +#include "4ed_font_data.h" #include "4coder_helper/4coder_seek_types.h" typedef struct Cursor_With_Index{ @@ -314,9 +314,9 @@ typedef struct Gap_Buffer{ u32 size2; u32 max; - u32 *line_starts; - u32 line_count; - u32 line_max; + i32 *line_starts; + i32 line_count; + i32 line_max; } Gap_Buffer; inline b32 @@ -338,7 +338,7 @@ typedef struct Gap_Buffer_Init{ } Gap_Buffer_Init; internal Gap_Buffer_Init -buffer_begin_init(Gap_Buffer *buffer, char *data, i32 size){ +buffer_begin_init(Gap_Buffer *buffer, char *data, u32 size){ Gap_Buffer_Init init; init.buffer = buffer; init.data = data; @@ -349,7 +349,7 @@ buffer_begin_init(Gap_Buffer *buffer, char *data, i32 size){ internal b32 buffer_init_need_more(Gap_Buffer_Init *init){ b32 result = true; - if (init->buffer->data){ + if (init->buffer->data != 0){ result = false; } return(result); @@ -369,15 +369,15 @@ buffer_init_provide_page(Gap_Buffer_Init *init, void *page, u32 page_size){ } internal b32 -buffer_end_init(Gap_Buffer_Init *init, void *scratch, u32 scratch_size){ +buffer_end_init(Gap_Buffer_Init *init){ Gap_Buffer *buffer = init->buffer; b32 result = false; - if (buffer->data && buffer->max >= init->size){ - u32 size = init->size; - u32 size2 = size*2; - u32 osize1 = size - size2; - u32 size1 = osize1; + if (buffer->data != 0 && buffer->max >= init->size){ + i32 size = init->size; + i32 size2 = size*2; + i32 osize1 = size - size2; + i32 size1 = osize1; if (size1 > 0){ size1 = eol_convert_in(buffer->data, init->data, size1); @@ -400,8 +400,8 @@ buffer_end_init(Gap_Buffer_Init *init, void *scratch, u32 scratch_size){ typedef struct Gap_Buffer_Stream{ Gap_Buffer *buffer; char *data; - u32 end; - u32 absolute_end; + i32 end; + i32 absolute_end; b32 separated; b32 use_termination_character; char terminator; @@ -629,15 +629,15 @@ buffer_convert_out(Gap_Buffer *buffer, char *dest, u32 max){ return(pos); } -internal u32 -buffer_count_newlines(Gap_Buffer *buffer, u32 start, u32 end){ +internal i32 +buffer_count_newlines(Gap_Buffer *buffer, i32 start, i32 end){ Gap_Buffer_Stream stream = {0}; - u32 i = start; - u32 count = 0; + i32 i = start; + i32 count = 0; assert(0 <= start); assert(start <= end); - assert(end <= buffer_size(buffer)); + assert(end <= (i32)buffer_size(buffer)); if (buffer_stringify_loop(&stream, buffer, i, end)){ b32 still_looping = 0; @@ -653,9 +653,9 @@ buffer_count_newlines(Gap_Buffer *buffer, u32 start, u32 end){ } typedef struct Buffer_Measure_Starts{ - u32 i; - u32 count; - u32 start; + i32 i; + i32 count; + i32 start; } Buffer_Measure_Starts; // TODO(allen): Rewrite this with a duff routine @@ -664,10 +664,10 @@ typedef struct Buffer_Measure_Starts{ internal b32 buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){ Gap_Buffer_Stream stream = {0}; - u32 size = (u32)buffer_size(buffer); - u32 start = state->start, i = state->i; - u32 *start_ptr = buffer->line_starts + state->count; - u32 *start_end = buffer->line_starts + buffer->line_max; + i32 size = (i32)buffer_size(buffer); + i32 start = state->start, i = state->i; + i32 *start_ptr = buffer->line_starts + state->count; + i32 *start_end = buffer->line_starts + buffer->line_max; b32 result = true; if (buffer_stringify_loop(&stream, buffer, i, size)){ @@ -707,13 +707,13 @@ buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){ } internal void -buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, u32 *character_starts, i32 mode, b32 virtual_white){ +buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, i32 *character_starts, i32 mode, b32 virtual_white){ assert(mode == 0); Gap_Buffer_Stream stream = {0}; - u32 line_index = 0; - u32 character_index = 0; + i32 line_index = 0; + i32 character_index = 0; character_starts[line_index++] = character_index; @@ -728,8 +728,8 @@ buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap stream.use_termination_character = 1; stream.terminator = '\n'; - u32 size = buffer_size(buffer); - u32 i = 0; + i32 size = (i32)buffer_size(buffer); + i32 i = 0; if (buffer_stringify_loop(&stream, buffer, i, size)){ b32 still_looping = false; do{ @@ -774,17 +774,17 @@ enum{ }; struct Buffer_Layout_Stop{ - u32 status; - u32 line_index; - u32 wrap_line_index; - u32 pos; - u32 next_line_pos; + i32 status; + i32 line_index; + i32 wrap_line_index; + i32 pos; + i32 next_line_pos; f32 x; }; struct Buffer_Measure_Wrap_Params{ Gap_Buffer *buffer; - u32 *wrap_line_index; + i32 *wrap_line_index; System_Functions *system; Render_Font *font; b32 virtual_white; @@ -792,17 +792,17 @@ struct Buffer_Measure_Wrap_Params{ struct Buffer_Measure_Wrap_State{ Gap_Buffer_Stream stream; - u32 i; - u32 size; + i32 i; + i32 size; b32 still_looping; - u32 line_index; + i32 line_index; - u32 current_wrap_index; + i32 current_wrap_index; f32 current_adv; f32 x; - u32 wrap_unit_end; + i32 wrap_unit_end; b32 skipping_whitespace; b32 did_wrap; b32 first_of_the_line; @@ -950,9 +950,9 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para #undef DrReturn internal void -buffer_remeasure_starts(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 line_shift, i32 text_shift){ - u32 *starts = buffer->line_starts; - u32 line_count = buffer->line_count; +buffer_remeasure_starts(Gap_Buffer *buffer, i32 start_line, i32 end_line, i32 line_shift, i32 text_shift){ + i32 *starts = buffer->line_starts; + i32 line_count = buffer->line_count; assert(0 <= start_line); assert(start_line <= end_line); @@ -963,7 +963,7 @@ buffer_remeasure_starts(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li // Adjust if (text_shift != 0){ - u32 line_i = end_line; + i32 line_i = end_line; starts += line_i; for (; line_i < line_count; ++line_i, ++starts){ *starts += text_shift; @@ -972,8 +972,8 @@ buffer_remeasure_starts(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li } // Shift - u32 new_line_count = line_count; - u32 new_end_line = end_line; + i32 new_line_count = line_count; + i32 new_end_line = end_line; if (line_shift != 0){ new_line_count += line_shift; new_end_line += line_shift; @@ -984,12 +984,12 @@ buffer_remeasure_starts(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li // Iteration data (yikes! Need better loop system) Gap_Buffer_Stream stream = {0}; - u32 size = buffer_size(buffer); - u32 char_i = starts[start_line]; - u32 line_i = start_line; + i32 size = buffer_size(buffer); + i32 char_i = starts[start_line]; + i32 line_i = start_line; // Line start measurement - u32 start = char_i; + i32 start = char_i; if (buffer_stringify_loop(&stream, buffer, char_i, size)){ b32 still_looping = 0; @@ -1023,10 +1023,10 @@ buffer_remeasure_starts(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li } internal void -buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 line_shift, u32 *character_starts, i32 mode, b32 virtual_whitespace){ +buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, i32 start_line, i32 end_line, i32 line_shift, i32 *character_starts, i32 mode, b32 virtual_whitespace){ assert(mode == 0); - u32 new_line_count = buffer->line_count; + i32 new_line_count = buffer->line_count; assert(0 <= start_line); assert(start_line <= end_line); @@ -1035,24 +1035,23 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G ++end_line; // Shift - u32 line_count = new_line_count; - u32 new_end_line = end_line; + i32 line_count = new_line_count; + i32 new_end_line = end_line; if (line_shift != 0){ line_count -= line_shift; new_end_line += line_shift; - memmove(character_starts + end_line + line_shift, character_starts + end_line, sizeof(i32)*(line_count - end_line + 1)); } // Iteration data Gap_Buffer_Stream stream = {0}; - u32 size = buffer_size(buffer); - u32 char_i = buffer->line_starts[start_line]; - u32 line_i = start_line; + i32 size = buffer_size(buffer); + i32 char_i = buffer->line_starts[start_line]; + i32 line_i = start_line; // Character measurement - u32 last_char_start = character_starts[line_i]; - u32 current_char_start = last_char_start; + i32 last_char_start = character_starts[line_i]; + i32 current_char_start = last_char_start; b32 skipping_whitespace = false; if (virtual_whitespace){ @@ -1063,7 +1062,7 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G Translation_State tran = {0}; Translation_Emits emits = {0}; - stream.use_termination_character = 1; + stream.use_termination_character = true; stream.terminator = '\n'; if (buffer_stringify_loop(&stream, buffer, char_i, size)){ b32 still_looping = 0; @@ -1126,8 +1125,8 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G } internal void -buffer_remeasure_wrap_y(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 line_shift, f32 *wraps, f32 font_height, f32 *adv, f32 max_width){ - u32 new_line_count = buffer->line_count; +buffer_remeasure_wrap_y(Gap_Buffer *buffer, i32 start_line, i32 end_line, i32 line_shift, f32 *wraps, f32 font_height, f32 *adv, f32 max_width){ + i32 new_line_count = buffer->line_count; assert(0 <= start_line); assert(start_line <= end_line); @@ -1136,8 +1135,8 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li ++end_line; // Shift - u32 line_count = new_line_count; - u32 new_end_line = end_line; + i32 line_count = new_line_count; + i32 new_end_line = end_line; if (line_shift != 0){ line_count -= line_shift; new_end_line += line_shift; @@ -1147,9 +1146,9 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li // Iteration data (yikes! Need better loop system) Gap_Buffer_Stream stream = {0}; - u32 size = buffer_size(buffer); - u32 char_i = buffer->line_starts[start_line]; - u32 line_i = start_line; + i32 size = buffer_size(buffer); + i32 char_i = buffer->line_starts[start_line]; + i32 line_i = start_line; // Line wrap measurement f32 last_wrap = wraps[line_i]; @@ -1206,10 +1205,10 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li } } -internal u32 -binary_search(u32 *array, u32 value, u32 l_bound, u32 u_bound){ +internal i32 +binary_search(i32 *array, i32 value, i32 l_bound, i32 u_bound){ value = clamp_bottom(0, value); - u32 start = l_bound, end = u_bound, i = 0; + i32 start = l_bound, end = u_bound, i = 0; for (;;){ i = (start + end) >> 1; if (array[i] < value){ @@ -1230,34 +1229,34 @@ binary_search(u32 *array, u32 value, u32 l_bound, u32 u_bound){ return(i); } -inline u32 -buffer_get_line_index_range(Gap_Buffer *buffer, u32 pos, u32 l_bound, u32 u_bound){ +inline i32 +buffer_get_line_index_range(Gap_Buffer *buffer, i32 pos, i32 l_bound, i32 u_bound){ assert(0 <= l_bound); assert(l_bound <= u_bound); assert(u_bound <= buffer->line_count); assert(buffer->line_starts != 0); - u32 i = binary_search(buffer->line_starts, pos, l_bound, u_bound); + i32 i = binary_search(buffer->line_starts, pos, l_bound, u_bound); return(i); } -inline u32 -buffer_get_line_index(Gap_Buffer *buffer, u32 pos){ - u32 result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); +inline i32 +buffer_get_line_index(Gap_Buffer *buffer, i32 pos){ + i32 result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); return(result); } -inline u32 -buffer_get_line_index_from_character_pos(u32 *character_starts, u32 pos, u32 l_bound, u32 u_bound){ - u32 i = binary_search(character_starts, pos, l_bound, u_bound); +inline i32 +buffer_get_line_index_from_character_pos(i32 *character_starts, i32 pos, i32 l_bound, i32 u_bound){ + i32 i = binary_search(character_starts, pos, l_bound, u_bound); return(i); } -inline u32 -buffer_get_line_index_from_wrapped_y(u32 *wrap_line_index, f32 y, i32 line_height, u32 l_bound, u32 u_bound){ - u32 wrap_index = floor32(y/line_height); - u32 i = binary_search(wrap_line_index, wrap_index, l_bound, u_bound); +inline i32 +buffer_get_line_index_from_wrapped_y(i32 *wrap_line_index, f32 y, i32 line_height, i32 l_bound, i32 u_bound){ + i32 wrap_index = floor32(y/line_height); + i32 i = binary_search(wrap_line_index, wrap_index, l_bound, u_bound); return(i); } @@ -1277,10 +1276,10 @@ buffer_partial_from_pos(Gap_Buffer *buffer, u32 pos){ } internal Partial_Cursor -buffer_partial_from_line_character(Gap_Buffer *buffer, u32 line, u32 character, b32 reversed){ +buffer_partial_from_line_character(Gap_Buffer *buffer, i32 line, i32 character, b32 reversed){ Partial_Cursor result = {0}; - u32 line_index = line - 1; + i32 line_index = line - 1; if (line_index >= buffer->line_count){ line_index = buffer->line_count - 1; } @@ -1288,16 +1287,16 @@ buffer_partial_from_line_character(Gap_Buffer *buffer, u32 line, u32 character, line_index = 0; } - u32 size = buffer_size(buffer); + i32 size = buffer_size(buffer); - u32 this_start = buffer->line_starts[line_index]; - u32 max_character = (size-this_start) + 1; + i32 this_start = buffer->line_starts[line_index]; + i32 max_character = (size-this_start) + 1; if (line_index+1 < buffer->line_count){ - u32 next_start = buffer->line_starts[line_index+1]; + i32 next_start = buffer->line_starts[line_index+1]; max_character = (next_start-this_start); } - u32 adjusted_pos = 0; + i32 adjusted_pos = 0; if (character > 0){ if (reversed){ if (character > max_character){ @@ -1332,8 +1331,8 @@ struct Buffer_Cursor_Seek_Params{ Buffer_Seek seek; System_Functions *system; Render_Font *font; - u32 *wrap_line_index; - u32 *character_starts; + i32 *wrap_line_index; + i32 *character_starts; b32 virtual_white; b32 return_hint; Full_Cursor *cursor_out; @@ -1346,9 +1345,9 @@ struct Buffer_Cursor_Seek_State{ Gap_Buffer_Stream stream; b32 still_looping; - u32 i; - u32 size; - u32 wrap_unit_end; + i32 i; + i32 size; + i32 wrap_unit_end; b32 first_of_the_line; b32 xy_seek; @@ -1372,7 +1371,7 @@ struct Buffer_Cursor_Seek_State{ #define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); } internal Buffer_Layout_Stop -buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params params, f32 line_shift, b32 do_wrap, u32 wrap_unit_end){ +buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params params, f32 line_shift, b32 do_wrap, i32 wrap_unit_end){ Buffer_Cursor_Seek_State S = *S_ptr; Buffer_Layout_Stop S_stop; @@ -1386,11 +1385,11 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa S.font_height = font_get_height(params.font); S.xy_seek = (params.seek.type == buffer_seek_wrapped_xy || params.seek.type == buffer_seek_unwrapped_xy); - S.size = (u32)buffer_size(params.buffer); + S.size = (i32)buffer_size(params.buffer); // Get cursor hint { - u32 line_index = 0; + i32 line_index = 0; switch (params.seek.type){ case buffer_seek_pos: { @@ -1401,25 +1400,25 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa case buffer_seek_character_pos: { - u32 line_count = params.buffer->line_count; - u32 max_character = params.character_starts[line_count] - 1; - params.seek.pos = clamp_u32(0, (u32)params.seek.pos, max_character); + i32 line_count = params.buffer->line_count; + i32 max_character = params.character_starts[line_count] - 1; + params.seek.pos = clamp_i32(0, (i32)params.seek.pos, max_character); - u32 *char_starts = params.character_starts; + i32 *char_starts = params.character_starts; - u32 pos = (u32)params.seek.pos; + i32 pos = (i32)params.seek.pos; line_index = buffer_get_line_index_from_character_pos(char_starts, pos, 0, line_count); }break; case buffer_seek_line_char: { - line_index = (u32)params.seek.line - 1; + line_index = params.seek.line - 1; line_index = clamp_bottom(0, line_index); }break; case buffer_seek_unwrapped_xy: { - line_index = (u32)(params.seek.y / S.font_height); + line_index = (i32)(params.seek.y / S.font_height); line_index = clamp_bottom(0, line_index); }break; @@ -1431,7 +1430,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa default: InvalidCodePath; } - u32 safe_line_index = line_index; + i32 safe_line_index = line_index; if (line_index >= params.buffer->line_count){ safe_line_index = params.buffer->line_count-1; } @@ -1821,8 +1820,8 @@ struct Buffer_Render_Params{ struct Buffer_Render_State{ Gap_Buffer_Stream stream; b32 still_looping; - u32 i; - u32 size; + i32 i; + i32 size; f32 shift_x; f32 shift_y; @@ -1832,9 +1831,9 @@ struct Buffer_Render_State{ Render_Item_Write write; f32 byte_advance; - u32 line; - u32 wrap_line; - u32 wrap_unit_end; + i32 line; + i32 wrap_line; + i32 wrap_unit_end; b32 skipping_whitespace; b32 first_of_the_line; diff --git a/4ed_buffer_model.h b/4ed_buffer_model.h index 7f7df32a..bf214b34 100644 --- a/4ed_buffer_model.h +++ b/4ed_buffer_model.h @@ -15,8 +15,8 @@ struct Buffer_Model_Step{ u32 type; u32 value; - u32 i; - u32 byte_length; + i32 i; + i32 byte_length; }; struct Buffer_Model_Behavior{ diff --git a/4ed_file.cpp b/4ed_file.cpp index c2778da9..b168ec2d 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -21,7 +21,7 @@ enum Edit_Pos_Set_Type{ struct File_Edit_Positions{ GUI_Scroll_Vars scroll; Full_Cursor cursor; - u32 mark; + i32 mark; f32 preferred_x; i32 scroll_i; i32 last_set_type; @@ -54,7 +54,7 @@ edit_pos_set_scroll(File_Edit_Positions *edit_pos, GUI_Scroll_Vars scroll){ // struct Text_Effect{ - u32 start, end; + i32 start, end; u32 color; f32 seconds_down, seconds_max; }; @@ -109,20 +109,20 @@ global_const Editing_File_Settings null_editing_file_settings = {0}; struct Editing_File_State{ Gap_Buffer buffer; - u32 *wrap_line_index; - u32 wrap_max; + i32 *wrap_line_index; + i32 wrap_max; - u32 *character_starts; - u32 character_start_max; + i32 *character_starts; + i32 character_start_max; f32 *line_indents; - u32 line_indent_max; + i32 line_indent_max; - u32 wrap_line_count; + i32 wrap_line_count; - u32 *wrap_positions; - u32 wrap_position_count; - u32 wrap_position_max; + i32 *wrap_positions; + i32 wrap_position_count; + i32 wrap_position_max; Undo_Data undo; diff --git a/4ed_file_track.h b/4ed_file_track.h index 698f29fb..a78d1fed 100644 --- a/4ed_file_track.h +++ b/4ed_file_track.h @@ -46,7 +46,7 @@ FILE_TRACK_LINK File_Track_Result expand_track_system_listeners(File_Track_System *system, Partition *scratch, void *mem, umem size); FILE_TRACK_LINK File_Track_Result -get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, umem max); +get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, umem max, umem *size); FILE_TRACK_LINK File_Track_Result shut_down_track_system(File_Track_System *system, Partition *scratch); diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index be69bfbd..47003718 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -402,11 +402,11 @@ view_compute_cursor(System_Functions *system, View *view, Buffer_Seek seek, b32 Buffer_Cursor_Seek_State state = {0}; Buffer_Layout_Stop stop = {0}; - u32 size = buffer_size(params.buffer); + i32 size = buffer_size(params.buffer); f32 line_shift = 0.f; - u32 wrap_unit_end = 0; - u32 wrap_array_index = 0; + i32 wrap_unit_end = 0; + i32 wrap_array_index = 0; b32 do_wrap = false; b32 first_wrap_determination = true; @@ -849,14 +849,14 @@ enum{ internal i32 file_grow_starts_as_needed(General_Memory *general, Gap_Buffer *buffer, i32 additional_lines){ b32 result = GROW_NOT_NEEDED; - u32 max = buffer->line_max; - u32 count = buffer->line_count; - u32 target_lines = count + additional_lines; + i32 max = buffer->line_max; + i32 count = buffer->line_count; + i32 target_lines = count + additional_lines; if (target_lines > max || max == 0){ max = l_round_up_u32(target_lines + max, KB(1)); - u32 *new_lines = (u32*)general_memory_reallocate(general, buffer->line_starts, sizeof(u32)*count, sizeof(u32)*max); + i32 *new_lines = (i32*)general_memory_reallocate(general, buffer->line_starts, sizeof(i32)*count, sizeof(i32)*max); if (new_lines){ result = GROW_SUCCESS; @@ -896,20 +896,20 @@ file_update_cursor_positions(System_Functions *system, Models *models, Editing_F internal void file_measure_starts(General_Memory *general, Gap_Buffer *buffer){ if (!buffer->line_starts){ - u32 max = buffer->line_max = KB(1); - buffer->line_starts = (u32*)general_memory_allocate(general, max*sizeof(u32)); + i32 max = buffer->line_max = KB(1); + buffer->line_starts = (i32*)general_memory_allocate(general, max*sizeof(i32)); TentativeAssert(buffer->line_starts != 0); // TODO(allen): when unable to allocate? } Buffer_Measure_Starts state = {0}; while (buffer_measure_starts(&state, buffer)){ - u32 count = state.count; - u32 max = buffer->line_max; + i32 count = state.count; + i32 max = buffer->line_max; max = ((max + 1) << 1); { - u32 *new_lines = (u32*)general_memory_reallocate(general, buffer->line_starts, sizeof(u32)*count, sizeof(u32)*max); + i32 *new_lines = (i32*)general_memory_reallocate(general, buffer->line_starts, sizeof(i32)*count, sizeof(i32)*max); // TODO(allen): when unable to grow? TentativeAssert(new_lines); @@ -921,16 +921,16 @@ file_measure_starts(General_Memory *general, Gap_Buffer *buffer){ // NOTE(allen): These calls assumes that the buffer's line starts are already correct, and that the buffer's line_count is correct. internal void -file_allocate_metadata_as_needed(General_Memory *general, Gap_Buffer *buffer, void **mem, u32 *mem_max_count, u32 count, u32 item_size){ +file_allocate_metadata_as_needed(General_Memory *general, Gap_Buffer *buffer, void **mem, i32 *mem_max_count, i32 count, i32 item_size){ if (*mem == 0){ - u32 max = ((count+1)*2); + i32 max = ((count+1)*2); max = (max+(0x3FF))&(~(0x3FF)); *mem = general_memory_allocate(general, max*item_size); *mem_max_count = max; } else if (*mem_max_count < count){ - u32 old_max = *mem_max_count; - u32 max = ((count+1)*2); + i32 old_max = *mem_max_count; + i32 max = ((count+1)*2); max = (max+(0x3FF))&(~(0x3FF)); void *new_mem = general_memory_reallocate(general, *mem, item_size*old_max, item_size*max); @@ -989,16 +989,16 @@ struct Code_Wrap_State{ b32 in_pp_body; Code_Wrap_X plane_wrap_x; - u32 *line_starts; - u32 line_index; - u32 next_line_start; + i32 *line_starts; + i32 line_index; + i32 next_line_start; f32 x; b32 consume_newline; Gap_Buffer_Stream stream; - u32 size; - u32 i; + i32 size; + i32 i; Render_Font *font; f32 tab_indent_amount; @@ -1052,8 +1052,8 @@ wrap_state_set_top(Code_Wrap_State *state, f32 line_shift){ } struct Code_Wrap_Step{ - u32 position_start; - u32 position_end; + i32 position_start; + i32 position_end; f32 start_x; f32 final_x; @@ -1062,9 +1062,9 @@ struct Code_Wrap_Step{ }; internal Code_Wrap_Step -wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_State *state, u32 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}; - u32 i = state->i; + i32 i = state->i; result.position_start = i; @@ -1102,9 +1102,9 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_ state->next_line_start = state->line_starts[state->line_index + 1]; } - u32 line_start = state->line_starts[state->line_index]; + i32 line_start = state->line_starts[state->line_index]; b32 still_looping = 0; - u32 end = state->token_ptr->start + state->token_ptr->size; + i32 end = state->token_ptr->start + state->token_ptr->size; if (fixed_end_point >= 0 && end > fixed_end_point){ end = fixed_end_point; @@ -1391,7 +1391,7 @@ struct Wrap_Current_Shift{ }; internal Wrap_Current_Shift -get_current_shift(Code_Wrap_State *wrap_state, u32 next_line_start){ +get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start){ Wrap_Current_Shift result = {0}; result.shift = wrap_state->wrap_x.paren_nesting[wrap_state->wrap_x.paren_safe_top]; @@ -1531,7 +1531,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, Gap_Buffer_Stream stream = {0}; u32 word_stage = 0; - u32 i = stop.pos; + i32 i = stop.pos; f32 x = stop.x; f32 self_x = 0; if (buffer_stringify_loop(&stream, params.buffer, i, size)){ @@ -1589,7 +1589,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, if (use_tokens){ Code_Wrap_State original_wrap_state = wrap_state; - u32 next_line_start = buffer_size(params.buffer); + i32 next_line_start = buffer_size(params.buffer); if (stop.line_index+1 < params.buffer->line_count){ next_line_start = params.buffer->line_starts[stop.line_index+1]; } @@ -1626,11 +1626,11 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, if (wrap_state.token_ptr->type == CPP_TOKEN_COMMENT || wrap_state.token_ptr->type == CPP_TOKEN_STRING_CONSTANT){ - u32 i = wrap_state.token_ptr->start; - u32 end_i = i + wrap_state.token_ptr->size; + i32 i = wrap_state.token_ptr->start; + i32 end_i = i + wrap_state.token_ptr->size; - i = clamp_bottom((u32)wrap_state.i, i); - end_i = clamp_top(end_i, (u32)wrap_state.next_line_start); + i = clamp_bottom(wrap_state.i, i); + end_i = clamp_top(end_i, wrap_state.next_line_start); f32 x = wrap_state.x; @@ -1734,7 +1734,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, next_token_is_on_line = true; } - u32 next_wrap_position = (u32)step.position_end; + i32 next_wrap_position = step.position_end; f32 wrap_x = step.final_x; if (wrap_state.token_ptr->start > step.position_start && next_wrap_position < wrap_state.token_ptr->start && next_token_is_on_line){ next_wrap_position = wrap_state.token_ptr->start; @@ -1826,7 +1826,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, } } - u32 wrap_position = potential_marks[best_i].wrap_position; + i32 wrap_position = potential_marks[best_i].wrap_position; f32 line_shift = potential_marks[best_i].line_shift; b32 adjust_top_to_this = potential_marks[best_i].adjust_top_to_this; wrap_indent_marks[real_count].wrap_position = wrap_position; @@ -1924,7 +1924,6 @@ file_set_min_base_width(System_Functions *system, Models *models, Editing_File * internal void file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String val, b8 read_only = 0){ General_Memory *general = &models->mem.general; - Partition *part = &models->mem.part; Open_File_Hook_Function *hook_open_file = models->hook_open_file; Application_Links *app_links = &models->app_links; @@ -1940,9 +1939,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * buffer_init_provide_page(&init, data, page_size); } - u32 scratch_size = (u32)partition_remaining(part); - Assert(scratch_size > 0); - b32 init_success = buffer_end_init(&init, part->base + part->pos, scratch_size); + b32 init_success = buffer_end_init(&init); AllowLocal(init_success); Assert(init_success); if (buffer_size(&file->state.buffer) < (u32)val.size){ @@ -2281,7 +2278,7 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ } internal b32 -file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *file, u32 start_i, u32 end_i, i32 shift_amount){ +file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, i32 shift_amount){ General_Memory *general = &mem->general; Partition *part = &mem->part; @@ -3432,7 +3429,7 @@ view_replace_range(System_Functions *system, Models *models, View *view, } inline void -view_post_paste_effect(View *view, f32 seconds, u32 start, u32 size, u32 color){ +view_post_paste_effect(View *view, f32 seconds, i32 start, i32 size, i32 color){ Editing_File *file = view->file_data.file; file->state.paste_effect.start = start; @@ -5970,7 +5967,7 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act f32 line_shift = 0.f; b32 do_wrap = false; - u32 wrap_unit_end = 0; + i32 wrap_unit_end = 0; b32 first_wrap_determination = true; u32 wrap_array_index = 0; @@ -6010,7 +6007,7 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act }while(stop.status != BLStatus_Finished); } - u32 cursor_begin = 0, cursor_end = 0; + i32 cursor_begin = 0, cursor_end = 0; u32 cursor_color = 0, at_cursor_color = 0; if (view->file_data.show_temp_highlight){ cursor_begin = (u32)view->file_data.temp_highlight.pos; @@ -6038,12 +6035,12 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act u32 mark_color = style->main.mark_color; Buffer_Render_Item *item = items; Buffer_Render_Item *item_end = item + count; - u32 prev_ind = max_u32; + i32 prev_ind = max_i32; u32 highlight_color = 0; u32 highlight_this_color = 0; for (; item < item_end; ++item){ - u32 ind = item->index; + i32 ind = item->index; highlight_this_color = 0; if (tokens_use && ind != prev_ind){ Cpp_Token current_token = token_array.tokens[token_i-1]; @@ -6103,9 +6100,7 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act u32 fade_color = 0xFFFF00FF; f32 fade_amount = 0.f; - if (file->state.paste_effect.seconds_down > 0.f && - file->state.paste_effect.start <= ind && - ind < file->state.paste_effect.end){ + if (file->state.paste_effect.seconds_down > 0.f && file->state.paste_effect.start <= ind && ind < file->state.paste_effect.end){ fade_color = file->state.paste_effect.color; fade_amount = file->state.paste_effect.seconds_down; fade_amount /= file->state.paste_effect.seconds_max; diff --git a/4ed_font_data.h b/4ed_font_data.h new file mode 100644 index 00000000..07231146 --- /dev/null +++ b/4ed_font_data.h @@ -0,0 +1,59 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 03.03.2017 + * + * Font data type definitions. + * + */ + +// TOP + +#if !defined(FCODER_FONT_DATA_H) +#define FCODER_FONT_DATA_H + +#define ITEM_PER_FONT_PAGE 256 + +struct Glyph_Bounds{ + f32 x0, x1; + f32 y0, y1; + f32 xoff, yoff; + f32 xoff2, yoff2; +}; +global_const Glyph_Bounds null_glyph_bounds = {0}; + +struct Glyph_Page{ + u32 page_number; + f32 advance[ITEM_PER_FONT_PAGE]; + Glyph_Bounds glyphs[ITEM_PER_FONT_PAGE]; + u32 tex; + i32 tex_width, tex_height; +}; + +#define FONT_PAGE_EMPTY ((Glyph_Page*)0) +#define FONT_PAGE_DELETED ((Glyph_Page*)(1)) +#define FONT_PAGE_MAX 0x1100 + +struct Render_Font{ + Glyph_Page **pages; + u32 page_count, page_max; + f32 byte_advance; + f32 byte_sub_advances[3]; + i32 height, ascent, descent, line_skip, advance; + + u32 filename_len; + u32 name_len; + char filename[256]; + char name[256]; +}; + +struct Glyph_Data{ + Glyph_Bounds bounds; + u32 tex; + i32 tex_width, tex_height; +}; + +#endif + +// BOTTOM + diff --git a/4ed_font_interface.h b/4ed_font_interface.h new file mode 100644 index 00000000..d1f1eeb6 --- /dev/null +++ b/4ed_font_interface.h @@ -0,0 +1,76 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 11.03.2017 + * + * Font system interface. + * + */ + +// TOP + +#if !defined(FCODER_FONT_INTERFACE_H) +#define FCODER_FONT_INTERFACE_H + +typedef u32 Font_ID; + +struct Render_Font; +struct Glyph_Page; + +#define Sys_Font_Get_Count_Sig(name_) u32 (name_)(void) +typedef Sys_Font_Get_Count_Sig(Font_Get_Count_Function); + +#define Sys_Font_Get_IDs_By_Index_Sig(name_) b32 (name_)(u32 first_index, u32 index_count, u32 *id_out) +typedef Sys_Font_Get_IDs_By_Index_Sig(Font_Get_IDs_By_Index_Function); + +#define Sys_Font_Get_Name_By_Index_Sig(name_) u32 (name_)(u32 font_index, char *str_out, u32 str_out_cap) +typedef Sys_Font_Get_Name_By_Index_Sig(Font_Get_Name_By_Index_Function); + +#define Sys_Font_Get_Name_By_ID_Sig(name_) u32 (name_)(u32 font_id, char *str_out, u32 str_out_cap) +typedef Sys_Font_Get_Name_By_ID_Sig(Font_Get_Name_By_ID_Function); + +#define Sys_Font_Get_Render_Data_By_ID_Sig(name_) Render_Font* (name_)(u32 font_id) +typedef Sys_Font_Get_Render_Data_By_ID_Sig(Font_Get_Render_Data_By_ID_Function); + +#define Sys_Font_Load_Page_Sig(name_) void (name_)(Render_Font *font, Glyph_Page *page, u32 page_number) +typedef Sys_Font_Load_Page_Sig(Font_Load_Page_Function); + +#define Sys_Font_Allocate_Sig(name_) void* (name_)(i32 size) +typedef Sys_Font_Allocate_Sig(Font_Allocate_Function); + +#define Sys_Font_Free_Sig(name_) void (name_)(void *ptr) +typedef Sys_Font_Free_Sig(Font_Free_Function); + +struct Font_Functions{ + Font_Get_Count_Function *get_count; + Font_Get_IDs_By_Index_Function *get_ids_by_index; + Font_Get_Name_By_Index_Function *get_name_by_index; + Font_Get_Name_By_ID_Function *get_name_by_id; + Font_Get_Render_Data_By_ID_Function *get_render_data_by_id; + Font_Load_Page_Function *load_page; + + Font_Allocate_Function *allocate; + Font_Free_Function *free; +}; + +internal f32 font_get_byte_advance(Render_Font *font); +internal f32*font_get_byte_sub_advances(Render_Font *font); +internal i32 font_get_height(Render_Font *font); +internal i32 font_get_ascent(Render_Font *font); +internal i32 font_get_descent(Render_Font *font); +internal i32 font_get_line_skip(Render_Font *font); +internal i32 font_get_advance(Render_Font *font); + +internal b32 font_can_render(struct System_Functions *system, Render_Font *font, u32 codepoint); +internal f32 font_get_glyph_advance(struct System_Functions *system, Render_Font *font, u32 codepoint); + +struct Glyph_Data; +internal Glyph_Data font_get_glyph(System_Functions *system, Render_Font *font, u32 codepoint); + +internal Glyph_Page *font_get_or_make_page(struct System_Functions *system, Render_Font *font, u32 page_number); + +#endif + +// BOTTOM + + diff --git a/4ed_font_interface_to_os.h b/4ed_font_interface_to_os.h new file mode 100644 index 00000000..c9114711 --- /dev/null +++ b/4ed_font_interface_to_os.h @@ -0,0 +1,23 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 13.03.2017 + * + * Font system interface to the OS layer. + * + */ + +// TOP + +#if !defined(FCODER_FONT_INTERFACE_TO_OS_H) +#define FCODER_FONT_INTERFACE_TO_OS_H + +#define Sys_Font_Init_Sig(name_) void (name_)(Font_Functions *font, void *memory, umem memory_size, u32 font_size, b32 use_hinting) +internal Sys_Font_Init_Sig(system_font_init); + +#endif + +// BOTTOM + + + diff --git a/4ed_font_internal.cpp b/4ed_font_internal.cpp new file mode 100644 index 00000000..a8e66e65 --- /dev/null +++ b/4ed_font_internal.cpp @@ -0,0 +1,493 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 10.03.2017 + * + * Where I save crappy old font stuff. + * + */ + +// TOP + +#include "font/4coder_font_data.h" + +struct Font_Table_Entry{ + u32 hash; + String name; + Font_ID font_id; +}; + +struct Font_Info{ + Render_Font *font; + String filename; + String name; + i32 pt_size; +}; + +struct Font_Slot{ + Font_Slot *next, *prev; + Font_ID font_id; + u8 padding[6]; +}; +global_const Font_Slot null_font_slot = {0}; + +#define Font_Load_Sig(name)\ +i32 name(Render_Font *font_out, char *filename, char *fontname, i32 pt_size, i32 tab_width, b32 store_texture) +typedef Font_Load_Sig(Font_Load); + +#define Font_Load_Page_Sig(name)\ +i32 name(Render_Font *font, Glyph_Page *page, char *filename, i32 pt_size, i32 tab_width) +typedef Font_Load_Page_Sig(Font_Load_Page); + +#define Release_Font_Sig(name) void name(Render_Font *font) +typedef Release_Font_Sig(Release_Font); + +struct Font_Set{ + Font_Info *info; + Font_Table_Entry *entries; + u32 count, max; + + void *font_block; + Font_Slot free_slots; + Font_Slot used_slots; + + Font_Load *font_load; + Font_Load_Page *font_load_page; + Release_Font *release_font; + + b8 *font_used_flags; + Font_ID used_this_frame; + Font_ID live_max; +}; + +inline Font_Info* +get_font_info(Font_Set *set, Font_ID font_id){ + Font_Info *result = set->info + font_id - 1; + return(result); +} + +internal void +font_set_begin_render(Font_Set *font_set){ + font_set->used_this_frame = 0; + memset(font_set->font_used_flags, 0, font_set->max); +} + +inline u32 +font_hash(String name){ + u32 x = 5381; + char *p = name.str; + for (i32 i = 0; i < name.size; ++i, ++p){ + x = ((x << 5) + x) ^ (*p); + } + return(x); +} + +inline void +font__insert(Font_Slot *pos, Font_Slot *slot){ + Font_Slot *nex; + nex = pos->next; + + slot->next = nex; + slot->prev = pos; + nex->prev = slot; + pos->next = slot; +} + +inline void +font__remove(Font_Slot *slot){ + Font_Slot *n, *p; + n = slot->next; + p = slot->prev; + + p->next = n; + n->prev = p; +} + +internal void +font_set_init(Font_Set *set, Partition *partition, i32 max, Font_ID live_max){ + partition_align(partition, 8); + set->info = push_array(partition, Font_Info, max); + partition_align(partition, 8); + set->entries = push_array(partition, Font_Table_Entry, max); + set->count = 0; + set->max = max; + + partition_align(partition, 8); + set->font_block = push_block(partition, live_max*(sizeof(Render_Font) + sizeof(Font_Slot))); + + set->free_slots = null_font_slot; + set->used_slots = null_font_slot; + + dll_init_sentinel(&set->free_slots); + dll_init_sentinel(&set->used_slots); + + char *ptr = (char*)set->font_block; + for (i32 i = 0; i < live_max; ++i){ + dll_insert(&set->free_slots, (Font_Slot*)ptr); + ptr += sizeof(Font_Slot) + sizeof(Render_Font); + } + + set->font_used_flags = push_array(partition, b8, max); + set->live_max = live_max; +} + +internal b32 +font_set_can_add(Font_Set *set){ + b32 result = 0; + if (set->count*8 < set->max*7) result = 1; + return(result); +} + +internal void +font_set_add_hash(Font_Set *set, String name, Font_ID font_id){ + Font_Table_Entry entry; + entry.hash = font_hash(name); + entry.name = name; + entry.font_id = font_id; + + u32 i = entry.hash % set->max; + u32 j = i - 1; + if (i <= 1) j += set->max; + + for (; i != j; ++i){ + if (i == set->max) i = 0; + if (set->entries[i].font_id == 0){ + set->entries[i] = entry; + break; + } + } + + Assert(i != j); +} + +inline b32 +font_set_can_load(Font_Set *set){ + b32 result = (set->free_slots.next != &set->free_slots); + return(result); +} + +internal void +font_set_load(Font_Set *set, Font_ID font_id){ + Font_Info *info = get_font_info(set, font_id); + Font_Slot *slot = set->free_slots.next; + Assert(slot != &set->free_slots); + font__remove(slot); + font__insert(&set->used_slots, slot); + + Render_Font *font = (Render_Font*)(slot + 1); + set->font_load(font, info->filename.str, info->name.str, info->pt_size, 4, true); + info->font = font; + slot->font_id = font_id; +} + +internal void +font_set_evict_lru(Font_Set *set){ + Font_Slot *slot = set->used_slots.prev; + Assert(slot != &set->used_slots); + + Font_ID font_id = slot->font_id; + Font_Info *info = get_font_info(set, font_id); + Assert(((Font_Slot*)info->font) - 1 == slot); + + set->release_font(info->font); + + info->font = 0; + slot->font_id = 0; + font__remove(slot); + font__insert(&set->free_slots, slot); +} + +internal void +font_set_use(Font_Set *set, Font_ID font_id){ + b8 already_used = set->font_used_flags[font_id-1]; + + if (!already_used){ + if (set->used_this_frame < set->live_max){ + ++set->used_this_frame; + set->font_used_flags[font_id-1] = 1; + already_used = 1; + } + } + + if (already_used){ + // TODO(allen): optimize if you don't mind!!!! + Font_Info *info = get_font_info(set, font_id); + Font_Slot *slot; + if (info->font == 0){ + if (!font_set_can_load(set)){ + font_set_evict_lru(set); + } + font_set_load(set, font_id); + } + slot = ((Font_Slot*)info->font) - 1; + + font__remove(slot); + font__insert(&set->used_slots, slot); + } +} + +internal b32 +font_set_add(Font_Set *set, String filename, String name, i32 pt_size){ + b32 result = false; + if (font_set_can_add(set)){ + Render_Font dummy_font = {0}; + Font_ID font_id = (i16)(++set->count); + Font_Info *info = get_font_info(set, font_id); + info->filename = filename; + info->name = name; + info->pt_size = pt_size; + set->font_load(&dummy_font, info->filename.str, info->name.str, info->pt_size, 4, false); + + font_set_add_hash(set, name, font_id); + + if (font_set_can_load(set)){ + font_set_load(set, font_id); + } + + result = true; + } + return(result); +} + +internal b32 +font_set_find_pos(Font_Set *set, String name, u32 *position){ + u32 hash = font_hash(name); + u32 i = hash % set->max; + u32 j = i - 1; + if (j <= 1){ + j += set->max; + } + + b32 result = 0; + for (; i != j; ++i){ + if (i == set->max){ + i = 0; + } + + Font_Table_Entry *entry = set->entries + i; + if (entry->hash == hash){ + if (match_ss(name, entry->name)){ + result = 1; + *position = i; + break; + } + } + } + + return(result); +} + +internal b32 +font_set_get_name(Font_Set *set, Font_ID font_id, String *name){ + Font_Info *info = get_font_info(set, font_id); + b32 result = copy_checked_ss(name, info->name); + return(result); +} + +internal b32 +font_set_extract(Font_Set *set, String name, Font_ID *font_id){ + u32 position; + b32 result = font_set_find_pos(set, name, &position); + if (result){ + *font_id = set->entries[position].font_id; + } + return(result); +} + +////////////////////////////////// + +internal b32 +get_codepoint_can_render(Render_Font *font, u32 codepoint){ + b32 exists = false; + if (codepoint < 0x10FFFF){ + exists = true; + } + return(exists); +} + +struct Codepoint_Indexes{ + b32 exists; + u32 page_number; + u32 glyph_index; +}; + +internal Codepoint_Indexes +get_codepoint_page_number(Render_Font *font, u32 codepoint){ + Codepoint_Indexes result = {0}; + u32 page_number = (codepoint >> 8); + if (page_number <= 0x10FF){ + result.exists = true; + result.page_number = page_number; + result.glyph_index = (codepoint & 0x000000FF); + } + return(result); +} + +#define MAX_PAGE_COUNT (u32)(0x1100) +#define GLYPH_PAGE_EMPTY ((Glyph_Page*)(0)) +#define GLYPH_PAGE_DELETED ((Glyph_Page*)(max_u64)) +#define IS_REAL_FONT_PAGE(p) (((p) != GLYPH_PAGE_EMPTY) && ((p) != GLYPH_PAGE_DELETED)) + +internal Glyph_Page** +font_lookup_page(Render_Font *font, u32 page_number, b32 find_empty_slot){ + Glyph_Page **result = 0; + if (font->page_max > 0){ + u32 first_index = page_number % font->page_max; + + u32 range_count = 0; + u32 ranges[4]; + if (first_index == 0){ + ranges[0] = 0; + ranges[1] = font->page_max; + range_count = 2; + } + else{ + ranges[0] = first_index; + ranges[1] = font->page_max; + ranges[2] = 0; + ranges[3] = first_index; + range_count = 4; + } + + if (find_empty_slot){ + for(u32 j = 0; j < range_count; j += 2){ + u32 start = ranges[j]; + u32 stop = ranges[j+1]; + for (u32 i = start; i < stop; ++i){ + Glyph_Page *ptr = font->pages[i]; + if (ptr == GLYPH_PAGE_EMPTY || ptr == GLYPH_PAGE_DELETED){ + result = &font->pages[i]; + goto break2; + } + if (ptr->page_number == page_number){ + goto break2; + } + } + } + } + else{ + for(u32 j = 0; j < range_count; j += 2){ + u32 start = ranges[j]; + u32 stop = ranges[j+1]; + for (u32 i = start; i < stop; ++i){ + Glyph_Page *ptr = font->pages[i]; + if (ptr == GLYPH_PAGE_EMPTY){ + goto break2; + } + if (ptr != GLYPH_PAGE_DELETED){ + if (ptr->page_number == page_number){ + result = &font->pages[i]; + goto break2; + } + } + } + } + } + break2:; + } + return(result); +} + +internal Glyph_Page* +font_get_or_make_page(Render_Font *font, u32 page_number){ + Glyph_Page *page = 0; + if (page_number <= 0x10FF){ + Glyph_Page **page_ptr = font_lookup_page(font, page_number, false); + page = 0; + if (page_ptr != 0){ + page = *page_ptr; + } + + if (page == 0){ + u32 new_count = 1; + if (font->page_max < MAX_PAGE_COUNT && (font->page_count+new_count)*3 < font->page_max*2){ + u32 new_page_max = (font->page_count+new_count)*3; + new_page_max = clamp_top(new_page_max, MAX_PAGE_COUNT); + Glyph_Page **new_pages = (Glyph_Page**)ALLOCATE(new_page_max * sizeof(Glyph_Page*)); + + u32 old_page_max = font->page_max; + Glyph_Page **pages = font->pages; + for (u32 i = 0; i < old_page_max; ++i){ + Glyph_Page *current_page = pages[i]; + if (current_page != GLYPH_PAGE_EMPTY && current_page != GLYPH_PAGE_DELETED){ + Glyph_Page **dest = font_lookup_page(font, current_page->page_number, true); + Assert(dest != 0); + *dest = current_page; + } + } + + FREE(font->pages); + font->pages = new_pages; + font->page_max = new_page_max; + } + + Glyph_Page *new_page = (Glyph_Page*)ALLOCATE(sizeof(Glyph_Page)); + Glyph_Page **dest = font_lookup_page(font, page_number, true); + *dest = new_page; + ++font->page_count; + + //set->font_load_page(font, new_page, ); + } + } + return(page); +} + +internal void +get_codepoint_memory(Render_Font *font, u32 codepoint, Glyph_Bounds **bounds_mem_out, f32 **advance_mem_out){ + Glyph_Bounds *bounds = 0; + f32 *advance = 0; + + if (get_codepoint_can_render(font, codepoint)){ + Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); + Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); + bounds = &page->glyphs[indexes.glyph_index]; + advance = &page->advance[indexes.glyph_index]; + } + + *bounds_mem_out = bounds; + *advance_mem_out = advance; +} + +internal b32 +get_codepoint_glyph_data(Render_Font *font, u32 codepoint, Glyph_Data *data_out){ + b32 success = false; + if (get_codepoint_can_render(font, codepoint)){ + Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); + Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); + data_out->bounds = page->glyphs[indexes.glyph_index]; + data_out->tex = page->tex; + data_out->tex_width = page->tex_width; + data_out->tex_height = page->tex_height; + success = true; + } + return(success); +} + +internal f32 +get_codepoint_advance(Render_Font *font, u32 codepoint){ + f32 advance = (f32)font->advance; + if (get_codepoint_can_render(font, codepoint)){ + Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); + Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); + advance = page->advance[indexes.glyph_index]; + } + return(advance); +} + +internal b32 +set_codepoint_advance(Render_Font *font, u32 codepoint, f32 value){ + b32 success = false; + if (get_codepoint_can_render(font, codepoint)){ + Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); + Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); + page->advance[indexes.glyph_index] = value; + success = true; + } + return(success); +} + +// BOTTOM + + + + diff --git a/4ed_font_static_functions.cpp b/4ed_font_static_functions.cpp new file mode 100644 index 00000000..c65cd2f4 --- /dev/null +++ b/4ed_font_static_functions.cpp @@ -0,0 +1,198 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 11.03.2017 + * + * Implements some basic getters for fonts set up to make the font type opaque. + * + */ + +// TOP + +#include "4ed_font_data.h" + +internal f32 +font_get_byte_advance(Render_Font *font){ + return(font->byte_advance); +} + +internal f32* +font_get_byte_sub_advances(Render_Font *font){ + return(font->byte_sub_advances); +} + +internal i32 +font_get_height(Render_Font *font){ + return(font->height); +} + +internal i32 +font_get_ascent(Render_Font *font){ + return(font->ascent); +} + +internal i32 +font_get_descent(Render_Font *font){ + return(font->descent); +} + +internal i32 +font_get_line_skip(Render_Font *font){ + return(font->line_skip); +} + +internal i32 +font_get_advance(Render_Font *font){ + return(font->advance); +} + +internal b32 +font_can_render(System_Functions *system, Render_Font *font, u32 codepoint){ + b32 result = false; + u32 page_number = (codepoint >> 8); + u32 glyph_index = codepoint & 0xFF; + Glyph_Page *page = font_get_or_make_page(system, font, page_number); + if (page != 0 && page->advance[glyph_index] > 0.f){ + result = true; + } + return(result); +} + +internal f32 +font_get_glyph_advance(System_Functions *system, Render_Font *font, u32 codepoint){ + f32 result = 0.f; + u32 page_number = (codepoint >> 8); + u32 glyph_index = codepoint & 0xFF; + Glyph_Page *page = font_get_or_make_page(system, font, page_number); + if (page != 0 && page->advance[glyph_index] > 0.f){ + result = page->advance[glyph_index]; + } + return(result); +} + +internal Glyph_Data +font_get_glyph(System_Functions *system, Render_Font *font, u32 codepoint){ + Glyph_Data result = {0}; + u32 page_number = (codepoint >> 8); + u32 glyph_index = codepoint & 0xFF; + Glyph_Page *page = font_get_or_make_page(system, font, page_number); + if (page != 0 && page->advance[glyph_index] > 0.f){ + result.bounds = page->glyphs[glyph_index]; + result.tex = page->tex; + result.tex_width = page->tex_width; + result.tex_height = page->tex_height; + } + return(result); +} + +internal Glyph_Page** +font_page_lookup(Render_Font *font, u32 page_number, b32 get_empty_slot){ + Glyph_Page **result = 0; + + if (font->page_max > 0){ + u32 first_index = page_number % font->page_max; + + u32 range_count = 0; + u32 ranges[4]; + if (first_index == 0){ + ranges[0] = 0; + ranges[1] = font->page_max; + range_count = 2; + } + else{ + ranges[0] = first_index; + ranges[1] = font->page_max; + ranges[2] = 0; + ranges[3] = first_index; + range_count = 4; + } + + Glyph_Page **pages = font->pages; + if (get_empty_slot){ + for (u32 j = 0; j < range_count; j += 2){ + u32 stop = ranges[j+1]; + for (u32 i = ranges[j]; i < stop; ++i){ + if (pages[i] == FONT_PAGE_EMPTY || pages[i] == FONT_PAGE_DELETED){ + result = &pages[i]; + goto break2; + } + if (pages[i]->page_number == page_number){ + goto break2; + } + } + } + } + else{ + for (u32 j = 0; j < range_count; j += 2){ + u32 stop = ranges[j+1]; + for (u32 i = ranges[j]; i < stop; ++i){ + if (pages[i] == FONT_PAGE_EMPTY){ + goto break2; + } + if (pages[i] != FONT_PAGE_DELETED && pages[i]->page_number == page_number){ + result = &pages[i]; + goto break2; + } + } + } + } + + break2:; + } + + return(result); +} + +internal Glyph_Page* +font_get_or_make_page(System_Functions *system, Render_Font *font, u32 page_number){ + Glyph_Page *result = 0; + if (page_number <= 0x10FF){ + Glyph_Page **page_get_result = font_page_lookup(font, page_number, false); + + if (page_get_result == 0){ + b32 has_space = true; + u32 new_page_count = 1; + u32 new_max = (font->page_count+new_page_count)*3; + if (font->page_max < FONT_PAGE_MAX && new_max > font->page_max*2){ + Glyph_Page **pages = (Glyph_Page**)system->font.allocate(sizeof(Glyph_Page*)*new_max); + has_space = false; + if (pages != 0){ + memset(pages, 0, sizeof(*pages)*new_max); + u32 old_max = font->page_max; + for (u32 i = 0; i < old_max; ++i){ + Glyph_Page *this_page = pages[i]; + if (this_page != FONT_PAGE_EMPTY && this_page != FONT_PAGE_DELETED){ + u32 this_page_number = this_page->page_number; + Glyph_Page **dest = font_page_lookup(font, this_page_number, true); + Assert(dest != 0); + *dest = this_page; + } + } + system->font.free(font->pages); + font->pages = pages; + font->page_max = new_max; + has_space = true; + } + } + + if (has_space){ + Glyph_Page *new_page = (Glyph_Page*)system->font.allocate(sizeof(Glyph_Page)); + if (new_page != 0){ + Glyph_Page **dest = font_page_lookup(font, page_number, true); + Assert(dest != 0); + *dest = new_page; + font->page_count += new_page_count; + result = new_page; + system->font.load_page(font, new_page, page_number); + } + } + } + else{ + result = *page_get_result; + } + } + return(result); +} + +// BOTTOM + diff --git a/4ed_system.h b/4ed_system.h index 89025f84..e29ef63e 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -12,7 +12,7 @@ #if !defined(FCODER_SYSTEM_INTERFACE_H) #define FCODER_SYSTEM_INTERFACE_H -#include "font/4coder_font_interface.h" +#include "4ed_font_interface.h" // types struct Plat_Handle{ @@ -57,7 +57,7 @@ typedef Sys_Add_Listener_Sig(System_Add_Listener); #define Sys_Remove_Listener_Sig(name) b32 name(char *filename) typedef Sys_Remove_Listener_Sig(System_Remove_Listener); -#define Sys_Get_File_Change_Sig(name) i32 name(char *buffer, i32 max, b32 *mem_too_small, i32 *required_size) +#define Sys_Get_File_Change_Sig(name) i32 name(char *buffer, umem max, b32 *mem_too_small, umem *required_size) typedef Sys_Get_File_Change_Sig(System_Get_File_Change); // time @@ -212,7 +212,7 @@ typedef Sys_Memory_Set_Protection_Sig(System_Memory_Set_Protection); #define Sys_Memory_Free_Sig(name) void name(void *ptr, umem size) 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, u32 len) typedef Sys_File_Exists_Sig(System_File_Exists); #define Sys_Directory_CD_Sig(name) bool32 name(char *dir, i32 *len, i32 cap, char *rel_path, i32 rel_len) diff --git a/4ed_system_shared.cpp b/4ed_system_shared.cpp index e3fd92c3..977aaa78 100644 --- a/4ed_system_shared.cpp +++ b/4ed_system_shared.cpp @@ -12,7 +12,7 @@ #if !defined(FCODER_SYSTEM_SHARED_CPP) #define FCODER_SYSTEM_SHARED_CPP -#include "font/4coder_font_data.h" +#include "4ed_font_data.h" // // Standard implementation of file system stuff based on the file track layer. @@ -21,14 +21,14 @@ internal void init_shared_vars(){ umem scratch_size = KB(128); - void *scratch_memory = system_get_memory(scratch_size); + void *scratch_memory = system_memory_allocate(scratch_size); shared_vars.scratch = make_part(scratch_memory, scratch_size); shared_vars.track_table_size = KB(16); - shared_vars.track_table = system_get_memory(shared_vars.track_table_size); + shared_vars.track_table = system_memory_allocate(shared_vars.track_table_size); shared_vars.track_node_size = KB(16); - void *track_nodes = system_get_memory(shared_vars.track_node_size); + void *track_nodes = system_memory_allocate(shared_vars.track_node_size); i32 track_result = init_track_system(&shared_vars.track, &shared_vars.scratch, shared_vars.track_table, shared_vars.track_table_size, track_nodes, shared_vars.track_node_size); @@ -45,9 +45,10 @@ handle_track_out_of_memory(i32 val){ case FileTrack_OutOfTableMemory: { u32 new_table_size = shared_vars.track_table_size*2; - void *new_table = system_get_memory(new_table_size); + u32 old_table_size = shared_vars.track_table_size; + void *new_table = system_memory_allocate(new_table_size); move_track_system(&shared_vars.track, &shared_vars.scratch, new_table, new_table_size); - system_free_memory(shared_vars.track_table); + system_memory_free(shared_vars.track_table, old_table_size); shared_vars.track_table_size = new_table_size; shared_vars.track_table = new_table; }break; @@ -55,7 +56,7 @@ handle_track_out_of_memory(i32 val){ case FileTrack_OutOfListenerMemory: { shared_vars.track_node_size *= 2; - void *node_expansion = system_get_memory(shared_vars.track_node_size); + void *node_expansion = system_memory_allocate(shared_vars.track_node_size); expand_track_system_listeners(&shared_vars.track, &shared_vars.scratch, node_expansion, shared_vars.track_node_size); }break; @@ -67,13 +68,13 @@ handle_track_out_of_memory(i32 val){ internal Sys_Add_Listener_Sig(system_add_listener){ - b32 result = 0; + b32 result = false; for (;;){ - i32 track_result = add_listener(&shared_vars.track, &shared_vars.scratch, filename); + File_Track_Result track_result = add_listener(&shared_vars.track, &shared_vars.scratch, (u8*)filename); if (handle_track_out_of_memory(track_result)){ if (track_result == FileTrack_Good){ - result = 1; + result = true; } break; } @@ -84,10 +85,10 @@ Sys_Add_Listener_Sig(system_add_listener){ internal Sys_Remove_Listener_Sig(system_remove_listener){ - i32 result = 0; - i32 track_result = remove_listener(&shared_vars.track, &shared_vars.scratch, filename); + b32 result = false; + File_Track_Result track_result = remove_listener(&shared_vars.track, &shared_vars.scratch, (u8*)filename); if (track_result == FileTrack_Good){ - result = 1; + result = true; } return(result); } @@ -96,8 +97,8 @@ internal Sys_Get_File_Change_Sig(system_get_file_change){ b32 result = false; - i32 size = 0; - i32 get_result = get_change_event(&shared_vars.track, &shared_vars.scratch, buffer, max, &size); + umem size = 0; + File_Track_Result get_result = get_change_event(&shared_vars.track, &shared_vars.scratch, (u8*)buffer, max, &size); *required_size = size; *mem_too_small = false; @@ -127,14 +128,14 @@ sysshared_load_file(char *filename){ result.got_file = 1; if (size > 0){ result.size = size; - result.data = (char*)system_get_memory(size+1); + result.data = (char*)system_memory_allocate(size+1); if (!result.data){ result = null_file_data; } else{ if (!system_load_file(handle, result.data, size)){ - system_free_memory(result.data); + system_memory_free(result.data, size+1); result = null_file_data; } } @@ -157,11 +158,9 @@ usable_ascii(char c){ internal void sysshared_filter_real_files(char **files, i32 *file_count){ - i32 i, j; - i32 end; - - end = *file_count; - for (i = 0, j = 0; i < end; ++i){ + i32 end = *file_count; + i32 i = 0, j = 0; + for (; i < end; ++i){ if (system_file_can_be_made(files[i])){ files[j] = files[i]; ++j; @@ -172,20 +171,20 @@ sysshared_filter_real_files(char **files, i32 *file_count){ internal Partition sysshared_scratch_partition(i32 size){ - void *data = system_get_memory(size); + void *data = system_memory_allocate(size); Partition part = make_part(data, size); return(part); } +// TODO(allen): attempt to grow in place by just acquiring next vpages?! internal void -sysshared_partition_grow(Partition *part, i32 new_size){ - void *data = 0; +sysshared_partition_grow(Partition *part, umem new_size){ if (new_size > part->max){ - // TODO(allen): attempt to grow in place by just acquiring next vpages?! - data = system_get_memory(new_size); + void *data = system_memory_allocate(new_size); memcpy(data, part->base, part->pos); - system_free_memory(part->base); + system_memory_free(part->base, part->max); part->base = (char*)data; + part->max = new_size; } } diff --git a/meta/meta_parser.cpp b/meta/meta_parser.cpp index 347dc2e9..0c0f618d 100644 --- a/meta/meta_parser.cpp +++ b/meta/meta_parser.cpp @@ -886,7 +886,7 @@ static Argument_Breakdown parameter_parse(Partition *part, char *data, Cpp_Token *args_start_token, Cpp_Token *args_end_token){ int32_t arg_index = 0; Cpp_Token *arg_token = args_start_token + 1; - uint32_t param_string_start = arg_token->start; + int32_t param_string_start = arg_token->start; int32_t arg_count = 1; arg_token = args_start_token; diff --git a/power/4coder_experiments.cpp b/power/4coder_experiments.cpp index 8092a03a..3af9d57c 100644 --- a/power/4coder_experiments.cpp +++ b/power/4coder_experiments.cpp @@ -23,7 +23,7 @@ TYPE: 'build-target' #include static float -get_line_y(Application_Links *app, View_Summary *view, size_t line){ +get_line_y(Application_Links *app, View_Summary *view, int32_t line){ Full_Cursor cursor = {0}; view_compute_cursor(app, view, seek_line_char(line, 1), &cursor); float y = cursor.wrapped_y; @@ -43,9 +43,9 @@ CUSTOM_COMMAND_SIG(kill_rect){ int32_t line_count = (int32_t)(rect.y1 - rect.y0 + 1); for (int32_t line_i = line_count; line_i >= 0; --line_i){ - size_t line = rect.y0 + line_i; - size_t start = 0; - size_t end = 0; + int32_t line = rect.y0 + line_i; + int32_t start = 0; + int32_t end = 0; bool32 success = true; Full_Cursor cursor = {0}; @@ -71,7 +71,7 @@ CUSTOM_COMMAND_SIG(kill_rect){ } static void -pad_buffer_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line, char padchar, size_t target){ +pad_buffer_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line, char padchar, int32_t target){ Partial_Cursor start = {0}; Partial_Cursor end = {0}; @@ -83,7 +83,7 @@ pad_buffer_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, if (buffer_compute_cursor(app, buffer, seek_end, &end)){ if (end.character-1 < target){ Temp_Memory temp = begin_temp_memory(part); - size_t size = target - (end.character-1); + int32_t size = target - (end.character-1); char *str = push_array(part, char, size); memset(str, ' ', size); buffer_replace_range(app, buffer, end.pos, end.pos, str, size); @@ -137,10 +137,10 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ Buffer_Rect rect = get_rect(&view); - size_t start_line = view.cursor.line; - size_t pos = view.cursor.character-1; + int32_t start_line = view.cursor.line; + int32_t pos = view.cursor.character-1; - for (size_t i = rect.line0; i <= rect.line1; ++i){ + for (int32_t i = rect.line0; i <= rect.line1; ++i){ pad_buffer_line(app, &global_part, &buffer, i, ' ', pos); } @@ -158,7 +158,7 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ Buffer_Edit *edits = edit; for (int32_t i = 0; i <= line_count; ++i){ - size_t line = i + rect.line0; + int32_t line = i + rect.line0; Partial_Cursor cursor = {0}; Buffer_Seek seek = seek_line_char(line, pos+1); @@ -188,7 +188,7 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ Buffer_Edit *edits = edit; for (int32_t i = 0; i <= line_count; ++i){ - size_t line = i + rect.line0; + int32_t line = i + rect.line0; Partial_Cursor cursor = {0}; Buffer_Seek seek = seek_line_char(line, pos+1); @@ -227,11 +227,11 @@ enum{ }; static bool32 -find_scope_top(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ +find_scope_top(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - size_t position = 0; + int32_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index; @@ -287,11 +287,11 @@ find_scope_top(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, } static bool32 -find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ +find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - size_t position = 0; + int32_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index+1; @@ -348,11 +348,11 @@ find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, size_t start_p } static bool32 -find_next_scope(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ +find_next_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - size_t position = 0; + int32_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index+1; @@ -428,11 +428,11 @@ find_next_scope(Application_Links *app, Buffer_Summary *buffer, size_t start_pos } static bool32 -find_prev_scope(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ +find_prev_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - size_t position = 0; + int32_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index-1; @@ -507,7 +507,7 @@ find_prev_scope(Application_Links *app, Buffer_Summary *buffer, size_t start_pos } static void -view_set_to_region(Application_Links *app, View_Summary *view, size_t major_pos, size_t minor_pos, float normalized_threshold){ +view_set_to_region(Application_Links *app, View_Summary *view, int32_t major_pos, int32_t minor_pos, float normalized_threshold){ Range range = make_range(major_pos, minor_pos); bool32 bottom_major = false; if (major_pos == range.max){ @@ -562,8 +562,8 @@ CUSTOM_COMMAND_SIG(highlight_surrounding_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_scope_top(app, &buffer, start_pos, FindScope_Parent, &top)){ view_set_cursor(app, &view, seek_pos(top), true); if (find_scope_bottom(app, &buffer, start_pos, FindScope_Parent | FindScope_EndOfToken, &bottom)){ @@ -582,8 +582,8 @@ CUSTOM_COMMAND_SIG(highlight_first_child_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_next_scope(app, &buffer, start_pos, 0, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -598,8 +598,8 @@ CUSTOM_COMMAND_SIG(highlight_next_sibling_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_next_scope(app, &buffer, start_pos, FindScope_NextSibling, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -614,8 +614,8 @@ CUSTOM_COMMAND_SIG(highlight_prev_sibling_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_prev_scope(app, &buffer, start_pos, FindScope_NextSibling, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -630,8 +630,8 @@ CUSTOM_COMMAND_SIG(highlight_next_scope_absolute){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_next_scope(app, &buffer, start_pos, 0, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -646,8 +646,8 @@ CUSTOM_COMMAND_SIG(highlight_prev_scope_absolute){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_prev_scope(app, &buffer, start_pos, 0, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -697,11 +697,11 @@ CUSTOM_COMMAND_SIG(place_in_scope){ --max_adjustment; } - size_t min_pos = range.min + min_adjustment; - size_t max_pos = range.max + max_adjustment; + int32_t min_pos = range.min + min_adjustment; + int32_t max_pos = range.max + max_adjustment; - size_t cursor_pos = min_pos; - size_t mark_pos = max_pos; + int32_t cursor_pos = min_pos; + int32_t mark_pos = max_pos; if (view.cursor.pos > view.mark.pos){ cursor_pos = max_pos; @@ -735,11 +735,11 @@ CUSTOM_COMMAND_SIG(delete_current_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t top = view.cursor.pos; - size_t bottom = view.mark.pos; + int32_t top = view.cursor.pos; + int32_t bottom = view.mark.pos; if (top > bottom){ - Swap(size_t, top, bottom); + Swap(int32_t, top, bottom); } if (buffer_get_char(app, &buffer, top) == '{' && buffer_get_char(app, &buffer, bottom-1) == '}'){ @@ -948,10 +948,10 @@ parse_statement_down(Application_Links *app, Statement_Parser *parser, Cpp_Token } static bool32 -find_whole_statement_down(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t *start_out, size_t *end_out){ +find_whole_statement_down(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t *start_out, int32_t *end_out){ bool32 result = false; - size_t start = pos; - size_t end = start; + int32_t start = pos; + int32_t end = start; Cpp_Get_Token_Result get_result = {0}; @@ -990,11 +990,11 @@ CUSTOM_COMMAND_SIG(scope_absorb_down){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t top = view.cursor.pos; - size_t bottom = view.mark.pos; + int32_t top = view.cursor.pos; + int32_t bottom = view.mark.pos; if (top > bottom){ - Swap(size_t, top, bottom); + Swap(int32_t, top, bottom); } Partition *part = &global_part; @@ -1123,9 +1123,9 @@ CUSTOM_COMMAND_SIG(rename_parameter){ String replace_string = with.string; Buffer_Edit *edits = (Buffer_Edit*)partition_current(part); - size_t remaining = partition_remaining(part); - size_t edit_size = sizeof(Buffer_Edit); - uint32_t edit_max = (uint32_t)(remaining/edit_size); + uint32_t remaining = (uint32_t)partition_remaining(part); + uint32_t edit_size = sizeof(Buffer_Edit); + uint32_t edit_max = remaining/edit_size; uint32_t edit_count = 0; if (edit_max >= 1){ @@ -1149,7 +1149,7 @@ CUSTOM_COMMAND_SIG(rename_parameter){ switch (token_ptr->type){ case CPP_TOKEN_IDENTIFIER: { - if (token_ptr->size == (uint32_t)old_lexeme.size){ + if (token_ptr->size == old_lexeme.size){ char other_lexeme_base[128]; String other_lexeme = make_fixed_width_string(other_lexeme_base); other_lexeme.size = old_lexeme.size; diff --git a/power/4coder_miblo_numbers.cpp b/power/4coder_miblo_numbers.cpp index fc2197e1..ab2e506c 100644 --- a/power/4coder_miblo_numbers.cpp +++ b/power/4coder_miblo_numbers.cpp @@ -15,7 +15,7 @@ TYPE: 'drop-in-command-pack' #include "4coder_helper/4coder_streaming.h" static bool32 -get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, size_t *numeric_start, size_t *numeric_end){ +get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, int32_t *numeric_start, int32_t *numeric_end){ bool32 result = false; char current = buffer_get_char(app, buffer, start_pos); @@ -25,10 +25,10 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, siz int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; - size_t pos = start_pos; + int32_t pos = start_pos; - size_t pos1 = 0; - size_t pos2 = 0; + int32_t pos1 = 0; + int32_t pos2 = 0; if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){ @@ -72,15 +72,15 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, siz } struct Miblo_Number_Info{ - size_t start, end; + int32_t start, end; int32_t x; }; static bool32 -get_numeric_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t pos, Miblo_Number_Info *info){ +get_numeric_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Miblo_Number_Info *info){ bool32 result = false; - size_t numeric_start = 0, numeric_end = 0; + int32_t numeric_start = 0, numeric_end = 0; if (get_numeric_string_at_cursor(app, buffer, pos, &numeric_start, &numeric_end)){ int32_t string_length = (int32_t)(numeric_end - numeric_start); char numeric_string[1024]; @@ -133,7 +133,7 @@ CUSTOM_COMMAND_SIG(miblo_decrement_basic){ // (h+:)?m?m:ss static bool32 -get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, size_t *timestamp_start, size_t *timestamp_end){ +get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, int32_t *timestamp_start, int32_t *timestamp_end){ bool32 result = false; char current = buffer_get_char(app, buffer, start_pos); @@ -143,10 +143,10 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, s int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; - size_t pos = start_pos; + int32_t pos = start_pos; - size_t pos1 = 0; - size_t pos2 = 0; + int32_t pos1 = 0; + int32_t pos2 = 0; if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){ @@ -272,15 +272,15 @@ timestamp_to_str(String *dest, Miblo_Timestamp t){ } struct Miblo_Timestamp_Info{ - size_t start, end; + int32_t start, end; Miblo_Timestamp time; }; static bool32 -get_timestamp_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t pos, Miblo_Timestamp_Info *info){ +get_timestamp_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Miblo_Timestamp_Info *info){ bool32 result = false; - size_t timestamp_start = 0, timestamp_end = 0; + int32_t timestamp_start = 0, timestamp_end = 0; if (get_timestamp_string_at_cursor(app, buffer, pos, ×tamp_start, ×tamp_end)){ int32_t string_length = (int32_t)(timestamp_end - timestamp_start); char timestamp_string[1024]; diff --git a/win32_4ed.cpp b/win32_4ed.cpp index d97ed6a7..0f05df2c 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -72,10 +72,9 @@ ////////////////////////////// #include "4ed_file_track.h" +#include "4ed_font_interface_to_os.h" #include "4ed_system_shared.h" -#include "win32_4ed_file_track.cpp" - // // Win32_Vars structs // @@ -1148,31 +1147,35 @@ Sys_Get_Binary_Path_Sig(system_get_binary_path){ internal Sys_File_Exists_Sig(system_file_exists){ - char full_filename_space[1024]; - String full_filename; - HANDLE file; - b32 result = 0; + b32 result = false; - if (len < sizeof(full_filename_space)){ - full_filename = make_fixed_width_string(full_filename_space); - copy_ss(&full_filename, make_string(filename, len)); - terminate_with_null(&full_filename); - - file = CreateFile(full_filename.str, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + u32 filename_16_max = (len+1)*2; + u16 *filename_16 = push_array(scratch, u16, filename_16_max); + + b32 convert_error = false; + u32 filename_16_len = (u32)utf8_to_utf16_minimal_checking(filename_16, filename_16_max, (u8*)filename, len, &convert_error); + + if (!convert_error){ + filename_16[filename_16_len] = 0; + HANDLE file = CreateFile((LPWSTR)filename_16, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ CloseHandle(file); - result = 1; + result = true; } } + end_temp_memory(temp); + return(result); } internal Sys_Directory_CD_Sig(system_directory_cd){ String directory = make_string_cap(dir, *len, cap); - b32 result = 0; + b32 result = false; i32 old_size; char rel_path_space[1024]; @@ -1182,7 +1185,7 @@ Sys_Directory_CD_Sig(system_directory_cd){ if (rel_path[0] != 0){ if (rel_path[0] == '.' && rel_path[1] == 0){ - result = 1; + result = true; } else if (rel_path[0] == '.' && rel_path[1] == '.' && rel_path[2] == 0){ result = remove_last_folder(&directory); @@ -1193,8 +1196,8 @@ Sys_Directory_CD_Sig(system_directory_cd){ old_size = directory.size; append_partial_sc(&directory, rel_path); append_s_char(&directory, '\\'); - if (Win32DirectoryExists(directory.str)){ - result = 1; + if (Win32DirectoryExists((u8*)directory.str)){ + result = true; } else{ directory.size = old_size; @@ -1299,10 +1302,57 @@ Win32ReadClipboardContents(){ // Command Line Exectuion // +internal b32 +win32_create_process_utf8(char *cmd, char *command_line, char *path, STARTUPINFO *startup, PROCESS_INFORMATION *info){ + b32 result = false; + LPWSTR env_variables = 0; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 cmd_len = 0; + for (;cmd[cmd_len];++cmd_len); + + u32 command_line_len = 0; + for (;command_line[command_line_len];++command_line_len); + + u32 path_len = 0; + for (;path[path_len];++path_len); + + u32 cmd_16_max = (cmd_len+1)*2; + u32 command_line_16_max = (command_line_len+1)*2; + u32 path_16_max = (path_len+1)*2; + + u16 *cmd_16 = push_array(scratch, u16, cmd_16_max); + u16 *command_line_16 = push_array(scratch, u16, command_line_16_max); + u16 *path_16 = push_array(scratch, u16, path_16_max); + + b32 convert_error = false; + u32 cmd_16_len = (u32)utf8_to_utf16_minimal_checking(cmd_16, cmd_16_max - 1, (u8*)cmd, cmd_len, &convert_error); + if (!convert_error){ + u32 command_line_16_len = (u32)utf8_to_utf16_minimal_checking(command_line_16, command_line_16_max - 1, (u8*)command_line, command_line_len, &convert_error); + + if (!convert_error){ + u32 path_16_len = (u32)utf8_to_utf16_minimal_checking(path_16, path_16_max - 1, (u8*)path, path_len, &convert_error); + + if (!convert_error){ + cmd_16[cmd_16_len] = 0; + command_line_16[command_line_16_len] = 0; + path_16[path_16_len] = 0; + + result = CreateProcess((LPWSTR)cmd_16, (LPWSTR)command_line_16, 0, 0, TRUE, 0, env_variables, (LPWSTR)path_16, startup, info); + } + } + } + + end_temp_memory(temp); + + return(result); +} + internal Sys_CLI_Call_Sig(system_cli_call){ char cmd[] = "c:\\windows\\system32\\cmd.exe"; - char *env_variables = 0; char command_line[2048]; String s = make_fixed_width_string(command_line); @@ -1332,10 +1382,7 @@ Sys_CLI_Call_Sig(system_cli_call){ PROCESS_INFORMATION info = {}; Assert(sizeof(Plat_Handle) >= sizeof(HANDLE)); - if (CreateProcess(cmd, command_line, - 0, 0, TRUE, 0, - env_variables, path, - &startup, &info)){ + if (win32_create_process_utf8(cmd, command_line, path, &startup, &info)){ success = 1; CloseHandle(info.hThread); *(HANDLE*)&cli_out->proc = info.hProcess; @@ -2130,7 +2177,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS memory_vars.user_memory = VirtualAlloc(base, memory_vars.target_memory_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); win32vars.target.max = MB(1); - win32vars.target.push_buffer = (char*)system_get_memory(win32vars.target.max); + win32vars.target.push_buffer = (char*)system_memory_allocate(win32vars.target.max); if (memory_vars.vars_memory == 0 || memory_vars.target_memory == 0 || memory_vars.user_memory == 0 || win32vars.target.push_buffer == 0){ exit(1); @@ -2157,11 +2204,16 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // Read Command Line // - DWORD required = (GetCurrentDirectory(0, 0)*4) + 1; - char *current_directory_mem = (char*)system_get_memory(required); - DWORD written = GetCurrentDirectory(required, current_directory_mem); + DWORD cd_required = (GetCurrentDirectory(0, 0)*4) + 1; + u16 *current_directory_16 = (u16*)system_memory_allocate(cd_required*4); + DWORD written_16 = GetCurrentDirectory(cd_required, (LPWSTR)current_directory_16); - String current_directory = make_string_cap(current_directory_mem, written, required); + u8 *current_directory_mem = (u8*)(current_directory_16 + cd_required); + + b32 convert_error = false; + u32 current_directory_len = (u32)utf16_to_utf8_minimal_checking(current_directory_mem, cd_required*2, current_directory_16, written_16, &convert_error); + + String current_directory = make_string_cap(current_directory_mem, current_directory_len, cd_required*2); terminate_with_null(¤t_directory); replace_char(¤t_directory, '\\', '/'); @@ -2199,7 +2251,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS if (win32vars.custom_api.get_alpha_4coder_version == 0 || win32vars.custom_api.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){ - MessageBox(0,"Error: The application and custom version numbers don't match.\n", "Error",0); + MessageBox(0, L"Error: The application and custom version numbers don't match.\n", L"Error", 0); exit(1); } win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*) @@ -2207,7 +2259,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } if (win32vars.custom_api.get_bindings == 0){ - MessageBox(0,"Error: The custom dll is missing.\n", "Error",0); + MessageBox(0, L"Error: The custom dll is missing.\n", L"Error", 0); exit(1); } @@ -2223,8 +2275,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS window_class.style = CS_HREDRAW|CS_VREDRAW; window_class.lpfnWndProc = (WNDPROC)(Win32Callback); window_class.hInstance = hInstance; - window_class.lpszClassName = "4coder-win32-wndclass"; - window_class.hIcon = LoadIcon(hInstance, "main"); + window_class.lpszClassName = L"4coder-win32-wndclass"; + window_class.hIcon = LoadIcon(hInstance, L"main"); if (!RegisterClass(&window_class)){ exit(1); @@ -2245,7 +2297,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // TODO(allen): non-fatal diagnostics } -#define WINDOW_NAME "4coder-window: " VERSION +#define WINDOW_NAME L"4coder-window: " L_VERSION i32 window_x = CW_USEDEFAULT; i32 window_y = CW_USEDEFAULT; @@ -2334,7 +2386,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS win32vars.app.init(&win32vars.system, &win32vars.target, &memory_vars, win32vars.clipboard_contents, current_directory, win32vars.custom_api); - system_free_memory(current_directory.str); + system_memory_free(current_directory_16, 0); b32 keep_playing = 1; win32vars.first = 1; @@ -2574,10 +2626,10 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS return(0); } -#include "font/4coder_font_static_functions.cpp" +#include "4ed_font_static_functions.cpp" #include "win32_4ed_fonts.cpp" -//#include "win32_4ed_file_track.cpp" +#include "win32_4ed_file_track.cpp" #if 0 // NOTE(allen): In case I want to switch back to a console diff --git a/win32_4ed_file_track.cpp b/win32_4ed_file_track.cpp index 1794ec72..a64fcbb4 100644 --- a/win32_4ed_file_track.cpp +++ b/win32_4ed_file_track.cpp @@ -295,7 +295,7 @@ expand_track_system_listeners(File_Track_System *system, Partition *scratch, voi } FILE_TRACK_LINK File_Track_Result -get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 max, umem *size){ +get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, umem max, umem *size){ File_Track_Result result = FileTrack_NoMoreEvents; Win32_File_Track_Vars *vars = to_vars(system); @@ -341,7 +341,7 @@ get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 i32 req_size = dir_len + 1 + len; if (req_size < max){ u16 *buffer_16 = push_array(scratch, u16, req_size+1); - i32 pos = GetFinalPathNameByHandle(listener.dir, (LPWSTR)buffer_16, max, FILE_NAME_NORMALIZED); + i32 pos = GetFinalPathNameByHandle(listener.dir, (LPWSTR)buffer_16, (DWORD)max, FILE_NAME_NORMALIZED); b32 convert_error = false; umem buffer_size = utf16_to_utf8_minimal_checking(buffer, max-1, buffer_16, pos, &convert_error); diff --git a/win32_4ed_fonts.cpp b/win32_4ed_fonts.cpp index 3b50b8f3..2bc907cf 100644 --- a/win32_4ed_fonts.cpp +++ b/win32_4ed_fonts.cpp @@ -10,9 +10,9 @@ // TOP #include "4ed_system_shared.h" -#include "font/4coder_font_interface.h" -#include "font/4coder_font_interface_to_os.h" -#include "font/4coder_font_data.h" +#include "4ed_font_interface.h" +#include "4ed_font_interface_to_os.h" +#include "4ed_font_data.h" struct Win32_Fonts{ Partition part; From db39b1ea901aaf7f1e1ef6c4119eff86c797c2b6 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 23 Mar 2017 15:14:39 -0400 Subject: [PATCH 04/17] Revert "finished platform layer, it's fucked, rolling back" unfucking things This reverts commit c492bfdb4ef7bb62feba2eb66271a973bbfc1d59. --- 4coder_API/app_functions.h | 12 +- 4coder_API/types.h | 50 +-- 4coder_API/version.h | 16 - 4coder_auto_indent.cpp | 68 ++-- 4coder_base_commands.cpp | 48 +-- 4coder_clipboard.cpp | 25 +- 4coder_default_include.cpp | 20 +- 4coder_helper/4coder_helper.h | 30 +- 4coder_helper/4coder_jump_parsing.h | 6 +- 4coder_helper/4coder_long_seek.h | 180 +++++----- 4coder_helper/4coder_seek_types.h | 8 +- 4coder_jump_parsing.cpp | 12 +- 4coder_lib/4coder_table.h | 2 +- 4coder_lib/4coder_utf8.h | 4 +- 4coder_search.cpp | 70 ++-- 4cpp/4cpp_lexer.h | 6 +- 4cpp/4cpp_lexer_types.h | 18 +- 4ed.cpp | 14 +- 4ed_api_implementation.cpp | 8 +- 4ed_app_target.cpp | 2 +- 4ed_buffer.cpp | 227 ++++++------- 4ed_buffer_model.h | 4 +- 4ed_file.cpp | 22 +- 4ed_file_track.h | 2 +- 4ed_file_view.cpp | 93 +++--- 4ed_font_data.h | 59 ---- 4ed_font_interface.h | 76 ----- 4ed_font_interface_to_os.h | 23 -- 4ed_font_internal.cpp | 493 ---------------------------- 4ed_font_static_functions.cpp | 198 ----------- 4ed_system.h | 6 +- 4ed_system_shared.cpp | 55 ++-- meta/meta_parser.cpp | 2 +- power/4coder_experiments.cpp | 98 +++--- power/4coder_miblo_numbers.cpp | 28 +- win32_4ed.cpp | 122 ++----- win32_4ed_file_track.cpp | 4 +- win32_4ed_fonts.cpp | 6 +- 38 files changed, 604 insertions(+), 1513 deletions(-) delete mode 100644 4ed_font_data.h delete mode 100644 4ed_font_interface.h delete mode 100644 4ed_font_interface_to_os.h delete mode 100644 4ed_font_internal.cpp delete mode 100644 4ed_font_static_functions.cpp diff --git a/4coder_API/app_functions.h b/4coder_API/app_functions.h index 6828bd20..357ef1f1 100644 --- a/4coder_API/app_functions.h +++ b/4coder_API/app_functions.h @@ -1,9 +1,9 @@ struct Application_Links; #define EXEC_COMMAND_SIG(n) bool32 n(Application_Links *app, Command_ID command_id) #define EXEC_SYSTEM_COMMAND_SIG(n) bool32 n(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags) -#define CLIPBOARD_POST_SIG(n) void n(Application_Links *app, int32_t clipboard_id, char *str, uint32_t len) +#define CLIPBOARD_POST_SIG(n) void n(Application_Links *app, int32_t clipboard_id, char *str, size_t len) #define CLIPBOARD_COUNT_SIG(n) uint32_t n(Application_Links *app, uint32_t clipboard_id) -#define CLIPBOARD_INDEX_SIG(n) uint32_t n(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, uint32_t len) +#define CLIPBOARD_INDEX_SIG(n) size_t n(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len) #define GET_BUFFER_COUNT_SIG(n) int32_t n(Application_Links *app) #define GET_BUFFER_FIRST_SIG(n) Buffer_Summary n(Application_Links *app, Access_Flag access) #define GET_BUFFER_NEXT_SIG(n) void n(Application_Links *app, Buffer_Summary *buffer, Access_Flag access) @@ -369,9 +369,9 @@ app_links->send_exit_signal_ = Send_Exit_Signal;} while(false) #if defined(ALLOW_DEP_4CODER) static inline bool32 exec_command(Application_Links *app, Command_ID command_id){return(app->exec_command(app, command_id));} static inline bool32 exec_system_command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags){return(app->exec_system_command(app, view, buffer, path, path_len, command, command_len, flags));} -static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, uint32_t len){(app->clipboard_post(app, clipboard_id, str, len));} +static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, size_t len){(app->clipboard_post(app, clipboard_id, str, len));} static inline uint32_t clipboard_count(Application_Links *app, uint32_t clipboard_id){return(app->clipboard_count(app, clipboard_id));} -static inline uint32_t clipboard_index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, uint32_t len){return(app->clipboard_index(app, clipboard_id, item_index, out, len));} +static inline size_t clipboard_index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len){return(app->clipboard_index(app, clipboard_id, item_index, out, len));} static inline int32_t get_buffer_count(Application_Links *app){return(app->get_buffer_count(app));} static inline Buffer_Summary get_buffer_first(Application_Links *app, Access_Flag access){return(app->get_buffer_first(app, access));} static inline void get_buffer_next(Application_Links *app, Buffer_Summary *buffer, Access_Flag access){(app->get_buffer_next(app, buffer, access));} @@ -441,9 +441,9 @@ static inline void send_exit_signal(Application_Links *app){(app->send_exit_sign #else static inline bool32 exec_command(Application_Links *app, Command_ID command_id){return(app->exec_command_(app, command_id));} static inline bool32 exec_system_command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags){return(app->exec_system_command_(app, view, buffer, path, path_len, command, command_len, flags));} -static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, uint32_t len){(app->clipboard_post_(app, clipboard_id, str, len));} +static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, size_t len){(app->clipboard_post_(app, clipboard_id, str, len));} static inline uint32_t clipboard_count(Application_Links *app, uint32_t clipboard_id){return(app->clipboard_count_(app, clipboard_id));} -static inline uint32_t clipboard_index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, uint32_t len){return(app->clipboard_index_(app, clipboard_id, item_index, out, len));} +static inline size_t clipboard_index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len){return(app->clipboard_index_(app, clipboard_id, item_index, out, len));} static inline int32_t get_buffer_count(Application_Links *app){return(app->get_buffer_count_(app));} static inline Buffer_Summary get_buffer_first(Application_Links *app, Access_Flag access){return(app->get_buffer_first_(app, access));} static inline void get_buffer_next(Application_Links *app, Buffer_Summary *buffer, Access_Flag access){(app->get_buffer_next_(app, buffer, access));} diff --git a/4coder_API/types.h b/4coder_API/types.h index abee807d..380d619a 100644 --- a/4coder_API/types.h +++ b/4coder_API/types.h @@ -399,15 +399,15 @@ Throughout the API ranges are thought of in the form [min,max) where max is "one UNION Range{ STRUCT{ /* DOC(This is the smaller value in the range, it is also the 'start'.) */ - int32_t min; + size_t min; /* DOC(This is the larger value in the range, it is also the 'end'.) */ - int32_t max; + size_t max; }; STRUCT{ /* DOC(This is the start of the range, it is also the 'min'.) */ - int32_t start; + size_t start; /* DOC(This is the end of the range, it is also the 'max'.) */ - int32_t end; + size_t end; }; }; @@ -496,7 +496,7 @@ STRUCT Buffer_Seek{ UNION{ STRUCT { /* DOC(The pos field specified the pos when the seek is in absolute position.) */ - int32_t pos; + size_t pos; }; STRUCT { /* DOC(For xy coordinate seeks, rounding down means that any x in the box of the character lands on that character. For instance when clicking rounding down is the user's expected behavior. Not rounding down means that the right hand portion of the character's box, which is closer to the next character, will land on that next character. The unrounded behavior is the expected behavior when moving vertically and keeping the preferred x.) */ @@ -508,9 +508,9 @@ STRUCT Buffer_Seek{ }; STRUCT { /* DOC(The line number of a line-character type seek.) */ - int32_t line; + size_t line; /* DOC(The character number of a line-character type seek.) */ - int32_t character; + size_t character; }; }; }; @@ -519,15 +519,15 @@ STRUCT Buffer_Seek{ DOC_SEE(4coder_Buffer_Positioning_System) */ STRUCT Full_Cursor{ /* DOC(This field contains the cursor's position in absolute byte index positioning.) */ - int32_t pos; + size_t pos; /* DOC(This field contains the cursor's position in apparent character index positioning.) */ - int32_t character_pos; + size_t character_pos; /* DOC(This field contains the number of the line where the cursor is located. This field is one based.) */ - int32_t line; + size_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.) */ - int32_t character; + size_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.) */ - int32_t wrap_line; + size_t wrap_line; /* DOC(This field contains the x position measured with unwrapped lines.) */ float unwrapped_x; /* DOC(This field contains the y position measured with unwrapped lines.) */ @@ -542,24 +542,24 @@ STRUCT Full_Cursor{ DOC_SEE(4coder_Buffer_Positioning_System) */ STRUCT Partial_Cursor{ /* DOC(This field contains the cursor's position in absolute byte index positioning.) */ - int32_t pos; + size_t pos; /* DOC(This field contains the number of the character from the beginninf of the line where the cursor is located. This field is one based.) */ - int32_t line; + size_t line; /* DOC(This field contains the number of the column where the cursor is located. This field is one based.) */ - int32_t character; + size_t character; }; /* DOC(Buffer_Edit describes a range of a buffer and string to replace that range. A Buffer_Edit has to be paired with a string that contains the actual text that will be replaced into the buffer.) */ STRUCT Buffer_Edit{ /* DOC(The str_start field specifies the first character in the accompanying string that corresponds with this edit.) */ - int32_t str_start; + size_t str_start; /* DOC(The len field specifies the length of the string being written into the buffer.) */ - int32_t len; + size_t len; /* DOC(The start field specifies the start of the range in the buffer to replace in absolute position.) */ - int32_t start; + size_t start; /* DOC(The end field specifies one past the end of the range in the buffer to replace in absolute position.) */ - int32_t end; + size_t end; }; /* DOC(Buffer_Summary acts as a handle to a buffer and describes the state of the buffer.) @@ -616,7 +616,7 @@ DOC_SEE(buffer_add_markers) */ STRUCT Marker{ /* DOC(The current position of the marker measure in absolute byte positioning coordinates.) */ - int32_t pos; + size_t pos; /* DOC(When a marker is inside a range that gets edited, by default the marker 'leans_left' which means it goes to the beginning of the edited range. If the field lean_right is set to true, the marker will lean right with edits and will go to the end of edited range.) */ bool32 lean_right; }; @@ -638,10 +638,10 @@ STRUCT i32_Rect{ GLOBAL_VAR i32_Rect null_i32_rect = {0}; STRUCT pos_Rect{ - int32_t x0; - int32_t y0; - int32_t x1; - int32_t y1; + size_t x0; + size_t y0; + size_t x1; + size_t y1; }; GLOBAL_VAR pos_Rect null_pos_rect = {0}; @@ -735,7 +735,7 @@ STRUCT Buffer_Batch_Edit{ /* DOC(The pointer to the edit string buffer.) */ char *str; /* DOC(The length of the edit string buffer.) */ - int32_t str_len; + size_t str_len; /* DOC(The array of edits to be applied.) */ Buffer_Edit *edits; diff --git a/4coder_API/version.h b/4coder_API/version.h index 46e15982..496d6f8e 100644 --- a/4coder_API/version.h +++ b/4coder_API/version.h @@ -2,7 +2,6 @@ #define MINOR 0 #define PATCH 18 -// strings #define VN__(a,b,c) #a"."#b"."#c #define VN_(a,b,c) VN__(a,b,c) #define VERSION_NUMBER VN_(MAJOR,MINOR,PATCH) @@ -15,18 +14,3 @@ #endif #define VERSION VERSION_STRING VERSION_TYPE - -// long strings -#define L_VN__(a,b,c) L#a L"." L#b L"." L#c -#define L_VN_(a,b,c) L_VN__(a,b,c) -#define L_VERSION_NUMBER L_VN_(MAJOR, MINOR, PATCH) -#define L_VERSION_STRING L"alpha " L_VERSION_NUMBER - -#if defined(FRED_SUPER) -#define L_VERSION_TYPE L" super!" -#else -#define L_VERSION_TYPE -#endif - -#define L_VERSION L_VERSION_STRING L_VERSION_TYPE - diff --git a/4coder_auto_indent.cpp b/4coder_auto_indent.cpp index 7f40b38e..079e15aa 100644 --- a/4coder_auto_indent.cpp +++ b/4coder_auto_indent.cpp @@ -28,14 +28,14 @@ TYPE: 'drop-in-command-pack' // struct Hard_Start_Result{ - int32_t char_pos; + size_t char_pos; int32_t indent_pos; bool32 all_whitespace; bool32 all_space; }; static Hard_Start_Result -buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, int32_t line_start, int32_t tab_width){ +buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, size_t line_start, int32_t tab_width){ Hard_Start_Result result = {0}; result.all_space = 1; result.indent_pos = 0; @@ -49,7 +49,7 @@ buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, int32_t l if (init_stream_chunk(&stream, app, buffer, line_start, data_chunk, sizeof(data_chunk))){ int32_t still_looping = 1; do{ - for (; result.char_pos < stream.end; ++result.char_pos){ + for (; result.char_pos < (size_t)stream.end; ++result.char_pos){ char c = stream.data[result.char_pos]; if (c == '\n' || c == 0){ @@ -86,24 +86,24 @@ struct Indent_Options{ }; static Buffer_Batch_Edit -make_batch_from_indent_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line_start, int32_t line_end, int32_t *indent_marks, Indent_Options opts){ +make_batch_from_indent_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line_start, size_t line_end, int32_t *indent_marks, Indent_Options opts){ Buffer_Batch_Edit result = {0}; - uint32_t edit_max = line_end - line_start; + size_t edit_max = line_end - line_start; uint32_t edit_count = 0; Buffer_Edit *edits = push_array(part, Buffer_Edit, edit_max); char *str_base = (char*)part->base + part->pos; - int32_t str_size = 0; + size_t str_size = 0; // NOTE(allen): Shift the array so that line_i can just operate in // it's natural value range. indent_marks -= line_start; - for (int32_t line_i = line_start; line_i < line_end; ++line_i){ - int32_t line_start_pos = buffer_get_line_start(app, buffer, line_i); + for (size_t line_i = line_start; line_i < line_end; ++line_i){ + size_t line_start_pos = buffer_get_line_start(app, buffer, line_i); Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, line_start_pos, opts.tab_width); int32_t correct_indentation = indent_marks[line_i]; @@ -156,7 +156,7 @@ make_batch_from_indent_marks(Application_Links *app, Partition *part, Buffer_Sum } static void -set_line_indents(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line_start, int32_t line_end, int32_t *indent_marks, Indent_Options opts){ +set_line_indents(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line_start, size_t line_end, int32_t *indent_marks, Indent_Options opts){ Buffer_Batch_Edit batch = make_batch_from_indent_marks(app, part, buffer, line_start, line_end, indent_marks, opts); @@ -192,7 +192,7 @@ seek_matching_token_backwards(Cpp_Token_Array tokens, Cpp_Token *token, Cpp_Toke } static Cpp_Token* -find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line_start, int32_t tab_width, int32_t *current_indent_out){ +find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t line_start, int32_t tab_width, int32_t *current_indent_out){ Cpp_Token *token = get_first_token_at_line(app, buffer, tokens, line_start); if (token == 0 && tokens.count == 0){ @@ -220,8 +220,8 @@ find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Arra int32_t current_indent = 0; int32_t found_safe_start_position = 0; do{ - int32_t line = buffer_get_line_index(app, buffer, token->start); - int32_t start = buffer_get_line_start(app, buffer, line); + size_t line = buffer_get_line_index(app, buffer, token->start); + size_t start = buffer_get_line_start(app, buffer, line); Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, start, tab_width); current_indent = hard_start.indent_pos; @@ -294,9 +294,9 @@ struct Indent_Parse_State{ }; static int32_t* -get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line_start, int32_t line_end, bool32 exact_align, int32_t tab_width){ +get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t line_start, size_t line_end, bool32 exact_align, int32_t tab_width){ - int32_t indent_mark_count = line_end - line_start; + size_t indent_mark_count = line_end - line_start; int32_t *indent_marks = push_array(part, int32_t, indent_mark_count); // Shift the array so line_index works correctly. indent_marks -= line_start; @@ -306,18 +306,18 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b Cpp_Token *token_ptr = find_anchor_token(app, buffer, tokens, line_start, tab_width, &indent.current_indent); if (token_ptr == 0){ - for (int32_t line_index = line_start; line_index < line_end; ++line_index){ + for (size_t line_index = line_start; line_index < line_end; ++line_index){ indent_marks[line_index] = 0; } } else{ - int32_t line_index = buffer_get_line_index(app, buffer, token_ptr->start); + size_t line_index = buffer_get_line_index(app, buffer, token_ptr->start); if (line_index > line_start){ line_index = line_start; } - int32_t next_line_start_pos = buffer_get_line_start(app, buffer, line_index+1); + size_t next_line_start_pos = buffer_get_line_start(app, buffer, line_index+1); switch (token_ptr->type){ case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += tab_width; break; @@ -347,8 +347,8 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b { int32_t previous_indent = indent.previous_line_indent; - int32_t this_line_start = buffer_get_line_start(app, buffer, line_index); - int32_t next_line_start = buffer_get_line_start(app, buffer, line_index+1); + size_t this_line_start = buffer_get_line_start(app, buffer, line_index); + size_t next_line_start = buffer_get_line_start(app, buffer, line_index+1); bool32 did_special_behavior = false; @@ -456,8 +456,8 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b case CPP_TOKEN_COMMENT: { - int32_t line = buffer_get_line_index(app, buffer, token.start); - int32_t start = buffer_get_line_start(app, buffer, line); + size_t line = buffer_get_line_index(app, buffer, token.start); + size_t start = buffer_get_line_start(app, buffer, line); int32_t char_pos = (int32_t)(token.start - start); indent.comment_shift = (indent.current_indent - char_pos); indent.previous_comment_indent = char_pos; @@ -466,8 +466,8 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b case CPP_TOKEN_PARENTHESE_OPEN: if (!(token.flags & CPP_TFLAG_PP_BODY)){ if (indent.paren_nesting < ArrayCount(indent.paren_anchor_indent)){ - int32_t line = buffer_get_line_index(app, buffer, token.start); - int32_t start = buffer_get_line_start(app, buffer, line); + size_t line = buffer_get_line_index(app, buffer, token.start); + size_t start = buffer_get_line_start(app, buffer, line); int32_t char_pos = (int32_t)(token.start - start); Hard_Start_Result hard_start = @@ -499,21 +499,21 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b } static void -get_indent_lines_minimum(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, int32_t end_pos, int32_t *line_start_out, int32_t *line_end_out){ - int32_t line_start = buffer_get_line_index(app, buffer, start_pos); - int32_t line_end = buffer_get_line_index(app, buffer, end_pos) + 1; +get_indent_lines_minimum(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, size_t end_pos, size_t *line_start_out, size_t *line_end_out){ + size_t line_start = buffer_get_line_index(app, buffer, start_pos); + size_t line_end = buffer_get_line_index(app, buffer, end_pos) + 1; *line_start_out = line_start; *line_end_out = line_end; } static void -get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t start_pos, int32_t end_pos, int32_t *line_start_out, int32_t *line_end_out){ - int32_t line_start = buffer_get_line_index(app, buffer, start_pos); - int32_t line_end = buffer_get_line_index(app, buffer, end_pos); +get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t start_pos, size_t end_pos, size_t *line_start_out, size_t *line_end_out){ + size_t line_start = buffer_get_line_index(app, buffer, start_pos); + size_t line_end = buffer_get_line_index(app, buffer, end_pos); for (;line_start > 0;){ - int32_t line_start_pos = 0; + size_t line_start_pos = 0; Cpp_Token *token = get_first_token_at_line(app, buffer, tokens, line_start, &line_start_pos); if (token != 0 && token->start < line_start_pos){ line_start = buffer_get_line_index(app, buffer, token->start); @@ -524,7 +524,7 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cp } for (;line_end+1 < buffer->line_count;){ - int32_t next_line_start_pos = 0; + size_t next_line_start_pos = 0; Cpp_Token *token = get_first_token_at_line(app, buffer, tokens, line_end+1, &next_line_start_pos); if (token && token->start < next_line_start_pos){ line_end = buffer_get_line_index(app, buffer, token->start+token->size); @@ -545,7 +545,7 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cp } static bool32 -buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t start, int32_t end, int32_t tab_width, Auto_Indent_Flag flags){ +buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t start, size_t end, int32_t tab_width, Auto_Indent_Flag flags){ bool32 result = false; if (buffer->exists && buffer->tokens_are_ready){ @@ -562,7 +562,7 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buff // Stage 2: Decide where the first and last lines are. // The lines in the range [line_start,line_end) will be indented. - int32_t line_start = 0, line_end = 0; + size_t line_start = 0, line_end = 0; if (flags & AutoIndent_FullTokens){ get_indent_lines_whole_tokens(app, buffer, tokens, start, end, &line_start, &line_end); } @@ -591,7 +591,7 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buff } static bool32 -buffer_auto_indent(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, int32_t tab_width, Auto_Indent_Flag flags){ +buffer_auto_indent(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, int32_t tab_width, Auto_Indent_Flag flags){ bool32 result = buffer_auto_indent(app, &global_part, buffer, start, end, tab_width, flags); return(result); } diff --git a/4coder_base_commands.cpp b/4coder_base_commands.cpp index f0216d07..b47837d4 100644 --- a/4coder_base_commands.cpp +++ b/4coder_base_commands.cpp @@ -33,7 +33,7 @@ CUSTOM_COMMAND_SIG(write_character){ if (length != 0){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t pos = view.cursor.pos; + size_t pos = view.cursor.pos; Marker next_cursor_marker = {0}; next_cursor_marker.pos = character_pos_to_pos(app, &view, &buffer, view.cursor.character_pos); @@ -60,8 +60,8 @@ CUSTOM_COMMAND_SIG(delete_char){ Full_Cursor cursor; view_compute_cursor(app, &view, seek, &cursor); - int32_t start = view.cursor.pos; - int32_t end = cursor.pos; + size_t start = view.cursor.pos; + size_t end = cursor.pos; if (0 <= start && start < buffer.size){ buffer_replace_range(app, &buffer, start, end, 0, 0); @@ -77,8 +77,8 @@ CUSTOM_COMMAND_SIG(backspace_char){ Full_Cursor cursor; view_compute_cursor(app, &view, seek, &cursor); - int32_t end = view.cursor.pos; - int32_t start = cursor.pos; + size_t end = view.cursor.pos; + size_t start = cursor.pos; if (0 < end && end <= buffer.size){ buffer_replace_range(app, &buffer, start, end, 0, 0); @@ -97,8 +97,8 @@ CUSTOM_COMMAND_SIG(set_mark){ CUSTOM_COMMAND_SIG(cursor_mark_swap){ View_Summary view = get_active_view(app, AccessProtected); - int32_t cursor = view.cursor.pos; - int32_t mark = view.mark.pos; + size_t cursor = view.cursor.pos; + size_t mark = view.mark.pos; view_set_cursor(app, &view, seek_pos(mark), true); view_set_mark(app, &view, seek_pos(cursor)); @@ -250,14 +250,14 @@ CUSTOM_COMMAND_SIG(page_down){ CUSTOM_COMMAND_SIG(move_left){ uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); - int32_t new_pos = view.cursor.character_pos - 1; + size_t new_pos = view.cursor.character_pos - 1; view_set_cursor(app, &view, seek_character_pos(new_pos), 1); } CUSTOM_COMMAND_SIG(move_right){ uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); - int32_t new_pos = view.cursor.character_pos + 1; + size_t new_pos = view.cursor.character_pos + 1; view_set_cursor(app, &view, seek_character_pos(new_pos), 1); } @@ -277,7 +277,7 @@ CUSTOM_COMMAND_SIG(seek_whitespace_up){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t new_pos = buffer_seek_whitespace_up(app, &buffer, view.cursor.pos); + size_t new_pos = buffer_seek_whitespace_up(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -286,7 +286,7 @@ CUSTOM_COMMAND_SIG(seek_whitespace_down){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t new_pos = buffer_seek_whitespace_down(app, &buffer, view.cursor.pos); + size_t new_pos = buffer_seek_whitespace_down(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -295,7 +295,7 @@ CUSTOM_COMMAND_SIG(seek_end_of_textual_line){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t new_pos = seek_line_end(app, &buffer, view.cursor.pos); + size_t new_pos = seek_line_end(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -304,7 +304,7 @@ CUSTOM_COMMAND_SIG(seek_beginning_of_textual_line){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t new_pos = seek_line_beginning(app, &buffer, view.cursor.pos); + size_t new_pos = seek_line_beginning(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -350,7 +350,7 @@ CUSTOM_COMMAND_SIG(to_uppercase){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen); Range range = get_range(&view); - int32_t size = range.max - range.min; + size_t size = range.max - range.min; if (size <= app->memory_size){ char *mem = (char*)app->memory; @@ -368,7 +368,7 @@ CUSTOM_COMMAND_SIG(to_lowercase){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen); Range range = get_range(&view); - int32_t size = range.max - range.min; + size_t size = range.max - range.min; if (size <= app->memory_size){ char *mem = (char*)app->memory; @@ -580,9 +580,9 @@ isearch(Application_Links *app, bool32 start_reversed){ if (start_query_bar(app, &bar, 0) == 0) return; bool32 reverse = start_reversed; - int32_t pos = view.cursor.pos; - int32_t start_pos = pos; - int32_t first_pos = pos; + size_t pos = view.cursor.pos; + size_t start_pos = pos; + size_t first_pos = pos; Range match = make_range(pos, pos); char bar_string_space[256]; @@ -646,8 +646,8 @@ isearch(Application_Links *app, bool32 start_reversed){ if (in.key.keycode != key_back){ char *str = bar.string.str; - int32_t str_size = bar.string.size; - int32_t new_pos = 0; + size_t str_size = bar.string.size; + size_t new_pos = 0; if (reverse){ buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1, 0, str, str_size, &new_pos); if (new_pos >= 0){ @@ -723,8 +723,8 @@ CUSTOM_COMMAND_SIG(replace_in_range){ Range range = get_range(&view); - int32_t pos = range.min; - int32_t new_pos = 0; + size_t pos = range.min; + size_t new_pos = 0; buffer_seek_string_forward(app, &buffer, pos, 0, r.str, r.size, &new_pos); while (new_pos + r.size <= range.end){ @@ -765,8 +765,8 @@ CUSTOM_COMMAND_SIG(query_replace){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t pos = view.cursor.pos; - int32_t new_pos = 0; + size_t pos = view.cursor.pos; + size_t new_pos = 0; buffer_seek_string_forward(app, &buffer, pos, 0, r.str, r.size, &new_pos); User_Input in = {0}; diff --git a/4coder_clipboard.cpp b/4coder_clipboard.cpp index 8c03a3bd..b0dfbf6a 100644 --- a/4coder_clipboard.cpp +++ b/4coder_clipboard.cpp @@ -14,21 +14,21 @@ TYPE: 'drop-in-command-pack' #include "4coder_helper/4coder_helper.h" static bool32 -clipboard_copy(Application_Links *app, int32_t start, int32_t end, Buffer_Summary *buffer_out, uint32_t access){ +clipboard_copy(Application_Links *app, size_t start, size_t end, Buffer_Summary *buffer_out, uint32_t access){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - bool32 result = false; + bool32 result = 0; if (buffer.exists){ if (0 <= start && start <= end && end <= buffer.size){ - uint32_t size = (end - start); + size_t size = (end - start); char *str = (char*)app->memory; - if (size <= (uint32_t)app->memory_size){ + if (size <= app->memory_size){ buffer_read_range(app, &buffer, start, end, str); clipboard_post(app, 0, str, size); if (buffer_out){*buffer_out = buffer;} - result = true; + result = 1; } } } @@ -37,7 +37,7 @@ clipboard_copy(Application_Links *app, int32_t start, int32_t end, Buffer_Summar } static bool32 -clipboard_cut(Application_Links *app, int32_t start, int32_t end, Buffer_Summary *buffer_out, uint32_t access){ +clipboard_cut(Application_Links *app, size_t start, size_t end, Buffer_Summary *buffer_out, uint32_t access){ Buffer_Summary buffer = {0}; bool32 result = false; @@ -76,9 +76,10 @@ CUSTOM_COMMAND_SIG(paste){ int32_t paste_index = 0; view_paste_index[view.view_id].index = paste_index; - uint32_t len = clipboard_index(app, 0, paste_index, 0, 0); + size_t len = clipboard_index(app, 0, paste_index, 0, 0); char *str = 0; - if (len <= (uint32_t)app->memory_size){ + + if (len <= app->memory_size){ str = (char*)app->memory; } @@ -86,7 +87,7 @@ CUSTOM_COMMAND_SIG(paste){ clipboard_index(app, 0, paste_index, str, len); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t pos = view.cursor.pos; + size_t pos = view.cursor.pos; buffer_replace_range(app, &buffer, pos, pos, str, len); view_set_mark(app, &view, seek_pos(pos)); view_set_cursor(app, &view, seek_pos(pos + len), true); @@ -112,10 +113,10 @@ CUSTOM_COMMAND_SIG(paste_next){ int32_t paste_index = view_paste_index[view.view_id].index + 1; view_paste_index[view.view_id].index = paste_index; - uint32_t len = clipboard_index(app, 0, paste_index, 0, 0); + size_t len = clipboard_index(app, 0, paste_index, 0, 0); char *str = 0; - if (len <= (uint32_t)app->memory_size){ + if (len <= app->memory_size){ str = (char*)app->memory; } @@ -124,7 +125,7 @@ CUSTOM_COMMAND_SIG(paste_next){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); Range range = get_range(&view); - int32_t pos = range.min; + size_t pos = range.min; buffer_replace_range(app, &buffer, range.min, range.max, str, len); view_set_cursor(app, &view, seek_pos(pos + len), true); diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 84dba8f7..28e17112 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -42,9 +42,9 @@ TYPE: 'major-system-include' // Seeks Using Default Framework Memory // -static int32_t -buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags){ - int32_t result = buffer_boundary_seek(app, buffer, &global_part, start_pos, seek_forward, flags); +static size_t +buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags){ + size_t result = buffer_boundary_seek(app, buffer, &global_part, start_pos, seek_forward, flags); return(result); } @@ -53,7 +53,7 @@ basic_seek(Application_Links *app, int32_t seek_type, uint32_t flags){ uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t pos = buffer_boundary_seek(app, &buffer, view.cursor.pos, seek_type, flags); + size_t pos = buffer_boundary_seek(app, &buffer, view.cursor.pos, seek_type, flags); view_set_cursor(app, &view, seek_pos(pos), true); } @@ -115,8 +115,8 @@ CUSTOM_COMMAND_SIG(snipe_token_or_word){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t pos1 = buffer_boundary_seek(app, &buffer, view.cursor.pos, 0, BoundaryToken | BoundaryWhitespace); - int32_t pos2 = buffer_boundary_seek(app, &buffer, pos1, 1, BoundaryToken | BoundaryWhitespace); + size_t pos1 = buffer_boundary_seek(app, &buffer, view.cursor.pos, 0, BoundaryToken | BoundaryWhitespace); + size_t pos2 = buffer_boundary_seek(app, &buffer, pos1, 1, BoundaryToken | BoundaryWhitespace); Range range = make_range(pos1, pos2); buffer_replace_range(app, &buffer, range.start, range.end, 0, 0); @@ -201,7 +201,7 @@ long_braces(Application_Links *app, char *text, int32_t size){ uint32_t access = AccessOpen; View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t pos = view.cursor.pos; + size_t pos = view.cursor.pos; buffer_replace_range(app, &buffer, pos, pos, text, size); view_set_cursor(app, &view, seek_pos(pos + 2), true); @@ -333,13 +333,13 @@ file_name_in_quotes(Application_Links *app, String *file_name){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); if (buffer.file_name != 0){ - int32_t pos = view.cursor.pos; - int32_t start = 0, end = 0; + size_t pos = view.cursor.pos; + size_t start = 0, end = 0; buffer_seek_delimiter_forward(app, &buffer, pos, '"', &end); buffer_seek_delimiter_backward(app, &buffer, pos, '"', &start); ++start; - int32_t size = end - start; + size_t size = end - start; char short_file_name[128]; // NOTE(allen): This check is necessary because buffer_read_range diff --git a/4coder_helper/4coder_helper.h b/4coder_helper/4coder_helper.h index fc13c55b..7fb8cd15 100644 --- a/4coder_helper/4coder_helper.h +++ b/4coder_helper/4coder_helper.h @@ -148,7 +148,7 @@ query_user_number(Application_Links *app, Query_Bar *bar){ } static char -buffer_get_char(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ +buffer_get_char(Application_Links *app, Buffer_Summary *buffer, size_t pos){ char result = ' '; *buffer = get_buffer(app, buffer->buffer_id, AccessAll); if (pos < buffer->size){ @@ -188,7 +188,7 @@ create_buffer(Application_Links *app, char *filename, int32_t filename_len, Buff } static Range -make_range(int32_t p1, int32_t p2){ +make_range(size_t p1, size_t p2){ Range range; if (p1 < p2){ range.min = p1; @@ -212,9 +212,9 @@ adjust_all_buffer_wrap_widths(Application_Links *app, int32_t wrap_width, int32_ } // TODO(allen): Setup buffer seeking to do character_pos and get View_Summary out of this parameter list. -static int32_t -character_pos_to_pos(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, int32_t character_pos){ - int32_t result = 0; +static size_t +character_pos_to_pos(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, size_t character_pos){ + size_t result = 0; Full_Cursor cursor = {0}; if (view_compute_cursor(app, view, seek_character_pos(character_pos), &cursor)){ result = cursor.pos; @@ -223,8 +223,8 @@ character_pos_to_pos(Application_Links *app, View_Summary *view, Buffer_Summary } struct Buffer_Rect{ - int32_t char0, line0; - int32_t char1, line1; + size_t char0, line0; + size_t char1, line1; }; #ifndef Swap @@ -242,10 +242,10 @@ get_rect(View_Summary *view){ rect.line1 = view->cursor.line; if (rect.line0 > rect.line1){ - Swap(int32_t, rect.line0, rect.line1); + Swap(size_t, rect.line0, rect.line1); } if (rect.char0 > rect.char1){ - Swap(int32_t, rect.char0, rect.char1); + Swap(size_t, rect.char0, rect.char1); } return(rect); @@ -256,21 +256,21 @@ get_line_x_rect(View_Summary *view){ pos_Rect rect = {0}; if (view->unwrapped_lines){ - rect.x0 = (int32_t)view->mark.unwrapped_x; - rect.x1 = (int32_t)view->cursor.unwrapped_x; + rect.x0 = (size_t)view->mark.unwrapped_x; + rect.x1 = (size_t)view->cursor.unwrapped_x; } else{ - rect.x0 = (int32_t)view->mark.wrapped_x; - rect.x1 = (int32_t)view->cursor.wrapped_x; + rect.x0 = (size_t)view->mark.wrapped_x; + rect.x1 = (size_t)view->cursor.wrapped_x; } rect.y0 = view->mark.line; rect.y1 = view->cursor.line; if (rect.y0 > rect.y1){ - Swap(int32_t, rect.y0, rect.y1); + Swap(size_t, rect.y0, rect.y1); } if (rect.x0 > rect.x1){ - Swap(int32_t, rect.x0, rect.x1); + Swap(size_t, rect.x0, rect.x1); } return(rect); diff --git a/4coder_helper/4coder_jump_parsing.h b/4coder_helper/4coder_jump_parsing.h index 548ce9bd..d37de476 100644 --- a/4coder_helper/4coder_jump_parsing.h +++ b/4coder_helper/4coder_jump_parsing.h @@ -41,7 +41,7 @@ ms_style_verify(String line, int32_t paren_pos){ } static int32_t -parse_jump_location(String line, Name_Based_Jump_Location *location, int32_t skip_sub_errors, int32_t *colon_char){ +parse_jump_location(String line, Name_Based_Jump_Location *location, int32_t skip_sub_errors, size_t *colon_char){ bool32 result = false; int32_t whitespace_length = 0; @@ -153,13 +153,13 @@ parse_jump_location(String line, Name_Based_Jump_Location *location, int32_t ski } static bool32 -parse_jump_from_buffer_line(Application_Links *app, Partition *part, int32_t buffer_id, int32_t line, int32_t skip_sub_errors, Name_Based_Jump_Location *location){ +parse_jump_from_buffer_line(Application_Links *app, Partition *part, int32_t buffer_id, size_t line, int32_t skip_sub_errors, Name_Based_Jump_Location *location){ bool32 result = false; String line_str = {0}; Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll); if (read_line(app, part, &buffer, line, &line_str)){ - int32_t colon_char = 0; + size_t colon_char = 0; if (parse_jump_location(line_str, location, skip_sub_errors, &colon_char)){ result = true; } diff --git a/4coder_helper/4coder_long_seek.h b/4coder_helper/4coder_long_seek.h index f7148db7..831334e7 100644 --- a/4coder_helper/4coder_long_seek.h +++ b/4coder_helper/4coder_long_seek.h @@ -15,16 +15,16 @@ // Whitespace Based Seeks // -static int32_t -seek_line_end(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ +static size_t +seek_line_end(Application_Links *app, Buffer_Summary *buffer, size_t pos){ char chunk[1024]; - int32_t chunk_size = sizeof(chunk); + size_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ bool32 still_looping = true; do{ - for (; pos < (int32_t)stream.end; ++pos){ + for (; pos < (size_t)stream.end; ++pos){ char at_pos = stream.data[pos]; if (at_pos == '\n'){ goto double_break; @@ -42,17 +42,17 @@ seek_line_end(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ return(pos); } -static int32_t -seek_line_beginning(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ +static size_t +seek_line_beginning(Application_Links *app, Buffer_Summary *buffer, size_t pos){ char chunk[1024]; - int32_t chunk_size = sizeof(chunk); + size_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; --pos; if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ bool32 still_looping = false; do{ - for (; pos >= (int32_t)stream.start; --pos){ + for (; pos >= (size_t)stream.start; --pos){ char at_pos = stream.data[pos]; if (at_pos == '\n'){ goto double_break; @@ -80,12 +80,12 @@ move_past_lead_whitespace(Application_Links *app, View_Summary *view, Buffer_Sum char space[1024]; Stream_Chunk chunk = {0}; - int32_t new_pos = seek_line_beginning(app, buffer, view->cursor.pos); - int32_t i = new_pos; + size_t new_pos = seek_line_beginning(app, buffer, view->cursor.pos); + size_t i = new_pos; if (init_stream_chunk(&chunk, app, buffer, i, space, sizeof(space))){ bool32 still_looping = false; do{ - for (; i < (int32_t)chunk.end; ++i){ + for (; i < (size_t)chunk.end; ++i){ char at_pos = chunk.data[i]; if (at_pos == '\n' || !char_is_whitespace(at_pos)){ goto break2; @@ -101,10 +101,10 @@ move_past_lead_whitespace(Application_Links *app, View_Summary *view, Buffer_Sum } } -static int32_t -buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ +static size_t +buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, size_t pos){ char chunk[1024]; - int32_t chunk_size = sizeof(chunk); + size_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; --pos; @@ -113,7 +113,7 @@ buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, int32_ // behind the current position. bool32 still_looping = true; while (still_looping){ - for (; pos >= (int32_t)stream.start; --pos){ + for (; pos >= (size_t)stream.start; --pos){ char at_pos = stream.data[pos]; if (!char_is_whitespace(at_pos)){ goto double_break_1; @@ -130,7 +130,7 @@ buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, int32_ // the next '\n' int32_t no_hard = false; while (still_looping){ - for (; pos >= (int32_t)stream.start; --pos){ + for (; pos >= (size_t)stream.start; --pos){ char at_pos = stream.data[pos]; if (at_pos == '\n'){ if (no_hard){ @@ -156,10 +156,10 @@ buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, int32_ return(pos); } -static int32_t -buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ +static size_t +buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, size_t pos){ char chunk[1024]; - int32_t chunk_size = sizeof(chunk); + size_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ @@ -167,7 +167,7 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, int3 // ahead of the current position. bool32 still_looping = true; do{ - for (; pos < (int32_t)stream.end; ++pos){ + for (; pos < (size_t)stream.end; ++pos){ char at_pos = stream.data[pos]; if (!char_is_whitespace(at_pos)){ goto double_break_1; @@ -184,9 +184,9 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, int3 // all whitespace. bool32 no_hard = false; bool32 was_at_end = true; - int32_t prev_endline = 0; + size_t prev_endline = 0; while(still_looping){ - for (; pos < (int32_t)stream.end; ++pos){ + for (; pos < (size_t)stream.end; ++pos){ char at_pos = stream.data[pos]; if (at_pos == '\n'){ if (no_hard){ @@ -216,8 +216,8 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, int3 return(pos); } -static int32_t -buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ +static size_t +buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, size_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -226,7 +226,7 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, int bool32 still_looping = 1; do{ - for (; pos < (int32_t)stream.end; ++pos){ + for (; pos < (size_t)stream.end; ++pos){ if (!char_is_whitespace(stream.data[pos])){ goto double_break1; } @@ -237,7 +237,7 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, int still_looping = 1; do{ - for (; pos < (int32_t)stream.end; ++pos){ + for (; pos < (size_t)stream.end; ++pos){ if (char_is_whitespace(stream.data[pos])){ goto double_break2; } @@ -250,8 +250,8 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, int return(pos); } -static int32_t -buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ +static size_t +buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, size_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -262,7 +262,7 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, int3 bool32 still_looping = 1; do{ - for (; pos >= (int32_t)stream.start; --pos){ + for (; pos >= (size_t)stream.start; --pos){ if (!char_is_whitespace(stream.data[pos])){ goto double_break1; } @@ -273,7 +273,7 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, int3 still_looping = 1; do{ - for (; pos >= (int32_t)stream.start; --pos){ + for (; pos >= (size_t)stream.start; --pos){ if (char_is_whitespace(stream.data[pos])){ ++pos; goto double_break2; @@ -295,8 +295,8 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, int3 // Boundary Type Seeks // -static int32_t -buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ +static size_t +buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, size_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -305,7 +305,7 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, i bool32 still_looping = 1; do{ - for (; pos < (int32_t)stream.end; ++pos){ + for (; pos < (size_t)stream.end; ++pos){ if (char_is_alpha_numeric_true(stream.data[pos])){ goto double_break1; } @@ -316,7 +316,7 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, i still_looping = 1; do{ - for (; pos < (int32_t)stream.end; ++pos){ + for (; pos < (size_t)stream.end; ++pos){ if (!char_is_alpha_numeric_true(stream.data[pos])){ goto double_break2; } @@ -329,8 +329,8 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, i return(pos); } -static int32_t -buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ +static size_t +buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, size_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -341,7 +341,7 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, in bool32 still_looping = 1; do{ - for (; pos >= (int32_t)stream.start; --pos){ + for (; pos >= (size_t)stream.start; --pos){ if (char_is_alpha_numeric_true(stream.data[pos])){ goto double_break1; } @@ -352,7 +352,7 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, in still_looping = 1; do{ - for (; pos >= (int32_t)stream.start; --pos){ + for (; pos >= (size_t)stream.start; --pos){ if (!char_is_alpha_numeric_true(stream.data[pos])){ ++pos; goto double_break2; @@ -370,8 +370,8 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, in return(pos); } -static int32_t -buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t an_pos){ +static size_t +buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t an_pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -386,7 +386,7 @@ buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, in bool32 still_looping = 1; do{ - for (; pos < (int32_t)stream.end; ++pos){ + for (; pos < (size_t)stream.end; ++pos){ c = stream.data[pos]; if (char_is_upper(c) && char_is_lower(pc)){ goto double_break1; @@ -405,8 +405,8 @@ buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, in return(pos); } -static int32_t -buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t an_pos){ +static size_t +buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t an_pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -419,7 +419,7 @@ buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, int bool32 still_looping = 1; do{ - for (; pos >= (int32_t)stream.start; --pos){ + for (; pos >= (size_t)stream.start; --pos){ c = stream.data[pos]; if (char_is_upper(c) && char_is_lower(pc)){ goto double_break1; @@ -438,22 +438,22 @@ buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, int return(pos); } -static int32_t -buffer_seek_alphanumeric_or_camel_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ - int32_t an_pos = buffer_seek_alphanumeric_right(app, buffer, pos); - int32_t result = buffer_seek_range_camel_right(app, buffer, pos, an_pos); +static size_t +buffer_seek_alphanumeric_or_camel_right(Application_Links *app, Buffer_Summary *buffer, size_t pos){ + size_t an_pos = buffer_seek_alphanumeric_right(app, buffer, pos); + size_t result = buffer_seek_range_camel_right(app, buffer, pos, an_pos); return(result); } -static int32_t -buffer_seek_alphanumeric_or_camel_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ - int32_t an_pos = buffer_seek_alphanumeric_left(app, buffer, pos); - int32_t result = buffer_seek_range_camel_left(app, buffer, pos, an_pos); +static size_t +buffer_seek_alphanumeric_or_camel_left(Application_Links *app, Buffer_Summary *buffer, size_t pos){ + size_t an_pos = buffer_seek_alphanumeric_left(app, buffer, pos); + size_t result = buffer_seek_range_camel_left(app, buffer, pos, an_pos); return(result); } -static int32_t -seek_token_left(Cpp_Token_Array *tokens, int32_t pos){ +static size_t +seek_token_left(Cpp_Token_Array *tokens, size_t pos){ Cpp_Get_Token_Result get = cpp_get_token(*tokens, pos); if (get.token_index == -1){ get.token_index = 0; @@ -467,8 +467,8 @@ seek_token_left(Cpp_Token_Array *tokens, int32_t pos){ return(token->start); } -static int32_t -seek_token_right(Cpp_Token_Array *tokens, int32_t pos){ +static size_t +seek_token_right(Cpp_Token_Array *tokens, size_t pos){ Cpp_Get_Token_Result get = cpp_get_token(*tokens, pos); if (get.in_whitespace){ ++get.token_index; @@ -497,8 +497,8 @@ buffer_get_all_tokens(Application_Links *app, Partition *part, Buffer_Summary *b return(array); } -static int32_t -buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Partition *part, int32_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags)/* +static size_t +buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Partition *part, size_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags)/* DOC_PARAM(buffer, The buffer parameter specifies the buffer through which to seek.) DOC_PARAM(start_pos, The beginning position of the seek is specified by start_pos measured in absolute position.) DOC_PARAM(seek_forward, If this parameter is non-zero it indicates that the seek should move foward through the buffer.) @@ -509,14 +509,14 @@ DOC_RETURN(This call returns the absolute position where the seek stopped. If th DOC_SEE(Seek_Boundary_Flag) DOC_SEE(4coder_Buffer_Positioning_System) */{ - int32_t result = 0; + size_t result = 0; // TODO(allen): reduce duplication? Temp_Memory temp = begin_temp_memory(part); if (buffer->exists){ - int32_t pos[4]; - int32_t size = buffer->size; - int32_t new_pos = 0; + size_t pos[4]; + size_t size = buffer->size; + size_t new_pos = 0; if (start_pos < 0){ start_pos = 0; @@ -613,7 +613,7 @@ DOC_SEE(4coder_Buffer_Positioning_System) // static void -buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, char delim, int32_t *result){ +buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, size_t pos, char delim, size_t *result){ if (buffer->exists){ char chunk[1024]; int32_t size = sizeof(chunk); @@ -622,7 +622,7 @@ buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, in if (init_stream_chunk(&stream, app, buffer, pos, chunk, size)){ int32_t still_looping = 1; do{ - for(; pos < (int32_t)stream.end; ++pos){ + for(; pos < (size_t)stream.end; ++pos){ char at_pos = stream.data[pos]; if (at_pos == delim){ *result = pos; @@ -640,7 +640,7 @@ buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, in } static void -buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, char delim, int32_t *result){ +buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, size_t pos, char delim, size_t *result){ if (buffer->exists){ char chunk[1024]; int32_t size = sizeof(chunk); @@ -649,7 +649,7 @@ buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, i if (init_stream_chunk(&stream, app, buffer, pos, chunk, size)){ int32_t still_looping = 1; do{ - for(; pos >= (int32_t)stream.start; --pos){ + for(; pos >= (size_t)stream.start; --pos){ char at_pos = stream.data[pos]; if (at_pos == delim){ *result = pos; @@ -677,7 +677,7 @@ buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, i // You can push it up or do something more clever by just // replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t end, char *str, int32_t size, int32_t *result){ +buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t end, char *str, size_t size, size_t *result){ char read_buffer[512]; if (buffer->size > end){ @@ -702,7 +702,7 @@ buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, int32 if (init_stream_chunk(&stream, app, buffer, pos, chunk, sizeof(chunk))){ bool32 still_looping = 1; do{ - for(; pos < (int32_t)stream.end; ++pos){ + for(; pos < (size_t)stream.end; ++pos){ char at_pos = stream.data[pos]; if (at_pos == first_char){ buffer_read_range(app, buffer, pos, pos+size, read_buffer); @@ -732,7 +732,7 @@ buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, int32 // You can push it up or do something more clever by just // replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t min, char *str, int32_t size, int32_t *result){ +buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t min, char *str, size_t size, size_t *result){ char read_buffer[512]; *result = min-1; @@ -751,7 +751,7 @@ buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, int3 if (init_stream_chunk(&stream, app, buffer, pos, chunk, sizeof(chunk))){ int32_t still_looping = 1; do{ - for(; pos >= (int32_t)stream.start; --pos){ + for(; pos >= (size_t)stream.start; --pos){ char at_pos = stream.data[pos]; if (at_pos == first_char){ buffer_read_range(app, buffer, pos, pos+size, read_buffer); @@ -774,7 +774,7 @@ buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, int3 // You can push it up or do something more clever by just // replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t end, char *str, int32_t size, int32_t *result){ +buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t end, char *str, size_t size, size_t *result){ char read_buffer[512]; char chunk[1024]; int32_t chunk_size = sizeof(chunk); @@ -798,7 +798,7 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *b if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ bool32 still_looping = true; do{ - for(; pos < (int32_t)stream.end; ++pos){ + for(; pos < (size_t)stream.end; ++pos){ char at_pos = char_to_upper(stream.data[pos]); if (at_pos == first_char){ buffer_read_range(app, buffer, pos, pos+size, read_buffer); @@ -819,7 +819,7 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *b // You can push it up or do something more clever by just // replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t min, char *str, int32_t size, int32_t *result){ +buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t min, char *str, size_t size, size_t *result){ char read_buffer[512]; char chunk[1024]; int32_t chunk_size = sizeof(chunk); @@ -837,7 +837,7 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary * if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ int32_t still_looping = 1; do{ - for(; pos >= (int32_t)stream.start; --pos){ + for(; pos >= (size_t)stream.start; --pos){ char at_pos = char_to_upper(stream.data[pos]); if (at_pos == first_char){ buffer_read_range(app, buffer, pos, pos+size, read_buffer); @@ -860,7 +860,7 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary * // static bool32 -read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line, String *str){ +read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line, String *str){ bool32 success = false; Buffer_Seek seek_begin = seek_line_char(line, 1); @@ -872,7 +872,7 @@ read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32 if (begin.line == line){ if (buffer_compute_cursor(app, buffer, seek_end, &end)){ if (0 <= begin.pos && begin.pos <= end.pos && end.pos <= buffer->size){ - int32_t size = (end.pos - begin.pos); + size_t size = (end.pos - begin.pos); *str = make_string(push_array(part, char, size+1), (int32_t)(size+1)); if (str->str){ success = true; @@ -888,10 +888,10 @@ read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32 return(success); } -static int32_t -buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, int32_t line){ +static size_t +buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, size_t line){ Partial_Cursor partial_cursor; - int32_t result = buffer->size; + size_t result = buffer->size; if (line <= buffer->line_count){ buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &partial_cursor); result = partial_cursor.pos; @@ -899,10 +899,10 @@ buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, int32_t li return(result); } -static int32_t -buffer_get_line_end(Application_Links *app, Buffer_Summary *buffer, int32_t line){ +static size_t +buffer_get_line_end(Application_Links *app, Buffer_Summary *buffer, size_t line){ Partial_Cursor partial_cursor; - int32_t result = buffer->size; + size_t result = buffer->size; if (line <= buffer->line_count){ buffer_compute_cursor(app, buffer, seek_line_reverse_char(line, 1), &partial_cursor); result = partial_cursor.pos; @@ -911,7 +911,7 @@ buffer_get_line_end(Application_Links *app, Buffer_Summary *buffer, int32_t line } static bool32 -buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, int32_t line){ +buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, size_t line){ Partial_Cursor start, end; bool32 result = 0; if (line <= buffer->line_count){ @@ -921,17 +921,17 @@ buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, int32_t lin buffer_compute_cursor(app, buffer, seek_start, &start); buffer_compute_cursor(app, buffer, seek_end, &end); - static const int32_t chunk_size = 1024; + static const size_t chunk_size = 1024; char chunk[chunk_size]; Stream_Chunk stream = {0}; - int32_t i = start.pos; + size_t i = start.pos; stream.max_end = end.pos; result = true; if (init_stream_chunk(&stream, app, buffer, i, chunk, chunk_size)){ bool32 still_looping = false; do{ - for (;i < (int32_t)stream.end; ++i){ + for (;i < (size_t)stream.end; ++i){ char c = stream.data[i]; if (!(c == ' ' || c == '\t' || c == '\r' || c == '\v' || c == '\n')){ result = false; @@ -946,16 +946,16 @@ buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, int32_t lin return(result); } -static int32_t -buffer_get_line_index(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ +static size_t +buffer_get_line_index(Application_Links *app, Buffer_Summary *buffer, size_t pos){ Partial_Cursor partial_cursor; buffer_compute_cursor(app, buffer, seek_pos(pos), &partial_cursor); return(partial_cursor.line); } static Cpp_Token* -get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line, int32_t *line_start_out = 0){ - int32_t line_start = buffer_get_line_start(app, buffer, line); +get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t line, size_t *line_start_out = 0){ + size_t line_start = buffer_get_line_start(app, buffer, line); Cpp_Get_Token_Result get = cpp_get_token(tokens, line_start); if (get.in_whitespace){ diff --git a/4coder_helper/4coder_seek_types.h b/4coder_helper/4coder_seek_types.h index f6c61586..2d2e8a58 100644 --- a/4coder_helper/4coder_seek_types.h +++ b/4coder_helper/4coder_seek_types.h @@ -13,7 +13,7 @@ #define FRED_BUFFER_TYPES_H static Buffer_Seek -seek_pos(int32_t pos){ +seek_pos(size_t pos){ Buffer_Seek result; result.type = buffer_seek_pos; result.pos = pos; @@ -21,7 +21,7 @@ seek_pos(int32_t pos){ } static Buffer_Seek -seek_character_pos(int32_t pos){ +seek_character_pos(size_t pos){ Buffer_Seek result; result.type = buffer_seek_character_pos; result.pos = pos; @@ -59,7 +59,7 @@ seek_xy(float x, float y, bool32 round_down, bool32 unwrapped){ } static Buffer_Seek -seek_line_char(int32_t line, int32_t character){ +seek_line_char(size_t line, size_t character){ Buffer_Seek result; result.type = buffer_seek_line_char; result.line = line; @@ -68,7 +68,7 @@ seek_line_char(int32_t line, int32_t character){ } static Buffer_Seek -seek_line_reverse_char(int32_t line, int32_t character){ +seek_line_reverse_char(size_t line, size_t character){ Buffer_Seek result; result.type = buffer_seek_line_reverse_char; result.line = line; diff --git a/4coder_jump_parsing.cpp b/4coder_jump_parsing.cpp index 902334fb..3071c786 100644 --- a/4coder_jump_parsing.cpp +++ b/4coder_jump_parsing.cpp @@ -37,12 +37,12 @@ CUSTOM_COMMAND_SIG(goto_jump_at_cursor){ // static bool32 -seek_next_jump_in_buffer(Application_Links *app, Partition *part, int32_t buffer_id, int32_t first_line, bool32 skip_sub_errors, int32_t direction, int32_t *line_out, int32_t *colon_index_out, Name_Based_Jump_Location *location_out){ +seek_next_jump_in_buffer(Application_Links *app, Partition *part, int32_t buffer_id, size_t first_line, bool32 skip_sub_errors, int32_t direction, size_t *line_out, size_t *colon_index_out, Name_Based_Jump_Location *location_out){ Assert(direction == 1 || direction == -1); bool32 result = false; - int32_t line = first_line; + size_t line = first_line; String line_str = {0}; Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll); for (;;){ @@ -83,12 +83,12 @@ convert_name_based_to_id_based(Application_Links *app, Name_Based_Jump_Location } static int32_t -seek_next_jump_in_view(Application_Links *app, Partition *part, View_Summary *view, bool32 skip_sub_errors, int32_t direction, int32_t *line_out, int32_t *colon_index_out, Name_Based_Jump_Location *location_out){ +seek_next_jump_in_view(Application_Links *app, Partition *part, View_Summary *view, bool32 skip_sub_errors, int32_t direction, size_t *line_out, size_t *colon_index_out, Name_Based_Jump_Location *location_out){ int32_t result = false; Name_Based_Jump_Location location = {0}; - int32_t line = view->cursor.line; - int32_t colon_index = 0; + size_t line = view->cursor.line; + size_t colon_index = 0; if (seek_next_jump_in_buffer(app, part, view->buffer_id, line+direction, skip_sub_errors, direction, &line, &colon_index, &location)){ result = true; *line_out = line; @@ -117,7 +117,7 @@ advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_Summar Name_Based_Jump_Location location = {0}; ID_Based_Jump_Location jump = {0}; - int32_t line = 0, colon_index = 0; + size_t line = 0, colon_index = 0; do{ Temp_Memory temp = begin_temp_memory(part); diff --git a/4coder_lib/4coder_table.h b/4coder_lib/4coder_table.h index 9efb9019..044306e0 100644 --- a/4coder_lib/4coder_table.h +++ b/4coder_lib/4coder_table.h @@ -117,7 +117,7 @@ table_add(Table *table, void *item, void *arg, Hash_Function *hash_func, Compare static i32_4tech table_find_pos(Table *table, void *search_key, void *arg, i32_4tech *pos, i32_4tech *index, Hash_Function *hash_func, Compare_Function *comp_func){ - Assert(((table->count!=0)?(table->count - 1):0) * 8 < table->max * 7); + Assert((table->count - 1) * 8 < table->max * 7); u32_4tech hash = (hash_func(search_key, arg) | TableHashMin); u32_4tech i = hash % table->max; diff --git a/4coder_lib/4coder_utf8.h b/4coder_lib/4coder_utf8.h index 7d20a7e6..76d6580d 100644 --- a/4coder_lib/4coder_utf8.h +++ b/4coder_lib/4coder_utf8.h @@ -281,10 +281,10 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * static umem_4tech utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *src, umem_4tech length, b32_4tech *error){ u16_4tech *s = src; - u16_4tech *s_end = s + length; + u16_4tech *s_end = s + max_chars; u8_4tech *d = dst; - u8_4tech *d_end = d + max_chars; + u8_4tech *d_end = d + length; umem_4tech limit = length; umem_4tech needed_max = 0; diff --git a/4coder_search.cpp b/4coder_search.cpp index 694e6f84..e5c76b48 100644 --- a/4coder_search.cpp +++ b/4coder_search.cpp @@ -40,10 +40,10 @@ struct Search_Range{ int32_t type; uint32_t flags; int32_t buffer; - int32_t start; - int32_t size; - int32_t mid_start; - int32_t mid_size; + size_t start; + size_t size; + size_t mid_start; + size_t mid_size; }; struct Search_Set{ @@ -54,22 +54,22 @@ struct Search_Set{ struct Search_Iter{ String word; - int32_t pos; - int32_t back_pos; - int32_t i; + size_t pos; + size_t back_pos; + size_t i; bool32 range_initialized; }; struct Search_Match{ Buffer_Summary buffer; - int32_t start; - int32_t end; + size_t start; + size_t end; bool32 found_match; }; static void -search_iter_init(General_Memory *general, Search_Iter *iter, int32_t size){ - int32_t str_max = size*2; +search_iter_init(General_Memory *general, Search_Iter *iter, size_t size){ + size_t str_max = size*2; if (iter->word.str == 0){ iter->word.str = (char*)general_memory_allocate(general, str_max); iter->word.memory_size = (int32_t)str_max; @@ -91,7 +91,7 @@ search_set_init(General_Memory *general, Search_Set *set, int32_t range_count){ set->max = max; } else if (set->max < range_count){ - int32_t mem_size = sizeof(Search_Range)*max;; + size_t mem_size = sizeof(Search_Range)*max;; set->ranges = (Search_Range*)general_memory_reallocate_nocopy(general, set->ranges, mem_size); set->max = max; } @@ -174,14 +174,14 @@ search_hit_add(General_Memory *general, Table *hits, String_Space *space, char * return(result); } -static int32_t -buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ +static size_t +buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_Summary *buffer, size_t pos){ char space[1024]; Stream_Chunk chunk = {0}; if (init_stream_chunk(&chunk, app, buffer, pos, space, sizeof(space))){ bool32 still_looping = true; do{ - for (; pos < (int32_t)chunk.end; ++pos){ + for (; pos < (size_t)chunk.end; ++pos){ char at_pos = chunk.data[pos]; if (!char_is_alpha_numeric(at_pos)) goto double_break; } @@ -207,11 +207,11 @@ enum{ }; static int32_t -match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Match *result_ptr, String word){ +match_check(Application_Links *app, Search_Range *range, size_t *pos, Search_Match *result_ptr, String word){ int32_t found_match = FindResult_None; Search_Match result = *result_ptr; - int32_t end_pos = range->start + range->size; + size_t end_pos = range->start + range->size; uint32_t type = (range->flags & SearchFlag_MatchMask); @@ -281,14 +281,14 @@ match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Ma } static int32_t -search_front_to_back_step(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ +search_front_to_back_step(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; Search_Match result = *result_ptr; - int32_t end_pos = range->start + range->size; + size_t end_pos = range->start + range->size; if (*pos + word.size < end_pos){ - int32_t start_pos = *pos; + size_t start_pos = *pos; if (start_pos < range->start){ start_pos = range->start; } @@ -298,7 +298,7 @@ search_front_to_back_step(Application_Links *app, Search_Range *range, String wo result.buffer = get_buffer(app, range->buffer, AccessAll); char *word_str = word.str; - int32_t word_size = (int32_t)word.size; + size_t word_size = (size_t)word.size; if (case_insensitive){ buffer_seek_string_insensitive_forward(app, &result.buffer, start_pos, end_pos, word_str, word_size, &result.start); } @@ -329,7 +329,7 @@ search_front_to_back_step(Application_Links *app, Search_Range *range, String wo } static int32_t -search_front_to_back(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ +search_front_to_back(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; for (;found_match == FindResult_None;){ found_match = search_front_to_back_step(app, range, word, pos, result_ptr); @@ -338,13 +338,13 @@ search_front_to_back(Application_Links *app, Search_Range *range, String word, i } static int32_t -search_back_to_front_step(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ +search_back_to_front_step(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; Search_Match result = *result_ptr; if (*pos > range->start){ - int32_t start_pos = *pos; + size_t start_pos = *pos; result.buffer = get_buffer(app, range->buffer, AccessAll); buffer_seek_string_backward(app, &result.buffer, @@ -374,7 +374,7 @@ search_back_to_front_step(Application_Links *app, Search_Range *range, String wo } static int32_t -search_back_to_front(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ +search_back_to_front(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; for (;found_match == FindResult_None;){ found_match = search_back_to_front_step(app, range, word, pos, result_ptr); @@ -440,9 +440,9 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){ if (backward_result == FindResult_FoundMatch){ find_result = FindResult_FoundMatch; - int32_t forward_start = range->mid_start + range->mid_size; - int32_t forward_distance = forward_match.start - forward_start; - int32_t backward_distance = range->mid_start - backward_match.end; + size_t forward_start = range->mid_start + range->mid_size; + size_t forward_distance = forward_match.start - forward_start; + size_t backward_distance = range->mid_start - backward_match.end; if (backward_distance < forward_distance){ iter.pos = forward_match.start; @@ -713,8 +713,8 @@ struct Word_Complete_State{ Search_Iter iter; Table hits; String_Space str; - int32_t word_start; - int32_t word_end; + size_t word_start; + size_t word_end; bool32 initialized; }; @@ -737,10 +737,10 @@ CUSTOM_COMMAND_SIG(word_complete){ do_init = true; } - int32_t word_end = 0; - int32_t word_start = 0; - int32_t cursor_pos = 0; - int32_t size = 0; + size_t word_end = 0; + size_t word_start = 0; + size_t cursor_pos = 0; + size_t size = 0; if (do_init){ // NOTE(allen): Get the range where the partial word is written. @@ -753,7 +753,7 @@ CUSTOM_COMMAND_SIG(word_complete){ if (init_stream_chunk(&chunk, app, &buffer, cursor_pos, space, sizeof(space))){ int32_t still_looping = true; do{ - for (; cursor_pos >= (int32_t)chunk.start; --cursor_pos){ + for (; cursor_pos >= (size_t)chunk.start; --cursor_pos){ char c = chunk.data[cursor_pos]; if (char_is_alpha(c)){ word_start = cursor_pos; diff --git a/4cpp/4cpp_lexer.h b/4cpp/4cpp_lexer.h index 56e977bb..5c57ec9e 100644 --- a/4cpp/4cpp_lexer.h +++ b/4cpp/4cpp_lexer.h @@ -349,7 +349,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, u32_4tech s u8_4tech c = 0; - i32_4tech end_pos = size + S.chunk_pos; + u32_4tech end_pos = size + S.chunk_pos; chunk -= S.chunk_pos; switch (S.__pc__){ @@ -970,7 +970,7 @@ cpp_lex_nonalloc_null_end_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech } FCPP_LINK Cpp_Lex_Result -cpp_lex_nonalloc_no_null_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech size, i32_4tech full_size, +cpp_lex_nonalloc_no_null_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, u32_4tech size, u32_4tech full_size, Cpp_Token_Array *token_array_out){ Cpp_Lex_Result result = 0; if (S_ptr->pos >= full_size){ @@ -1157,7 +1157,7 @@ cpp_index_array(Cpp_Token_Array *array, i32_4tech file_size, u32_4tech index){ } API_EXPORT FCPP_LINK Cpp_Relex_Range -cpp_get_relex_range(Cpp_Token_Array *array, i32_4tech start_pos, i32_4tech end_pos) +cpp_get_relex_range(Cpp_Token_Array *array, u32_4tech start_pos, u32_4tech end_pos) /* DOC_PARAM(array, A pointer to the token array that will be modified by the relex, this array should already contain the tokens for the previous state of the file.) DOC_PARAM(start_pos, The start position of the edited region of the file. The start and end points are based on the edited region of the file before the edit.) diff --git a/4cpp/4cpp_lexer_types.h b/4cpp/4cpp_lexer_types.h index 6c45b7b5..4c597489 100644 --- a/4cpp/4cpp_lexer_types.h +++ b/4cpp/4cpp_lexer_types.h @@ -237,10 +237,10 @@ STRUCT Cpp_Token{ Cpp_Token_Type type; /* DOC(The start field indicates the index of the first character of this token's lexeme.) */ - int32_t start; + uint32_t start; /* DOC(The size field indicates the number of bytes in this token's lexeme.) */ - int32_t size; + uint32_t size; /* DOC(The state_flags should not be used outside of the lexer's implementation.) */ uint16_t state_flags; @@ -291,10 +291,10 @@ STRUCT Cpp_Get_Token_Result{ uint32_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.) */ - int32_t token_start; + uint32_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.) */ - int32_t token_end; + uint32_t token_end; }; /* DOC(Cpp_Relex_Range is the return result of the cpp_get_relex_range call.) @@ -321,12 +321,12 @@ DOC_SEE(cpp_lex_data_init) HIDE_MEMBERS() */ STRUCT Cpp_Lex_Data{ char tb[32]; - int32_t tb_pos; - int32_t token_start; + uint32_t tb_pos; + uint32_t token_start; - int32_t pos; - int32_t pos_overide; - int32_t chunk_pos; + uint32_t pos; + uint32_t pos_overide; + uint32_t chunk_pos; Cpp_Lex_FSM fsm; uint8_t white_done; diff --git a/4ed.cpp b/4ed.cpp index bb4f4865..929a0586 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -343,8 +343,8 @@ COMMAND_DECL(reopen){ General_Memory *general = &models->mem.general; File_Edit_Positions edit_poss[16]; - i32 line_number[16]; - i32 column_number[16]; + umem line_number[16]; + umem column_number[16]; View *vptrs[16]; i32 vptr_count = 0; for (View_Iter iter = file_view_iter_init(&models->layout, file, 0); @@ -364,8 +364,8 @@ COMMAND_DECL(reopen){ for (i32 i = 0; i < vptr_count; ++i){ view_set_file(system, vptrs[i], file, models); - i32 line = line_number[i]; - i32 character = column_number[i]; + umem line = line_number[i]; + umem character = column_number[i]; *vptrs[i]->edit_pos = edit_poss[i]; Full_Cursor cursor = view_compute_cursor(system, vptrs[i], seek_line_char(line, character), 0); @@ -1597,8 +1597,8 @@ App_Step_Sig(app_step){ // NOTE(allen): check files are up to date { b32 mem_too_small = 0; - umem size = 0; - umem buffer_size = KB(32); + i32 size = 0; + i32 buffer_size = KB(32); Partition *part = &models->mem.part; Temp_Memory temp = begin_temp_memory(part); @@ -1612,7 +1612,7 @@ App_Step_Sig(app_step){ for (;system->get_file_change(buffer, buffer_size, &mem_too_small, &size);){ Assert(!mem_too_small); Editing_File_Canon_Name canon; - if (get_canon_name(system, &canon, make_string(buffer, (i32)size))){ + if (get_canon_name(system, &canon, make_string(buffer, size))){ Editing_File *file = working_set_canon_contains(working_set, canon.name); if (file){ if (file->state.ignore_behind_os == 0){ diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 41a35d9f..d23b4b24 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -347,7 +347,7 @@ DOC_SEE(Command_Line_Interface_Flag) } API_EXPORT void -Clipboard_Post(Application_Links *app, int32_t clipboard_id, char *str, uint32_t len) +Clipboard_Post(Application_Links *app, int32_t clipboard_id, char *str, size_t len) /* DOC_PARAM(clipboard_id, This parameter is set up to prepare for future features, it should always be 0 for now.) DOC_PARAM(str, The str parameter specifies the string to be posted to the clipboard, it need not be null terminated.) @@ -379,8 +379,8 @@ DOC_SEE(The_4coder_Clipboard) return(count); } -API_EXPORT uint32_t -Clipboard_Index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, uint32_t len) +API_EXPORT size_t +Clipboard_Index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len) /* DOC_PARAM(clipboard_id, This parameter is set up to prepare for future features, it should always be 0 for now.) DOC_PARAM(item_index, This parameter specifies which item to read, 0 is the most recent copy, 1 is the second most recent copy, etc.) @@ -395,7 +395,7 @@ DOC_SEE(The_4coder_Clipboard) Command_Data *cmd = (Command_Data*)app->cmd_context; Working_Set *working = &cmd->models->working_set; - u32 size = 0; + size_t size = 0; String *str = working_set_clipboard_index(working, item_index); if (str){ size = str->size; diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index 88b699cc..1743cdda 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -62,7 +62,7 @@ #include "4ed_file_view.cpp" #include "4ed.cpp" -#include "4ed_font_static_functions.cpp" +#include "font/4coder_font_static_functions.cpp" // BOTTOM diff --git a/4ed_buffer.cpp b/4ed_buffer.cpp index 6c38bafa..421f04ef 100644 --- a/4ed_buffer.cpp +++ b/4ed_buffer.cpp @@ -13,7 +13,7 @@ // Buffer low level operations // -#include "4ed_font_data.h" +#include "font/4coder_font_data.h" #include "4coder_helper/4coder_seek_types.h" typedef struct Cursor_With_Index{ @@ -314,9 +314,9 @@ typedef struct Gap_Buffer{ u32 size2; u32 max; - i32 *line_starts; - i32 line_count; - i32 line_max; + u32 *line_starts; + u32 line_count; + u32 line_max; } Gap_Buffer; inline b32 @@ -338,7 +338,7 @@ typedef struct Gap_Buffer_Init{ } Gap_Buffer_Init; internal Gap_Buffer_Init -buffer_begin_init(Gap_Buffer *buffer, char *data, u32 size){ +buffer_begin_init(Gap_Buffer *buffer, char *data, i32 size){ Gap_Buffer_Init init; init.buffer = buffer; init.data = data; @@ -349,7 +349,7 @@ buffer_begin_init(Gap_Buffer *buffer, char *data, u32 size){ internal b32 buffer_init_need_more(Gap_Buffer_Init *init){ b32 result = true; - if (init->buffer->data != 0){ + if (init->buffer->data){ result = false; } return(result); @@ -369,15 +369,15 @@ buffer_init_provide_page(Gap_Buffer_Init *init, void *page, u32 page_size){ } internal b32 -buffer_end_init(Gap_Buffer_Init *init){ +buffer_end_init(Gap_Buffer_Init *init, void *scratch, u32 scratch_size){ Gap_Buffer *buffer = init->buffer; b32 result = false; - if (buffer->data != 0 && buffer->max >= init->size){ - i32 size = init->size; - i32 size2 = size*2; - i32 osize1 = size - size2; - i32 size1 = osize1; + if (buffer->data && buffer->max >= init->size){ + u32 size = init->size; + u32 size2 = size*2; + u32 osize1 = size - size2; + u32 size1 = osize1; if (size1 > 0){ size1 = eol_convert_in(buffer->data, init->data, size1); @@ -400,8 +400,8 @@ buffer_end_init(Gap_Buffer_Init *init){ typedef struct Gap_Buffer_Stream{ Gap_Buffer *buffer; char *data; - i32 end; - i32 absolute_end; + u32 end; + u32 absolute_end; b32 separated; b32 use_termination_character; char terminator; @@ -629,15 +629,15 @@ buffer_convert_out(Gap_Buffer *buffer, char *dest, u32 max){ return(pos); } -internal i32 -buffer_count_newlines(Gap_Buffer *buffer, i32 start, i32 end){ +internal u32 +buffer_count_newlines(Gap_Buffer *buffer, u32 start, u32 end){ Gap_Buffer_Stream stream = {0}; - i32 i = start; - i32 count = 0; + u32 i = start; + u32 count = 0; assert(0 <= start); assert(start <= end); - assert(end <= (i32)buffer_size(buffer)); + assert(end <= buffer_size(buffer)); if (buffer_stringify_loop(&stream, buffer, i, end)){ b32 still_looping = 0; @@ -653,9 +653,9 @@ buffer_count_newlines(Gap_Buffer *buffer, i32 start, i32 end){ } typedef struct Buffer_Measure_Starts{ - i32 i; - i32 count; - i32 start; + u32 i; + u32 count; + u32 start; } Buffer_Measure_Starts; // TODO(allen): Rewrite this with a duff routine @@ -664,10 +664,10 @@ typedef struct Buffer_Measure_Starts{ internal b32 buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){ Gap_Buffer_Stream stream = {0}; - i32 size = (i32)buffer_size(buffer); - i32 start = state->start, i = state->i; - i32 *start_ptr = buffer->line_starts + state->count; - i32 *start_end = buffer->line_starts + buffer->line_max; + u32 size = (u32)buffer_size(buffer); + u32 start = state->start, i = state->i; + u32 *start_ptr = buffer->line_starts + state->count; + u32 *start_end = buffer->line_starts + buffer->line_max; b32 result = true; if (buffer_stringify_loop(&stream, buffer, i, size)){ @@ -707,13 +707,13 @@ buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){ } internal void -buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, i32 *character_starts, i32 mode, b32 virtual_white){ +buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, u32 *character_starts, i32 mode, b32 virtual_white){ assert(mode == 0); Gap_Buffer_Stream stream = {0}; - i32 line_index = 0; - i32 character_index = 0; + u32 line_index = 0; + u32 character_index = 0; character_starts[line_index++] = character_index; @@ -728,8 +728,8 @@ buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap stream.use_termination_character = 1; stream.terminator = '\n'; - i32 size = (i32)buffer_size(buffer); - i32 i = 0; + u32 size = buffer_size(buffer); + u32 i = 0; if (buffer_stringify_loop(&stream, buffer, i, size)){ b32 still_looping = false; do{ @@ -774,17 +774,17 @@ enum{ }; struct Buffer_Layout_Stop{ - i32 status; - i32 line_index; - i32 wrap_line_index; - i32 pos; - i32 next_line_pos; + u32 status; + u32 line_index; + u32 wrap_line_index; + u32 pos; + u32 next_line_pos; f32 x; }; struct Buffer_Measure_Wrap_Params{ Gap_Buffer *buffer; - i32 *wrap_line_index; + u32 *wrap_line_index; System_Functions *system; Render_Font *font; b32 virtual_white; @@ -792,17 +792,17 @@ struct Buffer_Measure_Wrap_Params{ struct Buffer_Measure_Wrap_State{ Gap_Buffer_Stream stream; - i32 i; - i32 size; + u32 i; + u32 size; b32 still_looping; - i32 line_index; + u32 line_index; - i32 current_wrap_index; + u32 current_wrap_index; f32 current_adv; f32 x; - i32 wrap_unit_end; + u32 wrap_unit_end; b32 skipping_whitespace; b32 did_wrap; b32 first_of_the_line; @@ -950,9 +950,9 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para #undef DrReturn internal void -buffer_remeasure_starts(Gap_Buffer *buffer, i32 start_line, i32 end_line, i32 line_shift, i32 text_shift){ - i32 *starts = buffer->line_starts; - i32 line_count = buffer->line_count; +buffer_remeasure_starts(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 line_shift, i32 text_shift){ + u32 *starts = buffer->line_starts; + u32 line_count = buffer->line_count; assert(0 <= start_line); assert(start_line <= end_line); @@ -963,7 +963,7 @@ buffer_remeasure_starts(Gap_Buffer *buffer, i32 start_line, i32 end_line, i32 li // Adjust if (text_shift != 0){ - i32 line_i = end_line; + u32 line_i = end_line; starts += line_i; for (; line_i < line_count; ++line_i, ++starts){ *starts += text_shift; @@ -972,8 +972,8 @@ buffer_remeasure_starts(Gap_Buffer *buffer, i32 start_line, i32 end_line, i32 li } // Shift - i32 new_line_count = line_count; - i32 new_end_line = end_line; + u32 new_line_count = line_count; + u32 new_end_line = end_line; if (line_shift != 0){ new_line_count += line_shift; new_end_line += line_shift; @@ -984,12 +984,12 @@ buffer_remeasure_starts(Gap_Buffer *buffer, i32 start_line, i32 end_line, i32 li // Iteration data (yikes! Need better loop system) Gap_Buffer_Stream stream = {0}; - i32 size = buffer_size(buffer); - i32 char_i = starts[start_line]; - i32 line_i = start_line; + u32 size = buffer_size(buffer); + u32 char_i = starts[start_line]; + u32 line_i = start_line; // Line start measurement - i32 start = char_i; + u32 start = char_i; if (buffer_stringify_loop(&stream, buffer, char_i, size)){ b32 still_looping = 0; @@ -1023,10 +1023,10 @@ buffer_remeasure_starts(Gap_Buffer *buffer, i32 start_line, i32 end_line, i32 li } internal void -buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, i32 start_line, i32 end_line, i32 line_shift, i32 *character_starts, i32 mode, b32 virtual_whitespace){ +buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 line_shift, u32 *character_starts, i32 mode, b32 virtual_whitespace){ assert(mode == 0); - i32 new_line_count = buffer->line_count; + u32 new_line_count = buffer->line_count; assert(0 <= start_line); assert(start_line <= end_line); @@ -1035,23 +1035,24 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G ++end_line; // Shift - i32 line_count = new_line_count; - i32 new_end_line = end_line; + u32 line_count = new_line_count; + u32 new_end_line = end_line; if (line_shift != 0){ line_count -= line_shift; new_end_line += line_shift; + memmove(character_starts + end_line + line_shift, character_starts + end_line, sizeof(i32)*(line_count - end_line + 1)); } // Iteration data Gap_Buffer_Stream stream = {0}; - i32 size = buffer_size(buffer); - i32 char_i = buffer->line_starts[start_line]; - i32 line_i = start_line; + u32 size = buffer_size(buffer); + u32 char_i = buffer->line_starts[start_line]; + u32 line_i = start_line; // Character measurement - i32 last_char_start = character_starts[line_i]; - i32 current_char_start = last_char_start; + u32 last_char_start = character_starts[line_i]; + u32 current_char_start = last_char_start; b32 skipping_whitespace = false; if (virtual_whitespace){ @@ -1062,7 +1063,7 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G Translation_State tran = {0}; Translation_Emits emits = {0}; - stream.use_termination_character = true; + stream.use_termination_character = 1; stream.terminator = '\n'; if (buffer_stringify_loop(&stream, buffer, char_i, size)){ b32 still_looping = 0; @@ -1125,8 +1126,8 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G } internal void -buffer_remeasure_wrap_y(Gap_Buffer *buffer, i32 start_line, i32 end_line, i32 line_shift, f32 *wraps, f32 font_height, f32 *adv, f32 max_width){ - i32 new_line_count = buffer->line_count; +buffer_remeasure_wrap_y(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 line_shift, f32 *wraps, f32 font_height, f32 *adv, f32 max_width){ + u32 new_line_count = buffer->line_count; assert(0 <= start_line); assert(start_line <= end_line); @@ -1135,8 +1136,8 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, i32 start_line, i32 end_line, i32 li ++end_line; // Shift - i32 line_count = new_line_count; - i32 new_end_line = end_line; + u32 line_count = new_line_count; + u32 new_end_line = end_line; if (line_shift != 0){ line_count -= line_shift; new_end_line += line_shift; @@ -1146,9 +1147,9 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, i32 start_line, i32 end_line, i32 li // Iteration data (yikes! Need better loop system) Gap_Buffer_Stream stream = {0}; - i32 size = buffer_size(buffer); - i32 char_i = buffer->line_starts[start_line]; - i32 line_i = start_line; + u32 size = buffer_size(buffer); + u32 char_i = buffer->line_starts[start_line]; + u32 line_i = start_line; // Line wrap measurement f32 last_wrap = wraps[line_i]; @@ -1205,10 +1206,10 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, i32 start_line, i32 end_line, i32 li } } -internal i32 -binary_search(i32 *array, i32 value, i32 l_bound, i32 u_bound){ +internal u32 +binary_search(u32 *array, u32 value, u32 l_bound, u32 u_bound){ value = clamp_bottom(0, value); - i32 start = l_bound, end = u_bound, i = 0; + u32 start = l_bound, end = u_bound, i = 0; for (;;){ i = (start + end) >> 1; if (array[i] < value){ @@ -1229,34 +1230,34 @@ binary_search(i32 *array, i32 value, i32 l_bound, i32 u_bound){ return(i); } -inline i32 -buffer_get_line_index_range(Gap_Buffer *buffer, i32 pos, i32 l_bound, i32 u_bound){ +inline u32 +buffer_get_line_index_range(Gap_Buffer *buffer, u32 pos, u32 l_bound, u32 u_bound){ assert(0 <= l_bound); assert(l_bound <= u_bound); assert(u_bound <= buffer->line_count); assert(buffer->line_starts != 0); - i32 i = binary_search(buffer->line_starts, pos, l_bound, u_bound); + u32 i = binary_search(buffer->line_starts, pos, l_bound, u_bound); return(i); } -inline i32 -buffer_get_line_index(Gap_Buffer *buffer, i32 pos){ - i32 result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); +inline u32 +buffer_get_line_index(Gap_Buffer *buffer, u32 pos){ + u32 result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); return(result); } -inline i32 -buffer_get_line_index_from_character_pos(i32 *character_starts, i32 pos, i32 l_bound, i32 u_bound){ - i32 i = binary_search(character_starts, pos, l_bound, u_bound); +inline u32 +buffer_get_line_index_from_character_pos(u32 *character_starts, u32 pos, u32 l_bound, u32 u_bound){ + u32 i = binary_search(character_starts, pos, l_bound, u_bound); return(i); } -inline i32 -buffer_get_line_index_from_wrapped_y(i32 *wrap_line_index, f32 y, i32 line_height, i32 l_bound, i32 u_bound){ - i32 wrap_index = floor32(y/line_height); - i32 i = binary_search(wrap_line_index, wrap_index, l_bound, u_bound); +inline u32 +buffer_get_line_index_from_wrapped_y(u32 *wrap_line_index, f32 y, i32 line_height, u32 l_bound, u32 u_bound){ + u32 wrap_index = floor32(y/line_height); + u32 i = binary_search(wrap_line_index, wrap_index, l_bound, u_bound); return(i); } @@ -1276,10 +1277,10 @@ buffer_partial_from_pos(Gap_Buffer *buffer, u32 pos){ } internal Partial_Cursor -buffer_partial_from_line_character(Gap_Buffer *buffer, i32 line, i32 character, b32 reversed){ +buffer_partial_from_line_character(Gap_Buffer *buffer, u32 line, u32 character, b32 reversed){ Partial_Cursor result = {0}; - i32 line_index = line - 1; + u32 line_index = line - 1; if (line_index >= buffer->line_count){ line_index = buffer->line_count - 1; } @@ -1287,16 +1288,16 @@ buffer_partial_from_line_character(Gap_Buffer *buffer, i32 line, i32 character, line_index = 0; } - i32 size = buffer_size(buffer); + u32 size = buffer_size(buffer); - i32 this_start = buffer->line_starts[line_index]; - i32 max_character = (size-this_start) + 1; + u32 this_start = buffer->line_starts[line_index]; + u32 max_character = (size-this_start) + 1; if (line_index+1 < buffer->line_count){ - i32 next_start = buffer->line_starts[line_index+1]; + u32 next_start = buffer->line_starts[line_index+1]; max_character = (next_start-this_start); } - i32 adjusted_pos = 0; + u32 adjusted_pos = 0; if (character > 0){ if (reversed){ if (character > max_character){ @@ -1331,8 +1332,8 @@ struct Buffer_Cursor_Seek_Params{ Buffer_Seek seek; System_Functions *system; Render_Font *font; - i32 *wrap_line_index; - i32 *character_starts; + u32 *wrap_line_index; + u32 *character_starts; b32 virtual_white; b32 return_hint; Full_Cursor *cursor_out; @@ -1345,9 +1346,9 @@ struct Buffer_Cursor_Seek_State{ Gap_Buffer_Stream stream; b32 still_looping; - i32 i; - i32 size; - i32 wrap_unit_end; + u32 i; + u32 size; + u32 wrap_unit_end; b32 first_of_the_line; b32 xy_seek; @@ -1371,7 +1372,7 @@ struct Buffer_Cursor_Seek_State{ #define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); } internal Buffer_Layout_Stop -buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params params, f32 line_shift, b32 do_wrap, i32 wrap_unit_end){ +buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params params, f32 line_shift, b32 do_wrap, u32 wrap_unit_end){ Buffer_Cursor_Seek_State S = *S_ptr; Buffer_Layout_Stop S_stop; @@ -1385,11 +1386,11 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa S.font_height = font_get_height(params.font); S.xy_seek = (params.seek.type == buffer_seek_wrapped_xy || params.seek.type == buffer_seek_unwrapped_xy); - S.size = (i32)buffer_size(params.buffer); + S.size = (u32)buffer_size(params.buffer); // Get cursor hint { - i32 line_index = 0; + u32 line_index = 0; switch (params.seek.type){ case buffer_seek_pos: { @@ -1400,25 +1401,25 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa case buffer_seek_character_pos: { - i32 line_count = params.buffer->line_count; - i32 max_character = params.character_starts[line_count] - 1; - params.seek.pos = clamp_i32(0, (i32)params.seek.pos, max_character); + u32 line_count = params.buffer->line_count; + u32 max_character = params.character_starts[line_count] - 1; + params.seek.pos = clamp_u32(0, (u32)params.seek.pos, max_character); - i32 *char_starts = params.character_starts; + u32 *char_starts = params.character_starts; - i32 pos = (i32)params.seek.pos; + u32 pos = (u32)params.seek.pos; line_index = buffer_get_line_index_from_character_pos(char_starts, pos, 0, line_count); }break; case buffer_seek_line_char: { - line_index = params.seek.line - 1; + line_index = (u32)params.seek.line - 1; line_index = clamp_bottom(0, line_index); }break; case buffer_seek_unwrapped_xy: { - line_index = (i32)(params.seek.y / S.font_height); + line_index = (u32)(params.seek.y / S.font_height); line_index = clamp_bottom(0, line_index); }break; @@ -1430,7 +1431,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa default: InvalidCodePath; } - i32 safe_line_index = line_index; + u32 safe_line_index = line_index; if (line_index >= params.buffer->line_count){ safe_line_index = params.buffer->line_count-1; } @@ -1820,8 +1821,8 @@ struct Buffer_Render_Params{ struct Buffer_Render_State{ Gap_Buffer_Stream stream; b32 still_looping; - i32 i; - i32 size; + u32 i; + u32 size; f32 shift_x; f32 shift_y; @@ -1831,9 +1832,9 @@ struct Buffer_Render_State{ Render_Item_Write write; f32 byte_advance; - i32 line; - i32 wrap_line; - i32 wrap_unit_end; + u32 line; + u32 wrap_line; + u32 wrap_unit_end; b32 skipping_whitespace; b32 first_of_the_line; diff --git a/4ed_buffer_model.h b/4ed_buffer_model.h index bf214b34..7f7df32a 100644 --- a/4ed_buffer_model.h +++ b/4ed_buffer_model.h @@ -15,8 +15,8 @@ struct Buffer_Model_Step{ u32 type; u32 value; - i32 i; - i32 byte_length; + u32 i; + u32 byte_length; }; struct Buffer_Model_Behavior{ diff --git a/4ed_file.cpp b/4ed_file.cpp index b168ec2d..c2778da9 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -21,7 +21,7 @@ enum Edit_Pos_Set_Type{ struct File_Edit_Positions{ GUI_Scroll_Vars scroll; Full_Cursor cursor; - i32 mark; + u32 mark; f32 preferred_x; i32 scroll_i; i32 last_set_type; @@ -54,7 +54,7 @@ edit_pos_set_scroll(File_Edit_Positions *edit_pos, GUI_Scroll_Vars scroll){ // struct Text_Effect{ - i32 start, end; + u32 start, end; u32 color; f32 seconds_down, seconds_max; }; @@ -109,20 +109,20 @@ global_const Editing_File_Settings null_editing_file_settings = {0}; struct Editing_File_State{ Gap_Buffer buffer; - i32 *wrap_line_index; - i32 wrap_max; + u32 *wrap_line_index; + u32 wrap_max; - i32 *character_starts; - i32 character_start_max; + u32 *character_starts; + u32 character_start_max; f32 *line_indents; - i32 line_indent_max; + u32 line_indent_max; - i32 wrap_line_count; + u32 wrap_line_count; - i32 *wrap_positions; - i32 wrap_position_count; - i32 wrap_position_max; + u32 *wrap_positions; + u32 wrap_position_count; + u32 wrap_position_max; Undo_Data undo; diff --git a/4ed_file_track.h b/4ed_file_track.h index a78d1fed..698f29fb 100644 --- a/4ed_file_track.h +++ b/4ed_file_track.h @@ -46,7 +46,7 @@ FILE_TRACK_LINK File_Track_Result expand_track_system_listeners(File_Track_System *system, Partition *scratch, void *mem, umem size); FILE_TRACK_LINK File_Track_Result -get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, umem max, umem *size); +get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, umem max); FILE_TRACK_LINK File_Track_Result shut_down_track_system(File_Track_System *system, Partition *scratch); diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 47003718..be69bfbd 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -402,11 +402,11 @@ view_compute_cursor(System_Functions *system, View *view, Buffer_Seek seek, b32 Buffer_Cursor_Seek_State state = {0}; Buffer_Layout_Stop stop = {0}; - i32 size = buffer_size(params.buffer); + u32 size = buffer_size(params.buffer); f32 line_shift = 0.f; - i32 wrap_unit_end = 0; - i32 wrap_array_index = 0; + u32 wrap_unit_end = 0; + u32 wrap_array_index = 0; b32 do_wrap = false; b32 first_wrap_determination = true; @@ -849,14 +849,14 @@ enum{ internal i32 file_grow_starts_as_needed(General_Memory *general, Gap_Buffer *buffer, i32 additional_lines){ b32 result = GROW_NOT_NEEDED; - i32 max = buffer->line_max; - i32 count = buffer->line_count; - i32 target_lines = count + additional_lines; + u32 max = buffer->line_max; + u32 count = buffer->line_count; + u32 target_lines = count + additional_lines; if (target_lines > max || max == 0){ max = l_round_up_u32(target_lines + max, KB(1)); - i32 *new_lines = (i32*)general_memory_reallocate(general, buffer->line_starts, sizeof(i32)*count, sizeof(i32)*max); + u32 *new_lines = (u32*)general_memory_reallocate(general, buffer->line_starts, sizeof(u32)*count, sizeof(u32)*max); if (new_lines){ result = GROW_SUCCESS; @@ -896,20 +896,20 @@ file_update_cursor_positions(System_Functions *system, Models *models, Editing_F internal void file_measure_starts(General_Memory *general, Gap_Buffer *buffer){ if (!buffer->line_starts){ - i32 max = buffer->line_max = KB(1); - buffer->line_starts = (i32*)general_memory_allocate(general, max*sizeof(i32)); + u32 max = buffer->line_max = KB(1); + buffer->line_starts = (u32*)general_memory_allocate(general, max*sizeof(u32)); TentativeAssert(buffer->line_starts != 0); // TODO(allen): when unable to allocate? } Buffer_Measure_Starts state = {0}; while (buffer_measure_starts(&state, buffer)){ - i32 count = state.count; - i32 max = buffer->line_max; + u32 count = state.count; + u32 max = buffer->line_max; max = ((max + 1) << 1); { - i32 *new_lines = (i32*)general_memory_reallocate(general, buffer->line_starts, sizeof(i32)*count, sizeof(i32)*max); + u32 *new_lines = (u32*)general_memory_reallocate(general, buffer->line_starts, sizeof(u32)*count, sizeof(u32)*max); // TODO(allen): when unable to grow? TentativeAssert(new_lines); @@ -921,16 +921,16 @@ file_measure_starts(General_Memory *general, Gap_Buffer *buffer){ // NOTE(allen): These calls assumes that the buffer's line starts are already correct, and that the buffer's line_count is correct. internal void -file_allocate_metadata_as_needed(General_Memory *general, Gap_Buffer *buffer, void **mem, i32 *mem_max_count, i32 count, i32 item_size){ +file_allocate_metadata_as_needed(General_Memory *general, Gap_Buffer *buffer, void **mem, u32 *mem_max_count, u32 count, u32 item_size){ if (*mem == 0){ - i32 max = ((count+1)*2); + u32 max = ((count+1)*2); max = (max+(0x3FF))&(~(0x3FF)); *mem = general_memory_allocate(general, max*item_size); *mem_max_count = max; } else if (*mem_max_count < count){ - i32 old_max = *mem_max_count; - i32 max = ((count+1)*2); + u32 old_max = *mem_max_count; + u32 max = ((count+1)*2); max = (max+(0x3FF))&(~(0x3FF)); void *new_mem = general_memory_reallocate(general, *mem, item_size*old_max, item_size*max); @@ -989,16 +989,16 @@ struct Code_Wrap_State{ b32 in_pp_body; Code_Wrap_X plane_wrap_x; - i32 *line_starts; - i32 line_index; - i32 next_line_start; + u32 *line_starts; + u32 line_index; + u32 next_line_start; f32 x; b32 consume_newline; Gap_Buffer_Stream stream; - i32 size; - i32 i; + u32 size; + u32 i; Render_Font *font; f32 tab_indent_amount; @@ -1052,8 +1052,8 @@ wrap_state_set_top(Code_Wrap_State *state, f32 line_shift){ } struct Code_Wrap_Step{ - i32 position_start; - i32 position_end; + u32 position_start; + u32 position_end; f32 start_x; f32 final_x; @@ -1062,9 +1062,9 @@ struct Code_Wrap_Step{ }; internal Code_Wrap_Step -wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_State *state, i32 fixed_end_point){ +wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_State *state, u32 fixed_end_point){ Code_Wrap_Step result = {0}; - i32 i = state->i; + u32 i = state->i; result.position_start = i; @@ -1102,9 +1102,9 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_ state->next_line_start = state->line_starts[state->line_index + 1]; } - i32 line_start = state->line_starts[state->line_index]; + u32 line_start = state->line_starts[state->line_index]; b32 still_looping = 0; - i32 end = state->token_ptr->start + state->token_ptr->size; + u32 end = state->token_ptr->start + state->token_ptr->size; if (fixed_end_point >= 0 && end > fixed_end_point){ end = fixed_end_point; @@ -1391,7 +1391,7 @@ struct Wrap_Current_Shift{ }; internal Wrap_Current_Shift -get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start){ +get_current_shift(Code_Wrap_State *wrap_state, u32 next_line_start){ Wrap_Current_Shift result = {0}; result.shift = wrap_state->wrap_x.paren_nesting[wrap_state->wrap_x.paren_safe_top]; @@ -1531,7 +1531,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, Gap_Buffer_Stream stream = {0}; u32 word_stage = 0; - i32 i = stop.pos; + u32 i = stop.pos; f32 x = stop.x; f32 self_x = 0; if (buffer_stringify_loop(&stream, params.buffer, i, size)){ @@ -1589,7 +1589,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, if (use_tokens){ Code_Wrap_State original_wrap_state = wrap_state; - i32 next_line_start = buffer_size(params.buffer); + u32 next_line_start = buffer_size(params.buffer); if (stop.line_index+1 < params.buffer->line_count){ next_line_start = params.buffer->line_starts[stop.line_index+1]; } @@ -1626,11 +1626,11 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, if (wrap_state.token_ptr->type == CPP_TOKEN_COMMENT || wrap_state.token_ptr->type == CPP_TOKEN_STRING_CONSTANT){ - i32 i = wrap_state.token_ptr->start; - i32 end_i = i + wrap_state.token_ptr->size; + u32 i = wrap_state.token_ptr->start; + u32 end_i = i + wrap_state.token_ptr->size; - i = clamp_bottom(wrap_state.i, i); - end_i = clamp_top(end_i, wrap_state.next_line_start); + i = clamp_bottom((u32)wrap_state.i, i); + end_i = clamp_top(end_i, (u32)wrap_state.next_line_start); f32 x = wrap_state.x; @@ -1734,7 +1734,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, next_token_is_on_line = true; } - i32 next_wrap_position = step.position_end; + u32 next_wrap_position = (u32)step.position_end; f32 wrap_x = step.final_x; if (wrap_state.token_ptr->start > step.position_start && next_wrap_position < wrap_state.token_ptr->start && next_token_is_on_line){ next_wrap_position = wrap_state.token_ptr->start; @@ -1826,7 +1826,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, } } - i32 wrap_position = potential_marks[best_i].wrap_position; + u32 wrap_position = potential_marks[best_i].wrap_position; f32 line_shift = potential_marks[best_i].line_shift; b32 adjust_top_to_this = potential_marks[best_i].adjust_top_to_this; wrap_indent_marks[real_count].wrap_position = wrap_position; @@ -1924,6 +1924,7 @@ file_set_min_base_width(System_Functions *system, Models *models, Editing_File * internal void file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String val, b8 read_only = 0){ General_Memory *general = &models->mem.general; + Partition *part = &models->mem.part; Open_File_Hook_Function *hook_open_file = models->hook_open_file; Application_Links *app_links = &models->app_links; @@ -1939,7 +1940,9 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * buffer_init_provide_page(&init, data, page_size); } - b32 init_success = buffer_end_init(&init); + u32 scratch_size = (u32)partition_remaining(part); + Assert(scratch_size > 0); + b32 init_success = buffer_end_init(&init, part->base + part->pos, scratch_size); AllowLocal(init_success); Assert(init_success); if (buffer_size(&file->state.buffer) < (u32)val.size){ @@ -2278,7 +2281,7 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ } internal b32 -file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, i32 shift_amount){ +file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *file, u32 start_i, u32 end_i, i32 shift_amount){ General_Memory *general = &mem->general; Partition *part = &mem->part; @@ -3429,7 +3432,7 @@ view_replace_range(System_Functions *system, Models *models, View *view, } inline void -view_post_paste_effect(View *view, f32 seconds, i32 start, i32 size, i32 color){ +view_post_paste_effect(View *view, f32 seconds, u32 start, u32 size, u32 color){ Editing_File *file = view->file_data.file; file->state.paste_effect.start = start; @@ -5967,7 +5970,7 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act f32 line_shift = 0.f; b32 do_wrap = false; - i32 wrap_unit_end = 0; + u32 wrap_unit_end = 0; b32 first_wrap_determination = true; u32 wrap_array_index = 0; @@ -6007,7 +6010,7 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act }while(stop.status != BLStatus_Finished); } - i32 cursor_begin = 0, cursor_end = 0; + u32 cursor_begin = 0, cursor_end = 0; u32 cursor_color = 0, at_cursor_color = 0; if (view->file_data.show_temp_highlight){ cursor_begin = (u32)view->file_data.temp_highlight.pos; @@ -6035,12 +6038,12 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act u32 mark_color = style->main.mark_color; Buffer_Render_Item *item = items; Buffer_Render_Item *item_end = item + count; - i32 prev_ind = max_i32; + u32 prev_ind = max_u32; u32 highlight_color = 0; u32 highlight_this_color = 0; for (; item < item_end; ++item){ - i32 ind = item->index; + u32 ind = item->index; highlight_this_color = 0; if (tokens_use && ind != prev_ind){ Cpp_Token current_token = token_array.tokens[token_i-1]; @@ -6100,7 +6103,9 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act u32 fade_color = 0xFFFF00FF; f32 fade_amount = 0.f; - if (file->state.paste_effect.seconds_down > 0.f && file->state.paste_effect.start <= ind && ind < file->state.paste_effect.end){ + if (file->state.paste_effect.seconds_down > 0.f && + file->state.paste_effect.start <= ind && + ind < file->state.paste_effect.end){ fade_color = file->state.paste_effect.color; fade_amount = file->state.paste_effect.seconds_down; fade_amount /= file->state.paste_effect.seconds_max; diff --git a/4ed_font_data.h b/4ed_font_data.h deleted file mode 100644 index 07231146..00000000 --- a/4ed_font_data.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 03.03.2017 - * - * Font data type definitions. - * - */ - -// TOP - -#if !defined(FCODER_FONT_DATA_H) -#define FCODER_FONT_DATA_H - -#define ITEM_PER_FONT_PAGE 256 - -struct Glyph_Bounds{ - f32 x0, x1; - f32 y0, y1; - f32 xoff, yoff; - f32 xoff2, yoff2; -}; -global_const Glyph_Bounds null_glyph_bounds = {0}; - -struct Glyph_Page{ - u32 page_number; - f32 advance[ITEM_PER_FONT_PAGE]; - Glyph_Bounds glyphs[ITEM_PER_FONT_PAGE]; - u32 tex; - i32 tex_width, tex_height; -}; - -#define FONT_PAGE_EMPTY ((Glyph_Page*)0) -#define FONT_PAGE_DELETED ((Glyph_Page*)(1)) -#define FONT_PAGE_MAX 0x1100 - -struct Render_Font{ - Glyph_Page **pages; - u32 page_count, page_max; - f32 byte_advance; - f32 byte_sub_advances[3]; - i32 height, ascent, descent, line_skip, advance; - - u32 filename_len; - u32 name_len; - char filename[256]; - char name[256]; -}; - -struct Glyph_Data{ - Glyph_Bounds bounds; - u32 tex; - i32 tex_width, tex_height; -}; - -#endif - -// BOTTOM - diff --git a/4ed_font_interface.h b/4ed_font_interface.h deleted file mode 100644 index d1f1eeb6..00000000 --- a/4ed_font_interface.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 11.03.2017 - * - * Font system interface. - * - */ - -// TOP - -#if !defined(FCODER_FONT_INTERFACE_H) -#define FCODER_FONT_INTERFACE_H - -typedef u32 Font_ID; - -struct Render_Font; -struct Glyph_Page; - -#define Sys_Font_Get_Count_Sig(name_) u32 (name_)(void) -typedef Sys_Font_Get_Count_Sig(Font_Get_Count_Function); - -#define Sys_Font_Get_IDs_By_Index_Sig(name_) b32 (name_)(u32 first_index, u32 index_count, u32 *id_out) -typedef Sys_Font_Get_IDs_By_Index_Sig(Font_Get_IDs_By_Index_Function); - -#define Sys_Font_Get_Name_By_Index_Sig(name_) u32 (name_)(u32 font_index, char *str_out, u32 str_out_cap) -typedef Sys_Font_Get_Name_By_Index_Sig(Font_Get_Name_By_Index_Function); - -#define Sys_Font_Get_Name_By_ID_Sig(name_) u32 (name_)(u32 font_id, char *str_out, u32 str_out_cap) -typedef Sys_Font_Get_Name_By_ID_Sig(Font_Get_Name_By_ID_Function); - -#define Sys_Font_Get_Render_Data_By_ID_Sig(name_) Render_Font* (name_)(u32 font_id) -typedef Sys_Font_Get_Render_Data_By_ID_Sig(Font_Get_Render_Data_By_ID_Function); - -#define Sys_Font_Load_Page_Sig(name_) void (name_)(Render_Font *font, Glyph_Page *page, u32 page_number) -typedef Sys_Font_Load_Page_Sig(Font_Load_Page_Function); - -#define Sys_Font_Allocate_Sig(name_) void* (name_)(i32 size) -typedef Sys_Font_Allocate_Sig(Font_Allocate_Function); - -#define Sys_Font_Free_Sig(name_) void (name_)(void *ptr) -typedef Sys_Font_Free_Sig(Font_Free_Function); - -struct Font_Functions{ - Font_Get_Count_Function *get_count; - Font_Get_IDs_By_Index_Function *get_ids_by_index; - Font_Get_Name_By_Index_Function *get_name_by_index; - Font_Get_Name_By_ID_Function *get_name_by_id; - Font_Get_Render_Data_By_ID_Function *get_render_data_by_id; - Font_Load_Page_Function *load_page; - - Font_Allocate_Function *allocate; - Font_Free_Function *free; -}; - -internal f32 font_get_byte_advance(Render_Font *font); -internal f32*font_get_byte_sub_advances(Render_Font *font); -internal i32 font_get_height(Render_Font *font); -internal i32 font_get_ascent(Render_Font *font); -internal i32 font_get_descent(Render_Font *font); -internal i32 font_get_line_skip(Render_Font *font); -internal i32 font_get_advance(Render_Font *font); - -internal b32 font_can_render(struct System_Functions *system, Render_Font *font, u32 codepoint); -internal f32 font_get_glyph_advance(struct System_Functions *system, Render_Font *font, u32 codepoint); - -struct Glyph_Data; -internal Glyph_Data font_get_glyph(System_Functions *system, Render_Font *font, u32 codepoint); - -internal Glyph_Page *font_get_or_make_page(struct System_Functions *system, Render_Font *font, u32 page_number); - -#endif - -// BOTTOM - - diff --git a/4ed_font_interface_to_os.h b/4ed_font_interface_to_os.h deleted file mode 100644 index c9114711..00000000 --- a/4ed_font_interface_to_os.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 13.03.2017 - * - * Font system interface to the OS layer. - * - */ - -// TOP - -#if !defined(FCODER_FONT_INTERFACE_TO_OS_H) -#define FCODER_FONT_INTERFACE_TO_OS_H - -#define Sys_Font_Init_Sig(name_) void (name_)(Font_Functions *font, void *memory, umem memory_size, u32 font_size, b32 use_hinting) -internal Sys_Font_Init_Sig(system_font_init); - -#endif - -// BOTTOM - - - diff --git a/4ed_font_internal.cpp b/4ed_font_internal.cpp deleted file mode 100644 index a8e66e65..00000000 --- a/4ed_font_internal.cpp +++ /dev/null @@ -1,493 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 10.03.2017 - * - * Where I save crappy old font stuff. - * - */ - -// TOP - -#include "font/4coder_font_data.h" - -struct Font_Table_Entry{ - u32 hash; - String name; - Font_ID font_id; -}; - -struct Font_Info{ - Render_Font *font; - String filename; - String name; - i32 pt_size; -}; - -struct Font_Slot{ - Font_Slot *next, *prev; - Font_ID font_id; - u8 padding[6]; -}; -global_const Font_Slot null_font_slot = {0}; - -#define Font_Load_Sig(name)\ -i32 name(Render_Font *font_out, char *filename, char *fontname, i32 pt_size, i32 tab_width, b32 store_texture) -typedef Font_Load_Sig(Font_Load); - -#define Font_Load_Page_Sig(name)\ -i32 name(Render_Font *font, Glyph_Page *page, char *filename, i32 pt_size, i32 tab_width) -typedef Font_Load_Page_Sig(Font_Load_Page); - -#define Release_Font_Sig(name) void name(Render_Font *font) -typedef Release_Font_Sig(Release_Font); - -struct Font_Set{ - Font_Info *info; - Font_Table_Entry *entries; - u32 count, max; - - void *font_block; - Font_Slot free_slots; - Font_Slot used_slots; - - Font_Load *font_load; - Font_Load_Page *font_load_page; - Release_Font *release_font; - - b8 *font_used_flags; - Font_ID used_this_frame; - Font_ID live_max; -}; - -inline Font_Info* -get_font_info(Font_Set *set, Font_ID font_id){ - Font_Info *result = set->info + font_id - 1; - return(result); -} - -internal void -font_set_begin_render(Font_Set *font_set){ - font_set->used_this_frame = 0; - memset(font_set->font_used_flags, 0, font_set->max); -} - -inline u32 -font_hash(String name){ - u32 x = 5381; - char *p = name.str; - for (i32 i = 0; i < name.size; ++i, ++p){ - x = ((x << 5) + x) ^ (*p); - } - return(x); -} - -inline void -font__insert(Font_Slot *pos, Font_Slot *slot){ - Font_Slot *nex; - nex = pos->next; - - slot->next = nex; - slot->prev = pos; - nex->prev = slot; - pos->next = slot; -} - -inline void -font__remove(Font_Slot *slot){ - Font_Slot *n, *p; - n = slot->next; - p = slot->prev; - - p->next = n; - n->prev = p; -} - -internal void -font_set_init(Font_Set *set, Partition *partition, i32 max, Font_ID live_max){ - partition_align(partition, 8); - set->info = push_array(partition, Font_Info, max); - partition_align(partition, 8); - set->entries = push_array(partition, Font_Table_Entry, max); - set->count = 0; - set->max = max; - - partition_align(partition, 8); - set->font_block = push_block(partition, live_max*(sizeof(Render_Font) + sizeof(Font_Slot))); - - set->free_slots = null_font_slot; - set->used_slots = null_font_slot; - - dll_init_sentinel(&set->free_slots); - dll_init_sentinel(&set->used_slots); - - char *ptr = (char*)set->font_block; - for (i32 i = 0; i < live_max; ++i){ - dll_insert(&set->free_slots, (Font_Slot*)ptr); - ptr += sizeof(Font_Slot) + sizeof(Render_Font); - } - - set->font_used_flags = push_array(partition, b8, max); - set->live_max = live_max; -} - -internal b32 -font_set_can_add(Font_Set *set){ - b32 result = 0; - if (set->count*8 < set->max*7) result = 1; - return(result); -} - -internal void -font_set_add_hash(Font_Set *set, String name, Font_ID font_id){ - Font_Table_Entry entry; - entry.hash = font_hash(name); - entry.name = name; - entry.font_id = font_id; - - u32 i = entry.hash % set->max; - u32 j = i - 1; - if (i <= 1) j += set->max; - - for (; i != j; ++i){ - if (i == set->max) i = 0; - if (set->entries[i].font_id == 0){ - set->entries[i] = entry; - break; - } - } - - Assert(i != j); -} - -inline b32 -font_set_can_load(Font_Set *set){ - b32 result = (set->free_slots.next != &set->free_slots); - return(result); -} - -internal void -font_set_load(Font_Set *set, Font_ID font_id){ - Font_Info *info = get_font_info(set, font_id); - Font_Slot *slot = set->free_slots.next; - Assert(slot != &set->free_slots); - font__remove(slot); - font__insert(&set->used_slots, slot); - - Render_Font *font = (Render_Font*)(slot + 1); - set->font_load(font, info->filename.str, info->name.str, info->pt_size, 4, true); - info->font = font; - slot->font_id = font_id; -} - -internal void -font_set_evict_lru(Font_Set *set){ - Font_Slot *slot = set->used_slots.prev; - Assert(slot != &set->used_slots); - - Font_ID font_id = slot->font_id; - Font_Info *info = get_font_info(set, font_id); - Assert(((Font_Slot*)info->font) - 1 == slot); - - set->release_font(info->font); - - info->font = 0; - slot->font_id = 0; - font__remove(slot); - font__insert(&set->free_slots, slot); -} - -internal void -font_set_use(Font_Set *set, Font_ID font_id){ - b8 already_used = set->font_used_flags[font_id-1]; - - if (!already_used){ - if (set->used_this_frame < set->live_max){ - ++set->used_this_frame; - set->font_used_flags[font_id-1] = 1; - already_used = 1; - } - } - - if (already_used){ - // TODO(allen): optimize if you don't mind!!!! - Font_Info *info = get_font_info(set, font_id); - Font_Slot *slot; - if (info->font == 0){ - if (!font_set_can_load(set)){ - font_set_evict_lru(set); - } - font_set_load(set, font_id); - } - slot = ((Font_Slot*)info->font) - 1; - - font__remove(slot); - font__insert(&set->used_slots, slot); - } -} - -internal b32 -font_set_add(Font_Set *set, String filename, String name, i32 pt_size){ - b32 result = false; - if (font_set_can_add(set)){ - Render_Font dummy_font = {0}; - Font_ID font_id = (i16)(++set->count); - Font_Info *info = get_font_info(set, font_id); - info->filename = filename; - info->name = name; - info->pt_size = pt_size; - set->font_load(&dummy_font, info->filename.str, info->name.str, info->pt_size, 4, false); - - font_set_add_hash(set, name, font_id); - - if (font_set_can_load(set)){ - font_set_load(set, font_id); - } - - result = true; - } - return(result); -} - -internal b32 -font_set_find_pos(Font_Set *set, String name, u32 *position){ - u32 hash = font_hash(name); - u32 i = hash % set->max; - u32 j = i - 1; - if (j <= 1){ - j += set->max; - } - - b32 result = 0; - for (; i != j; ++i){ - if (i == set->max){ - i = 0; - } - - Font_Table_Entry *entry = set->entries + i; - if (entry->hash == hash){ - if (match_ss(name, entry->name)){ - result = 1; - *position = i; - break; - } - } - } - - return(result); -} - -internal b32 -font_set_get_name(Font_Set *set, Font_ID font_id, String *name){ - Font_Info *info = get_font_info(set, font_id); - b32 result = copy_checked_ss(name, info->name); - return(result); -} - -internal b32 -font_set_extract(Font_Set *set, String name, Font_ID *font_id){ - u32 position; - b32 result = font_set_find_pos(set, name, &position); - if (result){ - *font_id = set->entries[position].font_id; - } - return(result); -} - -////////////////////////////////// - -internal b32 -get_codepoint_can_render(Render_Font *font, u32 codepoint){ - b32 exists = false; - if (codepoint < 0x10FFFF){ - exists = true; - } - return(exists); -} - -struct Codepoint_Indexes{ - b32 exists; - u32 page_number; - u32 glyph_index; -}; - -internal Codepoint_Indexes -get_codepoint_page_number(Render_Font *font, u32 codepoint){ - Codepoint_Indexes result = {0}; - u32 page_number = (codepoint >> 8); - if (page_number <= 0x10FF){ - result.exists = true; - result.page_number = page_number; - result.glyph_index = (codepoint & 0x000000FF); - } - return(result); -} - -#define MAX_PAGE_COUNT (u32)(0x1100) -#define GLYPH_PAGE_EMPTY ((Glyph_Page*)(0)) -#define GLYPH_PAGE_DELETED ((Glyph_Page*)(max_u64)) -#define IS_REAL_FONT_PAGE(p) (((p) != GLYPH_PAGE_EMPTY) && ((p) != GLYPH_PAGE_DELETED)) - -internal Glyph_Page** -font_lookup_page(Render_Font *font, u32 page_number, b32 find_empty_slot){ - Glyph_Page **result = 0; - if (font->page_max > 0){ - u32 first_index = page_number % font->page_max; - - u32 range_count = 0; - u32 ranges[4]; - if (first_index == 0){ - ranges[0] = 0; - ranges[1] = font->page_max; - range_count = 2; - } - else{ - ranges[0] = first_index; - ranges[1] = font->page_max; - ranges[2] = 0; - ranges[3] = first_index; - range_count = 4; - } - - if (find_empty_slot){ - for(u32 j = 0; j < range_count; j += 2){ - u32 start = ranges[j]; - u32 stop = ranges[j+1]; - for (u32 i = start; i < stop; ++i){ - Glyph_Page *ptr = font->pages[i]; - if (ptr == GLYPH_PAGE_EMPTY || ptr == GLYPH_PAGE_DELETED){ - result = &font->pages[i]; - goto break2; - } - if (ptr->page_number == page_number){ - goto break2; - } - } - } - } - else{ - for(u32 j = 0; j < range_count; j += 2){ - u32 start = ranges[j]; - u32 stop = ranges[j+1]; - for (u32 i = start; i < stop; ++i){ - Glyph_Page *ptr = font->pages[i]; - if (ptr == GLYPH_PAGE_EMPTY){ - goto break2; - } - if (ptr != GLYPH_PAGE_DELETED){ - if (ptr->page_number == page_number){ - result = &font->pages[i]; - goto break2; - } - } - } - } - } - break2:; - } - return(result); -} - -internal Glyph_Page* -font_get_or_make_page(Render_Font *font, u32 page_number){ - Glyph_Page *page = 0; - if (page_number <= 0x10FF){ - Glyph_Page **page_ptr = font_lookup_page(font, page_number, false); - page = 0; - if (page_ptr != 0){ - page = *page_ptr; - } - - if (page == 0){ - u32 new_count = 1; - if (font->page_max < MAX_PAGE_COUNT && (font->page_count+new_count)*3 < font->page_max*2){ - u32 new_page_max = (font->page_count+new_count)*3; - new_page_max = clamp_top(new_page_max, MAX_PAGE_COUNT); - Glyph_Page **new_pages = (Glyph_Page**)ALLOCATE(new_page_max * sizeof(Glyph_Page*)); - - u32 old_page_max = font->page_max; - Glyph_Page **pages = font->pages; - for (u32 i = 0; i < old_page_max; ++i){ - Glyph_Page *current_page = pages[i]; - if (current_page != GLYPH_PAGE_EMPTY && current_page != GLYPH_PAGE_DELETED){ - Glyph_Page **dest = font_lookup_page(font, current_page->page_number, true); - Assert(dest != 0); - *dest = current_page; - } - } - - FREE(font->pages); - font->pages = new_pages; - font->page_max = new_page_max; - } - - Glyph_Page *new_page = (Glyph_Page*)ALLOCATE(sizeof(Glyph_Page)); - Glyph_Page **dest = font_lookup_page(font, page_number, true); - *dest = new_page; - ++font->page_count; - - //set->font_load_page(font, new_page, ); - } - } - return(page); -} - -internal void -get_codepoint_memory(Render_Font *font, u32 codepoint, Glyph_Bounds **bounds_mem_out, f32 **advance_mem_out){ - Glyph_Bounds *bounds = 0; - f32 *advance = 0; - - if (get_codepoint_can_render(font, codepoint)){ - Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); - Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); - bounds = &page->glyphs[indexes.glyph_index]; - advance = &page->advance[indexes.glyph_index]; - } - - *bounds_mem_out = bounds; - *advance_mem_out = advance; -} - -internal b32 -get_codepoint_glyph_data(Render_Font *font, u32 codepoint, Glyph_Data *data_out){ - b32 success = false; - if (get_codepoint_can_render(font, codepoint)){ - Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); - Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); - data_out->bounds = page->glyphs[indexes.glyph_index]; - data_out->tex = page->tex; - data_out->tex_width = page->tex_width; - data_out->tex_height = page->tex_height; - success = true; - } - return(success); -} - -internal f32 -get_codepoint_advance(Render_Font *font, u32 codepoint){ - f32 advance = (f32)font->advance; - if (get_codepoint_can_render(font, codepoint)){ - Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); - Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); - advance = page->advance[indexes.glyph_index]; - } - return(advance); -} - -internal b32 -set_codepoint_advance(Render_Font *font, u32 codepoint, f32 value){ - b32 success = false; - if (get_codepoint_can_render(font, codepoint)){ - Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); - Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); - page->advance[indexes.glyph_index] = value; - success = true; - } - return(success); -} - -// BOTTOM - - - - diff --git a/4ed_font_static_functions.cpp b/4ed_font_static_functions.cpp deleted file mode 100644 index c65cd2f4..00000000 --- a/4ed_font_static_functions.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 11.03.2017 - * - * Implements some basic getters for fonts set up to make the font type opaque. - * - */ - -// TOP - -#include "4ed_font_data.h" - -internal f32 -font_get_byte_advance(Render_Font *font){ - return(font->byte_advance); -} - -internal f32* -font_get_byte_sub_advances(Render_Font *font){ - return(font->byte_sub_advances); -} - -internal i32 -font_get_height(Render_Font *font){ - return(font->height); -} - -internal i32 -font_get_ascent(Render_Font *font){ - return(font->ascent); -} - -internal i32 -font_get_descent(Render_Font *font){ - return(font->descent); -} - -internal i32 -font_get_line_skip(Render_Font *font){ - return(font->line_skip); -} - -internal i32 -font_get_advance(Render_Font *font){ - return(font->advance); -} - -internal b32 -font_can_render(System_Functions *system, Render_Font *font, u32 codepoint){ - b32 result = false; - u32 page_number = (codepoint >> 8); - u32 glyph_index = codepoint & 0xFF; - Glyph_Page *page = font_get_or_make_page(system, font, page_number); - if (page != 0 && page->advance[glyph_index] > 0.f){ - result = true; - } - return(result); -} - -internal f32 -font_get_glyph_advance(System_Functions *system, Render_Font *font, u32 codepoint){ - f32 result = 0.f; - u32 page_number = (codepoint >> 8); - u32 glyph_index = codepoint & 0xFF; - Glyph_Page *page = font_get_or_make_page(system, font, page_number); - if (page != 0 && page->advance[glyph_index] > 0.f){ - result = page->advance[glyph_index]; - } - return(result); -} - -internal Glyph_Data -font_get_glyph(System_Functions *system, Render_Font *font, u32 codepoint){ - Glyph_Data result = {0}; - u32 page_number = (codepoint >> 8); - u32 glyph_index = codepoint & 0xFF; - Glyph_Page *page = font_get_or_make_page(system, font, page_number); - if (page != 0 && page->advance[glyph_index] > 0.f){ - result.bounds = page->glyphs[glyph_index]; - result.tex = page->tex; - result.tex_width = page->tex_width; - result.tex_height = page->tex_height; - } - return(result); -} - -internal Glyph_Page** -font_page_lookup(Render_Font *font, u32 page_number, b32 get_empty_slot){ - Glyph_Page **result = 0; - - if (font->page_max > 0){ - u32 first_index = page_number % font->page_max; - - u32 range_count = 0; - u32 ranges[4]; - if (first_index == 0){ - ranges[0] = 0; - ranges[1] = font->page_max; - range_count = 2; - } - else{ - ranges[0] = first_index; - ranges[1] = font->page_max; - ranges[2] = 0; - ranges[3] = first_index; - range_count = 4; - } - - Glyph_Page **pages = font->pages; - if (get_empty_slot){ - for (u32 j = 0; j < range_count; j += 2){ - u32 stop = ranges[j+1]; - for (u32 i = ranges[j]; i < stop; ++i){ - if (pages[i] == FONT_PAGE_EMPTY || pages[i] == FONT_PAGE_DELETED){ - result = &pages[i]; - goto break2; - } - if (pages[i]->page_number == page_number){ - goto break2; - } - } - } - } - else{ - for (u32 j = 0; j < range_count; j += 2){ - u32 stop = ranges[j+1]; - for (u32 i = ranges[j]; i < stop; ++i){ - if (pages[i] == FONT_PAGE_EMPTY){ - goto break2; - } - if (pages[i] != FONT_PAGE_DELETED && pages[i]->page_number == page_number){ - result = &pages[i]; - goto break2; - } - } - } - } - - break2:; - } - - return(result); -} - -internal Glyph_Page* -font_get_or_make_page(System_Functions *system, Render_Font *font, u32 page_number){ - Glyph_Page *result = 0; - if (page_number <= 0x10FF){ - Glyph_Page **page_get_result = font_page_lookup(font, page_number, false); - - if (page_get_result == 0){ - b32 has_space = true; - u32 new_page_count = 1; - u32 new_max = (font->page_count+new_page_count)*3; - if (font->page_max < FONT_PAGE_MAX && new_max > font->page_max*2){ - Glyph_Page **pages = (Glyph_Page**)system->font.allocate(sizeof(Glyph_Page*)*new_max); - has_space = false; - if (pages != 0){ - memset(pages, 0, sizeof(*pages)*new_max); - u32 old_max = font->page_max; - for (u32 i = 0; i < old_max; ++i){ - Glyph_Page *this_page = pages[i]; - if (this_page != FONT_PAGE_EMPTY && this_page != FONT_PAGE_DELETED){ - u32 this_page_number = this_page->page_number; - Glyph_Page **dest = font_page_lookup(font, this_page_number, true); - Assert(dest != 0); - *dest = this_page; - } - } - system->font.free(font->pages); - font->pages = pages; - font->page_max = new_max; - has_space = true; - } - } - - if (has_space){ - Glyph_Page *new_page = (Glyph_Page*)system->font.allocate(sizeof(Glyph_Page)); - if (new_page != 0){ - Glyph_Page **dest = font_page_lookup(font, page_number, true); - Assert(dest != 0); - *dest = new_page; - font->page_count += new_page_count; - result = new_page; - system->font.load_page(font, new_page, page_number); - } - } - } - else{ - result = *page_get_result; - } - } - return(result); -} - -// BOTTOM - diff --git a/4ed_system.h b/4ed_system.h index e29ef63e..89025f84 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -12,7 +12,7 @@ #if !defined(FCODER_SYSTEM_INTERFACE_H) #define FCODER_SYSTEM_INTERFACE_H -#include "4ed_font_interface.h" +#include "font/4coder_font_interface.h" // types struct Plat_Handle{ @@ -57,7 +57,7 @@ typedef Sys_Add_Listener_Sig(System_Add_Listener); #define Sys_Remove_Listener_Sig(name) b32 name(char *filename) typedef Sys_Remove_Listener_Sig(System_Remove_Listener); -#define Sys_Get_File_Change_Sig(name) i32 name(char *buffer, umem max, b32 *mem_too_small, umem *required_size) +#define Sys_Get_File_Change_Sig(name) i32 name(char *buffer, i32 max, b32 *mem_too_small, i32 *required_size) typedef Sys_Get_File_Change_Sig(System_Get_File_Change); // time @@ -212,7 +212,7 @@ typedef Sys_Memory_Set_Protection_Sig(System_Memory_Set_Protection); #define Sys_Memory_Free_Sig(name) void name(void *ptr, umem size) typedef Sys_Memory_Free_Sig(System_Memory_Free); -#define Sys_File_Exists_Sig(name) b32 name(char *filename, u32 len) +#define Sys_File_Exists_Sig(name) b32 name(char *filename, i32 len) typedef Sys_File_Exists_Sig(System_File_Exists); #define Sys_Directory_CD_Sig(name) bool32 name(char *dir, i32 *len, i32 cap, char *rel_path, i32 rel_len) diff --git a/4ed_system_shared.cpp b/4ed_system_shared.cpp index 977aaa78..e3fd92c3 100644 --- a/4ed_system_shared.cpp +++ b/4ed_system_shared.cpp @@ -12,7 +12,7 @@ #if !defined(FCODER_SYSTEM_SHARED_CPP) #define FCODER_SYSTEM_SHARED_CPP -#include "4ed_font_data.h" +#include "font/4coder_font_data.h" // // Standard implementation of file system stuff based on the file track layer. @@ -21,14 +21,14 @@ internal void init_shared_vars(){ umem scratch_size = KB(128); - void *scratch_memory = system_memory_allocate(scratch_size); + void *scratch_memory = system_get_memory(scratch_size); shared_vars.scratch = make_part(scratch_memory, scratch_size); shared_vars.track_table_size = KB(16); - shared_vars.track_table = system_memory_allocate(shared_vars.track_table_size); + shared_vars.track_table = system_get_memory(shared_vars.track_table_size); shared_vars.track_node_size = KB(16); - void *track_nodes = system_memory_allocate(shared_vars.track_node_size); + void *track_nodes = system_get_memory(shared_vars.track_node_size); i32 track_result = init_track_system(&shared_vars.track, &shared_vars.scratch, shared_vars.track_table, shared_vars.track_table_size, track_nodes, shared_vars.track_node_size); @@ -45,10 +45,9 @@ handle_track_out_of_memory(i32 val){ case FileTrack_OutOfTableMemory: { u32 new_table_size = shared_vars.track_table_size*2; - u32 old_table_size = shared_vars.track_table_size; - void *new_table = system_memory_allocate(new_table_size); + void *new_table = system_get_memory(new_table_size); move_track_system(&shared_vars.track, &shared_vars.scratch, new_table, new_table_size); - system_memory_free(shared_vars.track_table, old_table_size); + system_free_memory(shared_vars.track_table); shared_vars.track_table_size = new_table_size; shared_vars.track_table = new_table; }break; @@ -56,7 +55,7 @@ handle_track_out_of_memory(i32 val){ case FileTrack_OutOfListenerMemory: { shared_vars.track_node_size *= 2; - void *node_expansion = system_memory_allocate(shared_vars.track_node_size); + void *node_expansion = system_get_memory(shared_vars.track_node_size); expand_track_system_listeners(&shared_vars.track, &shared_vars.scratch, node_expansion, shared_vars.track_node_size); }break; @@ -68,13 +67,13 @@ handle_track_out_of_memory(i32 val){ internal Sys_Add_Listener_Sig(system_add_listener){ - b32 result = false; + b32 result = 0; for (;;){ - File_Track_Result track_result = add_listener(&shared_vars.track, &shared_vars.scratch, (u8*)filename); + i32 track_result = add_listener(&shared_vars.track, &shared_vars.scratch, filename); if (handle_track_out_of_memory(track_result)){ if (track_result == FileTrack_Good){ - result = true; + result = 1; } break; } @@ -85,10 +84,10 @@ Sys_Add_Listener_Sig(system_add_listener){ internal Sys_Remove_Listener_Sig(system_remove_listener){ - b32 result = false; - File_Track_Result track_result = remove_listener(&shared_vars.track, &shared_vars.scratch, (u8*)filename); + i32 result = 0; + i32 track_result = remove_listener(&shared_vars.track, &shared_vars.scratch, filename); if (track_result == FileTrack_Good){ - result = true; + result = 1; } return(result); } @@ -97,8 +96,8 @@ internal Sys_Get_File_Change_Sig(system_get_file_change){ b32 result = false; - umem size = 0; - File_Track_Result get_result = get_change_event(&shared_vars.track, &shared_vars.scratch, (u8*)buffer, max, &size); + i32 size = 0; + i32 get_result = get_change_event(&shared_vars.track, &shared_vars.scratch, buffer, max, &size); *required_size = size; *mem_too_small = false; @@ -128,14 +127,14 @@ sysshared_load_file(char *filename){ result.got_file = 1; if (size > 0){ result.size = size; - result.data = (char*)system_memory_allocate(size+1); + result.data = (char*)system_get_memory(size+1); if (!result.data){ result = null_file_data; } else{ if (!system_load_file(handle, result.data, size)){ - system_memory_free(result.data, size+1); + system_free_memory(result.data); result = null_file_data; } } @@ -158,9 +157,11 @@ usable_ascii(char c){ internal void sysshared_filter_real_files(char **files, i32 *file_count){ - i32 end = *file_count; - i32 i = 0, j = 0; - for (; i < end; ++i){ + i32 i, j; + i32 end; + + end = *file_count; + for (i = 0, j = 0; i < end; ++i){ if (system_file_can_be_made(files[i])){ files[j] = files[i]; ++j; @@ -171,20 +172,20 @@ sysshared_filter_real_files(char **files, i32 *file_count){ internal Partition sysshared_scratch_partition(i32 size){ - void *data = system_memory_allocate(size); + void *data = system_get_memory(size); Partition part = make_part(data, size); return(part); } -// TODO(allen): attempt to grow in place by just acquiring next vpages?! internal void -sysshared_partition_grow(Partition *part, umem new_size){ +sysshared_partition_grow(Partition *part, i32 new_size){ + void *data = 0; if (new_size > part->max){ - void *data = system_memory_allocate(new_size); + // TODO(allen): attempt to grow in place by just acquiring next vpages?! + data = system_get_memory(new_size); memcpy(data, part->base, part->pos); - system_memory_free(part->base, part->max); + system_free_memory(part->base); part->base = (char*)data; - part->max = new_size; } } diff --git a/meta/meta_parser.cpp b/meta/meta_parser.cpp index 0c0f618d..347dc2e9 100644 --- a/meta/meta_parser.cpp +++ b/meta/meta_parser.cpp @@ -886,7 +886,7 @@ static Argument_Breakdown parameter_parse(Partition *part, char *data, Cpp_Token *args_start_token, Cpp_Token *args_end_token){ int32_t arg_index = 0; Cpp_Token *arg_token = args_start_token + 1; - int32_t param_string_start = arg_token->start; + uint32_t param_string_start = arg_token->start; int32_t arg_count = 1; arg_token = args_start_token; diff --git a/power/4coder_experiments.cpp b/power/4coder_experiments.cpp index 3af9d57c..8092a03a 100644 --- a/power/4coder_experiments.cpp +++ b/power/4coder_experiments.cpp @@ -23,7 +23,7 @@ TYPE: 'build-target' #include static float -get_line_y(Application_Links *app, View_Summary *view, int32_t line){ +get_line_y(Application_Links *app, View_Summary *view, size_t line){ Full_Cursor cursor = {0}; view_compute_cursor(app, view, seek_line_char(line, 1), &cursor); float y = cursor.wrapped_y; @@ -43,9 +43,9 @@ CUSTOM_COMMAND_SIG(kill_rect){ int32_t line_count = (int32_t)(rect.y1 - rect.y0 + 1); for (int32_t line_i = line_count; line_i >= 0; --line_i){ - int32_t line = rect.y0 + line_i; - int32_t start = 0; - int32_t end = 0; + size_t line = rect.y0 + line_i; + size_t start = 0; + size_t end = 0; bool32 success = true; Full_Cursor cursor = {0}; @@ -71,7 +71,7 @@ CUSTOM_COMMAND_SIG(kill_rect){ } static void -pad_buffer_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line, char padchar, int32_t target){ +pad_buffer_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line, char padchar, size_t target){ Partial_Cursor start = {0}; Partial_Cursor end = {0}; @@ -83,7 +83,7 @@ pad_buffer_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, if (buffer_compute_cursor(app, buffer, seek_end, &end)){ if (end.character-1 < target){ Temp_Memory temp = begin_temp_memory(part); - int32_t size = target - (end.character-1); + size_t size = target - (end.character-1); char *str = push_array(part, char, size); memset(str, ' ', size); buffer_replace_range(app, buffer, end.pos, end.pos, str, size); @@ -137,10 +137,10 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ Buffer_Rect rect = get_rect(&view); - int32_t start_line = view.cursor.line; - int32_t pos = view.cursor.character-1; + size_t start_line = view.cursor.line; + size_t pos = view.cursor.character-1; - for (int32_t i = rect.line0; i <= rect.line1; ++i){ + for (size_t i = rect.line0; i <= rect.line1; ++i){ pad_buffer_line(app, &global_part, &buffer, i, ' ', pos); } @@ -158,7 +158,7 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ Buffer_Edit *edits = edit; for (int32_t i = 0; i <= line_count; ++i){ - int32_t line = i + rect.line0; + size_t line = i + rect.line0; Partial_Cursor cursor = {0}; Buffer_Seek seek = seek_line_char(line, pos+1); @@ -188,7 +188,7 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ Buffer_Edit *edits = edit; for (int32_t i = 0; i <= line_count; ++i){ - int32_t line = i + rect.line0; + size_t line = i + rect.line0; Partial_Cursor cursor = {0}; Buffer_Seek seek = seek_line_char(line, pos+1); @@ -227,11 +227,11 @@ enum{ }; static bool32 -find_scope_top(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ +find_scope_top(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - int32_t position = 0; + size_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index; @@ -287,11 +287,11 @@ find_scope_top(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos } static bool32 -find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ +find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - int32_t position = 0; + size_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index+1; @@ -348,11 +348,11 @@ find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, int32_t start_ } static bool32 -find_next_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ +find_next_scope(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - int32_t position = 0; + size_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index+1; @@ -428,11 +428,11 @@ find_next_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_po } static bool32 -find_prev_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ +find_prev_scope(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - int32_t position = 0; + size_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index-1; @@ -507,7 +507,7 @@ find_prev_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_po } static void -view_set_to_region(Application_Links *app, View_Summary *view, int32_t major_pos, int32_t minor_pos, float normalized_threshold){ +view_set_to_region(Application_Links *app, View_Summary *view, size_t major_pos, size_t minor_pos, float normalized_threshold){ Range range = make_range(major_pos, minor_pos); bool32 bottom_major = false; if (major_pos == range.max){ @@ -562,8 +562,8 @@ CUSTOM_COMMAND_SIG(highlight_surrounding_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t start_pos = view.cursor.pos; - int32_t top = 0, bottom = 0; + size_t start_pos = view.cursor.pos; + size_t top = 0, bottom = 0; if (find_scope_top(app, &buffer, start_pos, FindScope_Parent, &top)){ view_set_cursor(app, &view, seek_pos(top), true); if (find_scope_bottom(app, &buffer, start_pos, FindScope_Parent | FindScope_EndOfToken, &bottom)){ @@ -582,8 +582,8 @@ CUSTOM_COMMAND_SIG(highlight_first_child_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t start_pos = view.cursor.pos; - int32_t top = 0, bottom = 0; + size_t start_pos = view.cursor.pos; + size_t top = 0, bottom = 0; if (find_next_scope(app, &buffer, start_pos, 0, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -598,8 +598,8 @@ CUSTOM_COMMAND_SIG(highlight_next_sibling_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t start_pos = view.cursor.pos; - int32_t top = 0, bottom = 0; + size_t start_pos = view.cursor.pos; + size_t top = 0, bottom = 0; if (find_next_scope(app, &buffer, start_pos, FindScope_NextSibling, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -614,8 +614,8 @@ CUSTOM_COMMAND_SIG(highlight_prev_sibling_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t start_pos = view.cursor.pos; - int32_t top = 0, bottom = 0; + size_t start_pos = view.cursor.pos; + size_t top = 0, bottom = 0; if (find_prev_scope(app, &buffer, start_pos, FindScope_NextSibling, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -630,8 +630,8 @@ CUSTOM_COMMAND_SIG(highlight_next_scope_absolute){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t start_pos = view.cursor.pos; - int32_t top = 0, bottom = 0; + size_t start_pos = view.cursor.pos; + size_t top = 0, bottom = 0; if (find_next_scope(app, &buffer, start_pos, 0, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -646,8 +646,8 @@ CUSTOM_COMMAND_SIG(highlight_prev_scope_absolute){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t start_pos = view.cursor.pos; - int32_t top = 0, bottom = 0; + size_t start_pos = view.cursor.pos; + size_t top = 0, bottom = 0; if (find_prev_scope(app, &buffer, start_pos, 0, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -697,11 +697,11 @@ CUSTOM_COMMAND_SIG(place_in_scope){ --max_adjustment; } - int32_t min_pos = range.min + min_adjustment; - int32_t max_pos = range.max + max_adjustment; + size_t min_pos = range.min + min_adjustment; + size_t max_pos = range.max + max_adjustment; - int32_t cursor_pos = min_pos; - int32_t mark_pos = max_pos; + size_t cursor_pos = min_pos; + size_t mark_pos = max_pos; if (view.cursor.pos > view.mark.pos){ cursor_pos = max_pos; @@ -735,11 +735,11 @@ CUSTOM_COMMAND_SIG(delete_current_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t top = view.cursor.pos; - int32_t bottom = view.mark.pos; + size_t top = view.cursor.pos; + size_t bottom = view.mark.pos; if (top > bottom){ - Swap(int32_t, top, bottom); + Swap(size_t, top, bottom); } if (buffer_get_char(app, &buffer, top) == '{' && buffer_get_char(app, &buffer, bottom-1) == '}'){ @@ -948,10 +948,10 @@ parse_statement_down(Application_Links *app, Statement_Parser *parser, Cpp_Token } static bool32 -find_whole_statement_down(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t *start_out, int32_t *end_out){ +find_whole_statement_down(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t *start_out, size_t *end_out){ bool32 result = false; - int32_t start = pos; - int32_t end = start; + size_t start = pos; + size_t end = start; Cpp_Get_Token_Result get_result = {0}; @@ -990,11 +990,11 @@ CUSTOM_COMMAND_SIG(scope_absorb_down){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - int32_t top = view.cursor.pos; - int32_t bottom = view.mark.pos; + size_t top = view.cursor.pos; + size_t bottom = view.mark.pos; if (top > bottom){ - Swap(int32_t, top, bottom); + Swap(size_t, top, bottom); } Partition *part = &global_part; @@ -1123,9 +1123,9 @@ CUSTOM_COMMAND_SIG(rename_parameter){ String replace_string = with.string; Buffer_Edit *edits = (Buffer_Edit*)partition_current(part); - uint32_t remaining = (uint32_t)partition_remaining(part); - uint32_t edit_size = sizeof(Buffer_Edit); - uint32_t edit_max = remaining/edit_size; + size_t remaining = partition_remaining(part); + size_t edit_size = sizeof(Buffer_Edit); + uint32_t edit_max = (uint32_t)(remaining/edit_size); uint32_t edit_count = 0; if (edit_max >= 1){ @@ -1149,7 +1149,7 @@ CUSTOM_COMMAND_SIG(rename_parameter){ switch (token_ptr->type){ case CPP_TOKEN_IDENTIFIER: { - if (token_ptr->size == old_lexeme.size){ + if (token_ptr->size == (uint32_t)old_lexeme.size){ char other_lexeme_base[128]; String other_lexeme = make_fixed_width_string(other_lexeme_base); other_lexeme.size = old_lexeme.size; diff --git a/power/4coder_miblo_numbers.cpp b/power/4coder_miblo_numbers.cpp index ab2e506c..fc2197e1 100644 --- a/power/4coder_miblo_numbers.cpp +++ b/power/4coder_miblo_numbers.cpp @@ -15,7 +15,7 @@ TYPE: 'drop-in-command-pack' #include "4coder_helper/4coder_streaming.h" static bool32 -get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, int32_t *numeric_start, int32_t *numeric_end){ +get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, size_t *numeric_start, size_t *numeric_end){ bool32 result = false; char current = buffer_get_char(app, buffer, start_pos); @@ -25,10 +25,10 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, int int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; - int32_t pos = start_pos; + size_t pos = start_pos; - int32_t pos1 = 0; - int32_t pos2 = 0; + size_t pos1 = 0; + size_t pos2 = 0; if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){ @@ -72,15 +72,15 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, int } struct Miblo_Number_Info{ - int32_t start, end; + size_t start, end; int32_t x; }; static bool32 -get_numeric_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Miblo_Number_Info *info){ +get_numeric_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t pos, Miblo_Number_Info *info){ bool32 result = false; - int32_t numeric_start = 0, numeric_end = 0; + size_t numeric_start = 0, numeric_end = 0; if (get_numeric_string_at_cursor(app, buffer, pos, &numeric_start, &numeric_end)){ int32_t string_length = (int32_t)(numeric_end - numeric_start); char numeric_string[1024]; @@ -133,7 +133,7 @@ CUSTOM_COMMAND_SIG(miblo_decrement_basic){ // (h+:)?m?m:ss static bool32 -get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, int32_t *timestamp_start, int32_t *timestamp_end){ +get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, size_t *timestamp_start, size_t *timestamp_end){ bool32 result = false; char current = buffer_get_char(app, buffer, start_pos); @@ -143,10 +143,10 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, i int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; - int32_t pos = start_pos; + size_t pos = start_pos; - int32_t pos1 = 0; - int32_t pos2 = 0; + size_t pos1 = 0; + size_t pos2 = 0; if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){ @@ -272,15 +272,15 @@ timestamp_to_str(String *dest, Miblo_Timestamp t){ } struct Miblo_Timestamp_Info{ - int32_t start, end; + size_t start, end; Miblo_Timestamp time; }; static bool32 -get_timestamp_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Miblo_Timestamp_Info *info){ +get_timestamp_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t pos, Miblo_Timestamp_Info *info){ bool32 result = false; - int32_t timestamp_start = 0, timestamp_end = 0; + size_t timestamp_start = 0, timestamp_end = 0; if (get_timestamp_string_at_cursor(app, buffer, pos, ×tamp_start, ×tamp_end)){ int32_t string_length = (int32_t)(timestamp_end - timestamp_start); char timestamp_string[1024]; diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 0f05df2c..d97ed6a7 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -72,9 +72,10 @@ ////////////////////////////// #include "4ed_file_track.h" -#include "4ed_font_interface_to_os.h" #include "4ed_system_shared.h" +#include "win32_4ed_file_track.cpp" + // // Win32_Vars structs // @@ -1147,35 +1148,31 @@ Sys_Get_Binary_Path_Sig(system_get_binary_path){ internal Sys_File_Exists_Sig(system_file_exists){ - b32 result = false; + char full_filename_space[1024]; + String full_filename; + HANDLE file; + b32 result = 0; - Partition *scratch = &shared_vars.scratch; - Temp_Memory temp = begin_temp_memory(scratch); - u32 filename_16_max = (len+1)*2; - u16 *filename_16 = push_array(scratch, u16, filename_16_max); - - b32 convert_error = false; - u32 filename_16_len = (u32)utf8_to_utf16_minimal_checking(filename_16, filename_16_max, (u8*)filename, len, &convert_error); - - if (!convert_error){ - filename_16[filename_16_len] = 0; + if (len < sizeof(full_filename_space)){ + full_filename = make_fixed_width_string(full_filename_space); + copy_ss(&full_filename, make_string(filename, len)); + terminate_with_null(&full_filename); + + file = CreateFile(full_filename.str, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - HANDLE file = CreateFile((LPWSTR)filename_16, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ CloseHandle(file); - result = true; + result = 1; } } - end_temp_memory(temp); - return(result); } internal Sys_Directory_CD_Sig(system_directory_cd){ String directory = make_string_cap(dir, *len, cap); - b32 result = false; + b32 result = 0; i32 old_size; char rel_path_space[1024]; @@ -1185,7 +1182,7 @@ Sys_Directory_CD_Sig(system_directory_cd){ if (rel_path[0] != 0){ if (rel_path[0] == '.' && rel_path[1] == 0){ - result = true; + result = 1; } else if (rel_path[0] == '.' && rel_path[1] == '.' && rel_path[2] == 0){ result = remove_last_folder(&directory); @@ -1196,8 +1193,8 @@ Sys_Directory_CD_Sig(system_directory_cd){ old_size = directory.size; append_partial_sc(&directory, rel_path); append_s_char(&directory, '\\'); - if (Win32DirectoryExists((u8*)directory.str)){ - result = true; + if (Win32DirectoryExists(directory.str)){ + result = 1; } else{ directory.size = old_size; @@ -1302,57 +1299,10 @@ Win32ReadClipboardContents(){ // Command Line Exectuion // -internal b32 -win32_create_process_utf8(char *cmd, char *command_line, char *path, STARTUPINFO *startup, PROCESS_INFORMATION *info){ - b32 result = false; - LPWSTR env_variables = 0; - - Partition *scratch = &shared_vars.scratch; - Temp_Memory temp = begin_temp_memory(scratch); - - u32 cmd_len = 0; - for (;cmd[cmd_len];++cmd_len); - - u32 command_line_len = 0; - for (;command_line[command_line_len];++command_line_len); - - u32 path_len = 0; - for (;path[path_len];++path_len); - - u32 cmd_16_max = (cmd_len+1)*2; - u32 command_line_16_max = (command_line_len+1)*2; - u32 path_16_max = (path_len+1)*2; - - u16 *cmd_16 = push_array(scratch, u16, cmd_16_max); - u16 *command_line_16 = push_array(scratch, u16, command_line_16_max); - u16 *path_16 = push_array(scratch, u16, path_16_max); - - b32 convert_error = false; - u32 cmd_16_len = (u32)utf8_to_utf16_minimal_checking(cmd_16, cmd_16_max - 1, (u8*)cmd, cmd_len, &convert_error); - if (!convert_error){ - u32 command_line_16_len = (u32)utf8_to_utf16_minimal_checking(command_line_16, command_line_16_max - 1, (u8*)command_line, command_line_len, &convert_error); - - if (!convert_error){ - u32 path_16_len = (u32)utf8_to_utf16_minimal_checking(path_16, path_16_max - 1, (u8*)path, path_len, &convert_error); - - if (!convert_error){ - cmd_16[cmd_16_len] = 0; - command_line_16[command_line_16_len] = 0; - path_16[path_16_len] = 0; - - result = CreateProcess((LPWSTR)cmd_16, (LPWSTR)command_line_16, 0, 0, TRUE, 0, env_variables, (LPWSTR)path_16, startup, info); - } - } - } - - end_temp_memory(temp); - - return(result); -} - internal Sys_CLI_Call_Sig(system_cli_call){ char cmd[] = "c:\\windows\\system32\\cmd.exe"; + char *env_variables = 0; char command_line[2048]; String s = make_fixed_width_string(command_line); @@ -1382,7 +1332,10 @@ Sys_CLI_Call_Sig(system_cli_call){ PROCESS_INFORMATION info = {}; Assert(sizeof(Plat_Handle) >= sizeof(HANDLE)); - if (win32_create_process_utf8(cmd, command_line, path, &startup, &info)){ + if (CreateProcess(cmd, command_line, + 0, 0, TRUE, 0, + env_variables, path, + &startup, &info)){ success = 1; CloseHandle(info.hThread); *(HANDLE*)&cli_out->proc = info.hProcess; @@ -2177,7 +2130,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS memory_vars.user_memory = VirtualAlloc(base, memory_vars.target_memory_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); win32vars.target.max = MB(1); - win32vars.target.push_buffer = (char*)system_memory_allocate(win32vars.target.max); + win32vars.target.push_buffer = (char*)system_get_memory(win32vars.target.max); if (memory_vars.vars_memory == 0 || memory_vars.target_memory == 0 || memory_vars.user_memory == 0 || win32vars.target.push_buffer == 0){ exit(1); @@ -2204,16 +2157,11 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // Read Command Line // - DWORD cd_required = (GetCurrentDirectory(0, 0)*4) + 1; - u16 *current_directory_16 = (u16*)system_memory_allocate(cd_required*4); - DWORD written_16 = GetCurrentDirectory(cd_required, (LPWSTR)current_directory_16); + DWORD required = (GetCurrentDirectory(0, 0)*4) + 1; + char *current_directory_mem = (char*)system_get_memory(required); + DWORD written = GetCurrentDirectory(required, current_directory_mem); - u8 *current_directory_mem = (u8*)(current_directory_16 + cd_required); - - b32 convert_error = false; - u32 current_directory_len = (u32)utf16_to_utf8_minimal_checking(current_directory_mem, cd_required*2, current_directory_16, written_16, &convert_error); - - String current_directory = make_string_cap(current_directory_mem, current_directory_len, cd_required*2); + String current_directory = make_string_cap(current_directory_mem, written, required); terminate_with_null(¤t_directory); replace_char(¤t_directory, '\\', '/'); @@ -2251,7 +2199,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS if (win32vars.custom_api.get_alpha_4coder_version == 0 || win32vars.custom_api.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){ - MessageBox(0, L"Error: The application and custom version numbers don't match.\n", L"Error", 0); + MessageBox(0,"Error: The application and custom version numbers don't match.\n", "Error",0); exit(1); } win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*) @@ -2259,7 +2207,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } if (win32vars.custom_api.get_bindings == 0){ - MessageBox(0, L"Error: The custom dll is missing.\n", L"Error", 0); + MessageBox(0,"Error: The custom dll is missing.\n", "Error",0); exit(1); } @@ -2275,8 +2223,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS window_class.style = CS_HREDRAW|CS_VREDRAW; window_class.lpfnWndProc = (WNDPROC)(Win32Callback); window_class.hInstance = hInstance; - window_class.lpszClassName = L"4coder-win32-wndclass"; - window_class.hIcon = LoadIcon(hInstance, L"main"); + window_class.lpszClassName = "4coder-win32-wndclass"; + window_class.hIcon = LoadIcon(hInstance, "main"); if (!RegisterClass(&window_class)){ exit(1); @@ -2297,7 +2245,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // TODO(allen): non-fatal diagnostics } -#define WINDOW_NAME L"4coder-window: " L_VERSION +#define WINDOW_NAME "4coder-window: " VERSION i32 window_x = CW_USEDEFAULT; i32 window_y = CW_USEDEFAULT; @@ -2386,7 +2334,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS win32vars.app.init(&win32vars.system, &win32vars.target, &memory_vars, win32vars.clipboard_contents, current_directory, win32vars.custom_api); - system_memory_free(current_directory_16, 0); + system_free_memory(current_directory.str); b32 keep_playing = 1; win32vars.first = 1; @@ -2626,10 +2574,10 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS return(0); } -#include "4ed_font_static_functions.cpp" +#include "font/4coder_font_static_functions.cpp" #include "win32_4ed_fonts.cpp" -#include "win32_4ed_file_track.cpp" +//#include "win32_4ed_file_track.cpp" #if 0 // NOTE(allen): In case I want to switch back to a console diff --git a/win32_4ed_file_track.cpp b/win32_4ed_file_track.cpp index a64fcbb4..1794ec72 100644 --- a/win32_4ed_file_track.cpp +++ b/win32_4ed_file_track.cpp @@ -295,7 +295,7 @@ expand_track_system_listeners(File_Track_System *system, Partition *scratch, voi } FILE_TRACK_LINK File_Track_Result -get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, umem max, umem *size){ +get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 max, umem *size){ File_Track_Result result = FileTrack_NoMoreEvents; Win32_File_Track_Vars *vars = to_vars(system); @@ -341,7 +341,7 @@ get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, umem i32 req_size = dir_len + 1 + len; if (req_size < max){ u16 *buffer_16 = push_array(scratch, u16, req_size+1); - i32 pos = GetFinalPathNameByHandle(listener.dir, (LPWSTR)buffer_16, (DWORD)max, FILE_NAME_NORMALIZED); + i32 pos = GetFinalPathNameByHandle(listener.dir, (LPWSTR)buffer_16, max, FILE_NAME_NORMALIZED); b32 convert_error = false; umem buffer_size = utf16_to_utf8_minimal_checking(buffer, max-1, buffer_16, pos, &convert_error); diff --git a/win32_4ed_fonts.cpp b/win32_4ed_fonts.cpp index 2bc907cf..3b50b8f3 100644 --- a/win32_4ed_fonts.cpp +++ b/win32_4ed_fonts.cpp @@ -10,9 +10,9 @@ // TOP #include "4ed_system_shared.h" -#include "4ed_font_interface.h" -#include "4ed_font_interface_to_os.h" -#include "4ed_font_data.h" +#include "font/4coder_font_interface.h" +#include "font/4coder_font_interface_to_os.h" +#include "font/4coder_font_data.h" struct Win32_Fonts{ Partition part; From baa8ef3d8dbaf739bf4cc6c2e95aafb501c42bf7 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 23 Mar 2017 15:15:05 -0400 Subject: [PATCH 05/17] Revert "progress converting the platform layer over" unfucking things This reverts commit c7b1328cabb55c65eea6f3225708e74500675f1d. --- 4coder_API/types.h | 10 +- 4coder_project_commands.cpp | 6 +- 4ed.cpp | 2 +- 4ed_api_implementation.cpp | 10 +- 4ed_buffer.cpp | 210 +++++++++++++++++---------------- 4ed_buffer_model.h | 2 +- 4ed_file.cpp | 12 +- 4ed_file_view.cpp | 183 +++++++++++++++-------------- 4ed_hot_directory.cpp | 2 +- 4ed_system.h | 8 +- 4ed_translation.cpp | 8 +- 4ed_working_set.cpp | 2 +- pens_arena.cpp | 14 +++ power/4coder_experiments.cpp | 7 +- win32_4ed.cpp | 220 +++++++++-------------------------- 15 files changed, 313 insertions(+), 383 deletions(-) create mode 100644 pens_arena.cpp diff --git a/4coder_API/types.h b/4coder_API/types.h index 380d619a..b168b18c 100644 --- a/4coder_API/types.h +++ b/4coder_API/types.h @@ -417,11 +417,11 @@ DOC_SEE(File_List) */ STRUCT File_Info{ /* DOC(This field is a null terminated string specifying the name of the file.) */ - uint8_t *filename; + char *filename; /* DOC(This field specifies the length of the filename string not counting the null terminator.) */ - uint32_t filename_len; + int32_t filename_len; /* DOC(This field indicates that the description is for a folder not a file.) */ - bool32 folder; + int32_t folder; }; /* DOC(File_List is a list of File_Info structs.) */ @@ -431,9 +431,9 @@ STRUCT File_List{ /* DOC(This field is an array of File_Info structs.) */ File_Info *infos; /* DOC(This field specifies the number of struts in the info array.) */ - uint32_t count; + int32_t count; /* DOC(This field is for internal use.) */ - uint32_t block_size; + int32_t block_size; }; /* DOC(Buffer_Identifier acts as a loosely typed description of a buffer that can either be a name or an id.) */ diff --git a/4coder_project_commands.cpp b/4coder_project_commands.cpp index d7d8b66c..97d77ffe 100644 --- a/4coder_project_commands.cpp +++ b/4coder_project_commands.cpp @@ -102,12 +102,12 @@ open_all_files_with_extension_internal(Application_Links *app, String dir, char File_List list = get_file_list(app, dir.str, dir.size); int32_t dir_size = dir.size; - for (uint32_t i = 0; i < list.count; ++i){ + for (int32_t i = 0; i < list.count; ++i){ File_Info *info = list.infos + i; if (info->folder){ if (recursive){ dir.size = dir_size; - append(&dir, (char*)info->filename); + append(&dir, info->filename); append(&dir, "/"); open_all_files_with_extension_internal(app, dir, extension_list, extension_count, recursive); } @@ -130,7 +130,7 @@ open_all_files_with_extension_internal(Application_Links *app, String dir, char if (is_match){ dir.size = dir_size; - append(&dir, (char*)info->filename); + append(&dir, info->filename); create_buffer(app, dir.str, dir.size, 0); } } diff --git a/4ed.cpp b/4ed.cpp index 929a0586..54cb706b 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -452,7 +452,7 @@ COMMAND_DECL(toggle_line_wrap){ else{ file->settings.unwrapped_lines = 1; } - view_cursor_move(system, view, (u32)view->edit_pos->cursor.pos); + view_cursor_move(system, view, view->edit_pos->cursor.pos); view_set_relative_scrolling(view, scrolling); } diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index d23b4b24..f5f62908 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -571,7 +571,7 @@ DOC_SEE(4coder_Buffer_Positioning_System) size = buffer_size(&file->state.buffer); if (0 <= start && start <= end && end <= size){ result = true; - buffer_stringify(&file->state.buffer, (u32)start, (u32)end, out); + buffer_stringify(&file->state.buffer, start, end, out); } fill_buffer_summary(buffer, file, cmd); } @@ -672,7 +672,7 @@ DOC_SEE(Buffer_Batch_Edit_Type) char *inv_str = (char*)part->base + part->pos; umem inv_str_max = part->max - part->pos; - Edit_Spec spec = file_compute_edit(mem, file, edits, str, (u32)str_len, inverse_edits, inv_str, (u32)inv_str_max, (u32)edit_count, type); + Edit_Spec spec = file_compute_edit(mem, file, edits, str, str_len, inverse_edits, inv_str, (u32)inv_str_max, (u32)edit_count, type); file_do_batch_edit(system, models, file, spec, hist_normal, type); @@ -1802,11 +1802,11 @@ DOC_SEE(Buffer_Seek) if (seek.type != buffer_seek_pos){ result = true; cursor = view_compute_cursor(system, vptr, seek, 0); - vptr->edit_pos->mark = (u32)cursor.pos; + vptr->edit_pos->mark = cursor.pos; } else{ result = true; - vptr->edit_pos->mark = (u32)seek.pos; + vptr->edit_pos->mark = seek.pos; } fill_view_summary(system, view, vptr, cmd); } @@ -1832,7 +1832,7 @@ DOC(The highlight is mutually exclusive to the cursor. When the turn_on paramet if (vptr != 0){ result = true; if (turn_on){ - view_set_temp_highlight(system, vptr, (u32)start, (u32)end); + view_set_temp_highlight(system, vptr, start, end); } else{ vptr->file_data.show_temp_highlight = false; diff --git a/4ed_buffer.cpp b/4ed_buffer.cpp index 421f04ef..2c2868c7 100644 --- a/4ed_buffer.cpp +++ b/4ed_buffer.cpp @@ -17,12 +17,12 @@ #include "4coder_helper/4coder_seek_types.h" typedef struct Cursor_With_Index{ - u32 pos; + umem pos; i32 index; } Cursor_With_Index; inline void -write_cursor_with_index(Cursor_With_Index *positions, u32 *count, u32 pos){ +write_cursor_with_index(Cursor_With_Index *positions, i32 *count, umem pos){ positions[(*count)].index = *count; positions[(*count)].pos = pos; ++(*count); @@ -33,7 +33,7 @@ write_cursor_with_index(Cursor_With_Index *positions, u32 *count, u32 pos){ internal void buffer_quick_sort_cursors(Cursor_With_Index *positions, i32 start, i32 pivot){ i32 mid = start; - u32 pivot_pos = positions[pivot].pos; + umem pivot_pos = positions[pivot].pos; for (i32 i = mid; i < pivot; ++i){ if (positions[i].pos < pivot_pos){ CursorSwap__(positions[mid], positions[i]); @@ -78,7 +78,7 @@ buffer_unsort_cursors(Cursor_With_Index *positions, i32 count){ } internal void -buffer_update_cursors(Cursor_With_Index *sorted_positions, u32 count, u32 start, u32 end, u32 len, b32 lean_right){ +buffer_update_cursors(Cursor_With_Index *sorted_positions, i32 count, i32 start, i32 end, i32 len, b32 lean_right){ i32 shift_amount = (len - (end - start)); Cursor_With_Index *position = sorted_positions + count - 1; @@ -121,8 +121,8 @@ buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, u32 edit_count){ Buffer_Edit *edit = sorted_edits; i32 shift_total = 0, shift_max = 0; for (u32 i = 0; i < edit_count; ++i, ++edit){ - u32 target_length = (u32)(edit->end - edit->start); - u32 edit_length = (u32)edit->len; + umem target_length = edit->end - edit->start; + umem edit_length = edit->len; if (edit_length > target_length){ shift_total += (i32)(edit_length - target_length); } @@ -138,7 +138,7 @@ buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, u32 edit_count){ } internal i32 -buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, u32 count, Buffer_Edit *sorted_edits, u32 edit_count, b32 lean_right){ +buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, Buffer_Edit *sorted_edits, i32 edit_count, b32 lean_right){ Cursor_With_Index *position = sorted_positions; Cursor_With_Index *end_position = sorted_positions + count; Buffer_Edit *edit = sorted_edits; @@ -147,20 +147,20 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, u32 count, if (lean_right){ for (; edit < end_edit && position < end_position; ++edit){ - u32 start = (u32)edit->start; - u32 end = (u32)edit->end; + umem start = edit->start; + umem end = edit->end; for (; position->pos < start && position < end_position; ++position){ position->pos += shift_amount; } - u32 new_end = start + (u32)edit->len + shift_amount; + umem new_end = start + edit->len + shift_amount; for (; position->pos <= end && position < end_position; ++position){ position->pos = new_end; } - u32 target_length = end - start; - u32 edit_length = (u32)edit->len; + umem target_length = end - start; + umem edit_length = edit->len; if (edit_length > target_length){ shift_amount += (i32)(edit_length - target_length); } @@ -171,20 +171,20 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, u32 count, } else{ for (; edit < end_edit && position < end_position; ++edit){ - u32 start = (u32)edit->start; - u32 end = (u32)edit->end; + umem start = edit->start; + umem end = edit->end; for (; position->pos < start && position < end_position; ++position){ position->pos += shift_amount; } - u32 new_end = start + shift_amount; + umem new_end = start + shift_amount; for (; position->pos <= end && position < end_position; ++position){ position->pos = new_end; } - u32 target_length = end - start; - u32 edit_length = (u32)edit->len; + umem target_length = end - start; + umem edit_length = edit->len; if (edit_length > target_length){ shift_amount += (i32)(edit_length - target_length); } @@ -199,8 +199,8 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, u32 count, } for (; edit < end_edit; ++edit){ - u32 target_length = (u32)(edit->end - edit->start); - u32 edit_length = (u32)edit->len; + umem target_length = edit->end - edit->start; + umem edit_length = edit->len; if (edit_length > target_length){ shift_amount += (i32)(edit_length - target_length); } @@ -214,9 +214,9 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, u32 count, ////////////////////////////////////// -internal u32 -eol_convert_in(char *dest, char *src, u32 size){ - u32 i = 0, j = 0, k = 0; +internal umem +eol_convert_in(char *dest, char *src, umem size){ + umem i = 0, j = 0, k = 0; for (; j < size && src[j] != '\r'; ++j); memcpy(dest, src, j); @@ -238,9 +238,9 @@ eol_convert_in(char *dest, char *src, u32 size){ return(j); } -internal u32 -eol_in_place_convert_in(char *data, u32 size){ - u32 i = 0, j = 0, k = 0; +internal umem +eol_in_place_convert_in(char *data, umem size){ + umem i = 0, j = 0, k = 0; for (; j < size && data[j] != '\r'; ++j); @@ -263,9 +263,9 @@ eol_in_place_convert_in(char *data, u32 size){ // TODO(allen): iterative memory check? internal b32 -eol_convert_out(char *dest, u32 max, char *src, u32 size, u32 *size_out){ +eol_convert_out(char *dest, umem max, char *src, umem size, umem *size_out){ b32 result = true; - u32 i = 0, j = 0; + umem i = 0, j = 0; for (; i < size; ++i, ++j){ if (src[i] == '\n'){ @@ -284,9 +284,9 @@ eol_convert_out(char *dest, u32 max, char *src, u32 size, u32 *size_out){ // TODO(allen): iterative memory check? internal b32 -eol_in_place_convert_out(char *data, u32 size, u32 max, u32 *size_out){ +eol_in_place_convert_out(char *data, umem size, umem max, umem *size_out){ b32 result = true; - u32 i = 0; + umem i = 0; for (; i < size; ++i){ if (data[i] == '\n'){ @@ -309,10 +309,10 @@ eol_in_place_convert_out(char *data, u32 size, u32 max, u32 *size_out){ typedef struct Gap_Buffer{ char *data; - u32 size1; - u32 gap_size; - u32 size2; - u32 max; + umem size1; + umem gap_size; + umem size2; + umem max; u32 *line_starts; u32 line_count; @@ -325,16 +325,22 @@ buffer_good(Gap_Buffer *buffer){ return(good); } +inline umem +buffer_size_umem(Gap_Buffer *buffer){ + umem size = buffer->size1 + buffer->size2; + return(size); +} + inline u32 buffer_size(Gap_Buffer *buffer){ - u32 size = buffer->size1 + buffer->size2; - return(size); + umem size = buffer->size1 + buffer->size2; + return(u32)(size); } typedef struct Gap_Buffer_Init{ Gap_Buffer *buffer; char *data; - u32 size; + umem size; } Gap_Buffer_Init; internal Gap_Buffer_Init @@ -355,29 +361,29 @@ buffer_init_need_more(Gap_Buffer_Init *init){ return(result); } -internal u32 +internal umem buffer_init_page_size(Gap_Buffer_Init *init){ - u32 result = init->size * 2; + umem result = init->size * 2; return(result); } internal void -buffer_init_provide_page(Gap_Buffer_Init *init, void *page, u32 page_size){ +buffer_init_provide_page(Gap_Buffer_Init *init, void *page, umem page_size){ Gap_Buffer *buffer = init->buffer; buffer->data = (char*)page; buffer->max = page_size; } internal b32 -buffer_end_init(Gap_Buffer_Init *init, void *scratch, u32 scratch_size){ +buffer_end_init(Gap_Buffer_Init *init, void *scratch, umem scratch_size){ Gap_Buffer *buffer = init->buffer; b32 result = false; if (buffer->data && buffer->max >= init->size){ - u32 size = init->size; - u32 size2 = size*2; - u32 osize1 = size - size2; - u32 size1 = osize1; + umem size = init->size; + umem size2 = size*2; + umem osize1 = size - size2; + umem size1 = osize1; if (size1 > 0){ size1 = eol_convert_in(buffer->data, init->data, size1); @@ -400,8 +406,8 @@ buffer_end_init(Gap_Buffer_Init *init, void *scratch, u32 scratch_size){ typedef struct Gap_Buffer_Stream{ Gap_Buffer *buffer; char *data; - u32 end; - u32 absolute_end; + umem end; + umem absolute_end; b32 separated; b32 use_termination_character; char terminator; @@ -409,7 +415,7 @@ typedef struct Gap_Buffer_Stream{ static Gap_Buffer_Stream null_buffer_stream = {0}; internal b32 -buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, u32 start, u32 end){ +buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, umem start, umem end){ b32 result = false; if (0 <= start && start < end && end <= buffer->size1 + buffer->size2){ @@ -482,7 +488,7 @@ buffer_stringify_next(Gap_Buffer_Stream *stream){ } internal b32 -buffer_replace_range(Gap_Buffer *buffer, u32 start, u32 end, char *str, u32 len, i32 *shift_amount, void *scratch, u32 scratch_memory, u32 *request_amount){ +buffer_replace_range(Gap_Buffer *buffer, u32 start, u32 end, char *str, u32 len, i32 *shift_amount, void *scratch, umem scratch_memory, umem *request_amount){ char *data = buffer->data; u32 size = buffer_size(buffer); b32 result = false; @@ -491,7 +497,7 @@ buffer_replace_range(Gap_Buffer *buffer, u32 start, u32 end, char *str, u32 len, assert(start <= end); assert(end <= size); - u32 target_length = end - start; + umem target_length = end - start; if (target_length <= max_i32 && len <= max_i32){ if (len >= target_length){ @@ -502,7 +508,7 @@ buffer_replace_range(Gap_Buffer *buffer, u32 start, u32 end, char *str, u32 len, } if (*shift_amount + size <= buffer->max){ - u32 move_size = 0; + umem move_size = 0; if (end < buffer->size1){ move_size = buffer->size1 - end; memmove(data + buffer->size1 + buffer->gap_size - move_size, data + end, move_size); @@ -525,7 +531,7 @@ buffer_replace_range(Gap_Buffer *buffer, u32 start, u32 end, char *str, u32 len, assert(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max); } else{ - *request_amount = l_round_up_u32(2*(*shift_amount + size), KB(4)); + *request_amount = l_round_up_umem(2*(*shift_amount + size), KB(4)); result = true; } } @@ -540,7 +546,7 @@ typedef struct Buffer_Batch_State{ // TODO(allen): Now that we are just using Gap_Buffer we could afford to improve this for the Gap_Buffer's behavior. internal b32 -buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, char *strings, u32 edit_count, void *scratch, u32 scratch_size, u32 *request_amount){ +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){ Buffer_Edit *edit = 0; u32 i = state->i; i32 shift_total = state->shift_total; @@ -567,10 +573,10 @@ buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edi } internal void* -buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, u32 new_max){ +buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, umem new_max){ void *result = buffer->data; - u32 size = buffer_size(buffer); - u32 new_gap_size = new_max - size; + umem size = buffer_size_umem(buffer); + umem new_gap_size = new_max - size; assert(new_max >= size); @@ -589,14 +595,14 @@ buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, u32 new_max){ // inline void -buffer_stringify(Gap_Buffer *buffer, u32 start, u32 end, char *out){ +buffer_stringify(Gap_Buffer *buffer, umem start, umem end, char *out){ Gap_Buffer_Stream stream = {0}; - u32 i = start; + umem i = start; if (buffer_stringify_loop(&stream, buffer, i, end)){ b32 still_looping = false; do{ - u32 size = stream.end - i; + umem size = stream.end - i; memcpy(out, stream.data + i, size); i = stream.end; out += size; @@ -605,19 +611,19 @@ buffer_stringify(Gap_Buffer *buffer, u32 start, u32 end, char *out){ } } -internal u32 -buffer_convert_out(Gap_Buffer *buffer, char *dest, u32 max){ +internal umem +buffer_convert_out(Gap_Buffer *buffer, char *dest, umem max){ Gap_Buffer_Stream stream = {0}; u32 size = buffer_size(buffer); assert(size + buffer->line_count <= max); - u32 pos = 0; + umem pos = 0; if (buffer_stringify_loop(&stream, buffer, 0, size)){ - u32 i = 0; + umem i = 0; b32 still_looping = false; do{ - u32 chunk_size = stream.end - i; - u32 out_size = 0; + umem chunk_size = stream.end - i; + umem out_size = 0; b32 result = eol_convert_out(dest + pos, max - pos, stream.data + i, chunk_size, &out_size); assert(result); i = stream.end; @@ -728,8 +734,8 @@ buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap stream.use_termination_character = 1; stream.terminator = '\n'; - u32 size = buffer_size(buffer); - u32 i = 0; + umem size = buffer_size(buffer); + umem i = 0; if (buffer_stringify_loop(&stream, buffer, i, size)){ b32 still_looping = false; do{ @@ -1126,8 +1132,8 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G } internal void -buffer_remeasure_wrap_y(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 line_shift, f32 *wraps, f32 font_height, f32 *adv, f32 max_width){ - u32 new_line_count = buffer->line_count; +buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 line_shift, f32 *wraps, f32 font_height, f32 *adv, f32 max_width){ + umem new_line_count = buffer->line_count; assert(0 <= start_line); assert(start_line <= end_line); @@ -1136,8 +1142,8 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li ++end_line; // Shift - u32 line_count = new_line_count; - u32 new_end_line = end_line; + umem line_count = new_line_count; + umem new_end_line = end_line; if (line_shift != 0){ line_count -= line_shift; new_end_line += line_shift; @@ -1147,9 +1153,9 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li // Iteration data (yikes! Need better loop system) Gap_Buffer_Stream stream = {0}; - u32 size = buffer_size(buffer); - u32 char_i = buffer->line_starts[start_line]; - u32 line_i = start_line; + umem size = buffer_size(buffer); + umem char_i = buffer->line_starts[start_line]; + umem line_i = start_line; // Line wrap measurement f32 last_wrap = wraps[line_i]; @@ -1262,11 +1268,11 @@ buffer_get_line_index_from_wrapped_y(u32 *wrap_line_index, f32 y, i32 line_heigh } internal Partial_Cursor -buffer_partial_from_pos(Gap_Buffer *buffer, u32 pos){ +buffer_partial_from_pos(Gap_Buffer *buffer, umem pos){ Partial_Cursor result = {0}; u32 size = buffer_size(buffer); - pos = clamp_u32(0, pos, size); + pos = clamp_umem(0, pos, size); u32 line_index = buffer_get_line_index_range(buffer, (u32)pos, 0, (u32)buffer->line_count); result.pos = pos; @@ -1277,10 +1283,10 @@ buffer_partial_from_pos(Gap_Buffer *buffer, u32 pos){ } internal Partial_Cursor -buffer_partial_from_line_character(Gap_Buffer *buffer, u32 line, u32 character, b32 reversed){ +buffer_partial_from_line_character(Gap_Buffer *buffer, umem line, umem character, b32 reversed){ Partial_Cursor result = {0}; - u32 line_index = line - 1; + umem line_index = line - 1; if (line_index >= buffer->line_count){ line_index = buffer->line_count - 1; } @@ -1288,16 +1294,16 @@ buffer_partial_from_line_character(Gap_Buffer *buffer, u32 line, u32 character, line_index = 0; } - u32 size = buffer_size(buffer); + umem size = buffer_size(buffer); - u32 this_start = buffer->line_starts[line_index]; - u32 max_character = (size-this_start) + 1; + umem this_start = buffer->line_starts[line_index]; + umem max_character = (size-this_start) + 1; if (line_index+1 < buffer->line_count){ - u32 next_start = buffer->line_starts[line_index+1]; + umem next_start = buffer->line_starts[line_index+1]; max_character = (next_start-this_start); } - u32 adjusted_pos = 0; + umem adjusted_pos = 0; if (character > 0){ if (reversed){ if (character > max_character){ @@ -1431,7 +1437,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa default: InvalidCodePath; } - u32 safe_line_index = line_index; + umem safe_line_index = line_index; if (line_index >= params.buffer->line_count){ safe_line_index = params.buffer->line_count-1; } @@ -1460,9 +1466,9 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa S.next_cursor.unwrapped_x += line_shift; S.next_cursor.wrapped_x += line_shift; - S.stream.use_termination_character = true; + S.stream.use_termination_character = 1; S.stream.terminator = '\n'; - if (buffer_stringify_loop(&S.stream, params.buffer, (u32)S.next_cursor.pos, S.size)){ + if (buffer_stringify_loop(&S.stream, params.buffer, S.next_cursor.pos, S.size)){ do{ for (; S.next_cursor.pos < S.stream.end; ++S.next_cursor.pos){ u8 ch = (u8)S.stream.data[S.next_cursor.pos]; @@ -1707,7 +1713,7 @@ buffer_invert_edit_shift(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inve inverse->len = len; inverse->start = edit.start + shift_amount; inverse->end = edit.start + edit.len + shift_amount; - buffer_stringify(buffer, (u32)edit.start, (u32)edit.end, strings + pos); + buffer_stringify(buffer, edit.start, edit.end, strings + pos); } inline void @@ -1716,7 +1722,7 @@ buffer_invert_edit(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inverse, c } typedef struct Buffer_Invert_Batch{ - u32 i; + umem i; i32 shift_amount; u32 len; } Buffer_Invert_Batch; @@ -1724,7 +1730,7 @@ typedef struct Buffer_Invert_Batch{ internal b32 buffer_invert_batch(Buffer_Invert_Batch *state, Gap_Buffer *buffer, Buffer_Edit *edits, u32 count, Buffer_Edit *inverse, char *strings, u32 *str_pos, u32 max){ i32 shift_amount = state->shift_amount; - u32 i = state->i; + umem i = state->i; Buffer_Edit *edit = edits + i; Buffer_Edit *inv_edit = inverse + i; b32 result = false; @@ -1733,8 +1739,8 @@ buffer_invert_batch(Buffer_Invert_Batch *state, Gap_Buffer *buffer, Buffer_Edit if (*str_pos + edit->end - edit->start <= max){ buffer_invert_edit_shift(buffer, *edit, inv_edit, strings, str_pos, max, shift_amount); - u32 target_length = (u32)(edit->end - edit->start); - u32 edit_length = (u32)edit->len; + umem target_length = edit->end - edit->start; + umem edit_length = edit->len; if (edit_length > target_length){ shift_amount += (i32)(edit_length - target_length); } @@ -1760,7 +1766,7 @@ enum Buffer_Render_Flag{ }; typedef struct Buffer_Render_Item{ - u32 index; + umem index; u32 codepoint; u32 flags; f32 x0, y0; @@ -1778,7 +1784,7 @@ typedef struct Render_Item_Write{ } Render_Item_Write; inline Render_Item_Write -write_render_item(Render_Item_Write write, u32 index, u32 codepoint, u32 flags){ +write_render_item(Render_Item_Write write, umem index, u32 codepoint, u32 flags){ f32 ch_width = font_get_glyph_advance(write.system, write.font, codepoint); if (write.x <= write.x_max && write.x + ch_width >= write.x_min){ @@ -1821,8 +1827,8 @@ struct Buffer_Render_Params{ struct Buffer_Render_State{ Gap_Buffer_Stream stream; b32 still_looping; - u32 i; - u32 size; + umem i; + umem size; f32 shift_x; f32 shift_y; @@ -1832,9 +1838,9 @@ struct Buffer_Render_State{ Render_Item_Write write; f32 byte_advance; - u32 line; - u32 wrap_line; - u32 wrap_unit_end; + umem line; + umem wrap_line; + umem wrap_unit_end; b32 skipping_whitespace; b32 first_of_the_line; @@ -1877,8 +1883,8 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 S.shift_y += params.start_cursor.unwrapped_y; } - S.line = (u32)params.start_cursor.line - 1; - S.wrap_line = (u32)params.start_cursor.wrap_line - 1; + S.line = params.start_cursor.line - 1; + S.wrap_line = params.start_cursor.wrap_line - 1; if (params.virtual_white){ S_stop.status = BLStatus_NeedLineShift; @@ -1903,7 +1909,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 } S.first_of_the_line = 1; - S.i = (u32)params.start_cursor.pos; + S.i = params.start_cursor.pos; if (buffer_stringify_loop(&S.stream, params.buffer, S.i, S.size)){ do{ for (; S.i < S.stream.end; ++S.i){ @@ -1989,7 +1995,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 } if (!S.skipping_whitespace){ - u32 I = S.step.i; + umem I = S.step.i; switch (n){ case '\r': { @@ -2017,7 +2023,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 } else if (S.behavior.do_number_advance){ u8 n = (u8)S.step.value; - u32 I = S.step.i; + umem I = S.step.i; S.skipping_whitespace = false; S.ch_width = S.byte_advance; diff --git a/4ed_buffer_model.h b/4ed_buffer_model.h index 7f7df32a..a9abc718 100644 --- a/4ed_buffer_model.h +++ b/4ed_buffer_model.h @@ -15,7 +15,7 @@ struct Buffer_Model_Step{ u32 type; u32 value; - u32 i; + umem i; u32 byte_length; }; diff --git a/4ed_file.cpp b/4ed_file.cpp index c2778da9..7e407e53 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -21,7 +21,7 @@ enum Edit_Pos_Set_Type{ struct File_Edit_Positions{ GUI_Scroll_Vars scroll; Full_Cursor cursor; - u32 mark; + umem mark; f32 preferred_x; i32 scroll_i; i32 last_set_type; @@ -385,13 +385,13 @@ edit_pos_get_new(Editing_File *file, i32 index){ // inline Partial_Cursor -file_compute_cursor_from_pos(Editing_File *file, u32 pos){ +file_compute_cursor_from_pos(Editing_File *file, umem pos){ Partial_Cursor result = buffer_partial_from_pos(&file->state.buffer, pos); return(result); } inline Partial_Cursor -file_compute_cursor_from_line_character(Editing_File *file, u32 line, u32 character, b32 reversed){ +file_compute_cursor_from_line_character(Editing_File *file, umem line, umem character, b32 reversed){ Partial_Cursor result = buffer_partial_from_line_character(&file->state.buffer, line, character, reversed); return(result); } @@ -402,17 +402,17 @@ file_compute_partial_cursor(Editing_File *file, Buffer_Seek seek, Partial_Cursor switch (seek.type){ case buffer_seek_pos: { - *cursor = file_compute_cursor_from_pos(file, (u32)seek.pos); + *cursor = file_compute_cursor_from_pos(file, seek.pos); }break; case buffer_seek_line_char: { - *cursor = file_compute_cursor_from_line_character(file, (u32)seek.line, (u32)seek.character, true); + *cursor = file_compute_cursor_from_line_character(file, seek.line, seek.character, true); }break; case buffer_seek_line_reverse_char: { - *cursor = file_compute_cursor_from_line_character(file, (u32)seek.line, (u32)seek.character, false); + *cursor = file_compute_cursor_from_line_character(file, seek.line, seek.character, false); }break; default: diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index be69bfbd..0e3c5b2f 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -146,7 +146,7 @@ struct File_Viewing_Data{ Editing_File *file; Full_Cursor temp_highlight; - u32 temp_highlight_end_pos; + umem temp_highlight_end_pos; b32 show_temp_highlight; b32 show_whitespace; @@ -289,14 +289,14 @@ view_file_height(View *view){ return (result); } -inline u32 +inline size_t view_get_cursor_pos(View *view){ - u32 result = 0; + size_t result = 0; if (view->file_data.show_temp_highlight){ - result = (u32)view->file_data.temp_highlight.pos; + result = view->file_data.temp_highlight.pos; } else if (view->edit_pos){ - result = (u32)view->edit_pos->cursor.pos; + result = view->edit_pos->cursor.pos; } return(result); } @@ -402,7 +402,7 @@ view_compute_cursor(System_Functions *system, View *view, Buffer_Seek seek, b32 Buffer_Cursor_Seek_State state = {0}; Buffer_Layout_Stop stop = {0}; - u32 size = buffer_size(params.buffer); + umem size = buffer_size(params.buffer); f32 line_shift = 0.f; u32 wrap_unit_end = 0; @@ -619,7 +619,7 @@ view_set_cursor_and_scroll(View *view, Full_Cursor cursor, b32 set_preferred_x, } inline void -view_set_temp_highlight(System_Functions *system, View *view, u32 pos, u32 end_pos){ +view_set_temp_highlight(System_Functions *system, View *view, umem pos, umem end_pos){ view->file_data.temp_highlight = view_compute_cursor(system, view, seek_pos(pos), 0); view->file_data.temp_highlight_end_pos = end_pos; view->file_data.show_temp_highlight = 1; @@ -741,7 +741,7 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, models->hook_save_file(&models->app_links, file->id.id); } - u32 max = 0, size = 0; + umem max = 0, size = 0; b32 dos_write_mode = file->settings.dos_write_mode; Gap_Buffer *buffer = &file->state.buffer; @@ -779,7 +779,7 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, if (!using_actual_filename && file->canon.name.str != 0){ char space[512]; u32 length = str_size(filename); - system->get_canonical((u8*)filename, length, (u8*)space, sizeof(space)); + system->get_canonical(filename, length, space, sizeof(space)); char *source_path = file->canon.name.str; if (match(space, source_path)){ @@ -877,7 +877,7 @@ file_update_cursor_positions(System_Functions *system, Models *models, Editing_F for (View_Iter iter = file_view_iter_init(layout, file, 0); file_view_iter_good(iter); iter = file_view_iter_next(iter)){ - u32 pos = view_get_cursor_pos(iter.view); + umem pos = view_get_cursor_pos(iter.view); if (!iter.view->file_data.show_temp_highlight){ Full_Cursor cursor = view_compute_cursor(system, iter.view, seek_pos(pos), 0); @@ -997,8 +997,8 @@ struct Code_Wrap_State{ b32 consume_newline; Gap_Buffer_Stream stream; - u32 size; - u32 i; + umem size; + umem i; Render_Font *font; f32 tab_indent_amount; @@ -1052,8 +1052,8 @@ wrap_state_set_top(Code_Wrap_State *state, f32 line_shift){ } struct Code_Wrap_Step{ - u32 position_start; - u32 position_end; + umem position_start; + umem position_end; f32 start_x; f32 final_x; @@ -1062,9 +1062,9 @@ struct Code_Wrap_Step{ }; internal Code_Wrap_Step -wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_State *state, u32 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}; - u32 i = state->i; + umem i = state->i; result.position_start = i; @@ -1102,9 +1102,9 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_ state->next_line_start = state->line_starts[state->line_index + 1]; } - u32 line_start = state->line_starts[state->line_index]; + i32 line_start = state->line_starts[state->line_index]; b32 still_looping = 0; - u32 end = state->token_ptr->start + state->token_ptr->size; + i32 end = state->token_ptr->start + state->token_ptr->size; if (fixed_end_point >= 0 && end > fixed_end_point){ end = fixed_end_point; @@ -1234,7 +1234,7 @@ struct Wrap_Indent_Pair{ }; struct Potential_Wrap_Indent_Pair{ - u32 wrap_position; + i32 wrap_position; f32 line_shift; f32 wrap_x; @@ -1498,8 +1498,8 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, potential_marks = push_array(part, Potential_Wrap_Indent_Pair, floor32(width)); - u32 remaining = (u32)partition_remaining(part); - u32 pair_size = sizeof(Wrap_Indent_Pair); + umem remaining = partition_remaining(part); + 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); } @@ -1530,8 +1530,8 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, else{ Gap_Buffer_Stream stream = {0}; - u32 word_stage = 0; - u32 i = stop.pos; + i32 word_stage = 0; + i32 i = stop.pos; f32 x = stop.x; f32 self_x = 0; if (buffer_stringify_loop(&stream, params.buffer, i, size)){ @@ -1826,7 +1826,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, } } - u32 wrap_position = potential_marks[best_i].wrap_position; + i32 wrap_position = potential_marks[best_i].wrap_position; f32 line_shift = potential_marks[best_i].line_shift; b32 adjust_top_to_this = potential_marks[best_i].adjust_top_to_this; wrap_indent_marks[real_count].wrap_position = wrap_position; @@ -1931,8 +1931,8 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * file->state = null_editing_file_state; Gap_Buffer_Init init = buffer_begin_init(&file->state.buffer, val.str, val.size); for (; buffer_init_need_more(&init); ){ - u32 page_size = buffer_init_page_size(&init); - page_size = l_round_up_u32(page_size, KB(4)); + umem page_size = buffer_init_page_size(&init); + page_size = l_round_up_umem(page_size, KB(4)); if (page_size < KB(4)){ page_size = KB(4); } @@ -1940,7 +1940,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * buffer_init_provide_page(&init, data, page_size); } - u32 scratch_size = (u32)partition_remaining(part); + umem scratch_size = partition_remaining(part); Assert(scratch_size > 0); b32 init_success = buffer_end_init(&init, part->base + part->pos, scratch_size); AllowLocal(init_success); Assert(init_success); @@ -2048,7 +2048,7 @@ Job_Callback_Sig(job_full_lex){ u32 text_size = buffer_size(buffer); u32 aligned_buffer_size = (text_size + 3)&(~3); - while (memory->size < aligned_buffer_size){ + while (memory->size < (umem)aligned_buffer_size){ system->grow_thread_memory(memory); } @@ -2063,7 +2063,7 @@ Job_Callback_Sig(job_full_lex){ // TODO(allen): deduplicate this against relex char *chunks[3]; - u32 chunk_sizes[3]; + umem chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2078,7 +2078,7 @@ Job_Callback_Sig(job_full_lex){ do{ char *chunk = chunks[chunk_index]; - u32 chunk_size = chunk_sizes[chunk_index]; + umem chunk_size = chunk_sizes[chunk_index]; i32 result = cpp_lex_step(&lex, chunk, (i32)chunk_size, text_size, &tokens, 2048); @@ -2192,7 +2192,7 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ Gap_Buffer *buffer = &file->state.buffer; i32 text_size = buffer_size(buffer); - u32 mem_size = (u32)partition_remaining(part); + umem mem_size = partition_remaining(part); Cpp_Token_Array tokens; tokens.max_count = (u32)(mem_size / sizeof(Cpp_Token)); @@ -2205,7 +2205,7 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ // TODO(allen): deduplicate this against relex char *chunks[3]; - u32 chunk_sizes[3]; + umem chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2222,7 +2222,7 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ do{ char *chunk = chunks[chunk_index]; - u32 chunk_size = chunk_sizes[chunk_index]; + umem chunk_size = chunk_sizes[chunk_index]; i32 result = cpp_lex_step(&lex, chunk, (i32)chunk_size, text_size, &tokens, NO_OUT_LIMIT); @@ -2313,7 +2313,7 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi Cpp_Relex_Data state = cpp_relex_init(array, start_i, end_i, shift_amount); char *chunks[3]; - u32 chunk_sizes[3]; + umem chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2326,7 +2326,7 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi i32 chunk_index = 0; char *chunk = chunks[chunk_index]; - u32 chunk_size = chunk_sizes[chunk_index]; + umem chunk_size = chunk_sizes[chunk_index]; while (!cpp_relex_is_start_chunk(&state, chunk, (i32)chunk_size)){ ++chunk_index; @@ -2421,8 +2421,8 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, Gap_Buffer *buffer = &file->state.buffer; Cpp_Token_Array *array = &file->state.token_array; - u32 remaining = (u32)partition_remaining(part); - u32 token_size = sizeof(Cpp_Token); + umem remaining = partition_remaining(part); + umem token_size = sizeof(Cpp_Token); Temp_Memory temp = begin_temp_memory(part); Cpp_Token_Array relex_array; @@ -2435,7 +2435,7 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, Cpp_Relex_Data state = cpp_relex_init(array, start_i, end_i, shift_amount); char *chunks[3]; - u32 chunk_sizes[3]; + umem chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2446,9 +2446,9 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, chunks[2] = 0; chunk_sizes[2] = 0; - u32 chunk_index = 0; + umem chunk_index = 0; char *chunk = chunks[chunk_index]; - u32 chunk_size = chunk_sizes[chunk_index]; + umem chunk_size = chunk_sizes[chunk_index]; while (!cpp_relex_is_start_chunk(&state, chunk, (i32)chunk_size)){ ++chunk_index; @@ -2488,7 +2488,7 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, } internal void -undo_stack_grow_string(General_Memory *general, Edit_Stack *stack, u32 extra_size){ +undo_stack_grow_string(General_Memory *general, Edit_Stack *stack, umem extra_size){ u32 old_max = stack->max; u8 *old_str = stack->strings; u32 new_max = old_max*2 + (u32)(extra_size); @@ -2508,27 +2508,27 @@ undo_stack_grow_edits(General_Memory *general, Edit_Stack *stack){ } internal void -child_stack_grow_string(General_Memory *general, Small_Edit_Stack *stack, u32 extra_size){ - u32 old_max = stack->max; +child_stack_grow_string(General_Memory *general, Small_Edit_Stack *stack, umem extra_size){ + umem old_max = stack->max; u8 *old_str = stack->strings; - u32 new_max = old_max*2 + extra_size; + umem new_max = old_max*2 + extra_size; u8 *new_str = (u8*)general_memory_reallocate(general, old_str, old_max, new_max); stack->strings = new_str; stack->max = (u32)new_max; } internal void -child_stack_grow_edits(General_Memory *general, Small_Edit_Stack *stack, u32 amount){ - u32 old_max = stack->edit_max; +child_stack_grow_edits(General_Memory *general, Small_Edit_Stack *stack, umem amount){ + umem old_max = stack->edit_max; Buffer_Edit *old_eds = stack->edits; - u32 new_max = old_max*2 + amount; + umem new_max = old_max*2 + amount; Buffer_Edit *new_eds = (Buffer_Edit*)general_memory_reallocate(general, old_eds, old_max*sizeof(Buffer_Edit), new_max*sizeof(Buffer_Edit)); stack->edits = new_eds; stack->edit_max = (u32)new_max; } internal i32 -undo_children_push(General_Memory *general, Small_Edit_Stack *children, Buffer_Edit *edits, u32 edit_count, u8 *strings, u32 string_size){ +undo_children_push(General_Memory *general, Small_Edit_Stack *children, Buffer_Edit *edits, u32 edit_count, u8 *strings, umem string_size){ i32 result = children->edit_count; if (children->edit_count + edit_count > children->edit_max){ child_stack_grow_edits(general, children, edit_count); @@ -2570,7 +2570,7 @@ file_post_undo(General_Memory *general, Editing_File *file, Edit_Step step, b32 if (step.child_count == 0){ if (step.edit.end - step.edit.start + undo->size > undo->max){ - undo_stack_grow_string(general, undo, (u32)(step.edit.end - step.edit.start)); + undo_stack_grow_string(general, undo, step.edit.end - step.edit.start); } Buffer_Edit inv; @@ -2639,7 +2639,7 @@ file_post_redo(General_Memory *general, Editing_File *file, Edit_Step step){ if (step.child_count == 0){ if (step.edit.end - step.edit.start + redo->size > redo->max){ - undo_stack_grow_string(general, redo, (u32)(step.edit.end - step.edit.start)); + undo_stack_grow_string(general, redo, step.edit.end - step.edit.start); } Buffer_Edit inv; @@ -2707,7 +2707,7 @@ file_post_history(General_Memory *general, Editing_File *file, Edit_Step step, b if (step.child_count == 0){ if (step.edit.end - step.edit.start + history->size > history->max){ - undo_stack_grow_string(general, history, (u32)(step.edit.end - step.edit.start)); + undo_stack_grow_string(general, history, step.edit.end - step.edit.start); } Buffer_Edit inv; @@ -2780,7 +2780,7 @@ view_cursor_move(View *view, Full_Cursor cursor){ } inline void -view_cursor_move(System_Functions *system, View *view, u32 pos){ +view_cursor_move(System_Functions *system, View *view, umem pos){ Full_Cursor cursor = view_compute_cursor(system, view, seek_pos(pos), 0); view_cursor_move(view, cursor); } @@ -3106,8 +3106,8 @@ file_edit_cursor_fix(System_Functions *system, Models *models, Editing_File *fil Cursor_With_Index *r_cursors = push_array(part, Cursor_With_Index, cursor_max); Assert(cursors != 0); - u32 cursor_count = 0; - u32 r_cursor_count = 0; + i32 cursor_count = 0; + i32 r_cursor_count = 0; View *view = 0; Panel *panel = 0, *used_panels = &layout->used_sentinel; @@ -3115,9 +3115,9 @@ file_edit_cursor_fix(System_Functions *system, Models *models, Editing_File *fil view = panel->view; if (view->file_data.file == file){ Assert(view->edit_pos); - write_cursor_with_index(cursors, &cursor_count, (u32)view->edit_pos->cursor.pos); - write_cursor_with_index(cursors, &cursor_count, (u32)view->edit_pos->mark); - write_cursor_with_index(cursors, &cursor_count, (u32)view->edit_pos->scroll_i); + write_cursor_with_index(cursors, &cursor_count, view->edit_pos->cursor.pos); + write_cursor_with_index(cursors, &cursor_count, view->edit_pos->mark); + write_cursor_with_index(cursors, &cursor_count, view->edit_pos->scroll_i); } } @@ -3128,10 +3128,10 @@ file_edit_cursor_fix(System_Functions *system, Models *models, Editing_File *fil Marker *markers = &marker_it->marker_0; for (u32 i = 0; i < count; ++i){ if (markers[i].lean_right){ - write_cursor_with_index(r_cursors, &r_cursor_count, (u32)markers[i].pos); + write_cursor_with_index(r_cursors, &r_cursor_count, markers[i].pos); } else{ - write_cursor_with_index(cursors, &cursor_count, (u32)markers[i].pos); + write_cursor_with_index(cursors, &cursor_count, markers[i].pos); } } } @@ -3157,7 +3157,7 @@ file_edit_cursor_fix(System_Functions *system, Models *models, Editing_File *fil if (view->file_data.file == file){ Assert(view->edit_pos); - u32 cursor_pos = cursors[cursor_count++].pos; + umem cursor_pos = cursors[cursor_count++].pos; Full_Cursor new_cursor = view_compute_cursor(system, view, seek_pos(cursor_pos), 0); GUI_Scroll_Vars scroll = view->edit_pos->scroll; @@ -3223,10 +3223,10 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file u32 end = (u32)spec.step.edit.end; u32 str_len = (u32)spec.step.edit.len; - u32 scratch_size = (u32)partition_remaining(part); + umem scratch_size = partition_remaining(part); Assert(scratch_size > 0); - u32 request_amount = 0; + umem request_amount = 0; Assert(end <= buffer_size(&file->state.buffer)); while (buffer_replace_range(&file->state.buffer, start, end, str, str_len, &shift_amount, part->base + part->pos, scratch_size, &request_amount)){ void *new_data = 0; @@ -3303,7 +3303,7 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, u32 scratch_size = (u32)partition_remaining(part); Buffer_Batch_State state = {0}; - u32 request_amount = 0; + umem request_amount = 0; while (buffer_batch_edit_step(&state, &file->state.buffer, batch, (char*)str_base, batch_size, part->base + part->pos, scratch_size, &request_amount)){ @@ -3354,8 +3354,8 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, for (; token < end_token; ++token){ original = *token; for (; edit < end_edit && edit->start <= original.start; ++edit){ - u32 target_length = (u32)(edit->end - edit->start); - u32 edit_length = (u32)edit->len; + umem target_length = edit->end - edit->start; + umem edit_length = edit->len; if (edit_length > target_length){ local_shift = (i32)(edit_length - target_length); } @@ -3367,8 +3367,8 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, token->start += shift_amount; local_shift = 0; for (; edit < end_edit && edit->start < original.start + original.size; ++edit){ - u32 target_length = (u32)(edit->end - edit->start); - u32 edit_length = (u32)edit->len; + umem target_length = edit->end - edit->start; + umem edit_length = edit->len; if (edit_length > target_length){ local_shift = (i32)(edit_length - target_length); } @@ -3464,8 +3464,8 @@ apply_history_edit(System_Functions *system, Models *models, Editing_File *file, file_do_single_edit(system, models, file, spec, history_mode); if (view){ - view_cursor_move(system, view, (u32)(step.edit.start + step.edit.len)); - view->edit_pos->mark = (u32)view->edit_pos->cursor.pos; + view_cursor_move(system, view, step.edit.start + step.edit.len); + view->edit_pos->mark = view->edit_pos->cursor.pos; Style *style = main_style(models); view_post_paste_effect(view, 0.333f, (u32)step.edit.start, (u32)step.edit.len, style->main.undo_color); @@ -3594,15 +3594,15 @@ working_set_clipboard_roll_down(Working_Set *working){ internal void clipboard_copy(System_Functions *system, General_Memory *general, Working_Set *working, Range range, Editing_File *file){ - u32 size = (u32)(range.end - range.start); + umem size = range.end - range.start; String *dest = working_set_next_clipboard_string(general, working, (u32)size); - buffer_stringify(&file->state.buffer, (u32)range.start, (u32)range.end, dest->str); + buffer_stringify(&file->state.buffer, range.start, range.end, dest->str); dest->size = (i32)size; system->post_clipboard(*dest); } internal Edit_Spec -file_compute_edit(Mem_Options *mem, Editing_File *file, Buffer_Edit *edits, char *str_base, u32 str_size, Buffer_Edit *inverse_array, char *inv_str, u32 inv_max, u32 edit_count, i32 batch_type){ +file_compute_edit(Mem_Options *mem, Editing_File *file, Buffer_Edit *edits, char *str_base, umem str_size, Buffer_Edit *inverse_array, char *inv_str, u32 inv_max, u32 edit_count, i32 batch_type){ General_Memory *general = &mem->general; u32 inv_str_pos = 0; @@ -4260,7 +4260,7 @@ get_exhaustive_info(System_Functions *system, Working_Set *working_set, Exhausti result.info = loop->infos + i; loop->full_path.size = loop->r; - append_sc(&loop->full_path, (char*)result.info->filename); + append_sc(&loop->full_path, result.info->filename); terminate_with_null(&loop->full_path); Editing_File *file = working_set_canon_contains(working_set, loop->full_path); @@ -4493,6 +4493,16 @@ show_gui_u64(GUI_Target *target, String *string, i32 indent_level, i32 h_align, gui_do_text_field(target, *string, null_string); } +internal void +show_gui_umem(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message, umem x){ + string->size = 0; + append_label(string, indent_level, message); + append_padding(string, '-', h_align); + append_s_char(string, ' '); + append_u64_to_str(string, x); + gui_do_text_field(target, *string, null_string); +} + internal void show_gui_int_int(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message, i32 x, i32 m){ string->size = 0; @@ -4546,9 +4556,9 @@ show_gui_scroll(GUI_Target *target, String *string, internal void show_gui_cursor(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message,Full_Cursor cursor){ show_gui_line (target, string, indent_level , 0, message, 0); - show_gui_u64 (target, string, indent_level+1, h_align, " pos ", cursor.pos); - show_gui_u64 (target, string, indent_level+1, h_align, " line ", cursor.line); - show_gui_u64 (target, string, indent_level+1, h_align, " column ", cursor.character); + show_gui_umem (target, string, indent_level+1, h_align, " pos ", cursor.pos); + show_gui_umem (target, string, indent_level+1, h_align, " line ", cursor.line); + show_gui_umem (target, string, indent_level+1, h_align, " column ", cursor.character); show_gui_float(target, string, indent_level+1, h_align, " unwrapped_x ", cursor.unwrapped_x); show_gui_float(target, string, indent_level+1, h_align, " unwrapped_y ", cursor.unwrapped_y); show_gui_float(target, string, indent_level+1, h_align, " wrapped_x ", cursor.wrapped_x); @@ -4983,13 +4993,13 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su if (file_info.name_match){ id.id[0] = (u64)(file_info.info); - char *str = (char*)file_info.info->filename; + char *str = file_info.info->filename; i32 len = file_info.info->filename_len; String filename = make_string_cap(str, len, len + 1); if (gui_do_file_option(target, id, filename, file_info.is_folder, file_info.message)){ if (file_info.is_folder){ - set_last_folder_sc(&hdir->string, (char*)file_info.info->filename, '/'); + set_last_folder_sc(&hdir->string, file_info.info->filename, '/'); do_new_directory = 1; } @@ -5460,6 +5470,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su #define SHOW_GUI_INT(n, h, str, v) show_gui_int(target, &string, n, h, " " str " ", v) #define SHOW_GUI_INT_INT(n, h, str, v, m) show_gui_int_int(target, &string, n, h, " " str " ", v, m) #define SHOW_GUI_U64(n, h, str, v) show_gui_u64(target, &string, n, h, " " str " ", v) +#define SHOW_GUI_UMEM(n, h, str, v) show_gui_umem(target, &string, n, h, " " str " ", v) #define SHOW_GUI_ID(n, h, str, v) show_gui_id(target, &string, n, h, " " str, v) #define SHOW_GUI_FLOAT(n, h, str, v) show_gui_float(target, &string, n, h, " " str " ", v) #define SHOW_GUI_BOOL(n, h, str, v) do { if (v) { show_gui_line(target, &string, n, h, " " str " ", "true"); }\ @@ -5499,8 +5510,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su SHOW_GUI_LINE(1, "file data:"); SHOW_GUI_BOOL(2, h_align, "has file", view_ptr->file_data.file); SHOW_GUI_BOOL(2, h_align, "show temp highlight", view_ptr->file_data.show_temp_highlight); - SHOW_GUI_U64(2, h_align, "start temp highlight", view_ptr->file_data.temp_highlight.pos); - SHOW_GUI_U64(2, h_align, "end temp highlight", view_ptr->file_data.temp_highlight_end_pos); + SHOW_GUI_UMEM(2, h_align, "start temp highlight", view_ptr->file_data.temp_highlight.pos); + SHOW_GUI_UMEM(2, h_align, "end temp highlight", view_ptr->file_data.temp_highlight_end_pos); SHOW_GUI_BOOL(2, h_align, "show whitespace", view_ptr->file_data.show_whitespace); SHOW_GUI_BOOL(2, h_align, "locked", view_ptr->file_data.file_locked); @@ -5518,7 +5529,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su SHOW_GUI_BLANK (2); SHOW_GUI_CURSOR(2, h_align, "cursor:", edit_pos->cursor); SHOW_GUI_BLANK (2); - SHOW_GUI_U64 (2, h_align, "mark", edit_pos->mark); + SHOW_GUI_UMEM (2, h_align, "mark", edit_pos->mark); SHOW_GUI_FLOAT (2, h_align, "preferred_x", edit_pos->preferred_x); SHOW_GUI_INT (2, h_align, "scroll_i", edit_pos->scroll_i); } @@ -5916,9 +5927,9 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act f32 left_side_space = 0; - u32 remaining = (u32)partition_remaining(part); - u32 render_item_size = sizeof(Buffer_Render_Item); - u32 max = remaining / render_item_size; + umem remaining = partition_remaining(part); + umem render_item_size = sizeof(Buffer_Render_Item); + u32 max = (u32)(remaining / render_item_size); Buffer_Render_Item *items = push_array(part, Buffer_Render_Item, max); Font_ID font_id = file->settings.font_id; @@ -6038,12 +6049,12 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act u32 mark_color = style->main.mark_color; Buffer_Render_Item *item = items; Buffer_Render_Item *item_end = item + count; - u32 prev_ind = max_u32; + umem prev_ind = max_umem; u32 highlight_color = 0; u32 highlight_this_color = 0; for (; item < item_end; ++item){ - u32 ind = item->index; + umem ind = item->index; highlight_this_color = 0; if (tokens_use && ind != prev_ind){ Cpp_Token current_token = token_array.tokens[token_i-1]; diff --git a/4ed_hot_directory.cpp b/4ed_hot_directory.cpp index 070cde47..889bb6f4 100644 --- a/4ed_hot_directory.cpp +++ b/4ed_hot_directory.cpp @@ -34,7 +34,7 @@ hot_directory_quick_partition(File_Info *infos, i32 start, i32 pivot){ i32 comp = 0; comp = p->folder - a->folder; if (comp == 0){ - comp = compare_cc((char*)a->filename, (char*)p->filename); + comp = compare_cc(a->filename, p->filename); } if (comp < 0){ Swap(File_Info, *a, infos[start]); diff --git a/4ed_system.h b/4ed_system.h index 89025f84..e2f12321 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -31,7 +31,7 @@ handle_equal(Plat_Handle a, Plat_Handle b){ #define Sys_Set_File_List_Sig(name) void name(File_List *file_list, char *directory, char *canon_directory_out, u32 *canon_directory_size_out, u32 canon_directory_max) typedef Sys_Set_File_List_Sig(System_Set_File_List); -#define Sys_Get_Canonical_Sig(name) u32 name(u8 *src, u32 len, u8 *dst, u32 max) +#define Sys_Get_Canonical_Sig(name) u32 name(char *filename, u32 len, char *buffer, u32 max) typedef Sys_Get_Canonical_Sig(System_Get_Canonical); // file load/save @@ -47,7 +47,7 @@ typedef Sys_Load_File_Sig(System_Load_File); #define Sys_Load_Close_Sig(name) b32 name(Plat_Handle handle) typedef Sys_Load_Close_Sig(System_Load_Close); -#define Sys_Save_File_Sig(name) b32 name(char *filename, char *buffer, u32 size) +#define Sys_Save_File_Sig(name) b32 name(char *filename, char *buffer, umem size) typedef Sys_Save_File_Sig(System_Save_File); // file changes @@ -136,8 +136,8 @@ enum Thread_Group_ID{ struct Thread_Memory{ void *data; - u32 size; - u32 id; + i32 size; + i32 id; }; inline Thread_Memory thread_memory_zero(){ diff --git a/4ed_translation.cpp b/4ed_translation.cpp index 259240c0..e5318d80 100644 --- a/4ed_translation.cpp +++ b/4ed_translation.cpp @@ -13,7 +13,7 @@ struct Translation_State{ u8 fill_buffer[4]; - u32 fill_start_i; + umem fill_start_i; u8 fill_i; u8 fill_expected; }; @@ -47,7 +47,7 @@ struct Translation_Emits{ #define SINGLE_BYTE_ERROR_CLASS max_u8 internal void -translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Byte_Description *desc_out){ +translating_consume_byte(Translation_State *tran, u8 ch, umem i, umem size, Translation_Byte_Description *desc_out){ desc_out->byte_class = 0; if ((ch >= ' ' && ch < 0x7F) || ch == '\t' || ch == '\n' || ch == '\r'){ desc_out->byte_class = 1; @@ -146,7 +146,7 @@ translating_select_emit_rule_with_font(System_Functions *system, Render_Font *fo } internal void -translating_generate_emits(Translation_State *tran, Translation_Emit_Rule emit_rule, u8 ch, u32 i, Translation_Emits *emits_out){ +translating_generate_emits(Translation_State *tran, Translation_Emit_Rule emit_rule, u8 ch, umem i, Translation_Emits *emits_out){ emits_out->step_count = 0; switch (emit_rule.emit_type){ default: goto skip_all; @@ -199,7 +199,7 @@ translating_generate_emits(Translation_State *tran, Translation_Emit_Rule emit_r } internal void -translating_fully_process_byte(System_Functions *system, Render_Font *font, Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Emits *emits_out){ +translating_fully_process_byte(System_Functions *system, Render_Font *font, Translation_State *tran, u8 ch, umem i, umem size, Translation_Emits *emits_out){ Translation_Byte_Description description = {0}; translating_consume_byte(tran, ch, i, size, &description); Translation_Emit_Rule emit_rule = {0}; diff --git a/4ed_working_set.cpp b/4ed_working_set.cpp index cd1019d6..55dca405 100644 --- a/4ed_working_set.cpp +++ b/4ed_working_set.cpp @@ -360,7 +360,7 @@ internal b32 get_canon_name(System_Functions *system, Editing_File_Canon_Name *canon_name, String filename){ canon_name->name = make_fixed_width_string(canon_name->name_); - canon_name->name.size = system->get_canonical((u8*)filename.str, filename.size, (u8*)canon_name->name.str, canon_name->name.memory_size); + canon_name->name.size = system->get_canonical(filename.str, filename.size, canon_name->name.str, canon_name->name.memory_size); terminate_with_null(&canon_name->name); b32 result = (canon_name->name.size != 0); diff --git a/pens_arena.cpp b/pens_arena.cpp new file mode 100644 index 00000000..1f6c46f8 --- /dev/null +++ b/pens_arena.cpp @@ -0,0 +1,14 @@ +/* +Build target for the 'pens' project. +By Allen Webster +Created 09.01.2017 (dd.mm.yyyy) +*/ + +// TOP + +struct Arena{ + +}; + +// BOTTOM + diff --git a/power/4coder_experiments.cpp b/power/4coder_experiments.cpp index 8092a03a..a1ea1720 100644 --- a/power/4coder_experiments.cpp +++ b/power/4coder_experiments.cpp @@ -1409,8 +1409,11 @@ get_bindings(void *data, int32_t size){ bind(context, 'k', MDFR_ALT, kill_rect); bind(context, ' ', MDFR_ALT | MDFR_CTRL, multi_line_edit); - bind(context, key_page_up, MDFR_ALT, miblo_increment_basic); - bind(context, key_page_down, MDFR_ALT, miblo_decrement_basic); + bind(context, key_page_up, MDFR_ALT, miblo_increment_time_stamp); + bind(context, key_page_down, MDFR_ALT, miblo_decrement_time_stamp); + + bind(context, key_home, MDFR_ALT, miblo_increment_time_stamp_minute); + bind(context, key_end, MDFR_ALT, miblo_decrement_time_stamp_minute); end_map(context); diff --git a/win32_4ed.cpp b/win32_4ed.cpp index d97ed6a7..b2bd7a69 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -284,7 +284,7 @@ Sys_Memory_Free_Sig(system_memory_free){ } #define Win32GetMemory(size) system_memory_allocate(size) -#define Win32FreeMemory(ptr) system_memory_free(ptr, 0) +#define Win32FreeMemory(ptr) system_memory_free(ptr) #define Win32ScratchPartition sysshared_scratch_partition #define Win32ScratchPartitionGrow sysshared_partition_grow @@ -721,17 +721,14 @@ Sys_File_Can_Be_Made_Sig(system_file_can_be_made){ Partition *scratch = &shared_vars.scratch; Temp_Memory temp = begin_temp_memory(scratch); - u32 len = str_size(filename); - u32 filename_16_max = (len+1)*2; - u16 *filename_16 = push_array(scratch, u16, filename_16_max); + umem len = str_size(filename); + umem max = (len+1)*2; + u16 *filename_16 = push_array(scratch, u16, max); - b32 convert_error = false; - u32 filename_16_len = (u32)utf8_to_utf16_minimal_checking(filename_16, filename_16_max-1, (u8*)filename, len, &convert_error); - filename_16[filename_16_len] = 0;; + b32 error = false; + utf8_to_utf16_minimal_checking(filename_16, max, (u8*)filename, len, &error); - if (!convert_error){ - filename_16[filename_16_len] = 0; - + 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){ @@ -816,14 +813,13 @@ Sys_Set_File_List_Sig(system_set_file_list){ u32 required_size = character_count*2 + file_count * sizeof(File_Info); if (file_list->block_size < (i32)required_size){ - Win32FreeMemory(file_list->block); + system_memory_free(file_list->block, 0); file_list->block = system_memory_allocate(required_size); file_list->block_size = required_size; } - umem remaining_size = required_size; file_list->infos = (File_Info*)file_list->block; - u8 *name = (u8*)(file_list->infos + file_count); + char *name = (char*)(file_list->infos + file_count); if (file_list->block != 0){ search = FindFirstFile((LPWSTR)filename_16, &find_data); @@ -836,15 +832,14 @@ Sys_Set_File_List_Sig(system_set_file_list){ info->folder = (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; info->filename = name; + //u32 length = copy_fast_unsafe_cc(name, find_data.cFileName); u32 size = 0; for(;find_data.cFileName[size];++size); - umem length = utf16_to_utf8_minimal_checking(info->filename, remaining_size, (u16*)find_data.cFileName, size, &convert_error); - + umem length = utf16_to_utf8_minimal_checking(info->filename, remaining_size, file_data.cFileName, size, &convert_error); if (!convert_error){ name += length; - remaining_size += length; - info->filename_len = (u32)length; + info->filename_len = length; *name++ = 0; String fname = make_string_cap(info->filename, info->filename_len, info->filename_len+1); replace_char(&fname, '\\', '/'); @@ -877,54 +872,43 @@ Sys_Set_File_List_Sig(system_set_file_list){ } internal u32 -win32_canonical_name(u16 *src, u32 len, u16 *dst, u32 max){ +win32_canonical_ascii_name(char *src, u32 len, char *dst, u32 max){ u32 result = 0; - if (len >= 2 && ((src[0] >= 'a' && src[0] <= 'z') || (src[0] >= 'A' && src[0] <= 'Z')) && src[1] == ':'){ + char src_space[MAX_PATH + 32]; + if (len < sizeof(src_space) && len >= 2 && ((src[0] >= 'a' && src[0] <= 'z') || (src[0] >= 'A' && src[0] <= 'Z')) && src[1] == ':'){ + memcpy(src_space, src, len); + src_space[len] = 0; - HANDLE file = CreateFile((LPWSTR)src, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + HANDLE file = CreateFile(src_space, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ - DWORD final_length = GetFinalPathNameByHandle(file, (LPWSTR)dst, max, 0); + DWORD final_length = GetFinalPathNameByHandle(file, dst, max, 0); if (final_length < max && final_length >= 4){ if (dst[final_length-1] == 0){ --final_length; } final_length -= 4; - memmove(dst, dst+4, final_length*sizeof(u16)); + memmove(dst, dst+4, final_length); dst[final_length] = 0; - result = (u32)final_length; + result = final_length; } CloseHandle(file); } else{ - //String src_str = make_string(src, len); - //String path_str = path_of_directory(src_str); - //String front_str = front_of_directory(src_str); + String src_str = make_string(src, len); + String path_str = path_of_directory(src_str); + String front_str = front_of_directory(src_str); - Partition *scratch = &shared_vars.scratch; - Temp_Memory temp = begin_temp_memory(scratch); + memcpy(src_space, path_str.str, path_str.size); + src_space[path_str.size] = 0; - u16 *path_src = push_array(scratch, u16, len+1); - memcpy(path_src, src, len*sizeof(u16)); - u32 path_end = len; - for (u32 j = len; j > 0; --j){ - if (path_src[j] == '/' || path_src[j] == '\\'){ - path_end = j+1; - break; - } - } - path_src[path_end] = 0; - - u32 front_size = len - path_end; - u16 *front_src = path_src + path_end; - - HANDLE dir = CreateFile((LPWSTR)src, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + HANDLE dir = CreateFile(src_space, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir != INVALID_HANDLE_VALUE){ - DWORD final_length = GetFinalPathNameByHandle(dir, (LPWSTR)dst, max, 0); + DWORD final_length = GetFinalPathNameByHandle(dir, dst, max, 0); if (final_length < max && final_length >= 4){ if (dst[final_length-1] == 0){ @@ -933,18 +917,15 @@ win32_canonical_name(u16 *src, u32 len, u16 *dst, u32 max){ final_length -= 4; memmove(dst, dst+4, final_length); dst[final_length++] = '\\'; - memcpy(dst + final_length, front_src, front_size); - final_length += front_size; + memcpy(dst + final_length, front_str.str, front_str.size); + final_length += front_str.size; dst[final_length] = 0; - result = (u32)final_length; + result = final_length; } CloseHandle(dir); } - - end_temp_memory(temp); } - } return(result); @@ -952,57 +933,20 @@ win32_canonical_name(u16 *src, u32 len, u16 *dst, u32 max){ internal Sys_Get_Canonical_Sig(system_get_canonical){ - u32 result = 0; - - Partition *scratch = &shared_vars.scratch; - Temp_Memory temp = begin_temp_memory(scratch); - - u32 src_16_max = (len+1)*2; - u16 *src_16 = push_array(scratch, u16, src_16_max); - - u32 dst_16_max = (max+1)*2; - u16 *dst_16 = push_array(scratch, u16, dst_16_max); - - b32 convert_error = false; - u32 src_16_len = (u32)utf8_to_utf16_minimal_checking(src_16, src_16_max-1, src, len, &convert_error); - src_16[src_16_len] = 0; - - if (!convert_error){ - u32 dst_16_len = win32_canonical_name(src_16, src_16_len, dst_16, dst_16_max); - - result = (u32)utf16_to_utf8_minimal_checking(dst, max-1, dst_16, dst_16_len, &convert_error); - if (!convert_error){ - dst[result] = 0; - } - else{ - result = 0; - } - } - - end_temp_memory(temp); + u32 result = win32_canonical_ascii_name(filename, len, buffer, max); return(result); } internal Sys_Load_Handle_Sig(system_load_handle){ - b32 result = false; + b32 result = 0; + HANDLE file = CreateFile(filename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - Partition *scratch = &shared_vars.scratch; - Temp_Memory temp = begin_temp_memory(scratch); - - u32 len = 0; - for (;filename[len];++len); - - u32 filename_16_max = (len+1)*2; - u16 *filename_16 = push_array(scratch, u16, filename_16_max); - - HANDLE file = CreateFile((LPWSTR)filename_16, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ *(HANDLE*)handle_out = file; - result = true; + result = 1; } - end_temp_memory(temp); return(result); } @@ -1039,52 +983,36 @@ Sys_Load_File_Sig(system_load_file){ internal Sys_Load_Close_Sig(system_load_close){ - b32 result = false; + b32 result = 0; HANDLE file = *(HANDLE*)(&handle); if (CloseHandle(file)){ - result = true; + result = 1; } return(result); } internal Sys_Save_File_Sig(system_save_file){ - b32 result = false; - Partition *scratch = &shared_vars.scratch; - Temp_Memory temp = begin_temp_memory(scratch); + b32 result = 0; + HANDLE file = CreateFile(filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - u32 len = 0; - for (;filename[len];++len); - - u32 filename_16_max = (len+1)*2; - u16 *filename_16 = push_array(scratch, u16, filename_16_max); - - b32 convert_error = false; - u32 filename_16_len = (u32)utf8_to_utf16_minimal_checking(filename_16, filename_16_max-1, (u8*)filename, len, &convert_error); - - if (!convert_error){ - filename_16[filename_16_len] = 0; + if (file != INVALID_HANDLE_VALUE){ + DWORD written_total = 0; + DWORD written_size = 0; - HANDLE file = CreateFile((LPWSTR)filename_16, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - if (file != INVALID_HANDLE_VALUE){ - DWORD written_total = 0; - DWORD written_size = 0; - - result = true; - - while (written_total < size){ - if (!WriteFile(file, buffer + written_total, size - written_total, &written_size, 0)){ - result = false; - break; - } - written_total += written_size; + result = 1; + + while (written_total < size){ + if (!WriteFile(file, buffer + written_total, size - written_total, &written_size, 0)){ + result = 0; + break; } - - CloseHandle(file); + written_total += written_size; } + + CloseHandle(file); } - end_temp_memory(temp); return(result); } @@ -1095,54 +1023,21 @@ Sys_Now_Time_Sig(system_now_time){ } internal b32 -Win32DirectoryExists(u8 *path){ - b32 result = false; - Partition *scratch = &shared_vars.scratch; - Temp_Memory temp = begin_temp_memory(scratch); - - u32 len = 0; - for(;path[len];++len); - - u32 path_16_max = (len+1)*2; - u16 *path_16 = push_array(scratch, u16, path_16_max); - - b32 convert_error = false; - u32 path_16_len = (u32)utf8_to_utf16_minimal_checking(path_16, path_16_max-1, path, len, &convert_error); - - if (!convert_error){ - path_16[path_16_len] = 0; - - DWORD attrib = GetFileAttributes((LPWSTR)path_16); - result = (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY)); - } - - end_temp_memory(temp); - return(result); +Win32DirectoryExists(char *path){ + DWORD attrib = GetFileAttributes(path); + return (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY)); } internal Sys_Get_Binary_Path_Sig(system_get_binary_path){ i32 result = 0; - - Partition *scratch = &shared_vars.scratch; - Temp_Memory temp = begin_temp_memory(scratch); - - u32 filename_16_max = (out->memory_size+1)*2; - u16 *filename_16 = push_array(scratch, u16, filename_16_max); - - u32 length_16 = GetModuleFileName(0, (LPWSTR)filename_16, filename_16_max); - - b32 convert_error = false; - u32 size = (u32)utf16_to_utf8_minimal_checking((u8*)out->str, out->memory_size-1, filename_16, length_16, &convert_error); - - if (!convert_error){ + i32 size = GetModuleFileName(0, out->str, out->memory_size); + if (size < out->memory_size-1){ out->size = size; remove_last_folder(out); terminate_with_null(out); result = out->size; } - - end_temp_memory(temp); return(result); } @@ -1158,7 +1053,8 @@ Sys_File_Exists_Sig(system_file_exists){ copy_ss(&full_filename, make_string(filename, len)); terminate_with_null(&full_filename); - file = CreateFile(full_filename.str, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + file = CreateFile(full_filename.str, GENERIC_READ, 0, 0, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ CloseHandle(file); From c4fcde16e3a84596754bb950cc515a09eb27b6a0 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 23 Mar 2017 15:15:29 -0400 Subject: [PATCH 06/17] Revert "working on the windows layer utf8 <-> utf16 stuff" This reverts commit 3006d5425c24d21ef792f4bb81ccded4ef7167ab. --- win32_4ed.cpp | 176 ++++++++++++++++++--------------------- win32_4ed_file_track.cpp | 4 +- 2 files changed, 81 insertions(+), 99 deletions(-) diff --git a/win32_4ed.cpp b/win32_4ed.cpp index b2bd7a69..390c2446 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -726,7 +726,7 @@ Sys_File_Can_Be_Made_Sig(system_file_can_be_made){ u16 *filename_16 = push_array(scratch, u16, max); b32 error = false; - utf8_to_utf16_minimal_checking(filename_16, max, (u8*)filename, len, &error); + 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); @@ -746,120 +746,102 @@ internal Sys_Set_File_List_Sig(system_set_file_list){ b32 clear_list = true; if (directory != 0){ - Partition *scratch = &shared_vars.scratch; - Temp_Memory temp = begin_temp_memory(scratch); - char dir_space[MAX_PATH + 32]; String dir = make_string_cap(dir_space, 0, MAX_PATH + 32); append_sc(&dir, directory); terminate_with_null(&dir); - umem filename_16_max = (dir.size+1)*2; - u16 *filename_16 = push_array(scratch, u16, filename_16_max); - b32 convert_error = false; - umem length = utf8_to_utf16_minimal_checking(filename_16, filename_16_max-1, (u8*)dir.str, dir.size, &convert_error); + HANDLE dir_handle = CreateFile(dir.str, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); - if (!convert_error){ - filename_16[length] = 0; + if (dir_handle != INVALID_HANDLE_VALUE){ + DWORD final_length = GetFinalPathNameByHandle(dir_handle, dir_space, sizeof(dir_space), 0); + CloseHandle(dir_handle); - HANDLE dir_handle = CreateFile((LPWSTR)filename_16, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); - - if (dir_handle != INVALID_HANDLE_VALUE){ - DWORD final_length = GetFinalPathNameByHandle(dir_handle, (LPWSTR)filename_16, (DWORD)filename_16_max, 0); - CloseHandle(dir_handle); + if (final_length < sizeof(dir_space)){ + char *c_str_dir = dir_space; - if (final_length < sizeof(dir_space)){ - final_length -= 4; - memmove(filename_16, filename_16+4, final_length*sizeof(*filename_16)); - filename_16[final_length] = '\\'; - filename_16[final_length+1] = '*'; - filename_16[final_length+2] = 0; + final_length -= 4; + memmove(c_str_dir, c_str_dir+4, final_length); + c_str_dir[final_length] = '\\'; + c_str_dir[final_length+1] = '*'; + c_str_dir[final_length+2] = 0; + + if (canon_directory_out != 0){ + if (final_length+1 < canon_directory_max){ + memcpy(canon_directory_out, c_str_dir, final_length); + if (canon_directory_out[final_length-1] != '\\'){ + canon_directory_out[final_length++] = '\\'; + } + canon_directory_out[final_length] = 0; + *canon_directory_size_out = final_length; + } + else{ + u32 length = copy_fast_unsafe_cc(canon_directory_out, directory); + canon_directory_out[length] = 0; + *canon_directory_size_out = length; + } + } + + WIN32_FIND_DATA find_data; + HANDLE search = FindFirstFile(c_str_dir, &find_data); + + if (search != INVALID_HANDLE_VALUE){ + i32 character_count = 0; + i32 file_count = 0; + BOOL more_files = true; + do{ + if (!match_cs(find_data.cFileName, make_lit_string(".")) && + !match_cs(find_data.cFileName, make_lit_string(".."))){ + ++file_count; + i32 size = 0; + for(;find_data.cFileName[size];++size); + character_count += size + 1; + } + more_files = FindNextFile(search, &find_data); + }while(more_files); + FindClose(search); - if (canon_directory_out != 0){ - umem out_length = utf16_to_utf8_minimal_checking((u8*)canon_directory_out, canon_directory_max-1, filename_16, final_length, &convert_error); - - if (!convert_error){ - if (canon_directory_out[out_length-1] != '\\'){ - canon_directory_out[out_length++] = '\\'; - } - canon_directory_out[out_length] = 0; - *canon_directory_size_out = (u32)out_length; - } - else{ - u32 length = copy_fast_unsafe_cc(canon_directory_out, directory); - canon_directory_out[length] = 0; - *canon_directory_size_out = length; - } + i32 required_size = character_count + file_count * sizeof(File_Info); + if (file_list->block_size < required_size){ + system_free_memory(file_list->block); + file_list->block = system_get_memory(required_size); + file_list->block_size = required_size; } - WIN32_FIND_DATA find_data; - HANDLE search = FindFirstFile((LPWSTR)filename_16, &find_data); - - if (search != INVALID_HANDLE_VALUE){ - u32 character_count = 0; - u32 file_count = 0; - BOOL more_files = true; - do{ - if (!(find_data.cFileName[0] == '.' && find_data.cFileName[1] == 0) && - !(find_data.cFileName[0] == '.' && find_data.cFileName[1] == '.' && find_data.cFileName[2] == 0)){ - ++file_count; - u32 size = 0; - for(;find_data.cFileName[size];++size); - character_count += size + 1; - } - more_files = FindNextFile(search, &find_data); - }while(more_files); - FindClose(search); + file_list->infos = (File_Info*)file_list->block; + char *name = (char*)(file_list->infos + file_count); + if (file_list->block != 0){ + search = FindFirstFile(c_str_dir, &find_data); - u32 required_size = character_count*2 + file_count * sizeof(File_Info); - if (file_list->block_size < (i32)required_size){ - system_memory_free(file_list->block, 0); - file_list->block = system_memory_allocate(required_size); - file_list->block_size = required_size; - } - - file_list->infos = (File_Info*)file_list->block; - char *name = (char*)(file_list->infos + file_count); - if (file_list->block != 0){ - search = FindFirstFile((LPWSTR)filename_16, &find_data); + if (search != INVALID_HANDLE_VALUE){ + File_Info *info = file_list->infos; + more_files = true; + do{ + if (!match_cs(find_data.cFileName, make_lit_string(".")) && + !match_cs(find_data.cFileName, make_lit_string(".."))){ + info->folder = (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; + info->filename = name; + + i32 length = copy_fast_unsafe_cc(name, find_data.cFileName); + name += length; + + info->filename_len = length; + *name++ = 0; + String fname = make_string_cap(info->filename, info->filename_len, info->filename_len+1); + replace_char(&fname, '\\', '/'); + ++info; + } + more_files = FindNextFile(search, &find_data); + }while(more_files); + FindClose(search); - if (search != INVALID_HANDLE_VALUE){ - File_Info *info = file_list->infos; - more_files = true; - do{ - if (!(find_data.cFileName[0] == '.' && find_data.cFileName[1] == 0) && - !(find_data.cFileName[0] == '.' && find_data.cFileName[1] == '.' && find_data.cFileName[2] == 0)){ - info->folder = (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; - info->filename = name; - - //u32 length = copy_fast_unsafe_cc(name, find_data.cFileName); - u32 size = 0; - for(;find_data.cFileName[size];++size); - umem length = utf16_to_utf8_minimal_checking(info->filename, remaining_size, file_data.cFileName, size, &convert_error); - if (!convert_error){ - name += length; - - info->filename_len = length; - *name++ = 0; - String fname = make_string_cap(info->filename, info->filename_len, info->filename_len+1); - replace_char(&fname, '\\', '/'); - ++info; - } - } - more_files = FindNextFile(search, &find_data); - }while(more_files); - FindClose(search); - - file_list->count = file_count; - clear_list = false; - } + file_list->count = file_count; + clear_list = false; } } } } } - - end_temp_memory(temp); } if (clear_list){ diff --git a/win32_4ed_file_track.cpp b/win32_4ed_file_track.cpp index 1794ec72..d0b03d3d 100644 --- a/win32_4ed_file_track.cpp +++ b/win32_4ed_file_track.cpp @@ -135,7 +135,7 @@ add_listener(File_Track_System *system, Partition *scratch, u8 *filename){ u16 dir_name[1024]; internal_utf8_file_to_utf16_parent(dir_name, ArrayCount(dir_name), filename); - HANDLE dir = CreateFile((LPWSTR)dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + HANDLE dir = CreateFile((LPCWSTR)dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir != INVALID_HANDLE_VALUE){ BY_HANDLE_FILE_INFORMATION dir_info = {0}; @@ -217,7 +217,7 @@ remove_listener(File_Track_System *system, Partition *scratch, u8 *filename){ u16 dir_name[1024]; internal_utf8_file_to_utf16_parent(dir_name, ArrayCount(dir_name), filename); - HANDLE dir = CreateFile((LPWSTR)dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + HANDLE dir = CreateFile((LPCWSTR)dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir != INVALID_HANDLE_VALUE){ BY_HANDLE_FILE_INFORMATION dir_info = {0}; From 51b59d31d1cbdadb178be95aa9900753d1e24731 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 23 Mar 2017 15:15:33 -0400 Subject: [PATCH 07/17] Revert "Changed the a lot of stuff over to umem" This reverts commit 906f79ef8eaf866f782a4fa6d411be1cb1a8c69d. --- 4coder_API/app_functions.h | 48 ++-- 4coder_API/types.h | 18 +- 4coder_auto_indent.cpp | 121 +++++---- 4coder_base_commands.cpp | 89 +++--- 4coder_clipboard.cpp | 22 +- 4coder_default_include.cpp | 41 +-- 4coder_function_list.cpp | 6 +- 4coder_helper/4coder_helper.h | 8 +- 4coder_helper/4coder_jump_parsing.h | 16 +- 4coder_helper/4coder_long_seek.h | 350 ++++++++++++------------ 4coder_helper/4coder_seek_types.h | 9 - 4coder_helper/4coder_streaming.h | 34 +-- 4coder_jump_parsing.cpp | 27 +- 4coder_lib/4coder_mem.h | 16 +- 4coder_lib/4coder_table.h | 33 +-- 4coder_search.cpp | 175 +++++++----- 4cpp/4cpp_lexer.h | 2 +- 4ed.cpp | 22 +- 4ed_api_implementation.cpp | 82 ++++-- 4ed_buffer.cpp | 407 +++++++++++++--------------- 4ed_file.cpp | 35 +-- 4ed_file_view.cpp | 369 ++++++++++++------------- 4ed_layout.cpp | 6 +- 4ed_math.h | 6 +- 4ed_system.h | 2 +- 4ed_undo.cpp | 27 +- 4ed_working_set.cpp | 12 +- 4tech_defines.h | 12 - internal_4coder_tests.cpp | 6 - linux_release_compat.c | 12 +- power/4coder_experiments.cpp | 129 +++++---- power/4coder_miblo_numbers.cpp | 109 ++++---- vc140.pdb | Bin 36864 -> 0 bytes 33 files changed, 1110 insertions(+), 1141 deletions(-) delete mode 100644 vc140.pdb diff --git a/4coder_API/app_functions.h b/4coder_API/app_functions.h index 357ef1f1..4f4c666e 100644 --- a/4coder_API/app_functions.h +++ b/4coder_API/app_functions.h @@ -1,15 +1,15 @@ struct Application_Links; #define EXEC_COMMAND_SIG(n) bool32 n(Application_Links *app, Command_ID command_id) #define EXEC_SYSTEM_COMMAND_SIG(n) bool32 n(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags) -#define CLIPBOARD_POST_SIG(n) void n(Application_Links *app, int32_t clipboard_id, char *str, size_t len) -#define CLIPBOARD_COUNT_SIG(n) uint32_t n(Application_Links *app, uint32_t clipboard_id) -#define CLIPBOARD_INDEX_SIG(n) size_t n(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len) +#define CLIPBOARD_POST_SIG(n) void n(Application_Links *app, int32_t clipboard_id, char *str, int32_t len) +#define CLIPBOARD_COUNT_SIG(n) int32_t n(Application_Links *app, int32_t clipboard_id) +#define CLIPBOARD_INDEX_SIG(n) int32_t n(Application_Links *app, int32_t clipboard_id, int32_t item_index, char *out, int32_t len) #define GET_BUFFER_COUNT_SIG(n) int32_t n(Application_Links *app) #define GET_BUFFER_FIRST_SIG(n) Buffer_Summary n(Application_Links *app, Access_Flag access) #define GET_BUFFER_NEXT_SIG(n) void n(Application_Links *app, Buffer_Summary *buffer, Access_Flag access) #define GET_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, Buffer_ID buffer_id, Access_Flag access) #define GET_BUFFER_BY_NAME_SIG(n) Buffer_Summary n(Application_Links *app, char *name, int32_t len, Access_Flag access) -#define BUFFER_READ_RANGE_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, char *out) +#define BUFFER_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_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) @@ -20,8 +20,8 @@ struct Application_Links; #define BUFFER_GET_SETTING_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t *value_out) #define BUFFER_SET_SETTING_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t value) #define BUFFER_TOKEN_COUNT_SIG(n) int32_t n(Application_Links *app, Buffer_Summary *buffer) -#define BUFFER_READ_TOKENS_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, size_t start_token, size_t end_token, Cpp_Token *tokens_out) -#define BUFFER_GET_TOKEN_INDEX_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, size_t pos, Cpp_Get_Token_Result *get_result) +#define BUFFER_READ_TOKENS_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out) +#define BUFFER_GET_TOKEN_INDEX_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Get_Token_Result *get_result) #define BEGIN_BUFFER_CREATION_SIG(n) bool32 n(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags) #define BUFFER_CREATION_NAME_SIG(n) bool32 n(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags) #define END_BUFFER_CREATION_SIG(n) Buffer_Summary n(Application_Links *app, Buffer_Creation_Data *data) @@ -41,9 +41,9 @@ struct Application_Links; #define VIEW_SET_CURSOR_SIG(n) bool32 n(Application_Links *app, View_Summary *view, Buffer_Seek seek, bool32 set_preferred_x) #define VIEW_SET_SCROLL_SIG(n) bool32 n(Application_Links *app, View_Summary *view, GUI_Scroll_Vars scroll) #define VIEW_SET_MARK_SIG(n) bool32 n(Application_Links *app, View_Summary *view, Buffer_Seek seek) -#define VIEW_SET_HIGHLIGHT_SIG(n) bool32 n(Application_Links *app, View_Summary *view, size_t start, size_t end, bool32 turn_on) +#define VIEW_SET_HIGHLIGHT_SIG(n) bool32 n(Application_Links *app, View_Summary *view, int32_t start, int32_t end, bool32 turn_on) #define VIEW_SET_BUFFER_SIG(n) bool32 n(Application_Links *app, View_Summary *view, Buffer_ID buffer_id, Set_Buffer_Flag flags) -#define VIEW_POST_FADE_SIG(n) bool32 n(Application_Links *app, View_Summary *view, float seconds, size_t start, size_t end, int_color color) +#define VIEW_POST_FADE_SIG(n) bool32 n(Application_Links *app, View_Summary *view, float seconds, int32_t start, int32_t end, int_color color) #define GET_USER_INPUT_SIG(n) User_Input n(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type) #define GET_COMMAND_INPUT_SIG(n) User_Input n(Application_Links *app) #define GET_MOUSE_STATE_SIG(n) Mouse_State n(Application_Links *app) @@ -369,15 +369,15 @@ app_links->send_exit_signal_ = Send_Exit_Signal;} while(false) #if defined(ALLOW_DEP_4CODER) static inline bool32 exec_command(Application_Links *app, Command_ID command_id){return(app->exec_command(app, command_id));} static inline bool32 exec_system_command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags){return(app->exec_system_command(app, view, buffer, path, path_len, command, command_len, flags));} -static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, size_t len){(app->clipboard_post(app, clipboard_id, str, len));} -static inline uint32_t clipboard_count(Application_Links *app, uint32_t clipboard_id){return(app->clipboard_count(app, clipboard_id));} -static inline size_t clipboard_index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len){return(app->clipboard_index(app, clipboard_id, item_index, out, len));} +static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, int32_t len){(app->clipboard_post(app, clipboard_id, str, len));} +static inline int32_t clipboard_count(Application_Links *app, int32_t clipboard_id){return(app->clipboard_count(app, clipboard_id));} +static inline int32_t clipboard_index(Application_Links *app, int32_t clipboard_id, int32_t item_index, char *out, int32_t len){return(app->clipboard_index(app, clipboard_id, item_index, out, len));} static inline int32_t get_buffer_count(Application_Links *app){return(app->get_buffer_count(app));} static inline Buffer_Summary get_buffer_first(Application_Links *app, Access_Flag access){return(app->get_buffer_first(app, access));} static inline void get_buffer_next(Application_Links *app, Buffer_Summary *buffer, Access_Flag access){(app->get_buffer_next(app, buffer, access));} static inline Buffer_Summary get_buffer(Application_Links *app, Buffer_ID buffer_id, Access_Flag access){return(app->get_buffer(app, buffer_id, access));} static inline Buffer_Summary get_buffer_by_name(Application_Links *app, char *name, int32_t len, Access_Flag access){return(app->get_buffer_by_name(app, name, len, access));} -static inline bool32 buffer_read_range(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, char *out){return(app->buffer_read_range(app, buffer, start, end, out));} +static inline bool32 buffer_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_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));} @@ -388,8 +388,8 @@ static inline bool32 buffer_remove_markers(Application_Links *app, Buffer_Summar static inline bool32 buffer_get_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t *value_out){return(app->buffer_get_setting(app, buffer, setting, value_out));} static inline bool32 buffer_set_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t value){return(app->buffer_set_setting(app, buffer, setting, value));} static inline int32_t buffer_token_count(Application_Links *app, Buffer_Summary *buffer){return(app->buffer_token_count(app, buffer));} -static inline bool32 buffer_read_tokens(Application_Links *app, Buffer_Summary *buffer, size_t start_token, size_t end_token, Cpp_Token *tokens_out){return(app->buffer_read_tokens(app, buffer, start_token, end_token, tokens_out));} -static inline bool32 buffer_get_token_index(Application_Links *app, Buffer_Summary *buffer, size_t pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index(app, buffer, pos, get_result));} +static inline bool32 buffer_read_tokens(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out){return(app->buffer_read_tokens(app, buffer, start_token, end_token, tokens_out));} +static inline bool32 buffer_get_token_index(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index(app, buffer, pos, get_result));} static inline bool32 begin_buffer_creation(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags){return(app->begin_buffer_creation(app, data, flags));} static inline bool32 buffer_creation_name(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags){return(app->buffer_creation_name(app, data, filename, filename_len, flags));} static inline Buffer_Summary end_buffer_creation(Application_Links *app, Buffer_Creation_Data *data){return(app->end_buffer_creation(app, data));} @@ -409,9 +409,9 @@ static inline bool32 view_compute_cursor(Application_Links *app, View_Summary *v static inline bool32 view_set_cursor(Application_Links *app, View_Summary *view, Buffer_Seek seek, bool32 set_preferred_x){return(app->view_set_cursor(app, view, seek, set_preferred_x));} static inline bool32 view_set_scroll(Application_Links *app, View_Summary *view, GUI_Scroll_Vars scroll){return(app->view_set_scroll(app, view, scroll));} static inline bool32 view_set_mark(Application_Links *app, View_Summary *view, Buffer_Seek seek){return(app->view_set_mark(app, view, seek));} -static inline bool32 view_set_highlight(Application_Links *app, View_Summary *view, size_t start, size_t end, bool32 turn_on){return(app->view_set_highlight(app, view, start, end, turn_on));} +static inline bool32 view_set_highlight(Application_Links *app, View_Summary *view, int32_t start, int32_t end, bool32 turn_on){return(app->view_set_highlight(app, view, start, end, turn_on));} static inline bool32 view_set_buffer(Application_Links *app, View_Summary *view, Buffer_ID buffer_id, Set_Buffer_Flag flags){return(app->view_set_buffer(app, view, buffer_id, flags));} -static inline bool32 view_post_fade(Application_Links *app, View_Summary *view, float seconds, size_t start, size_t end, int_color color){return(app->view_post_fade(app, view, seconds, start, end, color));} +static inline bool32 view_post_fade(Application_Links *app, View_Summary *view, float seconds, int32_t start, int32_t end, int_color color){return(app->view_post_fade(app, view, seconds, start, end, color));} static inline User_Input get_user_input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type){return(app->get_user_input(app, get_type, abort_type));} static inline User_Input get_command_input(Application_Links *app){return(app->get_command_input(app));} static inline Mouse_State get_mouse_state(Application_Links *app){return(app->get_mouse_state(app));} @@ -441,15 +441,15 @@ static inline void send_exit_signal(Application_Links *app){(app->send_exit_sign #else static inline bool32 exec_command(Application_Links *app, Command_ID command_id){return(app->exec_command_(app, command_id));} static inline bool32 exec_system_command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Interface_Flag flags){return(app->exec_system_command_(app, view, buffer, path, path_len, command, command_len, flags));} -static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, size_t len){(app->clipboard_post_(app, clipboard_id, str, len));} -static inline uint32_t clipboard_count(Application_Links *app, uint32_t clipboard_id){return(app->clipboard_count_(app, clipboard_id));} -static inline size_t clipboard_index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len){return(app->clipboard_index_(app, clipboard_id, item_index, out, len));} +static inline void clipboard_post(Application_Links *app, int32_t clipboard_id, char *str, int32_t len){(app->clipboard_post_(app, clipboard_id, str, len));} +static inline int32_t clipboard_count(Application_Links *app, int32_t clipboard_id){return(app->clipboard_count_(app, clipboard_id));} +static inline int32_t clipboard_index(Application_Links *app, int32_t clipboard_id, int32_t item_index, char *out, int32_t len){return(app->clipboard_index_(app, clipboard_id, item_index, out, len));} static inline int32_t get_buffer_count(Application_Links *app){return(app->get_buffer_count_(app));} static inline Buffer_Summary get_buffer_first(Application_Links *app, Access_Flag access){return(app->get_buffer_first_(app, access));} static inline void get_buffer_next(Application_Links *app, Buffer_Summary *buffer, Access_Flag access){(app->get_buffer_next_(app, buffer, access));} static inline Buffer_Summary get_buffer(Application_Links *app, Buffer_ID buffer_id, Access_Flag access){return(app->get_buffer_(app, buffer_id, access));} static inline Buffer_Summary get_buffer_by_name(Application_Links *app, char *name, int32_t len, Access_Flag access){return(app->get_buffer_by_name_(app, name, len, access));} -static inline bool32 buffer_read_range(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, char *out){return(app->buffer_read_range_(app, buffer, start, end, out));} +static inline bool32 buffer_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_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));} @@ -460,8 +460,8 @@ static inline bool32 buffer_remove_markers(Application_Links *app, Buffer_Summar static inline bool32 buffer_get_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t *value_out){return(app->buffer_get_setting_(app, buffer, setting, value_out));} static inline bool32 buffer_set_setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t value){return(app->buffer_set_setting_(app, buffer, setting, value));} static inline int32_t buffer_token_count(Application_Links *app, Buffer_Summary *buffer){return(app->buffer_token_count_(app, buffer));} -static inline bool32 buffer_read_tokens(Application_Links *app, Buffer_Summary *buffer, size_t start_token, size_t end_token, Cpp_Token *tokens_out){return(app->buffer_read_tokens_(app, buffer, start_token, end_token, tokens_out));} -static inline bool32 buffer_get_token_index(Application_Links *app, Buffer_Summary *buffer, size_t pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index_(app, buffer, pos, get_result));} +static inline bool32 buffer_read_tokens(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out){return(app->buffer_read_tokens_(app, buffer, start_token, end_token, tokens_out));} +static inline bool32 buffer_get_token_index(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index_(app, buffer, pos, get_result));} static inline bool32 begin_buffer_creation(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags){return(app->begin_buffer_creation_(app, data, flags));} static inline bool32 buffer_creation_name(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags){return(app->buffer_creation_name_(app, data, filename, filename_len, flags));} static inline Buffer_Summary end_buffer_creation(Application_Links *app, Buffer_Creation_Data *data){return(app->end_buffer_creation_(app, data));} @@ -481,9 +481,9 @@ static inline bool32 view_compute_cursor(Application_Links *app, View_Summary *v static inline bool32 view_set_cursor(Application_Links *app, View_Summary *view, Buffer_Seek seek, bool32 set_preferred_x){return(app->view_set_cursor_(app, view, seek, set_preferred_x));} static inline bool32 view_set_scroll(Application_Links *app, View_Summary *view, GUI_Scroll_Vars scroll){return(app->view_set_scroll_(app, view, scroll));} static inline bool32 view_set_mark(Application_Links *app, View_Summary *view, Buffer_Seek seek){return(app->view_set_mark_(app, view, seek));} -static inline bool32 view_set_highlight(Application_Links *app, View_Summary *view, size_t start, size_t end, bool32 turn_on){return(app->view_set_highlight_(app, view, start, end, turn_on));} +static inline bool32 view_set_highlight(Application_Links *app, View_Summary *view, int32_t start, int32_t end, bool32 turn_on){return(app->view_set_highlight_(app, view, start, end, turn_on));} static inline bool32 view_set_buffer(Application_Links *app, View_Summary *view, Buffer_ID buffer_id, Set_Buffer_Flag flags){return(app->view_set_buffer_(app, view, buffer_id, flags));} -static inline bool32 view_post_fade(Application_Links *app, View_Summary *view, float seconds, size_t start, size_t end, int_color color){return(app->view_post_fade_(app, view, seconds, start, end, color));} +static inline bool32 view_post_fade(Application_Links *app, View_Summary *view, float seconds, int32_t start, int32_t end, int_color color){return(app->view_post_fade_(app, view, seconds, start, end, color));} static inline User_Input get_user_input(Application_Links *app, Input_Type_Flag get_type, Input_Type_Flag abort_type){return(app->get_user_input_(app, get_type, abort_type));} static inline User_Input get_command_input(Application_Links *app){return(app->get_command_input_(app));} static inline Mouse_State get_mouse_state(Application_Links *app){return(app->get_mouse_state_(app));} diff --git a/4coder_API/types.h b/4coder_API/types.h index b168b18c..51b0a039 100644 --- a/4coder_API/types.h +++ b/4coder_API/types.h @@ -399,15 +399,15 @@ Throughout the API ranges are thought of in the form [min,max) where max is "one UNION Range{ STRUCT{ /* DOC(This is the smaller value in the range, it is also the 'start'.) */ - size_t min; + int32_t min; /* DOC(This is the larger value in the range, it is also the 'end'.) */ - size_t max; + int32_t max; }; STRUCT{ /* DOC(This is the start of the range, it is also the 'min'.) */ - size_t start; + int32_t start; /* DOC(This is the end of the range, it is also the 'max'.) */ - size_t end; + int32_t end; }; }; @@ -482,9 +482,7 @@ ENUM(int32_t, Buffer_Seek_Type){ buffer_seek_unwrapped_xy, /* DOC(This value indicates line-character positioning. These coordinates are 1 based to match standard line numbering.) */ - buffer_seek_line_char, - /* DOC(This value indicates line-character positioning, but with characters counted from the end of the line instead of the beginning, so that 1 is the last character of the line.) */ - buffer_seek_line_reverse_char, + buffer_seek_line_char }; /* DOC(Buffer_Seek describes the destination of a seek operation. There are helpers for concisely creating Buffer_Seek structs. They can be found in 4coder_buffer_types.h.) @@ -616,7 +614,7 @@ DOC_SEE(buffer_add_markers) */ STRUCT Marker{ /* DOC(The current position of the marker measure in absolute byte positioning coordinates.) */ - size_t pos; + int32_t pos; /* DOC(When a marker is inside a range that gets edited, by default the marker 'leans_left' which means it goes to the beginning of the edited range. If the field lean_right is set to true, the marker will lean right with edits and will go to the end of edited range.) */ bool32 lean_right; }; @@ -735,12 +733,12 @@ STRUCT Buffer_Batch_Edit{ /* DOC(The pointer to the edit string buffer.) */ char *str; /* DOC(The length of the edit string buffer.) */ - size_t str_len; + int32_t str_len; /* DOC(The array of edits to be applied.) */ Buffer_Edit *edits; /* DOC(The number of edits in the array.) */ - uint32_t edit_count; + int32_t edit_count; }; diff --git a/4coder_auto_indent.cpp b/4coder_auto_indent.cpp index 079e15aa..89942135 100644 --- a/4coder_auto_indent.cpp +++ b/4coder_auto_indent.cpp @@ -28,29 +28,31 @@ TYPE: 'drop-in-command-pack' // struct Hard_Start_Result{ - size_t char_pos; + int32_t char_pos; int32_t indent_pos; - bool32 all_whitespace; - bool32 all_space; + int32_t all_whitespace; + int32_t all_space; }; static Hard_Start_Result -buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, size_t line_start, int32_t tab_width){ +buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, int32_t line_start, int32_t tab_width){ Hard_Start_Result result = {0}; + char data_chunk[1024]; + Stream_Chunk stream = {0}; + char c; + + tab_width -= 1; + result.all_space = 1; result.indent_pos = 0; result.char_pos = line_start; - tab_width -= 1; - - char data_chunk[1024]; - Stream_Chunk stream = {0}; stream.add_null = 1; if (init_stream_chunk(&stream, app, buffer, line_start, data_chunk, sizeof(data_chunk))){ int32_t still_looping = 1; do{ - for (; result.char_pos < (size_t)stream.end; ++result.char_pos){ - char c = stream.data[result.char_pos]; + for (; result.char_pos < stream.end; ++result.char_pos){ + c = stream.data[result.char_pos]; if (c == '\n' || c == 0){ result.all_whitespace = 1; @@ -86,25 +88,26 @@ struct Indent_Options{ }; static Buffer_Batch_Edit -make_batch_from_indent_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line_start, size_t line_end, int32_t *indent_marks, Indent_Options opts){ +make_batch_from_indent_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line_start, int32_t line_end, int32_t *indent_marks, Indent_Options opts){ Buffer_Batch_Edit result = {0}; - size_t edit_max = line_end - line_start; - uint32_t edit_count = 0; + int32_t edit_max = line_end - line_start; + int32_t edit_count = 0; Buffer_Edit *edits = push_array(part, Buffer_Edit, edit_max); char *str_base = (char*)part->base + part->pos; - size_t str_size = 0; + int32_t str_size = 0; // NOTE(allen): Shift the array so that line_i can just operate in // it's natural value range. indent_marks -= line_start; - for (size_t line_i = line_start; line_i < line_end; ++line_i){ - size_t line_start_pos = buffer_get_line_start(app, buffer, line_i); - Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, line_start_pos, opts.tab_width); + for (int32_t line_i = line_start; line_i < line_end; ++line_i){ + int32_t line_start_pos = buffer_get_line_start(app, buffer, line_i); + Hard_Start_Result hard_start = + buffer_find_hard_start(app, buffer, line_start_pos, opts.tab_width); int32_t correct_indentation = indent_marks[line_i]; if (hard_start.all_whitespace && opts.empty_blank_lines){ @@ -156,12 +159,13 @@ make_batch_from_indent_marks(Application_Links *app, Partition *part, Buffer_Sum } static void -set_line_indents(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line_start, size_t line_end, int32_t *indent_marks, Indent_Options opts){ +set_line_indents(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line_start, int32_t line_end, int32_t *indent_marks, Indent_Options opts){ Buffer_Batch_Edit batch = make_batch_from_indent_marks(app, part, buffer, line_start, line_end, indent_marks, opts); if (batch.edit_count > 0){ - buffer_batch_edit(app, buffer, batch.str, batch.str_len, batch.edits, batch.edit_count, BatchEdit_PreserveTokens); + buffer_batch_edit(app, buffer, batch.str, batch.str_len, + batch.edits, batch.edit_count, BatchEdit_PreserveTokens); } } @@ -192,7 +196,7 @@ seek_matching_token_backwards(Cpp_Token_Array tokens, Cpp_Token *token, Cpp_Toke } static Cpp_Token* -find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t line_start, int32_t tab_width, int32_t *current_indent_out){ +find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line_start, int32_t tab_width, int32_t *current_indent_out){ Cpp_Token *token = get_first_token_at_line(app, buffer, tokens, line_start); if (token == 0 && tokens.count == 0){ @@ -220,8 +224,8 @@ find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Arra int32_t current_indent = 0; int32_t found_safe_start_position = 0; do{ - size_t line = buffer_get_line_index(app, buffer, token->start); - size_t start = buffer_get_line_start(app, buffer, line); + int32_t line = buffer_get_line_index(app, buffer, token->start); + int32_t start = buffer_get_line_start(app, buffer, line); Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, start, tab_width); current_indent = hard_start.indent_pos; @@ -294,30 +298,32 @@ struct Indent_Parse_State{ }; static int32_t* -get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t line_start, size_t line_end, bool32 exact_align, int32_t tab_width){ +get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line_start, int32_t line_end, bool32 exact_align, int32_t tab_width){ - size_t indent_mark_count = line_end - line_start; + int32_t indent_mark_count = line_end - line_start; int32_t *indent_marks = push_array(part, int32_t, indent_mark_count); // Shift the array so line_index works correctly. indent_marks -= line_start; + // Decide where to start indentation parsing. Indent_Parse_State indent = {0}; - Cpp_Token *token_ptr = find_anchor_token(app, buffer, tokens, line_start, tab_width, &indent.current_indent); + Cpp_Token *token_ptr = find_anchor_token(app, buffer, tokens, line_start, + tab_width, &indent.current_indent); if (token_ptr == 0){ - for (size_t line_index = line_start; line_index < line_end; ++line_index){ + for (int32_t line_index = line_start; line_index < line_end; ++line_index){ indent_marks[line_index] = 0; } } else{ - size_t line_index = buffer_get_line_index(app, buffer, token_ptr->start); + int32_t line_index = buffer_get_line_index(app, buffer, token_ptr->start); if (line_index > line_start){ line_index = line_start; } - size_t next_line_start_pos = buffer_get_line_start(app, buffer, line_index+1); + uint32_t next_line_start_pos = buffer_get_line_start(app, buffer, line_index+1); switch (token_ptr->type){ case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += tab_width; break; @@ -347,8 +353,8 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b { int32_t previous_indent = indent.previous_line_indent; - size_t this_line_start = buffer_get_line_start(app, buffer, line_index); - size_t next_line_start = buffer_get_line_start(app, buffer, line_index+1); + uint32_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); bool32 did_special_behavior = false; @@ -364,7 +370,7 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b this_indent = previous_indent; } else{ - uint32_t line_pos = (uint32_t)(hard_start.char_pos - this_line_start); + int32_t line_pos = hard_start.char_pos - this_line_start; this_indent = line_pos + indent.comment_shift; if (this_indent < 0){ this_indent = 0; @@ -456,24 +462,24 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b case CPP_TOKEN_COMMENT: { - size_t line = buffer_get_line_index(app, buffer, token.start); - size_t start = buffer_get_line_start(app, buffer, line); - int32_t char_pos = (int32_t)(token.start - start); - indent.comment_shift = (indent.current_indent - char_pos); - indent.previous_comment_indent = char_pos; + int32_t line = buffer_get_line_index(app, buffer, token.start); + int32_t start = buffer_get_line_start(app, buffer, line); + + indent.comment_shift = (indent.current_indent - (token.start - start)); + indent.previous_comment_indent = (token.start - start); }break; case CPP_TOKEN_PARENTHESE_OPEN: if (!(token.flags & CPP_TFLAG_PP_BODY)){ if (indent.paren_nesting < ArrayCount(indent.paren_anchor_indent)){ - size_t line = buffer_get_line_index(app, buffer, token.start); - size_t start = buffer_get_line_start(app, buffer, line); - int32_t char_pos = (int32_t)(token.start - start); + int32_t line = buffer_get_line_index(app, buffer, token.start); + int32_t start = buffer_get_line_start(app, buffer, line); + int32_t char_pos = token.start - start; Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, start, tab_width); - int32_t line_pos = (int32_t)(hard_start.char_pos - start); + int32_t line_pos = hard_start.char_pos - start; indent.paren_anchor_indent[indent.paren_nesting] = char_pos - line_pos + indent.previous_line_indent + 1; @@ -499,21 +505,25 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b } static void -get_indent_lines_minimum(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, size_t end_pos, size_t *line_start_out, size_t *line_end_out){ - size_t line_start = buffer_get_line_index(app, buffer, start_pos); - size_t line_end = buffer_get_line_index(app, buffer, end_pos) + 1; +get_indent_lines_minimum(Application_Links *app, Buffer_Summary *buffer, + int32_t start_pos, int32_t end_pos, + int32_t *line_start_out, int32_t *line_end_out){ + int32_t line_start = buffer_get_line_index(app, buffer, start_pos); + int32_t line_end = buffer_get_line_index(app, buffer, end_pos) + 1; *line_start_out = line_start; *line_end_out = line_end; } static void -get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t start_pos, size_t end_pos, size_t *line_start_out, size_t *line_end_out){ - size_t line_start = buffer_get_line_index(app, buffer, start_pos); - size_t line_end = buffer_get_line_index(app, buffer, end_pos); +get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, + int32_t start_pos, int32_t end_pos, + int32_t *line_start_out, int32_t *line_end_out){ + int32_t line_start = buffer_get_line_index(app, buffer, start_pos); + int32_t line_end = buffer_get_line_index(app, buffer, end_pos); for (;line_start > 0;){ - size_t line_start_pos = 0; + uint32_t line_start_pos = 0; Cpp_Token *token = get_first_token_at_line(app, buffer, tokens, line_start, &line_start_pos); if (token != 0 && token->start < line_start_pos){ line_start = buffer_get_line_index(app, buffer, token->start); @@ -524,7 +534,7 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cp } for (;line_end+1 < buffer->line_count;){ - size_t next_line_start_pos = 0; + uint32_t next_line_start_pos = 0; Cpp_Token *token = get_first_token_at_line(app, buffer, tokens, line_end+1, &next_line_start_pos); if (token && token->start < next_line_start_pos){ line_end = buffer_get_line_index(app, buffer, token->start+token->size); @@ -545,11 +555,12 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cp } static bool32 -buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t start, size_t end, int32_t tab_width, Auto_Indent_Flag flags){ +buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buffer, + int32_t start, int32_t end, int32_t tab_width, Auto_Indent_Flag flags){ - bool32 result = false; + bool32 result = 0; if (buffer->exists && buffer->tokens_are_ready){ - result = true; + result = 1; Temp_Memory temp = begin_temp_memory(part); @@ -562,7 +573,7 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buff // Stage 2: Decide where the first and last lines are. // The lines in the range [line_start,line_end) will be indented. - size_t line_start = 0, line_end = 0; + int32_t line_start = 0, line_end = 0; if (flags & AutoIndent_FullTokens){ get_indent_lines_whole_tokens(app, buffer, tokens, start, end, &line_start, &line_end); } @@ -574,7 +585,8 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buff // Get an array representing how much each line in // the range [line_start,line_end) should be indented. int32_t *indent_marks = - get_indentation_marks(app, part, buffer, tokens, line_start, line_end, (flags & AutoIndent_ExactAlignBlock), tab_width); + get_indentation_marks(app, part, buffer, tokens, line_start, line_end, + (flags & AutoIndent_ExactAlignBlock), tab_width); // Stage 4: Set the Line Indents Indent_Options opts = {0}; @@ -591,7 +603,8 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buff } static bool32 -buffer_auto_indent(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, int32_t tab_width, Auto_Indent_Flag flags){ +buffer_auto_indent(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, + int32_t tab_width, Auto_Indent_Flag flags){ bool32 result = buffer_auto_indent(app, &global_part, buffer, start, end, tab_width, flags); return(result); } diff --git a/4coder_base_commands.cpp b/4coder_base_commands.cpp index b47837d4..d85c0616 100644 --- a/4coder_base_commands.cpp +++ b/4coder_base_commands.cpp @@ -33,7 +33,7 @@ CUSTOM_COMMAND_SIG(write_character){ if (length != 0){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos = view.cursor.pos; + int32_t pos = view.cursor.pos; Marker next_cursor_marker = {0}; next_cursor_marker.pos = character_pos_to_pos(app, &view, &buffer, view.cursor.character_pos); @@ -56,12 +56,11 @@ CUSTOM_COMMAND_SIG(delete_char){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - Buffer_Seek seek = seek_character_pos(view.cursor.character_pos+1); - Full_Cursor cursor; - view_compute_cursor(app, &view, seek, &cursor); + int32_t start = view.cursor.pos; - size_t start = view.cursor.pos; - size_t end = cursor.pos; + Full_Cursor cursor; + view_compute_cursor(app, &view, seek_character_pos(view.cursor.character_pos+1), &cursor); + int32_t end = cursor.pos; if (0 <= start && start < buffer.size){ buffer_replace_range(app, &buffer, start, end, 0, 0); @@ -73,17 +72,15 @@ CUSTOM_COMMAND_SIG(backspace_char){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - Buffer_Seek seek = seek_character_pos(view.cursor.character_pos-1); - Full_Cursor cursor; - view_compute_cursor(app, &view, seek, &cursor); + int32_t end = view.cursor.pos; - size_t end = view.cursor.pos; - size_t start = cursor.pos; + Full_Cursor cursor; + view_compute_cursor(app, &view, seek_character_pos(view.cursor.character_pos-1), &cursor); + int32_t start = cursor.pos; if (0 < end && end <= buffer.size){ buffer_replace_range(app, &buffer, start, end, 0, 0); - seek = seek_character_pos(view.cursor.character_pos-1); - view_set_cursor(app, &view, seek, true); + view_set_cursor(app, &view, seek_character_pos(view.cursor.character_pos-1), true); } } @@ -97,8 +94,8 @@ CUSTOM_COMMAND_SIG(set_mark){ CUSTOM_COMMAND_SIG(cursor_mark_swap){ View_Summary view = get_active_view(app, AccessProtected); - size_t cursor = view.cursor.pos; - size_t mark = view.mark.pos; + int32_t cursor = view.cursor.pos; + int32_t mark = view.mark.pos; view_set_cursor(app, &view, seek_pos(mark), true); view_set_mark(app, &view, seek_pos(cursor)); @@ -250,14 +247,14 @@ CUSTOM_COMMAND_SIG(page_down){ CUSTOM_COMMAND_SIG(move_left){ uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); - size_t new_pos = view.cursor.character_pos - 1; + int32_t new_pos = view.cursor.character_pos - 1; view_set_cursor(app, &view, seek_character_pos(new_pos), 1); } CUSTOM_COMMAND_SIG(move_right){ uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); - size_t new_pos = view.cursor.character_pos + 1; + int32_t new_pos = view.cursor.character_pos + 1; view_set_cursor(app, &view, seek_character_pos(new_pos), 1); } @@ -277,7 +274,7 @@ CUSTOM_COMMAND_SIG(seek_whitespace_up){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t new_pos = buffer_seek_whitespace_up(app, &buffer, view.cursor.pos); + int32_t new_pos = buffer_seek_whitespace_up(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -286,7 +283,7 @@ CUSTOM_COMMAND_SIG(seek_whitespace_down){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t new_pos = buffer_seek_whitespace_down(app, &buffer, view.cursor.pos); + int32_t new_pos = buffer_seek_whitespace_down(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -295,7 +292,7 @@ CUSTOM_COMMAND_SIG(seek_end_of_textual_line){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t new_pos = seek_line_end(app, &buffer, view.cursor.pos); + int32_t new_pos = seek_line_end(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -304,7 +301,7 @@ CUSTOM_COMMAND_SIG(seek_beginning_of_textual_line){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t new_pos = seek_line_beginning(app, &buffer, view.cursor.pos); + int32_t new_pos = seek_line_beginning(app, &buffer, view.cursor.pos); view_set_cursor(app, &view, seek_pos(new_pos), true); } @@ -350,7 +347,7 @@ CUSTOM_COMMAND_SIG(to_uppercase){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen); Range range = get_range(&view); - size_t size = range.max - range.min; + int32_t size = range.max - range.min; if (size <= app->memory_size){ char *mem = (char*)app->memory; @@ -368,7 +365,7 @@ CUSTOM_COMMAND_SIG(to_lowercase){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen); Range range = get_range(&view); - size_t size = range.max - range.min; + int32_t size = range.max - range.min; if (size <= app->memory_size){ char *mem = (char*)app->memory; @@ -568,7 +565,7 @@ CUSTOM_COMMAND_SIG(search); CUSTOM_COMMAND_SIG(reverse_search); static void -isearch(Application_Links *app, bool32 start_reversed){ +isearch(Application_Links *app, int32_t start_reversed){ uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); @@ -579,10 +576,10 @@ isearch(Application_Links *app, bool32 start_reversed){ Query_Bar bar = {0}; if (start_query_bar(app, &bar, 0) == 0) return; - bool32 reverse = start_reversed; - size_t pos = view.cursor.pos; - size_t start_pos = pos; - size_t first_pos = pos; + int32_t reverse = start_reversed; + int32_t pos = view.cursor.pos; + int32_t start_pos = pos; + int32_t first_pos = pos; Range match = make_range(pos, pos); char bar_string_space[256]; @@ -645,16 +642,16 @@ isearch(Application_Links *app, bool32 start_reversed){ } if (in.key.keycode != key_back){ - char *str = bar.string.str; - size_t str_size = bar.string.size; - size_t new_pos = 0; + int32_t new_pos; if (reverse){ - buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1, 0, str, str_size, &new_pos); + buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1, 0, + bar.string.str, bar.string.size, &new_pos); if (new_pos >= 0){ if (step_backward){ pos = new_pos; start_pos = new_pos; - buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1, 0, str, str_size, &new_pos); + buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1, 0, + bar.string.str, bar.string.size, &new_pos); if (new_pos < 0) new_pos = start_pos; } match.start = new_pos; @@ -662,13 +659,14 @@ isearch(Application_Links *app, bool32 start_reversed){ } } else{ - buffer_seek_string_insensitive_forward(app, &buffer, start_pos + 1, 0, str, str_size, &new_pos); + buffer_seek_string_insensitive_forward(app, &buffer, start_pos + 1, 0, + bar.string.str, bar.string.size, &new_pos); if (new_pos < buffer.size){ if (step_forward){ pos = new_pos; start_pos = new_pos; buffer_seek_string_insensitive_forward(app, &buffer, start_pos + 1, 0, - str, str_size, &new_pos); + bar.string.str, bar.string.size, &new_pos); if (new_pos >= buffer.size) new_pos = start_pos; } match.start = new_pos; @@ -723,8 +721,9 @@ CUSTOM_COMMAND_SIG(replace_in_range){ Range range = get_range(&view); - size_t pos = range.min; - size_t new_pos = 0; + int32_t pos, new_pos; + pos = range.min; + buffer_seek_string_forward(app, &buffer, pos, 0, r.str, r.size, &new_pos); while (new_pos + r.size <= range.end){ @@ -752,21 +751,25 @@ CUSTOM_COMMAND_SIG(query_replace){ if (!query_user_string(app, &with)) return; - String r = replace.string; - String w = with.string; + String r, w; + r = replace.string; + w = with.string; Query_Bar bar; + Buffer_Summary buffer; + View_Summary view; + int32_t pos, new_pos; + bar.prompt = make_lit_string("Replace? (y)es, (n)ext, (esc)\n"); bar.string = null_string; start_query_bar(app, &bar, 0); uint32_t access = AccessOpen; - View_Summary view = get_active_view(app, access); - Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); + view = get_active_view(app, access); + buffer = get_buffer(app, view.buffer_id, access); - size_t pos = view.cursor.pos; - size_t new_pos = 0; + pos = view.cursor.pos; buffer_seek_string_forward(app, &buffer, pos, 0, r.str, r.size, &new_pos); User_Input in = {0}; diff --git a/4coder_clipboard.cpp b/4coder_clipboard.cpp index b0dfbf6a..56e13c01 100644 --- a/4coder_clipboard.cpp +++ b/4coder_clipboard.cpp @@ -14,14 +14,14 @@ TYPE: 'drop-in-command-pack' #include "4coder_helper/4coder_helper.h" static bool32 -clipboard_copy(Application_Links *app, size_t start, size_t end, Buffer_Summary *buffer_out, uint32_t access){ +clipboard_copy(Application_Links *app, int32_t start, int32_t end, Buffer_Summary *buffer_out, uint32_t access){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); bool32 result = 0; if (buffer.exists){ if (0 <= start && start <= end && end <= buffer.size){ - size_t size = (end - start); + int32_t size = (end - start); char *str = (char*)app->memory; if (size <= app->memory_size){ @@ -36,16 +36,14 @@ clipboard_copy(Application_Links *app, size_t start, size_t end, Buffer_Summary return(result); } -static bool32 -clipboard_cut(Application_Links *app, size_t start, size_t end, Buffer_Summary *buffer_out, uint32_t access){ +static int32_t +clipboard_cut(Application_Links *app, int32_t start, int32_t end, Buffer_Summary *buffer_out, uint32_t access){ Buffer_Summary buffer = {0}; - bool32 result = false; + int32_t result = false; if (clipboard_copy(app, start, end, &buffer, access)){ buffer_replace_range(app, &buffer, start, end, 0, 0); - if (buffer_out){ - *buffer_out = buffer; - } + if (buffer_out){*buffer_out = buffer;} } return(result); @@ -76,7 +74,7 @@ CUSTOM_COMMAND_SIG(paste){ int32_t paste_index = 0; view_paste_index[view.view_id].index = paste_index; - size_t len = clipboard_index(app, 0, paste_index, 0, 0); + int32_t len = clipboard_index(app, 0, paste_index, 0, 0); char *str = 0; if (len <= app->memory_size){ @@ -87,7 +85,7 @@ CUSTOM_COMMAND_SIG(paste){ clipboard_index(app, 0, paste_index, str, len); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos = view.cursor.pos; + int32_t pos = view.cursor.pos; buffer_replace_range(app, &buffer, pos, pos, str, len); view_set_mark(app, &view, seek_pos(pos)); view_set_cursor(app, &view, seek_pos(pos + len), true); @@ -113,7 +111,7 @@ CUSTOM_COMMAND_SIG(paste_next){ int32_t paste_index = view_paste_index[view.view_id].index + 1; view_paste_index[view.view_id].index = paste_index; - size_t len = clipboard_index(app, 0, paste_index, 0, 0); + int32_t len = clipboard_index(app, 0, paste_index, 0, 0); char *str = 0; if (len <= app->memory_size){ @@ -125,7 +123,7 @@ CUSTOM_COMMAND_SIG(paste_next){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); Range range = get_range(&view); - size_t pos = range.min; + int32_t pos = range.min; buffer_replace_range(app, &buffer, range.min, range.max, str, len); view_set_cursor(app, &view, seek_pos(pos + len), true); diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 28e17112..45a9aaa7 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -42,9 +42,9 @@ TYPE: 'major-system-include' // Seeks Using Default Framework Memory // -static size_t -buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags){ - size_t result = buffer_boundary_seek(app, buffer, &global_part, start_pos, seek_forward, flags); +static int32_t +buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags){ + int32_t result = buffer_boundary_seek(app, buffer, &global_part, start_pos, seek_forward, flags); return(result); } @@ -53,7 +53,7 @@ basic_seek(Application_Links *app, int32_t seek_type, uint32_t flags){ uint32_t access = AccessProtected; View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos = buffer_boundary_seek(app, &buffer, view.cursor.pos, seek_type, flags); + int32_t pos = buffer_boundary_seek(app, &buffer, view.cursor.pos, seek_type, flags); view_set_cursor(app, &view, seek_pos(pos), true); } @@ -85,10 +85,12 @@ CUSTOM_COMMAND_SIG(backspace_word){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); if (buffer.exists){ - size_t pos2 = view.cursor.pos; + int32_t pos2 = 0, pos1 = 0; + + pos2 = view.cursor.pos; exec_command(app, seek_alphanumeric_left); refresh_view(app, &view); - size_t pos1 = view.cursor.pos; + pos1 = view.cursor.pos; buffer_replace_range(app, &buffer, pos1, pos2, 0, 0); } @@ -101,10 +103,12 @@ CUSTOM_COMMAND_SIG(delete_word){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); if (buffer.exists){ - size_t pos1 = view.cursor.pos; + int32_t pos2 = 0, pos1 = 0; + + pos1 = view.cursor.pos; exec_command(app, seek_alphanumeric_right); refresh_view(app, &view); - size_t pos2 = view.cursor.pos; + pos2 = view.cursor.pos; buffer_replace_range(app, &buffer, pos1, pos2, 0, 0); } @@ -112,11 +116,12 @@ CUSTOM_COMMAND_SIG(delete_word){ CUSTOM_COMMAND_SIG(snipe_token_or_word){ uint32_t access = AccessOpen; + View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos1 = buffer_boundary_seek(app, &buffer, view.cursor.pos, 0, BoundaryToken | BoundaryWhitespace); - size_t pos2 = buffer_boundary_seek(app, &buffer, pos1, 1, BoundaryToken | BoundaryWhitespace); + int32_t pos1 = buffer_boundary_seek(app, &buffer, view.cursor.pos, 0, BoundaryToken | BoundaryWhitespace); + int32_t pos2 = buffer_boundary_seek(app, &buffer, pos1, 1, BoundaryToken | BoundaryWhitespace); Range range = make_range(pos1, pos2); buffer_replace_range(app, &buffer, range.start, range.end, 0, 0); @@ -141,7 +146,7 @@ CUSTOM_COMMAND_SIG(duplicate_line){ ++line_string.memory_size; append_s_char(&line_string, '\n'); - size_t pos = buffer_get_line_end(app, &buffer, view.cursor.line) + 1; + int32_t pos = buffer_get_line_end(app, &buffer, view.cursor.line) + 1; buffer_replace_range(app, &buffer, pos, pos, line_string.str, line_string.size); end_temp_memory(temp); @@ -154,8 +159,8 @@ CUSTOM_COMMAND_SIG(delete_line){ Partition *part = &global_part; Temp_Memory temp = begin_temp_memory(part); - size_t start = buffer_get_line_start(app, &buffer, view.cursor.line); - size_t end = buffer_get_line_end(app, &buffer, view.cursor.line) + 1; + int32_t start = buffer_get_line_start(app, &buffer, view.cursor.line); + int32_t end = buffer_get_line_end(app, &buffer, view.cursor.line) + 1; buffer_replace_range(app, &buffer, start, end, 0, 0); @@ -201,7 +206,7 @@ long_braces(Application_Links *app, char *text, int32_t size){ uint32_t access = AccessOpen; View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t pos = view.cursor.pos; + int32_t pos = view.cursor.pos; buffer_replace_range(app, &buffer, pos, pos, text, size); view_set_cursor(app, &view, seek_pos(pos + 2), true); @@ -333,13 +338,13 @@ file_name_in_quotes(Application_Links *app, String *file_name){ Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); if (buffer.file_name != 0){ - size_t pos = view.cursor.pos; - size_t start = 0, end = 0; + int32_t pos = view.cursor.pos; + int32_t start = 0, end = 0; buffer_seek_delimiter_forward(app, &buffer, pos, '"', &end); buffer_seek_delimiter_backward(app, &buffer, pos, '"', &start); ++start; - size_t size = end - start; + int32_t size = end - start; char short_file_name[128]; // NOTE(allen): This check is necessary because buffer_read_range @@ -349,7 +354,7 @@ file_name_in_quotes(Application_Links *app, String *file_name){ result = true; copy_ss(file_name, make_string(buffer.file_name, buffer.file_name_len)); remove_last_folder(file_name); - append_ss(file_name, make_string(short_file_name, (int32_t)size)); + append_ss(file_name, make_string(short_file_name, size)); } } } diff --git a/4coder_function_list.cpp b/4coder_function_list.cpp index d617723c..96558c9f 100644 --- a/4coder_function_list.cpp +++ b/4coder_function_list.cpp @@ -245,8 +245,8 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff size_t sig_size = extra_memory->pos; String sig = make_string(extra_memory->base, (int32_t)sig_size); - size_t line_number = buffer_get_line_index(app, buffer, open_paren_pos); - size_t line_number_len = int_to_str_size((int32_t)line_number); + int32_t line_number = buffer_get_line_index(app, buffer, open_paren_pos); + int32_t line_number_len = int_to_str_size(line_number); size_t append_len = buffer_name.size + 1 + line_number_len + 1 + 1 + sig_size + 1; @@ -266,7 +266,7 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff String out = make_string(out_space, 0, (int32_t)append_len); append(&out, buffer_name); append(&out, ':'); - append_int_to_str(&out, (int32_t)line_number); + append_int_to_str(&out, line_number); append(&out, ':'); append(&out, ' '); append(&out, sig); diff --git a/4coder_helper/4coder_helper.h b/4coder_helper/4coder_helper.h index 7fb8cd15..18abfde8 100644 --- a/4coder_helper/4coder_helper.h +++ b/4coder_helper/4coder_helper.h @@ -148,7 +148,7 @@ query_user_number(Application_Links *app, Query_Bar *bar){ } static char -buffer_get_char(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +buffer_get_char(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char result = ' '; *buffer = get_buffer(app, buffer->buffer_id, AccessAll); if (pos < buffer->size){ @@ -188,7 +188,7 @@ create_buffer(Application_Links *app, char *filename, int32_t filename_len, Buff } static Range -make_range(size_t p1, size_t p2){ +make_range(int32_t p1, int32_t p2){ Range range; if (p1 < p2){ range.min = p1; @@ -267,10 +267,10 @@ get_line_x_rect(View_Summary *view){ rect.y1 = view->cursor.line; if (rect.y0 > rect.y1){ - Swap(size_t, rect.y0, rect.y1); + Swap(int32_t, rect.y0, rect.y1); } if (rect.x0 > rect.x1){ - Swap(size_t, rect.x0, rect.x1); + Swap(int32_t, rect.x0, rect.x1); } return(rect); diff --git a/4coder_helper/4coder_jump_parsing.h b/4coder_helper/4coder_jump_parsing.h index d37de476..85d80933 100644 --- a/4coder_helper/4coder_jump_parsing.h +++ b/4coder_helper/4coder_jump_parsing.h @@ -41,20 +41,20 @@ ms_style_verify(String line, int32_t paren_pos){ } static int32_t -parse_jump_location(String line, Name_Based_Jump_Location *location, int32_t skip_sub_errors, size_t *colon_char){ - bool32 result = false; +parse_jump_location(String line, Name_Based_Jump_Location *location, int32_t skip_sub_errors, int32_t *colon_char){ + int32_t result = false; int32_t whitespace_length = 0; String original_line = line; line = skip_chop_whitespace(line, &whitespace_length); int32_t colon_pos = 0; - bool32 is_ms_style = false; + int32_t is_ms_style = 0; int32_t paren_pos = find_s_char(line, 0, ')'); while (!is_ms_style && paren_pos < line.size){ if (ms_style_verify(line, paren_pos)){ - is_ms_style = true; + is_ms_style = 1; colon_pos = find_s_char(line, paren_pos, ':'); if (colon_pos < line.size){ String location_str = substr(line, 0, colon_pos); @@ -152,14 +152,14 @@ parse_jump_location(String line, Name_Based_Jump_Location *location, int32_t ski return(result); } -static bool32 -parse_jump_from_buffer_line(Application_Links *app, Partition *part, int32_t buffer_id, size_t line, int32_t skip_sub_errors, Name_Based_Jump_Location *location){ +static int32_t +parse_jump_from_buffer_line(Application_Links *app, Partition *part, int32_t buffer_id, int32_t line, int32_t skip_sub_errors, Name_Based_Jump_Location *location){ - bool32 result = false; + int32_t result = false; String line_str = {0}; Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll); if (read_line(app, part, &buffer, line, &line_str)){ - size_t colon_char = 0; + int32_t colon_char = 0; if (parse_jump_location(line_str, location, skip_sub_errors, &colon_char)){ result = true; } diff --git a/4coder_helper/4coder_long_seek.h b/4coder_helper/4coder_long_seek.h index 831334e7..2b539db7 100644 --- a/4coder_helper/4coder_long_seek.h +++ b/4coder_helper/4coder_long_seek.h @@ -15,17 +15,20 @@ // Whitespace Based Seeks // -static size_t -seek_line_end(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +seek_line_end(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char chunk[1024]; - size_t chunk_size = sizeof(chunk); + int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; + int32_t still_looping; + char at_pos; + if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ - bool32 still_looping = true; + still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ - char at_pos = stream.data[pos]; + for (; pos < stream.end; ++pos){ + at_pos = stream.data[pos]; if (at_pos == '\n'){ goto double_break; } @@ -42,18 +45,21 @@ seek_line_end(Application_Links *app, Buffer_Summary *buffer, size_t pos){ return(pos); } -static size_t -seek_line_beginning(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +seek_line_beginning(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char chunk[1024]; - size_t chunk_size = sizeof(chunk); + int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; + int32_t still_looping; + char at_pos; + --pos; if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ - bool32 still_looping = false; + still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ - char at_pos = stream.data[pos]; + for (; pos >= stream.start; --pos){ + at_pos = stream.data[pos]; if (at_pos == '\n'){ goto double_break; } @@ -77,15 +83,15 @@ static void move_past_lead_whitespace(Application_Links *app, View_Summary *view, Buffer_Summary *buffer){ refresh_view(app, view); + int32_t new_pos = seek_line_beginning(app, buffer, view->cursor.pos); char space[1024]; Stream_Chunk chunk = {0}; + int32_t still_looping = false; - size_t new_pos = seek_line_beginning(app, buffer, view->cursor.pos); - size_t i = new_pos; + int32_t i = new_pos; if (init_stream_chunk(&chunk, app, buffer, i, space, sizeof(space))){ - bool32 still_looping = false; do{ - for (; i < (size_t)chunk.end; ++i){ + for (; i < chunk.end; ++i){ char at_pos = chunk.data[i]; if (at_pos == '\n' || !char_is_whitespace(at_pos)){ goto break2; @@ -101,20 +107,22 @@ move_past_lead_whitespace(Application_Links *app, View_Summary *view, Buffer_Sum } } -static size_t -buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char chunk[1024]; - size_t chunk_size = sizeof(chunk); + int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; + char at_pos; + --pos; if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ // Step 1: Find the first non-whitespace character // behind the current position. - bool32 still_looping = true; + int32_t still_looping = 1; while (still_looping){ - for (; pos >= (size_t)stream.start; --pos){ - char at_pos = stream.data[pos]; + for (; pos >= stream.start; --pos){ + at_pos = stream.data[pos]; if (!char_is_whitespace(at_pos)){ goto double_break_1; } @@ -130,8 +138,8 @@ buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, size_t // the next '\n' int32_t no_hard = false; while (still_looping){ - for (; pos >= (size_t)stream.start; --pos){ - char at_pos = stream.data[pos]; + for (; pos >= stream.start; --pos){ + at_pos = stream.data[pos]; if (at_pos == '\n'){ if (no_hard){ goto double_break_2; @@ -156,19 +164,24 @@ buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, size_t return(pos); } -static size_t -buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char chunk[1024]; - size_t chunk_size = sizeof(chunk); + int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; + int32_t no_hard; + int32_t prev_endline; + int32_t still_looping; + char at_pos; + if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ // step 1: find the first non-whitespace character // ahead of the current position. - bool32 still_looping = true; + still_looping = true; do{ - for (; pos < (size_t)stream.end; ++pos){ - char at_pos = stream.data[pos]; + for (; pos < stream.end; ++pos){ + at_pos = stream.data[pos]; if (!char_is_whitespace(at_pos)){ goto double_break_1; } @@ -182,12 +195,11 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, size // the prev_endline value. if another '\n' is found // with non-whitespace then the previous line was // all whitespace. - bool32 no_hard = false; - bool32 was_at_end = true; - size_t prev_endline = 0; + no_hard = false; + prev_endline = -1; while(still_looping){ - for (; pos < (size_t)stream.end; ++pos){ - char at_pos = stream.data[pos]; + for (; pos < stream.end; ++pos){ + at_pos = stream.data[pos]; if (at_pos == '\n'){ if (no_hard){ goto double_break_2; @@ -195,7 +207,6 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, size else{ no_hard = true; prev_endline = pos; - was_at_end = false; } } else if (!char_is_whitespace(at_pos)){ @@ -206,7 +217,7 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, size } double_break_2:; - if (was_at_end || prev_endline+1 >= buffer->size){ + if (prev_endline == -1 || prev_endline+1 >= buffer->size){ pos = buffer->size; } else{ @@ -216,8 +227,8 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, size return(pos); } -static size_t -buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -226,7 +237,7 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, siz bool32 still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < stream.end; ++pos){ if (!char_is_whitespace(stream.data[pos])){ goto double_break1; } @@ -237,7 +248,7 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, siz still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < stream.end; ++pos){ if (char_is_whitespace(stream.data[pos])){ goto double_break2; } @@ -250,8 +261,8 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, siz return(pos); } -static size_t -buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -262,7 +273,7 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, size bool32 still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= stream.start; --pos){ if (!char_is_whitespace(stream.data[pos])){ goto double_break1; } @@ -273,7 +284,7 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, size still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= stream.start; --pos){ if (char_is_whitespace(stream.data[pos])){ ++pos; goto double_break2; @@ -295,8 +306,8 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, size // Boundary Type Seeks // -static size_t -buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -305,7 +316,7 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, s bool32 still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < stream.end; ++pos){ if (char_is_alpha_numeric_true(stream.data[pos])){ goto double_break1; } @@ -316,7 +327,7 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, s still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < stream.end; ++pos){ if (!char_is_alpha_numeric_true(stream.data[pos])){ goto double_break2; } @@ -329,8 +340,8 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, s return(pos); } -static size_t -buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -341,7 +352,7 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, si bool32 still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= stream.start; --pos){ if (char_is_alpha_numeric_true(stream.data[pos])){ goto double_break1; } @@ -352,7 +363,7 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, si still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= stream.start; --pos){ if (!char_is_alpha_numeric_true(stream.data[pos])){ ++pos; goto double_break2; @@ -370,8 +381,8 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, si return(pos); } -static size_t -buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t an_pos){ +static int32_t +buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t an_pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -386,7 +397,7 @@ buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, si bool32 still_looping = 1; do{ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < stream.end; ++pos){ c = stream.data[pos]; if (char_is_upper(c) && char_is_lower(pc)){ goto double_break1; @@ -405,8 +416,8 @@ buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, si return(pos); } -static size_t -buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t an_pos){ +static int32_t +buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t an_pos){ char data_chunk[1024]; Stream_Chunk stream = {0}; @@ -419,7 +430,7 @@ buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, siz bool32 still_looping = 1; do{ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= stream.start; --pos){ c = stream.data[pos]; if (char_is_upper(c) && char_is_lower(pc)){ goto double_break1; @@ -438,22 +449,22 @@ buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, siz return(pos); } -static size_t -buffer_seek_alphanumeric_or_camel_right(Application_Links *app, Buffer_Summary *buffer, size_t pos){ - size_t an_pos = buffer_seek_alphanumeric_right(app, buffer, pos); - size_t result = buffer_seek_range_camel_right(app, buffer, pos, an_pos); +static int32_t +buffer_seek_alphanumeric_or_camel_right(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ + int32_t an_pos = buffer_seek_alphanumeric_right(app, buffer, pos); + int32_t result = buffer_seek_range_camel_right(app, buffer, pos, an_pos); return(result); } -static size_t -buffer_seek_alphanumeric_or_camel_left(Application_Links *app, Buffer_Summary *buffer, size_t pos){ - size_t an_pos = buffer_seek_alphanumeric_left(app, buffer, pos); - size_t result = buffer_seek_range_camel_left(app, buffer, pos, an_pos); +static int32_t +buffer_seek_alphanumeric_or_camel_left(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ + int32_t an_pos = buffer_seek_alphanumeric_left(app, buffer, pos); + int32_t result = buffer_seek_range_camel_left(app, buffer, pos, an_pos); return(result); } -static size_t -seek_token_left(Cpp_Token_Array *tokens, size_t pos){ +static int32_t +seek_token_left(Cpp_Token_Array *tokens, uint32_t pos){ Cpp_Get_Token_Result get = cpp_get_token(*tokens, pos); if (get.token_index == -1){ get.token_index = 0; @@ -467,8 +478,8 @@ seek_token_left(Cpp_Token_Array *tokens, size_t pos){ return(token->start); } -static size_t -seek_token_right(Cpp_Token_Array *tokens, size_t pos){ +static int32_t +seek_token_right(Cpp_Token_Array *tokens, uint32_t pos){ Cpp_Get_Token_Result get = cpp_get_token(*tokens, pos); if (get.in_whitespace){ ++get.token_index; @@ -497,26 +508,28 @@ buffer_get_all_tokens(Application_Links *app, Partition *part, Buffer_Summary *b return(array); } -static size_t -buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Partition *part, size_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags)/* +static int32_t +buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Partition *part, int32_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags)/* DOC_PARAM(buffer, The buffer parameter specifies the buffer through which to seek.) DOC_PARAM(start_pos, The beginning position of the seek is specified by start_pos measured in absolute position.) DOC_PARAM(seek_forward, If this parameter is non-zero it indicates that the seek should move foward through the buffer.) DOC_PARAM(flags, This field specifies the types of boundaries at which the seek should stop.) -DOC_RETURN(This call returns the absolute position where the seek stopped. If the seek goes below 0 the returned value is -1. If the seek goes past the end the returned value is the size of the buffer.) +DOC_RETURN(This call returns the absolute position where the seek stopped. +If the seek goes below 0 the returned value is -1. +If the seek goes past the end the returned value is the size of the buffer.) DOC_SEE(Seek_Boundary_Flag) DOC_SEE(4coder_Buffer_Positioning_System) */{ - size_t result = 0; + int32_t result = 0; // TODO(allen): reduce duplication? Temp_Memory temp = begin_temp_memory(part); if (buffer->exists){ - size_t pos[4]; - size_t size = buffer->size; - size_t new_pos = 0; + int32_t pos[4]; + int32_t size = buffer->size; + int32_t new_pos = 0; if (start_pos < 0){ start_pos = 0; @@ -612,8 +625,8 @@ DOC_SEE(4coder_Buffer_Positioning_System) // Character Seeks // -static void -buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, size_t pos, char delim, size_t *result){ +void +buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, char delim, int32_t *result){ if (buffer->exists){ char chunk[1024]; int32_t size = sizeof(chunk); @@ -622,7 +635,7 @@ buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, si if (init_stream_chunk(&stream, app, buffer, pos, chunk, size)){ int32_t still_looping = 1; do{ - for(; pos < (size_t)stream.end; ++pos){ + for(; pos < stream.end; ++pos){ char at_pos = stream.data[pos]; if (at_pos == delim){ *result = pos; @@ -640,7 +653,7 @@ buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, si } static void -buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, size_t pos, char delim, size_t *result){ +buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, char delim, int32_t *result){ if (buffer->exists){ char chunk[1024]; int32_t size = sizeof(chunk); @@ -649,7 +662,7 @@ buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, s if (init_stream_chunk(&stream, app, buffer, pos, chunk, size)){ int32_t still_looping = 1; do{ - for(; pos >= (size_t)stream.start; --pos){ + for(; pos >= stream.start; --pos){ char at_pos = stream.data[pos]; if (at_pos == delim){ *result = pos; @@ -677,7 +690,7 @@ buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, s // You can push it up or do something more clever by just // replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t end, char *str, size_t size, size_t *result){ +buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t end, char *str, int32_t size, int32_t *result){ char read_buffer[512]; if (buffer->size > end){ @@ -690,19 +703,19 @@ buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, size_ if (size > 0 && size <= sizeof(read_buffer)){ if (buffer->exists){ String read_str = make_fixed_width_string(read_buffer); - String needle_str = make_string(str, (int32_t)size); + String needle_str = make_string(str, size); char first_char = str[0]; - read_str.size = (int32_t)size; + read_str.size = size; char chunk[1024]; Stream_Chunk stream = {0}; stream.max_end = end; if (init_stream_chunk(&stream, app, buffer, pos, chunk, sizeof(chunk))){ - bool32 still_looping = 1; + int32_t still_looping = 1; do{ - for(; pos < (size_t)stream.end; ++pos){ + for(; pos < stream.end; ++pos){ char at_pos = stream.data[pos]; if (at_pos == first_char){ buffer_read_range(app, buffer, pos, pos+size, read_buffer); @@ -732,17 +745,17 @@ buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, size_ // You can push it up or do something more clever by just // replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t min, char *str, size_t size, size_t *result){ +buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t min, char *str, int32_t size, int32_t *result){ char read_buffer[512]; *result = min-1; if (size > 0 && size <= sizeof(read_buffer)){ if (buffer->exists){ String read_str = make_fixed_width_string(read_buffer); - String needle_str = make_string(str, (int32_t)size); + String needle_str = make_string(str, size); char first_char = str[0]; - read_str.size = (int32_t)size; + read_str.size = size; char chunk[1024]; Stream_Chunk stream = {0}; @@ -751,7 +764,7 @@ buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, size if (init_stream_chunk(&stream, app, buffer, pos, chunk, sizeof(chunk))){ int32_t still_looping = 1; do{ - for(; pos >= (size_t)stream.start; --pos){ + for(; pos >= stream.start; --pos){ char at_pos = stream.data[pos]; if (at_pos == first_char){ buffer_read_range(app, buffer, pos, pos+size, read_buffer); @@ -774,7 +787,7 @@ buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, size // You can push it up or do something more clever by just // replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t end, char *str, size_t size, size_t *result){ +buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t end, char *str, int32_t size, int32_t *result){ char read_buffer[512]; char chunk[1024]; int32_t chunk_size = sizeof(chunk); @@ -788,29 +801,32 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *b *result = end; } - if (size > 0 && size <= sizeof(read_buffer) && buffer->exists){ - String read_str = make_fixed_width_string(read_buffer); - String needle_str = make_string(str, (int32_t)size); - char first_char = char_to_upper(str[0]); - - read_str.size = (int32_t)size; - - if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ - bool32 still_looping = true; - do{ - for(; pos < (size_t)stream.end; ++pos){ - char at_pos = char_to_upper(stream.data[pos]); - if (at_pos == first_char){ - buffer_read_range(app, buffer, pos, pos+size, read_buffer); - if (match_insensitive_ss(needle_str, read_str)){ - *result = pos; - goto finished; + if (size > 0 && size <= sizeof(read_buffer)){ + if (buffer->exists){ + String read_str = make_fixed_width_string(read_buffer); + String needle_str = make_string(str, size); + char first_char = char_to_upper(str[0]); + + read_str.size = size; + + if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ + int32_t still_looping = 1; + do{ + for(; pos < stream.end; ++pos){ + char at_pos = char_to_upper(stream.data[pos]); + if (at_pos == first_char){ + buffer_read_range(app, buffer, pos, pos+size, read_buffer); + if (match_insensitive_ss(needle_str, read_str)){ + *result = pos; + goto finished; + } } } - } - still_looping = forward_stream_chunk(&stream); - }while (still_looping); + still_looping = forward_stream_chunk(&stream); + }while (still_looping); + } } + finished:; } } @@ -819,7 +835,7 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *b // You can push it up or do something more clever by just // replacing char read_buffer[512]; with more memory. static void -buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t min, char *str, size_t size, size_t *result){ +buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t min, char *str, int32_t size, int32_t *result){ char read_buffer[512]; char chunk[1024]; int32_t chunk_size = sizeof(chunk); @@ -827,29 +843,32 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary * stream.min_start = min; *result = min-1; - if (size > 0 && size <= sizeof(read_buffer) && buffer->exists){ - String read_str = make_fixed_width_string(read_buffer); - String needle_str = make_string(str, (int32_t)size); - char first_char = char_to_upper(str[0]); - - read_str.size = (int32_t)size; - - if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ - int32_t still_looping = 1; - do{ - for(; pos >= (size_t)stream.start; --pos){ - char at_pos = char_to_upper(stream.data[pos]); - if (at_pos == first_char){ - buffer_read_range(app, buffer, pos, pos+size, read_buffer); - if (match_insensitive_ss(needle_str, read_str)){ - *result = pos; - goto finished; + if (size > 0 && size <= sizeof(read_buffer)){ + if (buffer->exists){ + String read_str = make_fixed_width_string(read_buffer); + String needle_str = make_string(str, size); + char first_char = char_to_upper(str[0]); + + read_str.size = size; + + if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){ + int32_t still_looping = 1; + do{ + for(; pos >= stream.start; --pos){ + char at_pos = char_to_upper(stream.data[pos]); + if (at_pos == first_char){ + buffer_read_range(app, buffer, pos, pos+size, read_buffer); + if (match_insensitive_ss(needle_str, read_str)){ + *result = pos; + goto finished; + } } } - } - still_looping = backward_stream_chunk(&stream); - }while (still_looping); + still_looping = backward_stream_chunk(&stream); + }while (still_looping); + } } + finished:; } } @@ -859,25 +878,23 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary * // Buffer Line Positioning // -static bool32 -read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line, String *str){ - bool32 success = false; - - Buffer_Seek seek_begin = seek_line_char(line, 1); - Buffer_Seek seek_end = seek_line_reverse_char(line, 1); +static int32_t +read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line, String *str){ Partial_Cursor begin = {0}; Partial_Cursor end = {0}; - if (buffer_compute_cursor(app, buffer, seek_begin, &begin)){ - if (begin.line == line){ - if (buffer_compute_cursor(app, buffer, seek_end, &end)){ + int32_t success = 0; + + if (buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &begin)){ + if (buffer_compute_cursor(app, buffer, seek_line_char(line, -1), &end)){ + if (begin.line == line){ if (0 <= begin.pos && begin.pos <= end.pos && end.pos <= buffer->size){ - size_t size = (end.pos - begin.pos); - *str = make_string(push_array(part, char, size+1), (int32_t)(size+1)); + int32_t size = (end.pos - begin.pos); + *str = make_string(push_array(part, char, size+1), size+1); if (str->str){ - success = true; + success = 1; buffer_read_range(app, buffer, begin.pos, end.pos, str->str); - str->size = (int32_t)size; + str->size = size; terminate_with_null(str); } } @@ -888,10 +905,10 @@ read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_ return(success); } -static size_t -buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, size_t line){ +static int32_t +buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, int32_t line){ Partial_Cursor partial_cursor; - size_t result = buffer->size; + int32_t result = buffer->size; if (line <= buffer->line_count){ buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &partial_cursor); result = partial_cursor.pos; @@ -899,39 +916,36 @@ buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, size_t lin return(result); } -static size_t -buffer_get_line_end(Application_Links *app, Buffer_Summary *buffer, size_t line){ +static int32_t +buffer_get_line_end(Application_Links *app, Buffer_Summary *buffer, int32_t line){ Partial_Cursor partial_cursor; - size_t result = buffer->size; + int32_t result = buffer->size; if (line <= buffer->line_count){ - buffer_compute_cursor(app, buffer, seek_line_reverse_char(line, 1), &partial_cursor); + buffer_compute_cursor(app, buffer, seek_line_char(line, -1), &partial_cursor); result = partial_cursor.pos; } return(result); } static bool32 -buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, size_t line){ +buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, int32_t line){ Partial_Cursor start, end; bool32 result = 0; if (line <= buffer->line_count){ - Buffer_Seek seek_start = seek_line_char(line, 1); - Buffer_Seek seek_end = seek_line_reverse_char(line, 1); + buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &start); + buffer_compute_cursor(app, buffer, seek_line_char(line, -1), &end); - buffer_compute_cursor(app, buffer, seek_start, &start); - buffer_compute_cursor(app, buffer, seek_end, &end); - - static const size_t chunk_size = 1024; + static const int32_t chunk_size = 1024; char chunk[chunk_size]; Stream_Chunk stream = {0}; - size_t i = start.pos; + int32_t i = start.pos; stream.max_end = end.pos; result = true; if (init_stream_chunk(&stream, app, buffer, i, chunk, chunk_size)){ bool32 still_looping = false; do{ - for (;i < (size_t)stream.end; ++i){ + for (;i < stream.end; ++i){ char c = stream.data[i]; if (!(c == ' ' || c == '\t' || c == '\r' || c == '\v' || c == '\n')){ result = false; @@ -946,16 +960,16 @@ buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, size_t line return(result); } -static size_t -buffer_get_line_index(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_get_line_index(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ Partial_Cursor partial_cursor; buffer_compute_cursor(app, buffer, seek_pos(pos), &partial_cursor); return(partial_cursor.line); } static Cpp_Token* -get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, size_t line, size_t *line_start_out = 0){ - size_t line_start = buffer_get_line_start(app, buffer, line); +get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line, uint32_t *line_start_out = 0){ + int32_t line_start = buffer_get_line_start(app, buffer, line); Cpp_Get_Token_Result get = cpp_get_token(tokens, line_start); if (get.in_whitespace){ @@ -963,7 +977,7 @@ get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Toke } uint32_t target_token_index = (uint32_t)(get.token_index); - if (line_start_out != 0){ + if (line_start_out){ *line_start_out = line_start; } diff --git a/4coder_helper/4coder_seek_types.h b/4coder_helper/4coder_seek_types.h index 2d2e8a58..849e3d77 100644 --- a/4coder_helper/4coder_seek_types.h +++ b/4coder_helper/4coder_seek_types.h @@ -67,15 +67,6 @@ seek_line_char(size_t line, size_t character){ return(result); } -static Buffer_Seek -seek_line_reverse_char(size_t line, size_t character){ - Buffer_Seek result; - result.type = buffer_seek_line_reverse_char; - result.line = line; - result.character = character; - return(result); -} - #endif // BOTTOM diff --git a/4coder_helper/4coder_streaming.h b/4coder_helper/4coder_streaming.h index 3317d13e..ac3bc849 100644 --- a/4coder_helper/4coder_streaming.h +++ b/4coder_helper/4coder_streaming.h @@ -9,32 +9,31 @@ #include "4coder_helper/4coder_helper.h" -// TODO(allen): Rewrite the backward seek to get this on size_t instead of int64_t. struct Stream_Chunk{ Application_Links *app; Buffer_Summary *buffer; char *base_data; - int64_t start, end; - int64_t min_start, max_end; - int64_t data_size; + int32_t start, end; + int32_t min_start, max_end; bool32 add_null; + uint32_t data_size; char *data; }; -static uint64_t -round_down(uint64_t x, uint64_t b){ - uint64_t r = 0; +static int32_t +round_down(int32_t x, int32_t b){ + int32_t r = 0; if (x >= 0){ r = x - (x % b); } return(r); } -static uint64_t -round_up(uint64_t x, uint64_t b){ - uint64_t r = 0; +static int32_t +round_up(int32_t x, int32_t b){ + int32_t r = 0; if (x >= 0){ r = x - (x % b) + b; } @@ -42,7 +41,8 @@ round_up(uint64_t x, uint64_t b){ } static bool32 -init_stream_chunk(Stream_Chunk *chunk, Application_Links *app, Buffer_Summary *buffer, size_t pos, char *data, size_t size){ +init_stream_chunk(Stream_Chunk *chunk, Application_Links *app, Buffer_Summary *buffer, + int32_t pos, char *data, uint32_t size){ bool32 result = 0; refresh_buffer(app, buffer); @@ -153,12 +153,12 @@ struct Stream_Tokens{ Cpp_Token *base_tokens; Cpp_Token *tokens; - int64_t start, end; - int64_t count, token_count; + int32_t start, end; + int32_t count, token_count; }; static bool32 -init_stream_tokens(Stream_Tokens *stream, Application_Links *app, Buffer_Summary *buffer, size_t pos, Cpp_Token *data, size_t count){ +init_stream_tokens(Stream_Tokens *stream, Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Token *data, int32_t count){ bool32 result = 0; refresh_buffer(app, buffer); @@ -168,9 +168,9 @@ init_stream_tokens(Stream_Tokens *stream, Application_Links *app, Buffer_Summary stream->app = app; stream->buffer = buffer; stream->base_tokens = data; - stream->count = (int64_t)count; - stream->start = (int64_t)round_down(pos, count); - stream->end = (int64_t)round_up(pos, count); + stream->count = count; + stream->start = round_down(pos, count); + stream->end = round_up(pos, count); stream->token_count = token_count; if (stream->start < 0){ diff --git a/4coder_jump_parsing.cpp b/4coder_jump_parsing.cpp index 3071c786..c2248760 100644 --- a/4coder_jump_parsing.cpp +++ b/4coder_jump_parsing.cpp @@ -22,7 +22,10 @@ CUSTOM_COMMAND_SIG(goto_jump_at_cursor){ View_Summary view = get_active_view(app, AccessProtected); Name_Based_Jump_Location location = {0}; - if (parse_jump_from_buffer_line(app, &global_part, view.buffer_id, view.cursor.line, false, &location)){ + if (parse_jump_from_buffer_line(app, &global_part, + view.buffer_id, view.cursor.line, false, + &location)){ + exec_command(app, change_active_panel); view = get_active_view(app, AccessAll); jump_to_location(app, &view, &location); @@ -36,13 +39,13 @@ CUSTOM_COMMAND_SIG(goto_jump_at_cursor){ // Error Jumping // -static bool32 -seek_next_jump_in_buffer(Application_Links *app, Partition *part, int32_t buffer_id, size_t first_line, bool32 skip_sub_errors, int32_t direction, size_t *line_out, size_t *colon_index_out, Name_Based_Jump_Location *location_out){ +static int32_t +seek_next_jump_in_buffer(Application_Links *app, Partition *part, int32_t buffer_id, int32_t first_line, bool32 skip_sub_errors, int32_t direction, int32_t *line_out, int32_t *colon_index_out, Name_Based_Jump_Location *location_out){ Assert(direction == 1 || direction == -1); - bool32 result = false; - size_t line = first_line; + int32_t result = false; + int32_t line = first_line; String line_str = {0}; Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll); for (;;){ @@ -83,12 +86,12 @@ convert_name_based_to_id_based(Application_Links *app, Name_Based_Jump_Location } static int32_t -seek_next_jump_in_view(Application_Links *app, Partition *part, View_Summary *view, bool32 skip_sub_errors, int32_t direction, size_t *line_out, size_t *colon_index_out, Name_Based_Jump_Location *location_out){ +seek_next_jump_in_view(Application_Links *app, Partition *part, View_Summary *view, int32_t skip_sub_errors, int32_t direction, int32_t *line_out, int32_t *colon_index_out, Name_Based_Jump_Location *location_out){ int32_t result = false; Name_Based_Jump_Location location = {0}; - size_t line = view->cursor.line; - size_t colon_index = 0; + int32_t line = view->cursor.line; + int32_t colon_index = 0; if (seek_next_jump_in_buffer(app, part, view->buffer_id, line+direction, skip_sub_errors, direction, &line, &colon_index, &location)){ result = true; *line_out = line; @@ -111,13 +114,13 @@ skip_this_jump(ID_Based_Jump_Location prev, ID_Based_Jump_Location jump){ return(result); } -static bool32 -advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_Summary *view, int32_t skip_repeats, bool32 skip_sub_error, int32_t direction, Name_Based_Jump_Location *location_out){ - bool32 result = true; +static int32_t +advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_Summary *view, int32_t skip_repeats, int32_t skip_sub_error, int32_t direction, Name_Based_Jump_Location *location_out){ + int32_t result = true; Name_Based_Jump_Location location = {0}; ID_Based_Jump_Location jump = {0}; - size_t line = 0, colon_index = 0; + int32_t line = 0, colon_index = 0; do{ Temp_Memory temp = begin_temp_memory(part); diff --git a/4coder_lib/4coder_mem.h b/4coder_lib/4coder_mem.h index c798c6d6..8bdbdb0a 100644 --- a/4coder_lib/4coder_mem.h +++ b/4coder_lib/4coder_mem.h @@ -157,9 +157,9 @@ struct Bubble{ Bubble *next; Bubble *prev2; Bubble *next2; - size_t size; + i32_4tech size; u32_4tech flags; - u8_4tech _unused_[20 - sizeof(size_t)]; + u32_4tech _unused_[4]; }; struct General_Memory{ @@ -214,8 +214,8 @@ general_sentinel_init(Bubble *bubble){ #define BUBBLE_MIN_SIZE 1024 static void -general_memory_attempt_split(General_Memory *general, Bubble *bubble, size_t wanted_size){ - size_t remaining_size = bubble->size - wanted_size; +general_memory_attempt_split(General_Memory *general, Bubble *bubble, i32_4tech wanted_size){ + i32_4tech remaining_size = bubble->size - wanted_size; if (remaining_size >= BUBBLE_MIN_SIZE){ bubble->size = wanted_size; Bubble *new_bubble = (Bubble*)((char*)(bubble + 1) + wanted_size); @@ -284,7 +284,7 @@ general_memory_check(General_Memory *general){} #endif static void* -general_memory_allocate(General_Memory *general, size_t size){ +general_memory_allocate(General_Memory *general, i32_4tech size){ void *result = 0; if (size < BUBBLE_MIN_SIZE) size = BUBBLE_MIN_SIZE; for (Bubble *bubble = general->free_sentinel.next2; @@ -320,10 +320,10 @@ general_memory_free(General_Memory *general, void *memory){ } static void* -general_memory_reallocate(General_Memory *general, void *old, size_t old_size, size_t size){ +general_memory_reallocate(General_Memory *general, void *old, i32_4tech old_size, i32_4tech size){ void *result = old; Bubble *bubble = ((Bubble*)old) - 1; - size_t additional_space = size - bubble->size; + i32_4tech additional_space = size - bubble->size; if (additional_space > 0){ Bubble *next = bubble->next; if (!(next->flags & MEM_BUBBLE_USED) && @@ -341,7 +341,7 @@ general_memory_reallocate(General_Memory *general, void *old, size_t old_size, s } inline void* -general_memory_reallocate_nocopy(General_Memory *general, void *old, size_t size){ +general_memory_reallocate_nocopy(General_Memory *general, void *old, i32_4tech size){ void *result = general_memory_reallocate(general, old, 0, size); return(result); } diff --git a/4coder_lib/4coder_table.h b/4coder_lib/4coder_table.h index 044306e0..17e9bce4 100644 --- a/4coder_lib/4coder_table.h +++ b/4coder_lib/4coder_table.h @@ -52,20 +52,20 @@ typedef i32_4tech Compare_Function(void *key, void *item, void *arg); struct Table{ u32_4tech *hash_array; char *data_array; - u32_4tech count, max; - u32_4tech item_size; + i32_4tech count, max; + i32_4tech item_size; }; -static umem_4tech -table_required_mem_size(u32_4tech table_size, u32_4tech item_size){ - u32_4tech hash_size = ((table_size * sizeof(u32_4tech)) + 7) & ~7; - umem_4tech mem_size = hash_size + table_size * item_size; +static i32_4tech +table_required_mem_size(i32_4tech table_size, i32_4tech item_size){ + i32_4tech hash_size = ((table_size * sizeof(u32_4tech)) + 7) & ~7; + i32_4tech mem_size = hash_size + table_size * item_size; return(mem_size); } static void -table_init_memory(Table *table, void *memory, u32_4tech table_size, u32_4tech item_size){ - umem_4tech hash_size = table_size * sizeof(u32_4tech); +table_init_memory(Table *table, void *memory, i32_4tech table_size, i32_4tech item_size){ + i32_4tech hash_size = table_size * sizeof(u32_4tech); hash_size = (hash_size + 7) & ~7; table->hash_array = (u32_4tech*)memory; @@ -90,8 +90,8 @@ table_add(Table *table, void *item, void *arg, Hash_Function *hash_func, Compare Assert(table->count * 8 < table->max * 7); u32_4tech hash = (hash_func(item, arg) | TableHashMin); - u32_4tech i = hash % table->max; - u32_4tech start = i; + i32_4tech i = hash % table->max; + i32_4tech start = i; u32_4tech *inspect = table->hash_array + i; while (*inspect >= TableHashMin){ @@ -120,8 +120,8 @@ table_find_pos(Table *table, void *search_key, void *arg, i32_4tech *pos, i32_4t Assert((table->count - 1) * 8 < table->max * 7); u32_4tech hash = (hash_func(search_key, arg) | TableHashMin); - u32_4tech i = hash % table->max; - u32_4tech start = i; + i32_4tech i = hash % table->max; + i32_4tech start = i; u32_4tech *inspect = table->hash_array + i; while (*inspect != TableHashEmpty){ @@ -254,17 +254,18 @@ tbl_offset_string_compare(void *a, void *b, void *arg){ struct String_Space{ char *space; - u32_4tech pos; - u32_4tech new_pos; - u32_4tech max; + i32_4tech pos; + i32_4tech new_pos; + i32_4tech max; }; static Offset_String -strspace_append(String_Space *space, char *str, u32_4tech len){ +strspace_append(String_Space *space, char *str, i32_4tech len){ Offset_String result = {}; if (space->new_pos + len <= space->max){ result.offset = space->new_pos; result.size = len; + memcpy(space->space + space->new_pos, str, len); space->new_pos = space->pos + len; } diff --git a/4coder_search.cpp b/4coder_search.cpp index e5c76b48..d6669ad4 100644 --- a/4coder_search.cpp +++ b/4coder_search.cpp @@ -40,10 +40,10 @@ struct Search_Range{ int32_t type; uint32_t flags; int32_t buffer; - size_t start; - size_t size; - size_t mid_start; - size_t mid_size; + int32_t start; + int32_t size; + int32_t mid_start; + int32_t mid_size; }; struct Search_Set{ @@ -54,29 +54,29 @@ struct Search_Set{ struct Search_Iter{ String word; - size_t pos; - size_t back_pos; - size_t i; - bool32 range_initialized; + int32_t pos; + int32_t back_pos; + int32_t i; + int32_t range_initialized; }; struct Search_Match{ Buffer_Summary buffer; - size_t start; - size_t end; - bool32 found_match; + int32_t start; + int32_t end; + int32_t found_match; }; static void -search_iter_init(General_Memory *general, Search_Iter *iter, size_t size){ - size_t str_max = size*2; +search_iter_init(General_Memory *general, Search_Iter *iter, int32_t size){ + int32_t str_max = size*2; if (iter->word.str == 0){ iter->word.str = (char*)general_memory_allocate(general, str_max); - iter->word.memory_size = (int32_t)str_max; + iter->word.memory_size = str_max; } else if (iter->word.memory_size < size){ iter->word.str = (char*)general_memory_reallocate_nocopy(general, iter->word.str, str_max); - iter->word.memory_size = (int32_t)str_max; + iter->word.memory_size = str_max; } iter->i = 0; iter->range_initialized = 0; @@ -91,8 +91,8 @@ search_set_init(General_Memory *general, Search_Set *set, int32_t range_count){ set->max = max; } else if (set->max < range_count){ - size_t mem_size = sizeof(Search_Range)*max;; - set->ranges = (Search_Range*)general_memory_reallocate_nocopy(general, set->ranges, mem_size); + set->ranges = (Search_Range*)general_memory_reallocate_nocopy( + general, set->ranges, sizeof(Search_Range)*max); set->max = max; } @@ -100,9 +100,9 @@ search_set_init(General_Memory *general, Search_Set *set, int32_t range_count){ } static void -search_hits_table_alloc(General_Memory *general, Table *hits, uint32_t table_size){ +search_hits_table_alloc(General_Memory *general, Table *hits, int32_t table_size){ void *mem = 0; - size_t mem_size = table_required_mem_size(table_size, sizeof(Offset_String)); + int32_t mem_size = table_required_mem_size(table_size, sizeof(Offset_String)); if (hits->hash_array == 0){ mem = general_memory_allocate(general, mem_size); } @@ -113,12 +113,12 @@ search_hits_table_alloc(General_Memory *general, Table *hits, uint32_t table_siz } static void -search_hits_init(General_Memory *general, Table *hits, String_Space *str, uint32_t table_size, uint32_t str_size){ +search_hits_init(General_Memory *general, Table *hits, String_Space *str, int32_t table_size, int32_t str_size){ if (hits->hash_array == 0){ search_hits_table_alloc(general, hits, table_size); } else{ - size_t mem_size = table_required_mem_size(table_size, sizeof(Offset_String)); + int32_t mem_size = table_required_mem_size(table_size, sizeof(Offset_String)); void *mem = general_memory_reallocate_nocopy(general, hits->hash_array, mem_size); table_init_memory(hits, mem, table_size, sizeof(Offset_String)); } @@ -137,18 +137,19 @@ search_hits_init(General_Memory *general, Table *hits, String_Space *str, uint32 } static int32_t -search_hit_add(General_Memory *general, Table *hits, String_Space *space, char *str, uint32_t len){ +search_hit_add(General_Memory *general, Table *hits, String_Space *space, char *str, int32_t len){ int32_t result = false; Assert(len != 0); Offset_String ostring = strspace_append(space, str, len); if (ostring.size == 0){ - uint32_t new_size = space->max*2; + int32_t new_size = space->max*2; if (new_size < space->max + len){ new_size = space->max + len; } - space->space = (char*)general_memory_reallocate(general, space->space, space->new_pos, new_size); + space->space = (char*)general_memory_reallocate( + general, space->space, space->new_pos, new_size); ostring = strspace_append(space, str, len); } @@ -174,14 +175,14 @@ search_hit_add(General_Memory *general, Table *hits, String_Space *space, char * return(result); } -static size_t -buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_Summary *buffer, size_t pos){ +static int32_t +buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ char space[1024]; Stream_Chunk chunk = {0}; if (init_stream_chunk(&chunk, app, buffer, pos, space, sizeof(space))){ - bool32 still_looping = true; + int32_t still_looping = true; do{ - for (; pos < (size_t)chunk.end; ++pos){ + for (; pos < chunk.end; ++pos){ char at_pos = chunk.data[pos]; if (!char_is_alpha_numeric(at_pos)) goto double_break; } @@ -207,13 +208,13 @@ enum{ }; static int32_t -match_check(Application_Links *app, Search_Range *range, size_t *pos, Search_Match *result_ptr, String word){ +match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Match *result_ptr, String word){ int32_t found_match = FindResult_None; Search_Match result = *result_ptr; - size_t end_pos = range->start + range->size; + int32_t end_pos = range->start + range->size; - uint32_t type = (range->flags & SearchFlag_MatchMask); + int32_t type = (range->flags & SearchFlag_MatchMask); switch (type){ case SearchFlag_MatchWholeWord: @@ -250,7 +251,9 @@ match_check(Application_Links *app, Search_Range *range, size_t *pos, Search_Mat { char prev = buffer_get_char(app, &result.buffer, result.start - 1); if (!char_is_alpha_numeric(prev)){ - result.end =buffer_seek_alpha_numeric_end(app, &result.buffer, result.start); + result.end = + buffer_seek_alpha_numeric_end( + app, &result.buffer, result.start); if (result.end <= end_pos){ result.found_match = true; @@ -281,14 +284,14 @@ match_check(Application_Links *app, Search_Range *range, size_t *pos, Search_Mat } static int32_t -search_front_to_back_step(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ +search_front_to_back_step(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; Search_Match result = *result_ptr; - size_t end_pos = range->start + range->size; + int32_t end_pos = range->start + range->size; if (*pos + word.size < end_pos){ - size_t start_pos = *pos; + int32_t start_pos = *pos; if (start_pos < range->start){ start_pos = range->start; } @@ -296,11 +299,8 @@ search_front_to_back_step(Application_Links *app, Search_Range *range, String wo int32_t case_insensitive = (range->flags & SearchFlag_CaseInsensitive); result.buffer = get_buffer(app, range->buffer, AccessAll); - - char *word_str = word.str; - size_t word_size = (size_t)word.size; if (case_insensitive){ - buffer_seek_string_insensitive_forward(app, &result.buffer, start_pos, end_pos, word_str, word_size, &result.start); + buffer_seek_string_insensitive_forward(app, &result.buffer, start_pos, end_pos, word.str, word.size, &result.start); } else{ buffer_seek_string_forward(app, &result.buffer, start_pos, end_pos, word.str, word.size, &result.start); @@ -329,7 +329,7 @@ search_front_to_back_step(Application_Links *app, Search_Range *range, String wo } static int32_t -search_front_to_back(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ +search_front_to_back(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; for (;found_match == FindResult_None;){ found_match = search_front_to_back_step(app, range, word, pos, result_ptr); @@ -338,13 +338,13 @@ search_front_to_back(Application_Links *app, Search_Range *range, String word, s } static int32_t -search_back_to_front_step(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ +search_back_to_front_step(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; Search_Match result = *result_ptr; if (*pos > range->start){ - size_t start_pos = *pos; + int32_t start_pos = *pos; result.buffer = get_buffer(app, range->buffer, AccessAll); buffer_seek_string_backward(app, &result.buffer, @@ -374,7 +374,7 @@ search_back_to_front_step(Application_Links *app, Search_Range *range, String wo } static int32_t -search_back_to_front(Application_Links *app, Search_Range *range, String word, size_t *pos, Search_Match *result_ptr){ +search_back_to_front(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; for (;found_match == FindResult_None;){ found_match = search_back_to_front_step(app, range, word, pos, result_ptr); @@ -412,12 +412,20 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){ switch (range->type){ case SearchRange_FrontToBack: { - find_result = search_front_to_back(app, range, iter.word, &iter.pos, &result); + find_result = + search_front_to_back(app, range, + iter.word, + &iter.pos, + &result); }break; case SearchRange_BackToFront: { - find_result = search_back_to_front(app, range, iter.word, &iter.back_pos, &result); + find_result = + search_back_to_front(app, range, + iter.word, + &iter.back_pos, + &result); }break; case SearchRange_Wave: @@ -429,20 +437,26 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){ int32_t backward_result = FindResult_PastEnd; if (iter.pos < range->start + range->size){ - forward_result = search_front_to_back(app, range, iter.word, &iter.pos, &forward_match); + forward_result = search_front_to_back(app, range, + iter.word, + &iter.pos, + &forward_match); } if (iter.back_pos > range->start){ - backward_result = search_back_to_front(app, range, iter.word, &iter.back_pos, &backward_match); + backward_result = search_back_to_front(app, range, + iter.word, + &iter.back_pos, + &backward_match); } if (forward_result == FindResult_FoundMatch){ if (backward_result == FindResult_FoundMatch){ find_result = FindResult_FoundMatch; - size_t forward_start = range->mid_start + range->mid_size; - size_t forward_distance = forward_match.start - forward_start; - size_t backward_distance = range->mid_start - backward_match.end; + int32_t forward_start = range->mid_start + range->mid_size; + int32_t forward_distance = (forward_match.start - forward_start); + int32_t backward_distance = (range->mid_start - backward_match.end); if (backward_distance < forward_distance){ iter.pos = forward_match.start; @@ -575,8 +589,8 @@ generic_search_all_buffers(Application_Links *app, General_Memory *general, Part file_len = match.buffer.buffer_name_len; } - int32_t line_num_len = int_to_str_size((int32_t)word_pos.line); - int32_t column_num_len = int_to_str_size((int32_t)word_pos.character); + int32_t line_num_len = int_to_str_size(word_pos.line); + int32_t column_num_len = int_to_str_size(word_pos.character); Temp_Memory line_temp = begin_temp_memory(&line_part); String line_str = {0}; @@ -603,9 +617,9 @@ generic_search_all_buffers(Application_Links *app, General_Memory *general, Part String out_line = make_string_cap(spare, 0, str_len); append_ss(&out_line, make_string(file_name, file_len)); append_s_char(&out_line, ':'); - append_int_to_str(&out_line, (int32_t)word_pos.line); + append_int_to_str(&out_line, word_pos.line); append_s_char(&out_line, ':'); - append_int_to_str(&out_line, (int32_t)word_pos.character); + append_int_to_str(&out_line, word_pos.character); append_s_char(&out_line, ':'); append_s_char(&out_line, ' '); append_ss(&out_line, line_str); @@ -713,9 +727,9 @@ struct Word_Complete_State{ Search_Iter iter; Table hits; String_Space str; - size_t word_start; - size_t word_end; - bool32 initialized; + int32_t word_start; + int32_t word_end; + int32_t initialized; }; static Word_Complete_State complete_state = {0}; @@ -737,13 +751,14 @@ CUSTOM_COMMAND_SIG(word_complete){ do_init = true; } - size_t word_end = 0; - size_t word_start = 0; - size_t cursor_pos = 0; - size_t size = 0; + int32_t word_end = 0; + int32_t word_start = 0; + int32_t cursor_pos = 0; + int32_t size = 0; if (do_init){ - // NOTE(allen): Get the range where the partial word is written. + // NOTE(allen): Get the range where the + // partial word is written. word_end = view.cursor.pos; word_start = word_end; cursor_pos = word_end - 1; @@ -753,7 +768,7 @@ CUSTOM_COMMAND_SIG(word_complete){ if (init_stream_chunk(&chunk, app, &buffer, cursor_pos, space, sizeof(space))){ int32_t still_looping = true; do{ - for (; cursor_pos >= (size_t)chunk.start; --cursor_pos){ + for (; cursor_pos >= chunk.start; --cursor_pos){ char c = chunk.data[cursor_pos]; if (char_is_alpha(c)){ word_start = cursor_pos; @@ -774,12 +789,13 @@ CUSTOM_COMMAND_SIG(word_complete){ return; } - // NOTE(allen): Initialize the search iterator with the partial word. + // NOTE(allen): Initialize the search iterator + // with the partial word. complete_state.initialized = true; search_iter_init(&global_general, &complete_state.iter, size); buffer_read_range(app, &buffer, word_start, word_end, complete_state.iter.word.str); - complete_state.iter.word.size = (int32_t)size; + complete_state.iter.word.size = size; // NOTE(allen): Initialize the set of ranges to be searched. int32_t buffer_count = get_buffer_count(app); @@ -810,8 +826,11 @@ CUSTOM_COMMAND_SIG(word_complete){ complete_state.set.count = j; // NOTE(allen): Initialize the search hit table. - search_hits_init(&global_general, &complete_state.hits, &complete_state.str, 100, (4 << 10)); - search_hit_add(&global_general, &complete_state.hits, &complete_state.str, complete_state.iter.word.str, complete_state.iter.word.size); + search_hits_init(&global_general, &complete_state.hits, &complete_state.str, + 100, (4 << 10)); + search_hit_add(&global_general, &complete_state.hits, &complete_state.str, + complete_state.iter.word.str, + complete_state.iter.word.size); complete_state.word_start = word_start; complete_state.word_end = word_end; @@ -825,20 +844,26 @@ CUSTOM_COMMAND_SIG(word_complete){ // NOTE(allen): Iterate through matches. if (size > 0){ for (;;){ - uint32_t match_size = 0; - Search_Match match = search_next_match(app, &complete_state.set, &complete_state.iter); + int32_t match_size = 0; + Search_Match match = + search_next_match(app, &complete_state.set, + &complete_state.iter); if (match.found_match){ - match_size = (uint32_t)(match.end - match.start); + match_size = match.end - match.start; Temp_Memory temp = begin_temp_memory(&global_part); char *spare = push_array(&global_part, char, match_size); - buffer_read_range(app, &match.buffer, match.start, match.end, spare); + buffer_read_range(app, &match.buffer, + match.start, match.end, spare); - if (search_hit_add(&global_general, &complete_state.hits, &complete_state.str, spare, match_size)){ - buffer_replace_range(app, &buffer, word_start, word_end, spare, match_size); - Buffer_Seek seek = seek_pos(word_start + match_size); - view_set_cursor(app, &view, seek, true); + if (search_hit_add(&global_general, &complete_state.hits, &complete_state.str, + spare, match_size)){ + buffer_replace_range(app, &buffer, word_start, word_end, + spare, match_size); + view_set_cursor(app, &view, + seek_pos(word_start + match_size), + true); complete_state.word_end = word_start + match_size; complete_state.set.ranges[0].mid_size = match_size; diff --git a/4cpp/4cpp_lexer.h b/4cpp/4cpp_lexer.h index 5c57ec9e..5b0fcc8b 100644 --- a/4cpp/4cpp_lexer.h +++ b/4cpp/4cpp_lexer.h @@ -191,7 +191,7 @@ static String_And_Flag keywords[] = { static i32_4tech keywords_count = sizeof(keywords)/sizeof(keywords[0]); API_EXPORT FCPP_LINK Cpp_Get_Token_Result -cpp_get_token(Cpp_Token_Array array, umem_4tech pos)/* +cpp_get_token(Cpp_Token_Array array, u32_4tech pos)/* DOC_PARAM(array, The array of tokens from which to get a token.) DOC_PARAM(pos, The position, measured in bytes, to get the token for.) DOC_RETURN(A Cpp_Get_Token_Result struct is returned containing the index of a token and a flag indicating whether the pos is contained in the token or in whitespace after the token.) diff --git a/4ed.cpp b/4ed.cpp index 54cb706b..08cf2a1c 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -343,8 +343,8 @@ COMMAND_DECL(reopen){ General_Memory *general = &models->mem.general; File_Edit_Positions edit_poss[16]; - umem line_number[16]; - umem column_number[16]; + int32_t line_number[16]; + int32_t column_number[16]; View *vptrs[16]; i32 vptr_count = 0; for (View_Iter iter = file_view_iter_init(&models->layout, file, 0); @@ -364,8 +364,8 @@ COMMAND_DECL(reopen){ for (i32 i = 0; i < vptr_count; ++i){ view_set_file(system, vptrs[i], file, models); - umem line = line_number[i]; - umem character = column_number[i]; + int32_t line = line_number[i]; + int32_t character = column_number[i]; *vptrs[i]->edit_pos = edit_poss[i]; Full_Cursor cursor = view_compute_cursor(system, vptrs[i], seek_line_char(line, character), 0); @@ -488,14 +488,14 @@ case_change_range(System_Functions *system, Mem_Options *mem, View *view, Editin file_update_history_before_edit(mem, file, step, 0, hist_normal); u8 *data = (u8*)file->state.buffer.data; - for (umem i = range.start; i < range.end; ++i){ + for (i32 i = range.start; i < range.end; ++i){ if (data[i] >= a && data[i] <= z){ data[i] += char_delta; } } if (file->state.token_array.tokens){ - file_relex_parallel(system, mem, file, (u32)range.start, (u32)range.end, 0); + file_relex_parallel(system, mem, file, range.start, range.end, 0); } } } @@ -1552,7 +1552,7 @@ update_cli_handle_with_file(System_Functions *system, Models *models, CLI_Handle system->cli_begin_update(cli); if (system->cli_update_step(cli, dest, max, &amount)){ - amount = (u32)eol_in_place_convert_in(dest, amount); + amount = eol_in_place_convert_in(dest, amount); output_file_append(system, models, file, make_string(dest, amount), cursor_at_end); result = 1; } @@ -1591,7 +1591,7 @@ App_Step_Sig(app_step){ if (clipboard.str){ String *dest =working_set_next_clipboard_string(&models->mem.general, &models->working_set, clipboard.size); - dest->size = (i32)eol_convert_in(dest->str, clipboard.str, clipboard.size); + dest->size = eol_convert_in(dest->str, clipboard.str, clipboard.size); } // NOTE(allen): check files are up to date @@ -2503,16 +2503,16 @@ App_Step_Sig(app_step){ layout_compute_absolute_positions(&models->layout, absolute_positions); mouse_position = (divider->v_divider)?(mx):(my); layout_get_min_max(&models->layout, divider, absolute_positions, &min, &max); - absolute_positions[div_id] = clamp_i32(min, mouse_position, max); + absolute_positions[div_id] = clamp(min, mouse_position, max); layout_update_all_positions(&models->layout, absolute_positions); } else{ if (divider->v_divider){ - mouse_position = clamp_i32(0, mx, models->layout.full_width); + mouse_position = clamp(0, mx, models->layout.full_width); } else{ - mouse_position = clamp_i32(0, my, models->layout.full_height); + mouse_position = clamp(0, my, models->layout.full_height); } divider->pos = layout_compute_position(&models->layout, divider, mouse_position); } diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index f5f62908..a10595bd 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -347,12 +347,17 @@ DOC_SEE(Command_Line_Interface_Flag) } API_EXPORT void -Clipboard_Post(Application_Links *app, int32_t clipboard_id, char *str, size_t len) +Clipboard_Post(Application_Links *app, int32_t clipboard_id, char *str, int32_t len) /* DOC_PARAM(clipboard_id, This parameter is set up to prepare for future features, it should always be 0 for now.) DOC_PARAM(str, The str parameter specifies the string to be posted to the clipboard, it need not be null terminated.) DOC_PARAM(len, The len parameter specifies the length of the str string.) -DOC(Stores the string str in the clipboard initially with index 0. Also reports the copy to the operating system, so that it may be pasted into other applications.) +DOC +( +Stores the string str in the clipboard initially with index 0. +Also reports the copy to the operating system, so that it may +be pasted into other applications. +) DOC_SEE(The_4coder_Clipboard) */{ Command_Data *cmd = (Command_Data*)app->cmd_context; @@ -361,13 +366,13 @@ DOC_SEE(The_4coder_Clipboard) General_Memory *general = &models->mem.general; Working_Set *working = &models->working_set; - String *dest = working_set_next_clipboard_string(general, working, (u32)len); - copy_ss(dest, make_string(str, (i32)len)); + String *dest = working_set_next_clipboard_string(general, working, len); + copy_ss(dest, make_string(str, len)); system->post_clipboard(*dest); } -API_EXPORT uint32_t -Clipboard_Count(Application_Links *app, uint32_t clipboard_id) +API_EXPORT int32_t +Clipboard_Count(Application_Links *app, int32_t clipboard_id) /* DOC_PARAM(clipboard_id, This parameter is set up to prepare for future features, it should always be 0 for now.) DOC(This call returns the number of items in the clipboard.) @@ -375,12 +380,12 @@ DOC_SEE(The_4coder_Clipboard) */{ Command_Data *cmd = (Command_Data*)app->cmd_context; Working_Set *working = &cmd->models->working_set; - uint32_t count = working->clipboard_size; + int32_t count = working->clipboard_size; return(count); } -API_EXPORT size_t -Clipboard_Index(Application_Links *app, uint32_t clipboard_id, uint32_t item_index, char *out, size_t len) +API_EXPORT int32_t +Clipboard_Index(Application_Links *app, int32_t clipboard_id, int32_t item_index, char *out, int32_t len) /* DOC_PARAM(clipboard_id, This parameter is set up to prepare for future features, it should always be 0 for now.) DOC_PARAM(item_index, This parameter specifies which item to read, 0 is the most recent copy, 1 is the second most recent copy, etc.) @@ -395,12 +400,12 @@ DOC_SEE(The_4coder_Clipboard) Command_Data *cmd = (Command_Data*)app->cmd_context; Working_Set *working = &cmd->models->working_set; - size_t size = 0; + int32_t size = 0; String *str = working_set_clipboard_index(working, item_index); if (str){ size = str->size; if (out){ - String out_str = make_string_cap(out, 0, (i32)len); + String out_str = make_string_cap(out, 0, len); copy_ss(&out_str, *str); } } @@ -545,7 +550,7 @@ DOC_SEE(Access_Flag) } API_EXPORT bool32 -Buffer_Read_Range(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, char *out) +Buffer_Read_Range(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *out) /* DOC_PARAM(buffer, This parameter specifies the buffer to read.) DOC_PARAM(start, This parameter specifies absolute position of the first character in the read range.) @@ -588,22 +593,32 @@ DOC_PARAM(end, This parameter specifies the absolute position of the the charact DOC_PARAM(str, This parameter specifies the the string to write into the range; it need not be null terminated.) DOC_PARAM(len, This parameter specifies the length of the str string.) DOC_RETURN(This call returns non-zero if the replacement succeeds.) -DOC(If this call succeeds it deletes the range from start to end and writes str in the same position. If end == start then this call is equivalent to inserting the string at start. If len == 0 this call is equivalent to deleteing the range from start to end. +DOC +( +If this call succeeds it deletes the range from start to end +and writes str in the same position. If end == start then +this call is equivalent to inserting the string at start. +If len == 0 this call is equivalent to deleteing the range +from start to end. -This call fails if the buffer does not exist, or if the replace range is not within the bounds of the buffer.) +This call fails if the buffer does not exist, or if the replace +range is not within the bounds of the buffer. +) DOC_SEE(4coder_Buffer_Positioning_System) */{ Command_Data *cmd = (Command_Data*)app->cmd_context; Editing_File *file = imp_get_file(cmd, buffer); bool32 result = false; + int32_t size = 0; if (file){ - u32 size = buffer_size(&file->state.buffer); + size = buffer_size(&file->state.buffer); if (0 <= start && start <= end && end <= size){ result = true; - file_replace_range(cmd->system, cmd->models, file, (u32)start, (u32)end, str, (u32)len); + file_replace_range(cmd->system, cmd->models, + file, start, end, str, len); } fill_buffer_summary(buffer, file, cmd); } @@ -670,9 +685,9 @@ DOC_SEE(Buffer_Batch_Edit_Type) Assert(inverse_edits); char *inv_str = (char*)part->base + part->pos; - umem inv_str_max = part->max - part->pos; + int32_t inv_str_max = part->max - part->pos; - Edit_Spec spec = file_compute_edit(mem, file, edits, str, str_len, inverse_edits, inv_str, (u32)inv_str_max, (u32)edit_count, type); + Edit_Spec spec = file_compute_edit(mem, file, edits, str, str_len, inverse_edits, inv_str, inv_str_max, edit_count, type); file_do_batch_edit(system, models, file, spec, hist_normal, type); @@ -995,7 +1010,7 @@ If the buffer does not exist or if it is not a lexed buffer, the return is zero. } API_EXPORT bool32 -Buffer_Read_Tokens(Application_Links *app, Buffer_Summary *buffer, size_t start_token, size_t end_token, Cpp_Token *tokens_out) +Buffer_Read_Tokens(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out) /* DOC_PARAM(buffer, Specifies the buffer from which to read tokens.) DOC_PARAM(first_token, Specifies the index of the first token to read.) @@ -1022,7 +1037,7 @@ The number of output tokens will be end_token - start_token.) } API_EXPORT bool32 -Buffer_Get_Token_Index(Application_Links *app, Buffer_Summary *buffer, size_t pos, Cpp_Get_Token_Result *get_result) +Buffer_Get_Token_Index(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Get_Token_Result *get_result) /* DOC_PARAM(buffer, The buffer from which to get a token.) DOC_PARAM(pos, The position in the buffer in absolute coordinates.) @@ -1816,26 +1831,32 @@ DOC_SEE(Buffer_Seek) } API_EXPORT bool32 -View_Set_Highlight(Application_Links *app, View_Summary *view, size_t start, size_t end, bool32 turn_on)/* +View_Set_Highlight(Application_Links *app, View_Summary *view, int32_t start, int32_t end, bool32 turn_on)/* DOC_PARAM(view, The view parameter specifies the view in which to set the highlight.) DOC_PARAM(start, This parameter specifies the absolute position of the first character of the highlight range.) DOC_PARAM(end, This parameter specifies the absolute position of the character one past the end of the highlight range.) DOC_PARAM(turn_on, This parameter indicates whether the highlight is being turned on or off.) DOC_RETURN(This call returns non-zero on success.) -DOC(The highlight is mutually exclusive to the cursor. When the turn_on parameter is set to true the highlight will be shown and the cursor will be hidden. After that either setting the cursor with view_set_cursor or calling view_set_highlight and the turn_on set to false, will switch back to showing the cursor.) +DOC +( +The highlight is mutually exclusive to the cursor. When the turn_on parameter +is set to true the highlight will be shown and the cursor will be hidden. After +that either setting the cursor with view_set_cursor or calling view_set_highlight +and the turn_on set to false, will switch back to showing the cursor. +) */{ Command_Data *cmd = (Command_Data*)app->cmd_context; System_Functions *system = cmd->system; View *vptr = imp_get_view(cmd, view); bool32 result = false; - if (vptr != 0){ + if (vptr){ result = true; if (turn_on){ view_set_temp_highlight(system, vptr, start, end); } else{ - vptr->file_data.show_temp_highlight = false; + vptr->file_data.show_temp_highlight = 0; } fill_view_summary(system, view, vptr, cmd); } @@ -1879,7 +1900,7 @@ DOC_SEE(Set_Buffer_Flag) } API_EXPORT bool32 -View_Post_Fade(Application_Links *app, View_Summary *view, float seconds, size_t start, size_t end, int_color color) +View_Post_Fade(Application_Links *app, View_Summary *view, float seconds, int32_t start, int32_t end, int_color color) /* DOC_PARAM(view, The view parameter specifies the view onto which the fade effect shall be posted.) DOC_PARAM(seconds, This parameter specifies the number of seconds the fade effect should last.) @@ -1893,10 +1914,13 @@ DOC_SEE(int_color) View *vptr = imp_get_view(cmd, view); bool32 result = false; - size_t size = end - start; - if (vptr != 0 && size > 0){ - result = true; - view_post_paste_effect(vptr, seconds, (u32)start, (u32)size, color | 0xFF000000); + + int32_t size = end - start; + if (vptr){ + if (size > 0){ + result = true; + view_post_paste_effect(vptr, seconds, start, size, color | 0xFF000000); + } } return(result); diff --git a/4ed_buffer.cpp b/4ed_buffer.cpp index 2c2868c7..6d38f683 100644 --- a/4ed_buffer.cpp +++ b/4ed_buffer.cpp @@ -17,12 +17,12 @@ #include "4coder_helper/4coder_seek_types.h" typedef struct Cursor_With_Index{ - umem pos; + i32 pos; i32 index; } Cursor_With_Index; inline void -write_cursor_with_index(Cursor_With_Index *positions, i32 *count, umem pos){ +write_cursor_with_index(Cursor_With_Index *positions, i32 *count, i32 pos){ positions[(*count)].index = *count; positions[(*count)].pos = pos; ++(*count); @@ -33,7 +33,7 @@ write_cursor_with_index(Cursor_With_Index *positions, i32 *count, umem pos){ internal void buffer_quick_sort_cursors(Cursor_With_Index *positions, i32 start, i32 pivot){ i32 mid = start; - umem pivot_pos = positions[pivot].pos; + i32 pivot_pos = positions[pivot].pos; for (i32 i = mid; i < pivot; ++i){ if (positions[i].pos < pivot_pos){ CursorSwap__(positions[mid], positions[i]); @@ -100,15 +100,15 @@ buffer_update_cursors(Cursor_With_Index *sorted_positions, i32 count, i32 start, } } -internal b32 -buffer_batch_debug_sort_check(Buffer_Edit *sorted_edits, u32 edit_count){ - b32 result = true; - +internal i32 +buffer_batch_debug_sort_check(Buffer_Edit *sorted_edits, i32 edit_count){ Buffer_Edit *edit = sorted_edits; - size_t start_point = 0; - for (u32 i = 0; i < edit_count; ++i, ++edit){ + i32 i = 0, start_point = 0; + i32 result = 1; + + for (i = 0; i < edit_count; ++i, ++edit){ if (start_point > edit->start){ - result = false; break; + result = 0; break; } start_point = (edit->end < edit->start + 1)?(edit->start + 1):(edit->end); } @@ -117,18 +117,13 @@ buffer_batch_debug_sort_check(Buffer_Edit *sorted_edits, u32 edit_count){ } internal i32 -buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, u32 edit_count){ - Buffer_Edit *edit = sorted_edits; +buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, i32 edit_count){ + i32 i = 0; i32 shift_total = 0, shift_max = 0; - for (u32 i = 0; i < edit_count; ++i, ++edit){ - umem target_length = edit->end - edit->start; - umem edit_length = edit->len; - if (edit_length > target_length){ - shift_total += (i32)(edit_length - target_length); - } - else{ - shift_total -= (i32)(target_length - edit_length); - } + + Buffer_Edit *edit = sorted_edits; + for (i = 0; i < edit_count; ++i, ++edit){ + shift_total += (edit->len - (edit->end - edit->start)); if (shift_total > shift_max){ shift_max = shift_total; } @@ -147,50 +142,36 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, if (lean_right){ for (; edit < end_edit && position < end_position; ++edit){ - umem start = edit->start; - umem end = edit->end; + i32 start = edit->start; + i32 end = edit->end; for (; position->pos < start && position < end_position; ++position){ position->pos += shift_amount; } - umem new_end = start + edit->len + shift_amount; + i32 new_end = start + edit->len + shift_amount; for (; position->pos <= end && position < end_position; ++position){ position->pos = new_end; } - umem target_length = end - start; - umem edit_length = edit->len; - if (edit_length > target_length){ - shift_amount += (i32)(edit_length - target_length); - } - else{ - shift_amount -= (i32)(target_length - edit_length); - } + shift_amount += (edit->len - (end - start)); } } else{ for (; edit < end_edit && position < end_position; ++edit){ - umem start = edit->start; - umem end = edit->end; + i32 start = edit->start; + i32 end = edit->end; for (; position->pos < start && position < end_position; ++position){ position->pos += shift_amount; } - umem new_end = start + shift_amount; + i32 new_end = start + shift_amount; for (; position->pos <= end && position < end_position; ++position){ position->pos = new_end; } - umem target_length = end - start; - umem edit_length = edit->len; - if (edit_length > target_length){ - shift_amount += (i32)(edit_length - target_length); - } - else{ - shift_amount -= (i32)(target_length - edit_length); - } + shift_amount += (edit->len - (end - start)); } } @@ -199,14 +180,7 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, } for (; edit < end_edit; ++edit){ - umem target_length = edit->end - edit->start; - umem edit_length = edit->len; - if (edit_length > target_length){ - shift_amount += (i32)(edit_length - target_length); - } - else{ - shift_amount -= (i32)(target_length - edit_length); - } + shift_amount += (edit->len - (edit->end - edit->start)); } return(shift_amount); @@ -314,9 +288,9 @@ typedef struct Gap_Buffer{ umem size2; umem max; - u32 *line_starts; - u32 line_count; - u32 line_max; + umem *line_starts; + umem line_count; + umem line_max; } Gap_Buffer; inline b32 @@ -326,15 +300,9 @@ buffer_good(Gap_Buffer *buffer){ } inline umem -buffer_size_umem(Gap_Buffer *buffer){ - umem size = buffer->size1 + buffer->size2; - return(size); -} - -inline u32 buffer_size(Gap_Buffer *buffer){ umem size = buffer->size1 + buffer->size2; - return(u32)(size); + return(size); } typedef struct Gap_Buffer_Init{ @@ -368,7 +336,7 @@ buffer_init_page_size(Gap_Buffer_Init *init){ } internal void -buffer_init_provide_page(Gap_Buffer_Init *init, void *page, umem page_size){ +buffer_init_provide_page(Gap_Buffer_Init *init, void *page, i32 page_size){ Gap_Buffer *buffer = init->buffer; buffer->data = (char*)page; buffer->max = page_size; @@ -488,9 +456,9 @@ buffer_stringify_next(Gap_Buffer_Stream *stream){ } internal b32 -buffer_replace_range(Gap_Buffer *buffer, u32 start, u32 end, char *str, u32 len, i32 *shift_amount, void *scratch, umem scratch_memory, umem *request_amount){ +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){ char *data = buffer->data; - u32 size = buffer_size(buffer); + umem size = buffer_size(buffer); b32 result = false; assert(0 <= start); @@ -540,7 +508,7 @@ buffer_replace_range(Gap_Buffer *buffer, u32 start, u32 end, char *str, u32 len, } typedef struct Buffer_Batch_State{ - u32 i; + umem i; i32 shift_total; } Buffer_Batch_State; @@ -548,18 +516,14 @@ typedef struct Buffer_Batch_State{ internal b32 buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, char *strings, u32 edit_count, void *scratch, umem scratch_size, umem *request_amount){ Buffer_Edit *edit = 0; - u32 i = state->i; + umem i = state->i; i32 shift_total = state->shift_total; i32 shift_amount = 0; b32 result = false; edit = sorted_edits + i; for (; i < edit_count; ++i, ++edit){ - u32 start = (u32)(edit->start + shift_total); - u32 end = (u32)(edit->end + shift_total); - u32 len = (u32)(edit->len); - - result = buffer_replace_range(buffer, start, end, strings + edit->str_start, len, &shift_amount, scratch, scratch_size, request_amount); + result = buffer_replace_range(buffer, edit->start + shift_total, edit->end + shift_total, strings + edit->str_start, edit->len, &shift_amount, scratch, scratch_size, request_amount); if (result){ break; } @@ -575,7 +539,7 @@ buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edi internal void* buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, umem new_max){ void *result = buffer->data; - umem size = buffer_size_umem(buffer); + umem size = buffer_size(buffer); umem new_gap_size = new_max - size; assert(new_max >= size); @@ -614,7 +578,7 @@ buffer_stringify(Gap_Buffer *buffer, umem start, umem end, char *out){ internal umem buffer_convert_out(Gap_Buffer *buffer, char *dest, umem max){ Gap_Buffer_Stream stream = {0}; - u32 size = buffer_size(buffer); + umem size = buffer_size(buffer); assert(size + buffer->line_count <= max); umem pos = 0; @@ -624,7 +588,7 @@ buffer_convert_out(Gap_Buffer *buffer, char *dest, umem max){ do{ umem chunk_size = stream.end - i; umem out_size = 0; - b32 result = eol_convert_out(dest + pos, max - pos, stream.data + i, chunk_size, &out_size); + i32 result = eol_convert_out(dest + pos, max - pos, stream.data + i, chunk_size, &out_size); assert(result); i = stream.end; pos += out_size; @@ -635,11 +599,11 @@ buffer_convert_out(Gap_Buffer *buffer, char *dest, umem max){ return(pos); } -internal u32 -buffer_count_newlines(Gap_Buffer *buffer, u32 start, u32 end){ +internal i32 +buffer_count_newlines(Gap_Buffer *buffer, i32 start, i32 end){ Gap_Buffer_Stream stream = {0}; - u32 i = start; - u32 count = 0; + i32 i = start; + i32 count = 0; assert(0 <= start); assert(start <= end); @@ -659,9 +623,9 @@ buffer_count_newlines(Gap_Buffer *buffer, u32 start, u32 end){ } typedef struct Buffer_Measure_Starts{ - u32 i; - u32 count; - u32 start; + umem i; + umem count; + umem start; } Buffer_Measure_Starts; // TODO(allen): Rewrite this with a duff routine @@ -670,10 +634,10 @@ typedef struct Buffer_Measure_Starts{ internal b32 buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){ Gap_Buffer_Stream stream = {0}; - u32 size = (u32)buffer_size(buffer); - u32 start = state->start, i = state->i; - u32 *start_ptr = buffer->line_starts + state->count; - u32 *start_end = buffer->line_starts + buffer->line_max; + umem size = buffer_size(buffer); + umem start = state->start, i = state->i; + umem *start_ptr = buffer->line_starts + state->count; + umem *start_end = buffer->line_starts + buffer->line_max; b32 result = true; if (buffer_stringify_loop(&stream, buffer, i, size)){ @@ -713,13 +677,13 @@ buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){ } internal void -buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, u32 *character_starts, i32 mode, b32 virtual_white){ +buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, umem *character_starts, i32 mode, b32 virtual_white){ assert(mode == 0); Gap_Buffer_Stream stream = {0}; - u32 line_index = 0; - u32 character_index = 0; + umem line_index = 0; + umem character_index = 0; character_starts[line_index++] = character_index; @@ -781,16 +745,16 @@ enum{ struct Buffer_Layout_Stop{ u32 status; - u32 line_index; - u32 wrap_line_index; - u32 pos; - u32 next_line_pos; + i32 line_index; + i32 wrap_line_index; + umem pos; + umem next_line_pos; f32 x; }; struct Buffer_Measure_Wrap_Params{ Gap_Buffer *buffer; - u32 *wrap_line_index; + i32 *wrap_line_index; System_Functions *system; Render_Font *font; b32 virtual_white; @@ -798,18 +762,18 @@ struct Buffer_Measure_Wrap_Params{ struct Buffer_Measure_Wrap_State{ Gap_Buffer_Stream stream; - u32 i; - u32 size; + umem i; + umem size; b32 still_looping; - u32 line_index; + i32 line_index; - u32 current_wrap_index; + i32 current_wrap_index; f32 current_adv; f32 x; - u32 wrap_unit_end; b32 skipping_whitespace; + i32 wrap_unit_end; b32 did_wrap; b32 first_of_the_line; @@ -828,7 +792,7 @@ struct Buffer_Measure_Wrap_State{ #define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); } internal Buffer_Layout_Stop -buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Params params, f32 line_shift, b32 do_wrap, u32 wrap_unit_end){ +buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Params params, f32 line_shift, b32 do_wrap, i32 wrap_unit_end){ Buffer_Measure_Wrap_State S = *S_ptr; Buffer_Layout_Stop S_stop; @@ -839,7 +803,7 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para DrCase(4); } - S.size = (u32)buffer_size(params.buffer); + S.size = buffer_size(params.buffer); if (params.virtual_white){ S_stop.status = BLStatus_NeedLineShift; @@ -956,9 +920,9 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para #undef DrReturn internal void -buffer_remeasure_starts(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 line_shift, i32 text_shift){ - u32 *starts = buffer->line_starts; - u32 line_count = buffer->line_count; +buffer_remeasure_starts(Gap_Buffer *buffer, umem start_line, umem end_line, i32 line_shift, i32 text_shift){ + umem *starts = buffer->line_starts; + umem line_count = buffer->line_count; assert(0 <= start_line); assert(start_line <= end_line); @@ -969,7 +933,7 @@ buffer_remeasure_starts(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li // Adjust if (text_shift != 0){ - u32 line_i = end_line; + umem line_i = end_line; starts += line_i; for (; line_i < line_count; ++line_i, ++starts){ *starts += text_shift; @@ -978,8 +942,8 @@ buffer_remeasure_starts(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li } // Shift - u32 new_line_count = line_count; - u32 new_end_line = end_line; + umem new_line_count = line_count; + umem new_end_line = end_line; if (line_shift != 0){ new_line_count += line_shift; new_end_line += line_shift; @@ -990,12 +954,12 @@ buffer_remeasure_starts(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li // Iteration data (yikes! Need better loop system) Gap_Buffer_Stream stream = {0}; - u32 size = buffer_size(buffer); - u32 char_i = starts[start_line]; - u32 line_i = start_line; + umem size = buffer_size(buffer); + umem char_i = starts[start_line]; + umem line_i = start_line; // Line start measurement - u32 start = char_i; + umem start = char_i; if (buffer_stringify_loop(&stream, buffer, char_i, size)){ b32 still_looping = 0; @@ -1029,10 +993,10 @@ buffer_remeasure_starts(Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 li } internal void -buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, u32 start_line, u32 end_line, i32 line_shift, u32 *character_starts, i32 mode, b32 virtual_whitespace){ +buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, umem start_line, umem end_line, i32 line_shift, umem *character_starts, i32 mode, b32 virtual_whitespace){ assert(mode == 0); - u32 new_line_count = buffer->line_count; + umem new_line_count = buffer->line_count; assert(0 <= start_line); assert(start_line <= end_line); @@ -1041,8 +1005,8 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G ++end_line; // Shift - u32 line_count = new_line_count; - u32 new_end_line = end_line; + umem line_count = new_line_count; + umem new_end_line = end_line; if (line_shift != 0){ line_count -= line_shift; new_end_line += line_shift; @@ -1052,13 +1016,13 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G // Iteration data Gap_Buffer_Stream stream = {0}; - u32 size = buffer_size(buffer); - u32 char_i = buffer->line_starts[start_line]; - u32 line_i = start_line; + umem size = buffer_size(buffer); + umem char_i = buffer->line_starts[start_line]; + umem line_i = start_line; // Character measurement - u32 last_char_start = character_starts[line_i]; - u32 current_char_start = last_char_start; + umem last_char_start = character_starts[line_i]; + umem current_char_start = last_char_start; b32 skipping_whitespace = false; if (virtual_whitespace){ @@ -1112,8 +1076,8 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G // Adjust if (line_i <= new_end_line){ - u32 old_value = character_starts[line_i]; - u32 new_value = current_char_start; + umem old_value = 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); @@ -1212,10 +1176,10 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 } } -internal u32 -binary_search(u32 *array, u32 value, u32 l_bound, u32 u_bound){ +internal umem +binary_search(umem *array, umem value, umem l_bound, umem u_bound){ value = clamp_bottom(0, value); - u32 start = l_bound, end = u_bound, i = 0; + umem start = l_bound, end = u_bound, i = 0; for (;;){ i = (start + end) >> 1; if (array[i] < value){ @@ -1236,34 +1200,34 @@ binary_search(u32 *array, u32 value, u32 l_bound, u32 u_bound){ return(i); } -inline u32 -buffer_get_line_index_range(Gap_Buffer *buffer, u32 pos, u32 l_bound, u32 u_bound){ +inline umem +buffer_get_line_index_range(Gap_Buffer *buffer, umem pos, umem l_bound, umem u_bound){ assert(0 <= l_bound); assert(l_bound <= u_bound); assert(u_bound <= buffer->line_count); assert(buffer->line_starts != 0); - u32 i = binary_search(buffer->line_starts, pos, l_bound, u_bound); + umem i = binary_search(buffer->line_starts, pos, l_bound, u_bound); return(i); } -inline u32 -buffer_get_line_index(Gap_Buffer *buffer, u32 pos){ - u32 result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); +inline umem +buffer_get_line_index(Gap_Buffer *buffer, umem pos){ + umem result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); return(result); } -inline u32 -buffer_get_line_index_from_character_pos(u32 *character_starts, u32 pos, u32 l_bound, u32 u_bound){ - u32 i = binary_search(character_starts, pos, l_bound, u_bound); +inline umem +buffer_get_line_index_from_character_pos(umem *character_starts, umem pos, umem l_bound, umem u_bound){ + umem i = binary_search(character_starts, pos, l_bound, u_bound); return(i); } -inline u32 -buffer_get_line_index_from_wrapped_y(u32 *wrap_line_index, f32 y, i32 line_height, u32 l_bound, u32 u_bound){ - u32 wrap_index = floor32(y/line_height); - u32 i = binary_search(wrap_line_index, wrap_index, l_bound, u_bound); +inline umem +buffer_get_line_index_from_wrapped_y(umem *wrap_line_index, f32 y, umem line_height, umem l_bound, umem u_bound){ + umem wrap_index = floor32(y/line_height); + umem i = binary_search(wrap_line_index, wrap_index, l_bound, u_bound); return(i); } @@ -1271,10 +1235,10 @@ internal Partial_Cursor buffer_partial_from_pos(Gap_Buffer *buffer, umem pos){ Partial_Cursor result = {0}; - u32 size = buffer_size(buffer); + umem size = buffer_size(buffer); pos = clamp_umem(0, pos, size); - u32 line_index = buffer_get_line_index_range(buffer, (u32)pos, 0, (u32)buffer->line_count); + umem line_index = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); result.pos = pos; result.line = line_index+1; result.character = pos - buffer->line_starts[line_index] + 1; @@ -1283,10 +1247,10 @@ buffer_partial_from_pos(Gap_Buffer *buffer, umem pos){ } internal Partial_Cursor -buffer_partial_from_line_character(Gap_Buffer *buffer, umem line, umem character, b32 reversed){ +buffer_partial_from_line_character(Gap_Buffer *buffer, i32 line, i32 character){ Partial_Cursor result = {0}; - umem line_index = line - 1; + i32 line_index = line - 1; if (line_index >= buffer->line_count){ line_index = buffer->line_count - 1; } @@ -1294,37 +1258,35 @@ buffer_partial_from_line_character(Gap_Buffer *buffer, umem line, umem character line_index = 0; } - umem size = buffer_size(buffer); + i32 size = buffer_size(buffer); - umem this_start = buffer->line_starts[line_index]; - umem max_character = (size-this_start) + 1; + i32 this_start = buffer->line_starts[line_index]; + i32 max_character = (size-this_start) + 1; if (line_index+1 < buffer->line_count){ - umem next_start = buffer->line_starts[line_index+1]; + i32 next_start = buffer->line_starts[line_index+1]; max_character = (next_start-this_start); } - umem adjusted_pos = 0; + i32 adjusted_pos = 0; if (character > 0){ - if (reversed){ - if (character > max_character){ - adjusted_pos = 0; - } - else{ - adjusted_pos = max_character + character; - } + if (character > max_character){ + adjusted_pos = max_character - 1; } else{ - if (character > max_character){ - adjusted_pos = max_character - 1; - } - else{ - adjusted_pos = character - 1; - } + adjusted_pos = character - 1; } } else if (character == 0){ adjusted_pos = 0; } + else{ + if (-character > max_character){ + adjusted_pos = 0; + } + else{ + adjusted_pos = max_character + character; + } + } result.pos = this_start + adjusted_pos; result.line = line_index + 1; @@ -1338,8 +1300,8 @@ struct Buffer_Cursor_Seek_Params{ Buffer_Seek seek; System_Functions *system; Render_Font *font; - u32 *wrap_line_index; - u32 *character_starts; + i32 *wrap_line_index; + i32 *character_starts; b32 virtual_white; b32 return_hint; Full_Cursor *cursor_out; @@ -1352,9 +1314,9 @@ struct Buffer_Cursor_Seek_State{ Gap_Buffer_Stream stream; b32 still_looping; - u32 i; - u32 size; - u32 wrap_unit_end; + i32 i; + i32 size; + i32 wrap_unit_end; b32 first_of_the_line; b32 xy_seek; @@ -1378,7 +1340,7 @@ struct Buffer_Cursor_Seek_State{ #define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); } internal Buffer_Layout_Stop -buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params params, f32 line_shift, b32 do_wrap, u32 wrap_unit_end){ +buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params params, f32 line_shift, b32 do_wrap, i32 wrap_unit_end){ Buffer_Cursor_Seek_State S = *S_ptr; Buffer_Layout_Stop S_stop; @@ -1392,40 +1354,37 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa S.font_height = font_get_height(params.font); S.xy_seek = (params.seek.type == buffer_seek_wrapped_xy || params.seek.type == buffer_seek_unwrapped_xy); - S.size = (u32)buffer_size(params.buffer); + S.size = buffer_size(params.buffer); // Get cursor hint { - u32 line_index = 0; + i32 line_index = 0; switch (params.seek.type){ case buffer_seek_pos: { - params.seek.pos = clamp_u32(0, (u32)params.seek.pos, S.size); + params.seek.pos = clamp(0, params.seek.pos, S.size); - line_index = buffer_get_line_index(params.buffer, (u32)params.seek.pos); + line_index = buffer_get_line_index(params.buffer, params.seek.pos); }break; case buffer_seek_character_pos: { - u32 line_count = params.buffer->line_count; - u32 max_character = params.character_starts[line_count] - 1; - params.seek.pos = clamp_u32(0, (u32)params.seek.pos, max_character); + i32 line_count = params.buffer->line_count; + i32 max_character = params.character_starts[line_count] - 1; + params.seek.pos = clamp(0, params.seek.pos, max_character); - u32 *char_starts = params.character_starts; - - u32 pos = (u32)params.seek.pos; - line_index = buffer_get_line_index_from_character_pos(char_starts, pos, 0, line_count); + line_index = buffer_get_line_index_from_character_pos(params.character_starts, params.seek.pos, 0, params.buffer->line_count); }break; case buffer_seek_line_char: { - line_index = (u32)params.seek.line - 1; + line_index = params.seek.line - 1; line_index = clamp_bottom(0, line_index); }break; case buffer_seek_unwrapped_xy: { - line_index = (u32)(params.seek.y / S.font_height); + line_index = (i32)(params.seek.y / S.font_height); line_index = clamp_bottom(0, line_index); }break; @@ -1437,7 +1396,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa default: InvalidCodePath; } - umem safe_line_index = line_index; + i32 safe_line_index = line_index; if (line_index >= params.buffer->line_count){ safe_line_index = params.buffer->line_count-1; } @@ -1459,8 +1418,8 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa // non-virtual character of the line. if (params.virtual_white){ S_stop.status = BLStatus_NeedLineShift; - S_stop.line_index = (u32)(S.next_cursor.line-1); - S_stop.wrap_line_index = (u32)(S.next_cursor.wrap_line-1); + S_stop.line_index = S.next_cursor.line-1; + S_stop.wrap_line_index = S.next_cursor.wrap_line-1; DrYield(1, S_stop); S.next_cursor.unwrapped_x += line_shift; @@ -1536,7 +1495,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa } // Main seek loop - S.i = (u32)S.next_cursor.pos; + S.i = S.next_cursor.pos; S.stream = null_buffer_stream; S.stream.use_termination_character = 1; @@ -1569,8 +1528,8 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa if (params.virtual_white){ S_stop.status = BLStatus_NeedLineShift; - S_stop.line_index = (u32)(S.next_cursor.line-1); - S_stop.wrap_line_index = (u32)(S.next_cursor.wrap_line-1); + S_stop.line_index = S.next_cursor.line-1; + S_stop.wrap_line_index = S.next_cursor.wrap_line-1; DrYield(2, S_stop); } @@ -1588,9 +1547,9 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa if (S.step.i >= S.wrap_unit_end){ S_stop.status = BLStatus_NeedWrapDetermination; - S_stop.line_index = (u32)(S.next_cursor.line-1); - S_stop.wrap_line_index = (u32)(S.next_cursor.wrap_line-1); - S_stop.pos = (u32)(S.step.i); + S_stop.line_index = S.next_cursor.line-1; + S_stop.wrap_line_index = S.next_cursor.wrap_line-1; + S_stop.pos = S.step.i; S_stop.x = S.next_cursor.wrapped_x; DrYield(4, S_stop); @@ -1602,8 +1561,8 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa ++S.next_cursor.wrap_line; if (params.virtual_white){ S_stop.status = BLStatus_NeedWrapLineShift; - S_stop.line_index = (u32)(S.next_cursor.line-1); - S_stop.wrap_line_index = (u32)(S.next_cursor.wrap_line-1); + S_stop.line_index = S.next_cursor.line-1; + S_stop.wrap_line_index = S.next_cursor.wrap_line-1; DrYield(3, S_stop); } @@ -1703,9 +1662,11 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa #undef DrReturn internal void -buffer_invert_edit_shift(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, u32 *str_pos, u32 max, i32 shift_amount){ - u32 pos = *str_pos; - u32 len = (u32)(edit.end - edit.start); +buffer_invert_edit_shift(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, + i32 *str_pos, i32 max, i32 shift_amount){ + i32 pos = *str_pos; + i32 len = edit.end - edit.start; + assert(pos >= 0); assert(pos + len <= max); *str_pos = pos + len; @@ -1717,40 +1678,34 @@ buffer_invert_edit_shift(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inve } inline void -buffer_invert_edit(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, u32 *str_pos, u32 max){ +buffer_invert_edit(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, + i32 *str_pos, i32 max){ buffer_invert_edit_shift(buffer, edit, inverse, strings, str_pos, max, 0); } typedef struct Buffer_Invert_Batch{ - umem i; + i32 i; i32 shift_amount; - u32 len; + i32 len; } Buffer_Invert_Batch; -internal b32 -buffer_invert_batch(Buffer_Invert_Batch *state, Gap_Buffer *buffer, Buffer_Edit *edits, u32 count, Buffer_Edit *inverse, char *strings, u32 *str_pos, u32 max){ +internal i32 +buffer_invert_batch(Buffer_Invert_Batch *state, Gap_Buffer *buffer, Buffer_Edit *edits, i32 count, + Buffer_Edit *inverse, char *strings, i32 *str_pos, i32 max){ i32 shift_amount = state->shift_amount; - umem i = state->i; + i32 i = state->i; Buffer_Edit *edit = edits + i; Buffer_Edit *inv_edit = inverse + i; - b32 result = false; + i32 result = 0; for (; i < count; ++i, ++edit, ++inv_edit){ if (*str_pos + edit->end - edit->start <= max){ buffer_invert_edit_shift(buffer, *edit, inv_edit, strings, str_pos, max, shift_amount); - - umem target_length = edit->end - edit->start; - umem edit_length = edit->len; - if (edit_length > target_length){ - shift_amount += (i32)(edit_length - target_length); - } - else{ - shift_amount -= (i32)(target_length - edit_length); - } + shift_amount += (edit->len - (edit->end - edit->start)); } else{ - result = true; - state->len = (u32)(edit->end - edit->start); + result = 1; + state->len = edit->end - edit->start; } } @@ -1807,8 +1762,8 @@ write_render_item(Render_Item_Write write, umem index, u32 codepoint, u32 flags) struct Buffer_Render_Params{ Gap_Buffer *buffer; Buffer_Render_Item *items; - u32 max; - u32 *count; + i32 max; + i32 *count; f32 port_x; f32 port_y; f32 clip_w; @@ -1827,8 +1782,8 @@ struct Buffer_Render_Params{ struct Buffer_Render_State{ Gap_Buffer_Stream stream; b32 still_looping; - umem i; - umem size; + i32 i; + i32 size; f32 shift_x; f32 shift_y; @@ -1838,11 +1793,11 @@ struct Buffer_Render_State{ Render_Item_Write write; f32 byte_advance; - umem line; - umem wrap_line; - umem wrap_unit_end; + i32 line; + i32 wrap_line; b32 skipping_whitespace; b32 first_of_the_line; + i32 wrap_unit_end; Translation_State tran; Translation_Emits emits; @@ -1888,8 +1843,8 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 if (params.virtual_white){ S_stop.status = BLStatus_NeedLineShift; - S_stop.line_index = (u32)(S.line); - S_stop.wrap_line_index = (u32)(S.wrap_line); + S_stop.line_index = S.line; + S_stop.wrap_line_index = S.wrap_line; DrYield(1, S_stop); } @@ -1923,9 +1878,9 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 if (!S.behavior.do_newline && S.step.i >= S.wrap_unit_end){ S_stop.status = BLStatus_NeedWrapDetermination; - S_stop.line_index = (u32)(S.line); - S_stop.wrap_line_index = (u32)(S.wrap_line); - S_stop.pos = (u32)(S.step.i); + S_stop.line_index = S.line; + S_stop.wrap_line_index = S.wrap_line; + S_stop.pos = S.step.i; S_stop.x = S.write.x - S.shift_x; DrYield(4, S_stop); @@ -1934,8 +1889,8 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 if (do_wrap && !S.first_of_the_line){ if (params.virtual_white){ S_stop.status = BLStatus_NeedWrapLineShift; - S_stop.line_index = (u32)(S.line); - S_stop.wrap_line_index = (u32)(S.wrap_line + 1); + S_stop.line_index = S.line; + S_stop.wrap_line_index = S.wrap_line + 1; DrYield(2, S_stop); } @@ -1973,8 +1928,8 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 if (params.virtual_white){ S_stop.status = BLStatus_NeedLineShift; - S_stop.line_index = (u32)(S.line+1); - S_stop.wrap_line_index = (u32)(S.wrap_line+1); + S_stop.line_index = S.line+1; + S_stop.wrap_line_index = S.wrap_line+1; DrYield(3, S_stop); S.skipping_whitespace = 1; diff --git a/4ed_file.cpp b/4ed_file.cpp index 7e407e53..6543dbcc 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -21,7 +21,7 @@ enum Edit_Pos_Set_Type{ struct File_Edit_Positions{ GUI_Scroll_Vars scroll; Full_Cursor cursor; - umem mark; + i32 mark; f32 preferred_x; i32 scroll_i; i32 last_set_type; @@ -54,7 +54,7 @@ edit_pos_set_scroll(File_Edit_Positions *edit_pos, GUI_Scroll_Vars scroll){ // struct Text_Effect{ - u32 start, end; + i32 start, end; u32 color; f32 seconds_down, seconds_max; }; @@ -109,20 +109,20 @@ global_const Editing_File_Settings null_editing_file_settings = {0}; struct Editing_File_State{ Gap_Buffer buffer; - u32 *wrap_line_index; - u32 wrap_max; + i32 *wrap_line_index; + i32 wrap_max; - u32 *character_starts; - u32 character_start_max; + i32 *character_starts; + i32 character_start_max; f32 *line_indents; - u32 line_indent_max; + i32 line_indent_max; - u32 wrap_line_count; + i32 wrap_line_count; - u32 *wrap_positions; - u32 wrap_position_count; - u32 wrap_position_max; + i32 *wrap_positions; + i32 wrap_position_count; + i32 wrap_position_max; Undo_Data undo; @@ -385,14 +385,14 @@ edit_pos_get_new(Editing_File *file, i32 index){ // inline Partial_Cursor -file_compute_cursor_from_pos(Editing_File *file, umem pos){ +file_compute_cursor_from_pos(Editing_File *file, i32 pos){ Partial_Cursor result = buffer_partial_from_pos(&file->state.buffer, pos); return(result); } inline Partial_Cursor -file_compute_cursor_from_line_character(Editing_File *file, umem line, umem character, b32 reversed){ - Partial_Cursor result = buffer_partial_from_line_character(&file->state.buffer, line, character, reversed); +file_compute_cursor_from_line_character(Editing_File *file, i32 line, i32 character){ + Partial_Cursor result = buffer_partial_from_line_character(&file->state.buffer, line, character); return(result); } @@ -407,12 +407,7 @@ file_compute_partial_cursor(Editing_File *file, Buffer_Seek seek, Partial_Cursor case buffer_seek_line_char: { - *cursor = file_compute_cursor_from_line_character(file, seek.line, seek.character, true); - }break; - - case buffer_seek_line_reverse_char: - { - *cursor = file_compute_cursor_from_line_character(file, seek.line, seek.character, false); + *cursor = file_compute_cursor_from_line_character(file, seek.line, seek.character); }break; default: diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 0e3c5b2f..6ce55376 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -146,7 +146,7 @@ struct File_Viewing_Data{ Editing_File *file; Full_Cursor temp_highlight; - umem temp_highlight_end_pos; + i32 temp_highlight_end_pos; b32 show_temp_highlight; b32 show_whitespace; @@ -289,9 +289,9 @@ view_file_height(View *view){ return (result); } -inline size_t +inline i32 view_get_cursor_pos(View *view){ - size_t result = 0; + i32 result = 0; if (view->file_data.show_temp_highlight){ result = view->file_data.temp_highlight.pos; } @@ -402,14 +402,14 @@ view_compute_cursor(System_Functions *system, View *view, Buffer_Seek seek, b32 Buffer_Cursor_Seek_State state = {0}; Buffer_Layout_Stop stop = {0}; - umem size = buffer_size(params.buffer); + i32 size = buffer_size(params.buffer); f32 line_shift = 0.f; - u32 wrap_unit_end = 0; - u32 wrap_array_index = 0; + b32 do_wrap = 0; + i32 wrap_unit_end = 0; - b32 do_wrap = false; - b32 first_wrap_determination = true; + b32 first_wrap_determination = 1; + i32 wrap_array_index = 0; do{ stop = buffer_cursor_seek(&state, params, line_shift, do_wrap, wrap_unit_end); @@ -478,13 +478,15 @@ view_compute_max_target_y(i32 lowest_line, i32 line_height, f32 view_height){ internal i32 file_compute_lowest_line(Editing_File *file, f32 font_height){ i32 lowest_line = 0; + Gap_Buffer *buffer = &file->state.buffer; if (file->settings.unwrapped_lines){ - lowest_line = (i32)(buffer->line_count); + lowest_line = buffer->line_count; } else{ - lowest_line = (i32)(file->state.wrap_line_index[buffer->line_count]); + lowest_line = file->state.wrap_line_index[buffer->line_count]; } + return(lowest_line); } @@ -529,7 +531,7 @@ view_move_view_to_cursor(View *view, GUI_Scroll_Vars *scroll, b32 center_view){ } } - target_y = clamp_i32(0, target_y, max_y); + target_y = clamp(0, target_y, max_y); if (cursor_x >= target_x + max_x){ target_x = ceil32(cursor_x - max_x/2); @@ -619,7 +621,7 @@ view_set_cursor_and_scroll(View *view, Full_Cursor cursor, b32 set_preferred_x, } inline void -view_set_temp_highlight(System_Functions *system, View *view, umem pos, umem end_pos){ +view_set_temp_highlight(System_Functions *system, View *view, i32 pos, i32 end_pos){ view->file_data.temp_highlight = view_compute_cursor(system, view, seek_pos(pos), 0); view->file_data.temp_highlight_end_pos = end_pos; view->file_data.show_temp_highlight = 1; @@ -741,8 +743,9 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, models->hook_save_file(&models->app_links, file->id.id); } - umem max = 0, size = 0; + i32 max = 0, size = 0; b32 dos_write_mode = file->settings.dos_write_mode; + char *data = 0; Gap_Buffer *buffer = &file->state.buffer; if (dos_write_mode){ @@ -752,9 +755,8 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, max = buffer_size(buffer); } - Temp_Memory temp = begin_temp_memory(&mem->part); - char *data = 0; b32 used_general = 0; + Temp_Memory temp = begin_temp_memory(&mem->part); char empty = 0; if (max == 0){ data = ∅ @@ -849,14 +851,14 @@ enum{ internal i32 file_grow_starts_as_needed(General_Memory *general, Gap_Buffer *buffer, i32 additional_lines){ b32 result = GROW_NOT_NEEDED; - u32 max = buffer->line_max; - u32 count = buffer->line_count; - u32 target_lines = count + additional_lines; + i32 max = buffer->line_max; + i32 count = buffer->line_count; + i32 target_lines = count + additional_lines; if (target_lines > max || max == 0){ - max = l_round_up_u32(target_lines + max, KB(1)); + max = l_round_up_i32(target_lines + max, KB(1)); - u32 *new_lines = (u32*)general_memory_reallocate(general, buffer->line_starts, sizeof(u32)*count, sizeof(u32)*max); + i32 *new_lines = (i32*)general_memory_reallocate(general, buffer->line_starts, sizeof(i32)*count, sizeof(f32)*max); if (new_lines){ result = GROW_SUCCESS; @@ -877,7 +879,7 @@ file_update_cursor_positions(System_Functions *system, Models *models, Editing_F for (View_Iter iter = file_view_iter_init(layout, file, 0); file_view_iter_good(iter); iter = file_view_iter_next(iter)){ - umem pos = view_get_cursor_pos(iter.view); + i32 pos = view_get_cursor_pos(iter.view); if (!iter.view->file_data.show_temp_highlight){ Full_Cursor cursor = view_compute_cursor(system, iter.view, seek_pos(pos), 0); @@ -896,20 +898,20 @@ file_update_cursor_positions(System_Functions *system, Models *models, Editing_F internal void file_measure_starts(General_Memory *general, Gap_Buffer *buffer){ if (!buffer->line_starts){ - u32 max = buffer->line_max = KB(1); - buffer->line_starts = (u32*)general_memory_allocate(general, max*sizeof(u32)); - TentativeAssert(buffer->line_starts != 0); + i32 max = buffer->line_max = KB(1); + buffer->line_starts = (i32*)general_memory_allocate(general, max*sizeof(i32)); + TentativeAssert(buffer->line_starts); // TODO(allen): when unable to allocate? } Buffer_Measure_Starts state = {0}; while (buffer_measure_starts(&state, buffer)){ - u32 count = state.count; - u32 max = buffer->line_max; + i32 count = state.count; + i32 max = buffer->line_max; max = ((max + 1) << 1); { - u32 *new_lines = (u32*)general_memory_reallocate(general, buffer->line_starts, sizeof(u32)*count, sizeof(u32)*max); + i32 *new_lines = (i32*)general_memory_reallocate(general, buffer->line_starts, sizeof(i32)*count, sizeof(i32)*max); // TODO(allen): when unable to grow? TentativeAssert(new_lines); @@ -919,18 +921,19 @@ file_measure_starts(General_Memory *general, Gap_Buffer *buffer){ } } -// NOTE(allen): These calls assumes that the buffer's line starts are already correct, and that the buffer's line_count is correct. +// NOTE(allen): These calls assumes that the buffer's line starts are already correct, +// and that the buffer's line_count is correct. internal void -file_allocate_metadata_as_needed(General_Memory *general, Gap_Buffer *buffer, void **mem, u32 *mem_max_count, u32 count, u32 item_size){ +file_allocate_metadata_as_needed(General_Memory *general, Gap_Buffer *buffer, void **mem, i32 *mem_max_count, i32 count, i32 item_size){ if (*mem == 0){ - u32 max = ((count+1)*2); + i32 max = ((count+1)*2); max = (max+(0x3FF))&(~(0x3FF)); *mem = general_memory_allocate(general, max*item_size); *mem_max_count = max; } else if (*mem_max_count < count){ - u32 old_max = *mem_max_count; - u32 max = ((count+1)*2); + i32 old_max = *mem_max_count; + i32 max = ((count+1)*2); max = (max+(0x3FF))&(~(0x3FF)); void *new_mem = general_memory_reallocate(general, *mem, item_size*old_max, item_size*max); @@ -943,7 +946,7 @@ file_allocate_metadata_as_needed(General_Memory *general, Gap_Buffer *buffer, vo inline void file_allocate_character_starts_as_needed(General_Memory *general, Editing_File *file){ - file_allocate_metadata_as_needed(general, &file->state.buffer, (void**)&file->state.character_starts, &file->state.character_start_max, file->state.buffer.line_count, sizeof(u32)); + file_allocate_metadata_as_needed(general, &file->state.buffer, (void**)&file->state.character_starts, &file->state. character_start_max, file->state.buffer.line_count, sizeof(i32)); } internal void @@ -989,9 +992,9 @@ struct Code_Wrap_State{ b32 in_pp_body; Code_Wrap_X plane_wrap_x; - u32 *line_starts; - u32 line_index; - u32 next_line_start; + i32 *line_starts; + i32 line_index; + i32 next_line_start; f32 x; b32 consume_newline; @@ -1391,7 +1394,7 @@ struct Wrap_Current_Shift{ }; internal Wrap_Current_Shift -get_current_shift(Code_Wrap_State *wrap_state, u32 next_line_start){ +get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start){ Wrap_Current_Shift result = {0}; result.shift = wrap_state->wrap_x.paren_nesting[wrap_state->wrap_x.paren_safe_top]; @@ -1589,7 +1592,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, if (use_tokens){ Code_Wrap_State original_wrap_state = wrap_state; - u32 next_line_start = buffer_size(params.buffer); + i32 next_line_start = buffer_size(params.buffer); if (stop.line_index+1 < params.buffer->line_count){ next_line_start = params.buffer->line_starts[stop.line_index+1]; } @@ -1625,12 +1628,16 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, if (wrap_state.token_ptr->type == CPP_TOKEN_COMMENT || wrap_state.token_ptr->type == CPP_TOKEN_STRING_CONSTANT){ + i32 i = wrap_state.token_ptr->start; + i32 end_i = i + wrap_state.token_ptr->size; - u32 i = wrap_state.token_ptr->start; - u32 end_i = i + wrap_state.token_ptr->size; + if (i < wrap_state.i){ + i = wrap_state.i; + } - i = clamp_bottom((u32)wrap_state.i, i); - end_i = clamp_top(end_i, (u32)wrap_state.next_line_start); + if (end_i > wrap_state.next_line_start){ + end_i = wrap_state.next_line_start; + } f32 x = wrap_state.x; @@ -1729,12 +1736,12 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, current_shift = get_current_shift(&wrap_state, next_line_start); - b32 next_token_is_on_line = false; + b32 next_token_is_on_line = 0; if (wrap_state.token_ptr->start < next_line_start){ - next_token_is_on_line = true; + next_token_is_on_line = 1; } - u32 next_wrap_position = (u32)step.position_end; + i32 next_wrap_position = step.position_end; f32 wrap_x = step.final_x; if (wrap_state.token_ptr->start > step.position_start && next_wrap_position < wrap_state.token_ptr->start && next_token_is_on_line){ next_wrap_position = wrap_state.token_ptr->start; @@ -1923,6 +1930,8 @@ file_set_min_base_width(System_Functions *system, Models *models, Editing_File * internal void file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String val, b8 read_only = 0){ + + //Font_Set *font_set = models->font_set; General_Memory *general = &models->mem.general; Partition *part = &models->mem.part; Open_File_Hook_Function *hook_open_file = models->hook_open_file; @@ -1931,8 +1940,8 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * file->state = null_editing_file_state; Gap_Buffer_Init init = buffer_begin_init(&file->state.buffer, val.str, val.size); for (; buffer_init_need_more(&init); ){ - umem page_size = buffer_init_page_size(&init); - page_size = l_round_up_umem(page_size, KB(4)); + i32 page_size = buffer_init_page_size(&init); + page_size = l_round_up_i32(page_size, KB(4)); if (page_size < KB(4)){ page_size = KB(4); } @@ -1945,7 +1954,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * b32 init_success = buffer_end_init(&init, part->base + part->pos, scratch_size); AllowLocal(init_success); Assert(init_success); - if (buffer_size(&file->state.buffer) < (u32)val.size){ + if (buffer_size(&file->state.buffer) < val.size){ file->settings.dos_write_mode = 1; } file_synchronize_times(system, file); @@ -2045,10 +2054,11 @@ Job_Callback_Sig(job_full_lex){ General_Memory *general = (General_Memory*)data[1]; Gap_Buffer *buffer = &file->state.buffer; - u32 text_size = buffer_size(buffer); - u32 aligned_buffer_size = (text_size + 3)&(~3); + i32 text_size = buffer_size(buffer); - while (memory->size < (umem)aligned_buffer_size){ + i32 aligned_buffer_size = (text_size + 3)&(~3); + + while (memory->size < aligned_buffer_size){ system->grow_thread_memory(memory); } @@ -2063,7 +2073,7 @@ Job_Callback_Sig(job_full_lex){ // TODO(allen): deduplicate this against relex char *chunks[3]; - umem chunk_sizes[3]; + i32 chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2078,10 +2088,10 @@ Job_Callback_Sig(job_full_lex){ do{ char *chunk = chunks[chunk_index]; - umem chunk_size = chunk_sizes[chunk_index]; + i32 chunk_size = chunk_sizes[chunk_index]; i32 result = - cpp_lex_step(&lex, chunk, (i32)chunk_size, text_size, &tokens, 2048); + cpp_lex_step(&lex, chunk, chunk_size, text_size, &tokens, 2048); switch (result){ case LexResult_NeedChunk: ++chunk_index; break; @@ -2205,7 +2215,7 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ // TODO(allen): deduplicate this against relex char *chunks[3]; - umem chunk_sizes[3]; + i32 chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2222,9 +2232,9 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ do{ char *chunk = chunks[chunk_index]; - umem chunk_size = chunk_sizes[chunk_index]; + i32 chunk_size = chunk_sizes[chunk_index]; - i32 result = cpp_lex_step(&lex, chunk, (i32)chunk_size, text_size, &tokens, NO_OUT_LIMIT); + i32 result = cpp_lex_step(&lex, chunk, chunk_size, text_size, &tokens, NO_OUT_LIMIT); switch (result){ case LexResult_NeedChunk: ++chunk_index; break; @@ -2281,7 +2291,7 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ } internal b32 -file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *file, u32 start_i, u32 end_i, i32 shift_amount){ +file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, i32 shift_amount){ General_Memory *general = &mem->general; Partition *part = &mem->part; @@ -2313,7 +2323,7 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi Cpp_Relex_Data state = cpp_relex_init(array, start_i, end_i, shift_amount); char *chunks[3]; - umem chunk_sizes[3]; + i32 chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2326,16 +2336,17 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi i32 chunk_index = 0; char *chunk = chunks[chunk_index]; - umem chunk_size = chunk_sizes[chunk_index]; + i32 chunk_size = chunk_sizes[chunk_index]; - while (!cpp_relex_is_start_chunk(&state, chunk, (i32)chunk_size)){ + while (!cpp_relex_is_start_chunk(&state, chunk, chunk_size)){ ++chunk_index; chunk = chunks[chunk_index]; chunk_size = chunk_sizes[chunk_index]; } for(;;){ - Cpp_Lex_Result lex_result =cpp_relex_step(&state, chunk, (i32)chunk_size, size, array, &relex_array); + Cpp_Lex_Result lex_result = + cpp_relex_step(&state, chunk, chunk_size, size, array, &relex_array); switch (lex_result){ case LexResult_NeedChunk: @@ -2355,7 +2366,7 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi doublebreak:; if (inline_lex){ - u32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array); + i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array); if (new_count > array->max_count){ i32 new_max = l_round_up_i32(new_count, KB(1)); array->tokens = (Cpp_Token*) @@ -2421,13 +2432,10 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, Gap_Buffer *buffer = &file->state.buffer; Cpp_Token_Array *array = &file->state.token_array; - umem remaining = partition_remaining(part); - umem token_size = sizeof(Cpp_Token); - Temp_Memory temp = begin_temp_memory(part); Cpp_Token_Array relex_array; relex_array.count = 0; - relex_array.max_count = (u32)(remaining/token_size); + relex_array.max_count = partition_remaining(part) / sizeof(Cpp_Token); relex_array.tokens = push_array(part, Cpp_Token, relex_array.max_count); i32 size = buffer_size(buffer); @@ -2435,7 +2443,7 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, Cpp_Relex_Data state = cpp_relex_init(array, start_i, end_i, shift_amount); char *chunks[3]; - umem chunk_sizes[3]; + i32 chunk_sizes[3]; chunks[0] = buffer->data; chunk_sizes[0] = buffer->size1; @@ -2446,18 +2454,18 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, chunks[2] = 0; chunk_sizes[2] = 0; - umem chunk_index = 0; + i32 chunk_index = 0; char *chunk = chunks[chunk_index]; - umem chunk_size = chunk_sizes[chunk_index]; + i32 chunk_size = chunk_sizes[chunk_index]; - while (!cpp_relex_is_start_chunk(&state, chunk, (i32)chunk_size)){ + while (!cpp_relex_is_start_chunk(&state, chunk, chunk_size)){ ++chunk_index; chunk = chunks[chunk_index]; chunk_size = chunk_sizes[chunk_index]; } for(;;){ - Cpp_Lex_Result lex_result = cpp_relex_step(&state, chunk, (i32)chunk_size, size, array, &relex_array); + Cpp_Lex_Result lex_result = cpp_relex_step(&state, chunk, chunk_size, size, array, &relex_array); switch (lex_result){ case LexResult_NeedChunk: @@ -2474,7 +2482,7 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, doublebreak:; i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array); - if ((u32)new_count > array->max_count){ + if (new_count > array->max_count){ i32 new_max = l_round_up_i32(new_count, KB(1)); array->tokens = (Cpp_Token*)general_memory_reallocate(general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token)); array->max_count = new_max; @@ -2488,10 +2496,10 @@ file_relex_serial(Mem_Options *mem, Editing_File *file, i32 start_i, i32 end_i, } internal void -undo_stack_grow_string(General_Memory *general, Edit_Stack *stack, umem extra_size){ - u32 old_max = stack->max; +undo_stack_grow_string(General_Memory *general, Edit_Stack *stack, i32 extra_size){ + i32 old_max = stack->max; u8 *old_str = stack->strings; - u32 new_max = old_max*2 + (u32)(extra_size); + i32 new_max = old_max*2 + extra_size; u8 *new_str = (u8*)general_memory_reallocate(general, old_str, old_max, new_max); stack->strings = new_str; stack->max = new_max; @@ -2508,27 +2516,27 @@ undo_stack_grow_edits(General_Memory *general, Edit_Stack *stack){ } internal void -child_stack_grow_string(General_Memory *general, Small_Edit_Stack *stack, umem extra_size){ - umem old_max = stack->max; +child_stack_grow_string(General_Memory *general, Small_Edit_Stack *stack, i32 extra_size){ + i32 old_max = stack->max; u8 *old_str = stack->strings; - umem new_max = old_max*2 + extra_size; + i32 new_max = old_max*2 + extra_size; u8 *new_str = (u8*)general_memory_reallocate(general, old_str, old_max, new_max); stack->strings = new_str; - stack->max = (u32)new_max; + stack->max = new_max; } internal void -child_stack_grow_edits(General_Memory *general, Small_Edit_Stack *stack, umem amount){ - umem old_max = stack->edit_max; +child_stack_grow_edits(General_Memory *general, Small_Edit_Stack *stack, i32 amount){ + i32 old_max = stack->edit_max; Buffer_Edit *old_eds = stack->edits; - umem new_max = old_max*2 + amount; + i32 new_max = old_max*2 + amount; Buffer_Edit *new_eds = (Buffer_Edit*)general_memory_reallocate(general, old_eds, old_max*sizeof(Buffer_Edit), new_max*sizeof(Buffer_Edit)); stack->edits = new_eds; - stack->edit_max = (u32)new_max; + stack->edit_max = new_max; } internal i32 -undo_children_push(General_Memory *general, Small_Edit_Stack *children, Buffer_Edit *edits, u32 edit_count, u8 *strings, umem string_size){ +undo_children_push(General_Memory *general, Small_Edit_Stack *children, Buffer_Edit *edits, i32 edit_count, u8 *strings, i32 string_size){ i32 result = children->edit_count; if (children->edit_count + edit_count > children->edit_max){ child_stack_grow_edits(general, children, edit_count); @@ -2543,12 +2551,12 @@ undo_children_push(General_Memory *general, Small_Edit_Stack *children, Buffer_E Buffer_Edit *edit = children->edits + children->edit_count; i32 start_pos = children->size; - for (u32 i = 0; i < edit_count; ++i, ++edit){ + for (i32 i = 0; i < edit_count; ++i, ++edit){ edit->str_start += start_pos; } children->edit_count += edit_count; - children->size += (u32)string_size; + children->size += string_size; return result; } @@ -2628,7 +2636,7 @@ undo_stack_pop(Edit_Stack *stack){ if (stack->edit_count > 0){ Edit_Step *edit = stack->edits + (--stack->edit_count); if (edit->child_count == 0){ - stack->size -= (u32)edit->edit.len; + stack->size -= edit->edit.len; } } } @@ -2671,7 +2679,7 @@ file_post_redo(General_Memory *general, Editing_File *file, Edit_Step step){ } inline void -file_post_history_block(Editing_File *file, u32 pos){ +file_post_history_block(Editing_File *file, i32 pos){ Assert(file->state.undo.history_head_block < pos); Assert(pos < file->state.undo.history.edit_count); @@ -2780,7 +2788,7 @@ view_cursor_move(View *view, Full_Cursor cursor){ } inline void -view_cursor_move(System_Functions *system, View *view, umem pos){ +view_cursor_move(System_Functions *system, View *view, i32 pos){ Full_Cursor cursor = view_compute_cursor(system, view, seek_pos(pos), 0); view_cursor_move(view, cursor); } @@ -2942,8 +2950,8 @@ file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step if (restore_redos){ Edit_Step *redo_start = redo_end; - u32 steps_of_redo = 0; - u32 strings_of_redo = 0; + i32 steps_of_redo = 0; + i32 strings_of_redo = 0; { i32 undo_count = 0; while (redo_start->type == ED_REDO || redo_start->type == ED_UNDO){ @@ -2953,7 +2961,7 @@ file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step } else{ ++steps_of_redo; - strings_of_redo += (u32)redo_start->edit.len; + strings_of_redo += redo_start->edit.len; } } else{ @@ -2967,15 +2975,11 @@ file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step ++redo_start; ++redo_end; - if (file->state.undo.redo.edit_count + steps_of_redo > file->state.undo.redo.edit_max){ - + if (file->state.undo.redo.edit_count + steps_of_redo > file->state.undo.redo.edit_max) undo_stack_grow_edits(general, &file->state.undo.redo); - } - if (file->state.undo.redo.size + strings_of_redo > file->state.undo.redo.max){ - + if (file->state.undo.redo.size + strings_of_redo > file->state.undo.redo.max) undo_stack_grow_string(general, &file->state.undo.redo, strings_of_redo); - } u8 *str_src = file->state.undo.history.strings + redo_end->edit.str_start; u8 *str_dest_base = file->state.undo.redo.strings; @@ -2985,8 +2989,8 @@ file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step Edit_Step *edit_dest = file->state.undo.redo.edits + file->state.undo.redo.edit_count + steps_of_redo; { - u32 undo_count = 0; - for (u32 i = 0; i < steps_of_redo;){ + i32 undo_count = 0; + for (i32 i = 0; i < steps_of_redo;){ --edit_src; str_src -= edit_src->edit.len; if (edit_src->type == ED_REDO){ @@ -2999,7 +3003,7 @@ file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step --edit_dest; *edit_dest = *edit_src; - str_redo_pos -= (u32)edit_dest->edit.len; + str_redo_pos -= edit_dest->edit.len; edit_dest->edit.str_start = str_redo_pos; memcpy(str_dest_base + str_redo_pos, str_src, edit_dest->edit.len); @@ -3157,13 +3161,13 @@ file_edit_cursor_fix(System_Functions *system, Models *models, Editing_File *fil if (view->file_data.file == file){ Assert(view->edit_pos); - umem cursor_pos = cursors[cursor_count++].pos; + i32 cursor_pos = cursors[cursor_count++].pos; Full_Cursor new_cursor = view_compute_cursor(system, view, seek_pos(cursor_pos), 0); GUI_Scroll_Vars scroll = view->edit_pos->scroll; view->edit_pos->mark = cursors[cursor_count++].pos; - i32 new_scroll_i = (i32)cursors[cursor_count++].pos; + i32 new_scroll_i = cursors[cursor_count++].pos; if (view->edit_pos->scroll_i != new_scroll_i){ view->edit_pos->scroll_i = new_scroll_i; @@ -3219,14 +3223,14 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file Partition *part = &mem->part; char *str = (char*)spec.str; - u32 start = (u32)spec.step.edit.start; - u32 end = (u32)spec.step.edit.end; - u32 str_len = (u32)spec.step.edit.len; + i32 start = spec.step.edit.start; + i32 end = spec.step.edit.end; + i32 str_len = spec.step.edit.len; - umem scratch_size = partition_remaining(part); + i32 scratch_size = partition_remaining(part); Assert(scratch_size > 0); - umem request_amount = 0; + i32 request_amount = 0; Assert(end <= buffer_size(&file->state.buffer)); while (buffer_replace_range(&file->state.buffer, start, end, str, str_len, &shift_amount, part->base + part->pos, scratch_size, &request_amount)){ void *new_data = 0; @@ -3281,7 +3285,8 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file } internal void -file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, Edit_Spec spec, History_Mode history_mode, i32 batch_type){ +file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, + Edit_Spec spec, History_Mode history_mode, i32 batch_type){ Mem_Options *mem = &models->mem; General_Memory *general = &mem->general; @@ -3301,9 +3306,9 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, Assert(spec.step.first_child < file->state.undo.children.edit_count); Assert(batch_size >= 0); - u32 scratch_size = (u32)partition_remaining(part); - Buffer_Batch_State state = {0}; - umem request_amount = 0; + i32 scratch_size = partition_remaining(part); + Buffer_Batch_State state = {}; + i32 request_amount = 0; while (buffer_batch_edit_step(&state, &file->state.buffer, batch, (char*)str_base, batch_size, part->base + part->pos, scratch_size, &request_amount)){ @@ -3329,10 +3334,10 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, Buffer_Edit *last_edit = batch + batch_size - 1; if (!file->settings.virtual_white){ - file_relex_parallel(system, mem, file, (u32)first_edit->start, (u32)last_edit->end, shift_total); + file_relex_parallel(system, mem, file, first_edit->start, last_edit->end, shift_total); } else{ - file_relex_serial(mem, file, (u32)first_edit->start, (u32)last_edit->end, shift_total); + file_relex_serial(mem, file, first_edit->start, last_edit->end, shift_total); } } }break; @@ -3354,27 +3359,13 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, for (; token < end_token; ++token){ original = *token; for (; edit < end_edit && edit->start <= original.start; ++edit){ - umem target_length = edit->end - edit->start; - umem edit_length = edit->len; - if (edit_length > target_length){ - local_shift = (i32)(edit_length - target_length); - } - else{ - local_shift = -(i32)(target_length - edit_length); - } + local_shift = (edit->len - (edit->end - edit->start)); shift_amount += local_shift; } token->start += shift_amount; local_shift = 0; for (; edit < end_edit && edit->start < original.start + original.size; ++edit){ - umem target_length = edit->end - edit->start; - umem edit_length = edit->len; - if (edit_length > target_length){ - local_shift = (i32)(edit_length - target_length); - } - else{ - local_shift = -(i32)(target_length - edit_length); - } + local_shift += (edit->len - (edit->end - edit->start)); } token->size += local_shift; shift_amount += local_shift; @@ -3432,7 +3423,7 @@ view_replace_range(System_Functions *system, Models *models, View *view, } inline void -view_post_paste_effect(View *view, f32 seconds, u32 start, u32 size, u32 color){ +view_post_paste_effect(View *view, f32 seconds, i32 start, i32 size, u32 color){ Editing_File *file = view->file_data.file; file->state.paste_effect.start = start; @@ -3454,7 +3445,7 @@ main_style(Models *models){ internal void apply_history_edit(System_Functions *system, Models *models, Editing_File *file, View *view, Edit_Stack *stack, Edit_Step step, History_Mode history_mode){ - Edit_Spec spec = {0}; + Edit_Spec spec = {}; spec.step = step; if (step.child_count == 0){ @@ -3468,7 +3459,7 @@ apply_history_edit(System_Functions *system, Models *models, Editing_File *file, view->edit_pos->mark = view->edit_pos->cursor.pos; Style *style = main_style(models); - view_post_paste_effect(view, 0.333f, (u32)step.edit.start, (u32)step.edit.len, style->main.undo_color); + view_post_paste_effect(view, 0.333f, step.edit.start, step.edit.len, style->main.undo_color); } } else{ @@ -3499,11 +3490,11 @@ view_history_step(System_Functions *system, Models *models, View *view, History_ Assert(file); Assert(view->edit_pos); - b32 do_history_step = false; + b32 do_history_step = 0; Edit_Step step = {}; if (history_mode == hist_backward){ if (file->state.undo.edit_history_cursor > 0){ - do_history_step = true; + do_history_step = 1; step = file->state.undo.history.edits[--file->state.undo.edit_history_cursor]; } } @@ -3511,9 +3502,9 @@ view_history_step(System_Functions *system, Models *models, View *view, History_ if (file->state.undo.edit_history_cursor < file->state.undo.history.edit_count){ Assert(((file->state.undo.history.edit_count - file->state.undo.edit_history_cursor) & 1) == 0); step = file->state.undo.history.edits[--file->state.undo.history.edit_count]; - file->state.undo.history.size -= (u32)step.edit.len; + file->state.undo.history.size -= step.edit.len; ++file->state.undo.edit_history_cursor; - do_history_step = true; + do_history_step = 1; } } @@ -3525,7 +3516,7 @@ view_history_step(System_Functions *system, Models *models, View *view, History_ } internal String* -working_set_next_clipboard_string(General_Memory *general, Working_Set *working, u32 str_size){ +working_set_next_clipboard_string(General_Memory *general, Working_Set *working, i32 str_size){ String *result = 0; i32 clipboard_current = working->clipboard_current; if (working->clipboard_size == 0){ @@ -3594,22 +3585,22 @@ working_set_clipboard_roll_down(Working_Set *working){ internal void clipboard_copy(System_Functions *system, General_Memory *general, Working_Set *working, Range range, Editing_File *file){ - umem size = range.end - range.start; - String *dest = working_set_next_clipboard_string(general, working, (u32)size); + i32 size = range.end - range.start; + String *dest = working_set_next_clipboard_string(general, working, size); buffer_stringify(&file->state.buffer, range.start, range.end, dest->str); - dest->size = (i32)size; + dest->size = size; system->post_clipboard(*dest); } internal Edit_Spec -file_compute_edit(Mem_Options *mem, Editing_File *file, Buffer_Edit *edits, char *str_base, umem str_size, Buffer_Edit *inverse_array, char *inv_str, u32 inv_max, u32 edit_count, i32 batch_type){ +file_compute_edit(Mem_Options *mem, Editing_File *file, Buffer_Edit *edits, char *str_base, i32 str_size, Buffer_Edit *inverse_array, char *inv_str, i32 inv_max, i32 edit_count, i32 batch_type){ General_Memory *general = &mem->general; - u32 inv_str_pos = 0; + i32 inv_str_pos = 0; Buffer_Invert_Batch state = {}; if (buffer_invert_batch(&state, &file->state.buffer, edits, edit_count, inverse_array, inv_str, &inv_str_pos, inv_max)){ - InvalidCodePath; + Assert(0); } i32 first_child = undo_children_push(general, &file->state.undo.children, edits, edit_count, (u8*)(str_base), str_size); @@ -4474,7 +4465,8 @@ show_gui_line(GUI_Target *target, String *string, i32 indent_level, i32 h_align, } internal void -show_gui_int(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message, i32 x){ +show_gui_int(GUI_Target *target, String *string, + i32 indent_level, i32 h_align, char *message, i32 x){ string->size = 0; append_label(string, indent_level, message); append_padding(string, '-', h_align); @@ -4484,7 +4476,8 @@ show_gui_int(GUI_Target *target, String *string, i32 indent_level, i32 h_align, } internal void -show_gui_u64(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message, u64 x){ +show_gui_u64(GUI_Target *target, String *string, + i32 indent_level, i32 h_align, char *message, u64 x){ string->size = 0; append_label(string, indent_level, message); append_padding(string, '-', h_align); @@ -4494,17 +4487,8 @@ show_gui_u64(GUI_Target *target, String *string, i32 indent_level, i32 h_align, } internal void -show_gui_umem(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message, umem x){ - string->size = 0; - append_label(string, indent_level, message); - append_padding(string, '-', h_align); - append_s_char(string, ' '); - append_u64_to_str(string, x); - gui_do_text_field(target, *string, null_string); -} - -internal void -show_gui_int_int(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message, i32 x, i32 m){ +show_gui_int_int(GUI_Target *target, String *string, + i32 indent_level, i32 h_align, char *message, i32 x, i32 m){ string->size = 0; append_label(string, indent_level, message); append_padding(string, '-', h_align); @@ -4554,11 +4538,13 @@ show_gui_scroll(GUI_Target *target, String *string, } internal void -show_gui_cursor(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message,Full_Cursor cursor){ - show_gui_line (target, string, indent_level , 0, message, 0); - show_gui_umem (target, string, indent_level+1, h_align, " pos ", cursor.pos); - show_gui_umem (target, string, indent_level+1, h_align, " line ", cursor.line); - show_gui_umem (target, string, indent_level+1, h_align, " column ", cursor.character); +show_gui_cursor(GUI_Target *target, String *string, + i32 indent_level, i32 h_align, char *message, + Full_Cursor cursor){ + show_gui_line (target, string, indent_level, 0, message, 0); + show_gui_int (target, string, indent_level+1, h_align, " pos ", cursor.pos); + show_gui_int (target, string, indent_level+1, h_align, " line ", cursor.line); + show_gui_int (target, string, indent_level+1, h_align, " column ", cursor.character); show_gui_float(target, string, indent_level+1, h_align, " unwrapped_x ", cursor.unwrapped_x); show_gui_float(target, string, indent_level+1, h_align, " unwrapped_y ", cursor.unwrapped_y); show_gui_float(target, string, indent_level+1, h_align, " wrapped_x ", cursor.wrapped_x); @@ -5380,9 +5366,9 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su string.size = 0; append_ss(&string, make_lit_string("part memory: ")); - append_int_to_str(&string, (i32)part->pos); + append_int_to_str(&string, part->pos); append_s_char(&string, '/'); - append_int_to_str(&string, (i32)part->max); + append_int_to_str(&string, part->max); gui_do_text_field(target, string, empty_str); #if !defined(FED_DEBUG_MEM_H) @@ -5397,7 +5383,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su append_ss(&string, make_lit_string(" free: ")); } - append_int_to_str(&string, (i32)bubble->size); + append_int_to_str(&string, bubble->size); append_padding(&string, ' ', 40); gui_do_text_field(target, string, empty_str); } @@ -5470,7 +5456,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su #define SHOW_GUI_INT(n, h, str, v) show_gui_int(target, &string, n, h, " " str " ", v) #define SHOW_GUI_INT_INT(n, h, str, v, m) show_gui_int_int(target, &string, n, h, " " str " ", v, m) #define SHOW_GUI_U64(n, h, str, v) show_gui_u64(target, &string, n, h, " " str " ", v) -#define SHOW_GUI_UMEM(n, h, str, v) show_gui_umem(target, &string, n, h, " " str " ", v) #define SHOW_GUI_ID(n, h, str, v) show_gui_id(target, &string, n, h, " " str, v) #define SHOW_GUI_FLOAT(n, h, str, v) show_gui_float(target, &string, n, h, " " str " ", v) #define SHOW_GUI_BOOL(n, h, str, v) do { if (v) { show_gui_line(target, &string, n, h, " " str " ", "true"); }\ @@ -5510,8 +5495,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su SHOW_GUI_LINE(1, "file data:"); SHOW_GUI_BOOL(2, h_align, "has file", view_ptr->file_data.file); SHOW_GUI_BOOL(2, h_align, "show temp highlight", view_ptr->file_data.show_temp_highlight); - SHOW_GUI_UMEM(2, h_align, "start temp highlight", view_ptr->file_data.temp_highlight.pos); - SHOW_GUI_UMEM(2, h_align, "end temp highlight", view_ptr->file_data.temp_highlight_end_pos); + SHOW_GUI_INT (2, h_align, "start temp highlight", view_ptr->file_data.temp_highlight.pos); + SHOW_GUI_INT (2, h_align, "end temp highlight", view_ptr->file_data.temp_highlight_end_pos); SHOW_GUI_BOOL(2, h_align, "show whitespace", view_ptr->file_data.show_whitespace); SHOW_GUI_BOOL(2, h_align, "locked", view_ptr->file_data.file_locked); @@ -5529,7 +5514,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su SHOW_GUI_BLANK (2); SHOW_GUI_CURSOR(2, h_align, "cursor:", edit_pos->cursor); SHOW_GUI_BLANK (2); - SHOW_GUI_UMEM (2, h_align, "mark", edit_pos->mark); + SHOW_GUI_INT (2, h_align, "mark", edit_pos->mark); SHOW_GUI_FLOAT (2, h_align, "preferred_x", edit_pos->preferred_x); SHOW_GUI_INT (2, h_align, "scroll_i", edit_pos->scroll_i); } @@ -5543,7 +5528,9 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su SHOW_GUI_BLANK (0); SHOW_GUI_LINE (1, "gui target"); - SHOW_GUI_INT_INT(2, h_align, "gui partition", (int32_t)view_ptr->gui_target.push.pos, (int32_t)view_ptr->gui_target.push.max); + SHOW_GUI_INT_INT(2, h_align, "gui partition", + view_ptr->gui_target.push.pos, + view_ptr->gui_target.push.max); SHOW_GUI_BLANK (2); SHOW_GUI_ID (2, h_align, "active", view_ptr->gui_target.active); @@ -5679,7 +5666,7 @@ do_step_file_view(System_Functions *system, View *view, i32_Rect rect, b32 is_ac GUI_Target *target = &view->gui_target; GUI_Interpret_Result interpret_result = {0}; - vars.target_y = clamp_i32(0, vars.target_y, max_y); + vars.target_y = clamp(0, vars.target_y, max_y); result.vars = vars; result.region = region; @@ -5812,7 +5799,7 @@ do_step_file_view(System_Functions *system, View *view, i32_Rect rect, b32 is_ac if (gui_id_eq(target->mouse_hot, id)){ v = unlerp(gui_session.scroll_top, (f32)my, gui_session.scroll_bottom); - v = clamp_f32(0.f, v, 1.f); + v = clamp(0.f, v, 1.f); result.vars.target_y = round32(lerp(0.f, v, (f32)max_y)); gui_activate_scrolling(target); @@ -5827,7 +5814,7 @@ do_step_file_view(System_Functions *system, View *view, i32_Rect rect, b32 is_ac result.vars.target_y += user_input->mouse.wheel*target->delta; result.vars.target_y = - clamp_i32(0, result.vars.target_y, max_y); + clamp(0, result.vars.target_y, max_y); gui_activate_scrolling(target); result.is_animating = 1; } @@ -5927,9 +5914,7 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act f32 left_side_space = 0; - umem remaining = partition_remaining(part); - umem render_item_size = sizeof(Buffer_Render_Item); - u32 max = (u32)(remaining / render_item_size); + i32 max = partition_remaining(part) / sizeof(Buffer_Render_Item); Buffer_Render_Item *items = push_array(part, Buffer_Render_Item, max); Font_ID font_id = file->settings.font_id; @@ -5951,9 +5936,9 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act render_cursor = view_compute_cursor(system, view, seek_unwrapped_xy(0, scroll_y, 0), 1); } - view->edit_pos->scroll_i = (i32)render_cursor.pos; + view->edit_pos->scroll_i = render_cursor.pos; - u32 count = 0; + i32 count = 0; { b32 wrapped = !file->settings.unwrapped_lines; @@ -5980,11 +5965,11 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act Buffer_Layout_Stop stop = {0}; f32 line_shift = 0.f; - b32 do_wrap = false; - u32 wrap_unit_end = 0; + b32 do_wrap = 0; + i32 wrap_unit_end = 0; - b32 first_wrap_determination = true; - u32 wrap_array_index = 0; + b32 first_wrap_determination = 1; + i32 wrap_array_index = 0; do{ stop = buffer_render_data(&state, params, line_shift, do_wrap, wrap_unit_end); @@ -6021,22 +6006,22 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act }while(stop.status != BLStatus_Finished); } - u32 cursor_begin = 0, cursor_end = 0; + i32 cursor_begin = 0, cursor_end = 0; u32 cursor_color = 0, at_cursor_color = 0; if (view->file_data.show_temp_highlight){ - cursor_begin = (u32)view->file_data.temp_highlight.pos; - cursor_end = (u32)view->file_data.temp_highlight_end_pos; + cursor_begin = view->file_data.temp_highlight.pos; + cursor_end = view->file_data.temp_highlight_end_pos; cursor_color = style->main.highlight_color; at_cursor_color = style->main.at_highlight_color; } else{ - cursor_begin = (u32)view->edit_pos->cursor.pos; + cursor_begin = view->edit_pos->cursor.pos; cursor_end = cursor_begin + 1; cursor_color = style->main.cursor_color; at_cursor_color = style->main.at_cursor_color; } - u32 token_i = 0; + i32 token_i = 0; u32 main_color = style->main.default_color; u32 special_color = style->main.special_character_color; u32 ghost_color = style->main.ghost_character_color; @@ -6049,12 +6034,12 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act u32 mark_color = style->main.mark_color; Buffer_Render_Item *item = items; Buffer_Render_Item *item_end = item + count; - umem prev_ind = max_umem; + i32 prev_ind = -1; u32 highlight_color = 0; u32 highlight_this_color = 0; for (; item < item_end; ++item){ - umem ind = item->index; + i32 ind = item->index; highlight_this_color = 0; if (tokens_use && ind != prev_ind){ Cpp_Token current_token = token_array.tokens[token_i-1]; @@ -6234,9 +6219,9 @@ draw_file_bar(System_Functions *system, Render_Target *target, View *view, Editi char bar_space[526]; String bar_text = make_fixed_width_string(bar_space); append_ss (&bar_text, make_lit_string(" L#")); - append_int_to_str(&bar_text, (int32_t)view->edit_pos->cursor.line); + append_int_to_str(&bar_text, view->edit_pos->cursor.line); append_ss (&bar_text, make_lit_string(" C#")); - append_int_to_str(&bar_text, (int32_t)view->edit_pos->cursor.character); + append_int_to_str(&bar_text, view->edit_pos->cursor.character); append_ss(&bar_text, make_lit_string(" -")); diff --git a/4ed_layout.cpp b/4ed_layout.cpp index 6dd8dcd0..4fa49eec 100644 --- a/4ed_layout.cpp +++ b/4ed_layout.cpp @@ -504,16 +504,16 @@ layout_update_pos_step(Editing_Layout *layout, i32 divider_id, i32_Rect rect, i3 i32 pos = abs_pos[divider_id]; i32_Rect r1 = rect, r2 = rect; f32 lpos = unlerp((f32)p0, (f32)pos, (f32)p1); - lpos = clamp_f32(0.f, lpos, 1.f); + lpos = clamp(0.f, lpos, 1.f); div->pos = lpos; if (div->v_divider){ - pos = clamp_i32(r1.x0, pos, r2.x1); + pos = clamp(r1.x0, pos, r2.x1); r1.x1 = pos; r2.x0 = pos; } else{ - pos = clamp_i32(r1.y0, pos, r2.y1); + pos = clamp(r1.y0, pos, r2.y1); r1.y1 = pos; r2.y0 = pos; } diff --git a/4ed_math.h b/4ed_math.h index 04fb1a01..be489847 100644 --- a/4ed_math.h +++ b/4ed_math.h @@ -432,21 +432,21 @@ unlerp(f32 a, f32 x, f32 b){ } inline f32 -clamp_f32(f32 a, f32 n, f32 z){ +clamp(f32 a, f32 n, f32 z){ if (n < a) n = a; else if (n > z) n = z; return (n); } inline i32 -clamp_i32(i32 a, i32 n, i32 z){ +clamp(i32 a, i32 n, i32 z){ if (n < a) n = a; else if (n > z) n = z; return (n); } inline u32 -clamp_u32(u32 a, u32 n, u32 z){ +clamp(u32 a, u32 n, u32 z){ if (n < a) n = a; else if (n > z) n = z; return (n); diff --git a/4ed_system.h b/4ed_system.h index e2f12321..1e304200 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -47,7 +47,7 @@ typedef Sys_Load_File_Sig(System_Load_File); #define Sys_Load_Close_Sig(name) b32 name(Plat_Handle handle) typedef Sys_Load_Close_Sig(System_Load_Close); -#define Sys_Save_File_Sig(name) b32 name(char *filename, char *buffer, umem size) +#define Sys_Save_File_Sig(name) b32 name(char *filename, char *buffer, u32 size) typedef Sys_Save_File_Sig(System_Save_File); // file changes diff --git a/4ed_undo.cpp b/4ed_undo.cpp index 98d32c05..f0e416b1 100644 --- a/4ed_undo.cpp +++ b/4ed_undo.cpp @@ -26,33 +26,33 @@ struct Edit_Step{ struct{ b32 can_merge; Buffer_Edit edit; - u32 next_block; - u32 prev_block; + i32 next_block; + i32 prev_block; }; struct{ - u32 first_child; - u32 inverse_first_child; - u32 inverse_child_count; - u32 special_type; + i32 first_child; + i32 inverse_first_child; + i32 inverse_child_count; + i32 special_type; }; }; - u32 child_count; + i32 child_count; }; struct Edit_Stack{ u8 *strings; - u32 size, max; + i32 size, max; Edit_Step *edits; - u32 edit_count, edit_max; + i32 edit_count, edit_max; }; struct Small_Edit_Stack{ u8 *strings; - u32 size, max; + i32 size, max; Buffer_Edit *edits; - u32 edit_count, edit_max; + i32 edit_count, edit_max; }; struct Undo_Data{ @@ -61,9 +61,8 @@ struct Undo_Data{ Edit_Stack history; Small_Edit_Stack children; - u32 history_block_count; - u32 history_head_block; - u32 edit_history_cursor; + i32 history_block_count, history_head_block; + i32 edit_history_cursor; b32 current_block_normal; }; diff --git a/4ed_working_set.cpp b/4ed_working_set.cpp index 55dca405..4150c39f 100644 --- a/4ed_working_set.cpp +++ b/4ed_working_set.cpp @@ -204,7 +204,7 @@ working_set_init(Working_Set *working_set, Partition *partition, General_Memory { i32 item_size = sizeof(File_Name_Entry); i32 table_size = working_set->file_max; - umem mem_size = table_required_mem_size(table_size, item_size); + i32 mem_size = table_required_mem_size(table_size, item_size); void *mem = general_memory_allocate(general, mem_size); memset(mem, 0, mem_size); table_init_memory(&working_set->canon_table, mem, table_size, item_size); @@ -212,9 +212,9 @@ working_set_init(Working_Set *working_set, Partition *partition, General_Memory // NOTE(allen): init name table { - u32 item_size = sizeof(File_Name_Entry); - u32 table_size = working_set->file_max; - umem mem_size = table_required_mem_size(table_size, item_size); + i32 item_size = sizeof(File_Name_Entry); + i32 table_size = working_set->file_max; + i32 mem_size = table_required_mem_size(table_size, item_size); void *mem = general_memory_allocate(general, mem_size); memset(mem, 0, mem_size); table_init_memory(&working_set->name_table, mem, table_size, item_size); @@ -225,8 +225,8 @@ inline void working_set__grow_if_needed(Table *table, General_Memory *general, void *arg, Hash_Function *hash_func, Compare_Function *comp_func){ if (table_at_capacity(table)){ Table btable = {0}; - u32 new_max = table->max * 2; - umem mem_size = table_required_mem_size(new_max, table->item_size); + i32 new_max = table->max * 2; + i32 mem_size = table_required_mem_size(new_max, table->item_size); void *mem = general_memory_allocate(general, mem_size); table_init_memory(&btable, mem, new_max, table->item_size); table_clear(&btable); diff --git a/4tech_defines.h b/4tech_defines.h index f11c18a2..b9ecf77e 100644 --- a/4tech_defines.h +++ b/4tech_defines.h @@ -135,18 +135,6 @@ inline u32 round_up_pot_u32(u32 x){ #define min_u32 ((u32)0) #define min_u64 ((u64)0) -#if defined(FTECH_32_BIT) -#define max_imem max_i64 -#define min_imem min_i64 -#define max_umem max_u64 -#define min_umem min_u64 -#else -#define max_imem max_i32 -#define min_imem min_i32 -#define max_umem max_u32 -#define min_umem min_u32 -#endif - #define Bit_0 (1 << 0) #define Bit_1 (1 << 1) #define Bit_2 (1 << 2) diff --git a/internal_4coder_tests.cpp b/internal_4coder_tests.cpp index fe65facc..59184519 100644 --- a/internal_4coder_tests.cpp +++ b/internal_4coder_tests.cpp @@ -16,7 +16,6 @@ Allen Webster #include "4coder_default_include.cpp" -#if 0 #include #include @@ -225,17 +224,12 @@ CUSTOM_COMMAND_SIG(run_all_tests){ exec_command(app, load_unicode_file); exec_command(app, edit_giant_file); } -#endif static void test_get_bindings(Bind_Helper *context){ - -#if 0 begin_map(context, mapid_global); bind(context, key_f3, MDFR_NONE, run_all_tests); end_map(context); -#endif - } #define BIND_4CODER_TESTS(context) test_get_bindings(context) diff --git a/linux_release_compat.c b/linux_release_compat.c index 6722c636..5dafb8f4 100644 --- a/linux_release_compat.c +++ b/linux_release_compat.c @@ -1,10 +1,12 @@ #include -// Link to the memcpy symbol with version 2.2.5 instead of the newer 2.14 one since they are functionaly equivalent, but using the old one allows 4coder to run on older distros without glibc >= 2.14 +// Link to the memcpy symbol with version 2.2.5 instead of the newer 2.14 one +// since they are functionaly equivalent, but using the old one allows 4coder +// to run on older distros without glibc >= 2.14 extern "C" { - asm (".symver memcpy, memcpy@GLIBC_2.2.5"); - void *__wrap_memcpy(void *dest, const void *src, size_t n){ - return memcpy(dest, src, n); - } +asm (".symver memcpy, memcpy@GLIBC_2.2.5"); +void *__wrap_memcpy(void *dest, const void *src, size_t n){ + return memcpy(dest, src, n); +} } diff --git a/power/4coder_experiments.cpp b/power/4coder_experiments.cpp index a1ea1720..b5fb94eb 100644 --- a/power/4coder_experiments.cpp +++ b/power/4coder_experiments.cpp @@ -23,7 +23,7 @@ TYPE: 'build-target' #include static float -get_line_y(Application_Links *app, View_Summary *view, size_t line){ +get_line_y(Application_Links *app, View_Summary *view, int32_t line){ Full_Cursor cursor = {0}; view_compute_cursor(app, view, seek_line_char(line, 1), &cursor); float y = cursor.wrapped_y; @@ -37,30 +37,26 @@ CUSTOM_COMMAND_SIG(kill_rect){ View_Summary view = get_active_view(app, AccessOpen); Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen); - pos_Rect rect = get_line_x_rect(&view); + i32_Rect rect = get_line_x_rect(&view); bool32 unwrapped = view.unwrapped_lines; - int32_t line_count = (int32_t)(rect.y1 - rect.y0 + 1); - for (int32_t line_i = line_count; line_i >= 0; --line_i){ - size_t line = rect.y0 + line_i; - size_t start = 0; - size_t end = 0; + for (int32_t line = rect.y1; line >= rect.y0; --line){ + int32_t start = 0; + int32_t end = 0; - bool32 success = true; + bool32 success = 1; Full_Cursor cursor = {0}; float y = get_line_y(app, &view, line); if (success){ - Buffer_Seek seek = seek_xy((float)rect.x0, y, 0, unwrapped); - success = view_compute_cursor(app, &view, seek, &cursor); + success = view_compute_cursor(app, &view, seek_xy((float)rect.x0, y, 0, unwrapped), &cursor); } start = cursor.pos; if (success){ - Buffer_Seek seek = seek_xy((float)rect.x0, y, 0, unwrapped); - success = view_compute_cursor(app, &view, seek, &cursor); + success = view_compute_cursor(app, &view, seek_xy((float)rect.x1, y, 0, unwrapped), &cursor); } end = cursor.pos; @@ -71,19 +67,16 @@ CUSTOM_COMMAND_SIG(kill_rect){ } static void -pad_buffer_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, size_t line, char padchar, size_t target){ +pad_buffer_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, int32_t line, char padchar, int32_t target){ Partial_Cursor start = {0}; Partial_Cursor end = {0}; - Buffer_Seek seek_start = seek_line_char(line, 1); - Buffer_Seek seek_end = seek_line_reverse_char(line, 1); - - if (buffer_compute_cursor(app, buffer, seek_start, &start)){ - if (start.line == line){ - if (buffer_compute_cursor(app, buffer, seek_end, &end)){ + if (buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &start)){ + if (buffer_compute_cursor(app, buffer, seek_line_char(line, 65536), &end)){ + if (start.line == line){ if (end.character-1 < target){ Temp_Memory temp = begin_temp_memory(part); - size_t size = target - (end.character-1); + int32_t size = target - (end.character-1); char *str = push_array(part, char, size); memset(str, ' ', size); buffer_replace_range(app, buffer, end.pos, end.pos, str, size); @@ -137,14 +130,14 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ Buffer_Rect rect = get_rect(&view); - size_t start_line = view.cursor.line; - size_t pos = view.cursor.character-1; + int32_t start_line = view.cursor.line; + int32_t pos = view.cursor.character-1; - for (size_t i = rect.line0; i <= rect.line1; ++i){ + for (int32_t i = rect.line0; i <= rect.line1; ++i){ pad_buffer_line(app, &global_part, &buffer, i, ' ', pos); } - int32_t line_count = (int32_t)(rect.line1 - rect.line0 + 1); + int32_t line_count = rect.line1 - rect.line0 + 1; for (;;){ User_Input in = get_user_input(app, EventOnAnyKey, EventOnEsc | EventOnButton); @@ -157,12 +150,10 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ Buffer_Edit *edit = push_array(part, Buffer_Edit, line_count); Buffer_Edit *edits = edit; - for (int32_t i = 0; i <= line_count; ++i){ - size_t line = i + rect.line0; + for (int32_t i = rect.line0; i <= rect.line1; ++i){ Partial_Cursor cursor = {0}; - Buffer_Seek seek = seek_line_char(line, pos+1); - if (buffer_compute_cursor(app, &buffer, seek, &cursor)){ + if (buffer_compute_cursor(app, &buffer, seek_line_char(i, pos+1), &cursor)){ edit->str_start = 0; edit->len = 1; edit->start = cursor.pos; @@ -187,12 +178,10 @@ CUSTOM_COMMAND_SIG(multi_line_edit){ Buffer_Edit *edit = push_array(part, Buffer_Edit, line_count); Buffer_Edit *edits = edit; - for (int32_t i = 0; i <= line_count; ++i){ - size_t line = i + rect.line0; + for (int32_t i = rect.line0; i <= rect.line1; ++i){ Partial_Cursor cursor = {0}; - Buffer_Seek seek = seek_line_char(line, pos+1); - if (buffer_compute_cursor(app, &buffer, seek, &cursor)){ + if (buffer_compute_cursor(app, &buffer, seek_line_char(i, pos+1), &cursor)){ edit->str_start = 0; edit->len = 0; edit->start = cursor.pos-1; @@ -227,11 +216,11 @@ enum{ }; static bool32 -find_scope_top(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ +find_scope_top(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - size_t position = 0; + int32_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index; @@ -287,11 +276,11 @@ find_scope_top(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, } static bool32 -find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ +find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - size_t position = 0; + int32_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index+1; @@ -348,11 +337,11 @@ find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, size_t start_p } static bool32 -find_next_scope(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ +find_next_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - size_t position = 0; + int32_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index+1; @@ -428,11 +417,11 @@ find_next_scope(Application_Links *app, Buffer_Summary *buffer, size_t start_pos } static bool32 -find_prev_scope(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, uint32_t flags, size_t *end_pos_out){ +find_prev_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){ Cpp_Get_Token_Result get_result = {0}; bool32 success = 0; - size_t position = 0; + int32_t position = 0; if (buffer_get_token_index(app, buffer, start_pos, &get_result)){ int32_t token_index = get_result.token_index-1; @@ -507,7 +496,7 @@ find_prev_scope(Application_Links *app, Buffer_Summary *buffer, size_t start_pos } static void -view_set_to_region(Application_Links *app, View_Summary *view, size_t major_pos, size_t minor_pos, float normalized_threshold){ +view_set_to_region(Application_Links *app, View_Summary *view, int32_t major_pos, int32_t minor_pos, float normalized_threshold){ Range range = make_range(major_pos, minor_pos); bool32 bottom_major = false; if (major_pos == range.max){ @@ -562,8 +551,8 @@ CUSTOM_COMMAND_SIG(highlight_surrounding_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_scope_top(app, &buffer, start_pos, FindScope_Parent, &top)){ view_set_cursor(app, &view, seek_pos(top), true); if (find_scope_bottom(app, &buffer, start_pos, FindScope_Parent | FindScope_EndOfToken, &bottom)){ @@ -582,8 +571,8 @@ CUSTOM_COMMAND_SIG(highlight_first_child_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_next_scope(app, &buffer, start_pos, 0, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -598,8 +587,8 @@ CUSTOM_COMMAND_SIG(highlight_next_sibling_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_next_scope(app, &buffer, start_pos, FindScope_NextSibling, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -614,8 +603,8 @@ CUSTOM_COMMAND_SIG(highlight_prev_sibling_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_prev_scope(app, &buffer, start_pos, FindScope_NextSibling, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -630,8 +619,8 @@ CUSTOM_COMMAND_SIG(highlight_next_scope_absolute){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_next_scope(app, &buffer, start_pos, 0, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -646,8 +635,8 @@ CUSTOM_COMMAND_SIG(highlight_prev_scope_absolute){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t start_pos = view.cursor.pos; - size_t top = 0, bottom = 0; + int32_t start_pos = view.cursor.pos; + int32_t top = 0, bottom = 0; if (find_prev_scope(app, &buffer, start_pos, 0, &top)){ if (find_scope_bottom(app, &buffer, top, FindScope_EndOfToken, &bottom)){ view_set_cursor(app, &view, seek_pos(top), true); @@ -671,6 +660,7 @@ CUSTOM_COMMAND_SIG(place_in_scope){ range.max = buffer_get_line_end(app, &buffer, lines.max); bool32 do_full = false; + if (lines.min < lines.max){ do_full = true; } @@ -697,11 +687,11 @@ CUSTOM_COMMAND_SIG(place_in_scope){ --max_adjustment; } - size_t min_pos = range.min + min_adjustment; - size_t max_pos = range.max + max_adjustment; + int32_t min_pos = range.min + min_adjustment; + int32_t max_pos = range.max + max_adjustment; - size_t cursor_pos = min_pos; - size_t mark_pos = max_pos; + int32_t cursor_pos = min_pos; + int32_t mark_pos = max_pos; if (view.cursor.pos > view.mark.pos){ cursor_pos = max_pos; @@ -735,11 +725,13 @@ CUSTOM_COMMAND_SIG(delete_current_scope){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t top = view.cursor.pos; - size_t bottom = view.mark.pos; + int32_t top = view.cursor.pos; + int32_t bottom = view.mark.pos; if (top > bottom){ - Swap(size_t, top, bottom); + int32_t x = top; + top = bottom; + bottom = x; } if (buffer_get_char(app, &buffer, top) == '{' && buffer_get_char(app, &buffer, bottom-1) == '}'){ @@ -948,10 +940,10 @@ parse_statement_down(Application_Links *app, Statement_Parser *parser, Cpp_Token } static bool32 -find_whole_statement_down(Application_Links *app, Buffer_Summary *buffer, size_t pos, size_t *start_out, size_t *end_out){ +find_whole_statement_down(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t *start_out, int32_t *end_out){ bool32 result = false; - size_t start = pos; - size_t end = start; + int32_t start = pos; + int32_t end = start; Cpp_Get_Token_Result get_result = {0}; @@ -990,11 +982,13 @@ CUSTOM_COMMAND_SIG(scope_absorb_down){ View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - size_t top = view.cursor.pos; - size_t bottom = view.mark.pos; + int32_t top = view.cursor.pos; + int32_t bottom = view.mark.pos; if (top > bottom){ - Swap(size_t, top, bottom); + int32_t x = top; + top = bottom; + bottom = x; } Partition *part = &global_part; @@ -1006,8 +1000,7 @@ CUSTOM_COMMAND_SIG(scope_absorb_down){ char *string_space = push_array(part, char, range.end - range.start); buffer_read_range(app, &buffer, range.start, range.end, string_space); - int32_t string_length = (int32_t)(range.end - range.start); - String string = make_string(string_space, string_length); + String string = make_string(string_space, range.end - range.start); string = skip_chop_whitespace(string); int32_t newline_count = 0; diff --git a/power/4coder_miblo_numbers.cpp b/power/4coder_miblo_numbers.cpp index fc2197e1..803e9dad 100644 --- a/power/4coder_miblo_numbers.cpp +++ b/power/4coder_miblo_numbers.cpp @@ -14,9 +14,9 @@ TYPE: 'drop-in-command-pack' #include "4coder_helper/4coder_helper.h" #include "4coder_helper/4coder_streaming.h" -static bool32 -get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, size_t *numeric_start, size_t *numeric_end){ - bool32 result = false; +static int32_t +get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, int32_t *numeric_start, int32_t *numeric_end){ + int32_t result = 0; char current = buffer_get_char(app, buffer, start_pos); @@ -25,16 +25,16 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, siz int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; - size_t pos = start_pos; + int32_t pos = start_pos; - size_t pos1 = 0; - size_t pos2 = 0; + int32_t pos1 = 0; + int32_t pos2 = 0; if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){ int32_t still_looping = 1; while (still_looping){ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= stream.start; --pos){ char at_pos = stream.data[pos]; if (!char_is_numeric(at_pos)){ ++pos; @@ -50,7 +50,7 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, siz still_looping = 1; while (still_looping){ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < stream.end; ++pos){ char at_pos = stream.data[pos]; if (!char_is_numeric(at_pos)){ goto double_break_2; @@ -61,7 +61,7 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, siz double_break_2:; pos2 = pos; - result = true; + result = 1; *numeric_start = pos1; *numeric_end = pos2; } @@ -72,19 +72,18 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, siz } struct Miblo_Number_Info{ - size_t start, end; + int32_t start, end; int32_t x; }; -static bool32 -get_numeric_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t pos, Miblo_Number_Info *info){ - bool32 result = false; +static int32_t +get_numeric_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Miblo_Number_Info *info){ + int32_t result = 0; - size_t numeric_start = 0, numeric_end = 0; + int32_t numeric_start = 0, numeric_end = 0; if (get_numeric_string_at_cursor(app, buffer, pos, &numeric_start, &numeric_end)){ - int32_t string_length = (int32_t)(numeric_end - numeric_start); char numeric_string[1024]; - String str = make_string(numeric_string, string_length, sizeof(numeric_string)); + String str = make_string(numeric_string, numeric_end - numeric_start, sizeof(numeric_string)); if (str.size < str.memory_size){ buffer_read_range(app, buffer, numeric_start, numeric_end, numeric_string); @@ -94,7 +93,7 @@ get_numeric_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t pos info->start = numeric_start; info->end = numeric_end; info->x = x; - result = true; + result = 1; } } @@ -132,9 +131,9 @@ CUSTOM_COMMAND_SIG(miblo_decrement_basic){ // NOTE(allen): miblo time stamp format // (h+:)?m?m:ss -static bool32 -get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t start_pos, size_t *timestamp_start, size_t *timestamp_end){ - bool32 result = false; +static int32_t +get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, int32_t *timestamp_start, int32_t *timestamp_end){ + int32_t result = 0; char current = buffer_get_char(app, buffer, start_pos); @@ -143,16 +142,16 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, s int32_t chunk_size = sizeof(chunk); Stream_Chunk stream = {0}; - size_t pos = start_pos; + int32_t pos = start_pos; - size_t pos1 = 0; - size_t pos2 = 0; + int32_t pos1 = 0; + int32_t pos2 = 0; if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){ int32_t still_looping = 1; while (still_looping){ - for (; pos >= (size_t)stream.start; --pos){ + for (; pos >= stream.start; --pos){ char at_pos = stream.data[pos]; if (!(char_is_numeric(at_pos) || at_pos == ':')){ ++pos; @@ -168,7 +167,7 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, s still_looping = 1; while (still_looping){ - for (; pos < (size_t)stream.end; ++pos){ + for (; pos < stream.end; ++pos){ char at_pos = stream.data[pos]; if (!(char_is_numeric(at_pos) || at_pos == ':')){ goto double_break_2; @@ -179,7 +178,7 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_Summary *buffer, s double_break_2:; pos2 = pos; - result = true; + result = 1; *timestamp_start = pos1; *timestamp_end = pos2; } @@ -272,19 +271,18 @@ timestamp_to_str(String *dest, Miblo_Timestamp t){ } struct Miblo_Timestamp_Info{ - size_t start, end; + int32_t start, end; Miblo_Timestamp time; }; -static bool32 -get_timestamp_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t pos, Miblo_Timestamp_Info *info){ - bool32 result = false; +static int32_t +get_timestamp_at_cursor(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Miblo_Timestamp_Info *info){ + int32_t result = 0; - size_t timestamp_start = 0, timestamp_end = 0; + int32_t timestamp_start = 0, timestamp_end = 0; if (get_timestamp_string_at_cursor(app, buffer, pos, ×tamp_start, ×tamp_end)){ - int32_t string_length = (int32_t)(timestamp_end - timestamp_start); char timestamp_string[1024]; - String str = make_string(timestamp_string, string_length, sizeof(timestamp_string)); + String str = make_string(timestamp_string, timestamp_end - timestamp_start, sizeof(timestamp_string)); if (str.size < str.memory_size){ buffer_read_range(app, buffer, timestamp_start, timestamp_end, timestamp_string); @@ -298,10 +296,10 @@ get_timestamp_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t p if (count_colons == 1 || count_colons == 2){ Miblo_Timestamp t = {0}; - bool32 success = false; + int32_t success = 0; - size_t i = 0; - size_t number_start[3], number_end[3]; + int32_t i = 0; + int32_t number_start[3], number_end[3]; for (int32_t k = 0; k < 3; ++k){ number_start[k] = i; for (; i <= str.size; ++i){ @@ -317,42 +315,27 @@ get_timestamp_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t p } if (count_colons == 2){ + t.hour = str_to_int(make_string(str.str + number_start[0], number_end[0] - number_start[0])); - int32_t number_length = (int32_t)(number_end[0] - number_start[0]); - String number_string = make_string(str.str + number_start[0], number_length); - t.hour = str_to_int(number_string); - - number_length = (int32_t)(number_end[1] - number_start[1]); - if (number_length == 2){ + if (number_end[1] - number_start[1] == 2){ - number_string = make_string(str.str + number_start[1], number_length); - t.minute = str_to_int(number_string); + t.minute = str_to_int(make_string(str.str + number_start[1], number_end[1] - number_start[1])); - number_length = (int32_t)(number_end[2] - number_start[2]); - if (number_length == 2){ + if (number_end[2] - number_start[2] == 2){ + t.second = str_to_int(make_string(str.str + number_start[2], number_end[2] - number_start[2])); - number_string = make_string(str.str + number_start[2], number_length); - t.second = str_to_int(number_string); - - success = true; + success = 1; } } } else{ - - int32_t number_length = (int32_t)(number_end[0] - number_start[0]); - if (number_length == 2 || number_length == 1){ + if (number_end[0] - number_start[0] == 2 || number_end[0] - number_start[0] == 1){ + t.minute = str_to_int(make_string(str.str + number_start[0], number_end[0] - number_start[0])); - String number_string = make_string(str.str + number_start[0], number_length); - t.minute = str_to_int(number_string); - - number_length = (int32_t)(number_end[1] - number_start[1]); - if (number_length == 2){ + if (number_end[1] - number_start[1] == 2){ + t.second = str_to_int(make_string(str.str + number_start[1], number_end[1] - number_start[1])); - number_string = make_string(str.str + number_start[1], number_length); - t.second = str_to_int(number_string); - - success = true; + success = 1; } } } @@ -361,7 +344,7 @@ get_timestamp_at_cursor(Application_Links *app, Buffer_Summary *buffer, size_t p info->start = timestamp_start; info->end = timestamp_end; info->time = t; - result = true; + result = 1; } } } diff --git a/vc140.pdb b/vc140.pdb deleted file mode 100644 index 02119923348e34b8071a9beb3112e92ae3d47da5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 36864 zcmeI(u}T9m7y#g_+KLvzQAF_eLTz!-!L90K2kGMGAPPDJ@3_$F_byB!8}1@_#p_xwOwuF1nZ9v#Y$d(W=$*c4t4|sy7--i>texEXHz{ z&BU}2TOM1A`Cif!AV7cs0RjXF5FkK+009CMBJlnl1OWmB2oNAZfB*pk1PBlyFy#U( zQ(m9)2oNAZfB*pk1PBlyK!5;&5UMZD(sue*A%5ro+hVF@Antn|LK2`;r)MlPIVUZq}Oi!1PBlyK!5-N0t5&UAVA>12;A12rRv)2 zQ8^ZTaQ%GqaQv}%e|q=$`LzDkHz>tHYQyn%xLN#Zc-oi%0RjXF5FkK+009C72oM+} zfwb?>W7{dLDV_hPxfI27|Ne7tR!@Kc0RjXF5FkK+009C72#mWxB`&ad|G)f)`~S}W z$NkM(9{~ac2oNAZfB*pk1PBlq2#mV_Z~s5=F(N>K009C72oNAZfB*pk(;)Bz0c9tE From f9d2414281baf969a463502c1cf3fd7a16b636af Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 23 Mar 2017 15:16:39 -0400 Subject: [PATCH 08/17] Revert "Converting to proper use of umem everywhere (kind of went off on a tanget there :D)" This reverts commit fe7c0fe47e95c432ee71cde3b6d6dbfcfb913b24. --- 4coder_API/app_functions.h | 30 +- 4coder_API/types.h | 39 +-- 4coder_auto_indent.cpp | 12 +- 4coder_default_framework.h | 14 +- 4coder_function_list.cpp | 14 +- 4coder_helper/4coder_helper.h | 26 +- 4coder_helper/4coder_long_seek.h | 25 +- 4coder_helper/4coder_seek_types.h | 10 +- 4coder_lib/4coder_mem.h | 18 +- 4coder_project_commands.cpp | 4 +- 4cpp/4cpp_lexer.h | 60 ++-- 4cpp/4cpp_lexer_types.h | 34 +-- 4ed_api_implementation.cpp | 10 +- 4ed_buffer.cpp | 472 +++++++++++++++--------------- 4ed_buffer_model.h | 2 +- 4ed_file_track.h | 8 +- 4ed_file_track_general.cpp | 25 +- 4ed_file_view.cpp | 20 +- 4ed_math.h | 7 - 4ed_system.h | 9 +- 4ed_system_shared.cpp | 11 + 4ed_system_shared.h | 26 +- 4ed_translation.cpp | 8 +- 4tech_defines.h | 4 - meta/meta_parser.cpp | 2 +- meta/out_context.cpp | 22 +- power/4coder_experiments.cpp | 11 +- win32_4ed.cpp | 72 +++-- win32_4ed_file_track.cpp | 69 ++--- 29 files changed, 533 insertions(+), 531 deletions(-) diff --git a/4coder_API/app_functions.h b/4coder_API/app_functions.h index 4f4c666e..5f1ab6f7 100644 --- a/4coder_API/app_functions.h +++ b/4coder_API/app_functions.h @@ -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_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_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_BATCH_EDIT_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, char *str, size_t str_len, Buffer_Edit *edits, uint32_t edit_count, Buffer_Batch_Edit_Type type) +#define BUFFER_BATCH_EDIT_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, char *str, int32_t str_len, Buffer_Edit *edits, int32_t edit_count, Buffer_Batch_Edit_Type type) #define BUFFER_ADD_MARKERS_SIG(n) Marker_Handle n(Application_Links *app, Buffer_Summary *buffer, uint32_t marker_count) #define BUFFER_SET_MARKERS_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Marker_Handle marker, uint32_t first_marker_index, uint32_t marker_count, Marker *source_markers) #define BUFFER_GET_MARKERS_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Marker_Handle marker, uint32_t first_marker_index, uint32_t marker_count, Marker *markers_out) @@ -60,9 +60,9 @@ struct Application_Links; #define GET_FILE_LIST_SIG(n) File_List n(Application_Links *app, char *dir, int32_t len) #define FREE_FILE_LIST_SIG(n) void n(Application_Links *app, File_List list) #define SET_GUI_UP_DOWN_KEYS_SIG(n) void n(Application_Links *app, int16_t up_key, int16_t down_key) -#define MEMORY_ALLOCATE_SIG(n) void* n(Application_Links *app, size_t size) -#define MEMORY_SET_PROTECTION_SIG(n) bool32 n(Application_Links *app, void *ptr, size_t size, Memory_Protect_Flags flags) -#define MEMORY_FREE_SIG(n) void n(Application_Links *app, void *ptr, size_t size) +#define MEMORY_ALLOCATE_SIG(n) void* n(Application_Links *app, int32_t size) +#define MEMORY_SET_PROTECTION_SIG(n) bool32 n(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags) +#define MEMORY_FREE_SIG(n) void n(Application_Links *app, void *ptr, int32_t size) #define FILE_EXISTS_SIG(n) bool32 n(Application_Links *app, char *filename, int32_t len) #define DIRECTORY_CD_SIG(n) bool32 n(Application_Links *app, char *dir, int32_t *len, int32_t capacity, char *rel_path, int32_t rel_len) #define GET_4ED_PATH_SIG(n) int32_t n(Application_Links *app, char *out, int32_t capacity) @@ -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_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_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_batch_edit(Application_Links *app, Buffer_Summary *buffer, char *str, size_t str_len, Buffer_Edit *edits, uint32_t edit_count, Buffer_Batch_Edit_Type type){return(app->buffer_batch_edit(app, buffer, str, str_len, edits, edit_count, type));} +static inline bool32 buffer_batch_edit(Application_Links *app, Buffer_Summary *buffer, char *str, int32_t str_len, Buffer_Edit *edits, int32_t edit_count, Buffer_Batch_Edit_Type type){return(app->buffer_batch_edit(app, buffer, str, str_len, edits, edit_count, type));} static inline Marker_Handle buffer_add_markers(Application_Links *app, Buffer_Summary *buffer, uint32_t marker_count){return(app->buffer_add_markers(app, buffer, marker_count));} static inline bool32 buffer_set_markers(Application_Links *app, Buffer_Summary *buffer, Marker_Handle marker, uint32_t first_marker_index, uint32_t marker_count, Marker *source_markers){return(app->buffer_set_markers(app, buffer, marker, first_marker_index, marker_count, source_markers));} static inline bool32 buffer_get_markers(Application_Links *app, Buffer_Summary *buffer, Marker_Handle marker, uint32_t first_marker_index, uint32_t marker_count, Marker *markers_out){return(app->buffer_get_markers(app, buffer, marker, first_marker_index, marker_count, markers_out));} @@ -428,9 +428,9 @@ static inline int32_t directory_get_hot(Application_Links *app, char *out, int32 static inline File_List get_file_list(Application_Links *app, char *dir, int32_t len){return(app->get_file_list(app, dir, len));} static inline void free_file_list(Application_Links *app, File_List list){(app->free_file_list(app, list));} static inline void set_gui_up_down_keys(Application_Links *app, int16_t up_key, int16_t down_key){(app->set_gui_up_down_keys(app, up_key, down_key));} -static inline void* memory_allocate(Application_Links *app, size_t size){return(app->memory_allocate(app, size));} -static inline bool32 memory_set_protection(Application_Links *app, void *ptr, size_t size, Memory_Protect_Flags flags){return(app->memory_set_protection(app, ptr, size, flags));} -static inline void memory_free(Application_Links *app, void *ptr, size_t size){(app->memory_free(app, ptr, size));} +static inline void* memory_allocate(Application_Links *app, int32_t size){return(app->memory_allocate(app, size));} +static inline bool32 memory_set_protection(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags){return(app->memory_set_protection(app, ptr, size, flags));} +static inline void memory_free(Application_Links *app, void *ptr, int32_t size){(app->memory_free(app, ptr, size));} static inline bool32 file_exists(Application_Links *app, char *filename, int32_t len){return(app->file_exists(app, filename, len));} static inline bool32 directory_cd(Application_Links *app, char *dir, int32_t *len, int32_t capacity, char *rel_path, int32_t rel_len){return(app->directory_cd(app, dir, len, capacity, rel_path, rel_len));} static inline int32_t get_4ed_path(Application_Links *app, char *out, int32_t capacity){return(app->get_4ed_path(app, out, capacity));} @@ -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_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_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_batch_edit(Application_Links *app, Buffer_Summary *buffer, char *str, size_t str_len, Buffer_Edit *edits, uint32_t edit_count, Buffer_Batch_Edit_Type type){return(app->buffer_batch_edit_(app, buffer, str, str_len, edits, edit_count, type));} +static inline bool32 buffer_batch_edit(Application_Links *app, Buffer_Summary *buffer, char *str, int32_t str_len, Buffer_Edit *edits, int32_t edit_count, Buffer_Batch_Edit_Type type){return(app->buffer_batch_edit_(app, buffer, str, str_len, edits, edit_count, type));} static inline Marker_Handle buffer_add_markers(Application_Links *app, Buffer_Summary *buffer, uint32_t marker_count){return(app->buffer_add_markers_(app, buffer, marker_count));} static inline bool32 buffer_set_markers(Application_Links *app, Buffer_Summary *buffer, Marker_Handle marker, uint32_t first_marker_index, uint32_t marker_count, Marker *source_markers){return(app->buffer_set_markers_(app, buffer, marker, first_marker_index, marker_count, source_markers));} static inline bool32 buffer_get_markers(Application_Links *app, Buffer_Summary *buffer, Marker_Handle marker, uint32_t first_marker_index, uint32_t marker_count, Marker *markers_out){return(app->buffer_get_markers_(app, buffer, marker, first_marker_index, marker_count, markers_out));} @@ -500,9 +500,9 @@ static inline int32_t directory_get_hot(Application_Links *app, char *out, int32 static inline File_List get_file_list(Application_Links *app, char *dir, int32_t len){return(app->get_file_list_(app, dir, len));} static inline void free_file_list(Application_Links *app, File_List list){(app->free_file_list_(app, list));} static inline void set_gui_up_down_keys(Application_Links *app, int16_t up_key, int16_t down_key){(app->set_gui_up_down_keys_(app, up_key, down_key));} -static inline void* memory_allocate(Application_Links *app, size_t size){return(app->memory_allocate_(app, size));} -static inline bool32 memory_set_protection(Application_Links *app, void *ptr, size_t size, Memory_Protect_Flags flags){return(app->memory_set_protection_(app, ptr, size, flags));} -static inline void memory_free(Application_Links *app, void *ptr, size_t size){(app->memory_free_(app, ptr, size));} +static inline void* memory_allocate(Application_Links *app, int32_t size){return(app->memory_allocate_(app, size));} +static inline bool32 memory_set_protection(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags){return(app->memory_set_protection_(app, ptr, size, flags));} +static inline void memory_free(Application_Links *app, void *ptr, int32_t size){(app->memory_free_(app, ptr, size));} static inline bool32 file_exists(Application_Links *app, char *filename, int32_t len){return(app->file_exists_(app, filename, len));} static inline bool32 directory_cd(Application_Links *app, char *dir, int32_t *len, int32_t capacity, char *rel_path, int32_t rel_len){return(app->directory_cd_(app, dir, len, capacity, rel_path, rel_len));} static inline int32_t get_4ed_path(Application_Links *app, char *out, int32_t capacity){return(app->get_4ed_path_(app, out, capacity));} diff --git a/4coder_API/types.h b/4coder_API/types.h index 51b0a039..06d45281 100644 --- a/4coder_API/types.h +++ b/4coder_API/types.h @@ -494,7 +494,7 @@ STRUCT Buffer_Seek{ UNION{ STRUCT { /* DOC(The pos field specified the pos when the seek is in absolute position.) */ - size_t pos; + int32_t pos; }; STRUCT { /* DOC(For xy coordinate seeks, rounding down means that any x in the box of the character lands on that character. For instance when clicking rounding down is the user's expected behavior. Not rounding down means that the right hand portion of the character's box, which is closer to the next character, will land on that next character. The unrounded behavior is the expected behavior when moving vertically and keeping the preferred x.) */ @@ -506,9 +506,9 @@ STRUCT Buffer_Seek{ }; STRUCT { /* DOC(The line number of a line-character type seek.) */ - size_t line; + int32_t line; /* DOC(The character number of a line-character type seek.) */ - size_t character; + int32_t character; }; }; }; @@ -517,15 +517,15 @@ STRUCT Buffer_Seek{ DOC_SEE(4coder_Buffer_Positioning_System) */ STRUCT Full_Cursor{ /* DOC(This field contains the cursor's position in absolute byte index positioning.) */ - size_t pos; + int32_t pos; /* DOC(This field contains the cursor's position in apparent character index positioning.) */ - size_t character_pos; + int32_t character_pos; /* DOC(This field contains the number of the line where the cursor is located. This field is one based.) */ - size_t line; + int32_t line; /* DOC(This field contains the number of the character from the beginninf of the line where the cursor is located. This field is one based.) */ - size_t character; + int32_t character; /* DOC(This field contains the number of the line where the cursor is located, taking the line wrapping into account. This field is one based.) */ - size_t wrap_line; + int32_t wrap_line; /* DOC(This field contains the x position measured with unwrapped lines.) */ float unwrapped_x; /* DOC(This field contains the y position measured with unwrapped lines.) */ @@ -540,24 +540,24 @@ STRUCT Full_Cursor{ DOC_SEE(4coder_Buffer_Positioning_System) */ STRUCT Partial_Cursor{ /* DOC(This field contains the cursor's position in absolute byte index positioning.) */ - size_t pos; + int32_t pos; /* DOC(This field contains the number of the character from the beginninf of the line where the cursor is located. This field is one based.) */ - size_t line; + int32_t line; /* DOC(This field contains the number of the column where the cursor is located. This field is one based.) */ - size_t character; + int32_t character; }; /* DOC(Buffer_Edit describes a range of a buffer and string to replace that range. A Buffer_Edit has to be paired with a string that contains the actual text that will be replaced into the buffer.) */ STRUCT Buffer_Edit{ /* DOC(The str_start field specifies the first character in the accompanying string that corresponds with this edit.) */ - size_t str_start; + int32_t str_start; /* DOC(The len field specifies the length of the string being written into the buffer.) */ - size_t len; + int32_t len; /* DOC(The start field specifies the start of the range in the buffer to replace in absolute position.) */ - size_t start; + int32_t start; /* DOC(The end field specifies one past the end of the range in the buffer to replace in absolute position.) */ - size_t end; + int32_t end; }; /* DOC(Buffer_Summary acts as a handle to a buffer and describes the state of the buffer.) @@ -635,15 +635,6 @@ STRUCT i32_Rect{ GLOBAL_VAR i32_Rect null_i32_rect = {0}; -STRUCT pos_Rect{ - size_t x0; - size_t y0; - size_t x1; - size_t y1; -}; - -GLOBAL_VAR pos_Rect null_pos_rect = {0}; - STRUCT f32_Rect{ float x0; float y0; diff --git a/4coder_auto_indent.cpp b/4coder_auto_indent.cpp index 89942135..9845364c 100644 --- a/4coder_auto_indent.cpp +++ b/4coder_auto_indent.cpp @@ -323,7 +323,7 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b 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){ 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; - uint32_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 this_line_start = buffer_get_line_start(app, buffer, line_index); + int32_t next_line_start = buffer_get_line_start(app, buffer, line_index+1); bool32 did_special_behavior = false; @@ -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); 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); - if (token != 0 && token->start < line_start_pos){ + if (token && token->start < line_start_pos){ line_start = buffer_get_line_index(app, buffer, token->start); } else{ @@ -534,7 +534,7 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cp } 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); if (token && token->start < next_line_start_pos){ line_end = buffer_get_line_index(app, buffer, token->start+token->size); diff --git a/4coder_default_framework.h b/4coder_default_framework.h index 8d7afe16..d039ca8e 100644 --- a/4coder_default_framework.h +++ b/4coder_default_framework.h @@ -322,16 +322,16 @@ struct Config_Item{ struct Config_Array_Reader{ Cpp_Token_Array array; char *mem; - uint32_t i; - uint32_t val_array_end; + int32_t i; + int32_t val_array_end; bool32 good; }; static Cpp_Token -read_config_token(Cpp_Token_Array array, uint32_t *i_ptr){ +read_config_token(Cpp_Token_Array array, int32_t *i_ptr){ Cpp_Token token = {0}; - uint32_t i = *i_ptr; + int32_t i = *i_ptr; for (; i < array.count; ++i){ Cpp_Token comment_token = array.tokens[i]; @@ -350,10 +350,10 @@ read_config_token(Cpp_Token_Array array, uint32_t *i_ptr){ } static Config_Line -read_config_line(Cpp_Token_Array array, uint32_t *i_ptr){ +read_config_line(Cpp_Token_Array array, int32_t *i_ptr){ Config_Line config_line = {0}; - uint32_t i = *i_ptr; + int32_t i = *i_ptr; config_line.id_token = read_config_token(array, &i); if (config_line.id_token.type == CPP_TOKEN_IDENTIFIER){ @@ -723,7 +723,7 @@ process_config_file(Application_Links *app){ int32_t new_wrap_width = default_wrap_width; int32_t new_min_base_width = default_min_base_width; - for (uint32_t i = 0; i < array.count; ++i){ + for (int32_t i = 0; i < array.count; ++i){ Config_Line config_line = read_config_line(array, &i); if (config_line.read_success){ diff --git a/4coder_function_list.cpp b/4coder_function_list.cpp index 96558c9f..618fcf59 100644 --- a/4coder_function_list.cpp +++ b/4coder_function_list.cpp @@ -59,8 +59,8 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff Partition extra_memory_ = partition_sub_part(part, (4<<10)); Partition *extra_memory = &extra_memory_; char *str = (char*)partition_current(part); - size_t part_size = 0; - size_t size = 0; + int32_t part_size = 0; + int32_t size = 0; static const int32_t token_chunk_size = 512; Cpp_Token token_chunk[token_chunk_size]; @@ -217,7 +217,7 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff } if (delete_space_before){ - size_t pos = extra_memory->pos - 1; + int32_t pos = extra_memory->pos - 1; char *base = ((char*)(extra_memory->base)); if (pos >= 0 && base[pos] == ' '){ extra_memory->pos = pos; @@ -242,13 +242,13 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff finish_print:; { - size_t sig_size = extra_memory->pos; - String sig = make_string(extra_memory->base, (int32_t)sig_size); + int32_t sig_size = extra_memory->pos; + String sig = make_string(extra_memory->base, sig_size); int32_t line_number = buffer_get_line_index(app, buffer, open_paren_pos); int32_t line_number_len = int_to_str_size(line_number); - size_t append_len = buffer_name.size + 1 + line_number_len + 1 + 1 + sig_size + 1; + int32_t append_len = buffer_name.size + 1 + line_number_len + 1 + 1 + sig_size + 1; char *out_space = push_array(part, char, append_len); if (out_space == 0){ @@ -263,7 +263,7 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *buff } part_size += append_len; - String out = make_string(out_space, 0, (int32_t)append_len); + String out = make_string(out_space, 0, append_len); append(&out, buffer_name); append(&out, ':'); append_int_to_str(&out, line_number); diff --git a/4coder_helper/4coder_helper.h b/4coder_helper/4coder_helper.h index 18abfde8..d8e48b38 100644 --- a/4coder_helper/4coder_helper.h +++ b/4coder_helper/4coder_helper.h @@ -212,9 +212,9 @@ adjust_all_buffer_wrap_widths(Application_Links *app, int32_t wrap_width, int32_ } // TODO(allen): Setup buffer seeking to do character_pos and get View_Summary out of this parameter list. -static size_t -character_pos_to_pos(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, size_t character_pos){ - size_t result = 0; +static int32_t +character_pos_to_pos(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, int32_t character_pos){ + int32_t result = 0; Full_Cursor cursor = {0}; if (view_compute_cursor(app, view, seek_character_pos(character_pos), &cursor)){ result = cursor.pos; @@ -223,8 +223,8 @@ character_pos_to_pos(Application_Links *app, View_Summary *view, Buffer_Summary } struct Buffer_Rect{ - size_t char0, line0; - size_t char1, line1; + int32_t char0, line0; + int32_t char1, line1; }; #ifndef Swap @@ -242,26 +242,26 @@ get_rect(View_Summary *view){ rect.line1 = view->cursor.line; if (rect.line0 > rect.line1){ - Swap(size_t, rect.line0, rect.line1); + Swap(int32_t, rect.line0, rect.line1); } if (rect.char0 > rect.char1){ - Swap(size_t, rect.char0, rect.char1); + Swap(int32_t, rect.char0, rect.char1); } return(rect); } -static pos_Rect +static i32_Rect get_line_x_rect(View_Summary *view){ - pos_Rect rect = {0}; + i32_Rect rect = {0}; if (view->unwrapped_lines){ - rect.x0 = (size_t)view->mark.unwrapped_x; - rect.x1 = (size_t)view->cursor.unwrapped_x; + rect.x0 = (int32_t)view->mark.unwrapped_x; + rect.x1 = (int32_t)view->cursor.unwrapped_x; } else{ - rect.x0 = (size_t)view->mark.wrapped_x; - rect.x1 = (size_t)view->cursor.wrapped_x; + rect.x0 = (int32_t)view->mark.wrapped_x; + rect.x1 = (int32_t)view->cursor.wrapped_x; } rect.y0 = view->mark.line; rect.y1 = view->cursor.line; diff --git a/4coder_helper/4coder_long_seek.h b/4coder_helper/4coder_long_seek.h index 2b539db7..e625c903 100644 --- a/4coder_helper/4coder_long_seek.h +++ b/4coder_helper/4coder_long_seek.h @@ -464,7 +464,7 @@ buffer_seek_alphanumeric_or_camel_left(Application_Links *app, Buffer_Summary *b } 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); if (get.token_index == -1){ get.token_index = 0; @@ -479,18 +479,16 @@ seek_token_left(Cpp_Token_Array *tokens, uint32_t pos){ } 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); if (get.in_whitespace){ ++get.token_index; } - uint32_t target_token_index = (uint32_t)(get.token_index); - - if (target_token_index >= tokens->count){ - target_token_index = tokens->count-1; + if (get.token_index >= tokens->count){ + get.token_index = tokens->count-1; } - Cpp_Token *token = tokens->tokens + target_token_index; + Cpp_Token *token = tokens->tokens + get.token_index; return(token->start + token->size); } @@ -968,22 +966,21 @@ buffer_get_line_index(Application_Links *app, Buffer_Summary *buffer, int32_t po } 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); - 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){ - get.token_index += 1; + if (get_token.in_whitespace){ + get_token.token_index += 1; } - uint32_t target_token_index = (uint32_t)(get.token_index); if (line_start_out){ *line_start_out = line_start; } Cpp_Token *result = 0; - if (target_token_index < tokens.count){ - result = tokens.tokens + target_token_index; + if (get_token.token_index < tokens.count){ + result = tokens.tokens + get_token.token_index; } return(result); diff --git a/4coder_helper/4coder_seek_types.h b/4coder_helper/4coder_seek_types.h index 849e3d77..f5e8738e 100644 --- a/4coder_helper/4coder_seek_types.h +++ b/4coder_helper/4coder_seek_types.h @@ -13,7 +13,7 @@ #define FRED_BUFFER_TYPES_H static Buffer_Seek -seek_pos(size_t pos){ +seek_pos(int32_t pos){ Buffer_Seek result; result.type = buffer_seek_pos; result.pos = pos; @@ -21,7 +21,7 @@ seek_pos(size_t pos){ } static Buffer_Seek -seek_character_pos(size_t pos){ +seek_character_pos(int32_t pos){ Buffer_Seek result; result.type = buffer_seek_character_pos; result.pos = pos; @@ -29,7 +29,7 @@ seek_character_pos(size_t pos){ } static Buffer_Seek -seek_wrapped_xy(float x, float y, bool32 round_down){ +seek_wrapped_xy(float x, float y, int32_t round_down){ Buffer_Seek result; result.type = buffer_seek_wrapped_xy; result.x = x; @@ -39,7 +39,7 @@ seek_wrapped_xy(float x, float y, bool32 round_down){ } static Buffer_Seek -seek_unwrapped_xy(float x, float y, bool32 round_down){ +seek_unwrapped_xy(float x, float y, int32_t round_down){ Buffer_Seek result; result.type = buffer_seek_unwrapped_xy; result.x = x; @@ -59,7 +59,7 @@ seek_xy(float x, float y, bool32 round_down, bool32 unwrapped){ } static Buffer_Seek -seek_line_char(size_t line, size_t character){ +seek_line_char(int32_t line, int32_t character){ Buffer_Seek result; result.type = buffer_seek_line_char; result.line = line; diff --git a/4coder_lib/4coder_mem.h b/4coder_lib/4coder_mem.h index 8bdbdb0a..4371681d 100644 --- a/4coder_lib/4coder_mem.h +++ b/4coder_lib/4coder_mem.h @@ -44,23 +44,23 @@ typedef int32_t b32_4tech; struct Partition{ char *base; - umem_4tech pos; - umem_4tech max; + i32_4tech pos; + i32_4tech max; }; struct Temp_Memory{ void *handle; - umem_4tech pos; + i32_4tech pos; }; struct Tail_Temp_Partition{ Partition part; void *handle; - umem_4tech old_max; + i32_4tech old_max; }; inline Partition -make_part(void *memory, umem_4tech size){ +make_part(void *memory, i32_4tech size){ Partition partition; partition.base = (char*)memory; partition.pos = 0; @@ -69,7 +69,7 @@ make_part(void *memory, umem_4tech size){ } inline void* -partition_allocate(Partition *data, umem_4tech size){ +partition_allocate(Partition *data, i32_4tech size){ void *ret = 0; if (size > 0 && data->pos + size <= data->max){ ret = data->base + data->pos; @@ -79,7 +79,7 @@ partition_allocate(Partition *data, umem_4tech size){ } inline void -partition_align(Partition *data, umem_4tech boundary){ +partition_align(Partition *data, u32_4tech boundary){ --boundary; data->pos = (data->pos + boundary) & (~boundary); } @@ -89,7 +89,7 @@ partition_current(Partition *data){ return(data->base + data->pos); } -inline umem_4tech +inline i32_4tech partition_remaining(Partition *data){ return(data->max - data->pos); } @@ -122,7 +122,7 @@ end_temp_memory(Temp_Memory temp){ } inline Tail_Temp_Partition -begin_tail_part(Partition *data, umem_4tech size){ +begin_tail_part(Partition *data, i32_4tech size){ Tail_Temp_Partition result = {0}; if (data->pos + size <= data->max){ result.handle = data; diff --git a/4coder_project_commands.cpp b/4coder_project_commands.cpp index 97d77ffe..c1d96f7a 100644 --- a/4coder_project_commands.cpp +++ b/4coder_project_commands.cpp @@ -50,7 +50,7 @@ static void close_all_files_with_extension(Application_Links *app, Partition *scratch_part, char **extension_list, int32_t extension_count){ Temp_Memory temp = begin_temp_memory(scratch_part); - size_t buffers_to_close_max = partition_remaining(scratch_part)/sizeof(int32_t); + int32_t buffers_to_close_max = partition_remaining(scratch_part)/sizeof(int32_t); int32_t *buffers_to_close = push_array(scratch_part, int32_t, buffers_to_close_max); int32_t buffers_to_close_count = 0; @@ -225,7 +225,7 @@ CUSTOM_COMMAND_SIG(load_project){ } // Read the settings from project.4coder - for (uint32_t i = 0; i < array.count; ++i){ + for (int32_t i = 0; i < array.count; ++i){ Config_Line config_line = read_config_line(array, &i); if (config_line.read_success){ Config_Item item = get_config_item(config_line, mem, array); diff --git a/4cpp/4cpp_lexer.h b/4cpp/4cpp_lexer.h index 5b0fcc8b..473c1d15 100644 --- a/4cpp/4cpp_lexer.h +++ b/4cpp/4cpp_lexer.h @@ -42,9 +42,6 @@ typedef int32_t b32_4tech; #endif // standard preamble end -#include "4cpp_lexer_types.h" -#include "4cpp_lexer_tables.c" - // duff-routine defines #define DfrCase(PC) case PC: goto resumespot_##PC #define DfrYield(PC, n) { *S_ptr = S; S_ptr->__pc__ = PC; return(n); resumespot_##PC:; } @@ -54,6 +51,9 @@ typedef int32_t b32_4tech; # define FCPP_LINK static #endif +#include "4cpp_lexer_types.h" +#include "4cpp_lexer_tables.c" + // TODO(allen): revisit this keyword data declaration system struct String_And_Flag{ char *str; @@ -191,7 +191,7 @@ static String_And_Flag keywords[] = { static i32_4tech keywords_count = sizeof(keywords)/sizeof(keywords[0]); API_EXPORT FCPP_LINK Cpp_Get_Token_Result -cpp_get_token(Cpp_Token_Array array, 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(pos, The position, measured in bytes, to get the token for.) DOC_RETURN(A Cpp_Get_Token_Result struct is returned containing the index of a token and a flag indicating whether the pos is contained in the token or in whitespace after the token.) @@ -206,14 +206,14 @@ DOC_SEE(Cpp_Get_Token_Result) i32_4tech first = 0; i32_4tech count = array.count; i32_4tech last = count; + i32_4tech this_start = 0, next_start = 0; if (count > 0){ for (;;){ result.token_index = (first + last)/2; token = token_array + result.token_index; - u32_4tech this_start = token->start; - u32_4tech next_start = 0; + this_start = token->start; if (result.token_index + 1 < count){ next_start = (token + 1)->start; @@ -221,7 +221,6 @@ DOC_SEE(Cpp_Get_Token_Result) else{ next_start = this_start + token->size; } - if (this_start <= pos && pos < next_start){ break; } @@ -231,7 +230,6 @@ DOC_SEE(Cpp_Get_Token_Result) else{ first = result.token_index + 1; } - if (first == last){ result.token_index = first; break; @@ -309,7 +307,7 @@ cpp_pp_directive_to_state(Cpp_Token_Type type){ } FCPP_LINK b32_4tech -cpp__match(char *a, u32_4tech a_len, char *b, u32_4tech b_len){ +cpp__match(char *a, i32_4tech a_len, char *b, i32_4tech b_len){ b32_4tech result = false; if (a_len == b_len){ char *a_end = a + a_len; @@ -325,7 +323,7 @@ cpp__match(char *a, u32_4tech a_len, char *b, u32_4tech b_len){ } FCPP_LINK b32_4tech -cpp__table_match(String_And_Flag *table, i32_4tech count, char *s, u32_4tech len, i32_4tech *index_out){ +cpp__table_match(String_And_Flag *table, i32_4tech count, char *s, i32_4tech len, i32_4tech *index_out){ b32_4tech result = false; String_And_Flag *entry = table; *index_out = -1; @@ -340,7 +338,7 @@ cpp__table_match(String_And_Flag *table, i32_4tech count, char *s, u32_4tech len } FCPP_LINK Cpp_Lex_Result -cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, u32_4tech size, Cpp_Token_Array *token_array_out){ +cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech size, Cpp_Token_Array *token_array_out){ Cpp_Lex_Data S = *S_ptr; Cpp_Token *out_tokens = token_array_out->tokens; @@ -349,7 +347,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, u32_4tech s u8_4tech c = 0; - u32_4tech end_pos = size + S.chunk_pos; + i32_4tech end_pos = size + S.chunk_pos; chunk -= S.chunk_pos; switch (S.__pc__){ @@ -970,7 +968,7 @@ cpp_lex_nonalloc_null_end_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech } FCPP_LINK Cpp_Lex_Result -cpp_lex_nonalloc_no_null_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, u32_4tech size, u32_4tech full_size, +cpp_lex_nonalloc_no_null_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, i32_4tech size, i32_4tech full_size, Cpp_Token_Array *token_array_out){ Cpp_Lex_Result result = 0; if (S_ptr->pos >= full_size){ @@ -1141,7 +1139,7 @@ cpp_shift_token_starts(Cpp_Token_Array *array, i32_4tech from_token_i, i32_4tech } FCPP_LINK Cpp_Token -cpp_index_array(Cpp_Token_Array *array, i32_4tech file_size, u32_4tech index){ +cpp_index_array(Cpp_Token_Array *array, i32_4tech file_size, i32_4tech index){ Cpp_Token result; if (index < array->count){ result = array->tokens[index]; @@ -1157,11 +1155,16 @@ cpp_index_array(Cpp_Token_Array *array, i32_4tech file_size, u32_4tech index){ } API_EXPORT FCPP_LINK Cpp_Relex_Range -cpp_get_relex_range(Cpp_Token_Array *array, u32_4tech start_pos, u32_4tech end_pos) +cpp_get_relex_range(Cpp_Token_Array *array, i32_4tech start_pos, i32_4tech end_pos) /* -DOC_PARAM(array, A pointer to the token array that will be modified by the relex, this array should already contain the tokens for the previous state of the file.) -DOC_PARAM(start_pos, The start position of the edited region of the file. The start and end points are based on the edited region of the file before the edit.) -DOC_PARAM(end_pos, The end position of the edited region of the file. In particular, end_pos is the first character after the edited region not effected by the edit. Thus if the edited region contained one character end_pos - start_pos should equal 1. The start and end points are based on the edited region of the file before the edit.) +DOC_PARAM(array, A pointer to the token array that will be modified by the relex, +this array should already contain the tokens for the previous state of the file.) +DOC_PARAM(start_pos, The start position of the edited region of the file. +The start and end points are based on the edited region of the file before the edit.) +DOC_PARAM(end_pos, The end position of the edited region of the file. +In particular, end_pos is the first character after the edited region not effected by the edit. +Thus if the edited region contained one character end_pos - start_pos should equal 1. +The start and end points are based on the edited region of the file before the edit.) */{ Cpp_Relex_Range range = {0}; Cpp_Get_Token_Result get_result = {0}; @@ -1185,18 +1188,27 @@ DOC_PARAM(end_pos, The end position of the edited region of the file. In particu } API_EXPORT FCPP_LINK Cpp_Relex_Data -cpp_relex_init(Cpp_Token_Array *array, u32_4tech start_pos, u32_4tech end_pos, i32_4tech character_shift_amount) +cpp_relex_init(Cpp_Token_Array *array, i32_4tech start_pos, i32_4tech end_pos, i32_4tech character_shift_amount) /* -DOC_PARAM(array, A pointer to the token array that will be modified by the relex, this array should already contain the tokens for the previous state of the file.) -DOC_PARAM(start_pos, The start position of the edited region of the file. The start and end points are based on the edited region of the file before the edit.) -DOC_PARAM(end_pos, The end position of the edited region of the file. In particular, end_pos is the first character after the edited region not effected by the edit. Thus if the edited region contained one character end_pos - start_pos should equal 1. The start and end points are based on the edited region of the file before the edit.) +DOC_PARAM(array, A pointer to the token array that will be modified by the relex, +this array should already contain the tokens for the previous state of the file.) +DOC_PARAM(start_pos, The start position of the edited region of the file. +The start and end points are based on the edited region of the file before the edit.) +DOC_PARAM(end_pos, The end position of the edited region of the file. +In particular, end_pos is the first character after the edited region not effected by the edit. +Thus if the edited region contained one character end_pos - start_pos should equal 1. +The start and end points are based on the edited region of the file before the edit.) DOC_PARAM(character_shift_amount, The shift in the characters after the edited region.) DOC_RETURN(Returns a partially initialized relex state.) -DOC(This call does the first setup step of initializing a relex state. To finish initializing the relex state you must tell the state about the positioning of the first chunk it will be fed. There are two methods of doing this, the direct method is with cpp_relex_declare_first_chunk_position, the method that is often more convenient is with cpp_relex_is_start_chunk. If the file is not chunked the second step of initialization can be skipped.) +DOC(This call does the first setup step of initializing a relex state. To finish initializing the relex state +you must tell the state about the positioning of the first chunk it will be fed. There are two methods of doing +this, the direct method is with cpp_relex_declare_first_chunk_position, the method that is often more convenient +is with cpp_relex_is_start_chunk. If the file is not chunked the second step of initialization can be skipped.) DOC_SEE(cpp_relex_declare_first_chunk_position) DOC_SEE(cpp_relex_is_start_chunk) + */{ Cpp_Relex_Data state = {0}; @@ -1524,7 +1536,7 @@ DOC_SEE(cpp_make_token_array) } API_EXPORT FCPP_LINK void -cpp_resize_token_array(Cpp_Token_Array *token_array, u32_4tech new_max)/* +cpp_resize_token_array(Cpp_Token_Array *token_array, i32_4tech new_max)/* DOC_PARAM(token_array, An array previously allocated by cpp_make_token_array.) DOC_PARAM(new_max, The new maximum size the array should support. If this is not greater than the current size of the array the operation is ignored.) diff --git a/4cpp/4cpp_lexer_types.h b/4cpp/4cpp_lexer_types.h index 4c597489..f53b3b26 100644 --- a/4cpp/4cpp_lexer_types.h +++ b/4cpp/4cpp_lexer_types.h @@ -1,7 +1,7 @@ // TOP -#if !defined(FCPP_LEXER_TYPES_INC) +#ifndef FCPP_LEXER_TYPES_INC #define FCPP_LEXER_TYPES_INC #ifndef ENUM @@ -237,10 +237,10 @@ STRUCT Cpp_Token{ Cpp_Token_Type type; /* DOC(The start field indicates the index of the first character of this token's lexeme.) */ - uint32_t start; + int32_t start; /* DOC(The size field indicates the number of bytes in this token's lexeme.) */ - uint32_t size; + int32_t size; /* DOC(The state_flags should not be used outside of the lexer's implementation.) */ uint16_t state_flags; @@ -273,10 +273,10 @@ STRUCT Cpp_Token_Array{ Cpp_Token *tokens; /* DOC(The count field counts how many tokens in the array are currently used.) */ - uint32_t count; + int32_t count; /* DOC(The max_count field specifies the maximum size the count field may grow to before the tokens array is out of space.) */ - uint32_t max_count; + int32_t max_count; }; static Cpp_Token_Array null_cpp_token_array = {0}; @@ -288,13 +288,13 @@ STRUCT Cpp_Get_Token_Result{ int32_t token_index; /* DOC(The in_whitespace field is true when the query position was actually in whitespace after the result token.) */ - uint32_t in_whitespace; + int32_t in_whitespace; /* DOC(If the token_index refers to an actual token, this is the start value of the token. Otherwise this is zero.) */ - uint32_t token_start; + int32_t token_start; /* DOC(If the token_index refers to an actual token, this is the start+size value of the token. Otherwise this is zero.) */ - uint32_t token_end; + int32_t token_end; }; /* DOC(Cpp_Relex_Range is the return result of the cpp_get_relex_range call.) @@ -321,12 +321,12 @@ DOC_SEE(cpp_lex_data_init) HIDE_MEMBERS() */ STRUCT Cpp_Lex_Data{ char tb[32]; - uint32_t tb_pos; - uint32_t token_start; + int32_t tb_pos; + int32_t token_start; - uint32_t pos; - uint32_t pos_overide; - uint32_t chunk_pos; + int32_t pos; + int32_t pos_overide; + int32_t chunk_pos; Cpp_Lex_FSM fsm; uint8_t white_done; @@ -361,10 +361,10 @@ STRUCT Cpp_Relex_Data{ Cpp_Token end_token; - uint32_t relex_start_position; - uint32_t start_token_index; - uint32_t end_token_index; - uint32_t original_end_token_index; + int32_t relex_start_position; + int32_t start_token_index; + int32_t end_token_index; + int32_t original_end_token_index; int32_t character_shift_amount; diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index a10595bd..8617d859 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -585,7 +585,7 @@ DOC_SEE(4coder_Buffer_Positioning_System) } API_EXPORT bool32 -Buffer_Replace_Range(Application_Links *app, Buffer_Summary *buffer, size_t start, size_t end, char *str, size_t len) +Buffer_Replace_Range(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *str, int32_t len) /* DOC_PARAM(buffer, This parameter specifies the buffer to edit.) DOC_PARAM(start, This parameter specifies absolute position of the first character in the replace range.) @@ -656,7 +656,7 @@ DOC_SEE(Partial_Cursor) } API_EXPORT bool32 -Buffer_Batch_Edit(Application_Links *app, Buffer_Summary *buffer, char *str, size_t str_len, Buffer_Edit *edits, uint32_t edit_count, Buffer_Batch_Edit_Type type) +Buffer_Batch_Edit(Application_Links *app, Buffer_Summary *buffer, char *str, int32_t str_len, Buffer_Edit *edits, int32_t edit_count, Buffer_Batch_Edit_Type type) /* DOC_PARAM(buffer, The buffer on which to apply the batch of edits.) DOC_PARAM(str, This parameter provides all of the source string for the edits in the batch.) @@ -2287,7 +2287,7 @@ DOC(This is a temporary ad-hoc solution to allow some customization of the behav } API_EXPORT void* -Memory_Allocate(Application_Links *app, size_t size) +Memory_Allocate(Application_Links *app, int32_t size) /* DOC_PARAM(size, The size in bytes of the block that should be returned.) DOC(This calls to a low level OS allocator which means it is best used for infrequent, large allocations. The size of the block must be remembered if it will be freed or if it's mem protection status will be changed.) @@ -2300,7 +2300,7 @@ DOC_SEE(memory_free) } API_EXPORT bool32 -Memory_Set_Protection(Application_Links *app, void *ptr, size_t size, Memory_Protect_Flags flags) +Memory_Set_Protection(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags) /* DOC_PARAM(ptr, The base of the block on which to set memory protection flags.) DOC_PARAM(size, The size that was originally used to allocate this block.) @@ -2316,7 +2316,7 @@ DOC_SEE(Memory_Protect_Flags) } API_EXPORT void -Memory_Free(Application_Links *app, void *ptr, size_t size) +Memory_Free(Application_Links *app, void *ptr, int32_t size) /* DOC_PARAM(mem, The base of a block to free.) DOC_PARAM(size, The size that was originally used to allocate this block.) diff --git a/4ed_buffer.cpp b/4ed_buffer.cpp index 6d38f683..ba098998 100644 --- a/4ed_buffer.cpp +++ b/4ed_buffer.cpp @@ -188,9 +188,9 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, ////////////////////////////////////// -internal umem -eol_convert_in(char *dest, char *src, umem size){ - umem i = 0, j = 0, k = 0; +internal i32 +eol_convert_in(char *dest, char *src, i32 size){ + i32 i = 0, j = 0, k = 0; for (; j < size && src[j] != '\r'; ++j); memcpy(dest, src, j); @@ -212,9 +212,9 @@ eol_convert_in(char *dest, char *src, umem size){ return(j); } -internal umem -eol_in_place_convert_in(char *data, umem size){ - umem i = 0, j = 0, k = 0; +internal i32 +eol_in_place_convert_in(char *data, i32 size){ + i32 i = 0, j = 0, k = 0; for (; j < size && data[j] != '\r'; ++j); @@ -236,10 +236,10 @@ eol_in_place_convert_in(char *data, umem size){ } // TODO(allen): iterative memory check? -internal b32 -eol_convert_out(char *dest, umem max, char *src, umem size, umem *size_out){ - b32 result = true; - umem i = 0, j = 0; +internal i32 +eol_convert_out(char *dest, i32 max, char *src, i32 size, i32 *size_out){ + i32 result = 1; + i32 i = 0, j = 0; for (; i < size; ++i, ++j){ if (src[i] == '\n'){ @@ -247,9 +247,7 @@ eol_convert_out(char *dest, umem max, char *src, umem size, umem *size_out){ ++j; dest[j] = '\n'; } - else{ - dest[j] = src[i]; - } + else dest[j] = src[i]; } *size_out = j; @@ -257,10 +255,10 @@ eol_convert_out(char *dest, umem max, char *src, umem size, umem *size_out){ } // TODO(allen): iterative memory check? -internal b32 -eol_in_place_convert_out(char *data, umem size, umem max, umem *size_out){ - b32 result = true; - umem i = 0; +internal i32 +eol_in_place_convert_out(char *data, i32 size, i32 max, i32 *size_out){ + i32 result = 1; + i32 i = 0; for (; i < size; ++i){ if (data[i] == '\n'){ @@ -283,32 +281,32 @@ eol_in_place_convert_out(char *data, umem size, umem max, umem *size_out){ typedef struct Gap_Buffer{ char *data; - umem size1; - umem gap_size; - umem size2; - umem max; + i32 size1; + i32 gap_size; + i32 size2; + i32 max; - umem *line_starts; - umem line_count; - umem line_max; + i32 *line_starts; + i32 line_count; + i32 line_max; } Gap_Buffer; -inline b32 +inline i32 buffer_good(Gap_Buffer *buffer){ - b32 good = (buffer->data != 0); + i32 good = (buffer->data != 0); return(good); } -inline umem +inline i32 buffer_size(Gap_Buffer *buffer){ - umem size = buffer->size1 + buffer->size2; + i32 size = buffer->size1 + buffer->size2; return(size); } typedef struct Gap_Buffer_Init{ Gap_Buffer *buffer; char *data; - umem size; + i32 size; } Gap_Buffer_Init; internal Gap_Buffer_Init @@ -320,18 +318,16 @@ buffer_begin_init(Gap_Buffer *buffer, char *data, i32 size){ return(init); } -internal b32 +internal i32 buffer_init_need_more(Gap_Buffer_Init *init){ - b32 result = true; - if (init->buffer->data){ - result = false; - } + i32 result = 1; + if (init->buffer->data) result = 0; return(result); } -internal umem +internal i32 buffer_init_page_size(Gap_Buffer_Init *init){ - umem result = init->size * 2; + i32 result = init->size * 2; return(result); } @@ -343,15 +339,15 @@ buffer_init_provide_page(Gap_Buffer_Init *init, void *page, i32 page_size){ } internal b32 -buffer_end_init(Gap_Buffer_Init *init, void *scratch, umem scratch_size){ +buffer_end_init(Gap_Buffer_Init *init, void *scratch, i32 scratch_size){ Gap_Buffer *buffer = init->buffer; b32 result = false; if (buffer->data && buffer->max >= init->size){ - umem size = init->size; - umem size2 = size*2; - umem osize1 = size - size2; - umem size1 = osize1; + i32 size = init->size; + i32 size2 = size >> 1; + i32 osize1 = size - size2; + i32 size1 = osize1; if (size1 > 0){ size1 = eol_convert_in(buffer->data, init->data, size1); @@ -374,17 +370,18 @@ buffer_end_init(Gap_Buffer_Init *init, void *scratch, umem scratch_size){ typedef struct Gap_Buffer_Stream{ Gap_Buffer *buffer; char *data; - umem end; - umem absolute_end; - b32 separated; + i32 end; + i32 separated; + i32 absolute_end; + b32 use_termination_character; char terminator; } Gap_Buffer_Stream; static Gap_Buffer_Stream null_buffer_stream = {0}; internal b32 -buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, umem start, umem end){ - b32 result = false; +buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, i32 start, i32 end){ + b32 result = 0; if (0 <= start && start < end && end <= buffer->size1 + buffer->size2){ stream->buffer = buffer; @@ -392,15 +389,15 @@ buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, umem start, if (start < buffer->size1){ if (buffer->size1 < end){ - stream->separated = true; + stream->separated = 1; } else{ - stream->separated = false; + stream->separated = 0; } stream->data = buffer->data; } else{ - stream->separated = false; + stream->separated = 0; stream->data = buffer->data + buffer->gap_size; } @@ -415,17 +412,17 @@ buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, umem start, stream->end = stream->absolute_end; } - result = true; + result = 1; } - if (!result){ + if (result == 0){ if (stream->use_termination_character){ stream->buffer = buffer; stream->absolute_end = end; - stream->use_termination_character = false; + stream->use_termination_character = 0; stream->data = (&stream->terminator) - buffer->size1 - buffer->size2; stream->end = stream->absolute_end + 1; - result = true; + result = 1; } } @@ -434,99 +431,91 @@ buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, umem start, internal b32 buffer_stringify_next(Gap_Buffer_Stream *stream){ - b32 result = false; + b32 result = 0; Gap_Buffer *buffer = stream->buffer; if (stream->separated){ stream->data = buffer->data + buffer->gap_size; stream->end = stream->absolute_end; - stream->separated = false; - result = true; + stream->separated = 0; + result = 1; } - if (!result){ + if (result == 0){ if (stream->use_termination_character){ - stream->use_termination_character = false; + stream->use_termination_character = 0; stream->data = (&stream->terminator) - buffer->size1 - buffer->size2; stream->end = stream->absolute_end + 1; - result = true; + result = 1; } } return(result); } -internal b32 -buffer_replace_range(Gap_Buffer *buffer, umem start, umem end, char *str, umem len, i32 *shift_amount, void *scratch, umem scratch_memory, umem *request_amount){ +internal i32 +buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len, i32 *shift_amount, + void *scratch, i32 scratch_memory, i32 *request_amount){ char *data = buffer->data; - umem size = buffer_size(buffer); - b32 result = false; + i32 size = buffer_size(buffer); + i32 result = 0; + i32 move_size = 0; assert(0 <= start); assert(start <= end); assert(end <= size); - umem target_length = end - start; - - if (target_length <= max_i32 && len <= max_i32){ - if (len >= target_length){ - *shift_amount = (i32)(len - target_length); + *shift_amount = (len - (end - start)); + if (*shift_amount + size <= buffer->max){ + if (end < buffer->size1){ + move_size = buffer->size1 - end; + memmove(data + buffer->size1 + buffer->gap_size - move_size, data + end, move_size); + buffer->size1 -= move_size; + buffer->size2 += move_size; } - else{ - *shift_amount = -(i32)(target_length - len); + if (start > buffer->size1){ + move_size = start - buffer->size1; + memmove(data + buffer->size1, data + buffer->size1 + buffer->gap_size, move_size); + buffer->size1 += move_size; + buffer->size2 -= move_size; } - if (*shift_amount + size <= buffer->max){ - umem move_size = 0; - if (end < buffer->size1){ - move_size = buffer->size1 - end; - memmove(data + buffer->size1 + buffer->gap_size - move_size, data + end, move_size); - buffer->size1 -= move_size; - buffer->size2 += move_size; - } - if (start > buffer->size1){ - move_size = start - buffer->size1; - memmove(data + buffer->size1, data + buffer->size1 + buffer->gap_size, move_size); - buffer->size1 += move_size; - buffer->size2 -= move_size; - } - - memcpy(data + start, str, len); - buffer->size2 = size - end; - buffer->size1 = start + len; - buffer->gap_size -= *shift_amount; - - assert(buffer->size1 + buffer->size2 == size + *shift_amount); - assert(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max); - } - else{ - *request_amount = l_round_up_umem(2*(*shift_amount + size), KB(4)); - result = true; - } + memcpy(data + start, str, len); + buffer->size2 = size - end; + buffer->size1 = start + len; + buffer->gap_size -= *shift_amount; + + assert(buffer->size1 + buffer->size2 == size + *shift_amount); + assert(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max); + } + else{ + *request_amount = l_round_up_i32(2*(*shift_amount + size), 4 << 10); + result = 1; } return(result); } typedef struct Buffer_Batch_State{ - umem i; + i32 i; i32 shift_total; } Buffer_Batch_State; -// TODO(allen): Now that we are just using Gap_Buffer we could afford to improve this for the Gap_Buffer's behavior. -internal b32 -buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, char *strings, u32 edit_count, void *scratch, umem scratch_size, umem *request_amount){ +// TODO(allen): Now that we are just using Gap_Buffer we could afford to improve +// this for the Gap_Buffer's behavior. +internal i32 +buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, char *strings, i32 edit_count, void *scratch, i32 scratch_size, i32 *request_amount){ Buffer_Edit *edit = 0; - umem i = state->i; + i32 i = state->i; i32 shift_total = state->shift_total; i32 shift_amount = 0; - b32 result = false; + i32 result = 0; edit = sorted_edits + i; for (; i < edit_count; ++i, ++edit){ - result = buffer_replace_range(buffer, edit->start + shift_total, edit->end + shift_total, strings + edit->str_start, edit->len, &shift_amount, scratch, scratch_size, request_amount); - if (result){ - break; - } + result = buffer_replace_range(buffer, edit->start + shift_total, edit->end + shift_total, + strings + edit->str_start, edit->len, &shift_amount, + scratch, scratch_size, request_amount); + if (result) break; shift_total += shift_amount; } @@ -537,10 +526,10 @@ buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edi } internal void* -buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, umem new_max){ +buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, i32 new_max){ void *result = buffer->data; - umem size = buffer_size(buffer); - umem new_gap_size = new_max - size; + i32 size = buffer_size(buffer); + i32 new_gap_size = 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 -buffer_stringify(Gap_Buffer *buffer, umem start, umem end, char *out){ +buffer_stringify(Gap_Buffer *buffer, i32 start, i32 end, char *out){ Gap_Buffer_Stream stream = {0}; - umem i = start; + i32 i = start; if (buffer_stringify_loop(&stream, buffer, i, end)){ - b32 still_looping = false; + b32 still_looping = 0; do{ - umem size = stream.end - i; + i32 size = stream.end - i; memcpy(out, stream.data + i, size); i = stream.end; out += size; @@ -575,19 +564,19 @@ buffer_stringify(Gap_Buffer *buffer, umem start, umem end, char *out){ } } -internal umem -buffer_convert_out(Gap_Buffer *buffer, char *dest, umem max){ +internal i32 +buffer_convert_out(Gap_Buffer *buffer, char *dest, i32 max){ Gap_Buffer_Stream stream = {0}; - umem size = buffer_size(buffer); + i32 i = 0; + i32 size = buffer_size(buffer); assert(size + buffer->line_count <= max); - umem pos = 0; + i32 pos = 0; if (buffer_stringify_loop(&stream, buffer, 0, size)){ - umem i = 0; - b32 still_looping = false; + b32 still_looping = 0; do{ - umem chunk_size = stream.end - i; - umem out_size = 0; + i32 chunk_size = stream.end - i; + i32 out_size = 0; i32 result = eol_convert_out(dest + pos, max - pos, stream.data + i, chunk_size, &out_size); assert(result); i = stream.end; @@ -623,22 +612,22 @@ buffer_count_newlines(Gap_Buffer *buffer, i32 start, i32 end){ } typedef struct Buffer_Measure_Starts{ - umem i; - umem count; - umem start; + i32 i; + i32 count; + i32 start; } Buffer_Measure_Starts; // TODO(allen): Rewrite this with a duff routine // Also make it so that the array goes one past the end // and stores the size in the extra spot. -internal b32 +internal i32 buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){ Gap_Buffer_Stream stream = {0}; - umem size = buffer_size(buffer); - umem start = state->start, i = state->i; - umem *start_ptr = buffer->line_starts + state->count; - umem *start_end = buffer->line_starts + buffer->line_max; - b32 result = true; + i32 size = buffer_size(buffer); + i32 start = state->start, i = state->i; + i32 *start_ptr = buffer->line_starts + state->count; + i32 *start_end = buffer->line_starts + buffer->line_max; + i32 result = 1; if (buffer_stringify_loop(&stream, buffer, i, size)){ b32 still_looping = 0; @@ -657,12 +646,14 @@ buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){ still_looping = buffer_stringify_next(&stream); }while(still_looping); } + assert(i == size); + if (start_ptr == start_end){ goto buffer_measure_starts_widths_end; } *start_ptr++ = start; - result = false; + result = 0; buffer_measure_starts_widths_end:; state->i = i; @@ -677,19 +668,22 @@ buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){ } internal void -buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap_Buffer *buffer, 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); Gap_Buffer_Stream stream = {0}; + i32 i = 0; + i32 size = buffer_size(buffer); - umem line_index = 0; - umem character_index = 0; + i32 line_index = 0; + i32 character_index = 0; + + b32 skipping_whitespace = 0; character_starts[line_index++] = character_index; - b32 skipping_whitespace = false; if (virtual_white){ - skipping_whitespace = true; + skipping_whitespace = 1; } Translation_State tran = {0}; @@ -697,11 +691,8 @@ buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap stream.use_termination_character = 1; stream.terminator = '\n'; - - umem size = buffer_size(buffer); - umem i = 0; if (buffer_stringify_loop(&stream, buffer, i, size)){ - b32 still_looping = false; + b32 still_looping = 0; do{ for (; i < stream.end; ++i){ u8 ch = (u8)stream.data[i]; @@ -715,12 +706,12 @@ buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap ++character_index; character_starts[line_index++] = character_index; if (virtual_white){ - skipping_whitespace = true; + skipping_whitespace = 1; } } else if (behavior.do_codepoint_advance || behavior.do_number_advance){ if (ch != ' ' && ch != '\t'){ - skipping_whitespace = false; + skipping_whitespace = 0; } if (!skipping_whitespace){ @@ -747,8 +738,8 @@ struct Buffer_Layout_Stop{ u32 status; i32 line_index; i32 wrap_line_index; - umem pos; - umem next_line_pos; + i32 pos; + i32 next_line_pos; f32 x; }; @@ -762,8 +753,8 @@ struct Buffer_Measure_Wrap_Params{ struct Buffer_Measure_Wrap_State{ Gap_Buffer_Stream stream; - umem i; - umem size; + i32 i; + i32 size; b32 still_looping; i32 line_index; @@ -920,20 +911,20 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para #undef DrReturn internal void -buffer_remeasure_starts(Gap_Buffer *buffer, umem start_line, umem end_line, i32 line_shift, i32 text_shift){ - umem *starts = buffer->line_starts; - umem line_count = buffer->line_count; +buffer_remeasure_starts(Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 line_shift, i32 text_shift){ + i32 *starts = buffer->line_starts; + i32 line_count = buffer->line_count; - assert(0 <= start_line); - assert(start_line <= end_line); - assert(end_line < line_count); + assert(0 <= line_start); + assert(line_start <= line_end); + assert(line_end < line_count); assert(line_count + line_shift <= buffer->line_max); - ++end_line; + ++line_end; // Adjust if (text_shift != 0){ - umem line_i = end_line; + i32 line_i = line_end; starts += line_i; for (; line_i < line_count; ++line_i, ++starts){ *starts += text_shift; @@ -942,24 +933,24 @@ buffer_remeasure_starts(Gap_Buffer *buffer, umem start_line, umem end_line, i32 } // Shift - umem new_line_count = line_count; - umem new_end_line = end_line; + i32 new_line_count = line_count; + i32 new_line_end = line_end; if (line_shift != 0){ new_line_count += line_shift; - new_end_line += line_shift; + new_line_end += line_shift; - memmove(starts + end_line + line_shift, starts + end_line, - sizeof(i32)*(line_count - end_line)); + memmove(starts + line_end + line_shift, starts + line_end, + sizeof(i32)*(line_count - line_end)); } // Iteration data (yikes! Need better loop system) Gap_Buffer_Stream stream = {0}; - umem size = buffer_size(buffer); - umem char_i = starts[start_line]; - umem line_i = start_line; + i32 size = buffer_size(buffer); + i32 char_i = starts[line_start]; + i32 line_i = line_start; // Line start measurement - umem start = char_i; + i32 start = char_i; if (buffer_stringify_loop(&stream, buffer, char_i, size)){ b32 still_looping = 0; @@ -972,8 +963,9 @@ buffer_remeasure_starts(Gap_Buffer *buffer, umem start_line, umem end_line, i32 ++line_i; start = char_i + 1; - // TODO(allen): I would like to know that I am not guessing here, so let's try to turn the && into an Assert. - if (line_i >= new_end_line && (line_i >= new_line_count || start == starts[line_i])){ + // TODO(allen): I would like to know that I am not guessing here, + // so let's try to turn the && into an Assert. + if (line_i >= new_line_end && (line_i >= new_line_count || start == starts[line_i])){ goto buffer_remeasure_starts_end; } } @@ -993,40 +985,41 @@ buffer_remeasure_starts(Gap_Buffer *buffer, umem start_line, umem end_line, i32 } 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); - umem new_line_count = buffer->line_count; + i32 new_line_count = buffer->line_count; - assert(0 <= start_line); - assert(start_line <= end_line); - assert(end_line < new_line_count - line_shift); + assert(0 <= line_start); + assert(line_start <= line_end); + assert(line_end < new_line_count - line_shift); - ++end_line; + ++line_end; // Shift - umem line_count = new_line_count; - umem new_end_line = end_line; + i32 line_count = new_line_count; + i32 new_line_end = line_end; if (line_shift != 0){ line_count -= line_shift; - new_end_line += line_shift; + new_line_end += line_shift; - memmove(character_starts + end_line + line_shift, character_starts + end_line, sizeof(i32)*(line_count - end_line + 1)); + memmove(character_starts + line_end + line_shift, character_starts + line_end, sizeof(i32)*(line_count - line_end + 1)); } // Iteration data Gap_Buffer_Stream stream = {0}; - umem size = buffer_size(buffer); - umem char_i = buffer->line_starts[start_line]; - umem line_i = start_line; + i32 size = buffer_size(buffer); + i32 char_i = buffer->line_starts[line_start]; + i32 line_i = line_start; // Character measurement - umem last_char_start = character_starts[line_i]; - umem current_char_start = last_char_start; + i32 last_char_start = character_starts[line_i]; + i32 current_char_start = last_char_start; + + b32 skipping_whitespace = 0; - b32 skipping_whitespace = false; if (virtual_whitespace){ - skipping_whitespace = true; + skipping_whitespace = 1; } // Translation @@ -1053,7 +1046,7 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G skipping_whitespace = 1; } - if (line_i >= new_end_line){ + if (line_i >= new_line_end){ goto buffer_remeasure_character_starts_end; } } @@ -1071,20 +1064,14 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G still_looping = buffer_stringify_next(&stream); }while(still_looping); } - assert(line_i >= new_end_line); + + assert(line_i >= new_line_end); + buffer_remeasure_character_starts_end:; // Adjust - if (line_i <= new_end_line){ - umem old_value = 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 (line_i <= new_line_end){ + i32 character_shift = current_char_start - character_starts[line_i]; if (character_shift != 0){ character_starts += line_i; @@ -1096,30 +1083,31 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G } internal void -buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 line_shift, f32 *wraps, f32 font_height, f32 *adv, f32 max_width){ - umem new_line_count = buffer->line_count; +buffer_remeasure_wrap_y(Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 line_shift, + f32 *wraps, f32 font_height, f32 *adv, f32 max_width){ + i32 new_line_count = buffer->line_count; - assert(0 <= start_line); - assert(start_line <= end_line); - assert(end_line < new_line_count - line_shift); + assert(0 <= line_start); + assert(line_start <= line_end); + assert(line_end < new_line_count - line_shift); - ++end_line; + ++line_end; // Shift - umem line_count = new_line_count; - umem new_end_line = end_line; + i32 line_count = new_line_count; + i32 new_line_end = line_end; if (line_shift != 0){ line_count -= line_shift; - new_end_line += line_shift; + new_line_end += line_shift; - memmove(wraps + end_line + line_shift, wraps + end_line, sizeof(i32)*(line_count - end_line + 1)); + memmove(wraps + line_end + line_shift, wraps + line_end, sizeof(i32)*(line_count - line_end + 1)); } // Iteration data (yikes! Need better loop system) Gap_Buffer_Stream stream = {0}; - umem size = buffer_size(buffer); - umem char_i = buffer->line_starts[start_line]; - umem line_i = start_line; + i32 size = buffer_size(buffer); + i32 char_i = buffer->line_starts[line_start]; + i32 line_i = line_start; // Line wrap measurement f32 last_wrap = wraps[line_i]; @@ -1127,7 +1115,7 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 f32 x = 0.f; if (buffer_stringify_loop(&stream, buffer, char_i, size)){ - b32 still_looping = false; + b32 still_looping = 0; do{ for (; char_i < stream.end; ++char_i){ u8 ch = (u8)stream.data[char_i]; @@ -1140,7 +1128,7 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 x = 0.f; // TODO(allen): I would like to know that I am not guessing here. - if (line_i >= new_end_line){ + if (line_i >= new_line_end){ goto buffer_remeasure_wraps_end; } } @@ -1164,7 +1152,7 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 buffer_remeasure_wraps_end:; // Adjust - if (line_i <= new_end_line){ + if (line_i <= new_line_end){ f32 y_shift = current_wrap - wraps[line_i]; if (y_shift != 0){ @@ -1176,10 +1164,15 @@ buffer_remeasure_wrap_y(Gap_Buffer *buffer, umem start_line, umem end_line, i32 } } -internal umem -binary_search(umem *array, umem value, umem l_bound, umem u_bound){ - value = clamp_bottom(0, value); - umem start = l_bound, end = u_bound, i = 0; +internal i32 +binary_search(i32 *array, i32 value, i32 l_bound, i32 u_bound){ + i32 start = l_bound, end = u_bound; + i32 i = 0; + + if (value < 0){ + value = 0; + } + for (;;){ i = (start + end) >> 1; if (array[i] < value){ @@ -1197,48 +1190,54 @@ binary_search(umem *array, umem value, umem l_bound, umem u_bound){ break; } } + return(i); } -inline umem -buffer_get_line_index_range(Gap_Buffer *buffer, umem pos, umem l_bound, umem u_bound){ +inline i32 +buffer_get_line_index_range(Gap_Buffer *buffer, i32 pos, i32 l_bound, i32 u_bound){ assert(0 <= l_bound); assert(l_bound <= u_bound); assert(u_bound <= buffer->line_count); assert(buffer->line_starts != 0); - 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); } -inline umem -buffer_get_line_index(Gap_Buffer *buffer, umem pos){ - umem result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); +inline i32 +buffer_get_line_index(Gap_Buffer *buffer, i32 pos){ + i32 result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); return(result); } -inline umem -buffer_get_line_index_from_character_pos(umem *character_starts, umem pos, umem l_bound, umem u_bound){ - umem i = binary_search(character_starts, pos, l_bound, u_bound); +inline i32 +buffer_get_line_index_from_character_pos(i32 *character_starts, i32 pos, i32 l_bound, i32 u_bound){ + i32 i = binary_search(character_starts, pos, l_bound, u_bound); return(i); } -inline umem -buffer_get_line_index_from_wrapped_y(umem *wrap_line_index, f32 y, umem line_height, umem l_bound, umem u_bound){ - umem wrap_index = floor32(y/line_height); - umem i = binary_search(wrap_line_index, wrap_index, l_bound, u_bound); +inline i32 +buffer_get_line_index_from_wrapped_y(i32 *wrap_line_index, f32 y, i32 line_height, i32 l_bound, i32 u_bound){ + i32 wrap_index = floor32(y/line_height); + i32 i = binary_search(wrap_line_index, wrap_index, l_bound, u_bound); return(i); } internal Partial_Cursor -buffer_partial_from_pos(Gap_Buffer *buffer, umem pos){ +buffer_partial_from_pos(Gap_Buffer *buffer, i32 pos){ Partial_Cursor result = {0}; - umem size = buffer_size(buffer); - pos = clamp_umem(0, pos, size); + int32_t size = buffer_size(buffer); + if (pos > size){ + pos = size; + } + if (pos < 0){ + pos = 0; + } - 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.line = 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{ - umem index; + i32 index; u32 codepoint; u32 flags; f32 x0, y0; @@ -1739,7 +1738,8 @@ typedef struct Render_Item_Write{ } Render_Item_Write; inline Render_Item_Write -write_render_item(Render_Item_Write write, umem index, u32 codepoint, u32 flags){ +write_render_item(Render_Item_Write write, i32 index, u32 codepoint, u32 flags){ + f32 ch_width = font_get_glyph_advance(write.system, write.font, codepoint); if (write.x <= write.x_max && write.x + ch_width >= write.x_min){ @@ -1950,7 +1950,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 } if (!S.skipping_whitespace){ - umem I = S.step.i; + u32 I = S.step.i; switch (n){ case '\r': { @@ -1978,7 +1978,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 } else if (S.behavior.do_number_advance){ u8 n = (u8)S.step.value; - umem I = S.step.i; + u32 I = S.step.i; S.skipping_whitespace = false; S.ch_width = S.byte_advance; diff --git a/4ed_buffer_model.h b/4ed_buffer_model.h index a9abc718..86431e3c 100644 --- a/4ed_buffer_model.h +++ b/4ed_buffer_model.h @@ -15,7 +15,7 @@ struct Buffer_Model_Step{ u32 type; u32 value; - umem i; + i32 i; u32 byte_length; }; diff --git a/4ed_file_track.h b/4ed_file_track.h index 698f29fb..0ea2ac37 100644 --- a/4ed_file_track.h +++ b/4ed_file_track.h @@ -31,7 +31,7 @@ enum{ }; FILE_TRACK_LINK File_Track_Result -init_track_system(File_Track_System *system, Partition *scratch, void *table_memory, umem table_memory_size, void *listener_memory, umem listener_memory_size); +init_track_system(File_Track_System *system, Partition *scratch, void *table_memory, i32 table_memory_size, void *listener_memory, i32 listener_memory_size); FILE_TRACK_LINK File_Track_Result add_listener(File_Track_System *system, Partition *scratch, u8 *filename); @@ -40,13 +40,13 @@ FILE_TRACK_LINK File_Track_Result remove_listener(File_Track_System *system, Partition *scratch, u8 *filename); FILE_TRACK_LINK File_Track_Result -move_track_system(File_Track_System *system, Partition *scratch, void *mem, umem size); +move_track_system(File_Track_System *system, Partition *scratch, void *mem, i32 size); FILE_TRACK_LINK File_Track_Result -expand_track_system_listeners(File_Track_System *system, Partition *scratch, void *mem, umem size); +expand_track_system_listeners(File_Track_System *system, Partition *scratch, void *mem, i32 size); FILE_TRACK_LINK File_Track_Result -get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, umem max); +get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 max); FILE_TRACK_LINK File_Track_Result shut_down_track_system(File_Track_System *system, Partition *scratch); diff --git a/4ed_file_track_general.cpp b/4ed_file_track_general.cpp index 3ba45809..0d156cc1 100644 --- a/4ed_file_track_general.cpp +++ b/4ed_file_track_general.cpp @@ -12,7 +12,6 @@ typedef struct{ u32 id[4]; } File_Index; -global_const File_Index null_file_index = {0}; typedef u32 rptr32; @@ -26,7 +25,7 @@ typedef struct { global_const File_Track_Entry null_file_track_entry = {0}; typedef struct { - umem size; + i32 size; u32 tracked_count; u32 max; rptr32 file_table; @@ -37,6 +36,14 @@ typedef struct DLL_Node { struct DLL_Node *prev; } DLL_Node; + + +internal File_Index +zero_file_index(){ + File_Index a = {0}; + return(a); +} + internal i32 file_hash_is_zero(File_Index a){ return ((a.id[0] == 0) && @@ -175,18 +182,18 @@ internal_free_slot(File_Track_Tables *tables, File_Track_Entry *entry){ --tables->tracked_count; } -internal b32 -enough_memory_to_init_table(umem table_memory_size){ - b32 result = (sizeof(File_Track_Tables) + FILE_ENTRY_COST*8 <= table_memory_size); +internal i32 +enough_memory_to_init_table(i32 table_memory_size){ + i32 result = (sizeof(File_Track_Tables) + FILE_ENTRY_COST*8 <= table_memory_size); return(result); } internal void -init_table_memory(File_Track_Tables *tables, umem table_memory_size){ +init_table_memory(File_Track_Tables *tables, i32 table_memory_size){ tables->size = table_memory_size; tables->tracked_count = 0; - u32 max_number_of_entries = (u32)(table_memory_size - sizeof(*tables)) / FILE_ENTRY_COST; + i32 max_number_of_entries = (table_memory_size - sizeof(*tables)) / FILE_ENTRY_COST; tables->file_table = sizeof(*tables); tables->max = max_number_of_entries; @@ -194,7 +201,7 @@ init_table_memory(File_Track_Tables *tables, umem table_memory_size){ internal File_Track_Result move_table_memory(File_Track_Tables *original_tables, - void *mem, umem size){ + void *mem, i32 size){ File_Track_Result result = FileTrack_Good; if (original_tables->size < size){ @@ -205,7 +212,7 @@ move_table_memory(File_Track_Tables *original_tables, tables->size = size; i32 likely_entry_size = FILE_ENTRY_COST; - u32 max_number_of_entries = (u32)(size - sizeof(*tables)) / likely_entry_size; + i32 max_number_of_entries = (size - sizeof(*tables)) / likely_entry_size; tables->file_table = sizeof(*tables); tables->max = max_number_of_entries; diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 6ce55376..0ab0ab0c 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -1000,8 +1000,8 @@ struct Code_Wrap_State{ b32 consume_newline; Gap_Buffer_Stream stream; - umem size; - umem i; + i32 size; + i32 i; Render_Font *font; f32 tab_indent_amount; @@ -1055,8 +1055,8 @@ wrap_state_set_top(Code_Wrap_State *state, f32 line_shift){ } struct Code_Wrap_Step{ - umem position_start; - umem position_end; + i32 position_start; + i32 position_end; f32 start_x; f32 final_x; @@ -1067,7 +1067,7 @@ struct Code_Wrap_Step{ internal Code_Wrap_Step wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_State *state, i32 fixed_end_point){ Code_Wrap_Step result = {0}; - umem i = state->i; + i32 i = state->i; result.position_start = i; @@ -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)); - umem remaining = partition_remaining(part); - umem pair_size = sizeof(Wrap_Indent_Pair); - max_wrap_indent_mark = (i32)(remaining/pair_size); + max_wrap_indent_mark = partition_remaining(part)/sizeof(Wrap_Indent_Pair); wrap_indent_marks = push_array(part, Wrap_Indent_Pair, max_wrap_indent_mark); } @@ -1949,7 +1947,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * buffer_init_provide_page(&init, data, page_size); } - umem scratch_size = partition_remaining(part); + i32 scratch_size = partition_remaining(part); Assert(scratch_size > 0); b32 init_success = buffer_end_init(&init, part->base + part->pos, scratch_size); AllowLocal(init_success); Assert(init_success); @@ -2202,10 +2200,10 @@ file_first_lex_serial(Mem_Options *mem, Editing_File *file){ Gap_Buffer *buffer = &file->state.buffer; i32 text_size = buffer_size(buffer); - umem mem_size = partition_remaining(part); + i32 mem_size = partition_remaining(part); Cpp_Token_Array tokens; - tokens.max_count = (u32)(mem_size / sizeof(Cpp_Token)); + tokens.max_count = mem_size / sizeof(Cpp_Token); tokens.count = 0; tokens.tokens = push_array(part, Cpp_Token, tokens.max_count); diff --git a/4ed_math.h b/4ed_math.h index be489847..9f3df328 100644 --- a/4ed_math.h +++ b/4ed_math.h @@ -452,13 +452,6 @@ clamp(u32 a, u32 n, u32 z){ 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_bottom(a,b) Max(a,b) diff --git a/4ed_system.h b/4ed_system.h index 1e304200..41eb4a2f 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -169,7 +169,8 @@ struct Full_Job_Data{ struct Unbounded_Work_Queue{ Full_Job_Data *jobs; - u32 count, max, skip; + i32 count, max, skip; + u32 next_job_id; }; @@ -203,13 +204,13 @@ typedef Sys_Acquire_Lock_Sig(System_Acquire_Lock); typedef Sys_Release_Lock_Sig(System_Release_Lock); // 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); -#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); -#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); #define Sys_File_Exists_Sig(name) b32 name(char *filename, i32 len) diff --git a/4ed_system_shared.cpp b/4ed_system_shared.cpp index e3fd92c3..4bb6d099 100644 --- a/4ed_system_shared.cpp +++ b/4ed_system_shared.cpp @@ -18,6 +18,17 @@ // 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 init_shared_vars(){ umem scratch_size = KB(128); diff --git a/4ed_system_shared.h b/4ed_system_shared.h index 404493b0..dd52d280 100644 --- a/4ed_system_shared.h +++ b/4ed_system_shared.h @@ -9,7 +9,10 @@ // TOP -// TODO(allen): Find a new name/classification for this. +// NOTE(allen): This serves as a list of functions to implement +// in addition to those in 4ed_system.h These are not exposed to +// the application code, but system_shared.cpp +// rely on the functions listed here. #if !defined(FRED_SYSTEM_SHARED_H) #define FRED_SYSTEM_SHARED_H @@ -21,24 +24,17 @@ struct File_Data{ }; 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) -internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made); - #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); -///////////////////////////////////// - -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; +#define system_get_memory(size) system_get_memory_((size), __LINE__, __FILE__) #endif diff --git a/4ed_translation.cpp b/4ed_translation.cpp index e5318d80..259240c0 100644 --- a/4ed_translation.cpp +++ b/4ed_translation.cpp @@ -13,7 +13,7 @@ struct Translation_State{ u8 fill_buffer[4]; - umem fill_start_i; + u32 fill_start_i; u8 fill_i; u8 fill_expected; }; @@ -47,7 +47,7 @@ struct Translation_Emits{ #define SINGLE_BYTE_ERROR_CLASS max_u8 internal void -translating_consume_byte(Translation_State *tran, u8 ch, umem i, umem size, Translation_Byte_Description *desc_out){ +translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Byte_Description *desc_out){ desc_out->byte_class = 0; if ((ch >= ' ' && ch < 0x7F) || ch == '\t' || ch == '\n' || ch == '\r'){ desc_out->byte_class = 1; @@ -146,7 +146,7 @@ translating_select_emit_rule_with_font(System_Functions *system, Render_Font *fo } internal void -translating_generate_emits(Translation_State *tran, Translation_Emit_Rule emit_rule, u8 ch, umem i, Translation_Emits *emits_out){ +translating_generate_emits(Translation_State *tran, Translation_Emit_Rule emit_rule, u8 ch, u32 i, Translation_Emits *emits_out){ emits_out->step_count = 0; switch (emit_rule.emit_type){ default: goto skip_all; @@ -199,7 +199,7 @@ translating_generate_emits(Translation_State *tran, Translation_Emit_Rule emit_r } internal void -translating_fully_process_byte(System_Functions *system, Render_Font *font, Translation_State *tran, u8 ch, umem i, umem size, Translation_Emits *emits_out){ +translating_fully_process_byte(System_Functions *system, Render_Font *font, Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Emits *emits_out){ Translation_Byte_Description description = {0}; translating_consume_byte(tran, ch, i, size, &description); Translation_Emit_Rule emit_rule = {0}; diff --git a/4tech_defines.h b/4tech_defines.h index b9ecf77e..93ae61da 100644 --- a/4tech_defines.h +++ b/4tech_defines.h @@ -87,10 +87,6 @@ inline u32 l_round_up_u32(u32 x, u32 b){ return( ((x)+(b)-1) - (((x)+(b)-1)%(b)) ); } -inline umem l_round_up_umem(umem x, umem b){ - return( ((x)+(b)-1) - (((x)+(b)-1)%(b)) ); -} - inline u32 round_up_pot_u32(u32 x){ --x; x |= x >> 1; diff --git a/meta/meta_parser.cpp b/meta/meta_parser.cpp index 347dc2e9..0c0f618d 100644 --- a/meta/meta_parser.cpp +++ b/meta/meta_parser.cpp @@ -886,7 +886,7 @@ static Argument_Breakdown parameter_parse(Partition *part, char *data, Cpp_Token *args_start_token, Cpp_Token *args_end_token){ int32_t arg_index = 0; Cpp_Token *arg_token = args_start_token + 1; - uint32_t param_string_start = arg_token->start; + int32_t param_string_start = arg_token->start; int32_t arg_count = 1; arg_token = args_start_token; diff --git a/meta/out_context.cpp b/meta/out_context.cpp index 8350c36e..cb72b558 100644 --- a/meta/out_context.cpp +++ b/meta/out_context.cpp @@ -81,7 +81,7 @@ do_file_copy(Partition *part, char *src_file, char *dst_dir, char *dst_file){ terminate_with_null(&str); Temp_Memory temp = begin_temp_memory(part); - size_t mem_size = partition_remaining(part); + int32_t mem_size = partition_remaining(part); void *mem = push_block(part, mem_size); FILE *in = fopen(src_file, "rb"); if (in){ @@ -89,17 +89,17 @@ do_file_copy(Partition *part, char *src_file, char *dst_dir, char *dst_file){ int32_t file_size = ftell(in); if (mem_size >= file_size){ - fseek(in, 0, SEEK_SET); - fread(mem, 1, file_size, in); - - FILE *out = fopen(dst, "wb"); - if (out){ - fwrite(mem, 1, file_size, out); - fclose(out); - success = 1; - } + fseek(in, 0, SEEK_SET); + fread(mem, 1, file_size, in); + + FILE *out = fopen(dst, "wb"); + if (out){ + fwrite(mem, 1, file_size, out); + fclose(out); + success = 1; } - + } + fclose(in); } end_temp_memory(temp); diff --git a/power/4coder_experiments.cpp b/power/4coder_experiments.cpp index b5fb94eb..b9c941f9 100644 --- a/power/4coder_experiments.cpp +++ b/power/4coder_experiments.cpp @@ -1116,10 +1116,8 @@ CUSTOM_COMMAND_SIG(rename_parameter){ String replace_string = with.string; Buffer_Edit *edits = (Buffer_Edit*)partition_current(part); - size_t remaining = partition_remaining(part); - size_t edit_size = sizeof(Buffer_Edit); - uint32_t edit_max = (uint32_t)(remaining/edit_size); - uint32_t edit_count = 0; + int32_t edit_max = (partition_remaining(part))/sizeof(Buffer_Edit); + int32_t edit_count = 0; if (edit_max >= 1){ Buffer_Edit edit; @@ -1142,7 +1140,7 @@ CUSTOM_COMMAND_SIG(rename_parameter){ switch (token_ptr->type){ case CPP_TOKEN_IDENTIFIER: { - if (token_ptr->size == (uint32_t)old_lexeme.size){ + if (token_ptr->size == old_lexeme.size){ char other_lexeme_base[128]; String other_lexeme = make_fixed_width_string(other_lexeme_base); other_lexeme.size = old_lexeme.size; @@ -1255,8 +1253,7 @@ CUSTOM_COMMAND_SIG(write_explicit_enum_values){ Buffer_Edit *edits = push_array(part, Buffer_Edit, count_estimate); char *string_base = (char*)partition_current(part); - uint32_t remaining = (uint32_t)partition_remaining(part); - String string = make_string(string_base, 0, remaining); + String string = make_string(string_base, 0, partition_remaining(part)); closed_correctly = false; still_looping = false; diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 390c2446..5fbc36e7 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -283,13 +283,40 @@ Sys_Memory_Free_Sig(system_memory_free){ VirtualFree(ptr, 0, MEM_RELEASE); } -#define Win32GetMemory(size) system_memory_allocate(size) -#define Win32FreeMemory(ptr) system_memory_free(ptr) +// TODO(allen): delete +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 Win32ScratchPartitionGrow sysshared_partition_grow #define Win32ScratchPartitionDouble sysshared_partition_double +#if 0 +#if FRED_INTERNAL +internal void +INTERNAL_system_debug_message(char *message){ + OutputDebugStringW(message); +} +#endif +#endif + // // Multithreading @@ -380,8 +407,8 @@ JobThreadProc(LPVOID lpParameter){ internal void initialize_unbounded_queue(Unbounded_Work_Queue *source_queue){ - u32 max = 512; - source_queue->jobs = (Full_Job_Data*)system_memory_allocate(max*sizeof(Full_Job_Data)); + i32 max = 512; + source_queue->jobs = (Full_Job_Data*)system_get_memory(max*sizeof(Full_Job_Data)); source_queue->count = 0; source_queue->max = max; source_queue->skip = 0; @@ -493,11 +520,11 @@ Sys_Post_Job_Sig(system_post_job){ while (queue->count >= queue->max){ i32 new_max = queue->max*2; Full_Job_Data *new_jobs = (Full_Job_Data*) - system_memory_allocate(new_max*sizeof(Full_Job_Data)); + system_get_memory(new_max*sizeof(Full_Job_Data)); memcpy(new_jobs, queue->jobs, queue->count); - system_memory_free(queue->jobs, 0); + system_free_memory(queue->jobs); queue->jobs = new_jobs; queue->max = new_max; @@ -587,11 +614,11 @@ Sys_Grow_Thread_Memory_Sig(system_grow_thread_memory){ void *old_data = memory->data; i32 old_size = memory->size; 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; if (old_data){ 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); } @@ -717,29 +744,15 @@ Sys_Yield_Coroutine_Sig(system_yield_coroutine){ internal 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; - Temp_Memory temp = begin_temp_memory(scratch); - umem len = str_size(filename); - umem max = (len+1)*2; - u16 *filename_16 = push_array(scratch, u16, max); - - b32 error = false; - utf8_to_utf16_minimal_checking(filename_16, max, filename, len, &error); - - if (!error){ - HANDLE file = CreateFile((LPCWSTR)filename_16, FILE_APPEND_DATA, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - - if (file != 0 && file != INVALID_HANDLE_VALUE){ - result = true; - CloseHandle(file); - } + if (!file || file == INVALID_HANDLE_VALUE){ + return 0; } - end_temp_memory(temp); + CloseHandle(file); - return(result); + return(1); } internal @@ -1373,6 +1386,8 @@ Sys_Send_Exit_Signal_Sig(system_send_exit_signal){ #include "4ed_system_shared.cpp" +#include "win32_4ed_fonts.cpp" + // // 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 "win32_4ed_fonts.cpp" -//#include "win32_4ed_file_track.cpp" - #if 0 // NOTE(allen): In case I want to switch back to a console // application at some point. diff --git a/win32_4ed_file_track.cpp b/win32_4ed_file_track.cpp index d0b03d3d..683663ac 100644 --- a/win32_4ed_file_track.cpp +++ b/win32_4ed_file_track.cpp @@ -44,7 +44,7 @@ typedef struct { #define to_tables(v) ((File_Track_Tables*)(v->tables)) FILE_TRACK_LINK File_Track_Result -init_track_system(File_Track_System *system, Partition *scratch, void *table_memory, umem table_memory_size, void *listener_memory, umem listener_memory_size){ +init_track_system(File_Track_System *system, Partition *scratch, void *table_memory, i32 table_memory_size, void *listener_memory, i32 listener_memory_size){ File_Track_Result result = FileTrack_MemoryTooSmall; Win32_File_Track_Vars *vars = to_vars(system); @@ -63,9 +63,8 @@ init_track_system(File_Track_System *system, Partition *scratch, void *table_mem init_sentinel_node(&vars->free_sentinel); Win32_Directory_Listener_Node *listener = (Win32_Directory_Listener_Node*)listener_memory; - umem node_size = sizeof(Win32_Directory_Listener_Node); - u32 count = (u32)(listener_memory_size / node_size); - for (u32 i = 0; i < count; ++i, ++listener){ + i32 count = listener_memory_size / sizeof(Win32_Directory_Listener_Node); + for (i32 i = 0; i < count; ++i, ++listener){ insert_node(&vars->free_sentinel, &listener->node); } } @@ -255,7 +254,7 @@ remove_listener(File_Track_System *system, Partition *scratch, u8 *filename){ } FILE_TRACK_LINK File_Track_Result -move_track_system(File_Track_System *system, Partition *scratch, void *mem, umem size){ +move_track_system(File_Track_System *system, Partition *scratch, void *mem, i32 size){ File_Track_Result result = FileTrack_Good; Win32_File_Track_Vars *vars = to_vars(system); @@ -271,7 +270,7 @@ move_track_system(File_Track_System *system, Partition *scratch, void *mem, umem } FILE_TRACK_LINK File_Track_Result -expand_track_system_listeners(File_Track_System *system, Partition *scratch, void *mem, umem size){ +expand_track_system_listeners(File_Track_System *system, Partition *scratch, void *mem, i32 size){ File_Track_Result result = FileTrack_Good; Win32_File_Track_Vars *vars = to_vars(system); @@ -279,9 +278,8 @@ expand_track_system_listeners(File_Track_System *system, Partition *scratch, voi if (sizeof(Win32_Directory_Listener_Node) <= size){ Win32_Directory_Listener_Node *listener = (Win32_Directory_Listener_Node*)mem; - umem node_size = sizeof(Win32_Directory_Listener_Node); - u32 count = (u32)(size / node_size); - for (u32 i = 0; i < count; ++i, ++listener){ + i32 count = size / sizeof(Win32_Directory_Listener_Node); + for (i32 i = 0; i < count; ++i, ++listener){ insert_node(&vars->free_sentinel, &listener->node); } } @@ -295,7 +293,7 @@ expand_track_system_listeners(File_Track_System *system, Partition *scratch, voi } FILE_TRACK_LINK File_Track_Result -get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 max, umem *size){ +get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 max, i32 *size){ File_Track_Result result = FileTrack_NoMoreEvents; Win32_File_Track_Vars *vars = to_vars(system); @@ -303,19 +301,17 @@ get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 local_persist DWORD offset = 0; local_persist Win32_Directory_Listener listener = {0}; - Temp_Memory temp = begin_temp_memory(scratch); - EnterCriticalSection(&vars->table_lock); OVERLAPPED *overlapped = 0; DWORD length = 0; ULONG_PTR key = 0; - b32 has_result = false; + b32 has_result = 0; if (has_buffered_event){ has_buffered_event = 0; - has_result = true; + has_result = 1; } else{ if (GetQueuedCompletionStatus(vars->iocp, &length, &key, &overlapped, 0)){ @@ -328,7 +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); 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 req_size = dir_len + 1 + len; + *size = req_size; if (req_size < max){ - u16 *buffer_16 = push_array(scratch, u16, req_size+1); - i32 pos = GetFinalPathNameByHandle(listener.dir, (LPWSTR)buffer_16, max, FILE_NAME_NORMALIZED); + i32 pos = GetFinalPathNameByHandle(listener.dir, buffer, max, FILE_NAME_NORMALIZED); + buffer[pos++] = '\\'; - b32 convert_error = false; - umem buffer_size = utf16_to_utf8_minimal_checking(buffer, max-1, buffer_16, pos, &convert_error); - - if (buffer_size > max-1){ - result = FileTrack_MemoryTooSmall; + for (i32 i = 0; i < len; ++i, ++pos){ + buffer[pos] = (char)info->FileName[i]; } - else if (!convert_error){ - buffer[buffer_size++] = '\\'; - - if (buffer[0] == '\\'){ - for (i32 i = 0; i+4 < buffer_size; ++i){ - buffer[i] = buffer[i+4]; - } - buffer_size -= 4; + + if (buffer[0] == '\\'){ + for (i32 i = 0; i+4 < pos; ++i){ + buffer[i] = buffer[i+4]; } - *size = buffer_size; - result = FileTrack_Good; - } - else{ - result = FileTrack_FileSystemError; + *size -= 4; } + + result = FileTrack_Good; } else{ - // TODO(allen): Need some way to stash this result so that if the user comes back with more memory we can give them the change notification they missed. + // TODO(allen): Need some way to stash this result so that if the + // user comes back with more memory we can give them the change + // notification they missed. result = FileTrack_MemoryTooSmall; } if (info->NextEntryOffset != 0){ - // TODO(allen): We're not ready to handle this yet. For now I am breaking. In the future, if there are more results we should stash them and return them in future calls. + // TODO(allen): We're not ready to handle this yet. + // For now I am breaking. In the future, if there + // are more results we should stash them and return + // them in future calls. offset += info->NextEntryOffset; has_buffered_event = 1; } @@ -379,8 +372,6 @@ get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 LeaveCriticalSection(&vars->table_lock); - end_temp_memory(temp); - return(result); } From 3515722fdbd6cff767d3e663cdb4e381df2e1569 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 23 Mar 2017 18:45:32 -0400 Subject: [PATCH 09/17] fixed the utf8 <-> utf16 system in win32 --- 4coder_API/types.h | 4 +- 4coder_API/version.h | 15 +++ 4coder_lib/4coder_utf8.h | 4 +- 4coder_project_commands.cpp | 2 +- 4ed_file_track.h | 2 +- 4ed_system.h | 6 +- 4ed_system_shared.cpp | 53 ++++---- 4ed_system_shared.h | 8 +- internal_4coder_tests.cpp | 2 +- win32_4ed.cpp | 194 ++++++++++++--------------- win32_4ed_file_track.cpp | 30 ++--- win32_utf8.cpp | 258 ++++++++++++++++++++++++++++++++++++ win32_utf8.h | 42 ++++++ 13 files changed, 453 insertions(+), 167 deletions(-) create mode 100644 win32_utf8.cpp create mode 100644 win32_utf8.h diff --git a/4coder_API/types.h b/4coder_API/types.h index 06d45281..6d9a3d6f 100644 --- a/4coder_API/types.h +++ b/4coder_API/types.h @@ -431,9 +431,9 @@ STRUCT File_List{ /* DOC(This field is an array of File_Info structs.) */ File_Info *infos; /* DOC(This field specifies the number of struts in the info array.) */ - int32_t count; + uint32_t count; /* DOC(This field is for internal use.) */ - int32_t block_size; + uint32_t block_size; }; /* DOC(Buffer_Identifier acts as a loosely typed description of a buffer that can either be a name or an id.) */ diff --git a/4coder_API/version.h b/4coder_API/version.h index 496d6f8e..67f7e71c 100644 --- a/4coder_API/version.h +++ b/4coder_API/version.h @@ -2,6 +2,7 @@ #define MINOR 0 #define PATCH 18 +// string #define VN__(a,b,c) #a"."#b"."#c #define VN_(a,b,c) VN__(a,b,c) #define VERSION_NUMBER VN_(MAJOR,MINOR,PATCH) @@ -14,3 +15,17 @@ #endif #define VERSION VERSION_STRING VERSION_TYPE + +// long string +#define L_VN__(a,b,c) L#a L"." L#b L"." L#c +#define L_VN_(a,b,c) L_VN__(a,b,c) +#define L_VERSION_NUMBER L_VN_(MAJOR,MINOR,PATCH) +#define L_VERSION_STRING L"alpha " L_VERSION_NUMBER + +#if defined(FRED_SUPER) +#define L_VERSION_TYPE L" super!" +#else +#define L_VERSION_TYPE +#endif + +#define L_VERSION L_VERSION_STRING L_VERSION_TYPE diff --git a/4coder_lib/4coder_utf8.h b/4coder_lib/4coder_utf8.h index 76d6580d..7d20a7e6 100644 --- a/4coder_lib/4coder_utf8.h +++ b/4coder_lib/4coder_utf8.h @@ -281,10 +281,10 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * static umem_4tech utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *src, umem_4tech length, b32_4tech *error){ u16_4tech *s = src; - u16_4tech *s_end = s + max_chars; + u16_4tech *s_end = s + length; u8_4tech *d = dst; - u8_4tech *d_end = d + length; + u8_4tech *d_end = d + max_chars; umem_4tech limit = length; umem_4tech needed_max = 0; diff --git a/4coder_project_commands.cpp b/4coder_project_commands.cpp index c1d96f7a..c9104821 100644 --- a/4coder_project_commands.cpp +++ b/4coder_project_commands.cpp @@ -102,7 +102,7 @@ open_all_files_with_extension_internal(Application_Links *app, String dir, char File_List list = get_file_list(app, dir.str, dir.size); int32_t dir_size = dir.size; - for (int32_t i = 0; i < list.count; ++i){ + for (uint32_t i = 0; i < list.count; ++i){ File_Info *info = list.infos + i; if (info->folder){ if (recursive){ diff --git a/4ed_file_track.h b/4ed_file_track.h index 0ea2ac37..c09ef694 100644 --- a/4ed_file_track.h +++ b/4ed_file_track.h @@ -46,7 +46,7 @@ FILE_TRACK_LINK File_Track_Result expand_track_system_listeners(File_Track_System *system, Partition *scratch, void *mem, i32 size); FILE_TRACK_LINK File_Track_Result -get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 max); +get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 max, i32 *size); FILE_TRACK_LINK File_Track_Result shut_down_track_system(File_Track_System *system, Partition *scratch); diff --git a/4ed_system.h b/4ed_system.h index 41eb4a2f..70b92b6e 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -204,13 +204,13 @@ typedef Sys_Acquire_Lock_Sig(System_Acquire_Lock); typedef Sys_Release_Lock_Sig(System_Release_Lock); // needed for custom layer -#define Sys_Memory_Allocate_Sig(name) void* name(i32 size) +#define Sys_Memory_Allocate_Sig(name) void* name(umem size) typedef Sys_Memory_Allocate_Sig(System_Memory_Allocate); -#define Sys_Memory_Set_Protection_Sig(name) bool32 name(void *ptr, i32 size, u32 flags) +#define Sys_Memory_Set_Protection_Sig(name) bool32 name(void *ptr, umem size, u32 flags) typedef Sys_Memory_Set_Protection_Sig(System_Memory_Set_Protection); -#define Sys_Memory_Free_Sig(name) void name(void *ptr, i32 size) +#define Sys_Memory_Free_Sig(name) void name(void *ptr, umem size) typedef Sys_Memory_Free_Sig(System_Memory_Free); #define Sys_File_Exists_Sig(name) b32 name(char *filename, i32 len) diff --git a/4ed_system_shared.cpp b/4ed_system_shared.cpp index 4bb6d099..b9128811 100644 --- a/4ed_system_shared.cpp +++ b/4ed_system_shared.cpp @@ -32,14 +32,14 @@ global Shared_Vars shared_vars; internal void init_shared_vars(){ umem scratch_size = KB(128); - void *scratch_memory = system_get_memory(scratch_size); - shared_vars.scratch = make_part(scratch_memory, scratch_size); + void *scratch_memory = system_memory_allocate(scratch_size); + shared_vars.scratch = make_part(scratch_memory, (i32)scratch_size); shared_vars.track_table_size = KB(16); - shared_vars.track_table = system_get_memory(shared_vars.track_table_size); + shared_vars.track_table = system_memory_allocate(shared_vars.track_table_size); shared_vars.track_node_size = KB(16); - void *track_nodes = system_get_memory(shared_vars.track_node_size); + void *track_nodes = system_memory_allocate(shared_vars.track_node_size); i32 track_result = init_track_system(&shared_vars.track, &shared_vars.scratch, shared_vars.track_table, shared_vars.track_table_size, track_nodes, shared_vars.track_node_size); @@ -56,9 +56,9 @@ handle_track_out_of_memory(i32 val){ case FileTrack_OutOfTableMemory: { u32 new_table_size = shared_vars.track_table_size*2; - void *new_table = system_get_memory(new_table_size); + void *new_table = system_memory_allocate(new_table_size); move_track_system(&shared_vars.track, &shared_vars.scratch, new_table, new_table_size); - system_free_memory(shared_vars.track_table); + system_memory_free(shared_vars.track_table, shared_vars.track_table_size); shared_vars.track_table_size = new_table_size; shared_vars.track_table = new_table; }break; @@ -66,7 +66,7 @@ handle_track_out_of_memory(i32 val){ case FileTrack_OutOfListenerMemory: { shared_vars.track_node_size *= 2; - void *node_expansion = system_get_memory(shared_vars.track_node_size); + void *node_expansion = system_memory_allocate(shared_vars.track_node_size); expand_track_system_listeners(&shared_vars.track, &shared_vars.scratch, node_expansion, shared_vars.track_node_size); }break; @@ -78,13 +78,13 @@ handle_track_out_of_memory(i32 val){ internal Sys_Add_Listener_Sig(system_add_listener){ - b32 result = 0; + b32 result = false; for (;;){ - i32 track_result = add_listener(&shared_vars.track, &shared_vars.scratch, filename); + i32 track_result = add_listener(&shared_vars.track, &shared_vars.scratch, (u8*)filename); if (handle_track_out_of_memory(track_result)){ if (track_result == FileTrack_Good){ - result = 1; + result = true; } break; } @@ -95,10 +95,10 @@ Sys_Add_Listener_Sig(system_add_listener){ internal Sys_Remove_Listener_Sig(system_remove_listener){ - i32 result = 0; - i32 track_result = remove_listener(&shared_vars.track, &shared_vars.scratch, filename); + b32 result = false; + i32 track_result = remove_listener(&shared_vars.track, &shared_vars.scratch, (u8*)filename); if (track_result == FileTrack_Good){ - result = 1; + result = true; } return(result); } @@ -108,7 +108,7 @@ Sys_Get_File_Change_Sig(system_get_file_change){ b32 result = false; i32 size = 0; - i32 get_result = get_change_event(&shared_vars.track, &shared_vars.scratch, buffer, max, &size); + i32 get_result = get_change_event(&shared_vars.track, &shared_vars.scratch, (u8*)buffer, max, &size); *required_size = size; *mem_too_small = false; @@ -138,14 +138,14 @@ sysshared_load_file(char *filename){ result.got_file = 1; if (size > 0){ result.size = size; - result.data = (char*)system_get_memory(size+1); + result.data = (char*)system_memory_allocate(size+1); if (!result.data){ result = null_file_data; } else{ if (!system_load_file(handle, result.data, size)){ - system_free_memory(result.data); + system_memory_free(result.data, size+1); result = null_file_data; } } @@ -159,21 +159,19 @@ sysshared_load_file(char *filename){ internal b32 usable_ascii(char c){ - b32 result = 1; + b32 result = true; if ((c < ' ' || c > '~') && c != '\n' && c != '\r' && c != '\t'){ - result = 0; + result = false; } return(result); } internal void sysshared_filter_real_files(char **files, i32 *file_count){ - i32 i, j; - i32 end; - - end = *file_count; - for (i = 0, j = 0; i < end; ++i){ - if (system_file_can_be_made(files[i])){ + i32 end = *file_count; + i32 i = 0, j = 0; + for (; i < end; ++i){ + if (system_file_can_be_made((u8*)files[i])){ files[j] = files[i]; ++j; } @@ -183,7 +181,7 @@ sysshared_filter_real_files(char **files, i32 *file_count){ internal Partition sysshared_scratch_partition(i32 size){ - void *data = system_get_memory(size); + void *data = system_memory_allocate((umem)size); Partition part = make_part(data, size); return(part); } @@ -193,10 +191,11 @@ sysshared_partition_grow(Partition *part, i32 new_size){ void *data = 0; if (new_size > part->max){ // TODO(allen): attempt to grow in place by just acquiring next vpages?! - data = system_get_memory(new_size); + data = system_memory_allocate((umem)new_size); memcpy(data, part->base, part->pos); - system_free_memory(part->base); + system_memory_free(part->base, part->max); part->base = (char*)data; + part->max = new_size; } } diff --git a/4ed_system_shared.h b/4ed_system_shared.h index dd52d280..0347f017 100644 --- a/4ed_system_shared.h +++ b/4ed_system_shared.h @@ -24,18 +24,12 @@ struct File_Data{ }; 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(u8 *filename) #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); -#define system_get_memory(size) system_get_memory_((size), __LINE__, __FILE__) - #endif // BOTTOM diff --git a/internal_4coder_tests.cpp b/internal_4coder_tests.cpp index 59184519..9e1935a9 100644 --- a/internal_4coder_tests.cpp +++ b/internal_4coder_tests.cpp @@ -47,7 +47,7 @@ CUSTOM_COMMAND_SIG(load_lots_of_files){ append_s_char(&str, '/'); int32_t size = str.size; - for (int32_t i = 0; i < list.count; ++i, ++info){ + for (uint32_t i = 0; i < list.count; ++i, ++info){ if (!info->folder){ append_ss(&str, make_string(info->filename, info->filename_len)); Buffer_Summary buffer = create_buffer(app, str.str, str.size, diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 5fbc36e7..311f1f2b 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -71,7 +71,10 @@ ////////////////////////////// +#include "win32_utf8.h" + #include "4ed_file_track.h" +#include "font/4coder_font_interface_to_os.h" #include "4ed_system_shared.h" #include "win32_4ed_file_track.cpp" @@ -283,41 +286,6 @@ Sys_Memory_Free_Sig(system_memory_free){ VirtualFree(ptr, 0, MEM_RELEASE); } -// TODO(allen): delete -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 Win32ScratchPartitionGrow sysshared_partition_grow -#define Win32ScratchPartitionDouble sysshared_partition_double - -#if 0 -#if FRED_INTERNAL -internal void -INTERNAL_system_debug_message(char *message){ - OutputDebugStringW(message); -} -#endif -#endif - - // // Multithreading // @@ -358,7 +326,7 @@ JobThreadProc(LPVOID lpParameter){ if (thread_memory->size == 0){ i32 new_size = KB(64); - thread_memory->data = Win32GetMemory(new_size); + thread_memory->data = system_memory_allocate(new_size); thread_memory->size = new_size; } @@ -408,7 +376,7 @@ JobThreadProc(LPVOID lpParameter){ internal void initialize_unbounded_queue(Unbounded_Work_Queue *source_queue){ i32 max = 512; - source_queue->jobs = (Full_Job_Data*)system_get_memory(max*sizeof(Full_Job_Data)); + source_queue->jobs = (Full_Job_Data*)system_memory_allocate(max*sizeof(Full_Job_Data)); source_queue->count = 0; source_queue->max = max; source_queue->skip = 0; @@ -518,13 +486,12 @@ Sys_Post_Job_Sig(system_post_job){ u32 result = queue->next_job_id++; while (queue->count >= queue->max){ - i32 new_max = queue->max*2; - Full_Job_Data *new_jobs = (Full_Job_Data*) - system_get_memory(new_max*sizeof(Full_Job_Data)); + u32 new_max = queue->max*2; + Full_Job_Data *new_jobs = (Full_Job_Data*)system_memory_allocate(new_max*sizeof(Full_Job_Data)); memcpy(new_jobs, queue->jobs, queue->count); - system_free_memory(queue->jobs); + system_memory_free(queue->jobs, 0); queue->jobs = new_jobs; queue->max = new_max; @@ -614,11 +581,11 @@ Sys_Grow_Thread_Memory_Sig(system_grow_thread_memory){ void *old_data = memory->data; i32 old_size = memory->size; i32 new_size = l_round_up_i32(memory->size*2, KB(4)); - memory->data = system_get_memory(new_size); + memory->data = system_memory_allocate(new_size); memory->size = new_size; if (old_data){ memcpy(memory->data, old_data, old_size); - system_free_memory(old_data); + system_memory_free(old_data, 0); } system_release_lock(CANCEL_LOCK0 + memory->id - 1); } @@ -744,15 +711,13 @@ Sys_Yield_Coroutine_Sig(system_yield_coroutine){ internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made){ - HANDLE file = CreateFile((char*)filename, FILE_APPEND_DATA, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - - if (!file || file == INVALID_HANDLE_VALUE){ - return 0; + HANDLE file = CreateFile_utf8(filename, FILE_APPEND_DATA, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + b32 result = false; + if (file != 0 && file != INVALID_HANDLE_VALUE){ + CloseHandle(file); + result = true; } - - CloseHandle(file); - - return(1); + return(result); } internal @@ -764,14 +729,14 @@ Sys_Set_File_List_Sig(system_set_file_list){ append_sc(&dir, directory); terminate_with_null(&dir); - HANDLE dir_handle = CreateFile(dir.str, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + HANDLE dir_handle = CreateFile_utf8((u8*)dir.str, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir_handle != INVALID_HANDLE_VALUE){ - DWORD final_length = GetFinalPathNameByHandle(dir_handle, dir_space, sizeof(dir_space), 0); + DWORD final_length = GetFinalPathNameByHandle_utf8(dir_handle, (u8*)dir_space, sizeof(dir_space), 0); CloseHandle(dir_handle); if (final_length < sizeof(dir_space)){ - char *c_str_dir = dir_space; + u8 *c_str_dir = (u8*)dir_space; final_length -= 4; memmove(c_str_dir, c_str_dir+4, final_length); @@ -796,17 +761,18 @@ Sys_Set_File_List_Sig(system_set_file_list){ } WIN32_FIND_DATA find_data; - HANDLE search = FindFirstFile(c_str_dir, &find_data); + HANDLE search = FindFirstFile_utf8(c_str_dir, &find_data); if (search != INVALID_HANDLE_VALUE){ - i32 character_count = 0; - i32 file_count = 0; + u32 character_count = 0; + u32 file_count = 0; BOOL more_files = true; do{ - if (!match_cs(find_data.cFileName, make_lit_string(".")) && - !match_cs(find_data.cFileName, make_lit_string(".."))){ + b32 nav_dir = + (find_data.cFileName[0] == '.' && find_data.cFileName[1] == 0) ||(find_data.cFileName[0] == '.' && find_data.cFileName[1] == '.' && find_data.cFileName[2] == 0); + if (!nav_dir){ ++file_count; - i32 size = 0; + u32 size = 0; for(;find_data.cFileName[size];++size); character_count += size + 1; } @@ -814,41 +780,57 @@ Sys_Set_File_List_Sig(system_set_file_list){ }while(more_files); FindClose(search); - i32 required_size = character_count + file_count * sizeof(File_Info); + u32 remaining_size = character_count*2; + u32 required_size = remaining_size + file_count*sizeof(File_Info); if (file_list->block_size < required_size){ - system_free_memory(file_list->block); - file_list->block = system_get_memory(required_size); + system_memory_free(file_list->block, 0); + file_list->block = system_memory_allocate(required_size); file_list->block_size = required_size; } file_list->infos = (File_Info*)file_list->block; - char *name = (char*)(file_list->infos + file_count); + u8 *name = (u8*)(file_list->infos + file_count); + u32 corrected_file_count = 0; if (file_list->block != 0){ - search = FindFirstFile(c_str_dir, &find_data); + search = FindFirstFile_utf8(c_str_dir, &find_data); if (search != INVALID_HANDLE_VALUE){ File_Info *info = file_list->infos; more_files = true; do{ - if (!match_cs(find_data.cFileName, make_lit_string(".")) && - !match_cs(find_data.cFileName, make_lit_string(".."))){ + b32 nav_dir = + (find_data.cFileName[0] == '.' && find_data.cFileName[1] == 0) ||(find_data.cFileName[0] == '.' && find_data.cFileName[1] == '.' && find_data.cFileName[2] == 0); + + if (!nav_dir){ info->folder = (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; - info->filename = name; + info->filename = (char*)name; - i32 length = copy_fast_unsafe_cc(name, find_data.cFileName); - name += length; + u16 *src = (u16*)find_data.cFileName; + u32 src_len = 0; + for (;src[src_len];++src_len); - info->filename_len = length; - *name++ = 0; - String fname = make_string_cap(info->filename, info->filename_len, info->filename_len+1); - replace_char(&fname, '\\', '/'); - ++info; + u8 *dst = name; + u32 max = remaining_size-1; + + b32 error = false; + u32 length = (u32)utf16_to_utf8_minimal_checking(dst, max, src, src_len, &error); + + if (length <= max && !error){ + name += length; + + info->filename_len = length; + *name++ = 0; + String fname = make_string_cap(info->filename, length, length+1); + replace_char(&fname, '\\', '/'); + ++info; + ++corrected_file_count; + } } more_files = FindNextFile(search, &find_data); }while(more_files); FindClose(search); - file_list->count = file_count; + file_list->count = corrected_file_count; clear_list = false; } } @@ -858,7 +840,7 @@ Sys_Set_File_List_Sig(system_set_file_list){ } if (clear_list){ - Win32FreeMemory(file_list->block); + system_memory_free(file_list->block, 0); file_list->block = 0; file_list->block_size = 0; file_list->infos = 0; @@ -875,10 +857,10 @@ win32_canonical_ascii_name(char *src, u32 len, char *dst, u32 max){ memcpy(src_space, src, len); src_space[len] = 0; - HANDLE file = CreateFile(src_space, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + HANDLE file = CreateFile_utf8((u8*)src_space, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ - DWORD final_length = GetFinalPathNameByHandle(file, dst, max, 0); + DWORD final_length = GetFinalPathNameByHandle_utf8(file, (u8*)dst, max, 0); if (final_length < max && final_length >= 4){ if (dst[final_length-1] == 0){ @@ -900,10 +882,10 @@ win32_canonical_ascii_name(char *src, u32 len, char *dst, u32 max){ memcpy(src_space, path_str.str, path_str.size); src_space[path_str.size] = 0; - HANDLE dir = CreateFile(src_space, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + HANDLE dir = CreateFile_utf8((u8*)src_space, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir != INVALID_HANDLE_VALUE){ - DWORD final_length = GetFinalPathNameByHandle(dir, dst, max, 0); + DWORD final_length = GetFinalPathNameByHandle_utf8(dir, (u8*)dst, max, 0); if (final_length < max && final_length >= 4){ if (dst[final_length-1] == 0){ @@ -934,12 +916,12 @@ Sys_Get_Canonical_Sig(system_get_canonical){ internal Sys_Load_Handle_Sig(system_load_handle){ - b32 result = 0; - HANDLE file = CreateFile(filename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + b32 result = false; + HANDLE file = CreateFile_utf8((u8*)filename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ *(HANDLE*)handle_out = file; - result = 1; + result = true; } return(result); @@ -988,14 +970,14 @@ Sys_Load_Close_Sig(system_load_close){ internal Sys_Save_File_Sig(system_save_file){ - b32 result = 0; - HANDLE file = CreateFile(filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + b32 result = false; + HANDLE file = CreateFile_utf8((u8*)filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ DWORD written_total = 0; DWORD written_size = 0; - result = 1; + result = true; while (written_total < size){ if (!WriteFile(file, buffer + written_total, size - written_total, &written_size, 0)){ @@ -1019,14 +1001,14 @@ Sys_Now_Time_Sig(system_now_time){ internal b32 Win32DirectoryExists(char *path){ - DWORD attrib = GetFileAttributes(path); - return (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY)); + DWORD attrib = GetFileAttributes_utf8((u8*)path); + return(attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY)); } internal Sys_Get_Binary_Path_Sig(system_get_binary_path){ i32 result = 0; - i32 size = GetModuleFileName(0, out->str, out->memory_size); + i32 size = GetModuleFileName_utf8(0, (u8*)out->str, out->memory_size); if (size < out->memory_size-1){ out->size = size; remove_last_folder(out); @@ -1048,8 +1030,7 @@ Sys_File_Exists_Sig(system_file_exists){ copy_ss(&full_filename, make_string(filename, len)); terminate_with_null(&full_filename); - file = CreateFile(full_filename.str, GENERIC_READ, 0, 0, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + file = CreateFile_utf8((u8*)full_filename.str, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ CloseHandle(file); @@ -1223,10 +1204,7 @@ Sys_CLI_Call_Sig(system_cli_call){ PROCESS_INFORMATION info = {}; Assert(sizeof(Plat_Handle) >= sizeof(HANDLE)); - if (CreateProcess(cmd, command_line, - 0, 0, TRUE, 0, - env_variables, path, - &startup, &info)){ + if (CreateProcess_utf8((u8*)cmd, (u8*)command_line, 0, 0, TRUE, 0, env_variables, (u8*)path, &startup, &info)){ success = 1; CloseHandle(info.hThread); *(HANDLE*)&cli_out->proc = info.hProcess; @@ -2023,7 +2001,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS memory_vars.user_memory = VirtualAlloc(base, memory_vars.target_memory_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); win32vars.target.max = MB(1); - win32vars.target.push_buffer = (char*)system_get_memory(win32vars.target.max); + win32vars.target.push_buffer = (char*)system_memory_allocate(win32vars.target.max); if (memory_vars.vars_memory == 0 || memory_vars.target_memory == 0 || memory_vars.user_memory == 0 || win32vars.target.push_buffer == 0){ exit(1); @@ -2051,8 +2029,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // DWORD required = (GetCurrentDirectory(0, 0)*4) + 1; - char *current_directory_mem = (char*)system_get_memory(required); - DWORD written = GetCurrentDirectory(required, current_directory_mem); + u8 *current_directory_mem = (u8*)system_memory_allocate(required); + DWORD written = GetCurrentDirectory_utf8(required, current_directory_mem); String current_directory = make_string_cap(current_directory_mem, written, required); terminate_with_null(¤t_directory); @@ -2092,15 +2070,14 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS if (win32vars.custom_api.get_alpha_4coder_version == 0 || win32vars.custom_api.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){ - MessageBox(0,"Error: The application and custom version numbers don't match.\n", "Error",0); + MessageBox_utf8(0, (u8*)"Error: The application and custom version numbers don't match.\n", (u8*)"Error",0); exit(1); } - win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*) - GetProcAddress(win32vars.custom, "get_bindings"); + win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)GetProcAddress(win32vars.custom, "get_bindings"); } if (win32vars.custom_api.get_bindings == 0){ - MessageBox(0,"Error: The custom dll is missing.\n", "Error",0); + MessageBox_utf8(0, (u8*)"Error: The custom dll is missing.\n", (u8*)"Error", 0); exit(1); } @@ -2116,8 +2093,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS window_class.style = CS_HREDRAW|CS_VREDRAW; window_class.lpfnWndProc = (WNDPROC)(Win32Callback); window_class.hInstance = hInstance; - window_class.lpszClassName = "4coder-win32-wndclass"; - window_class.hIcon = LoadIcon(hInstance, "main"); + window_class.lpszClassName = L"4coder-win32-wndclass"; + window_class.hIcon = LoadIcon(hInstance, L"main"); if (!RegisterClass(&window_class)){ exit(1); @@ -2138,8 +2115,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // TODO(allen): non-fatal diagnostics } -#define WINDOW_NAME "4coder-window: " VERSION - i32 window_x = CW_USEDEFAULT; i32 window_y = CW_USEDEFAULT; @@ -2153,6 +2128,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS window_style |= WS_MAXIMIZE; } +#define WINDOW_NAME L"4coder-window: " L_VERSION + win32vars.window_handle = CreateWindow(window_class.lpszClassName, WINDOW_NAME, window_style, window_x, window_y, window_rect.right - window_rect.left, window_rect.bottom - window_rect.top, 0, 0, hInstance, 0); if (win32vars.window_handle == 0){ @@ -2227,7 +2204,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS win32vars.app.init(&win32vars.system, &win32vars.target, &memory_vars, win32vars.clipboard_contents, current_directory, win32vars.custom_api); - system_free_memory(current_directory.str); + system_memory_free(current_directory.str, 0); b32 keep_playing = 1; win32vars.first = 1; @@ -2468,6 +2445,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } #include "font/4coder_font_static_functions.cpp" +#include "win32_utf8.cpp" #if 0 // NOTE(allen): In case I want to switch back to a console diff --git a/win32_4ed_file_track.cpp b/win32_4ed_file_track.cpp index 683663ac..d48e9f8f 100644 --- a/win32_4ed_file_track.cpp +++ b/win32_4ed_file_track.cpp @@ -81,20 +81,19 @@ init_track_system(File_Track_System *system, Partition *scratch, void *table_mem return(result); } -internal umem -internal_utf8_file_to_utf16_parent(u16 *out, u32 max, u8 *name){ +internal i32 +internal_get_parent_name(u8 *out, i32 max, u8 *name){ u8 *ptr = name; for (; *ptr != 0; ++ptr); - umem len = (umem)(ptr - name); + i32 len = (i32)(ptr - name); // TODO(allen): make this system real Assert(len < max); - umem slash_i = len-1; + i32 slash_i = len-1; for (;slash_i > 0 && name[slash_i] != '\\' && name[slash_i] != '/';--slash_i); - b32 error = false; - slash_i = utf8_to_utf16_minimal_checking(out, max-1, name, len, &error); + for (i32 i = 0; i < slash_i; ++i) out[i] = name[i]; out[slash_i] = 0; return(slash_i); @@ -130,11 +129,10 @@ add_listener(File_Track_System *system, Partition *scratch, u8 *filename){ { File_Track_Tables *tables = to_tables(vars); - // TODO(allen): make this real! - u16 dir_name[1024]; - internal_utf8_file_to_utf16_parent(dir_name, ArrayCount(dir_name), filename); + u8 dir_name[1024]; + internal_get_parent_name(dir_name, ArrayCount(dir_name), filename); - HANDLE dir = CreateFile((LPCWSTR)dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + HANDLE dir = CreateFile_utf8(dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir != INVALID_HANDLE_VALUE){ BY_HANDLE_FILE_INFORMATION dir_info = {0}; @@ -213,10 +211,10 @@ remove_listener(File_Track_System *system, Partition *scratch, u8 *filename){ File_Track_Tables *tables = to_tables(vars); // TODO(allen): make this real! - u16 dir_name[1024]; - internal_utf8_file_to_utf16_parent(dir_name, ArrayCount(dir_name), filename); + u8 dir_name[1024]; + internal_get_parent_name(dir_name, ArrayCount(dir_name), filename); - HANDLE dir = CreateFile((LPCWSTR)dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); + HANDLE dir = CreateFile_utf8(dir_name, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir != INVALID_HANDLE_VALUE){ BY_HANDLE_FILE_INFORMATION dir_info = {0}; @@ -332,12 +330,14 @@ get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 FILE_NOTIFY_INFORMATION *info = (FILE_NOTIFY_INFORMATION*)(listener.result + offset); i32 len = info->FileNameLength / 2; - i32 dir_len = GetFinalPathNameByHandle(listener.dir, 0, 0, FILE_NAME_NORMALIZED); + i32 dir_len = GetFinalPathNameByHandle_utf8(listener.dir, 0, 0, FILE_NAME_NORMALIZED); i32 req_size = dir_len + 1 + len; *size = req_size; + + // TODO(allen): This check isn't really right, it should rely on the result from GetFinalPathNameByHandle_utf8. if (req_size < max){ - i32 pos = GetFinalPathNameByHandle(listener.dir, buffer, max, FILE_NAME_NORMALIZED); + i32 pos = GetFinalPathNameByHandle_utf8(listener.dir, buffer, max, FILE_NAME_NORMALIZED); buffer[pos++] = '\\'; for (i32 i = 0; i < len; ++i, ++pos){ diff --git a/win32_utf8.cpp b/win32_utf8.cpp new file mode 100644 index 00000000..a11d963f --- /dev/null +++ b/win32_utf8.cpp @@ -0,0 +1,258 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 23.03.2017 + * + * UTF8 versions of WIN32 calls. + * + */ + +// TOP + +#if !defined(FRED_WIN32_UTF8_CPP) +#define FRED_WIN32_UTF8_CPP + +internal HANDLE +CreateFile_utf8(u8 *name, DWORD access, DWORD share, LPSECURITY_ATTRIBUTES security, DWORD creation, DWORD flags, HANDLE template_file){ + HANDLE result = INVALID_HANDLE_VALUE; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 len = 0; + for (;name[len];++len); + u32 name_16_max = (len+1)*2; + u16 *name_16 = push_array(scratch, u16, name_16_max); + + b32 convert_error = false; + u32 name_16_len = (u32)utf8_to_utf16_minimal_checking(name_16, name_16_max-1, name, len, &convert_error); + + if (!convert_error){ + name_16[name_16_len] = 0; + result = CreateFileW((LPWSTR)name_16, access, share, security, creation, flags, template_file); + } + + end_temp_memory(temp); + + return(result); +} + +internal DWORD +GetFinalPathNameByHandle_utf8(HANDLE file, u8 *file_path_out, DWORD path_max, DWORD flags){ + DWORD result = 0; + + if (file_path_out == 0){ + result = GetFinalPathNameByHandleW(file, 0, 0, flags); + } + else{ + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 path_16_max = KB(32); + u16 *path_16 = push_array(scratch, u16, path_16_max); + + DWORD length_16 = GetFinalPathNameByHandleW(file, (LPWSTR)path_16, path_16_max, flags); + + if (length_16 != 0 && length_16 < path_16_max){ + b32 convert_error = false; + u32 path_8_len = (u32)utf16_to_utf8_minimal_checking(file_path_out, path_max-1, path_16, length_16, &convert_error); + if (path_8_len < path_max && !convert_error){ + file_path_out[path_8_len] = 0; + result = path_8_len; + } + } + + end_temp_memory(temp); + } + + return(result); +} + +internal HANDLE +FindFirstFile_utf8(u8 *name, LPWIN32_FIND_DATA find_data){ + HANDLE result = INVALID_HANDLE_VALUE; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 len = 0; + for (;name[len];++len); + u32 name_16_max = (len+1)*2; + u16 *name_16 = push_array(scratch, u16, name_16_max); + + b32 convert_error = false; + u32 name_16_len = (u32)utf8_to_utf16_minimal_checking(name_16, name_16_max-1, name, len, &convert_error); + + if (name_16_len < name_16_max && !convert_error){ + name_16[name_16_len] = 0; + result = FindFirstFileW((LPWSTR)name_16, find_data); + } + + end_temp_memory(temp); + + return(result); +} + +internal DWORD +GetFileAttributes_utf8(u8 *name){ + DWORD result = 0; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 len = 0; + for (;name[len];++len); + u32 name_16_max = (len+1)*2; + u16 *name_16 = push_array(scratch, u16, name_16_max); + + b32 convert_error = false; + u32 name_16_len = (u32)utf8_to_utf16_minimal_checking(name_16, name_16_max-1, name, len, &convert_error); + + if (name_16_len < name_16_max && !convert_error){ + name_16[name_16_len] = 0; + result = GetFileAttributesW((LPWSTR)name_16); + } + + end_temp_memory(temp); + + return(result); +} + +internal DWORD +GetModuleFileName_utf8(HMODULE module, u8 *file_out, DWORD max){ + DWORD result = 0; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 file_16_max = KB(40); + u16 *file_16 = push_array(scratch, u16, file_16_max); + + DWORD file_16_len = GetModuleFileNameW(module, (LPWSTR)file_16, file_16_max); + + if (max > 0){ + b32 convert_error = false; + u32 file_8_len = (u32)utf16_to_utf8_minimal_checking(file_out, max-1, file_16, file_16_len, &convert_error); + result = file_8_len; + if (convert_error || file_8_len >= max){ + result = 0; + } + } + + end_temp_memory(temp); + + return(result); +} + +internal BOOL +CreateProcess_utf8(u8 *app_name, u8 *command, LPSECURITY_ATTRIBUTES security, LPSECURITY_ATTRIBUTES thread, BOOL inherit_handles, DWORD creation, LPVOID environment, u8 *curdir, LPSTARTUPINFO startup, LPPROCESS_INFORMATION process){ + BOOL result = false; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 app_name_len = 0; + for (;app_name[app_name_len];++app_name_len); + + u32 command_len = 0; + for (;command[command_len];++command_len); + + u32 curdir_len = 0; + for (;curdir[curdir_len];++curdir_len); + + u32 app_name_16_max = (app_name_len+1)*2; + u32 command_16_max = (command_len+1)*2; + u32 curdir_16_max = (curdir_len+1)*2; + + u16 *app_name_16 = push_array(scratch, u16, app_name_16_max); + u16 *command_16 = push_array(scratch, u16, command_16_max); + u16 *curdir_16 = push_array(scratch, u16, curdir_16_max); + + b32 error = false; + u32 app_name_16_len = (u32)utf8_to_utf16_minimal_checking(app_name_16, app_name_16_max-1, app_name, app_name_len, &error); + + if (app_name_16_len < app_name_16_max && !error){ + u32 command_16_len = (u32)utf8_to_utf16_minimal_checking(command_16, command_16_max-1, command, command_len, &error); + + if (command_16_len < command_16_max && !error){ + u32 curdir_16_len = (u32)utf8_to_utf16_minimal_checking(curdir_16, curdir_16_max-1, curdir, curdir_len, &error); + + app_name_16[app_name_16_len] = 0; + command_16[command_16_len] = 0; + curdir_16[curdir_16_len] = 0; + + result = CreateProcessW((LPWSTR)app_name_16, (LPWSTR)command_16, security, thread, inherit_handles, creation, environment, (LPWSTR)curdir_16, startup, process); + } + } + + end_temp_memory(temp); + + return(result); +} + +internal DWORD +GetCurrentDirectory_utf8(DWORD max, u8 *buffer){ + DWORD result = 0; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 buffer_16_max = KB(40); + u16 *buffer_16 = push_array(scratch, u16, buffer_16_max); + + DWORD buffer_16_len = GetCurrentDirectoryW(buffer_16_max, (LPWSTR)buffer_16); + + b32 error = false; + u32 buffer_8_len = (u32)utf16_to_utf8_minimal_checking(buffer, max-1, buffer_16, buffer_16_len, &error); + + if (buffer_8_len < max && !error){ + buffer[buffer_8_len] = 0; + result = buffer_8_len; + } + + end_temp_memory(temp); + + return(result); +} + +internal int +MessageBox_utf8(HWND owner, u8 *text, u8 *caption, UINT type){ + int result = 0; + + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u32 text_len = 0; + for(;text[text_len];++text_len); + + u32 caption_len = 0; + for(;caption[caption_len];++caption_len); + + u32 text_16_max = (text_len+1)*2; + u32 caption_16_max = (caption_len+1)*2; + + u16 *text_16 = push_array(scratch, u16, text_16_max); + u16 *caption_16 = push_array(scratch, u16, caption_16_max); + + b32 error = false; + u32 text_16_len = (u32)utf8_to_utf16_minimal_checking(text_16, text_16_max-1, text, text_len, &error); + + if (text_16_len < text_16_max && !error){ + u32 caption_16_len = (u32)utf8_to_utf16_minimal_checking(caption_16, caption_16_max-1, caption, caption_len, &error); + + if (text_16_len < text_16_max && !error){ + text_16[text_16_len] = 0; + caption_16[caption_16_len] = 0; + MessageBoxW(owner, (LPWSTR)text_16, (LPWSTR)caption_16, type); + } + } + + end_temp_memory(temp); + + return(result); +} + +#endif + +// BOTTOM + diff --git a/win32_utf8.h b/win32_utf8.h new file mode 100644 index 00000000..b94d663e --- /dev/null +++ b/win32_utf8.h @@ -0,0 +1,42 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 23.03.2017 + * + * UTF8 versions of WIN32 calls. + * + */ + +// TOP + +#if !defined(FRED_WIN32_UTF8_H) +#define FRED_WIN32_UTF8_H + +internal HANDLE +CreateFile_utf8(u8 *name, DWORD access, DWORD share, LPSECURITY_ATTRIBUTES security, DWORD creation, DWORD flags, HANDLE template_file); + +internal DWORD +GetFinalPathNameByHandle_utf8(HANDLE file, u8 *file_path_out, DWORD path_max, DWORD flags); + +internal HANDLE +FindFirstFile_utf8(u8 *name, LPWIN32_FIND_DATA find_data); + +internal DWORD +GetFileAttributes_utf8(u8 *name); + +internal DWORD +GetModuleFileName_utf8(HMODULE module, u8 *file_out, DWORD max); + +internal BOOL +CreateProcess_utf8(u8 *app_name, u8 *command, LPSECURITY_ATTRIBUTES security, LPSECURITY_ATTRIBUTES thread, BOOL inherit_handles, DWORD creation, LPVOID environment, u8 *curdir, LPSTARTUPINFO startup, LPPROCESS_INFORMATION process); + +internal DWORD +GetCurrentDirectory_utf8(DWORD max, u8 *buffer); + +internal int +MessageBox_utf8(HWND owner, u8 *text, u8 *caption, UINT type); + +#endif + +// BOTTOM + From 4d46aa8e97ced5c5397576cbf75cf5405ac8f7e6 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 23 Mar 2017 19:40:16 -0400 Subject: [PATCH 10/17] got unicode working in the clipboard, reoganized some old stuff --- 4ed_app_target.cpp | 2 +- 4ed_buffer.cpp | 2 +- font/4coder_font_data.h => 4ed_font_data.h | 0 ...r_font_interface.h => 4ed_font_interface.h | 0 ...face_to_os.h => 4ed_font_interface_to_os.h | 0 ...tions.cpp => 4ed_font_static_functions.cpp | 2 +- 4ed_system.h | 2 +- 4ed_system_shared.cpp | 13 - 4ed_system_shared.h | 11 + font/4coder_font_internal.cpp | 493 ------------------ internal_4coder_tests.cpp | 241 --------- meta/build.cpp | 4 - win32_4ed.cpp | 79 ++- win32_4ed_fonts.cpp | 6 +- 14 files changed, 71 insertions(+), 784 deletions(-) rename font/4coder_font_data.h => 4ed_font_data.h (100%) rename font/4coder_font_interface.h => 4ed_font_interface.h (100%) rename font/4coder_font_interface_to_os.h => 4ed_font_interface_to_os.h (100%) rename font/4coder_font_static_functions.cpp => 4ed_font_static_functions.cpp (99%) delete mode 100644 font/4coder_font_internal.cpp delete mode 100644 internal_4coder_tests.cpp diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index 1743cdda..88b699cc 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -62,7 +62,7 @@ #include "4ed_file_view.cpp" #include "4ed.cpp" -#include "font/4coder_font_static_functions.cpp" +#include "4ed_font_static_functions.cpp" // BOTTOM diff --git a/4ed_buffer.cpp b/4ed_buffer.cpp index ba098998..87e228f2 100644 --- a/4ed_buffer.cpp +++ b/4ed_buffer.cpp @@ -13,7 +13,7 @@ // Buffer low level operations // -#include "font/4coder_font_data.h" +#include "4ed_font_data.h" #include "4coder_helper/4coder_seek_types.h" typedef struct Cursor_With_Index{ diff --git a/font/4coder_font_data.h b/4ed_font_data.h similarity index 100% rename from font/4coder_font_data.h rename to 4ed_font_data.h diff --git a/font/4coder_font_interface.h b/4ed_font_interface.h similarity index 100% rename from font/4coder_font_interface.h rename to 4ed_font_interface.h diff --git a/font/4coder_font_interface_to_os.h b/4ed_font_interface_to_os.h similarity index 100% rename from font/4coder_font_interface_to_os.h rename to 4ed_font_interface_to_os.h diff --git a/font/4coder_font_static_functions.cpp b/4ed_font_static_functions.cpp similarity index 99% rename from font/4coder_font_static_functions.cpp rename to 4ed_font_static_functions.cpp index 32dfdc3a..c65cd2f4 100644 --- a/font/4coder_font_static_functions.cpp +++ b/4ed_font_static_functions.cpp @@ -9,7 +9,7 @@ // TOP -#include "4coder_font_data.h" +#include "4ed_font_data.h" internal f32 font_get_byte_advance(Render_Font *font){ diff --git a/4ed_system.h b/4ed_system.h index 70b92b6e..6481c9b6 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -12,7 +12,7 @@ #if !defined(FCODER_SYSTEM_INTERFACE_H) #define FCODER_SYSTEM_INTERFACE_H -#include "font/4coder_font_interface.h" +#include "4ed_font_interface.h" // types struct Plat_Handle{ diff --git a/4ed_system_shared.cpp b/4ed_system_shared.cpp index b9128811..badb9ba4 100644 --- a/4ed_system_shared.cpp +++ b/4ed_system_shared.cpp @@ -12,23 +12,10 @@ #if !defined(FCODER_SYSTEM_SHARED_CPP) #define FCODER_SYSTEM_SHARED_CPP -#include "font/4coder_font_data.h" - // // Standard implementation of file system stuff based on the file track layer. // -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 init_shared_vars(){ umem scratch_size = KB(128); diff --git a/4ed_system_shared.h b/4ed_system_shared.h index 0347f017..cb7edab5 100644 --- a/4ed_system_shared.h +++ b/4ed_system_shared.h @@ -30,6 +30,17 @@ global File_Data null_file_data = {0}; internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made); internal Sys_Get_Binary_Path_Sig(system_get_binary_path); +struct Shared_Vars{ + File_Track_System track; + void *track_table; + u32 track_table_size; + u32 track_node_size; + + Partition scratch; +}; + +global Shared_Vars shared_vars; + #endif // BOTTOM diff --git a/font/4coder_font_internal.cpp b/font/4coder_font_internal.cpp deleted file mode 100644 index a8e66e65..00000000 --- a/font/4coder_font_internal.cpp +++ /dev/null @@ -1,493 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 10.03.2017 - * - * Where I save crappy old font stuff. - * - */ - -// TOP - -#include "font/4coder_font_data.h" - -struct Font_Table_Entry{ - u32 hash; - String name; - Font_ID font_id; -}; - -struct Font_Info{ - Render_Font *font; - String filename; - String name; - i32 pt_size; -}; - -struct Font_Slot{ - Font_Slot *next, *prev; - Font_ID font_id; - u8 padding[6]; -}; -global_const Font_Slot null_font_slot = {0}; - -#define Font_Load_Sig(name)\ -i32 name(Render_Font *font_out, char *filename, char *fontname, i32 pt_size, i32 tab_width, b32 store_texture) -typedef Font_Load_Sig(Font_Load); - -#define Font_Load_Page_Sig(name)\ -i32 name(Render_Font *font, Glyph_Page *page, char *filename, i32 pt_size, i32 tab_width) -typedef Font_Load_Page_Sig(Font_Load_Page); - -#define Release_Font_Sig(name) void name(Render_Font *font) -typedef Release_Font_Sig(Release_Font); - -struct Font_Set{ - Font_Info *info; - Font_Table_Entry *entries; - u32 count, max; - - void *font_block; - Font_Slot free_slots; - Font_Slot used_slots; - - Font_Load *font_load; - Font_Load_Page *font_load_page; - Release_Font *release_font; - - b8 *font_used_flags; - Font_ID used_this_frame; - Font_ID live_max; -}; - -inline Font_Info* -get_font_info(Font_Set *set, Font_ID font_id){ - Font_Info *result = set->info + font_id - 1; - return(result); -} - -internal void -font_set_begin_render(Font_Set *font_set){ - font_set->used_this_frame = 0; - memset(font_set->font_used_flags, 0, font_set->max); -} - -inline u32 -font_hash(String name){ - u32 x = 5381; - char *p = name.str; - for (i32 i = 0; i < name.size; ++i, ++p){ - x = ((x << 5) + x) ^ (*p); - } - return(x); -} - -inline void -font__insert(Font_Slot *pos, Font_Slot *slot){ - Font_Slot *nex; - nex = pos->next; - - slot->next = nex; - slot->prev = pos; - nex->prev = slot; - pos->next = slot; -} - -inline void -font__remove(Font_Slot *slot){ - Font_Slot *n, *p; - n = slot->next; - p = slot->prev; - - p->next = n; - n->prev = p; -} - -internal void -font_set_init(Font_Set *set, Partition *partition, i32 max, Font_ID live_max){ - partition_align(partition, 8); - set->info = push_array(partition, Font_Info, max); - partition_align(partition, 8); - set->entries = push_array(partition, Font_Table_Entry, max); - set->count = 0; - set->max = max; - - partition_align(partition, 8); - set->font_block = push_block(partition, live_max*(sizeof(Render_Font) + sizeof(Font_Slot))); - - set->free_slots = null_font_slot; - set->used_slots = null_font_slot; - - dll_init_sentinel(&set->free_slots); - dll_init_sentinel(&set->used_slots); - - char *ptr = (char*)set->font_block; - for (i32 i = 0; i < live_max; ++i){ - dll_insert(&set->free_slots, (Font_Slot*)ptr); - ptr += sizeof(Font_Slot) + sizeof(Render_Font); - } - - set->font_used_flags = push_array(partition, b8, max); - set->live_max = live_max; -} - -internal b32 -font_set_can_add(Font_Set *set){ - b32 result = 0; - if (set->count*8 < set->max*7) result = 1; - return(result); -} - -internal void -font_set_add_hash(Font_Set *set, String name, Font_ID font_id){ - Font_Table_Entry entry; - entry.hash = font_hash(name); - entry.name = name; - entry.font_id = font_id; - - u32 i = entry.hash % set->max; - u32 j = i - 1; - if (i <= 1) j += set->max; - - for (; i != j; ++i){ - if (i == set->max) i = 0; - if (set->entries[i].font_id == 0){ - set->entries[i] = entry; - break; - } - } - - Assert(i != j); -} - -inline b32 -font_set_can_load(Font_Set *set){ - b32 result = (set->free_slots.next != &set->free_slots); - return(result); -} - -internal void -font_set_load(Font_Set *set, Font_ID font_id){ - Font_Info *info = get_font_info(set, font_id); - Font_Slot *slot = set->free_slots.next; - Assert(slot != &set->free_slots); - font__remove(slot); - font__insert(&set->used_slots, slot); - - Render_Font *font = (Render_Font*)(slot + 1); - set->font_load(font, info->filename.str, info->name.str, info->pt_size, 4, true); - info->font = font; - slot->font_id = font_id; -} - -internal void -font_set_evict_lru(Font_Set *set){ - Font_Slot *slot = set->used_slots.prev; - Assert(slot != &set->used_slots); - - Font_ID font_id = slot->font_id; - Font_Info *info = get_font_info(set, font_id); - Assert(((Font_Slot*)info->font) - 1 == slot); - - set->release_font(info->font); - - info->font = 0; - slot->font_id = 0; - font__remove(slot); - font__insert(&set->free_slots, slot); -} - -internal void -font_set_use(Font_Set *set, Font_ID font_id){ - b8 already_used = set->font_used_flags[font_id-1]; - - if (!already_used){ - if (set->used_this_frame < set->live_max){ - ++set->used_this_frame; - set->font_used_flags[font_id-1] = 1; - already_used = 1; - } - } - - if (already_used){ - // TODO(allen): optimize if you don't mind!!!! - Font_Info *info = get_font_info(set, font_id); - Font_Slot *slot; - if (info->font == 0){ - if (!font_set_can_load(set)){ - font_set_evict_lru(set); - } - font_set_load(set, font_id); - } - slot = ((Font_Slot*)info->font) - 1; - - font__remove(slot); - font__insert(&set->used_slots, slot); - } -} - -internal b32 -font_set_add(Font_Set *set, String filename, String name, i32 pt_size){ - b32 result = false; - if (font_set_can_add(set)){ - Render_Font dummy_font = {0}; - Font_ID font_id = (i16)(++set->count); - Font_Info *info = get_font_info(set, font_id); - info->filename = filename; - info->name = name; - info->pt_size = pt_size; - set->font_load(&dummy_font, info->filename.str, info->name.str, info->pt_size, 4, false); - - font_set_add_hash(set, name, font_id); - - if (font_set_can_load(set)){ - font_set_load(set, font_id); - } - - result = true; - } - return(result); -} - -internal b32 -font_set_find_pos(Font_Set *set, String name, u32 *position){ - u32 hash = font_hash(name); - u32 i = hash % set->max; - u32 j = i - 1; - if (j <= 1){ - j += set->max; - } - - b32 result = 0; - for (; i != j; ++i){ - if (i == set->max){ - i = 0; - } - - Font_Table_Entry *entry = set->entries + i; - if (entry->hash == hash){ - if (match_ss(name, entry->name)){ - result = 1; - *position = i; - break; - } - } - } - - return(result); -} - -internal b32 -font_set_get_name(Font_Set *set, Font_ID font_id, String *name){ - Font_Info *info = get_font_info(set, font_id); - b32 result = copy_checked_ss(name, info->name); - return(result); -} - -internal b32 -font_set_extract(Font_Set *set, String name, Font_ID *font_id){ - u32 position; - b32 result = font_set_find_pos(set, name, &position); - if (result){ - *font_id = set->entries[position].font_id; - } - return(result); -} - -////////////////////////////////// - -internal b32 -get_codepoint_can_render(Render_Font *font, u32 codepoint){ - b32 exists = false; - if (codepoint < 0x10FFFF){ - exists = true; - } - return(exists); -} - -struct Codepoint_Indexes{ - b32 exists; - u32 page_number; - u32 glyph_index; -}; - -internal Codepoint_Indexes -get_codepoint_page_number(Render_Font *font, u32 codepoint){ - Codepoint_Indexes result = {0}; - u32 page_number = (codepoint >> 8); - if (page_number <= 0x10FF){ - result.exists = true; - result.page_number = page_number; - result.glyph_index = (codepoint & 0x000000FF); - } - return(result); -} - -#define MAX_PAGE_COUNT (u32)(0x1100) -#define GLYPH_PAGE_EMPTY ((Glyph_Page*)(0)) -#define GLYPH_PAGE_DELETED ((Glyph_Page*)(max_u64)) -#define IS_REAL_FONT_PAGE(p) (((p) != GLYPH_PAGE_EMPTY) && ((p) != GLYPH_PAGE_DELETED)) - -internal Glyph_Page** -font_lookup_page(Render_Font *font, u32 page_number, b32 find_empty_slot){ - Glyph_Page **result = 0; - if (font->page_max > 0){ - u32 first_index = page_number % font->page_max; - - u32 range_count = 0; - u32 ranges[4]; - if (first_index == 0){ - ranges[0] = 0; - ranges[1] = font->page_max; - range_count = 2; - } - else{ - ranges[0] = first_index; - ranges[1] = font->page_max; - ranges[2] = 0; - ranges[3] = first_index; - range_count = 4; - } - - if (find_empty_slot){ - for(u32 j = 0; j < range_count; j += 2){ - u32 start = ranges[j]; - u32 stop = ranges[j+1]; - for (u32 i = start; i < stop; ++i){ - Glyph_Page *ptr = font->pages[i]; - if (ptr == GLYPH_PAGE_EMPTY || ptr == GLYPH_PAGE_DELETED){ - result = &font->pages[i]; - goto break2; - } - if (ptr->page_number == page_number){ - goto break2; - } - } - } - } - else{ - for(u32 j = 0; j < range_count; j += 2){ - u32 start = ranges[j]; - u32 stop = ranges[j+1]; - for (u32 i = start; i < stop; ++i){ - Glyph_Page *ptr = font->pages[i]; - if (ptr == GLYPH_PAGE_EMPTY){ - goto break2; - } - if (ptr != GLYPH_PAGE_DELETED){ - if (ptr->page_number == page_number){ - result = &font->pages[i]; - goto break2; - } - } - } - } - } - break2:; - } - return(result); -} - -internal Glyph_Page* -font_get_or_make_page(Render_Font *font, u32 page_number){ - Glyph_Page *page = 0; - if (page_number <= 0x10FF){ - Glyph_Page **page_ptr = font_lookup_page(font, page_number, false); - page = 0; - if (page_ptr != 0){ - page = *page_ptr; - } - - if (page == 0){ - u32 new_count = 1; - if (font->page_max < MAX_PAGE_COUNT && (font->page_count+new_count)*3 < font->page_max*2){ - u32 new_page_max = (font->page_count+new_count)*3; - new_page_max = clamp_top(new_page_max, MAX_PAGE_COUNT); - Glyph_Page **new_pages = (Glyph_Page**)ALLOCATE(new_page_max * sizeof(Glyph_Page*)); - - u32 old_page_max = font->page_max; - Glyph_Page **pages = font->pages; - for (u32 i = 0; i < old_page_max; ++i){ - Glyph_Page *current_page = pages[i]; - if (current_page != GLYPH_PAGE_EMPTY && current_page != GLYPH_PAGE_DELETED){ - Glyph_Page **dest = font_lookup_page(font, current_page->page_number, true); - Assert(dest != 0); - *dest = current_page; - } - } - - FREE(font->pages); - font->pages = new_pages; - font->page_max = new_page_max; - } - - Glyph_Page *new_page = (Glyph_Page*)ALLOCATE(sizeof(Glyph_Page)); - Glyph_Page **dest = font_lookup_page(font, page_number, true); - *dest = new_page; - ++font->page_count; - - //set->font_load_page(font, new_page, ); - } - } - return(page); -} - -internal void -get_codepoint_memory(Render_Font *font, u32 codepoint, Glyph_Bounds **bounds_mem_out, f32 **advance_mem_out){ - Glyph_Bounds *bounds = 0; - f32 *advance = 0; - - if (get_codepoint_can_render(font, codepoint)){ - Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); - Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); - bounds = &page->glyphs[indexes.glyph_index]; - advance = &page->advance[indexes.glyph_index]; - } - - *bounds_mem_out = bounds; - *advance_mem_out = advance; -} - -internal b32 -get_codepoint_glyph_data(Render_Font *font, u32 codepoint, Glyph_Data *data_out){ - b32 success = false; - if (get_codepoint_can_render(font, codepoint)){ - Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); - Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); - data_out->bounds = page->glyphs[indexes.glyph_index]; - data_out->tex = page->tex; - data_out->tex_width = page->tex_width; - data_out->tex_height = page->tex_height; - success = true; - } - return(success); -} - -internal f32 -get_codepoint_advance(Render_Font *font, u32 codepoint){ - f32 advance = (f32)font->advance; - if (get_codepoint_can_render(font, codepoint)){ - Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); - Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); - advance = page->advance[indexes.glyph_index]; - } - return(advance); -} - -internal b32 -set_codepoint_advance(Render_Font *font, u32 codepoint, f32 value){ - b32 success = false; - if (get_codepoint_can_render(font, codepoint)){ - Codepoint_Indexes indexes = get_codepoint_page_number(font, codepoint); - Glyph_Page *page = font_get_or_make_page(font, indexes.page_number); - page->advance[indexes.glyph_index] = value; - success = true; - } - return(success); -} - -// BOTTOM - - - - diff --git a/internal_4coder_tests.cpp b/internal_4coder_tests.cpp deleted file mode 100644 index 9e1935a9..00000000 --- a/internal_4coder_tests.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/* - -A series of stress tests to more quickly verify that 4coder isn't totally -broken before I release in the future... "unit tests" perhaps, although -I guess I don't know what the "units" are... probably just "tests". - -Allen Webster -18.07.2016 - -*/ - -// TOP - -#define LOTS_OF_FILES "w:/4ed/data/lots_of_files" -#define TEST_FILES "w:/4ed/data/test" - -#include "4coder_default_include.cpp" - -#include -#include - -#include -#pragma intrinsic(__rdtsc) - -typedef uint64_t DWORD64; - -#define TEST_TIME_B(m) DWORD64 time_start = __rdtsc(), time_max = m; (void)(time_start), (void)(time_max) -#define TEST_TIME_E() DWORD64 time_total = __rdtsc() - time_start; if (time_total > time_max) {assert(!"failed timing");} -#define TEST_TIME_M(m) m = (float)(__rdtsc() - time_start) / time_max - -// NOTE(allen): This testing system only verifies that everything works -// without crashing and without blowing through a fair time budget. -// These tests do not verify the correctness of the output. - -CUSTOM_COMMAND_SIG(load_lots_of_files){ - // NOTE(allen): This timing restriction is based on 4GHz and 60fps - // 4G / 60 ~= 70M Reserving most of that time for rendering and hopefully idling - // I set the goal of 10M for all tests. - TEST_TIME_B(10000000); - - File_List list = get_file_list(app, literal(LOTS_OF_FILES)); - File_Info *info = list.infos; - - char space[1024]; - String str = make_fixed_width_string(space); - append_ss(&str, make_lit_string(LOTS_OF_FILES)); - append_s_char(&str, '/'); - int32_t size = str.size; - - for (uint32_t i = 0; i < list.count; ++i, ++info){ - if (!info->folder){ - append_ss(&str, make_string(info->filename, info->filename_len)); - Buffer_Summary buffer = create_buffer(app, str.str, str.size, - BufferCreate_Background); - assert(buffer.size != 0); - str.size = size; - } - } - - free_file_list(app, list); - - // TODO(allen): Pass this time test! - //TEST_TIME_E(); -} - -CUSTOM_COMMAND_SIG(reopen_test){ - // NOTE(allen): This is set to roughly one percent of the frame budget - // based on 4GHz and 60fps - TEST_TIME_B(700000); - - Buffer_Summary buffer = create_buffer(app, literal(TEST_FILES "/basic.cpp"), 0); - View_Summary view = get_active_view(app, AccessAll); - view_set_buffer(app, &view, buffer.buffer_id, 0); - - exec_command(app, cmdid_reopen); - - // TODO(allen): Pass this time test! - //TEST_TIME_E(); -} - -CUSTOM_COMMAND_SIG(generate_stop_spots_test_data){ - Buffer_Summary buffer = create_buffer(app, literal(LOTS_OF_FILES "/4ed.cpp"), 0); - View_Summary view = get_active_view(app, AccessAll); - view_set_buffer(app, &view, buffer.buffer_id, 0); - - FILE *file = fopen(TEST_FILES "/stop_spots_data", "wb"); - - if (file){ - Partial_Cursor curs; - int32_t pos; - - buffer_compute_cursor(app, &buffer, seek_line_char(316, 29), &curs); - fwrite(&curs.pos, 4, 1, file); - - for (int32_t i = 0; i < 10; ++i){ - Query_Bar bar = {0}; - bar.prompt = make_lit_string("Do something to continue the test"); - if (start_query_bar(app, &bar, 0)){ - get_user_input(app, EventAll, EventAll); - } - refresh_buffer(app, &buffer); - if (buffer.tokens_are_ready){ - break; - } - } - - static Seek_Boundary_Flag flag_set[] = { - BoundaryWhitespace, - BoundaryToken, - BoundaryAlphanumeric, - BoundaryCamelCase, - BoundaryWhitespace | BoundaryToken, - BoundaryWhitespace | BoundaryAlphanumeric, - BoundaryToken | BoundaryCamelCase, - }; - - for (int32_t flag_i = 0; flag_i < ArrayCount(flag_set); ++flag_i){ - for (int32_t seek_forward = 0; seek_forward <= 1; ++seek_forward){ - pos = curs.pos; - for (int32_t i = 0; i < 100; ++i){ - pos = buffer_boundary_seek(app, &buffer, pos, seek_forward, flag_set[flag_i]); - fwrite(&pos, 4, 1, file); - } - } - } - - fclose(file); - } -} - -static void -fcheck(int32_t x, FILE *file){ - int32_t x0 = 0; - fread(&x0, 4, 1, file); - Assert(x == x0); -} - -CUSTOM_COMMAND_SIG(stop_spots_test){ - Buffer_Summary buffer = create_buffer(app, literal(LOTS_OF_FILES "/4ed.cpp"), 0); - View_Summary view = get_active_view(app, AccessAll); - view_set_buffer(app, &view, buffer.buffer_id, 0); - - FILE *file = fopen(TEST_FILES "/stop_spots_data", "rb"); - - if (file){ - Partial_Cursor curs; - int32_t pos; - - buffer_compute_cursor(app, &buffer, seek_line_char(316, 29), &curs); - fcheck(curs.pos, file); - - for (int32_t i = 0; i < 10; ++i){ - Query_Bar bar = {0}; - bar.prompt = make_lit_string("Do something to continue the test"); - if (start_query_bar(app, &bar, 0)){ - get_user_input(app, EventAll, EventAll); - } - refresh_buffer(app, &buffer); - if (buffer.tokens_are_ready){ - break; - } - } - - static Seek_Boundary_Flag flag_set[] = { - BoundaryWhitespace, - BoundaryToken, - BoundaryAlphanumeric, - BoundaryCamelCase, - BoundaryWhitespace | BoundaryToken, - BoundaryWhitespace | BoundaryAlphanumeric, - BoundaryToken | BoundaryCamelCase, - }; - - for (int32_t flag_i = 0; flag_i < ArrayCount(flag_set); ++flag_i){ - for (int32_t seek_forward = 0; seek_forward <= 1; ++seek_forward){ - pos = curs.pos; - for (int32_t i = 0; i < 100; ++i){ - pos = buffer_boundary_seek(app, &buffer, pos, seek_forward, flag_set[flag_i]); - fcheck(pos, file); - } - } - } - - fclose(file); - } -} - -CUSTOM_COMMAND_SIG(load_unicode_file){ - Buffer_Summary buffer = create_buffer(app, literal(TEST_FILES "/mod_markov.c"), 0); - View_Summary view = get_active_view(app, AccessAll); - view_set_buffer(app, &view, buffer.buffer_id, 0); - - view_set_cursor(app, &view, seek_line_char(230, 25), 1); -} - -CUSTOM_COMMAND_SIG(edit_giant_file){ - Buffer_Summary buffer = create_buffer(app, literal(TEST_FILES "/test_large.cpp"), 0); - View_Summary view = get_active_view(app, AccessAll); - view_set_buffer(app, &view, buffer.buffer_id, 0); - view_set_cursor(app, &view, seek_line_char(230, 25), 1); - - for (int32_t i = 0; i < 600; ++i){ - Query_Bar bar = {0}; - bar.prompt = make_lit_string("Do something to continue the test"); - if (start_query_bar(app, &bar, 0)){ - get_user_input(app, EventAll, EventAll); - } - end_query_bar(app, &bar, 0); - refresh_buffer(app, &buffer); - if (buffer.tokens_are_ready){ - break; - } - } - - buffer_replace_range(app, &buffer, 2000, 2000, - literal("{\n//Not important at all\n}\n")); - buffer_auto_indent(app, &buffer, 2000, 2100, 4, 0); -} - -CUSTOM_COMMAND_SIG(run_all_tests){ - exec_command(app, load_lots_of_files); - exec_command(app, reopen_test); - exec_command(app, stop_spots_test); - exec_command(app, load_unicode_file); - exec_command(app, edit_giant_file); -} - -static void -test_get_bindings(Bind_Helper *context){ - begin_map(context, mapid_global); - bind(context, key_f3, MDFR_NONE, run_all_tests); - end_map(context); -} - -#define BIND_4CODER_TESTS(context) test_get_bindings(context) - -#include "power/4coder_experiments.cpp" - - -// BOTTOM - diff --git a/meta/build.cpp b/meta/build.cpp index 5e49fb7a..9da7a61c 100644 --- a/meta/build.cpp +++ b/meta/build.cpp @@ -433,11 +433,7 @@ do_buildsuper(char *cdir, i32 custom_option, u32 flags){ case Custom_Experiments: { -#if defined(IS_WINDOWS) - copy_sc(&str, "../code/internal_4coder_tests.cpp"); -#else copy_sc(&str, "../code/power/4coder_experiments.cpp"); -#endif }break; case Custom_Casey: diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 311f1f2b..d1191746 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -74,11 +74,9 @@ #include "win32_utf8.h" #include "4ed_file_track.h" -#include "font/4coder_font_interface_to_os.h" +#include "4ed_font_interface_to_os.h" #include "4ed_system_shared.h" -#include "win32_4ed_file_track.cpp" - // // Win32_Vars structs // @@ -187,6 +185,9 @@ typedef struct Win32_Vars{ HCURSOR cursor_arrow; HCURSOR cursor_leftright; HCURSOR cursor_updown; + + u8 *clip_buffer; + u32 clip_max; String clipboard_contents; b32 next_clipboard_is_self; DWORD clipboard_sequence; @@ -1122,6 +1123,7 @@ Win32ToggleFullscreen(void){ } } + // // Clipboard // @@ -1144,20 +1146,41 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){ } internal b32 -Win32ReadClipboardContents(){ - b32 result = 0; +win32_read_clipboard_contents(){ + b32 result = false; - if (IsClipboardFormatAvailable(CF_TEXT)){ - result = 1; + if (IsClipboardFormatAvailable(CF_UNICODETEXT)){ + result = true; if (OpenClipboard(win32vars.window_handle)){ - HANDLE clip_data; - clip_data = GetClipboardData(CF_TEXT); - if (clip_data){ - win32vars.clipboard_contents.str = (char*)GlobalLock(clip_data); - if (win32vars.clipboard_contents.str){ - win32vars.clipboard_contents.size = str_size((char*)win32vars.clipboard_contents.str); + HANDLE clip_data = GetClipboardData(CF_UNICODETEXT); + if (clip_data != 0){ + Partition *scratch = &shared_vars.scratch; + Temp_Memory temp = begin_temp_memory(scratch); + + u16 *clip_16 = (u16*)GlobalLock(clip_data); + + if (clip_16 != 0){ + u32 clip_16_len = 0; + for(;clip_16[clip_16_len];++clip_16_len); + + // TODO(allen): Extend the buffer if it is too small. + b32 error = false; + u32 clip_8_len = (u32)utf16_to_utf8_minimal_checking(win32vars.clip_buffer, win32vars.clip_max-1, clip_16, clip_16_len, &error); + + if (clip_8_len < win32vars.clip_max && !error){ + win32vars.clip_buffer[clip_8_len] = 0; + + win32vars.clipboard_contents = make_string_cap(win32vars.clip_buffer, clip_8_len, win32vars.clip_max); + } + GlobalUnlock(clip_data); } + + if (win32vars.clipboard_contents.str){ + win32vars.clipboard_contents.size = str_size((char*)win32vars.clipboard_contents.str); + } + + end_temp_memory(temp); } CloseClipboard(); } @@ -1362,33 +1385,31 @@ Sys_Send_Exit_Signal_Sig(system_send_exit_signal){ win32vars.send_exit_signal = 1; } -#include "4ed_system_shared.cpp" - -#include "win32_4ed_fonts.cpp" - // // Linkage to Custom and Application // internal b32 Win32LoadAppCode(){ - b32 result = 0; + b32 result = false; App_Get_Functions *get_funcs = 0; win32vars.app_code = LoadLibraryA("4ed_app.dll"); if (win32vars.app_code){ - get_funcs = (App_Get_Functions*) - GetProcAddress(win32vars.app_code, "app_get_functions"); + get_funcs = (App_Get_Functions*)GetProcAddress(win32vars.app_code, "app_get_functions"); } if (get_funcs){ - result = 1; - win32vars.app = get_funcs(); + result = true; + win32vars.app = get_funcs(); } - return result; + return(result); } +#include "4ed_font_data.h" +#include "4ed_system_shared.cpp" + internal void Win32LoadSystemCode(){ win32vars.system.set_file_list = system_set_file_list; @@ -2167,6 +2188,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS // Misc System Initializations // + win32vars.clip_max = KB(16); + win32vars.clip_buffer = (u8*)system_memory_allocate(win32vars.clip_max); + win32vars.clipboard_sequence = GetClipboardSequenceNumber(); if (win32vars.clipboard_sequence == 0){ system_post_clipboard(make_lit_string("")); @@ -2179,7 +2203,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } } else{ - Win32ReadClipboardContents(); + win32_read_clipboard_contents(); } Win32KeycodeInit(); @@ -2360,7 +2384,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS win32vars.next_clipboard_is_self = 0; } else{ - Win32ReadClipboardContents(); + win32_read_clipboard_contents(); } } } @@ -2444,7 +2468,10 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS return(0); } -#include "font/4coder_font_static_functions.cpp" +#include "win32_4ed_fonts.cpp" + +#include "win32_4ed_file_track.cpp" +#include "4ed_font_static_functions.cpp" #include "win32_utf8.cpp" #if 0 diff --git a/win32_4ed_fonts.cpp b/win32_4ed_fonts.cpp index 3b50b8f3..2bc907cf 100644 --- a/win32_4ed_fonts.cpp +++ b/win32_4ed_fonts.cpp @@ -10,9 +10,9 @@ // TOP #include "4ed_system_shared.h" -#include "font/4coder_font_interface.h" -#include "font/4coder_font_interface_to_os.h" -#include "font/4coder_font_data.h" +#include "4ed_font_interface.h" +#include "4ed_font_interface_to_os.h" +#include "4ed_font_data.h" struct Win32_Fonts{ Partition part; From fbe5c3ff4fccf8c8d255f5e825a51eaaf489e846 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 24 Mar 2017 19:41:10 -0400 Subject: [PATCH 11/17] Got unicode text files working, need to revist code wrapping --- 4coder_lib/4coder_utf8.h | 12 ++--- 4ed_buffer.cpp | 8 +-- 4ed_file_view.cpp | 66 +++++++++++++---------- 4tech_defines.h | 2 +- meta/build.cpp | 4 ++ string/4coder_string_build_num.txt | 2 +- string/_4coder_string.ctm | Bin 2724 -> 2740 bytes win32_4ed_fonts.cpp | 84 ++++++++++++++++++++++------- 8 files changed, 118 insertions(+), 60 deletions(-) diff --git a/4coder_lib/4coder_utf8.h b/4coder_lib/4coder_utf8.h index 7d20a7e6..22454d63 100644 --- a/4coder_lib/4coder_utf8.h +++ b/4coder_lib/4coder_utf8.h @@ -53,16 +53,16 @@ static u32_4tech utf8_to_u32_length_unchecked(u8_4tech *buffer, u32_4tech *length_out){ u32_4tech result = 0; - if (buffer[0] <= 0x7F){ + if (buffer[0] < 0x80){ result = (u32_4tech)buffer[0]; *length_out = 1; } - else if (buffer[0] <= 0xE0){ + else if (buffer[0] < 0xE0){ result = ((u32_4tech)((buffer[0])&0x1F)) << 6; result |= ((u32_4tech)((buffer[1])&0x3F)); *length_out = 2; } - else if (buffer[0] <= 0xF0){ + else if (buffer[0] < 0xF0){ result = ((u32_4tech)((buffer[0])&0x0F)) << 12; result |= ((u32_4tech)((buffer[1])&0x3F)) << 6; result |= ((u32_4tech)((buffer[2])&0x3F)); @@ -198,11 +198,11 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * u32_4tech codepoint = 0; u32_4tech utf8_size = 0; - if (s[0] <= 0x7F){ + if (s[0] < 0x80){ codepoint = (u32_4tech)s[0]; utf8_size = 1; } - else if (s[0] <= 0xE0){ + else if (s[0] < 0xE0){ if (limit <= 1){ *error = true; break; @@ -212,7 +212,7 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * codepoint |= ((u32_4tech)((s[1])&0x3F)); utf8_size = 2; } - else if (s[0] <= 0xF0){ + else if (s[0] < 0xF0){ if (limit <= 2){ *error = true; break; diff --git a/4ed_buffer.cpp b/4ed_buffer.cpp index 87e228f2..75163296 100644 --- a/4ed_buffer.cpp +++ b/4ed_buffer.cpp @@ -858,11 +858,11 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para } S.did_wrap = false; - if (S.i >= S.wrap_unit_end){ + if (S.step.i >= S.wrap_unit_end){ S_stop.status = BLStatus_NeedWrapDetermination; S_stop.line_index = S.line_index - 1; S_stop.wrap_line_index = S.current_wrap_index; - S_stop.pos = S.i; + S_stop.pos = S.step.i; S_stop.x = S.x; DrYield(4, S_stop); @@ -876,7 +876,7 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para S_stop.status = BLStatus_NeedWrapLineShift; S_stop.line_index = S.line_index - 1; S_stop.wrap_line_index = S.current_wrap_index; - S_stop.pos = S.i; + S_stop.pos = S.step.i; DrYield(3, S_stop); } @@ -1403,7 +1403,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa // Build the cursor hint S.next_cursor.pos = params.buffer->line_starts[safe_line_index]; S.next_cursor.character_pos = params.character_starts[safe_line_index]; - S.next_cursor.line = line_index + 1; + S.next_cursor.line = safe_line_index + 1; S.next_cursor.character = 1; S.next_cursor.wrap_line = params.wrap_line_index[safe_line_index] + 1; S.next_cursor.unwrapped_y = (f32)(safe_line_index * S.font_height); diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 0ab0ab0c..b0943d97 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -1476,9 +1476,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, Buffer_Layout_Stop stop = {0}; f32 edge_tolerance = 50.f; - if (edge_tolerance > width){ - edge_tolerance = width; - } + edge_tolerance = clamp_top(edge_tolerance, 50.f); f32 current_line_shift = 0.f; b32 do_wrap = 0; @@ -1509,6 +1507,9 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, i32 potential_count = 0; i32 stage = 0; + Translation_State tran = {0}; + Translation_Emits emits = {0}; + do{ stop = buffer_measure_wrap_y(&state, params, current_line_shift, do_wrap, wrap_unit_end); @@ -1535,35 +1536,46 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, i32 i = stop.pos; f32 x = stop.x; f32 self_x = 0; + i32 wrap_end_result = size; if (buffer_stringify_loop(&stream, params.buffer, i, size)){ b32 still_looping = 0; do{ for (; i < stream.end; ++i){ - u8 ch = stream.data[i]; + { + u8 ch = stream.data[i]; + translating_fully_process_byte(system, font, &tran, ch, i, size, &emits); + } - switch (word_stage){ - case 0: - { - if (char_is_whitespace(ch)){ - word_stage = 1; - } - else{ - f32 adv = font_get_glyph_advance(params.system, params.font, ch); - - x += adv; - self_x += adv; - if (self_x > width){ + for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){ + TRANSLATION_DECL_GET_STEP(step, behavior, J, emits); + + u32 codepoint = step.value; + switch (word_stage){ + case 0: + { + if (codepoint_is_whitespace(codepoint)){ + word_stage = 1; + } + else{ + f32 adv = font_get_glyph_advance(params.system, params.font, codepoint); + + x += adv; + self_x += adv; + if (self_x > width){ + wrap_end_result = step.i; + goto doublebreak; + } + } + }break; + + case 1: + { + if (!codepoint_is_whitespace(codepoint)){ + wrap_end_result = step.i; goto doublebreak; } - } - }break; - - case 1: - { - if (!char_is_whitespace(ch)){ - goto doublebreak; - } - }break; + }break; + } } } still_looping = buffer_stringify_next(&stream); @@ -1571,7 +1583,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, } doublebreak:; - wrap_unit_end = i; + wrap_unit_end = wrap_end_result; if (x > width){ do_wrap = 1; file_allocate_wrap_positions_as_needed(general, file, wrap_position_index); @@ -1608,7 +1620,6 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, Wrap_Current_Shift current_shift = get_current_shift(&wrap_state, next_line_start); - if (current_shift.adjust_top_to_this){ wrap_state_set_top(&wrap_state, current_shift.shift); } @@ -1702,7 +1713,6 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, goto doublebreak_stage2; } - f32 adv = font_get_glyph_advance(params.system, params.font, ch); x += adv; diff --git a/4tech_defines.h b/4tech_defines.h index 93ae61da..2365626c 100644 --- a/4tech_defines.h +++ b/4tech_defines.h @@ -8,6 +8,7 @@ Created 21.01.2017 (dd.mm.yyyy) #if !defined(FTECH_DEFINES) #define FTECH_DEFINES + #include typedef int8_t i8; @@ -23,7 +24,6 @@ typedef uint64_t u64; typedef i8 b8; typedef i32 b32; -// TODO(allen): Find a real way to detect 32 bit ness. #if defined(FTECH_32_BIT) typedef u32 umem; typedef i32 imem; diff --git a/meta/build.cpp b/meta/build.cpp index 9da7a61c..9a25bc92 100644 --- a/meta/build.cpp +++ b/meta/build.cpp @@ -164,6 +164,10 @@ build_cl(u32 flags, char *code_path, char *code_file, char *out_path, char *out_ build_ap(line, CL_OPTS); } + if (flags & X86){ + build_ap(line, "/DFTECH_32_BIT"); + } + if (flags & INCLUDES){ build_ap(line, CL_INCLUDES); } diff --git a/string/4coder_string_build_num.txt b/string/4coder_string_build_num.txt index 3c4899bf..f89e02d7 100644 --- a/string/4coder_string_build_num.txt +++ b/string/4coder_string_build_num.txt @@ -1,5 +1,5 @@ 1 0 -68 +69 diff --git a/string/_4coder_string.ctm b/string/_4coder_string.ctm index 77f6a7439b2cd0374f3dd2bf75e5d201915439c8..459c3affe802d9725e7d63685fabce04300195f8 100644 GIT binary patch delta 24 dcmZ1?xd`2EG6Q delta 7 OcmdlYxget_count = system_font_get_count; font->get_ids_by_index = system_font_get_ids_by_index; font->get_name_by_index = system_font_get_name_by_index; @@ -98,36 +101,77 @@ Sys_Font_Init_Sig(system_font_init){ font_size = clamp_bottom(8, font_size); - struct Font_Setup{ + struct TEST_DATA{ char *c_filename; i32 filename_len; char *c_name; i32 name_len; - u32 pt_size; }; - Font_Setup font_setup[] = { - {literal("LiberationSans-Regular.ttf"), literal("Liberation Sans"), font_size}, - {literal("liberation-mono.ttf"), literal("Liberation Mono"), font_size}, - {literal("Hack-Regular.ttf"), literal("Hack"), font_size}, - {literal("CutiveMono-Regular.ttf"), literal("Cutive Mono"), font_size}, - {literal("Inconsolata-Regular.ttf"), literal("Inconsolata"), font_size}, + TEST_DATA TEST_SETUP[] = { + {literal("fonts/LiberationSans-Regular.ttf"), literal("Liberation Sans"), }, + {literal("fonts/liberation-mono.ttf"), literal("Liberation Mono"), }, + {literal("fonts/Hack-Regular.ttf"), literal("Hack"), }, + {literal("fonts/CutiveMono-Regular.ttf"), literal("Cutive Mono"), }, + {literal("fonts/Inconsolata-Regular.ttf"), literal("Inconsolata"), }, }; - u32 font_count = Min(ArrayCount(win32_fonts.fonts), ArrayCount(font_setup)); - for (u32 i = 0; i < font_count; ++i){ - String filename = make_string(font_setup[i].c_filename, font_setup[i].filename_len); - String name = make_string(font_setup[i].c_name, font_setup[i].name_len); - u32 pt_size = font_setup[i].pt_size; - Render_Font *render_font = &win32_fonts.fonts[i]; + struct Font_Setup{ + Font_Setup *next_font; + char *c_filename; + char *c_name; + i32 filename_len; + i32 name_len; + }; + + Font_Setup *first_setup = 0; + Font_Setup *head_setup = 0; + + u32 TEST_COUNT = ArrayCount(TEST_SETUP); + for (u32 i = 0; i < TEST_COUNT; ++i){ + if (first_setup == 0){ + head_setup = push_struct(scratch, Font_Setup); + first_setup = head_setup; + } + else{ + head_setup->next_font = push_struct(scratch, Font_Setup); + head_setup = head_setup->next_font; + } - char full_filename_space[256]; - String full_filename = make_fixed_width_string(full_filename_space); - sysshared_to_binary_path(&full_filename, filename.str); + TEST_DATA *TEST = &TEST_SETUP[i]; - system_set_font(&win32vars.system, &win32_fonts.part, render_font, full_filename, name, pt_size, use_hinting); + head_setup->c_filename = push_array(scratch, char, TEST->filename_len+1); + memcpy(head_setup->c_filename, TEST->c_filename, TEST->filename_len+1); + head_setup->filename_len = TEST->filename_len; + + head_setup->c_name = push_array(scratch, char, TEST->name_len+1); + memcpy(head_setup->c_name, TEST->c_name, TEST->name_len+1); + head_setup->name_len = TEST->name_len; + + partition_align(scratch, 8); } - win32_fonts.font_count = font_count; + u32 font_count_max = ArrayCount(win32_fonts.fonts); + u32 font_count = 0; + u32 i = 0; + for (Font_Setup *ptr = first_setup; ptr != 0; ptr = ptr->next_font, ++i){ + if (i < font_count_max){ + String filename = make_string(ptr->c_filename, ptr->filename_len); + String name = make_string(ptr->c_name, ptr->name_len); + Render_Font *render_font = &win32_fonts.fonts[i]; + + char full_filename_space[256]; + String full_filename = make_fixed_width_string(full_filename_space); + sysshared_to_binary_path(&full_filename, filename.str); + + system_set_font(&win32vars.system, &win32_fonts.part, render_font, full_filename, name, font_size, use_hinting); + } + + ++font_count; + } + + win32_fonts.font_count = clamp_top(font_count, font_count_max); + + end_temp_memory(temp); } // BOTTOM From 7521c2f43608173f98297a05d45a3313b77b0886 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 24 Mar 2017 23:42:16 -0400 Subject: [PATCH 12/17] finished font folder system on windows build, fixed mouse wheel on windows build --- 4coder_lib/4coder_mem.h | 7 ++++ 4ed_system_shared.cpp | 46 +++++++++++++++---------- win32_4ed.cpp | 2 +- win32_4ed_fonts.cpp | 75 ++++++++++++++++++++++++++++++----------- 4 files changed, 92 insertions(+), 38 deletions(-) diff --git a/4coder_lib/4coder_mem.h b/4coder_lib/4coder_mem.h index 4371681d..69ce0e1b 100644 --- a/4coder_lib/4coder_mem.h +++ b/4coder_lib/4coder_mem.h @@ -78,6 +78,13 @@ partition_allocate(Partition *data, i32_4tech size){ return ret; } +inline void +partition_reduce(Partition *data, i32_4tech size){ + if (size > 0 && size <= data->pos){ + data->pos -= size; + } +} + inline void partition_align(Partition *data, u32_4tech boundary){ --boundary; diff --git a/4ed_system_shared.cpp b/4ed_system_shared.cpp index badb9ba4..1818a941 100644 --- a/4ed_system_shared.cpp +++ b/4ed_system_shared.cpp @@ -703,6 +703,14 @@ font_load(System_Functions *system, Partition *part, Render_Font *font, i32 pt_s FT_Request_Size(face, &size); // set size & metrics + char *name = face->family_name; + u32 name_len = 0; + for (;name[name_len];++name_len); + name_len = clamp_top(name_len, sizeof(font->name)-1); + memcpy(font->name, name, name_len); + font->name[name_len] = 0; + font->name_len = name_len; + font->ascent = ceil32 (face->size->metrics.ascender / 64.0f); font->descent = floor32 (face->size->metrics.descender / 64.0f); font->advance = ceil32 (face->size->metrics.max_advance / 64.0f); @@ -762,28 +770,30 @@ system_set_page(System_Functions *system, Partition *part, Render_Font *font, Gl } internal void -system_set_font(System_Functions *system, Partition *part, Render_Font *font, String filename, String name, u32 pt_size, b32 use_hinting){ +system_set_font(System_Functions *system, Partition *part, Render_Font *font, char *filename, u32 pt_size, b32 use_hinting){ memset(font, 0, sizeof(*font)); - copy_partial_cs(font->filename, sizeof(font->filename)-1, filename); - font->filename_len = filename.size; - font->filename[font->filename_len] = 0; - copy_partial_cs(font->name, sizeof(font->name)-1, name); - font->name_len = name.size; - font->name[font->name_len] = 0; + u32 filename_len = 0; + for (;filename[filename_len];++filename_len); - if (part->base == 0){ - *part = sysshared_scratch_partition(MB(8)); - } - - b32 success = false; - for (u32 R = 0; R < 3; ++R){ - success = font_load(system, part, font, pt_size, use_hinting); - if (success){ - break; + if (filename_len <= sizeof(font->filename)-1){ + memcpy(font->filename, filename, filename_len); + font->filename[filename_len] = 0; + font->filename_len = filename_len; + + if (part->base == 0){ + *part = sysshared_scratch_partition(MB(8)); } - else{ - sysshared_partition_double(part); + + b32 success = false; + for (u32 R = 0; R < 3; ++R){ + success = font_load(system, part, font, pt_size, use_hinting); + if (success){ + break; + } + else{ + sysshared_partition_double(part); + } } } } diff --git a/win32_4ed.cpp b/win32_4ed.cpp index d1191746..bd230e49 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -1833,7 +1833,7 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ case WM_MOUSEWHEEL: { win32vars.got_useful_event = 1; - Font_ID rotation = GET_WHEEL_DELTA_WPARAM(wParam); + i32 rotation = GET_WHEEL_DELTA_WPARAM(wParam); if (rotation > 0){ win32vars.input_chunk.trans.mouse_wheel = 1; } diff --git a/win32_4ed_fonts.cpp b/win32_4ed_fonts.cpp index 0aa839bc..e9671a72 100644 --- a/win32_4ed_fonts.cpp +++ b/win32_4ed_fonts.cpp @@ -24,7 +24,7 @@ global Win32_Fonts win32_fonts = {0}; internal Sys_Font_Get_Count_Sig(system_font_get_count){ - return(5); + return(win32_fonts.font_count); } internal @@ -101,6 +101,7 @@ Sys_Font_Init_Sig(system_font_init){ font_size = clamp_bottom(8, font_size); +#if 0 struct TEST_DATA{ char *c_filename; i32 filename_len; @@ -115,17 +116,6 @@ Sys_Font_Init_Sig(system_font_init){ {literal("fonts/Inconsolata-Regular.ttf"), literal("Inconsolata"), }, }; - struct Font_Setup{ - Font_Setup *next_font; - char *c_filename; - char *c_name; - i32 filename_len; - i32 name_len; - }; - - Font_Setup *first_setup = 0; - Font_Setup *head_setup = 0; - u32 TEST_COUNT = ArrayCount(TEST_SETUP); for (u32 i = 0; i < TEST_COUNT; ++i){ if (first_setup == 0){ @@ -149,21 +139,68 @@ Sys_Font_Init_Sig(system_font_init){ partition_align(scratch, 8); } +#endif + + struct Font_Setup{ + Font_Setup *next_font; + char *c_filename; + }; + + Font_Setup *first_setup = 0; + Font_Setup *head_setup = 0; + + u32 dir_max = KB(32); + u8 *directory = push_array(scratch, u8, dir_max); + DWORD dir_len = GetModuleFileName_utf8(0, directory, dir_max-1); + Assert(dir_len < dir_max); + + { + String dir_str = make_string_cap(directory, dir_len, dir_max); + remove_last_folder(&dir_str); + set_last_folder_sc(&dir_str, "fonts", '\\'); + terminate_with_null(&dir_str); + dir_len = dir_str.size; + } + + partition_reduce(scratch, dir_max - dir_len - 1); + partition_align(scratch, 8); + + File_List file_list = {0}; + system_set_file_list(&file_list, (char*)directory, 0, 0, 0); + + for (u32 i = 0; i < file_list.count; ++i){ + File_Info *info = &file_list.infos[i]; + if (first_setup == 0){ + first_setup = push_struct(scratch, Font_Setup); + head_setup = first_setup; + } + else{ + head_setup->next_font = push_struct(scratch, Font_Setup); + head_setup = head_setup->next_font; + } + head_setup->next_font = 0; + + char *filename = info->filename; + u32 len = 0; + for (;filename[len];++len); + + head_setup->c_filename = push_array(scratch, char, dir_len+len+1); + memcpy(head_setup->c_filename, directory, dir_len); + memcpy(head_setup->c_filename + dir_len, filename, len+1); + + partition_align(scratch, 8); + } + + system_set_file_list(&file_list, 0, 0, 0, 0); u32 font_count_max = ArrayCount(win32_fonts.fonts); u32 font_count = 0; u32 i = 0; for (Font_Setup *ptr = first_setup; ptr != 0; ptr = ptr->next_font, ++i){ if (i < font_count_max){ - String filename = make_string(ptr->c_filename, ptr->filename_len); - String name = make_string(ptr->c_name, ptr->name_len); Render_Font *render_font = &win32_fonts.fonts[i]; - char full_filename_space[256]; - String full_filename = make_fixed_width_string(full_filename_space); - sysshared_to_binary_path(&full_filename, filename.str); - - system_set_font(&win32vars.system, &win32_fonts.part, render_font, full_filename, name, font_size, use_hinting); + system_set_font(&win32vars.system, &win32_fonts.part, render_font, ptr->c_filename, font_size, use_hinting); } ++font_count; From a80ff44e04ce51afff50c80941f6024f488afb4a Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 25 Mar 2017 13:05:25 -0400 Subject: [PATCH 13/17] experimenting with extended utf8 --- 4coder_lib/4coder_utf8.h | 95 +++++++++++++++++++++++++++++++++------- 4ed_translation.cpp | 24 ++++++---- 2 files changed, 93 insertions(+), 26 deletions(-) diff --git a/4coder_lib/4coder_utf8.h b/4coder_lib/4coder_utf8.h index 22454d63..b4db6262 100644 --- a/4coder_lib/4coder_utf8.h +++ b/4coder_lib/4coder_utf8.h @@ -58,23 +58,40 @@ utf8_to_u32_length_unchecked(u8_4tech *buffer, u32_4tech *length_out){ *length_out = 1; } else if (buffer[0] < 0xE0){ - result = ((u32_4tech)((buffer[0])&0x1F)) << 6; + result = ((u32_4tech)((buffer[0])&0x1F)) << 6; result |= ((u32_4tech)((buffer[1])&0x3F)); *length_out = 2; } else if (buffer[0] < 0xF0){ - result = ((u32_4tech)((buffer[0])&0x0F)) << 12; + result = ((u32_4tech)((buffer[0])&0x0F)) << 12; result |= ((u32_4tech)((buffer[1])&0x3F)) << 6; result |= ((u32_4tech)((buffer[2])&0x3F)); *length_out = 3; } - else{ - result = ((u32_4tech)((buffer[0])&0x07)) << 18; + else if (buffer[0] < 0xF8){ + result = ((u32_4tech)((buffer[0])&0x07)) << 18; result |= ((u32_4tech)((buffer[1])&0x3F)) << 12; result |= ((u32_4tech)((buffer[2])&0x3F)) << 6; result |= ((u32_4tech)((buffer[3])&0x3F)); *length_out = 4; } + else if (buffer[0] < 0xFC){ + result = ((u32_4tech)((buffer[0])&0x03)) << 24; + result |= ((u32_4tech)((buffer[1])&0x3F)) << 18; + result |= ((u32_4tech)((buffer[2])&0x3F)) << 12; + result |= ((u32_4tech)((buffer[3])&0x3F)) << 6; + result |= ((u32_4tech)((buffer[4])&0x3F)); + *length_out = 5; + } + else{ + result = ((u32_4tech)((buffer[0])&0x01)) << 30; + result |= ((u32_4tech)((buffer[1])&0x03)) << 24; + result |= ((u32_4tech)((buffer[2])&0x3F)) << 18; + result |= ((u32_4tech)((buffer[3])&0x3F)) << 12; + result |= ((u32_4tech)((buffer[4])&0x3F)) << 6; + result |= ((u32_4tech)((buffer[5])&0x3F)); + *length_out = 6; + } return(result); } @@ -208,7 +225,7 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * break; } - codepoint = ((u32_4tech)((s[0])&0x1F)) << 6; + codepoint = ((u32_4tech)((s[0])&0x1F)) << 6; codepoint |= ((u32_4tech)((s[1])&0x3F)); utf8_size = 2; } @@ -218,23 +235,50 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * break; } - codepoint = ((u32_4tech)((s[0])&0x0F)) << 12; + codepoint = ((u32_4tech)((s[0])&0x0F)) << 12; codepoint |= ((u32_4tech)((s[1])&0x3F)) << 6; codepoint |= ((u32_4tech)((s[2])&0x3F)); utf8_size = 3; } - else{ - if (limit > 3){ + else if (s[0] < 0xF8){ + if (limit <= 3){ *error = true; break; } - codepoint = ((u32_4tech)((s[0])&0x07)) << 18; + codepoint = ((u32_4tech)((s[0])&0x07)) << 18; codepoint |= ((u32_4tech)((s[1])&0x3F)) << 12; codepoint |= ((u32_4tech)((s[2])&0x3F)) << 6; codepoint |= ((u32_4tech)((s[3])&0x3F)); utf8_size = 4; } + else if (s[0] < 0xFC){ + if (limit <= 4){ + *error = true; + break; + } + + codepoint = ((u32_4tech)((s[0])&0x03)) << 24; + codepoint |= ((u32_4tech)((s[1])&0x3F)) << 18; + codepoint |= ((u32_4tech)((s[2])&0x3F)) << 12; + codepoint |= ((u32_4tech)((s[3])&0x3F)) << 6; + codepoint |= ((u32_4tech)((s[4])&0x3F)); + utf8_size = 5; + } + else if (s[0] < 0xFE){ + if (limit <= 5){ + *error = true; + break; + } + + codepoint = ((u32_4tech)((s[0])&0x01)) << 30; + codepoint |= ((u32_4tech)((s[1])&0x3F)) << 24; + codepoint |= ((u32_4tech)((s[2])&0x3F)) << 18; + codepoint |= ((u32_4tech)((s[3])&0x3F)) << 12; + codepoint |= ((u32_4tech)((s[4])&0x3F)) << 6; + codepoint |= ((u32_4tech)((s[5])&0x3F)); + utf8_size = 6; + } s += utf8_size; limit -= utf8_size; @@ -320,7 +364,7 @@ utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *s s += utf16_size; limit -= utf16_size; - u8_4tech d_fill[4]; + u8_4tech d_fill[6]; u32_4tech d_fill_count = 0; if (codepoint <= 0x7F){ @@ -333,18 +377,35 @@ utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *s d_fill_count = 2; } else if (codepoint <= 0xFFFF){ - d_fill[0] = (u8_4tech)(0xE0 | (codepoint >> 12)); - d_fill[1] = (u8_4tech)(0x80 | ((codepoint >> 6) & 0x3F)); - d_fill[2] = (u8_4tech)(0x80 | (codepoint & 0x3F)); + d_fill[0] = (u8_4tech)(0xE0 | ( codepoint >> 12)); + d_fill[1] = (u8_4tech)(0x80 | ((codepoint >> 6 ) & 0x3F)); + d_fill[2] = (u8_4tech)(0x80 | ((codepoint) & 0x3F)); d_fill_count = 3; } - else if (codepoint <= 0x10FFFF){ - d_fill[0] = (u8_4tech)(0xF0 | (codepoint >> 18)); + else if (codepoint <= 0x1FFFFF){ + d_fill[0] = (u8_4tech)(0xF0 | ( codepoint >> 18)); d_fill[1] = (u8_4tech)(0x80 | ((codepoint >> 12) & 0x3F)); - d_fill[2] = (u8_4tech)(0x80 | ((codepoint >> 6) & 0x3F)); - d_fill[3] = (u8_4tech)(0x80 | (codepoint & 0x3F)); + d_fill[2] = (u8_4tech)(0x80 | ((codepoint >> 6 ) & 0x3F)); + d_fill[3] = (u8_4tech)(0x80 | ((codepoint) & 0x3F)); d_fill_count = 4; } + else if (codepoint <= 0x3FFFFFF){ + d_fill[0] = (u8_4tech)(0xF8 | ( codepoint >> 24)); + d_fill[1] = (u8_4tech)(0x80 | ((codepoint >> 18) & 0x3F)); + d_fill[2] = (u8_4tech)(0x80 | ((codepoint >> 12) & 0x3F)); + d_fill[3] = (u8_4tech)(0x80 | ((codepoint >> 6 ) & 0x3F)); + d_fill[4] = (u8_4tech)(0x80 | ((codepoint) & 0x3F)); + d_fill_count = 5; + } + else if (codepoint <= 0x7FFFFFFF){ + d_fill[0] = (u8_4tech)(0xFC | ( codepoint >> 30)); + d_fill[1] = (u8_4tech)(0x80 | ((codepoint >> 24) & 0x3F)); + d_fill[2] = (u8_4tech)(0x80 | ((codepoint >> 18) & 0x3F)); + d_fill[3] = (u8_4tech)(0x80 | ((codepoint >> 12) & 0x3F)); + d_fill[4] = (u8_4tech)(0x80 | ((codepoint >> 6 ) & 0x3F)); + d_fill[5] = (u8_4tech)(0x80 | ((codepoint) & 0x3F)); + d_fill_count = 6; + } else{ *error = true; break; diff --git a/4ed_translation.cpp b/4ed_translation.cpp index 259240c0..0e5c4853 100644 --- a/4ed_translation.cpp +++ b/4ed_translation.cpp @@ -12,7 +12,7 @@ #include "4ed_buffer_model.h" struct Translation_State{ - u8 fill_buffer[4]; + u8 fill_buffer[6]; u32 fill_start_i; u8 fill_i; u8 fill_expected; @@ -40,20 +40,20 @@ struct Translation_Emit_Rule{ }; struct Translation_Emits{ - Buffer_Model_Step steps[5]; + Buffer_Model_Step steps[7]; u32 step_count; }; -#define SINGLE_BYTE_ERROR_CLASS max_u8 +#define CONTINUATION_BYTE max_u8 internal void translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Byte_Description *desc_out){ desc_out->byte_class = 0; - if ((ch >= ' ' && ch < 0x7F) || ch == '\t' || ch == '\n' || ch == '\r'){ + if (ch < 0x80){ desc_out->byte_class = 1; } else if (ch < 0xC0){ - desc_out->byte_class = SINGLE_BYTE_ERROR_CLASS; + desc_out->byte_class = CONTINUATION_BYTE; } else if (ch < 0xE0){ desc_out->byte_class = 2; @@ -61,9 +61,15 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl else if (ch < 0xF0){ desc_out->byte_class = 3; } - else{ + else if (ch < 0xF8){ desc_out->byte_class = 4; } + else if (ch < 0xFC){ + desc_out->byte_class = 5; + } + else{ + desc_out->byte_class = 6; + } desc_out->prelim_emit_type = BufferModelUnit_None; desc_out->last_byte_handler = TranLBH_None; @@ -75,7 +81,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl if (desc_out->byte_class == 1){ desc_out->prelim_emit_type = BufferModelUnit_Codepoint; } - else if (desc_out->byte_class == 0 || desc_out->byte_class == SINGLE_BYTE_ERROR_CLASS){ + else if (desc_out->byte_class == 0 || desc_out->byte_class == CONTINUATION_BYTE){ desc_out->prelim_emit_type = BufferModelUnit_Numbers; } else{ @@ -83,7 +89,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl } } else{ - if (desc_out->byte_class == SINGLE_BYTE_ERROR_CLASS){ + if (desc_out->byte_class == CONTINUATION_BYTE){ tran->fill_buffer[tran->fill_i] = ch; ++tran->fill_i; @@ -92,7 +98,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl } } else{ - if (desc_out->byte_class >= 2 && desc_out->byte_class <= 4){ + if (desc_out->byte_class >= 2 && desc_out->byte_class <= 6){ desc_out->last_byte_handler = TranLBH_Rebuffer; } else if (desc_out->byte_class == 1){ From 3c3f4bd80bad5068eb40b7339423ae2f287ce240 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 25 Mar 2017 13:05:38 -0400 Subject: [PATCH 14/17] Revert "experimenting with extended utf8" This reverts commit a80ff44e04ce51afff50c80941f6024f488afb4a. --- 4coder_lib/4coder_utf8.h | 95 +++++++--------------------------------- 4ed_translation.cpp | 24 ++++------ 2 files changed, 26 insertions(+), 93 deletions(-) diff --git a/4coder_lib/4coder_utf8.h b/4coder_lib/4coder_utf8.h index b4db6262..22454d63 100644 --- a/4coder_lib/4coder_utf8.h +++ b/4coder_lib/4coder_utf8.h @@ -58,40 +58,23 @@ utf8_to_u32_length_unchecked(u8_4tech *buffer, u32_4tech *length_out){ *length_out = 1; } else if (buffer[0] < 0xE0){ - result = ((u32_4tech)((buffer[0])&0x1F)) << 6; + result = ((u32_4tech)((buffer[0])&0x1F)) << 6; result |= ((u32_4tech)((buffer[1])&0x3F)); *length_out = 2; } else if (buffer[0] < 0xF0){ - result = ((u32_4tech)((buffer[0])&0x0F)) << 12; + result = ((u32_4tech)((buffer[0])&0x0F)) << 12; result |= ((u32_4tech)((buffer[1])&0x3F)) << 6; result |= ((u32_4tech)((buffer[2])&0x3F)); *length_out = 3; } - else if (buffer[0] < 0xF8){ - result = ((u32_4tech)((buffer[0])&0x07)) << 18; + else{ + result = ((u32_4tech)((buffer[0])&0x07)) << 18; result |= ((u32_4tech)((buffer[1])&0x3F)) << 12; result |= ((u32_4tech)((buffer[2])&0x3F)) << 6; result |= ((u32_4tech)((buffer[3])&0x3F)); *length_out = 4; } - else if (buffer[0] < 0xFC){ - result = ((u32_4tech)((buffer[0])&0x03)) << 24; - result |= ((u32_4tech)((buffer[1])&0x3F)) << 18; - result |= ((u32_4tech)((buffer[2])&0x3F)) << 12; - result |= ((u32_4tech)((buffer[3])&0x3F)) << 6; - result |= ((u32_4tech)((buffer[4])&0x3F)); - *length_out = 5; - } - else{ - result = ((u32_4tech)((buffer[0])&0x01)) << 30; - result |= ((u32_4tech)((buffer[1])&0x03)) << 24; - result |= ((u32_4tech)((buffer[2])&0x3F)) << 18; - result |= ((u32_4tech)((buffer[3])&0x3F)) << 12; - result |= ((u32_4tech)((buffer[4])&0x3F)) << 6; - result |= ((u32_4tech)((buffer[5])&0x3F)); - *length_out = 6; - } return(result); } @@ -225,7 +208,7 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * break; } - codepoint = ((u32_4tech)((s[0])&0x1F)) << 6; + codepoint = ((u32_4tech)((s[0])&0x1F)) << 6; codepoint |= ((u32_4tech)((s[1])&0x3F)); utf8_size = 2; } @@ -235,50 +218,23 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * break; } - codepoint = ((u32_4tech)((s[0])&0x0F)) << 12; + codepoint = ((u32_4tech)((s[0])&0x0F)) << 12; codepoint |= ((u32_4tech)((s[1])&0x3F)) << 6; codepoint |= ((u32_4tech)((s[2])&0x3F)); utf8_size = 3; } - else if (s[0] < 0xF8){ - if (limit <= 3){ + else{ + if (limit > 3){ *error = true; break; } - codepoint = ((u32_4tech)((s[0])&0x07)) << 18; + codepoint = ((u32_4tech)((s[0])&0x07)) << 18; codepoint |= ((u32_4tech)((s[1])&0x3F)) << 12; codepoint |= ((u32_4tech)((s[2])&0x3F)) << 6; codepoint |= ((u32_4tech)((s[3])&0x3F)); utf8_size = 4; } - else if (s[0] < 0xFC){ - if (limit <= 4){ - *error = true; - break; - } - - codepoint = ((u32_4tech)((s[0])&0x03)) << 24; - codepoint |= ((u32_4tech)((s[1])&0x3F)) << 18; - codepoint |= ((u32_4tech)((s[2])&0x3F)) << 12; - codepoint |= ((u32_4tech)((s[3])&0x3F)) << 6; - codepoint |= ((u32_4tech)((s[4])&0x3F)); - utf8_size = 5; - } - else if (s[0] < 0xFE){ - if (limit <= 5){ - *error = true; - break; - } - - codepoint = ((u32_4tech)((s[0])&0x01)) << 30; - codepoint |= ((u32_4tech)((s[1])&0x3F)) << 24; - codepoint |= ((u32_4tech)((s[2])&0x3F)) << 18; - codepoint |= ((u32_4tech)((s[3])&0x3F)) << 12; - codepoint |= ((u32_4tech)((s[4])&0x3F)) << 6; - codepoint |= ((u32_4tech)((s[5])&0x3F)); - utf8_size = 6; - } s += utf8_size; limit -= utf8_size; @@ -364,7 +320,7 @@ utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *s s += utf16_size; limit -= utf16_size; - u8_4tech d_fill[6]; + u8_4tech d_fill[4]; u32_4tech d_fill_count = 0; if (codepoint <= 0x7F){ @@ -377,35 +333,18 @@ utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *s d_fill_count = 2; } else if (codepoint <= 0xFFFF){ - d_fill[0] = (u8_4tech)(0xE0 | ( codepoint >> 12)); - d_fill[1] = (u8_4tech)(0x80 | ((codepoint >> 6 ) & 0x3F)); - d_fill[2] = (u8_4tech)(0x80 | ((codepoint) & 0x3F)); + d_fill[0] = (u8_4tech)(0xE0 | (codepoint >> 12)); + d_fill[1] = (u8_4tech)(0x80 | ((codepoint >> 6) & 0x3F)); + d_fill[2] = (u8_4tech)(0x80 | (codepoint & 0x3F)); d_fill_count = 3; } - else if (codepoint <= 0x1FFFFF){ - d_fill[0] = (u8_4tech)(0xF0 | ( codepoint >> 18)); + else if (codepoint <= 0x10FFFF){ + d_fill[0] = (u8_4tech)(0xF0 | (codepoint >> 18)); d_fill[1] = (u8_4tech)(0x80 | ((codepoint >> 12) & 0x3F)); - d_fill[2] = (u8_4tech)(0x80 | ((codepoint >> 6 ) & 0x3F)); - d_fill[3] = (u8_4tech)(0x80 | ((codepoint) & 0x3F)); + d_fill[2] = (u8_4tech)(0x80 | ((codepoint >> 6) & 0x3F)); + d_fill[3] = (u8_4tech)(0x80 | (codepoint & 0x3F)); d_fill_count = 4; } - else if (codepoint <= 0x3FFFFFF){ - d_fill[0] = (u8_4tech)(0xF8 | ( codepoint >> 24)); - d_fill[1] = (u8_4tech)(0x80 | ((codepoint >> 18) & 0x3F)); - d_fill[2] = (u8_4tech)(0x80 | ((codepoint >> 12) & 0x3F)); - d_fill[3] = (u8_4tech)(0x80 | ((codepoint >> 6 ) & 0x3F)); - d_fill[4] = (u8_4tech)(0x80 | ((codepoint) & 0x3F)); - d_fill_count = 5; - } - else if (codepoint <= 0x7FFFFFFF){ - d_fill[0] = (u8_4tech)(0xFC | ( codepoint >> 30)); - d_fill[1] = (u8_4tech)(0x80 | ((codepoint >> 24) & 0x3F)); - d_fill[2] = (u8_4tech)(0x80 | ((codepoint >> 18) & 0x3F)); - d_fill[3] = (u8_4tech)(0x80 | ((codepoint >> 12) & 0x3F)); - d_fill[4] = (u8_4tech)(0x80 | ((codepoint >> 6 ) & 0x3F)); - d_fill[5] = (u8_4tech)(0x80 | ((codepoint) & 0x3F)); - d_fill_count = 6; - } else{ *error = true; break; diff --git a/4ed_translation.cpp b/4ed_translation.cpp index 0e5c4853..259240c0 100644 --- a/4ed_translation.cpp +++ b/4ed_translation.cpp @@ -12,7 +12,7 @@ #include "4ed_buffer_model.h" struct Translation_State{ - u8 fill_buffer[6]; + u8 fill_buffer[4]; u32 fill_start_i; u8 fill_i; u8 fill_expected; @@ -40,20 +40,20 @@ struct Translation_Emit_Rule{ }; struct Translation_Emits{ - Buffer_Model_Step steps[7]; + Buffer_Model_Step steps[5]; u32 step_count; }; -#define CONTINUATION_BYTE max_u8 +#define SINGLE_BYTE_ERROR_CLASS max_u8 internal void translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Byte_Description *desc_out){ desc_out->byte_class = 0; - if (ch < 0x80){ + if ((ch >= ' ' && ch < 0x7F) || ch == '\t' || ch == '\n' || ch == '\r'){ desc_out->byte_class = 1; } else if (ch < 0xC0){ - desc_out->byte_class = CONTINUATION_BYTE; + desc_out->byte_class = SINGLE_BYTE_ERROR_CLASS; } else if (ch < 0xE0){ desc_out->byte_class = 2; @@ -61,14 +61,8 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl else if (ch < 0xF0){ desc_out->byte_class = 3; } - else if (ch < 0xF8){ - desc_out->byte_class = 4; - } - else if (ch < 0xFC){ - desc_out->byte_class = 5; - } else{ - desc_out->byte_class = 6; + desc_out->byte_class = 4; } desc_out->prelim_emit_type = BufferModelUnit_None; @@ -81,7 +75,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl if (desc_out->byte_class == 1){ desc_out->prelim_emit_type = BufferModelUnit_Codepoint; } - else if (desc_out->byte_class == 0 || desc_out->byte_class == CONTINUATION_BYTE){ + else if (desc_out->byte_class == 0 || desc_out->byte_class == SINGLE_BYTE_ERROR_CLASS){ desc_out->prelim_emit_type = BufferModelUnit_Numbers; } else{ @@ -89,7 +83,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl } } else{ - if (desc_out->byte_class == CONTINUATION_BYTE){ + if (desc_out->byte_class == SINGLE_BYTE_ERROR_CLASS){ tran->fill_buffer[tran->fill_i] = ch; ++tran->fill_i; @@ -98,7 +92,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl } } else{ - if (desc_out->byte_class >= 2 && desc_out->byte_class <= 6){ + if (desc_out->byte_class >= 2 && desc_out->byte_class <= 4){ desc_out->last_byte_handler = TranLBH_Rebuffer; } else if (desc_out->byte_class == 1){ From 8f8919fd08c29397b2e0b5f86ae7314bd8baec85 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 25 Mar 2017 14:04:27 -0400 Subject: [PATCH 15/17] bullet prooffed the utf8 translation --- 4coder_lib/4coder_utf8.h | 45 +++++++++++++++++++++++++++++++++++++--- 4ed_translation.cpp | 25 +++++++++++++++------- 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/4coder_lib/4coder_utf8.h b/4coder_lib/4coder_utf8.h index 22454d63..bff8d7d7 100644 --- a/4coder_lib/4coder_utf8.h +++ b/4coder_lib/4coder_utf8.h @@ -40,6 +40,20 @@ typedef int32_t b32_4tech; #endif // standard preamble end +static u32_4tech cp_min_by_utf8_length[] = { + 0x0, + 0x0, + 0x80, + 0x800, + 0x10000, +}; + +static u32_4tech surrogate_min = 0xD800; +static u32_4tech surrogate_max = 0xDFFF; + +static u32_4tech nonchar_min = 0xFDD0; +static u32_4tech nonchar_max = 0xFDEF; + static b32_4tech codepoint_is_whitespace(u32_4tech codepoint){ b32_4tech result = false; @@ -76,6 +90,11 @@ utf8_to_u32_length_unchecked(u8_4tech *buffer, u32_4tech *length_out){ *length_out = 4; } + if (result < cp_min_by_utf8_length[*length_out] || (result >= surrogate_min && result <= surrogate_max) || (result >= nonchar_min && result <= nonchar_max) || ((result & 0xFFFF) >= 0xFE)){ + result = 0; + *length_out = 0; + } + return(result); } @@ -104,9 +123,12 @@ utf8_to_u32(u8_4tech **buffer_ptr, u8_4tech *end){ else if (buffer[0] < 0xF0){ length = 3; } - else{ + else if (buffer[0] < 0xF8){ length = 4; } + else{ + length = 0; + } for (u32_4tech i = 1; i < length; ++i){ if ((buffer[i] & 0xC0) != 0x80){ @@ -145,6 +167,11 @@ utf8_to_u32(u8_4tech **buffer_ptr, u8_4tech *end){ }break; } + if (result < cp_min_by_utf8_length[length] || (result >= surrogate_min && result <= surrogate_max) || (result >= nonchar_min && result <= nonchar_max) || ((result & 0xFFFF) >= 0xFE)){ + result = 0; + length = 0; + } + *buffer_ptr = buffer + length; } else{ @@ -171,7 +198,7 @@ u32_to_utf8_unchecked(u32_4tech codepoint, u8_4tech *buffer, u32_4tech *length_o buffer[2] = (u8_4tech)(0x80 | (codepoint & 0x3F)); *length_out = 3; } - else{ + else if (codepoint <= 0x10FFFF){ codepoint &= 0x001FFFFF; buffer[0] = (u8_4tech)(0xF0 | (codepoint >> 18)); buffer[1] = (u8_4tech)(0x80 | ((codepoint >> 12) & 0x3F)); @@ -179,6 +206,9 @@ u32_to_utf8_unchecked(u32_4tech codepoint, u8_4tech *buffer, u32_4tech *length_o buffer[3] = (u8_4tech)(0x80 | (codepoint & 0x3F)); *length_out = 4; } + else{ + *length_out = 0; + } } static umem_4tech @@ -223,7 +253,7 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * codepoint |= ((u32_4tech)((s[2])&0x3F)); utf8_size = 3; } - else{ + else if (s[0] < 0xF8){ if (limit > 3){ *error = true; break; @@ -235,6 +265,15 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech * codepoint |= ((u32_4tech)((s[3])&0x3F)); utf8_size = 4; } + else{ + *error = true; + break; + } + + if (codepoint < cp_min_by_utf8_length[utf8_size]){ + *error = true; + break; + } s += utf8_size; limit -= utf8_size; diff --git a/4ed_translation.cpp b/4ed_translation.cpp index 259240c0..c56b11aa 100644 --- a/4ed_translation.cpp +++ b/4ed_translation.cpp @@ -44,16 +44,17 @@ struct Translation_Emits{ u32 step_count; }; -#define SINGLE_BYTE_ERROR_CLASS max_u8 +#define ERROR_BYTE (max_u8-1) +#define CONTINUATION_BYTE max_u8 internal void translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Byte_Description *desc_out){ desc_out->byte_class = 0; - if ((ch >= ' ' && ch < 0x7F) || ch == '\t' || ch == '\n' || ch == '\r'){ + if (ch < 0x80){ desc_out->byte_class = 1; } else if (ch < 0xC0){ - desc_out->byte_class = SINGLE_BYTE_ERROR_CLASS; + desc_out->byte_class = CONTINUATION_BYTE; } else if (ch < 0xE0){ desc_out->byte_class = 2; @@ -61,9 +62,12 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl else if (ch < 0xF0){ desc_out->byte_class = 3; } - else{ + else if (ch < 0xF8){ desc_out->byte_class = 4; } + else{ + desc_out->byte_class = ERROR_BYTE; + } desc_out->prelim_emit_type = BufferModelUnit_None; desc_out->last_byte_handler = TranLBH_None; @@ -75,7 +79,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl if (desc_out->byte_class == 1){ desc_out->prelim_emit_type = BufferModelUnit_Codepoint; } - else if (desc_out->byte_class == 0 || desc_out->byte_class == SINGLE_BYTE_ERROR_CLASS){ + else if (desc_out->byte_class == 0 || desc_out->byte_class == CONTINUATION_BYTE || desc_out->byte_class == ERROR_BYTE){ desc_out->prelim_emit_type = BufferModelUnit_Numbers; } else{ @@ -83,7 +87,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl } } else{ - if (desc_out->byte_class == SINGLE_BYTE_ERROR_CLASS){ + if (desc_out->byte_class == CONTINUATION_BYTE){ tran->fill_buffer[tran->fill_i] = ch; ++tran->fill_i; @@ -138,8 +142,13 @@ translating_select_emit_rule_with_font(System_Functions *system, Render_Font *fo type_out->codepoint_length = 0; if (desc.prelim_emit_type == BufferModelUnit_Codepoint){ u32 cp = utf8_to_u32_length_unchecked(tran->fill_buffer, &type_out->codepoint_length); - type_out->codepoint = cp; - if (!font_can_render(system, font, cp)){ + if (type_out->codepoint_length != 0){ + type_out->codepoint = cp; + if (!font_can_render(system, font, cp)){ + type_out->emit_type = BufferModelUnit_Numbers; + } + } + else{ type_out->emit_type = BufferModelUnit_Numbers; } } From d94c8c3672279f99b777d86689ef60ab2a486ce4 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 25 Mar 2017 16:49:54 -0400 Subject: [PATCH 16/17] got code wrapping working --- 4coder_lib/4coder_utf8.h | 4 +- 4coder_project_commands.cpp | 2 +- 4ed_file_view.cpp | 74 ++++++++++++++++++++++++------------- 4ed_translation.cpp | 9 ++++- 4 files changed, 59 insertions(+), 30 deletions(-) diff --git a/4coder_lib/4coder_utf8.h b/4coder_lib/4coder_utf8.h index bff8d7d7..0cb1495f 100644 --- a/4coder_lib/4coder_utf8.h +++ b/4coder_lib/4coder_utf8.h @@ -90,7 +90,7 @@ utf8_to_u32_length_unchecked(u8_4tech *buffer, u32_4tech *length_out){ *length_out = 4; } - if (result < cp_min_by_utf8_length[*length_out] || (result >= surrogate_min && result <= surrogate_max) || (result >= nonchar_min && result <= nonchar_max) || ((result & 0xFFFF) >= 0xFE)){ + if (result < cp_min_by_utf8_length[*length_out] || (result >= surrogate_min && result <= surrogate_max)){ result = 0; *length_out = 0; } @@ -167,7 +167,7 @@ utf8_to_u32(u8_4tech **buffer_ptr, u8_4tech *end){ }break; } - if (result < cp_min_by_utf8_length[length] || (result >= surrogate_min && result <= surrogate_max) || (result >= nonchar_min && result <= nonchar_max) || ((result & 0xFFFF) >= 0xFE)){ + if (result < cp_min_by_utf8_length[length] || (result >= surrogate_min && result <= surrogate_max)){ result = 0; length = 0; } diff --git a/4coder_project_commands.cpp b/4coder_project_commands.cpp index c9104821..8a7c2459 100644 --- a/4coder_project_commands.cpp +++ b/4coder_project_commands.cpp @@ -344,7 +344,7 @@ CUSTOM_COMMAND_SIG(load_project){ if (read_bool){ if (config_bool_var(array_item, 0, 0, dest_bool)){ - if (dest_bool){ + if (*dest_bool){ append(&msg, "true, "); } else{ diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index b0943d97..ee96d513 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -1113,7 +1113,7 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_ end = fixed_end_point; } - i = clamp_top(i, line_start); + i = clamp_bottom(i, line_start); if (i == line_start){ skipping_whitespace = true; @@ -1507,9 +1507,6 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, i32 potential_count = 0; i32 stage = 0; - Translation_State tran = {0}; - Translation_Emits emits = {0}; - do{ stop = buffer_measure_wrap_y(&state, params, current_line_shift, do_wrap, wrap_unit_end); @@ -1530,6 +1527,8 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, } } else{ + Translation_State tran = {0}; + Translation_Emits emits = {0}; Gap_Buffer_Stream stream = {0}; i32 word_stage = 0; @@ -1655,6 +1654,8 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, step.this_token = wrap_state.token_ptr; Gap_Buffer_Stream stream = {0}; + Translation_State tran = {0}; + Translation_Emits emits = {0}; Potential_Wrap_Indent_Pair potential_wrap = {0}; potential_wrap.wrap_position = i; @@ -1668,10 +1669,16 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, while(still_looping){ for (; i < stream.end; ++i){ - u8 ch = stream.data[i]; + { + u8 ch = stream.data[i]; + translating_fully_process_byte(system, font, &tran, ch, i, end_i, &emits); + } - if (!char_is_whitespace(ch)){ - goto doublebreak_stage_vspace; + for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){ + TRANSLATION_DECL_GET_STEP(buffer_step, behav, J, emits); + if (!codepoint_is_whitespace(buffer_step.value)){ + goto doublebreak_stage_vspace; + } } } still_looping = buffer_stringify_next(&stream); @@ -1679,19 +1686,29 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, doublebreak_stage_vspace:; do{ + i32 pos_end_i = end_i; while (still_looping){ for (; i < stream.end; ++i){ - u8 ch = stream.data[i]; - - if (char_is_whitespace(ch)){ - goto doublebreak_stage1; + { + u8 ch = stream.data[i]; + translating_fully_process_byte(system, font, &tran, ch, i, end_i, &emits); } - f32 adv = font_get_glyph_advance(params.system, params.font, ch); - x += adv; - if (!first_word && x > current_width){ - emit_comment_position = 1; - goto doublebreak_stage1; + for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){ + TRANSLATION_DECL_GET_STEP(buffer_step, behav, J, emits); + if (codepoint_is_whitespace(buffer_step.value)){ + pos_end_i = buffer_step.i; + goto doublebreak_stage1; + } + + f32 adv = font_get_glyph_advance(params.system, params.font, buffer_step.value); + x += adv; + + if (!first_word && x > current_width){ + pos_end_i = buffer_step.i; + emit_comment_position = true; + goto doublebreak_stage1; + } } } still_looping = buffer_stringify_next(&stream); @@ -1700,28 +1717,35 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, first_word = 0; if (emit_comment_position){ - step.position_end = i; + step.position_end = pos_end_i; step.final_x = x; goto finished_comment_split; } while(still_looping){ for (; i < stream.end; ++i){ - u8 ch = stream.data[i]; - - if (!char_is_whitespace(ch)){ - goto doublebreak_stage2; + { + u8 ch = stream.data[i]; + translating_fully_process_byte(system, font, &tran, ch, i, end_i, &emits); } - f32 adv = font_get_glyph_advance(params.system, params.font, ch); - - x += adv; + for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){ + TRANSLATION_DECL_GET_STEP(buffer_step, behav, J, emits); + + if (!codepoint_is_whitespace(buffer_step.value)){ + pos_end_i = buffer_step.i; + goto doublebreak_stage2; + } + + f32 adv = font_get_glyph_advance(params.system, params.font, buffer_step.value); + x += adv; + } } still_looping = buffer_stringify_next(&stream); } doublebreak_stage2:; - potential_wrap.wrap_position = i; + potential_wrap.wrap_position = pos_end_i; potential_wrap.wrap_x = x; }while(still_looping); } diff --git a/4ed_translation.cpp b/4ed_translation.cpp index c56b11aa..97a15980 100644 --- a/4ed_translation.cpp +++ b/4ed_translation.cpp @@ -143,10 +143,15 @@ translating_select_emit_rule_with_font(System_Functions *system, Render_Font *fo if (desc.prelim_emit_type == BufferModelUnit_Codepoint){ u32 cp = utf8_to_u32_length_unchecked(tran->fill_buffer, &type_out->codepoint_length); if (type_out->codepoint_length != 0){ - type_out->codepoint = cp; - if (!font_can_render(system, font, cp)){ + if ((cp >= nonchar_min && cp <= nonchar_max) || ((cp & 0xFFFF) >= 0xFE)){ type_out->emit_type = BufferModelUnit_Numbers; } + else{ + type_out->codepoint = cp; + if (!font_can_render(system, font, cp)){ + type_out->emit_type = BufferModelUnit_Numbers; + } + } } else{ type_out->emit_type = BufferModelUnit_Numbers; From 74be67ac800cb5744dc520516b06ae79dbb977d3 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 25 Mar 2017 20:50:29 -0400 Subject: [PATCH 17/17] fixed noncharacter bug --- 4ed_translation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/4ed_translation.cpp b/4ed_translation.cpp index 97a15980..11aa4251 100644 --- a/4ed_translation.cpp +++ b/4ed_translation.cpp @@ -143,7 +143,7 @@ translating_select_emit_rule_with_font(System_Functions *system, Render_Font *fo if (desc.prelim_emit_type == BufferModelUnit_Codepoint){ u32 cp = utf8_to_u32_length_unchecked(tran->fill_buffer, &type_out->codepoint_length); if (type_out->codepoint_length != 0){ - if ((cp >= nonchar_min && cp <= nonchar_max) || ((cp & 0xFFFF) >= 0xFE)){ + if ((cp >= nonchar_min && cp <= nonchar_max) || ((cp & 0xFFFF) >= 0xFFFE)){ type_out->emit_type = BufferModelUnit_Numbers; } else{