From 23d611201e96c5e65701a69cfe1e26de848ef318 Mon Sep 17 00:00:00 2001 From: insofaras Date: Fri, 18 Mar 2016 20:53:07 +0000 Subject: [PATCH] linux updates, use the trying_to_kill/perform_kill thing + make set_file_list more consistent with win32 behaviour --- 4ed_delay.cpp | 2 +- linux_4ed.cpp | 44 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/4ed_delay.cpp b/4ed_delay.cpp index b881e9dc..3167e5ff 100644 --- a/4ed_delay.cpp +++ b/4ed_delay.cpp @@ -130,4 +130,4 @@ delayed_action_repush(Delay *delay, Delayed_Action *act){ #define delayed_try_kill(delay, ...) delayed_action_(delay, DACT_TRY_KILL, __VA_ARGS__) #define delayed_kill(delay, ...) delayed_action_(delay, DACT_KILL, __VA_ARGS__) #define delayed_touch_file(delay, ...) delayed_action_(delay, DACT_TOUCH_FILE, __VA_ARGS__) -#define delayed_close(delay, ...) delayed_action_(delay, DACT_CLOSE, __VA_ARGS__) +#define delayed_close(delay, ...) delayed_action_(delay, DACT_CLOSE, ##__VA_ARGS__) diff --git a/linux_4ed.cpp b/linux_4ed.cpp index fcebc0f5..f86da0bd 100644 --- a/linux_4ed.cpp +++ b/linux_4ed.cpp @@ -325,11 +325,24 @@ Sys_Set_File_List_Sig(system_set_file_list){ char *fname, *cursor, *cursor_start; File_Info *info_ptr; i32 count, file_count, size, required_size; - + + if(directory.size <= 0){ + if(!directory.str){ + system_free_memory(file_list->block); + file_list->block = 0; + file_list->block_size = 0; + } + file_list->infos = 0; + file_list->count = 0; + return; + } + char* dir = (char*) alloca(directory.size + 1); memcpy(dir, directory.str, directory.size); dir[directory.size] = 0; + LINUX_FN_DEBUG("%s", dir); + d = opendir(dir); if (d){ count = 0; @@ -421,15 +434,15 @@ static_assert( Sys_File_Unique_Hash_Sig(system_file_unique_hash){ Unique_Hash result = {}; - struct stat st; + struct stat st = {}; - if(stat(filename.str, &st) == -1){ - perror("sys_file_unique_hash: stat"); - } else { + if(stat(filename.str, &st) == 0){ memcpy(&result, &st.st_dev, sizeof(st.st_dev)); memcpy((char*)&result + sizeof(st.st_dev), &st.st_ino, sizeof(st.st_ino)); } +// LINUX_FN_DEBUG("%s = %ld:%ld", filename.str, (long)st.st_dev, (long)st.st_ino); + return result; } @@ -526,7 +539,7 @@ Sys_Yield_Coroutine_Sig(system_yield_coroutine){ } Sys_CLI_Call_Sig(system_cli_call){ -// fprintf(stderr, "cli call: %s, %s\n", path, script_name); + LINUX_FN_DEBUG("%s %s", path, script_name); int pipe_fds[2]; if(pipe(pipe_fds) == -1){ @@ -815,6 +828,8 @@ FILE_EXISTS_SIG(system_file_exists){ result = stat(buff, &st) == 0 && S_ISREG(st.st_mode); } + LINUX_FN_DEBUG("%s: %d", buff, result); + return(result); } @@ -851,6 +866,8 @@ DIRECTORY_CD_SIG(system_directory_cd){ } *len = directory.size; + + LINUX_FN_DEBUG("%.*s: %d", directory.size, directory.str, result); return(result); } @@ -1107,10 +1124,14 @@ Sys_To_Binary_Path(system_to_binary_path){ b32 translate_success = 0; i32 max = out_filename->memory_size; i32 size = readlink("/proc/self/exe", out_filename->str, max); + + LINUX_FN_DEBUG(); + if (size > 0 && size < max-1){ out_filename->size = size; remove_last_folder(out_filename); if (append(out_filename, filename) && terminate_with_null(out_filename)){ + LINUX_FN_DEBUG("%s", out_filename->str); translate_success = 1; } } @@ -2140,7 +2161,7 @@ main(int argc, char **argv) LinuxResizeTarget(WinWidth, WinHeight); b32 keep_running = 1; - while(keep_running) + while(1) { XEvent PrevEvent = {}; @@ -2271,7 +2292,7 @@ main(int argc, char **argv) case ClientMessage: { if ((Atom)Event.xclient.data.l[0] == WM_DELETE_WINDOW) { - keep_running = false; + keep_running = 0; } else if ((Atom)Event.xclient.data.l[0] == _NET_WM_PING) { Event.xclient.window = DefaultRootWindow(linuxvars.XDisplay); @@ -2416,6 +2437,9 @@ main(int argc, char **argv) result.redraw = linuxvars.redraw; result.lctrl_lalt_is_altgr = 0; + result.trying_to_kill = !keep_running; + result.perform_kill = 0; + u64 start_time = system_time(); linuxvars.app.step(linuxvars.system, @@ -2428,6 +2452,10 @@ main(int argc, char **argv) 1, linuxvars.first, linuxvars.redraw, &result); + if(result.perform_kill){ + break; + } + if (linuxvars.redraw || result.redraw){ LinuxRedrawTarget(); }