<commit_before>#include <windows.h>
#include "KURALauncher.h"


HINSTANCE hInst;								// current instance
TCHAR szTitle[] = "KURALauncher";
TCHAR szWindowClass[] = "KURALAUNCHER";

ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);

#define KURA_CMD_LINE_SIZE			32768
char *g_pszKuraCommandLine = NULL;

BOOL g_fKuraStarterActive = FALSE;
HANDLE g_hKuraStarterThread = NULL;
HANDLE g_hKuraProcess = NULL;

// This thread starts a child process which executes the Kura command (java).
// In case the kura process terminates unexpectedly, it attempts to restart it
DWORD WINAPI KuraStarter( LPVOID lpThreadParameter )
{
	STARTUPINFO mStartInfo;
	PROCESS_INFORMATION mProcInfo;

	UNREFERENCED_PARAMETER( lpThreadParameter );

	memset(&mStartInfo, 0, sizeof(mStartInfo));
	mStartInfo.cb = sizeof(STARTUPINFO); 
	mStartInfo.dwFlags = STARTF_USESTDHANDLES;

	while( g_fKuraStarterActive )
	{
		// Create the two pipes used for the STDIN and STDOUT of the KURA process
		if(CreatePipes())
		{
			// Create a thread to read the STDOUT data comming from the KURA process
			if(CreateThread(NULL, 0, STDOUT_Thread, NULL, 0, NULL))
			{
				mStartInfo.hStdInput  = g_hINRead;
				mStartInfo.hStdError = g_hOUTWrite;
				mStartInfo.hStdOutput = g_hOUTWrite;

				// Start the KURA process (java)
				if(CreateProcess(NULL, g_pszKuraCommandLine, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &mStartInfo, &mProcInfo))
				{
					g_hKuraProcess = mProcInfo.hProcess;
					// Wait for the KURA process to terminate, then clean up the handles associated with the process
					WaitForSingleObject(mProcInfo.hProcess, INFINITE);
					CloseHandle(mProcInfo.hThread);
					CloseHandle(mProcInfo.hProcess);
				}
				else
				{
					// LOG: Unable to start process
					Sleep( 2000 );
				}
			}
			else
			{
				// LOG: Unable to create STDIO thread 
				Sleep( 2000 );
			}

			// Close the handles associated with the STDIO pipes a new set gets created if required
			CloseHandle(g_hINWrite);
			CloseHandle(g_hINRead);
			CloseHandle(g_hOUTWrite);
			CloseHandle(g_hOUTRead);
		}
		else
		{
			// LOG: Unable to create pipes 
			Sleep( 2000 );
		}
	}

	return 0;
}

char KuraJavaArgs[] = "java \
-Xms256m -Xmx256m -Dkura.os.version=win32 \
-Dkura.arch=x86_64 \
-Dtarget.device=windows \
-Declipse.ignoreApp=true \
-Dkura.home=%KURA_HOME% \
-Dkura.data.dir=%KURA_DATA% \
-Dkura.configuration=file:%KURA_HOME_URI%/kura.properties \
-Dkura.custom.configuration=file:%KURA_HOME_URI%/kura_custom.properties \
-Ddpa.configuration=%KURA_HOME%\\dpa.properties \
-Dlog4j.configuration=file:%KURA_HOME_URI%/log4j.properties \
-Djdk.tls.trustNameService=true \
-jar \"%~dp0\\plugins\\org.eclipse.osgi_3.8.1.v20120830-144521.jar\" \
-configuration %KURA_TEMP%\\Configuration \
";

// Replace substr with replacement in string and return number of replacements made
// Caller should provide a buffer large enough for the replaced string to fit it
int str_replace ( char *string, size_t max_buf, const char *substr, const char *replacement )
{
  char *tok = NULL;
  char *newstr = NULL;
  char *oldstr = NULL;
  char *head = NULL;
  int cnt = 0;
 
  if ( substr == NULL || replacement == NULL )
	  return 0;

  newstr = _strdup (string);
  head = newstr;

  while ( (tok = strstr ( head, substr )) )
  {<commit_msg>Bring back console for launcher<commit_after>#include <windows.h>
#include "KURALauncher.h"


HINSTANCE hInst;								// current instance
TCHAR szTitle[] = "KURALauncher";
TCHAR szWindowClass[] = "KURALAUNCHER";

ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);

#define KURA_CMD_LINE_SIZE			32768
char *g_pszKuraCommandLine = NULL;

BOOL g_fKuraStarterActive = FALSE;
HANDLE g_hKuraStarterThread = NULL;
HANDLE g_hKuraProcess = NULL;

// This thread starts a child process which executes the Kura command (java).
// In case the kura process terminates unexpectedly, it attempts to restart it
DWORD WINAPI KuraStarter( LPVOID lpThreadParameter )
{
	STARTUPINFO mStartInfo;
	PROCESS_INFORMATION mProcInfo;

	UNREFERENCED_PARAMETER( lpThreadParameter );

	memset(&mStartInfo, 0, sizeof(mStartInfo));
	mStartInfo.cb = sizeof(STARTUPINFO); 
	mStartInfo.dwFlags = STARTF_USESTDHANDLES;

	while( g_fKuraStarterActive )
	{
		// Create the two pipes used for the STDIN and STDOUT of the KURA process
		if(CreatePipes())
		{
			// Create a thread to read the STDOUT data comming from the KURA process
			if(CreateThread(NULL, 0, STDOUT_Thread, NULL, 0, NULL))
			{
				mStartInfo.hStdInput  = g_hINRead;
				mStartInfo.hStdError = g_hOUTWrite;
				mStartInfo.hStdOutput = g_hOUTWrite;

				// Start the KURA process (java)
				if(CreateProcess(NULL, g_pszKuraCommandLine, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &mStartInfo, &mProcInfo))
				{
					g_hKuraProcess = mProcInfo.hProcess;
					// Wait for the KURA process to terminate, then clean up the handles associated with the process
					WaitForSingleObject(mProcInfo.hProcess, INFINITE);
					CloseHandle(mProcInfo.hThread);
					CloseHandle(mProcInfo.hProcess);
				}
				else
				{
					// LOG: Unable to start process
					Sleep( 2000 );
				}
			}
			else
			{
				// LOG: Unable to create STDIO thread 
				Sleep( 2000 );
			}

			// Close the handles associated with the STDIO pipes a new set gets created if required
			CloseHandle(g_hINWrite);
			CloseHandle(g_hINRead);
			CloseHandle(g_hOUTWrite);
			CloseHandle(g_hOUTRead);
		}
		else
		{
			// LOG: Unable to create pipes 
			Sleep( 2000 );
		}
	}

	return 0;
}

char KuraJavaArgs[] = "java \
-Xms256m -Xmx256m -Dkura.os.version=win32 \
-Dkura.arch=x86_64 \
-Dtarget.device=windows \
-Declipse.ignoreApp=true \
-Dkura.home=%KURA_HOME% \
-Dkura.data.dir=%KURA_DATA% \
-Dkura.configuration=file:%KURA_HOME_URI%/kura.properties \
-Dkura.custom.configuration=file:%KURA_HOME_URI%/kura_custom.properties \
-Ddpa.configuration=%KURA_HOME%\\dpa.properties \
-Dlog4j.configuration=file:%KURA_HOME_URI%/log4j.properties \
-Djdk.tls.trustNameService=true \
-jar \"%~dp0\\plugins\\org.eclipse.osgi_3.8.1.v20120830-144521.jar\" \
-configuration %KURA_TEMP%\\Configuration \
-console \
-consoleLog \
";

// Replace substr with replacement in string and return number of replacements made
// Caller should provide a buffer large enough for the replaced string to fit it
int str_replace ( char *string, size_t max_buf, const char *substr, const char *replacement )
{
  char *tok = NULL;
  char *newstr = NULL;
  char *oldstr = NULL;
  char *head = NULL;
  int cnt = 0;
 
  if ( substr == NULL || replacement == NULL )
	  return 0;

  newstr = _strdup (string);
  head = newstr;

  while ( (tok = strstr ( head, substr )) )
  {
{'fraction_non_alphanumeric': 0.10422493743559547, 'fraction_numerical': 0.016193139997055794, 'mean_word_length': 3.8355871886120996, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2769914', 'n_tokens_mistral': 2748, 'n_tokens_neox': 2404, 'n_words': 602}