Skip to content

Use an iterative method for expanding commands now #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/vcontrold.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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];
Expand Down