Example #1
0
QString shellQuote(const QString &program, const QStringList &args, HostOsInfo::HostOs os)
{
    QString result = shellQuote(program, os);
    if (!args.empty())
        result += QLatin1Char(' ') + shellQuote(args, os);
    return result;
}
Example #2
0
QString shellQuote(const QStringList &args, HostOsInfo::HostOs os)
{
    QString result;
    if (!args.empty()) {
        result += shellQuote(args.at(0), os);
        for (int i = 1; i < args.size(); ++i)
            result += QLatin1Char(' ') + shellQuote(args.at(i), os);
    }
    return result;
}
Example #3
0
QString CommandLine::toCommandLine(HostOsInfo::HostOs os) const
{
    QString result = PathUtils::toNativeSeparators(m_program, os);
    if (!m_isRawProgram)
        result = shellQuote(result, os);
    for (const Argument &arg : m_arguments) {
        const QString value = arg.isFilePath
                ? PathUtils::toNativeSeparators(arg.value, os)
                : arg.value;
        result += QLatin1Char(' ') + (arg.shouldQuote ? shellQuote(value, os) : value);
    }
    return result;
}
Example #4
0
std::string shellQuote(const std::vector<std::string> &args, HostOsInfo::HostOs os)
{
    std::string result;
    if (!args.empty()) {
        auto it = args.cbegin();
        const auto end = args.cend();
        result += shellQuote(*it++, os);
        for (; it != end; ++it) {
            result.push_back(' ');
            result.append(shellQuote(*it, os));
        }
    }
    return result;
}
Example #5
0
void CommandLineFrontend::handleProcessResultReport(const qbs::ProcessResult &result)
{
    bool hasOutput = !result.stdOut().empty() || !result.stdErr().empty();
    if (!hasOutput && result.success())
        return;

    LogWriter w = result.success() ? qbsInfo() : qbsError();
    w << shellQuote(QDir::toNativeSeparators(result.executableFilePath()), result.arguments())
      << (hasOutput ? QStringLiteral("\n") : QString())
      << (result.stdOut().empty() ? QString() : result.stdOut().join(QLatin1Char('\n')));
    if (!result.stdErr().empty())
        w << result.stdErr().join(QLatin1Char('\n')) << MessageTag(QStringLiteral("stdErr"));
}
Example #6
0
QScriptValue Process::js_shellQuote(QScriptContext *context, QScriptEngine *engine)
{
    if (Q_UNLIKELY(context->argumentCount() < 2)) {
        return context->throwError(QScriptContext::SyntaxError,
                                   QLatin1String("shellQuote expects at least 2 arguments"));
    }
    const QString program = context->argument(0).toString();
    const QStringList args = context->argument(1).toVariant().toStringList();
    HostOsInfo::HostOs hostOs = HostOsInfo::hostOs();
    if (context->argumentCount() > 2) {
        hostOs = context->argument(2).toVariant().toStringList().contains(QLatin1String("windows"))
                ? HostOsInfo::HostOsWindows : HostOsInfo::HostOsOtherUnix;
    }
    return engine->toScriptValue(shellQuote(program, args, hostOs));
}
Example #7
0
char *
replaceString(const char *source, const char *from, const char *to)
{
	char		*to_quoted, *dest;
	size_t		 dest_size;
	const char	*p1, *p2;

	to_quoted = shellQuote(to);
	dest_size = strlen(source) + strlen(to_quoted) + 1;
	dest = xcalloc(dest_size, sizeof(char));

	p1 = source;
	p2 = strstr(p1, from);
	if (p2 != NULL) {
		strncat(dest, p1, (size_t)(p2 - p1));
		strlcat(dest, to_quoted, dest_size);
		p1 = p2 + strlen(from);
	}
	strlcat(dest, p1, dest_size);

	xfree(to_quoted);

	return (dest);
}
Example #8
0
std::string shellQuote(const std::string &arg, HostOsInfo::HostOs os)
{
    return shellQuote(QString::fromStdString(arg), os).toStdString();
}