allow spaces around protocol parameters

This commit is contained in:
2018-07-24 18:04:31 +02:00
parent ca2e6f4a8b
commit 57ad547df6
2 changed files with 34 additions and 9 deletions

View File

@ -193,7 +193,11 @@ parse(const char* filename, const char* _protocolname)
{ {
while (i >= 0) while (i >= 0)
{ {
if (protocolname[i-1] == ' ')
protocolname.remove(--i, 1); // remove trailing space
protocolname[i] = '\0'; // replace '(' and ',' with '\0' protocolname[i] = '\0'; // replace '(' and ',' with '\0'
if (protocolname[i+1] == ' ')
protocolname.remove(i+1, 1); // remove leading space
i = protocolname.find(',', i+1); i = protocolname.find(',', i+1);
} }
// should have closing parentheses // should have closing parentheses

View File

@ -705,32 +705,53 @@ parseLink(const struct link *ioLink, char* filename,
char* protocol, char* busname, int* addr, char* busparam) char* protocol, char* busname, int* addr, char* busparam)
{ {
// parse link parameters: filename protocol busname addr busparam // parse link parameters: filename protocol busname addr busparam
int n; int n1, n2;
if (ioLink->type != INST_IO) if (ioLink->type != INST_IO)
{ {
error("%s: Wrong I/O link type %s\n", name(), error("%s: Wrong I/O link type %s\n", name(),
pamaplinkType[ioLink->type].strvalue); pamaplinkType[ioLink->type].strvalue);
return S_dev_badInitRet; return S_dev_badInitRet;
} }
int items = sscanf(ioLink->value.instio.string, "%s%s%s%n%i%n", if (0 >= sscanf(ioLink->value.instio.string, "%s%n", filename, &n1))
filename, protocol, busname, &n, addr, &n);
if (items <= 0)
{ {
error("%s: Empty I/O link. " error("%s: Empty I/O link. "
"Forgot the leading '@' or confused INP with OUT or link is too long ?\n", "Forgot the leading '@' or confused INP with OUT or link is too long ?\n",
name()); name());
return S_dev_badInitRet; return S_dev_badInitRet;
} }
if (items < 3) if (0 >= sscanf(ioLink->value.instio.string+n1, " %[^ \t(] %n", protocol, &n2))
{ {
error("%s: Wrong I/O link format\n" error("%s: Missing protocol name\n"
" expect \"@file protocol bus addr params\"\n" " expect \"@file protocol[(args)] bus [addr] [params]\"\n"
" in \"@%s\"\n", name(),
ioLink->value.instio.string);
return S_dev_badInitRet;
}
n1+=n2;
if (ioLink->value.instio.string[n1] == '(')
{
strcat(protocol, "(");
n1++;
sscanf(ioLink->value.instio.string+n1, " %[^)] %n", protocol+strlen(protocol), &n2);
n1+=n2;
if (ioLink->value.instio.string[n1++] != ')')
{
error("%s: Missing ')' after protocol '%s': '%s'\n"
" expect \"@file protocol(args) bus [addr] [params]\"\n"
" in \"@%s\"\n", name(), protocol, ioLink->value.instio.string+n1-1,
ioLink->value.instio.string);
return S_dev_badInitRet;
}
strcat(protocol, ")");
}
if (0 >= sscanf(ioLink->value.instio.string+n1, "%s %i %99c", busname, addr, busparam))
{
error("%s: Missing bus name\n"
" expect \"@file protocol[(args)] bus [addr] [params]\"\n"
" in \"@%s\"\n", name(), " in \"@%s\"\n", name(),
ioLink->value.instio.string); ioLink->value.instio.string);
return S_dev_badInitRet; return S_dev_badInitRet;
} }
while (isspace((unsigned char)ioLink->value.instio.string[n])) n++;
strcpy (busparam, ioLink->value.constantStr+n);
return OK; return OK;
} }