Shell-like parsing of quotation marks in the content of the "Command" field of the "Record" dialog will give more options to the users. For example, now we can trace python -c 'print("hello world")' Suggested-by: Stephen Brennan <stephen@xxxxxxxxxx> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204679 Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> --- kernel-shark/src/KsCaptureDialog.cpp | 38 ++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/kernel-shark/src/KsCaptureDialog.cpp b/kernel-shark/src/KsCaptureDialog.cpp index dc1e9b2..b3393b6 100644 --- a/kernel-shark/src/KsCaptureDialog.cpp +++ b/kernel-shark/src/KsCaptureDialog.cpp @@ -157,7 +157,9 @@ KsCaptureControl::KsCaptureControl(QWidget *parent) */ QStringList KsCaptureControl::getArgs() { + QString::SplitBehavior opt = QString::SkipEmptyParts; QStringList argv; + QString cmdTmp; argv << "record"; @@ -170,7 +172,36 @@ QStringList KsCaptureControl::getArgs() argv << _eventsWidget.getCheckedEvents(true); argv << "-o" << outputFileName(); - argv << _commandLineEdit.text().split(" "); + + cmdTmp = _commandLineEdit.text(); + if (!cmdTmp.contains('\'') && !cmdTmp.contains('\"')) { + /* Split all command line arguments. */ + argv << cmdTmp.split(" ", opt); + } else { + int iOpenQuots, iCloseQuots, size = cmdTmp.size(); + int iSingleQuots = (cmdTmp.count('\'') == 2) ? cmdTmp.indexOf('\'') : size; + int iDoubleQuots = (cmdTmp.count('\"') == 2) ? cmdTmp.indexOf('\"') : size; + + if (iSingleQuots < iDoubleQuots) { + iOpenQuots = iSingleQuots; + iCloseQuots = cmdTmp.lastIndexOf('\'') + 1; + } else if (iDoubleQuots < iSingleQuots) { + iOpenQuots = iDoubleQuots; + iCloseQuots = cmdTmp.lastIndexOf('\"') + 1; + } else { + emit print("\nERROR: Unable to parse the command."); + return {}; + } + + /* Split the arguments. */ + argv << cmdTmp.left(iOpenQuots).split(" ", opt); + + /* Everything in between the quotation marks goes in one piece. */ + argv << cmdTmp.mid(iOpenQuots, iCloseQuots - iOpenQuots); + + /* Split the rest of the arguments. */ + argv << cmdTmp.right(size - iCloseQuots).split(" ", opt); + } return argv; } @@ -350,7 +381,10 @@ void KsCaptureControl::_browse() void KsCaptureControl::_apply() { - emit argsReady(getArgs().join(" ")); + QStringList argv = getArgs(); + + if (argv.count()) + emit argsReady(argv.join(" ")); } /** @brief Create KsCaptureMonitor widget. */ -- 2.20.1