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>
This commit is contained in:
parent
c98b223567
commit
64f475aabd
@ -1797,6 +1797,23 @@ QMakeProject::doProjectInclude(QString file, uchar flags, QHash<QString, QString
|
|||||||
return IncludeSuccess;
|
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
|
QStringList
|
||||||
QMakeProject::doProjectExpand(QString func, const QString ¶ms,
|
QMakeProject::doProjectExpand(QString func, const QString ¶ms,
|
||||||
QHash<QString, QStringList> &place)
|
QHash<QString, QStringList> &place)
|
||||||
@ -1940,19 +1957,33 @@ QMakeProject::doProjectExpand(QString func, QList<QStringList> args_list,
|
|||||||
} else {
|
} else {
|
||||||
QString file = Option::normalizePath(args[0]);
|
QString file = Option::normalizePath(args[0]);
|
||||||
|
|
||||||
|
bool blob = false;
|
||||||
|
bool lines = false;
|
||||||
bool singleLine = true;
|
bool singleLine = true;
|
||||||
if(args.count() > 1)
|
if (args.count() > 1) {
|
||||||
singleLine = (args[1].toLower() == "true");
|
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);
|
QFile qfile(file);
|
||||||
if(qfile.open(QIODevice::ReadOnly)) {
|
if(qfile.open(QIODevice::ReadOnly)) {
|
||||||
QTextStream stream(&qfile);
|
QTextStream stream(&qfile);
|
||||||
|
if (blob) {
|
||||||
|
ret += stream.readAll();
|
||||||
|
} else {
|
||||||
while (!stream.atEnd()) {
|
while (!stream.atEnd()) {
|
||||||
|
if (lines) {
|
||||||
|
ret += stream.readLine();
|
||||||
|
} else {
|
||||||
ret += split_value_list(stream.readLine().trimmed());
|
ret += split_value_list(stream.readLine().trimmed());
|
||||||
if (!singleLine)
|
if (!singleLine)
|
||||||
ret += "\n";
|
ret += "\n";
|
||||||
}
|
}
|
||||||
qfile.close();
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break; }
|
break; }
|
||||||
@ -2113,26 +2144,33 @@ QMakeProject::doProjectExpand(QString func, QList<QStringList> args_list,
|
|||||||
fprintf(stderr, "%s:%d system(execut) requires one argument.\n",
|
fprintf(stderr, "%s:%d system(execut) requires one argument.\n",
|
||||||
parser.file.toLatin1().constData(), parser.line_no);
|
parser.file.toLatin1().constData(), parser.line_no);
|
||||||
} else {
|
} else {
|
||||||
char buff[256];
|
bool blob = false;
|
||||||
|
bool lines = false;
|
||||||
bool singleLine = true;
|
bool singleLine = true;
|
||||||
if(args.count() > 1)
|
if (args.count() > 1) {
|
||||||
singleLine = (args[1].toLower() == "true");
|
if (!args.at(1).compare(QLatin1String("false"), Qt::CaseInsensitive))
|
||||||
QString output;
|
singleLine = false;
|
||||||
FILE *proc = QT_POPEN(args[0].toLatin1().constData(), "r");
|
else if (!args.at(1).compare(QLatin1String("blob"), Qt::CaseInsensitive))
|
||||||
while(proc && !feof(proc)) {
|
blob = true;
|
||||||
int read_in = int(fread(buff, 1, 255, proc));
|
else if (!args.at(1).compare(QLatin1String("lines"), Qt::CaseInsensitive))
|
||||||
if(!read_in)
|
lines = true;
|
||||||
break;
|
|
||||||
for(int i = 0; i < read_in; i++) {
|
|
||||||
if((singleLine && buff[i] == '\n') || buff[i] == '\t')
|
|
||||||
buff[i] = ' ';
|
|
||||||
}
|
|
||||||
buff[read_in] = '\0';
|
|
||||||
output += buff;
|
|
||||||
}
|
}
|
||||||
|
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);
|
ret += split_value_list(output);
|
||||||
if(proc)
|
}
|
||||||
QT_PCLOSE(proc);
|
}
|
||||||
}
|
}
|
||||||
break; }
|
break; }
|
||||||
case E_UNIQUE: {
|
case E_UNIQUE: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user