diff --git a/src/parser.c b/src/parser.c index 4525eadc..cdce301d 100644 --- a/src/parser.c +++ b/src/parser.c @@ -436,14 +436,6 @@ void removeCompileList(compilePtr ptr) int expand(commandPtr cPtr, protocolPtr pPtr) { - // Recursion - if (! cPtr) { - return 0; - } - if (cPtr->next) { - expand(cPtr->next, pPtr); - } - // If no address has been set, we do nothing if (! cPtr->addr) { return 0; @@ -575,16 +567,17 @@ int expand(commandPtr cPtr, protocolPtr pPtr) return 1; } -compilePtr buildByteCode(commandPtr cPtr, unitPtr uPtr) +void expandAll(commandPtr cPtr, protocolPtr pPtr) { - // Recursion - if (!cPtr) { - return 0; - } - if (cPtr->next) { - buildByteCode(cPtr->next, uPtr); + // Start iteration + commandPtr curPtr = cPtr; + for (; curPtr; curPtr = curPtr->next) { + expand(curPtr, pPtr); } +} +compilePtr buildByteCode(commandPtr cPtr, unitPtr uPtr) +{ // If no address has been given, we do nothing if (! cPtr->addr) { return 0; @@ -650,16 +643,31 @@ compilePtr buildByteCode(commandPtr cPtr, unitPtr uPtr) return cmpStartPtr; } +void buildByteCodeAll(commandPtr cPtr, unitPtr uPtr) +{ + // Start iteration + commandPtr curPtr = cPtr; + for (; curPtr; curPtr = curPtr->next) { + buildByteCode(curPtr, uPtr); + } +} + void compileCommand(devicePtr dPtr, unitPtr uPtr) +{ + logIT(LOG_INFO, "Expanding command for device %s", dPtr->id); + expandAll(dPtr->cmdPtr, dPtr->protoPtr); + buildByteCodeAll(dPtr->cmdPtr, uPtr); +} + +void compileCommandAll(devicePtr dPtr, unitPtr uPtr) { if (! dPtr) { return; } - if (dPtr->next) { - compileCommand(dPtr->next, uPtr); - } - logIT(LOG_INFO, "Expanding command for device %s", dPtr->id); - expand(dPtr->cmdPtr, dPtr->protoPtr); - buildByteCode(dPtr->cmdPtr, uPtr); + // Start iteration + devicePtr curPtr = dPtr; + for (; curPtr; curPtr = curPtr->next) { + compileCommand(curPtr, uPtr); + } } diff --git a/src/parser.h b/src/parser.h index e5dc2fa6..1d8a56c9 100644 --- a/src/parser.h +++ b/src/parser.h @@ -11,7 +11,7 @@ void removeCompileList(compilePtr ptr); int execByteCode(compilePtr cmpPtr, int fd, char *recvBuf, short recvLen, char *sendBuf, short sendLen, short supressUnit, char bitpos, int retry, char *pRecvPtr, unsigned short recvTimeout); -void compileCommand(devicePtr dPtr, unitPtr uPtr); +void compileCommandAll(devicePtr dPtr, unitPtr uPtr); // Token Definition #define WAIT 1 diff --git a/src/vcontrold.c b/src/vcontrold.c index 9f8bd959..6dc48601 100644 --- a/src/vcontrold.c +++ b/src/vcontrold.c @@ -86,7 +86,7 @@ void usage() int reloadConfig() { if (parseXMLFile(xmlfile)) { - compileCommand(devPtr, uPtr); + compileCommandAll(devPtr, uPtr); logIT(LOG_NOTICE, "XML file %s reloaded", xmlfile); return 1; } else { @@ -803,7 +803,7 @@ int main(int argc, char *argv[]) } // The macros are replaced and the strings to send are converted to bytecode - compileCommand(devPtr, uPtr); + compileCommandAll(devPtr, uPtr); int fd = 0; char result[MAXBUF];