summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2012-07-25 20:02:23 +0200
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2012-08-01 16:43:57 +0200
commit3d629b1a2bec3c336cbb59fe8ed8aaf35b9b27cc (patch)
tree18b71c718210e492df16968f231572ea1e77d03e /src
parent3522a3e05031cced53f27f0b3e46f10543e17adc (diff)
downloadqt-creator-3d629b1a2bec3c336cbb59fe8ed8aaf35b9b27cc.tar.gz
add $$system_quote() & $$shell_quote() functions
follow suit with qmake ... Change-Id: I3db37ba73cb709d8baf200600ae29241bc26bee5 Reviewed-by: Daniel Teske <daniel.teske@nokia.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/shared/proparser/ioutils.cpp61
-rw-r--r--src/shared/proparser/ioutils.h9
-rw-r--r--src/shared/proparser/qmakebuiltins.cpp23
3 files changed, 61 insertions, 32 deletions
diff --git a/src/shared/proparser/ioutils.cpp b/src/shared/proparser/ioutils.cpp
index b85ed95378..cd8923a32c 100644
--- a/src/shared/proparser/ioutils.cpp
+++ b/src/shared/proparser/ioutils.cpp
@@ -91,44 +91,53 @@ QString IoUtils::resolvePath(const QString &baseDir, const QString &fileName)
return QDir::cleanPath(baseDir + QLatin1Char('/') + fileName);
}
-#ifdef QT_BOOTSTRAPPED
-inline static bool isSpecialChar(ushort c)
+inline static
+bool hasSpecialChars(const QString &arg, const uchar (&iqm)[16])
+{
+ for (int x = arg.length() - 1; x >= 0; --x) {
+ ushort c = arg.unicode()[x].unicode();
+ if ((c < sizeof(iqm) * 8) && (iqm[c / 8] & (1 << (c & 7))))
+ return true;
+ }
+ return false;
+}
+
+QString IoUtils::shellQuoteUnix(const QString &arg)
{
// Chars that should be quoted (TM). This includes:
-#ifdef Q_OS_WIN
- // - control chars & space
- // - the shell meta chars "&()<>^|
- // - the potential separators ,;=
- static const uchar iqm[] = {
- 0xff, 0xff, 0xff, 0xff, 0x45, 0x13, 0x00, 0x78,
- 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x10
- };
-#else
static const uchar iqm[] = {
0xff, 0xff, 0xff, 0xff, 0xdf, 0x07, 0x00, 0xd8,
0x00, 0x00, 0x00, 0x38, 0x01, 0x00, 0x00, 0x78
}; // 0-32 \'"$`<>|;&(){}*?#!~[]
-#endif
- return (c < sizeof(iqm) * 8) && (iqm[c / 8] & (1 << (c & 7)));
-}
+ if (!arg.length())
+ return QString::fromLatin1("\"\"");
-inline static bool hasSpecialChars(const QString &arg)
-{
- for (int x = arg.length() - 1; x >= 0; --x)
- if (isSpecialChar(arg.unicode()[x].unicode()))
- return true;
- return false;
+ QString ret(arg);
+ if (hasSpecialChars(ret, iqm)) {
+ ret.replace(QLatin1Char('\''), QLatin1String("'\\''"));
+ ret.prepend(QLatin1Char('\''));
+ ret.append(QLatin1Char('\''));
+ }
+ return ret;
}
-QString IoUtils::shellQuote(const QString &arg)
+QString IoUtils::shellQuoteWin(const QString &arg)
{
+ // Chars that should be quoted (TM). This includes:
+ // - control chars & space
+ // - the shell meta chars "&()<>^|
+ // - the potential separators ,;=
+ static const uchar iqm[] = {
+ 0xff, 0xff, 0xff, 0xff, 0x45, 0x13, 0x00, 0x78,
+ 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x10
+ };
+
if (!arg.length())
return QString::fromLatin1("\"\"");
QString ret(arg);
- if (hasSpecialChars(ret)) {
-#ifdef Q_OS_WIN
+ if (hasSpecialChars(ret, iqm)) {
// Quotes are escaped and their preceding backslashes are doubled.
// It's impossible to escape anything inside a quoted string on cmd
// level, so the outer quoting must be "suspended".
@@ -141,14 +150,8 @@ QString IoUtils::shellQuote(const QString &arg)
--i;
ret.insert(i, QLatin1Char('"'));
ret.prepend(QLatin1Char('"'));
-#else // Q_OS_WIN
- ret.replace(QLatin1Char('\''), QLatin1String("'\\''"));
- ret.prepend(QLatin1Char('\''));
- ret.append(QLatin1Char('\''));
-#endif // Q_OS_WIN
}
return ret;
}
-#endif
QT_END_NAMESPACE
diff --git a/src/shared/proparser/ioutils.h b/src/shared/proparser/ioutils.h
index 0482f7628e..8f1fadb7d7 100644
--- a/src/shared/proparser/ioutils.h
+++ b/src/shared/proparser/ioutils.h
@@ -55,8 +55,13 @@ public:
static bool isAbsolutePath(const QString &fileName) { return !isRelativePath(fileName); }
static QStringRef fileName(const QString &fileName); // Requires normalized path
static QString resolvePath(const QString &baseDir, const QString &fileName);
-#ifdef QT_BOOTSTRAPPED
- static QString shellQuote(const QString &arg);
+ static QString shellQuoteUnix(const QString &arg);
+ static QString shellQuoteWin(const QString &arg);
+ static QString shellQuote(const QString &arg)
+#ifdef Q_OS_UNIX
+ { return shellQuoteUnix(arg); }
+#else
+ { return shellQuoteWin(arg); }
#endif
};
diff --git a/src/shared/proparser/qmakebuiltins.cpp b/src/shared/proparser/qmakebuiltins.cpp
index 1e26c90af8..83d3cf3604 100644
--- a/src/shared/proparser/qmakebuiltins.cpp
+++ b/src/shared/proparser/qmakebuiltins.cpp
@@ -78,7 +78,7 @@ enum ExpandFunc {
E_UPPER, E_LOWER, E_FILES, E_PROMPT, E_RE_ESCAPE, E_VAL_ESCAPE,
E_REPLACE, E_SORT_DEPENDS, E_RESOLVE_DEPENDS, E_ENUMERATE_VARS,
E_SHADOWED, E_ABSOLUTE_PATH, E_RELATIVE_PATH, E_CLEAN_PATH,
- E_SYSTEM_PATH, E_SHELL_PATH
+ E_SYSTEM_PATH, E_SHELL_PATH, E_SYSTEM_QUOTE, E_SHELL_QUOTE
};
enum TestFunc {
@@ -131,6 +131,8 @@ void QMakeEvaluator::initFunctionStatics()
{ "clean_path", E_CLEAN_PATH },
{ "system_path", E_SYSTEM_PATH },
{ "shell_path", E_SHELL_PATH },
+ { "system_quote", E_SYSTEM_QUOTE },
+ { "shell_quote", E_SHELL_QUOTE },
};
for (unsigned i = 0; i < sizeof(expandInits)/sizeof(expandInits[0]); ++i)
statics.expands.insert(ProString(expandInits[i].name), expandInits[i].func);
@@ -890,6 +892,25 @@ ProStringList QMakeEvaluator::evaluateExpandFunction(
ret << ProString(rstr, NoHash).setSource(args.at(0));
}
break;
+ case E_SYSTEM_QUOTE:
+ if (args.count() != 1)
+ evalError(fL1S("system_quote(arg) requires one argument."));
+ else
+ ret << ProString(IoUtils::shellQuote(args.at(0).toQString(m_tmp1)),
+ NoHash).setSource(args.at(0));
+ break;
+ case E_SHELL_QUOTE:
+ if (args.count() != 1) {
+ evalError(fL1S("shell_quote(arg) requires one argument."));
+ } else {
+ QString rstr = args.at(0).toQString(m_tmp1);
+ if (m_option->dir_sep.at(0) != QLatin1Char('/'))
+ rstr = IoUtils::shellQuoteWin(rstr);
+ else
+ rstr = IoUtils::shellQuoteUnix(rstr);
+ ret << ProString(rstr, NoHash).setSource(args.at(0));
+ }
+ break;
case E_INVALID:
evalError(fL1S("'%1' is not a recognized replace function.")
.arg(func.toQString(m_tmp1)));