From bdd3bbe0d92e62332a221937395d54e830c99a3a Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Tue, 10 May 2016 13:36:53 -0400 Subject: [PATCH] ready for distribution --- 4coder_default_bindings.cpp | 3 +- 4coder_default_include.cpp | 29 +++++++++-- 4ed_file_view.cpp | 2 +- 4ed_gui.cpp | 2 +- win32_4ed.cpp | 99 +++++++++++++++++++++++-------------- 5 files changed, 90 insertions(+), 45 deletions(-) diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index 7385b8f2..3fbdcfc1 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -67,7 +67,7 @@ HOOK_SIG(my_file_settings){ } push_parameter(app, par_lex_as_cpp_file, treat_as_code); - push_parameter(app, par_wrap_lines, !treat_as_code); + push_parameter(app, par_wrap_lines, wrap_lines); push_parameter(app, par_key_mapid, (treat_as_code)?((int)my_code_map):((int)mapid_file)); exec_command(app, cmdid_set_settings); @@ -293,6 +293,7 @@ int get_bindings(void *data, int size){ bind(context, 'm', MDFR_ALT, build_search); bind(context, 'x', MDFR_ALT, execute_arbitrary_command); bind(context, 'z', MDFR_ALT, execute_any_cli); + bind(context, 'Z', MDFR_ALT, execute_previous_cli); // NOTE(allen): These callbacks may not actually be useful to you, but // go look at them and see what they do. diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index dcd9856c..fe57dcf0 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -513,20 +513,21 @@ CUSTOM_COMMAND_SIG(open_all_code){ app->free_file_list(app, list); } +char out_buffer_space[1024], command_space[1024], hot_directory_space[1024]; + CUSTOM_COMMAND_SIG(execute_any_cli){ Query_Bar bar_out, bar_cmd; String hot_directory; - char space[1024], more_space[1024], even_more_space[1024]; bar_out.prompt = make_lit_string("Output Buffer: "); - bar_out.string = make_fixed_width_string(space); + bar_out.string = make_fixed_width_string(out_buffer_space); if (!query_user_string(app, &bar_out)) return; bar_cmd.prompt = make_lit_string("Command: "); - bar_cmd.string = make_fixed_width_string(more_space); + bar_cmd.string = make_fixed_width_string(command_space); if (!query_user_string(app, &bar_cmd)) return; - hot_directory = make_fixed_width_string(even_more_space); + hot_directory = make_fixed_width_string(hot_directory_space); hot_directory.size = app->directory_get_hot(app, hot_directory.str, hot_directory.memory_size); push_parameter(app, par_flags, CLI_OverlapWithConflict); @@ -534,6 +535,26 @@ CUSTOM_COMMAND_SIG(execute_any_cli){ push_parameter(app, par_cli_path, hot_directory.str, hot_directory.size); push_parameter(app, par_cli_command, bar_cmd.string.str, bar_cmd.string.size); exec_command(app, cmdid_command_line); + + terminate_with_null(&bar_out.string); + terminate_with_null(&bar_cmd.string); + terminate_with_null(&hot_directory); +} + +CUSTOM_COMMAND_SIG(execute_previous_cli){ + String out_buffer, cmd, hot_directory; + + out_buffer = make_string_slowly(out_buffer_space); + cmd = make_string_slowly(command_space); + hot_directory = make_string_slowly(hot_directory_space); + + if (out_buffer.size > 0 && cmd.size > 0 && hot_directory.size > 0){ + push_parameter(app, par_flags, CLI_OverlapWithConflict); + push_parameter(app, par_name, out_buffer.str, out_buffer.size); + push_parameter(app, par_cli_path, hot_directory.str, hot_directory.size); + push_parameter(app, par_cli_command, cmd.str, cmd.size); + exec_command(app, cmdid_command_line); + } } CUSTOM_COMMAND_SIG(execute_arbitrary_command){ diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index d987b5ae..8a6d88ff 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -4783,7 +4783,7 @@ search_hit_add(General_Memory *general, Table *hits, String_Space *space, char * *hits = new_hits; } - if (table_add(hits, &ostring, space->space, tbl_offset_string_hash, tbl_offset_string_compare)){ + if (!table_add(hits, &ostring, space->space, tbl_offset_string_hash, tbl_offset_string_compare)){ result = 1; strspace_keep_prev(space); } diff --git a/4ed_gui.cpp b/4ed_gui.cpp index 1d4b4c8a..94132448 100644 --- a/4ed_gui.cpp +++ b/4ed_gui.cpp @@ -1166,7 +1166,7 @@ gui_standard_list(GUI_Target *target, GUI_id id, ++*list_i; break; - case '\n': + case '\n': case '\t': indirectly_activate = 1; break; } diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 9061477b..2ff0da28 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -166,6 +166,8 @@ struct Win32_Vars{ // will involve more coroutines. Win32_Coroutine coroutine_data[18]; Win32_Coroutine *coroutine_free; + + i32 running_cli; }; globalvar Win32_Vars win32vars; @@ -932,6 +934,8 @@ Sys_CLI_Call_Sig(system_cli_call){ *(HANDLE*)&cli_out->proc = info.hProcess; *(HANDLE*)&cli_out->out_read = out_read; *(HANDLE*)&cli_out->out_write = out_write; + + ++win32vars.running_cli; } else{ CloseHandle(out_read); @@ -943,6 +947,11 @@ Sys_CLI_Call_Sig(system_cli_call){ } else{ // TODO(allen): failed SetHandleInformation + CloseHandle(out_read); + CloseHandle(out_write); + *(HANDLE*)&cli_out->proc = INVALID_HANDLE_VALUE; + *(HANDLE*)&cli_out->out_read = INVALID_HANDLE_VALUE; + *(HANDLE*)&cli_out->out_write = INVALID_HANDLE_VALUE; } } else{ @@ -1016,6 +1025,8 @@ Sys_CLI_End_Update_Sig(system_cli_end_update){ CloseHandle(*(HANDLE*)&cli->proc); CloseHandle(*(HANDLE*)&cli->out_read); CloseHandle(*(HANDLE*)&cli->out_write); + + --win32vars.running_cli; } return close_me; } @@ -1708,17 +1719,22 @@ UpdateLoop(LPVOID param){ #include #endif -#if 0 +#if 1 int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ + + int argc = __argc; + char **argv = __argv; + #else int main(int argc, char **argv){ -#endif - + HINSTANCE hInstance = GetModuleHandle(0); +#endif + HANDLE original_out = GetStdHandle(STD_OUTPUT_HANDLE); win32vars = {}; @@ -1840,70 +1856,70 @@ int main(int argc, char **argv){ GetProcAddress(win32vars.custom, "get_bindings"); } #endif - - //FreeConsole(); - + + FreeConsole(); + sysshared_filter_real_files(files, file_count); - + LARGE_INTEGER lpf; QueryPerformanceFrequency(&lpf); win32vars.performance_frequency = lpf.QuadPart; QueryPerformanceCounter(&lpf); win32vars.start_pcount = lpf.QuadPart; - + FILETIME filetime; GetSystemTimeAsFileTime(&filetime); win32vars.start_time = ((u64)filetime.dwHighDateTime << 32) | (filetime.dwLowDateTime); win32vars.start_time /= 10; - + keycode_init(); - + if (win32vars.custom_api.get_bindings == 0){ win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)get_bindings; } - + Thread_Context background[4]; memset(background, 0, sizeof(background)); win32vars.groups[BACKGROUND_THREADS].threads = background; win32vars.groups[BACKGROUND_THREADS].count = ArrayCount(background); - + Thread_Memory thread_memory[ArrayCount(background)]; win32vars.thread_memory = thread_memory; - + exchange_vars.thread.queues[BACKGROUND_THREADS].semaphore = Win32GenHandle( CreateSemaphore(0, 0, win32vars.groups[BACKGROUND_THREADS].count, 0) ); - + u32 creation_flag = 0; for (i32 i = 0; i < win32vars.groups[BACKGROUND_THREADS].count; ++i){ Thread_Context *thread = win32vars.groups[BACKGROUND_THREADS].threads + i; thread->id = i + 1; - + Thread_Memory *memory = win32vars.thread_memory + i; *memory = {}; memory->id = thread->id; - + thread->queue = &exchange_vars.thread.queues[BACKGROUND_THREADS]; thread->handle = CreateThread(0, 0, JobThreadProc, thread, creation_flag, (LPDWORD)&thread->windows_id); } - + Assert(win32vars.locks); for (i32 i = 0; i < LOCK_COUNT; ++i){ win32vars.locks[i] = CreateSemaphore(0, 1, 1, 0); } win32vars.DEBUG_sysmem_lock = CreateSemaphore(0, 1, 1, 0); - + Win32LoadRenderCode(); win32vars.target.max = Mbytes(1); win32vars.target.push_buffer = (byte*)system_get_memory(win32vars.target.max); - + win32vars.cursor_ibeam = LoadCursor(NULL, IDC_IBEAM); win32vars.cursor_arrow = LoadCursor(NULL, IDC_ARROW); win32vars.cursor_leftright = LoadCursor(NULL, IDC_SIZEWE); win32vars.cursor_updown = LoadCursor(NULL, IDC_SIZENS); win32vars.prev_mouse_cursor = APP_MOUSE_CURSOR_ARROW; - + WNDCLASS window_class = {}; window_class.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC; window_class.lpfnWndProc = Win32Callback; @@ -2052,7 +2068,7 @@ int main(int argc, char **argv){ win32vars.input_chunk.pers.keep_playing = 1; win32vars.first = 1; timeBeginPeriod(1); - + #if 0 win32vars.update_loop_thread = CreateThread(0, @@ -2062,30 +2078,37 @@ int main(int argc, char **argv){ CREATE_SUSPENDED, &win32vars.update_loop_thread_id); #endif - + system_acquire_lock(FRAME_LOCK); - + SetForegroundWindow(window_handle); SetActiveWindow(window_handle); - + +#if 0 ResumeThread(win32vars.update_loop_thread); - +#endif + MSG msg; for (;win32vars.input_chunk.pers.keep_playing;){ - win32vars.got_useful_event = 0; - for (;win32vars.got_useful_event == 0;){ - system_release_lock(FRAME_LOCK); - if (GetMessage(&msg, 0, 0, 0)){ - system_acquire_lock(FRAME_LOCK); - if (msg.message == WM_QUIT){ - win32vars.input_chunk.pers.keep_playing = 0; - }else{ - TranslateMessage(&msg); - DispatchMessage(&msg); + // TODO(allen): Find a good way to wait on a pipe + // without interfering with the reading process + + if (win32vars.running_cli == 0){ + win32vars.got_useful_event = 0; + for (;win32vars.got_useful_event == 0;){ + system_release_lock(FRAME_LOCK); + if (GetMessage(&msg, 0, 0, 0)){ + system_acquire_lock(FRAME_LOCK); + if (msg.message == WM_QUIT){ + win32vars.input_chunk.pers.keep_playing = 0; + }else{ + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + else{ + system_acquire_lock(FRAME_LOCK); } - } - else{ - system_acquire_lock(FRAME_LOCK); } }