#include #include #include "Clean.h" #include "thread_message.h" int get_message_number (void) { return RegisterWindowMessage ("CleanCompiler"); } int get_current_thread_id (void) { return GetCurrentThreadId(); } static int CleanCompiler_message_nunber; int compiler_result_handler_installed=0; #define MAX_N_COMPILERS 32 int compiler_finished[MAX_N_COMPILERS]; int compiler_exit_codes[MAX_N_COMPILERS]; void compiler_result_handler (MSG *msg) { if (msg->message==CleanCompiler_message_nunber){ unsigned int compiler_n; compiler_n=msg->wParam; if (compiler_nlParam; compiler_finished[compiler_n]=1; } } } void install_compiler_result_handler (void (**dispatch_null_message_hook_p) (MSG*)) { CleanCompiler_message_nunber=get_message_number(); *dispatch_null_message_hook_p = &compiler_result_handler; } int start_compiler_process (void (**dispatch_null_message_hook_p) (MSG*),CleanString compiler_path,CleanString compiler_directory,CleanString command, int *compiler_thread_id_p,size_t *compiler_thread_handle_p,size_t *compiler_process_handle_p) { PSTR application_name,command_line,env,dir; STARTUPINFO si; PROCESS_INFORMATION pi; int r; if (!compiler_result_handler_installed){ if (dispatch_null_message_hook_p!=NULL) install_compiler_result_handler (dispatch_null_message_hook_p); compiler_result_handler_installed=1; } application_name=CleanStringCharacters (compiler_path); dir=CleanStringCharacters (compiler_directory); command_line=CleanStringCharacters (command); env=NULL; si.cb = sizeof (STARTUPINFO); si.lpReserved = NULL; si.lpReserved2 = NULL; si.cbReserved2 = 0; si.lpDesktop = NULL; si.lpTitle = NULL; si.dwFlags = 0; r=CreateProcess (application_name,command_line,NULL,NULL,TRUE,DETACHED_PROCESS/*0*/,env,dir,&si,&pi); if (r!=0){ *compiler_thread_id_p=pi.dwThreadId; *compiler_thread_handle_p=(size_t)pi.hThread; *compiler_process_handle_p=(size_t)pi.hProcess; } else { *compiler_thread_id_p=0; *compiler_thread_handle_p=0; *compiler_process_handle_p=0; } return r; } int get_integers_from_message (int wm_number,int *i1_p,int *i2_p) { MSG message; int r; r=GetMessage (&message,NULL,wm_number,wm_number); if (r!=0){ *i1_p=message.wParam; *i2_p=message.lParam; } else { *i1_p=0; *i2_p=0; } return r; } #define PM_QS_POSTMESSAGE ((QS_POSTMESSAGE | QS_HOTKEY | QS_TIMER) << 16) int get_integers_from_thread_message (int wm_number,size_t thread_handle,int *i1_p,int *i2_p) { MSG message; int r; r=PeekMessage (&message,INVALID_HANDLE_VALUE,wm_number,wm_number,PM_NOREMOVE | (QS_POSTMESSAGE<<16)); if (r==0){ r=MsgWaitForMultipleObjects (1,(HANDLE*)&thread_handle,0,INFINITE,QS_POSTMESSAGE); if (r==-1 || r==WAIT_OBJECT_0 || r==WAIT_ABANDONED_0){ *i1_p=0; *i2_p=0; return 0; } do { r=PeekMessage (&message,INVALID_HANDLE_VALUE,wm_number,wm_number,PM_NOREMOVE | (QS_POSTMESSAGE<<16)); } while (r==0); } r=PeekMessage (&message,INVALID_HANDLE_VALUE,wm_number,wm_number,PM_REMOVE | (QS_POSTMESSAGE<<16)); /* r=GetMessage (&message,INVALID_HANDLE_VALUE,wm_number,wm_number); */ if (r!=0){ *i1_p=message.wParam; *i2_p=message.lParam; } else { *i1_p=0; *i2_p=0; } return r; } int get_string_from_file_map_and_delete_map (size_t file_map,CleanString s) { int l,i; char *chars,*p; chars=CleanStringCharacters (s); l=CleanStringLength (s); p=MapViewOfFile ((HANDLE)file_map,FILE_MAP_ALL_ACCESS,0,0,l); if (p==NULL) return 0; for (i=0; i