summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2012-04-03 15:55:45 +0200
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2012-06-19 16:39:53 +0200
commit64f475aabd7cd57380dd1559c7d33fb3a5d6efa8 (patch)
treee9f9f3956a92e6e4aa3229d7611a2a28ab47f0e3
parentc98b2235677028c904e9247b9fc07558d42153b1 (diff)
add "blob" and "lines" modes to $$cat() and $$system()
this bypasses the otherwise done insane word splitting Change-Id: Ia9b8980bc0770de3999544a06d239f55fb34f801 Reviewed-by: Marius Storm-Olsen <marius.storm-olsen@nokia.com>
-rw-r--r--qmake/project.cpp88
1 files changed, 63 insertions, 25 deletions
diff --git a/qmake/project.cpp b/qmake/project.cpp
index f3a3856d82..000c6300b7 100644
--- a/qmake/project.cpp
+++ b/qmake/project.cpp
@@ -1797,6 +1797,23 @@ QMakeProject::doProjectInclude(QString file, uchar flags, QHash<QString, QString
return IncludeSuccess;
}
+static QByteArray
+getCommandOutput(const QString &args)
+{
+ QByteArray out;
+ if (FILE *proc = QT_POPEN(args.toLatin1().constData(), "r")) {
+ while (!feof(proc)) {
+ char buff[10 * 1024];
+ int read_in = int(fread(buff, 1, sizeof(buff), proc));
+ if (!read_in)
+ break;
+ out += QByteArray(buff, read_in);
+ }
+ QT_PCLOSE(proc);
+ }
+ return out;
+}
+
QStringList
QMakeProject::doProjectExpand(QString func, const QString &params,
QHash<QString, QStringList> &place)
@@ -1940,19 +1957,33 @@ QMakeProject::doProjectExpand(QString func, QList<QStringList> args_list,
} else {
QString file = Option::normalizePath(args[0]);
+ bool blob = false;
+ bool lines = false;
bool singleLine = true;
- if(args.count() > 1)
- singleLine = (args[1].toLower() == "true");
-
+ if (args.count() > 1) {
+ if (!args.at(1).compare(QLatin1String("false"), Qt::CaseInsensitive))
+ singleLine = false;
+ else if (!args.at(1).compare(QLatin1String("blob"), Qt::CaseInsensitive))
+ blob = true;
+ else if (!args.at(1).compare(QLatin1String("lines"), Qt::CaseInsensitive))
+ lines = true;
+ }
QFile qfile(file);
if(qfile.open(QIODevice::ReadOnly)) {
QTextStream stream(&qfile);
- while(!stream.atEnd()) {
- ret += split_value_list(stream.readLine().trimmed());
- if(!singleLine)
- ret += "\n";
+ if (blob) {
+ ret += stream.readAll();
+ } else {
+ while (!stream.atEnd()) {
+ if (lines) {
+ ret += stream.readLine();
+ } else {
+ ret += split_value_list(stream.readLine().trimmed());
+ if (!singleLine)
+ ret += "\n";
+ }
+ }
}
- qfile.close();
}
}
break; }
@@ -2113,26 +2144,33 @@ QMakeProject::doProjectExpand(QString func, QList<QStringList> args_list,
fprintf(stderr, "%s:%d system(execut) requires one argument.\n",
parser.file.toLatin1().constData(), parser.line_no);
} else {
- char buff[256];
+ bool blob = false;
+ bool lines = false;
bool singleLine = true;
- if(args.count() > 1)
- singleLine = (args[1].toLower() == "true");
- QString output;
- FILE *proc = QT_POPEN(args[0].toLatin1().constData(), "r");
- while(proc && !feof(proc)) {
- int read_in = int(fread(buff, 1, 255, proc));
- if(!read_in)
- break;
- for(int i = 0; i < read_in; i++) {
- if((singleLine && buff[i] == '\n') || buff[i] == '\t')
- buff[i] = ' ';
+ if (args.count() > 1) {
+ if (!args.at(1).compare(QLatin1String("false"), Qt::CaseInsensitive))
+ singleLine = false;
+ else if (!args.at(1).compare(QLatin1String("blob"), Qt::CaseInsensitive))
+ blob = true;
+ else if (!args.at(1).compare(QLatin1String("lines"), Qt::CaseInsensitive))
+ lines = true;
+ }
+ QByteArray bytes = getCommandOutput(args.at(0));
+ if (lines) {
+ QTextStream stream(bytes);
+ while (!stream.atEnd())
+ ret += stream.readLine();
+ } else {
+ QString output = QString::fromLocal8Bit(bytes);
+ if (blob) {
+ ret += output;
+ } else {
+ output.replace(QLatin1Char('\t'), QLatin1Char(' '));
+ if (singleLine)
+ output.replace(QLatin1Char('\n'), QLatin1Char(' '));
+ ret += split_value_list(output);
}
- buff[read_in] = '\0';
- output += buff;
}
- ret += split_value_list(output);
- if(proc)
- QT_PCLOSE(proc);
}
break; }
case E_UNIQUE: {