Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlain Magloire2004-04-29 15:54:32 +0000
committerAlain Magloire2004-04-29 15:54:32 +0000
commit79f4e89182f131d4ce3273b6d77ff51145a47756 (patch)
treef7b88a0e74e74d5ac7ddfa3829146a67b2302a68 /core/org.eclipse.cdt.core.win32/library/starter/starter.cpp
parentb984f9d6ea6422f2528bab237415f886fd7dbdd7 (diff)
downloadorg.eclipse.cdt-79f4e89182f131d4ce3273b6d77ff51145a47756.tar.gz
org.eclipse.cdt-79f4e89182f131d4ce3273b6d77ff51145a47756.tar.xz
org.eclipse.cdt-79f4e89182f131d4ce3273b6d77ff51145a47756.zip
Commit support for i18n from Alex Chapiro.
updates spawner and starter
Diffstat (limited to 'core/org.eclipse.cdt.core.win32/library/starter/starter.cpp')
-rw-r--r--core/org.eclipse.cdt.core.win32/library/starter/starter.cpp127
1 files changed, 71 insertions, 56 deletions
diff --git a/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp b/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp
index 7939182bf54..a60e8ac5b32 100644
--- a/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp
+++ b/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp
@@ -25,7 +25,8 @@
#define MAX_CMD_LINE_LENGTH (2049)
#define PIPE_NAME_LENGTH 100
-int copyTo(char * target, const char * source, int cpyLength, int availSpace);
+int copyTo(_TCHAR * target, const _TCHAR * source, int cpyLength, int availSpace);
+void DisplayErrorMessage();
///////////////////////////////////////////////////////////////////////////////
BOOL WINAPI HandlerRoutine( DWORD dwCtrlType) // control signal type
@@ -54,17 +55,17 @@ BOOL WINAPI HandlerRoutine( DWORD dwCtrlType) // control signal type
-extern "C" int _tmain(int argc, TCHAR* argv[]) {
+extern "C" int _tmain(int argc, _TCHAR * argv[]) {
// Make sure that we've been passed the right number of arguments
if (argc < 7) {
- _tprintf(__TEXT("Usage: %s (Three InheritableEventHandles) (CommandLineToSpawn)\n"),
+ _tprintf(_T("Usage: %s (Three InheritableEventHandles) (CommandLineToSpawn)\n"),
argv[0]);
return(0);
}
// Construct the full command line
- TCHAR szCmdLine[MAX_CMD_LINE_LENGTH] = { 0 };
+ _TCHAR szCmdLine[MAX_CMD_LINE_LENGTH] = { 0 };
int nPos = 0;
for(int i = 6; i < argc; ++i)
@@ -73,7 +74,7 @@ extern "C" int _tmain(int argc, TCHAR* argv[]) {
if(0 > (nCpyLen = copyTo(szCmdLine + nPos, argv[i], _tcslen(argv[i]), MAX_CMD_LINE_LENGTH - nPos)))
{
#ifdef DEBUG_MONITOR
- OutputDebugString("Not enough space to build command line\n");
+ OutputDebugStringW(_T("Not enough space to build command line\n"));
#endif
return 0;
}
@@ -83,34 +84,34 @@ extern "C" int _tmain(int argc, TCHAR* argv[]) {
}
szCmdLine[nPos] = _T('\0');
- STARTUPINFO si = { sizeof(si) };
+ STARTUPINFOW si = { sizeof(si) };
PROCESS_INFORMATION pi = { 0 };
DWORD dwExitCode = 0;
#ifdef DEBUG_MONITOR
int currentPID = GetCurrentProcessId();
- char buffer[MAX_CMD_LINE_LENGTH];
+ _TCHAR buffer[MAX_CMD_LINE_LENGTH];
#endif
BOOL exitProc = FALSE;
- HANDLE waitEvent = OpenEvent(EVENT_ALL_ACCESS, TRUE, argv[4]);
+ HANDLE waitEvent = OpenEventW(EVENT_ALL_ACCESS, TRUE, argv[4]);
HANDLE h[3];
- h[0] = OpenEvent(EVENT_ALL_ACCESS, TRUE, argv[3]);
- h[2] = OpenEvent(EVENT_ALL_ACCESS, TRUE, argv[5]); // This is a terminate event
+ h[0] = OpenEventW(EVENT_ALL_ACCESS, TRUE, argv[3]);
+ h[2] = OpenEventW(EVENT_ALL_ACCESS, TRUE, argv[5]); // This is a terminate event
SetConsoleCtrlHandler(HandlerRoutine, TRUE);
- int parentPid = strtol(argv[1], NULL, 10);
- int nCounter = strtol(argv[2], NULL, 10);
- char inPipeName[PIPE_NAME_LENGTH];
- char outPipeName[PIPE_NAME_LENGTH];
- char errPipeName[PIPE_NAME_LENGTH];
+ int parentPid = _tcstol(argv[1], NULL, 10);
+ int nCounter = _tcstol(argv[2], NULL, 10);
+ _TCHAR inPipeName[PIPE_NAME_LENGTH];
+ _TCHAR outPipeName[PIPE_NAME_LENGTH];
+ _TCHAR errPipeName[PIPE_NAME_LENGTH];
- sprintf(inPipeName, "\\\\.\\pipe\\stdin%08i%010i", parentPid, nCounter);
- sprintf(outPipeName, "\\\\.\\pipe\\stdout%08i%010i", parentPid, nCounter);
- sprintf(errPipeName, "\\\\.\\pipe\\stderr%08i%010i", parentPid, nCounter);
+ _stprintf(inPipeName, _T("\\\\.\\pipe\\stdin%08i%010i"), parentPid, nCounter);
+ _stprintf(outPipeName, _T("\\\\.\\pipe\\stdout%08i%010i"), parentPid, nCounter);
+ _stprintf(errPipeName, _T("\\\\.\\pipe\\stderr%08i%010i"), parentPid, nCounter);
#ifdef DEBUG_MONITOR
- sprintf(buffer, "Pipes: %s, %s, %s\n", inPipeName, outPipeName, errPipeName);
- OutputDebugString(buffer);
+ _stprintf(buffer, _T("Pipes: %s, %s, %s\n"), inPipeName, outPipeName, errPipeName);
+ OutputDebugStringW(buffer);
#endif
HANDLE stdHandles[3];
@@ -120,13 +121,13 @@ extern "C" int _tmain(int argc, TCHAR* argv[]) {
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
- if((INVALID_HANDLE_VALUE == (stdHandles[0] = CreateFile(inPipeName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, &sa))) ||
- (INVALID_HANDLE_VALUE == (stdHandles[1] = CreateFile(outPipeName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, &sa))) ||
- (INVALID_HANDLE_VALUE == (stdHandles[2] = CreateFile(errPipeName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, &sa))))
+ if((INVALID_HANDLE_VALUE == (stdHandles[0] = CreateFileW(inPipeName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, &sa))) ||
+ (INVALID_HANDLE_VALUE == (stdHandles[1] = CreateFileW(outPipeName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, &sa))) ||
+ (INVALID_HANDLE_VALUE == (stdHandles[2] = CreateFileW(errPipeName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, &sa))))
{
#ifdef DEBUG_MONITOR
- sprintf(buffer, "Failed to open pipe %i, %i, %i: %i\n", stdHandles[0], stdHandles[1], stdHandles[2], GetLastError());
- OutputDebugString(buffer);
+ _stprintf(buffer, _T("Failed to open pipe %i, %i, %i: %i\n"), stdHandles[0], stdHandles[1], stdHandles[2], GetLastError());
+ OutputDebugStringW(buffer);
#endif
CloseHandle(stdHandles[0]);
CloseHandle(stdHandles[1]);
@@ -141,8 +142,8 @@ extern "C" int _tmain(int argc, TCHAR* argv[]) {
!SetStdHandle(STD_OUTPUT_HANDLE, stdHandles[1]) ||
!SetStdHandle(STD_ERROR_HANDLE, stdHandles[2])) {
#ifdef DEBUG_MONITOR
- sprintf(buffer, "Failed to reassign standard streams: %i\n", GetLastError());
- OutputDebugString(buffer);
+ _stprintf(buffer, _T("Failed to reassign standard streams: %i\n"), GetLastError());
+ OutputDebugStringW(buffer);
#endif
CloseHandle(stdHandles[0]);
CloseHandle(stdHandles[1]);
@@ -150,19 +151,22 @@ extern "C" int _tmain(int argc, TCHAR* argv[]) {
return -1;;
}
+#ifdef DEBUG_MONITOR
+ _stprintf(buffer, _T("Starting: %s\n"), szCmdLine);
+ OutputDebugStringW(buffer);
+#endif
// Spawn the other processes as part of this Process Group
- BOOL f = CreateProcess(NULL, szCmdLine, NULL, NULL, TRUE,
+ BOOL f = CreateProcessW(NULL, szCmdLine, NULL, NULL, TRUE,
0, NULL, NULL, &si, &pi);
// We don't need them any more
CloseHandle(stdHandles[0]);
CloseHandle(stdHandles[1]);
CloseHandle(stdHandles[2]);
- if (f)
- {
+ if (f) {
#ifdef DEBUG_MONITOR
- sprintf(buffer, "Process %i started\n", pi.dwProcessId);
- OutputDebugString(buffer);
+ _stprintf(buffer, _T("Process %i started\n"), pi.dwProcessId);
+ OutputDebugStringW(buffer);
#endif
SetEvent(waitEvent); // Means thar process has been spawned
CloseHandle(pi.hThread);
@@ -175,8 +179,8 @@ extern "C" int _tmain(int argc, TCHAR* argv[]) {
{
case WAIT_OBJECT_0 + 0: // Send Ctrl-C
#ifdef DEBUG_MONITOR
- sprintf(buffer, "starter (PID %i) received CTRL-C event\n", currentPID);
- OutputDebugString(buffer);
+ _stprintf(buffer, _T("starter (PID %i) received CTRL-C event\n"), currentPID);
+ OutputDebugStringW(buffer);
#endif
GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
SetEvent(waitEvent);
@@ -185,16 +189,17 @@ extern "C" int _tmain(int argc, TCHAR* argv[]) {
case WAIT_OBJECT_0 + 1: // App terminated normally
// Make it's exit code our exit code
#ifdef DEBUG_MONITOR
- sprintf(buffer, "starter: launched process has been terminated(PID %i)\n", currentPID);
- OutputDebugString(buffer);
+ _stprintf(buffer, _T("starter: launched process has been terminated(PID %i)\n"),
+ pi.dwProcessId);
+ OutputDebugStringW(buffer);
#endif
GetExitCodeProcess(pi.hProcess, &dwExitCode);
exitProc = TRUE;
break;
case WAIT_OBJECT_0 + 2: // Kill
#ifdef DEBUG_MONITOR
- sprintf(buffer, "starter received KILL event (PID %i)\n", currentPID);
- OutputDebugString(buffer);
+ _stprintf(buffer, _T("starter received KILL event (PID %i)\n"), currentPID);
+ OutputDebugStringW(buffer);
#endif
GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
TerminateProcess(h[1], 0);
@@ -203,22 +208,7 @@ extern "C" int _tmain(int argc, TCHAR* argv[]) {
default:
// Unexpected code
#ifdef DEBUG_MONITOR
- LPTSTR lpMsgBuf;
-
- FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- GetLastError(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR) &lpMsgBuf,
- 0,
- NULL
- );
- OutputDebugString(lpMsgBuf);
- // Free the buffer.
- LocalFree( lpMsgBuf );
+ DisplayErrorMessage();
#endif
exitProc = TRUE;
break;
@@ -226,7 +216,14 @@ extern "C" int _tmain(int argc, TCHAR* argv[]) {
}
CloseHandle(pi.hProcess);
- }
+ } else {
+#ifdef DEBUG_MONITOR
+ _stprintf(buffer, _T("Cannot start: %s\n"), szCmdLine);
+ OutputDebugStringW(buffer);
+
+ DisplayErrorMessage();
+#endif
+ }
CloseHandle(waitEvent);
CloseHandle(h[0]);
@@ -245,7 +242,7 @@ extern "C" int _tmain(int argc, TCHAR* argv[]) {
// availSpace - size of the target buffer
// Return :number of bytes used in target, or -1 in case of error
/////////////////////////////////////////////////////////////////////////////////////
-int copyTo(LPTSTR target, LPCTSTR source, int cpyLength, int availSpace)
+int copyTo(_TCHAR * target, const _TCHAR * source, int cpyLength, int availSpace)
{
BOOL bSlash = FALSE;
int i = 0, j = 0;
@@ -314,5 +311,23 @@ int copyTo(LPTSTR target, LPCTSTR source, int cpyLength, int availSpace)
}
+void DisplayErrorMessage() {
+ char * lpMsgBuf;
+ FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (char *) &lpMsgBuf,
+ 0,
+ NULL
+ );
+ OutputDebugString(lpMsgBuf);
+ // Free the buffer.
+ LocalFree( lpMsgBuf );
+}
+
//////////////////////////////// End of File //////////////////////////////////

Back to the top