Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
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.cpp82
1 files changed, 82 insertions, 0 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 96cb4a35c7a..dd7b118e5b7 100644
--- a/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp
+++ b/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp
@@ -26,6 +26,8 @@
// #define DEBUG_MONITOR
#define MAX_CMD_LINE_LENGTH (1024)
+int copyTo(char * target, const char * source, int cpyLength, int availSpace);
+
///////////////////////////////////////////////////////////////////////////////
BOOL WINAPI HandlerRoutine( DWORD dwCtrlType) // control signal type
{
@@ -64,6 +66,24 @@ extern "C" int _tmain(int argc, TCHAR* argv[]) {
// Construct the full command line
TCHAR szCmdLine[MAX_CMD_LINE_LENGTH] = { 0 };
+ int nPos = 0;
+
+ for(int i = 4; i < argc; ++i)
+ {
+ int nCpyLen;
+ 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");
+#endif
+ return 0;
+ }
+ nPos += nCpyLen;
+ szCmdLine[nPos] = _T(' ');
+ ++nPos;
+ }
+ szCmdLine[nPos] = _T('\0');
+/*
for (int i = 4; i < argc; i++) {
if(sizeof(szCmdLine) > (_tcslen(szCmdLine) + _tcslen(argv[i])))
{
@@ -75,6 +95,7 @@ extern "C" int _tmain(int argc, TCHAR* argv[]) {
OutputDebugString("Command line is too long\n");
#endif
}
+*/
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi = { 0 };
@@ -173,5 +194,66 @@ extern "C" int _tmain(int argc, TCHAR* argv[]) {
return(dwExitCode);
}
+// Return number of bytes in target or -1 in case of error
+int copyTo(LPTSTR target, LPCTSTR source, int cpyLength, int availSpace)
+{
+ BOOL bSlash = FALSE;
+ int i = 0, j = 0;
+ int totCpyLength = cpyLength;
+ BOOL bQoutedTerm = FALSE;
+
+ if(availSpace < cpyLength)
+ return -1;
+// strncpy(target, source, cpyLength);
+// return cpyLength;
+
+ if((_T('\"') == *source) && (_T('\"') == *(source + cpyLength)))
+ bQoutedTerm = TRUE; // Already quoted
+ else
+ if(_tcschr(source, _T(' ')) == NULL)
+ bQoutedTerm = TRUE; // No reason to quotate term becase it doesn't have embedded spaces
+ else
+ {
+ *target = _T('\"');
+ ++j;
+ }
+
+
+ for(; i < cpyLength; ++i, ++j)
+ {
+ if(source[i] == _T('\\'))
+ bSlash = TRUE;
+ else
+ if((source[i] == _T('\"')) && (!bQoutedTerm || (i != 0) || i != (cpyLength)) )
+ {
+ if(!bSlash)
+ {
+ if(j == availSpace)
+ return -1;
+ target[j] = _T('\\');
+ ++j;
+ }
+ bSlash = FALSE;
+ }
+ else
+ bSlash = FALSE;
+
+ if(j == availSpace)
+ return -1;
+ target[j] = source[i];
+ }
+
+ if(!bQoutedTerm)
+ {
+ if(j == availSpace)
+ return -1;
+ target[j] = _T('\"');
+ ++j;
+ }
+
+ return j;
+}
+
+
//////////////////////////////// End of File //////////////////////////////////

Back to the top