forked from qt-creator/qt-creator
Fix various warnings
Change-Id: Iea85f4b890ce7700e8b3632de4656cf848729a36 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -186,63 +186,6 @@ const CommandLine &TerminalProcess::commandLine() const
|
||||
return d->m_commandLine;
|
||||
}
|
||||
|
||||
static QString quoteWinCommand(const QString &program)
|
||||
{
|
||||
const QChar doubleQuote = QLatin1Char('"');
|
||||
|
||||
// add the program as the first arg ... it works better
|
||||
QString programName = program;
|
||||
programName.replace(QLatin1Char('/'), QLatin1Char('\\'));
|
||||
if (!programName.startsWith(doubleQuote) && !programName.endsWith(doubleQuote)
|
||||
&& programName.contains(QLatin1Char(' '))) {
|
||||
programName.prepend(doubleQuote);
|
||||
programName.append(doubleQuote);
|
||||
}
|
||||
return programName;
|
||||
}
|
||||
|
||||
static QString quoteWinArgument(const QString &arg)
|
||||
{
|
||||
if (arg.isEmpty())
|
||||
return QString::fromLatin1("\"\"");
|
||||
|
||||
QString ret(arg);
|
||||
// Quotes are escaped and their preceding backslashes are doubled.
|
||||
ret.replace(QRegularExpression("(\\\\*)\""), "\\1\\1\\\"");
|
||||
if (ret.contains(QRegularExpression("\\s"))) {
|
||||
// The argument must not end with a \ since this would be interpreted
|
||||
// as escaping the quote -- rather put the \ behind the quote: e.g.
|
||||
// rather use "foo"\ than "foo\"
|
||||
int i = ret.length();
|
||||
while (i > 0 && ret.at(i - 1) == QLatin1Char('\\'))
|
||||
--i;
|
||||
ret.insert(i, QLatin1Char('"'));
|
||||
ret.prepend(QLatin1Char('"'));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Quote a Windows command line correctly for the "CreateProcess" API
|
||||
static QString createWinCommandline(const QString &program, const QStringList &args)
|
||||
{
|
||||
QString programName = quoteWinCommand(program);
|
||||
for (const QString &arg : args) {
|
||||
programName += QLatin1Char(' ');
|
||||
programName += quoteWinArgument(arg);
|
||||
}
|
||||
return programName;
|
||||
}
|
||||
|
||||
static QString createWinCommandline(const QString &program, const QString &args)
|
||||
{
|
||||
QString programName = quoteWinCommand(program);
|
||||
if (!args.isEmpty()) {
|
||||
programName += QLatin1Char(' ');
|
||||
programName += args;
|
||||
}
|
||||
return programName;
|
||||
}
|
||||
|
||||
void TerminalProcess::setAbortOnMetaChars(bool abort)
|
||||
{
|
||||
d->m_abortOnMetaChars = abort;
|
||||
@@ -334,15 +277,66 @@ void TerminalProcess::start()
|
||||
if (!workDir.isEmpty() && !workDir.endsWith(QLatin1Char('\\')))
|
||||
workDir.append(QLatin1Char('\\'));
|
||||
|
||||
// Quote a Windows command line correctly for the "CreateProcess" API
|
||||
static const auto quoteWinCommand = [](const QString &program) {
|
||||
const QChar doubleQuote = QLatin1Char('"');
|
||||
|
||||
// add the program as the first arg ... it works better
|
||||
QString programName = program;
|
||||
programName.replace(QLatin1Char('/'), QLatin1Char('\\'));
|
||||
if (!programName.startsWith(doubleQuote) && !programName.endsWith(doubleQuote)
|
||||
&& programName.contains(QLatin1Char(' '))) {
|
||||
programName.prepend(doubleQuote);
|
||||
programName.append(doubleQuote);
|
||||
}
|
||||
return programName;
|
||||
};
|
||||
static const auto quoteWinArgument = [](const QString &arg) {
|
||||
if (arg.isEmpty())
|
||||
return QString::fromLatin1("\"\"");
|
||||
|
||||
QString ret(arg);
|
||||
// Quotes are escaped and their preceding backslashes are doubled.
|
||||
ret.replace(QRegularExpression("(\\\\*)\""), "\\1\\1\\\"");
|
||||
if (ret.contains(QRegularExpression("\\s"))) {
|
||||
// The argument must not end with a \ since this would be interpreted
|
||||
// as escaping the quote -- rather put the \ behind the quote: e.g.
|
||||
// rather use "foo"\ than "foo\"
|
||||
int i = ret.length();
|
||||
while (i > 0 && ret.at(i - 1) == QLatin1Char('\\'))
|
||||
--i;
|
||||
ret.insert(i, QLatin1Char('"'));
|
||||
ret.prepend(QLatin1Char('"'));
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
static const auto createWinCommandlineMultiArgs = [](const QString &program, const QStringList &args) {
|
||||
QString programName = quoteWinCommand(program);
|
||||
for (const QString &arg : args) {
|
||||
programName += QLatin1Char(' ');
|
||||
programName += quoteWinArgument(arg);
|
||||
}
|
||||
return programName;
|
||||
};
|
||||
static const auto createWinCommandlineSingleArg = [](const QString &program, const QString &args)
|
||||
{
|
||||
QString programName = quoteWinCommand(program);
|
||||
if (!args.isEmpty()) {
|
||||
programName += QLatin1Char(' ');
|
||||
programName += args;
|
||||
}
|
||||
return programName;
|
||||
};
|
||||
|
||||
QStringList stubArgs;
|
||||
stubArgs << modeOption(d->m_terminalMode)
|
||||
<< d->m_stubServer.fullServerName()
|
||||
<< workDir
|
||||
<< (d->m_tempFile ? d->m_tempFile->fileName() : QString())
|
||||
<< createWinCommandline(pcmd, pargs)
|
||||
<< createWinCommandlineSingleArg(pcmd, pargs)
|
||||
<< msgPromptToClose();
|
||||
|
||||
const QString cmdLine = createWinCommandline(
|
||||
const QString cmdLine = createWinCommandlineMultiArgs(
|
||||
QCoreApplication::applicationDirPath() + QLatin1String("/qtcreator_process_stub.exe"), stubArgs);
|
||||
|
||||
bool success = CreateProcessW(0, (WCHAR*)cmdLine.utf16(),
|
||||
|
||||
Reference in New Issue
Block a user