From d8d6834d26be2e8d7c3016db48cc30c5b47c5942 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 12 May 2016 13:41:52 -0400 Subject: [PATCH] remove rvalue {}, update file load stuff in linux --- 4coder_custom.h | 15 +++++++++++++++ 4coder_helper.h | 6 +++--- 4coder_string.h | 6 ++++++ 4cpp_lexer.h | 5 ++++- 4ed.cpp | 38 +++++++++++++++++++++++++------------- 4ed.h | 5 +++++ 4ed_command.cpp | 8 +++++++- 4ed_delay.cpp | 12 ++++++++++-- 4ed_file.cpp | 28 +++++++++++++++++++++++----- 4ed_file_view.cpp | 47 ++++++++++++++++++++++++++++------------------- 4ed_font_set.cpp | 10 ++++++++-- 4ed_gui.cpp | 13 ++++++++++++- 4ed_layout.cpp | 14 ++++++++++---- 4ed_math.cpp | 12 ++++++++++++ 4ed_meta.h | 2 +- 4ed_system.h | 10 ++++++++++ Makefile | 4 ++-- linux_4ed.cpp | 32 +++++++++++++++++++++----------- system_shared.cpp | 6 +++--- 19 files changed, 205 insertions(+), 68 deletions(-) diff --git a/4coder_custom.h b/4coder_custom.h index 188b7fe3..3e58483e 100644 --- a/4coder_custom.h +++ b/4coder_custom.h @@ -39,6 +39,11 @@ typedef struct Key_Event_Data{ char modifiers[MDFR_INDEX_COUNT]; } Key_Event_Data; +inline Key_Event_Data +key_event_data_zero(){ + Key_Event_Data data={0}; + return(data); +} typedef struct Mouse_State{ char l, r; @@ -279,6 +284,11 @@ struct Buffer_Summary{ int is_lexed; int map_id; }; +inline Buffer_Summary +buffer_summary_zero(){ + Buffer_Summary summary={0}; + return(summary); +} struct View_Summary{ int exists; @@ -293,6 +303,11 @@ struct View_Summary{ int line_height; int unwrapped_lines; }; +inline View_Summary +view_summary_zero(){ + View_Summary summary={0}; + return(summary); +} #define UserInputKey 0 #define UserInputMouse 1 diff --git a/4coder_helper.h b/4coder_helper.h index e3269e83..5940ad4b 100644 --- a/4coder_helper.h +++ b/4coder_helper.h @@ -230,7 +230,7 @@ struct Buffer_Rect{ }; #ifndef Swap -#define Swap(a,b) do{ auto t = a; a = b; b = t; } while(0) +#define Swap(T,a,b) do{ T t = a; a = b; b = t; } while(0) #endif inline Buffer_Rect @@ -244,10 +244,10 @@ get_rect(View_Summary *view){ rect.line1 = view->cursor.line; if (rect.line0 > rect.line1){ - Swap(rect.line0, rect.line1); + Swap(int, rect.line0, rect.line1); } if (rect.char0 > rect.char1){ - Swap(rect.char0, rect.char1); + Swap(int, rect.char0, rect.char1); } return(rect); diff --git a/4coder_string.h b/4coder_string.h index dae901a6..81346ca5 100644 --- a/4coder_string.h +++ b/4coder_string.h @@ -64,6 +64,7 @@ inline bool char_is_alpha_numeric(char c) { return (c >= 'a' && c <= 'z' || c >= inline bool char_is_hex(char c) { return c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f'; } inline bool char_is_basic(char c) { return c >= ' ' && c <= '~'; } +inline String string_zero(); inline String make_string(void *s, int size, int mem_size); inline String make_string(void *s, int size); @@ -194,6 +195,11 @@ FCPP_LINK bool remove_last_folder(String *str); FCPP_LINK void replace_char(String str, char replace, char with); FCPP_LINK void replace_char(char *str, char replace, char with); +inline String string_zero(){ + String str={0}; + return(str); +} + inline String make_string(void *str, int size, int mem_size){ String result; result.str = (char*)str; diff --git a/4cpp_lexer.h b/4cpp_lexer.h index 267f5d24..cfd3bf84 100644 --- a/4cpp_lexer.h +++ b/4cpp_lexer.h @@ -139,11 +139,14 @@ FCPP_LINK Cpp_Token_Merge cpp_attempt_token_merge(Cpp_Token prev, Cpp_Token next FCPP_LINK bool cpp_push_token_no_merge(Cpp_Token_Stack *stack, Cpp_Token token); FCPP_LINK bool cpp_push_token_nonalloc(Cpp_Token_Stack *stack, Cpp_Token token); +inline Cpp_Lex_Data cpp_lex_data_zero() { Cpp_Lex_Data data = {(Cpp_Preprocessor_State)0}; return(data); } +inline Cpp_Token_Stack cpp_token_stack_zero() { Cpp_Token_Stack stack={0}; return(stack); } + FCPP_LINK Cpp_Read_Result cpp_lex_step(Cpp_File file, Cpp_Lex_Data *lex); FCPP_LINK int cpp_lex_file_token_count(Cpp_File file); FCPP_LINK Cpp_Lex_Data cpp_lex_file_nonalloc(Cpp_File file, Cpp_Token_Stack *stack, Cpp_Lex_Data data); -inline Cpp_Lex_Data cpp_lex_file_nonalloc(Cpp_File file, Cpp_Token_Stack *stack) { return cpp_lex_file_nonalloc(file, stack, {}); } +inline Cpp_Lex_Data cpp_lex_file_nonalloc(Cpp_File file, Cpp_Token_Stack *stack) { return cpp_lex_file_nonalloc(file, stack, cpp_lex_data_zero()); } FCPP_LINK Cpp_Get_Token_Result cpp_get_token(Cpp_Token_Stack *stack, int pos); diff --git a/4ed.cpp b/4ed.cpp index 3155150f..d23373da 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -1820,7 +1820,7 @@ globalvar Command_Function command_table[cmdid_count]; internal void fill_buffer_summary(Buffer_Summary *buffer, Editing_File *file, Working_Set *working_set){ - *buffer = {}; + *buffer = buffer_summary_zero(); if (!file->state.is_dummy){ buffer->exists = 1; buffer->ready = file_is_ready(file); @@ -1843,7 +1843,7 @@ internal void fill_view_summary(View_Summary *view, View *vptr, Live_Views *live_set, Working_Set *working_set){ i32 lock_level; int buffer_id; - *view = {}; + *view = view_summary_zero(); if (vptr->in_use){ view->exists = 1; @@ -1969,7 +1969,7 @@ extern "C"{ fill_buffer_summary(buffer, file, working_set); } else{ - *buffer = {}; + *buffer = buffer_summary_zero(); } } @@ -2259,11 +2259,11 @@ extern "C"{ fill_view_summary(view, panel->view, &cmd->vars->live_set, &cmd->models->working_set); } else{ - *view = {}; + *view = view_summary_zero(); } } else{ - *view = {}; + *view = view_summary_zero(); } } @@ -2529,7 +2529,7 @@ command_caller(Coroutine *coroutine){ // TODO(allen): this isn't really super awesome, could have issues if // the file view get's change out under us. - view->next_mode = {}; + view->next_mode = view_mode_zero(); cmd_in->bind.function(cmd->system, cmd, cmd_in->bind); view->mode = view->next_mode; } @@ -3032,12 +3032,18 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings, } } +inline App_Vars +app_vars_zero(){ + App_Vars vars={0}; + return(vars); +} + internal App_Vars* app_setup_memory(Application_Memory *memory){ Partition _partition = partition_open(memory->vars_memory, memory->vars_memory_size); App_Vars *vars = push_struct(&_partition, App_Vars); Assert(vars); - *vars = {}; + *vars = app_vars_zero(); vars->models.mem.part = _partition; general_memory_open(&vars->models.mem.general, memory->target_memory, memory->target_memory_size); @@ -3061,6 +3067,12 @@ execute_special_tool(void *memory, i32 size, Command_Line_Parameters clparams){ return(result); } +inline App_Settings +app_settings_zero(){ + App_Settings settings={0}; + return(settings); +} + App_Read_Command_Line_Sig(app_read_command_line){ App_Vars *vars; App_Settings *settings; @@ -3073,7 +3085,7 @@ App_Read_Command_Line_Sig(app_read_command_line){ vars = app_setup_memory(memory); settings = &vars->models.settings; - *settings = {}; + *settings = app_settings_zero(); settings->font_size = 16; if (clparams.argc > 1){ @@ -3637,12 +3649,12 @@ App_Step_Sig(app_step){ cmd->screen_width = target->width; cmd->screen_height = target->height; - - cmd->key = {}; - + + cmd->key = key_event_data_zero(); + Temp_Memory param_stack_temp = begin_temp_memory(&models->mem.part); cmd->part = partition_sub_part(&models->mem.part, 16 << 10); - + if (first_step){ General_Memory *general = &models->mem.general; Editing_File *file = working_set_alloc_always(&models->working_set, general); @@ -4456,7 +4468,7 @@ App_Step_Sig(app_step){ general_memory_free(general, string.str); } } - Swap(models->delay1, models->delay2); + Swap(Delay, models->delay1, models->delay2); } end_temp_memory(param_stack_temp); diff --git a/4ed.h b/4ed.h index b3ee3f88..a1f12b23 100644 --- a/4ed.h +++ b/4ed.h @@ -30,6 +30,11 @@ struct Key_Input_Data{ i32 press_count; i32 hold_count; }; +inline Key_Input_Data +key_input_data_zero(){ + Key_Input_Data data={0}; + return(data); +} struct Key_Summary{ i32 count; diff --git a/4ed_command.cpp b/4ed_command.cpp index 4681ad2e..a58ee7fe 100644 --- a/4ed_command.cpp +++ b/4ed_command.cpp @@ -110,13 +110,19 @@ map_drop(Command_Map *map, u16 event_code, u8 modifiers){ return result; } +inline Command_Binding +command_binding_zero(){ + Command_Binding binding = {0}; + return(binding); +} + internal void map_init(Command_Map *commands, Partition *part, i32 max, Command_Map *parent){ max = ((max < 6)?(6):(max)); commands->parent = parent; commands->commands = push_array(part, Command_Binding, max); memset(commands->commands, 0, max*sizeof(*commands->commands)); - commands->vanilla_keyboard_default = {}; + commands->vanilla_keyboard_default = command_binding_zero(); commands->max = max; commands->count = 0; } diff --git a/4ed_delay.cpp b/4ed_delay.cpp index 4a491f65..fcfbd6b6 100644 --- a/4ed_delay.cpp +++ b/4ed_delay.cpp @@ -35,7 +35,14 @@ str_alloc_copy(General_Memory *general, String str){ result.str = (char*)general_memory_allocate(general, result.memory_size, 0); memcpy(result.str, str.str, str.size); result.str[result.size] = 0; - return(result);} + return(result); +} + +inline Delayed_Action +delayed_action_zero(){ + Delayed_Action action={(Action_Type)0}; + return(action); +} inline Delayed_Action* delayed_action_(Delay *delay, Action_Type type){ @@ -45,7 +52,8 @@ delayed_action_(Delay *delay, Action_Type type){ delay->acts = (Delayed_Action*)general_memory_reallocate(delay->general, delay->acts, delay->count*sizeof(Delayed_Action), delay->max*sizeof(Delayed_Action), 0); } result = delay->acts + delay->count++; - *result = {}; + + *result = delayed_action_zero(); result->type = type; return(result); } diff --git a/4ed_file.cpp b/4ed_file.cpp index 0c8cf438..c3153e49 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -263,6 +263,12 @@ working_set_extend_memory(Working_Set *working_set, Editing_File *new_space, i16 } } +inline Editing_File +editing_file_zero(){ + Editing_File file = {0}; + return(file); +} + internal Editing_File* working_set_alloc(Working_Set *working_set){ Editing_File *result = 0; @@ -278,7 +284,7 @@ working_set_alloc(Working_Set *working_set){ // NOTE(allen): What I really want to do here is clear everything // except id, but writing that out will be a pain to maintain. id = result->id; - *result = {}; + *result = editing_file_zero(); result->id = id; dll_insert(&working_set->used_sentinel, node); ++working_set->file_count; @@ -504,11 +510,11 @@ hot_directory_quick_partition(File_Info *infos, i32 start, i32 pivot){ comp = p->folder - a->folder; if (comp == 0) comp = compare(a->filename, p->filename); if (comp < 0){ - Swap(*a, infos[start]); + Swap(File_Info, *a, infos[start]); ++start; } } - Swap(*p, infos[start]); + Swap(File_Info, *p, infos[start]); return start; } @@ -639,10 +645,22 @@ file_is_ready(Editing_File *file){ return(result); } +inline Editing_File_State +editing_file_state_zero(){ + Editing_File_State state={0}; + return(state); +} + +inline Editing_File_Settings +editing_file_settings_zero(){ + Editing_File_Settings settings={0}; + return(settings); +} + inline void file_set_to_loading(Editing_File *file){ - file->state = {}; - file->settings = {}; + file->state = editing_file_state_zero(); + file->settings = editing_file_settings_zero(); file->state.is_loading = 1; } diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index c461a3d4..846973fb 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -29,6 +29,11 @@ enum Interactive_Interaction{ struct View_Mode{ i32 rewrite; }; +inline View_Mode +view_mode_zero(){ + View_Mode mode={0}; + return(mode); +} enum View_Widget_Type{ FWIDG_NONE, @@ -79,6 +84,11 @@ struct File_Viewing_Data{ i32 line_count, line_max; f32 *line_wrap_y; }; +inline File_Viewing_Data +file_viewing_data_zero(){ + File_Viewing_Data data={0}; + return(data); +} struct View{ View *next, *prev; @@ -515,7 +525,7 @@ file_create_from_string(System_Functions *system, Models *models, Buffer_Init_Type init; i32 page_size, scratch_size, init_success; - file->state = {}; + file->state = editing_file_state_zero(); init = buffer_begin_init(&file->state.buffer, val.str, val.size); for (; buffer_init_need_more(&init); ){ @@ -581,16 +591,14 @@ file_create_from_string(System_Functions *system, Models *models, internal b32 file_create_empty(System_Functions *system, Models *models, Editing_File *file, char *filename){ - - file_create_from_string(system, models, file, filename, {}); + file_create_from_string(system, models, file, filename, string_zero()); return (1); } internal b32 file_create_read_only(System_Functions *system, Models *models, Editing_File *file, char *filename){ - - file_create_from_string(system, models, file, filename, {}, 1); + file_create_from_string(system, models, file, filename, string_zero(), 1); return (1); } @@ -707,7 +715,7 @@ file_kill_tokens(System_Functions *system, general_memory_free(general, file->state.token_stack.tokens); } file->state.tokens_complete = 0; - file->state.token_stack = {}; + file->state.token_stack = cpp_token_stack_zero(); } #if BUFFER_EXPERIMENT_SCALPEL <= 0 @@ -1270,7 +1278,7 @@ view_set_file( // NOTE(allen): Stuff that doesn't assume file exists. // TODO(allen): Use a proper file changer here. - view->file_data = {0}; + view->file_data = file_viewing_data_zero();; view->file_data.file = file; // NOTE(allen): Stuff that does assume file exists. @@ -1812,6 +1820,7 @@ file_replace_range(System_Functions *system, Models *models, Editing_File *file, spec.step.type = ED_NORMAL; spec.step.edit.start = start; spec.step.edit.end = end; + spec.step.edit.len = len; spec.step.pre_pos = file->state.cursor_pos; spec.step.post_pos = next_cursor; @@ -2580,7 +2589,7 @@ file_view_nullify_file(View *view){ if (view->file_data.line_wrap_y){ general_memory_free(general, view->file_data.line_wrap_y); } - view->file_data = {0}; + view->file_data = file_viewing_data_zero(); } internal void @@ -2861,7 +2870,7 @@ file_step(View *view, i32_Rect region, Input_Summary *user_input, b32 is_active) view_set_widget(view, FWIDG_NONE); if (rx >= 0 && rx < max_x && ry >= 0 && ry < max_visible_y){ view_cursor_move(view, rx + scroll_vars.scroll_x, ry + scroll_vars.scroll_y, 1); - view->mode = {}; + view->mode = view_mode_zero(); } } } @@ -2938,7 +2947,7 @@ get_exhaustive_info(System_Functions *system, Working_Set *working_set, Exhausti result.name_match = (filename_match(loop->front_name, &loop->absolutes, result.info->filename, 0) != 0); result.is_loaded = (file != 0 && file_is_ready(file)); - result.message = {0}; + result.message = string_zero(); if (result.is_loaded){ switch (buffer_get_sync(file)){ case SYNC_GOOD: result.message = message_loaded; break; @@ -3577,7 +3586,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su file = (Editing_File*)node; Assert(!file->state.is_dummy); - message = {0}; + message = string_zero(); switch (buffer_get_sync(file)){ case SYNC_BEHIND_OS: message = message_unsynced; break; case SYNC_UNSAVED: message = message_unsaved; break; @@ -3688,12 +3697,12 @@ click_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *user } if (user_input->mouse.release_l && gui_id_eq(target->mouse_hot, b->id)){ target->active = b->id; - target->mouse_hot = {0}; + target->mouse_hot = gui_id_zero(); *is_animating = 1; } } else if (gui_id_eq(target->hover, b->id)){ - target->hover = {0}; + target->hover = gui_id_zero(); } } @@ -3714,7 +3723,7 @@ scroll_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *use } } else if (gui_id_eq(target->hover, id)){ - target->hover = {0}; + target->hover = gui_id_zero(); } return(result); } @@ -3733,7 +3742,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange, gui_session_init(&gui_session, rect, view->font_height); - target->active = {0}; + target->active = gui_id_zero(); for (h = (GUI_Header*)target->push.base; h->type; @@ -3751,7 +3760,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange, GUI_Interactive *b = (GUI_Interactive*)h; if (interpret_result.auto_activate){ - target->auto_hot = {0}; + target->auto_hot = gui_id_zero(); target->active = b->id; is_animating = 1; } @@ -3844,7 +3853,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange, } } else if (gui_id_eq(target->hover, id)){ - target->hover = {0}; + target->hover = gui_id_zero(); } if (gui_id_eq(target->mouse_hot, id)){ @@ -3910,7 +3919,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange, if (!user_input->mouse.l){ if (!gui_id_is_null(target->mouse_hot)){ - target->mouse_hot = {0}; + target->mouse_hot = gui_id_zero(); is_animating = 1; } } @@ -4297,7 +4306,7 @@ draw_color_button(GUI_Target *gui_target, Render_Target *target, View *view, i16 font_id = models->global_font.font_id; if (active_level > 0){ - Swap(back, fore); + Swap(u32, back, fore); } draw_rectangle(target, rect, back); diff --git a/4ed_font_set.cpp b/4ed_font_set.cpp index e0410920..3a3ee64c 100644 --- a/4ed_font_set.cpp +++ b/4ed_font_set.cpp @@ -40,6 +40,12 @@ font__remove(Font_Slot *slot){ n->prev = p; } +internal Font_Slot +font_slot_zero(){ + Font_Slot slot = {}; + return(slot); +} + internal void font_set_init(Font_Set *set, Partition *partition, i32 max, i16 live_max){ partition_align(partition, 8); @@ -52,8 +58,8 @@ font_set_init(Font_Set *set, Partition *partition, i32 max, i16 live_max){ partition_align(partition, 8); set->font_block = push_block(partition, live_max*(sizeof(Render_Font) + sizeof(Font_Slot))); - set->free_slots = {}; - set->used_slots = {}; + set->free_slots = font_slot_zero(); + set->used_slots = font_slot_zero(); dll_init_sentinel(&set->free_slots); dll_init_sentinel(&set->used_slots); diff --git a/4ed_gui.cpp b/4ed_gui.cpp index 94132448..ed971051 100644 --- a/4ed_gui.cpp +++ b/4ed_gui.cpp @@ -115,6 +115,11 @@ super_color_post_byte(Super_Color *color, i32 channel, u8 byte){ struct GUI_id{ u64 id[2]; }; +inline GUI_id +gui_id_zero(){ + GUI_id id = {0}; + return(id); +} struct GUI_Scroll_Vars{ f32 scroll_y; @@ -736,11 +741,17 @@ gui_session_get_current_top(GUI_Session *session){ return(result); } +inline GUI_Session +gui_session_zero(){ + GUI_Session session={0}; + return(session); +} + internal void gui_session_init(GUI_Session *session, i32_Rect full_rect, i32 line_height){ GUI_Section *section; - *session = {0}; + *session = gui_session_zero(); session->full_rect = full_rect; session->line_height = line_height; session->scroll_bar_w = GUIScrollbarWidth; diff --git a/4ed_layout.cpp b/4ed_layout.cpp index 81d20fa9..86b00160 100644 --- a/4ed_layout.cpp +++ b/4ed_layout.cpp @@ -75,15 +75,21 @@ panel_init(Panel *panel){ panel->view = 0; panel->parent = -1; panel->which_child = 0; - panel->screen_region.full = {}; - panel->screen_region.inner = {}; - panel->screen_region.prev_inner = {}; + panel->screen_region.full = i32_rect_zero(); + panel->screen_region.inner = i32_rect_zero(); + panel->screen_region.prev_inner = i32_rect_zero(); panel->l_margin = 3; panel->r_margin = 3; panel->t_margin = 3; panel->b_margin = 3; } +inline Panel_Divider +panel_divider_zero(){ + Panel_Divider divider={0}; + return(divider); +} + internal Divider_And_ID layout_alloc_divider(Editing_Layout *layout){ Divider_And_ID result; @@ -92,7 +98,7 @@ layout_alloc_divider(Editing_Layout *layout){ result.divider = layout->free_divider; layout->free_divider = result.divider->next; - *result.divider = {}; + *result.divider = panel_divider_zero(); result.divider->parent = -1; result.divider->child1 = -1; result.divider->child2 = -1; diff --git a/4ed_math.cpp b/4ed_math.cpp index 9138485a..3d8f11a5 100644 --- a/4ed_math.cpp +++ b/4ed_math.cpp @@ -108,6 +108,18 @@ struct f32_Rect{ f32 x1, y1; }; +inline i32_Rect +i32_rect_zero(){ + i32_Rect rect={0}; + return(rect); +} + +inline f32_Rect +f32_rect_zero(){ + f32_Rect rect={0}; + return(rect); +} + inline i32_Rect i32R(i32 l, i32 t, i32 r, i32 b){ i32_Rect rect; diff --git a/4ed_meta.h b/4ed_meta.h index 97939246..a8cbd0eb 100644 --- a/4ed_meta.h +++ b/4ed_meta.h @@ -99,7 +99,7 @@ _OutDbgStr(u8*); #define OffsetOfStruct(S,c) ((i64)(& ((S*)0)->c )) #define OffsetOfPtr(s,c) ((i64)((char*)(&(s)->c) - (char*)(s))) -#define Swap(a,b) {auto t = a; a = b; b = t;} +#define Swap(T,a,b) do{ T t = a; a = b; b = t; } while(0) #ifndef literal #define literal(s) s, (sizeof(s)-1) diff --git a/4ed_system.h b/4ed_system.h index 28f753fb..3953a8d3 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -133,6 +133,11 @@ struct Thread_Memory{ i32 size; i32 id; }; +inline Thread_Memory +thread_memory_zero(){ + Thread_Memory memory={0}; + return(memory); +} struct Thread_Exchange; struct System_Functions; @@ -255,6 +260,11 @@ struct File_Slot{ i32 filename_len; u32 flags; }; +inline File_Slot +file_slot_zero(){ + File_Slot slot={0}; + return(slot); +} enum File_Exchange_Flag{ FEx_Request = 0x1, diff --git a/Makefile b/Makefile index 362ca37a..6f825432 100755 --- a/Makefile +++ b/Makefile @@ -7,10 +7,10 @@ FLAGS := -fPIC -fno-threadsafe-statics -pthread -I../foreign -g -O0 all: ../4ed_app.so ../4ed ../4ed_app.so: $(CPP_FILES) $(H_FILES) - g++ $(WARNINGS) $(FLAGS) -std=gnu++0x -shared 4ed_app_target.cpp -iquoteforeign -o $@ + g++ $(WARNINGS) $(FLAGS) -shared 4ed_app_target.cpp -iquoteforeign -o $@ ../4ed: $(CPP_FILES) $(H_FILES) - g++ $(WARNINGS) $(FLAGS) -std=gnu++0x linux_4ed.cpp -iquoteforeign $(PLAT_LINKS) -o $@ + g++ $(WARNINGS) $(FLAGS) linux_4ed.cpp -iquoteforeign $(PLAT_LINKS) -o $@ clean: $(RM) -f ../4ed_app.so ../4ed diff --git a/linux_4ed.cpp b/linux_4ed.cpp index 0ce38f50..be020889 100644 --- a/linux_4ed.cpp +++ b/linux_4ed.cpp @@ -14,6 +14,10 @@ #include "4ed_meta.h" +#if (__cplusplus <= 199711L) +#define static_assert(x, ...) +#endif + #define FCPP_FORBID_MALLOC #include "4cpp_types.h" @@ -934,7 +938,7 @@ Sys_File_Can_Be_Made(system_file_can_be_made){ internal Sys_Load_File_Sig(system_load_file){ - Data result = {}; + File_Data result = {}; struct stat info = {}; int fd; u8 *ptr, *read_ptr; @@ -986,8 +990,9 @@ Sys_Load_File_Sig(system_load_file){ } } while(bytes_to_read); - result.size = info.st_size; - result.data = ptr; + result.data.size = info.st_size; + result.data.data = ptr; + result.got_file = 1; out: if(fd >= 0) close(fd); @@ -1574,6 +1579,11 @@ struct Init_Input_Result{ XIMStyle best_style; XIC xic; }; +inline Init_Input_Result +init_input_result_zero(){ + Init_Input_Result result={0}; + return(result); +} // NOTE(inso): doesn't actually use XInput anymore, i should change the name... internal Init_Input_Result @@ -1626,12 +1636,12 @@ InitializeXInput(Display *dpy, Window XWindow) } } else{ - result = {}; + result = init_input_result_zero(); fputs("Could not get minimum required input style.\n", stderr); } } else{ - result = {}; + result = init_input_result_zero(); fputs("Could not open X Input Method.\n", stderr); } @@ -2214,7 +2224,7 @@ main(int argc, char **argv) thread->id = i + 1; Thread_Memory *memory = linuxvars.thread_memory + i; - *memory = {}; + *memory = thread_memory_zero(); memory->id = thread->id; thread->queue = &exchange_vars.thread.queues[BACKGROUND_THREADS]; @@ -2619,7 +2629,7 @@ main(int argc, char **argv) linuxvars.first = 0; linuxvars.redraw = 0; - linuxvars.key_data = {}; + linuxvars.key_data = key_input_data_zero(); linuxvars.mouse_data.press_l = 0; linuxvars.mouse_data.release_l = 0; linuxvars.mouse_data.press_r = 0; @@ -2647,14 +2657,14 @@ main(int argc, char **argv) if (file->flags & FEx_Request){ Assert((file->flags & FEx_Save) == 0); file->flags &= (~FEx_Request); - Data sysfile = system_load_file(file->filename); - if (sysfile.data == 0){ + File_Data sysfile = system_load_file(file->filename); + if (!sysfile.got_file){ file->flags |= FEx_Not_Exist; } else{ file->flags |= FEx_Ready; - file->data = sysfile.data; - file->size = sysfile.size; + file->data = sysfile.data.data; + file->size = sysfile.data.size; } LinuxScheduleStep(); diff --git a/system_shared.cpp b/system_shared.cpp index 947e78b8..26442b22 100644 --- a/system_shared.cpp +++ b/system_shared.cpp @@ -80,15 +80,15 @@ sysshared_init_file_exchange( i32 i; exchange->file.max = max; - exchange->file.available = {}; + exchange->file.available = file_slot_zero(); exchange->file.available.next = &exchange->file.available; exchange->file.available.prev = &exchange->file.available; - exchange->file.active = {}; + exchange->file.active = file_slot_zero(); exchange->file.active.next = &exchange->file.active; exchange->file.active.prev = &exchange->file.active; - exchange->file.free_list = {}; + 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;