From 57ad547df645bc1147e5ac16dcb575e875858ac4 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Tue, 24 Jul 2018 18:04:31 +0200 Subject: [PATCH] allow spaces around protocol parameters --- src/StreamCore.cc | 4 ++++ src/StreamEpics.cc | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/StreamCore.cc b/src/StreamCore.cc index b9a97b4..7573a71 100644 --- a/src/StreamCore.cc +++ b/src/StreamCore.cc @@ -193,7 +193,11 @@ parse(const char* filename, const char* _protocolname) { while (i >= 0) { + if (protocolname[i-1] == ' ') + protocolname.remove(--i, 1); // remove trailing space protocolname[i] = '\0'; // replace '(' and ',' with '\0' + if (protocolname[i+1] == ' ') + protocolname.remove(i+1, 1); // remove leading space i = protocolname.find(',', i+1); } // should have closing parentheses diff --git a/src/StreamEpics.cc b/src/StreamEpics.cc index 28676ab..812cff5 100644 --- a/src/StreamEpics.cc +++ b/src/StreamEpics.cc @@ -705,32 +705,53 @@ parseLink(const struct link *ioLink, char* filename, char* protocol, char* busname, int* addr, char* busparam) { // parse link parameters: filename protocol busname addr busparam - int n; + int n1, n2; if (ioLink->type != INST_IO) { error("%s: Wrong I/O link type %s\n", name(), pamaplinkType[ioLink->type].strvalue); return S_dev_badInitRet; } - int items = sscanf(ioLink->value.instio.string, "%s%s%s%n%i%n", - filename, protocol, busname, &n, addr, &n); - if (items <= 0) + if (0 >= sscanf(ioLink->value.instio.string, "%s%n", filename, &n1)) { error("%s: Empty I/O link. " "Forgot the leading '@' or confused INP with OUT or link is too long ?\n", name()); 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" - " expect \"@file protocol bus addr params\"\n" + error("%s: Missing protocol name\n" + " expect \"@file protocol[(args)] bus [addr] [params]\"\n" " in \"@%s\"\n", name(), ioLink->value.instio.string); return S_dev_badInitRet; } - while (isspace((unsigned char)ioLink->value.instio.string[n])) n++; - strcpy (busparam, ioLink->value.constantStr+n); + 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(), + ioLink->value.instio.string); + return S_dev_badInitRet; + } return OK; }