Revert "progress converting the platform layer over"

unfucking things
This reverts commit c7b1328cab.
master
Allen Webster 2017-03-23 15:15:05 -04:00
parent db39b1ea90
commit baa8ef3d8d
15 changed files with 313 additions and 383 deletions

View File

@ -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.) */

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

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

View File

@ -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:

View File

@ -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];

View File

@ -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]);

View File

@ -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(){

View File

@ -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};

View File

@ -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);

14
pens_arena.cpp Normal file
View File

@ -0,0 +1,14 @@
/*
Build target for the 'pens' project.
By Allen Webster
Created 09.01.2017 (dd.mm.yyyy)
*/
// TOP
struct Arena{
};
// BOTTOM

View File

@ -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);

View File

@ -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);