/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
# ifdef MOZILLA_INTERNAL_API # include "nsString.h" # endif // MOZILLA_INTERNAL_API
namespace mozilla {
// Out param `aWideCmdLine` must be free()d by the caller. inlineint assembleCmdLine(constchar* const* aArgv, wchar_t** aWideCmdLine,
UINT aCodePage) { constchar* const* arg; char* p; constchar* q; char* cmdLine; int cmdLineSize; int numBackslashes; int i; int argNeedQuotes;
/* *Findouthowlargethecommandlinebuffershouldbe.
*/
cmdLineSize = 0; for (arg = aArgv; *arg; ++arg) { /* *\and"needtobeescapedbya\.Intheworstcase, *everycharacterisa\or",sothestringoflength *maydouble.Ifwequoteanargument,thatneedstwo". *Finally,weneedaspacebetweenarguments,and *anullbyteattheendofcommandline.
*/
cmdLineSize += 2 * strlen(*arg) /* \ and " need to be escaped */
+ 2/* we quote every argument */
+ 1; /* space in between, or final null */
}
p = cmdLine = (char*)malloc(cmdLineSize * sizeof(char)); if (!p) { return -1;
}
for (arg = aArgv; *arg; ++arg) { /* Add a space to separates the arguments */ if (arg != aArgv) {
*p++ = ' ';
}
q = *arg;
numBackslashes = 0;
argNeedQuotes = 0;
if (argNeedQuotes) {
*p++ = '"';
} while (*q) { if (*q == '\\') {
numBackslashes++;
q++;
} elseif (*q == '"') { if (numBackslashes) { /* *Doublethebackslashessincetheyarefollowed *byaquote
*/ for (i = 0; i < 2 * numBackslashes; i++) {
*p++ = '\\';
}
numBackslashes = 0;
} /* To escape the quote */
*p++ = '\\';
*p++ = *q++;
} else { if (numBackslashes) { /* *Backslashesarenotfollowedbyaquote,so *don'tneedtodoublethebackslashes.
*/ for (i = 0; i < numBackslashes; i++) {
*p++ = '\\';
}
numBackslashes = 0;
}
*p++ = *q++;
}
}
/* Now we are at the end of this argument */ if (numBackslashes) { /* *Doublethebackslashesifwehaveaquotestring *delimiterattheend.
*/ if (argNeedQuotes) {
numBackslashes *= 2;
} for (i = 0; i < numBackslashes; i++) {
*p++ = '\\';
}
} if (argNeedQuotes) {
*p++ = '"';
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.