allow spaces in arguments of SCPI commands

This commit is contained in:
Jan Käberich 2025-12-02 10:33:04 +01:00
parent 72d547eb08
commit 9923038d6c

View file

@ -548,16 +548,43 @@ QString SCPINode::parse(QString cmd, SCPINode* &lastNode)
return SCPI::getResultName(SCPI::Result::Error);
} else {
// no more levels, search for command
auto params = cmd.split(" ");
auto cmd = params.front();
QStringList params;
params.append("");
bool inQuotes = false;
for(unsigned int i=0;i<cmd.length();i++) {
if(cmd[i] == '\\') {
// escape character, ignore
continue;
}
// check if we are starting/stopping quotes
if(cmd[i] == '"' || cmd[i] == '\'') {
// check whether quotes are escaped
if(i == 0 || cmd[i-1] != '\\') {
inQuotes = !inQuotes;
continue;
}
}
if(inQuotes) {
params.back().append(cmd[i]);
} else {
// not in quotes, handle splitting by space
if(cmd[i] == " ") {
if(params.back().length() > 0)
params.append("");
} else {
params.back().append(cmd[i]);
}
}
}
// remove command name
params.pop_front();
bool isQuery = false;
if (cmd[cmd.size()-1]=='?') {
if (cmdName[cmdName.size()-1]=='?') {
isQuery = true;
cmd.chop(1);
cmdName.chop(1);
}
for(auto c : commands) {
if(SCPI::match(c->leafName(), cmd.toUpper())) {
if(SCPI::match(c->leafName(), cmdName.toUpper())) {
// save current node in case of non-root for the next command
lastNode = this;
if(c->convertToUppercase()) {