diff --git a/network.c b/network.c index 4cc86bcf..4f3c37b3 100644 --- a/network.c +++ b/network.c @@ -555,7 +555,7 @@ int NETReadTillTerm(mkChannel *self, long timeout, char *pTerm, char *pBuffer, int iBufLen) { struct timeval start, now; - int bufPtr = 0, status, i, length; + int bufPtr = 0, status, i, length, matchIndex=1; char c; long dif; @@ -583,11 +583,29 @@ int NETReadTillTerm(mkChannel *self, long timeout, { return status; } - for(i = 0; i < length; i++) - { - if(c == pTerm[i]) + if ('&' != pTerm[0]) { + for(i = 0; i < length; i++) { - return bufPtr+1; + if(c == pTerm[i]) + { + return bufPtr+1; + } + } + } else { + if (matchIndex == 1 && c == pTerm[1]) { + matchIndex++; + } else { + if (c== pTerm[matchIndex] && matchIndex < length -1) { + matchIndex++; + } else { + if (c == pTerm[matchIndex] && matchIndex == length - 1) { + bufPtr = bufPtr - matchIndex + 1; + pBuffer[bufPtr] = '\0'; + return bufPtr; + } else { + matchIndex == 1; + } + } } } if (c == 0 && *pTerm != 0)