- allow scriptcontext objects to be dynamic
- enhancements in scriptcontext (error messages stored as properties)
This commit is contained in:
42
script.c
42
script.c
@@ -485,7 +485,6 @@ int SicsPrompt(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
/*----------------------- get object descriptor name -------------------------------
|
||||
get the name of the object descriptor
|
||||
*/
|
||||
|
||||
int SICSDescriptor(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
@@ -517,3 +516,44 @@ int SICSDescriptor(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
SCWrite(pCon, "notfound", eValue);
|
||||
return 1;
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
int SICSSilent(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]) {
|
||||
Tcl_Interp *pTcl = NULL;
|
||||
int iRet;
|
||||
char *cmd;
|
||||
char *result;
|
||||
writeFunc oldWrite;
|
||||
|
||||
assert(pCon);
|
||||
assert(pSics);
|
||||
|
||||
if (!SCinMacro(pCon)) {
|
||||
SCPrintf(pCon, eError,
|
||||
"ERROR: %s may only be called in scripts", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
pTcl = InterpGetTcl(pSics);
|
||||
assert(pTcl);
|
||||
if (argc < 3) {
|
||||
SCWrite(pCon, "ERROR: should be: silent <error-value> <tcl-command>", eError);
|
||||
return 0;
|
||||
}
|
||||
cmd = Arg2Tcl(argc-2,&argv[2],NULL,0);
|
||||
assert(cmd);
|
||||
|
||||
oldWrite = SCGetWriteFunc(pCon);
|
||||
SCSetWriteFunc(pCon,SCNotWrite);
|
||||
iRet = Tcl_EvalEx(pTcl, cmd, strlen(cmd), 0);
|
||||
SCSetWriteFunc(pCon,oldWrite);
|
||||
|
||||
if (iRet == TCL_OK) {
|
||||
result = strdup((char *)Tcl_GetStringResult(pTcl));
|
||||
SCWrite(pCon, result, eValue);
|
||||
free(result);
|
||||
} else {
|
||||
SCWrite(pCon, argv[1], eValue);
|
||||
}
|
||||
free(cmd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user