Attachment "tcl_bcl.txt" to
ticket [678400ffff]
added by
davygrvy
2003-10-03 05:35:52.
/*
*----------------------------------------------------------------------
*
* Exp_WinBuildCommandLine --
*
* The command line arguments are stored in linePtr separated
* by spaces, in a form that CreateProcess() understands. Special
* characters in individual arguments from argv[] must be quoted
* when being stored in linePtr.
*
* Results:
* None.
*
* Side effects:
* None.
*
* Comment: COPY OF NON_PUBLIC CORE FUNCTION WITH CHANGES!
*
*----------------------------------------------------------------------
*/
void
Exp_WinBuildCommandLine (
CONST char *executable, /* Full path of executable (including
* extension) UTF-8. Replacement for argv[0]. */
int objc, /* Number of arguments. */
struct Tcl_Obj * const objv[], /* Array of args in UTF-8. */
Tcl_DString *linePtr) /* Initialized Tcl_DString that receives the
* command line (TCHAR). */
{
const char *arg, *start, *special;
int quote, i;
Tcl_DString ds;
Tcl_DStringInit(&ds);
/*
* Prime the path.
*/
Tcl_DStringAppend(&ds, Tcl_DStringValue(linePtr), -1);
for (i = 0; i < objc; i++) {
if (i == 0) {
arg = executable;
} else {
arg = Tcl_GetString(objv[i]);
Tcl_DStringAppend(&ds, " ", 1);
}
quote = 0;
if (arg[0] == '\0') {
quote = 1;
} else {
for (start = arg; *start != '\0'; start++) {
if (isspace(*start)) { /* INTL: ISO space. */
quote = 1;
break;
}
}
}
if (quote) {
Tcl_DStringAppend(&ds, "\"", 1);
}
start = arg;
for (special = arg; ; ) {
if (*special == '"' && quote) {
Tcl_DStringAppend(&ds, start, (int) (special - start));
Tcl_DStringAppend(&ds, "\"\"", 2);
start = special + 1;
}
if (*special == '\0') {
break;
}
special++;
}
Tcl_DStringAppend(&ds, start, (int) (special - start));
if (quote) {
Tcl_DStringAppend(&ds, "\"", 1);
}
}
Tcl_DStringFree(linePtr);
Tcl_WinUtfToTChar(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds), linePtr);
Tcl_DStringFree(&ds);
}