allow commas inside matching pairs of parentheses in protocol parameters

This commit is contained in:
2020-03-02 09:10:28 +01:00
parent f072c217f3
commit 967539c4e1
4 changed files with 105 additions and 14 deletions

View File

@ -189,14 +189,26 @@ parse(const char* filename, const char* _protocolname)
ssize_t i = protocolname.find('(');
if (i >= 0)
{
while (i >= 0)
while (i < (ssize_t)protocolname.length())
{
if (protocolname[i-1] == ' ')
protocolname.remove(--i, 1); // remove trailing space
protocolname[i] = '\0'; // replace '(' and ',' with '\0'
protocolname[i] = '\0'; // replace initial '(' and separating ',' with '\0'
if (protocolname[i+1] == ' ')
protocolname.remove(i+1, 1); // remove leading space
i = protocolname.find(',', i+1);
int brackets = 0;
do {
i++;
i += strcspn(protocolname(i), ",()\\");
char c = protocolname[i];
if (c == '(') brackets++;
else if (c == ')') brackets--;
else if (c == ',' && brackets <= 0) break;
else if (c == '\\') {
if (protocolname[i+1] == '\\') i++; // keep '\\'
else protocolname.remove(i, 1); // else skip over next char
}
} while (i < (ssize_t)protocolname.length());
}
// should have closing parentheses
if (protocolname[-1] != ')')
@ -206,9 +218,8 @@ parse(const char* filename, const char* _protocolname)
}
protocolname.truncate(-1); // remove ')'
if (protocolname[-1] == ' ')
{
protocolname.truncate(-1); // remove trailing space
}
debug("StreamCore::parse \"%s\" -> \"%s\"\n", _protocolname, protocolname.expand()());
}
StreamProtocolParser::Protocol* protocol;
protocol = StreamProtocolParser::getProtocol(filename, protocolname);

View File

@ -764,7 +764,7 @@ initRecord(char* linkstring /* modifiable copy */)
}
// attach to bus interface
debug("Stream::initRecord %s: attachBus(%s, %ld, \"%s\")\n",
debug("Stream::initRecord %s: attachBus(\"%s\", %ld, \"%s\")\n",
name(), busname, addr, busparam);
if (!attachBus(busname, addr, busparam))
{
@ -774,7 +774,7 @@ initRecord(char* linkstring /* modifiable copy */)
}
// parse protocol file
debug("Stream::initRecord %s: parse(%s, %s)\n",
debug("Stream::initRecord %s: parse(\"%s\", \"%s\")\n",
name(), filename, protocol);
if (!parse(filename, protocol))
{