if (strstr(lpCmdLine, "\\\""))
{
int i, n;
+ char* pLastEnd = NULL;
lpEscapedCmdLine = (char*) malloc(cmdLineLength + 1);
p = (char*) lpCmdLine;
+ pLastEnd = (char*) lpCmdLine;
pOutput = (char*) lpEscapedCmdLine;
- pBeg = strstr(lpCmdLine, "\\\"");
- pEnd = pBeg + 2;
-
- while (pBeg >= lpCmdLine)
+ while (p < &lpCmdLine[cmdLineLength])
{
- if (*pBeg != '\\')
+ pBeg = strstr(p, "\\\"");
+
+ if (!pBeg)
{
- pBeg++;
+ length = strlen(p);
+ CopyMemory(pOutput, p, length);
+ pOutput += length;
+ p += length;
+
break;
}
- pBeg--;
- }
+ pEnd = pBeg + 2;
- n = (pEnd - pBeg) - 1;
+ while (pBeg >= lpCmdLine)
+ {
+ if (*pBeg != '\\')
+ {
+ pBeg++;
+ break;
+ }
- length = (pBeg - lpCmdLine);
- CopyMemory(pOutput, p, length);
- pOutput += length;
- p += length;
+ pBeg--;
+ }
- for (i = 0; i < (n / 2); i++)
- {
- *pOutput = '\\';
- pOutput++;
- }
+ n = (pEnd - pBeg) - 1;
- p += n + 1;
+ length = (pBeg - pLastEnd);
+ CopyMemory(pOutput, p, length);
+ pOutput += length;
+ p += length;
- if ((n % 2) != 0)
- lpEscapedChars[pOutput - lpEscapedCmdLine] = '\\';
+ for (i = 0; i < (n / 2); i++)
+ {
+ *pOutput = '\\';
+ pOutput++;
+ }
- *pOutput = '"';
- pOutput++;
+ p += n + 1;
- length = cmdLineLength - (pEnd - lpCmdLine);
- CopyMemory(pOutput, p, length);
- pOutput += length;
- p += length;
+ if ((n % 2) != 0)
+ lpEscapedChars[pOutput - lpEscapedCmdLine] = '\\';
+
+ *pOutput = '"';
+ pOutput++;
+
+ pLastEnd = p;
+ }
*pOutput = '\0';
pOutput++;
lpCmdLine = (LPCSTR) lpEscapedCmdLine;
cmdLineLength = strlen(lpCmdLine);
-
- //printf("EscapedCmdLine: %s\n", lpEscapedCmdLine);
}
maxNumArgs = 1;
NULL
};
+const char* test_args_line_7 = "a\\\\\\\\\"b c\" d e f\\\\\\\\\"g h\" i j";
+
+const char* test_args_list_7[] =
+{
+ "a\\\\b c",
+ "d",
+ "e",
+ "f\\\\g h",
+ "i",
+ "j",
+ NULL
+};
+
static int test_command_line_parsing_case(const char* line, const char** list)
{
int i;
printf("argv[%d] = %s\n", i, pArgs[i]);
}
+ HeapFree(GetProcessHeap(), 0, pArgs);
+
return 0;
}
test_command_line_parsing_case(test_args_line_4, test_args_list_4);
test_command_line_parsing_case(test_args_line_5, test_args_list_5);
test_command_line_parsing_case(test_args_line_6, test_args_list_6);
+ test_command_line_parsing_case(test_args_line_7, test_args_list_7);
return 0;
}