aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/process_ctrlc_stub.cpp
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@nokia.com>2011-08-15 12:39:59 +0200
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2011-08-15 15:46:44 +0200
commit3a32f0bbac9c4fd87d069af7c939f352a15e94a2 (patch)
tree4d347910d0c314ae653b8ff7a9dec3e2ea85e161 /src/libs/utils/process_ctrlc_stub.cpp
parentd636140ea4ef39b7e704cb9d787842c157a7f7df (diff)
process_ctrlc_stub: more intelligent removal of first argument
Change-Id: I693f5974a1c3f90a5d2f93d048c9a96504c44939 Reviewed-on: http://codereview.qt.nokia.com/2950 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
Diffstat (limited to 'src/libs/utils/process_ctrlc_stub.cpp')
-rw-r--r--src/libs/utils/process_ctrlc_stub.cpp34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/libs/utils/process_ctrlc_stub.cpp b/src/libs/utils/process_ctrlc_stub.cpp
index 8a768cf767..0fd2a0818c 100644
--- a/src/libs/utils/process_ctrlc_stub.cpp
+++ b/src/libs/utils/process_ctrlc_stub.cpp
@@ -57,7 +57,7 @@ HWND hwndMain = 0;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
BOOL WINAPI ctrlHandler(DWORD dwCtrlType);
-bool findFirst(const wchar_t *str, const size_t strLength, const size_t startPos, const wchar_t *chars, size_t &pos);
+bool isSpaceOrTab(const wchar_t c);
bool startProcess(wchar_t pCommandLine[]);
int main(int argc, char **)
@@ -85,17 +85,21 @@ int main(int argc, char **)
return FALSE;
// Get the command line and remove the call to this executable.
- // Note: We trust Qt Creator at this point to quote the call to this tool in a sensible way.
- // Strange things like C:\Q"t Crea"tor\bin\qtcreator_ctrlc_stub.exe are not supported.
wchar_t *strCommandLine = _wcsdup(GetCommandLine());
const size_t strCommandLineLength = wcslen(strCommandLine);
size_t pos = 1;
- if (strCommandLine[0] == L'"')
- if (!findFirst(strCommandLine, strCommandLineLength, pos, L"\"", pos))
- return 1;
- if (!findFirst(strCommandLine, strCommandLineLength, pos, L" \t", pos))
- return 1;
- bool bSuccess = startProcess(strCommandLine + pos + 1);
+ bool quoted = false;
+ while (pos < strCommandLineLength) {
+ if (strCommandLine[pos] == L'"') {
+ quoted = !quoted;
+ } else if (!quoted && isSpaceOrTab(strCommandLine[pos])) {
+ while (isSpaceOrTab(strCommandLine[++pos]));
+ break;
+ }
+ ++pos;
+ }
+
+ bool bSuccess = startProcess(strCommandLine + pos);
free(strCommandLine);
if (!bSuccess)
@@ -130,17 +134,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return 0;
}
-bool findFirst(const wchar_t *str, const size_t strLength, const size_t startPos, const wchar_t *chars, size_t &pos)
+bool isSpaceOrTab(const wchar_t c)
{
- for (size_t i=startPos; i < strLength; ++i) {
- for (size_t j=0; chars[j]; ++j) {
- if (str[i] == chars[j]) {
- pos = i;
- return true;
- }
- }
- }
- return false;
+ return c == L' ' || c == L'\t';
}
BOOL WINAPI ctrlHandler(DWORD /*dwCtrlType*/)