PSI update

r1464 | ffr | 2007-02-12 12:20:21 +1100 (Mon, 12 Feb 2007) | 2 lines
This commit is contained in:
Ferdi Franceschini
2007-02-12 12:20:21 +11:00
committed by Douglas Clowes
parent 634f2023b1
commit 3168325921
157 changed files with 29053 additions and 910 deletions

134
macro.c
View File

@@ -2,7 +2,7 @@
All you need to evaluate macros with SICS
The implmentation for the macro stuff is complex and non intuitive.
The implementation for the macro stuff is complex and non intuitive.
This is the price to pay for adding the extremly powerful and
strong Tcl-interpreter to SICS. The problem is that Tcl does not
know anything about connections and our error handling. We have
@@ -770,6 +770,127 @@ static int ProtectedExec(ClientData clientData, Tcl_Interp *interp,
}
return 1;
}
/*-----------------------------------------------------------------------*/
int GumPut(SConnection *pCon, SicsInterp *pInter, void *pData,
int argc, char *argv[])
{
OutCode eOut = eWarning;
int i = 0, iCode, iLen;
int iMacro;
char *ppCode;
char *pMessage = NULL;
commandContext cc;
assert(pCon);
assert(pInter);
if(argc < 2)
{
SCWrite(pCon,"Insufficient arguments to ClientPut",eError);
return 0;
}
/* handle optional I/O codes */
if(argc > 2)
{
/* the last one must be the code */
iCode = argc - 1;
ppCode = strdup(argv[iCode]);
strtolower(ppCode);
while(pCode[i] != NULL)
{
if(strcmp(pCode[i],ppCode) == 0)
{
break;
}
i++;
}
if(ppCode)
{
free(ppCode);
}
}
else
{
i = 10;
iCode = argc;
}
switch(i)
{
case 0:
eOut = eInternal;
break;
case 1:
eOut = eCommand;
break;
case 2:
eOut = eHWError;
break;
case 3:
eOut = eInError;
break;
case 4:
eOut = eStatus;
break;
case 5:
eOut = eValue;
break;
case 6:
eOut = eWarning;
break;
case 7:
eOut = eFinish;
break;
case 8:
eOut = eEvent;
break;
case 9:
eOut = eWarning;
break;
case 10:
eOut = eError;
break;
default:
eOut = eWarning;
iCode = argc;
break;
}
/* recombine the message */
/* find length */
iLen = 0;
for(i = 1; i < iCode; i++)
{
iLen += strlen(argv[i]);
}
pMessage = (char *)malloc((iLen+100)*sizeof(char));
if(!pMessage)
{
SCWrite(pCon,"ERROR: out of memory in clientput",eError);
return 0;
}
memset(pMessage,0,(iLen+100)*sizeof(char));
Arg2Text(iCode-1,&argv[1],pMessage,(iLen+100)*sizeof(char));
/* now write, thereby tunneling macro flag in order to get proper
write to client and not into interpreter. We also make sure that the device
is gumput
*/
iMacro = SCinMacro(pCon);
SCsetMacro(pCon,0);
cc = SCGetContext(pCon);
strcpy(cc.deviceID,"gumput");
SCPushContext2(pCon,cc);
SCWrite(pCon,pMessage,eOut);
SCPopContext(pCon);
SCsetMacro(pCon,iMacro);
if(pMessage)
{
free(pMessage);
}
return 1;
}
/*----------------------------------------------------------------------*/
int Broadcast(SConnection *pCon, SicsInterp *pInter, void *pData,
int argc, char *argv[])
@@ -891,14 +1012,9 @@ static int ProtectedExec(ClientData clientData, Tcl_Interp *interp,
if (pCommand != pBueffel) free(pCommand);
if(iRet == TCL_OK)
{
/* we do not now why, but at some time it was found that
we need a copy, and can not use pTcl->result directly
SCWrite(pCon,pTcl->result,eStatus);
let us use SCPrintf, which maked always a copy
*/
SCPrintf(pCon, eStatus, "%s", pTcl->result);
if(strlen(pTcl->result) > 0){
SCPrintf(pCon, eStatus, "%s", pTcl->result);
}
return 1;
}
else