From 4f55fca356aec64087a62fb001d72afc1c0ee297 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 28 May 2016 14:40:35 -0400 Subject: [PATCH] moved file exchange struct into application side --- 4ed.cpp | 73 ++++++++++++++++++++++---------------------- 4ed_app_models.h | 2 ++ 4ed_exchange.cpp | 49 ++++++++++++++++-------------- 4ed_file_view.cpp | 8 ++--- 4ed_system.h | 16 ---------- system_shared.cpp | 77 ----------------------------------------------- win32_4ed.cpp | 65 --------------------------------------- 7 files changed, 70 insertions(+), 220 deletions(-) diff --git a/4ed.cpp b/4ed.cpp index b5096d2d..ca387d13 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -913,16 +913,14 @@ view_file_in_panel(Command_Data *cmd, Panel *panel, Editing_File *file){ // - Keep current version open and do some sort of diff to keep // the cursor position correct COMMAND_DECL(reopen){ - USE_VARS(vars); USE_MODELS(models); USE_VIEW(view); REQ_FILE(file, view); - USE_EXCHANGE(exchange); if (match(file->name.source_path, file->name.live_name)) return; - i32 file_id = exchange_request_file(exchange, expand_str(file->name.source_path)); + i32 file_id = exchange_request_file(&models->files, expand_str(file->name.source_path)); i32 index = 0; if (file_id){ file_set_to_loading(file); @@ -3217,34 +3215,34 @@ App_Init_Sig(app_init){ target->partition = partition; { - //exchange + File_Exchange *files = &models->files; File_Slot *slots = vars->slots; i32 max = ArrayCount(vars->slots); { char *filename_space; i32 i; - exchange->file.max = max; - exchange->file.available = file_slot_zero(); - exchange->file.available.next = &exchange->file.available; - exchange->file.available.prev = &exchange->file.available; + files->max = max; + files->available = file_slot_zero(); + files->available.next = &files->available; + files->available.prev = &files->available; - exchange->file.active = file_slot_zero(); - exchange->file.active.next = &exchange->file.active; - exchange->file.active.prev = &exchange->file.active; + files->active = file_slot_zero(); + files->active.next = &files->active; + files->active.prev = &files->active; - exchange->file.free_list = file_slot_zero(); - exchange->file.free_list.next = &exchange->file.free_list; - exchange->file.free_list.prev = &exchange->file.free_list; + files->free_list = file_slot_zero(); + files->free_list.next = &files->free_list; + files->free_list.prev = &files->free_list; - exchange->file.files = slots; + files->files = slots; memset(slots, 0, sizeof(File_Slot)*max); filename_space = vars->filename_space; File_Slot *slot = slots; - for (i = 0; i < exchange->file.max; ++i, ++slot){ - ex__file_insert(&exchange->file.available, slot); + for (i = 0; i < files->max; ++i, ++slot){ + ex__file_insert(&files->available, slot); slot->filename = filename_space; filename_space += FileNameMax; } @@ -3562,7 +3560,7 @@ App_Init_Sig(app_init){ vars->cli_processes.count = 0; // NOTE(allen): sys app binding setup - vars->sys_app_max = exchange->file.max; + vars->sys_app_max = models->files.max; vars->sys_app_count = 0; vars->sys_app_bindings = (Sys_App_Binding*)push_array(partition, Sys_App_Binding, vars->sys_app_max); @@ -4430,11 +4428,12 @@ App_Step_Sig(app_step){ // NOTE(allen): Simulate what use to happen on the system side // for processing file exchange. { + File_Exchange *files = &models->files; File_Slot *file; int d = 0; - for (file = exchange->file.active.next; - file != &exchange->file.active; + for (file = files->active.next; + file != &files->active; file = file->next){ ++d; @@ -4475,25 +4474,26 @@ App_Step_Sig(app_step){ } int free_list_count = 0; - for (file = exchange->file.free_list.next; - file != &exchange->file.free_list; + for (file = files->free_list.next; + file != &files->free_list; file = file->next){ ++free_list_count; } - if (exchange->file.free_list.next != &exchange->file.free_list){ + if (files->free_list.next != &files->free_list){ Assert(free_list_count != 0); - ex__insert_range(exchange->file.free_list.next, - exchange->file.free_list.prev, - &exchange->file.available); - exchange->file.num_active -= free_list_count; + ex__insert_range(files->free_list.next, + files->free_list.prev, + &files->available); + files->num_active -= free_list_count; } - ex__check(&exchange->file); + ex__check(files); } // NOTE(allen): processing sys app bindings { + File_Exchange *files = &models->files; Mem_Options *mem = &models->mem; General_Memory *general = &mem->general; @@ -4509,13 +4509,13 @@ App_Step_Sig(app_step){ Working_Set *working_set = &models->working_set; File_Ready_Result file_result = - exchange_file_ready(exchange, binding->sys_id); + exchange_file_ready(files, binding->sys_id); if (file_result.ready){ ed_file = working_set_get_active_file(working_set, binding->app_id); Assert(ed_file); - filename = exchange_file_filename(exchange, binding->sys_id); + filename = exchange_file_filename(files, binding->sys_id); preload_settings = ed_file->preload; if (file_result.exists){ String val = make_string((char*)file_result.data, file_result.size); @@ -4549,7 +4549,7 @@ App_Step_Sig(app_step){ } } - exchange_free_file(exchange, binding->sys_id); + exchange_free_file(files, binding->sys_id); remove = 1; } @@ -4557,12 +4557,12 @@ App_Step_Sig(app_step){ byte *data; i32 size, max; - if (exchange_file_save_complete(exchange, binding->sys_id, &data, &size, &max, &failed)){ + if (exchange_file_save_complete(files, binding->sys_id, &data, &size, &max, &failed)){ Assert(remove == 0); if (data){ general_memory_free(general, data); - exchange_clear_file(exchange, binding->sys_id); + exchange_clear_file(files, binding->sys_id); } Editing_File *file = working_set_get_active_file(working_set, binding->app_id); @@ -4570,7 +4570,7 @@ App_Step_Sig(app_step){ file_synchronize_times(system, file, file->name.source_path.str); } - exchange_free_file(exchange, binding->sys_id); + exchange_free_file(files, binding->sys_id); remove = 1; // if (failed) { TODO(allen): saving error, now what? } @@ -4587,6 +4587,7 @@ App_Step_Sig(app_step){ // NOTE(allen): process as many delayed actions as possible if (models->delay1.count > 0){ + File_Exchange *files = &models->files; Working_Set *working_set = &models->working_set; Mem_Options *mem = &models->mem; General_Memory *general = &mem->general; @@ -4624,7 +4625,7 @@ App_Step_Sig(app_step){ result.is_new = 1; result.file = working_set_alloc_always(working_set, general); if (result.file){ - file_id = exchange_request_file(exchange, filename.str, filename.size); + file_id = exchange_request_file(files, filename.str, filename.size); if (file_id){ file_init_strings(result.file); file_set_name(working_set, result.file, filename.str); @@ -4698,7 +4699,7 @@ App_Step_Sig(app_step){ // TODO(allen): We could handle the case where someone tries to save the same thing // twice... that would be nice to have under control. if (file && buffer_get_sync(file) != SYNC_GOOD){ - i32 sys_id = file_save(system, exchange, mem, file, file->name.source_path.str); + i32 sys_id = file_save(system, files, mem, file, file->name.source_path.str); if (sys_id){ if (act->type == DACT_SAVE_AS){ file_set_name(working_set, file, string.str); diff --git a/4ed_app_models.h b/4ed_app_models.h index 92d4c991..cd17beaf 100644 --- a/4ed_app_models.h +++ b/4ed_app_models.h @@ -64,6 +64,8 @@ struct Models{ Custom_API config_api; Scroll_Rule_Function *scroll_rule; + + File_Exchange files; }; // BOTTOM diff --git a/4ed_exchange.cpp b/4ed_exchange.cpp index 6603f9b7..35f487c4 100644 --- a/4ed_exchange.cpp +++ b/4ed_exchange.cpp @@ -9,6 +9,21 @@ // TOP +enum File_Exchange_Flag{ + FEx_Request = 0x1, + FEx_Ready = 0x2, + FEx_Not_Exist = 0x4, + FEx_Save = 0x8, + FEx_Save_Complete = 0x10, + FEx_Save_Failed = 0x20 +}; + +struct File_Exchange{ + File_Slot available, active, free_list; + File_Slot *files; + i32 num_active, max; +}; + internal void ex__file_insert(File_Slot *pos, File_Slot *file){ pos->next->prev = file; @@ -63,8 +78,7 @@ ex__clear(File_Slot *file){ } internal File_Slot* -ex__get_file(Exchange *exchange){ - File_Exchange *files = &exchange->file; +ex__get_file(File_Exchange *files){ File_Slot *file; ++files->num_active; @@ -86,13 +100,12 @@ ex__set_filename(File_Slot *file, char *filename, int len){ } internal i32 -exchange_request_file(Exchange *exchange, char *filename, int len){ - File_Exchange *files = &exchange->file; +exchange_request_file(File_Exchange *files, char *filename, int len){ i32 result = 0; if (len+1 < FileNameMax){ if (files->num_active < files->max){ - File_Slot *file = ex__get_file(exchange); + File_Slot *file = ex__get_file(files); ex__set_filename(file, filename, len); file->flags |= FEx_Request; @@ -112,9 +125,8 @@ struct File_Ready_Result{ }; internal File_Ready_Result -exchange_file_ready(Exchange *exchange, i32 file_id){ +exchange_file_ready(File_Exchange *files, i32 file_id){ File_Ready_Result result = {0}; - File_Exchange *files = &exchange->file; File_Slot *file = 0; if (file_id > 0 && file_id <= files->max){ @@ -139,8 +151,7 @@ exchange_file_ready(Exchange *exchange, i32 file_id){ } internal b32 -exchange_file_does_not_exist(Exchange *exchange, i32 file_id){ - File_Exchange *files = &exchange->file; +exchange_file_does_not_exist(File_Exchange *files, i32 file_id){ b32 result = 1; File_Slot *slot; @@ -155,14 +166,13 @@ exchange_file_does_not_exist(Exchange *exchange, i32 file_id){ } internal i32 -exchange_save_file(Exchange *exchange, char *filename, int len, +exchange_save_file(File_Exchange *files, char *filename, int len, byte *data, int size, int max){ - File_Exchange *files = &exchange->file; i32 result = 0; if (len+1 < FileNameMax){ if (files->num_active < files->max){ - File_Slot *file = ex__get_file(exchange); + File_Slot *file = ex__get_file(files); ex__set_filename(file, filename, len); file->flags |= FEx_Save; @@ -178,8 +188,8 @@ exchange_save_file(Exchange *exchange, char *filename, int len, } internal b32 -exchange_file_save_complete(Exchange *exchange, i32 file_id, byte **data, int *size, int *max, int *failed){ - File_Exchange *files = &exchange->file; +exchange_file_save_complete(File_Exchange *files, i32 file_id, + byte **data, int *size, int *max, int *failed){ b32 result = 0; if (file_id > 0 && file_id <= files->max){ @@ -198,8 +208,7 @@ exchange_file_save_complete(Exchange *exchange, i32 file_id, byte **data, int *s } internal char* -exchange_file_filename(Exchange *exchange, i32 file_id, i32 *size = 0){ - File_Exchange *files = &exchange->file; +exchange_file_filename(File_Exchange *files, i32 file_id, i32 *size = 0){ char *result = 0; if (file_id > 0 && file_id <= files->max){ @@ -212,9 +221,7 @@ exchange_file_filename(Exchange *exchange, i32 file_id, i32 *size = 0){ } internal void -exchange_free_file(Exchange *exchange, i32 file_id){ - File_Exchange *files = &exchange->file; - +exchange_free_file(File_Exchange *files, i32 file_id){ if (file_id > 0 && file_id <= files->max){ File_Slot *file = files->files + file_id - 1; ex__file_remove(file); @@ -224,9 +231,7 @@ exchange_free_file(Exchange *exchange, i32 file_id){ } internal void -exchange_clear_file(Exchange *exchange, i32 file_id){ - File_Exchange *files = &exchange->file; - +exchange_clear_file(File_Exchange *files, i32 file_id){ if (file_id > 0 && file_id <= files->max){ File_Slot *file = files->files + file_id - 1; ex__clear(file); diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index c516b0a5..03a7b85e 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -436,7 +436,7 @@ file_synchronize_times(System_Functions *system, Editing_File *file, char *filen } internal i32 -file_save(System_Functions *system, Exchange *exchange, Mem_Options *mem, +file_save(System_Functions *system, File_Exchange *files, Mem_Options *mem, Editing_File *file, char *filename){ i32 result = 0; @@ -458,7 +458,7 @@ file_save(System_Functions *system, Exchange *exchange, Mem_Options *mem, else buffer_stringify(buffer, 0, size = max, data); - result = exchange_save_file(exchange, filename, str_size(filename), (byte*)data, size, max); + result = exchange_save_file(files, filename, str_size(filename), (byte*)data, size, max); if (result == 0){ general_memory_free(&mem->general, data); @@ -470,11 +470,11 @@ file_save(System_Functions *system, Exchange *exchange, Mem_Options *mem, } inline b32 -file_save_and_set_names(System_Functions *system, Exchange *exchange, +file_save_and_set_names(System_Functions *system, File_Exchange *files, Mem_Options *mem, Working_Set *working_set, Editing_File *file, char *filename){ b32 result = 0; - result = file_save(system, exchange, mem, file, filename); + result = file_save(system, files, mem, file, filename); if (result){ file_set_name(working_set, file, filename); } diff --git a/4ed_system.h b/4ed_system.h index 687e61f9..723e562d 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -282,21 +282,6 @@ file_slot_zero(){ return(slot); } -enum File_Exchange_Flag{ - FEx_Request = 0x1, - FEx_Ready = 0x2, - FEx_Not_Exist = 0x4, - FEx_Save = 0x8, - FEx_Save_Complete = 0x10, - FEx_Save_Failed = 0x20 -}; - -struct File_Exchange{ - File_Slot available, active, free_list; - File_Slot *files; - i32 num_active, max; -}; - struct Write_Event{ Write_Event *next, *prev; String filename; @@ -305,7 +290,6 @@ struct Write_Event{ struct Exchange{ Thread_Exchange thread; - File_Exchange file; Write_Event write_event_sentinel; }; diff --git a/system_shared.cpp b/system_shared.cpp index 5a8fff84..70158084 100644 --- a/system_shared.cpp +++ b/system_shared.cpp @@ -66,83 +66,6 @@ sysshared_filter_real_files(char **files, i32 *file_count){ *file_count = j; } -#if 0 -void -ex__file_insert(File_Slot *pos, File_Slot *file){ - file->next = pos->next; - file->next->prev = file; - file->prev = pos; - pos->next = file; -} - -void -ex__insert_range(File_Slot *start, File_Slot *end, File_Slot *pos){ - end->next->prev = start->prev; - start->prev->next = end->next; - - end->next = pos->next; - start->prev = pos; - pos->next->prev = end; - pos->next = start; -} - -internal void -ex__check_file(File_Slot *pos){ - File_Slot *file = pos; - - Assert(pos == pos->next->prev); - - for (pos = pos->next; - file != pos; - pos = pos->next){ - Assert(pos == pos->next->prev); - } -} - -internal void -ex__check(File_Exchange *file_exchange){ - ex__check_file(&file_exchange->available); - ex__check_file(&file_exchange->active); - ex__check_file(&file_exchange->free_list); -} - -internal void -sysshared_init_file_exchange( - Exchange *exchange, File_Slot *slots, i32 max, - char **filename_space_out){ - char *filename_space; - i32 i; - - exchange->file.max = max; - exchange->file.available = file_slot_zero(); - exchange->file.available.next = &exchange->file.available; - exchange->file.available.prev = &exchange->file.available; - - exchange->file.active = file_slot_zero(); - exchange->file.active.next = &exchange->file.active; - exchange->file.active.prev = &exchange->file.active; - - exchange->file.free_list = file_slot_zero(); - exchange->file.free_list.next = &exchange->file.free_list; - exchange->file.free_list.prev = &exchange->file.free_list; - - exchange->file.files = slots; - memset(slots, 0, sizeof(File_Slot)*max); - - filename_space = (char*) - system_get_memory(FileNameMax*exchange->file.max); - - File_Slot *slot = slots; - for (i = 0; i < exchange->file.max; ++i, ++slot){ - ex__file_insert(&exchange->file.available, slot); - slot->filename = filename_space; - filename_space += FileNameMax; - } - - if (filename_space_out) *filename_space_out = filename_space; -} -#endif - internal Partition sysshared_scratch_partition(i32 size){ void *data = system_get_memory(size); diff --git a/win32_4ed.cpp b/win32_4ed.cpp index d0a8df4d..0710504c 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -1906,11 +1906,6 @@ int main(int argc, char **argv){ } } } - -#if 0 - File_Slot file_slots[32]; - sysshared_init_file_exchange(&exchange_vars, file_slots, ArrayCount(file_slots), 0); -#endif win32vars.app.init(win32vars.system, &win32vars.target, &memory_vars, &exchange_vars, @@ -2058,66 +2053,6 @@ int main(int argc, char **argv){ win32vars.first = 0; -#if 0 - { - File_Slot *file; - int d = 0; - - for (file = exchange_vars.file.active.next; - file != &exchange_vars.file.active; - file = file->next){ - ++d; - - if (file->flags & FEx_Save){ - Assert((file->flags & FEx_Request) == 0); - file->flags &= (~FEx_Save); - if (sysshared_save_file(file->filename, (char*)file->data, file->size)){ - file->flags |= FEx_Save_Complete; - } - else{ - file->flags |= FEx_Save_Failed; - } - PostMessage(win32vars.window_handle, WM_4coder_ANIMATE, 0, 0); - } - - if (file->flags & FEx_Request){ - Assert((file->flags & FEx_Save) == 0); - file->flags &= (~FEx_Request); - File_Data sysfile = sysshared_load_file(file->filename); - if (!sysfile.got_file){ - file->flags |= FEx_Not_Exist; - } - else{ - file->flags |= FEx_Ready; - file->data = sysfile.data.data; - file->size = sysfile.data.size; - } - PostMessage(win32vars.window_handle, WM_4coder_ANIMATE, 0, 0); - } - } - - int free_list_count = 0; - for (file = exchange_vars.file.free_list.next; - file != &exchange_vars.file.free_list; - file = file->next){ - ++free_list_count; - if (file->data){ - system_free_memory(file->data); - } - } - - if (exchange_vars.file.free_list.next != &exchange_vars.file.free_list){ - Assert(free_list_count != 0); - ex__insert_range(exchange_vars.file.free_list.next, exchange_vars.file.free_list.prev, - &exchange_vars.file.available); - - exchange_vars.file.num_active -= free_list_count; - } - - ex__check(&exchange_vars.file); - } -#endif - i64 timer_end = system_time(); i64 end_target = (timer_start + frame_useconds);