From 3327c8d8bf7beae1a315521f89f424453b1484be Mon Sep 17 00:00:00 2001 From: zolliker Date: Wed, 30 Mar 2005 14:27:44 +0000 Subject: [PATCH] - inserted command echo into exe manager --- exe.w | 4 +++- exebuf.c | 37 ++++++++++++++++++++++++++++++++++--- exebuf.h | 6 +++--- exebuf.i | 4 ++-- exeman.c | 12 ++++++++++-- exeman.i | 5 +++-- 6 files changed, 55 insertions(+), 13 deletions(-) diff --git a/exe.w b/exe.w index cf4dabbf..3afd21ba 100644 --- a/exe.w +++ b/exe.w @@ -88,7 +88,7 @@ The interface to this buffer system comprises: * @@return 1 on success, 0 on error */ int exeBufProcess(pExeBuf self, SicsInterp *pSics, - SConnection *pCon, pICallBack pCall); + SConnection *pCon, pICallBack pCall, int echo); /** * retrieves the executing range * @@param self The exe buffer to query @@ -145,6 +145,7 @@ typedef struct __EXEMAN{ int exeStackPtr; int runList; pExeBuf uploadBuffer; + int echo; }ExeMan, *pExeMan; @} The fields: @@ -159,6 +160,7 @@ about the operation of this module. \item[uploadBuffer] A exe buffer to which data is uploaded. Also serves as a flag if uploading is possible. In this case uploadBuffer must be not NULL. +\item[echo] Echo flag. When set, SICS commands are echoed. \end{itemize} The public interface to the exe manager are the interpreter interface diff --git a/exebuf.c b/exebuf.c index 1246e144..b693d36a 100644 --- a/exebuf.c +++ b/exebuf.c @@ -147,11 +147,17 @@ static pDynString findBlockEnd(pExeBuf self){ } /*---------------------------------------------------------------------*/ int exeBufProcess(pExeBuf self, SicsInterp *pSics, - SConnection *pCon, pICallBack pCall){ + SConnection *pCon, pICallBack pCall, int echo){ pDynString command = NULL; Tcl_Interp *pTcl = NULL; int status; - + + static int weWantLogging = 1; + char *cmd; + char cmdName[128]; + char *ende; + int l; + assert(self); assert(pSics); @@ -162,9 +168,34 @@ int exeBufProcess(pExeBuf self, SicsInterp *pSics, InvokeCallBack(pCall,BATCHSTART,self->name); + if (echo) { + SCsetMacro(pCon,0); + } while((command = findBlockEnd(self)) != NULL){ InvokeCallBack(pCall,BATCHAREA,NULL); - status = Tcl_Eval(pTcl,GetCharArray(command)); + cmd = GetCharArray(command); + + if (echo) { + /* find first word */ + while (*cmd == ' ') { + cmd++; + } + ende = cmd; + while (*ende > ' ') { + ende++; + } + l = ende - cmd; + if (l < sizeof cmdName) { + strncpy(cmdName, cmd, l); + cmdName[l] = '\0'; + if (FindCommand(pSics, cmdName) != NULL) { + /* print only SICS commands */ + SCPrintf(pCon, eValue, "%s:%d>> %s",self->name,self->lineno,cmd); + } + } + } + + status = Tcl_Eval(pTcl,cmd); if(status != TCL_OK){ if(pCon->sicsError == 0){ /* diff --git a/exebuf.h b/exebuf.h index 3a432514..9e1792f2 100644 --- a/exebuf.h +++ b/exebuf.h @@ -1,5 +1,5 @@ -#line 205 "exe.w" +#line 207 "exe.w" /** * Buffer handling code for the Exe Buffer batch file processing @@ -62,7 +62,7 @@ * @return 1 on success, 0 on error */ int exeBufProcess(pExeBuf self, SicsInterp *pSics, - SConnection *pCon, pICallBack pCall); + SConnection *pCon, pICallBack pCall, int echo); /** * retrieves the executing range * @param self The exe buffer to query @@ -89,7 +89,7 @@ */ char *exeBufName(pExeBuf self); -#line 218 "exe.w" +#line 220 "exe.w" #endif diff --git a/exebuf.i b/exebuf.i index 11634dbf..3d4638ba 100644 --- a/exebuf.i +++ b/exebuf.i @@ -1,5 +1,5 @@ -#line 196 "exe.w" +#line 198 "exe.w" /*-------------------------------------------------------------------- Internal header file for the exe buffer module. Do not edit. This is @@ -16,6 +16,6 @@ typedef struct __EXEBUF{ int lineno; } ExeBuf; -#line 201 "exe.w" +#line 203 "exe.w" diff --git a/exeman.c b/exeman.c index 5df8f048..c768c169 100644 --- a/exeman.c +++ b/exeman.c @@ -208,7 +208,7 @@ static int runBatchBuffer(pExeMan self, SConnection *pCon, self->exeStackPtr++; DynarPut(self->exeStack,self->exeStackPtr,buffer); - status = exeBufProcess(buffer,pSics,pCon,self->pCall); + status = exeBufProcess(buffer,pSics,pCon,self->pCall,self->echo); self->exeStackPtr--; return status; } @@ -702,7 +702,7 @@ static int execQueue(pExeMan self, SConnection *pCon, SicsInterp *pSics){ return 0; } DynarPut(self->exeStack,self->exeStackPtr,buf); - status = exeBufProcess(buf,pSics,pCon,self->pCall); + status = exeBufProcess(buf,pSics,pCon,self->pCall,self->echo); self->exeStackPtr--; if(SCGetInterrupt(pCon) >= eAbortBatch){ SCWrite(pCon,"ERROR: queue processing interrupted",eError); @@ -781,6 +781,14 @@ int ExeManagerWrapper(SConnection *pCon, SicsInterp *pSics, void *pData, SCSendOK(pCon); } return status; + }else if(strcmp(argv[1],"echo") == 0){ + if (argc > 2) { + self->echo = atoi(argv[2]) != 0; + SCSendOK(pCon); + } else { + SCPrintf(pCon, eValue, "echo = %d", self->echo); + } + return 1; } else { status = runBatchBuffer(self,pCon,pSics,pBufferName); if(self->exeStackPtr < 0){ diff --git a/exeman.i b/exeman.i index 70bb2125..1918f5a1 100644 --- a/exeman.i +++ b/exeman.i @@ -1,5 +1,5 @@ -#line 174 "exe.w" +#line 176 "exe.w" /*------------------------------------------------------------------- Internal header file for the exe manager module. Do not edit. This @@ -17,7 +17,8 @@ typedef struct __EXEMAN{ int exeStackPtr; int runList; pExeBuf uploadBuffer; + int echo; }ExeMan, *pExeMan; -#line 179 "exe.w" +#line 181 "exe.w"