- Adapted indenation to new agreed upon system

- Added support for second generation scriptcontext based counter
This commit is contained in:
koennecke
2009-02-13 09:00:03 +00:00
parent a3dcad2bfa
commit 91d4af0541
405 changed files with 88101 additions and 88173 deletions

932
script.c
View File

@@ -55,515 +55,465 @@
#include "status.h"
#include "script.h"
#include "devexec.h"
extern Tcl_Interp *InterpGetTcl(SicsInterp *pSics);
extern void SNXFormatTime(char *pBueffel, int iLen); /* in nxdata.c */
extern Tcl_Interp *InterpGetTcl(SicsInterp * pSics);
extern void SNXFormatTime(char *pBueffel, int iLen); /* in nxdata.c */
/* -------------------------- Interrupts -----------------------------------*/
int GetSICSInterrupt(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])
{
char pBueffel[132];
SConnection *pOwner = NULL;
pExeList pDev = NULL;
assert(pCon);
assert(pSics);
int GetSICSInterrupt(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
char pBueffel[132];
SConnection *pOwner = NULL;
pExeList pDev = NULL;
/* we are interested in the interrupt pending in the executor. If
not specified, use our very own
*/
pDev = GetExecutor();
assert(pDev);
pOwner = GetExeOwner(pDev);
if(pOwner)
{
Interrupt2Text(SCGetInterrupt(pOwner),pBueffel,131);
SCWrite(pCon,pBueffel,eValue);
}
else
{
Interrupt2Text(SCGetInterrupt(pCon),pBueffel,131);
SCWrite(pCon,pBueffel,eValue);
}
return 1;
}
/*-------------------------------------------------------------------------*/
int SetSICSInterrupt(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])
{
int iInt;
char pBueffel[132];
SConnection *pOwner = NULL;
pExeList pDev = NULL;
assert(pCon);
assert(pSics);
/* minimum user privelege */
if(!SCMatchRights(pCon,usUser))
{
SCWrite(pCon,"ERROR: you are not priviledged to set interrupts",eError);
return 0;
}
/* only in script processing */
if(!SCinMacro(pCon))
{
SCWrite(pCon,"ERROR: Interrupt manipulation only permitted in Macros",
eError);
return 0;
}
/* is there a value ? */
if(argc < 2)
{
SCWrite(pCon,"ERROR: missing parameter for SetInterrupt",eError);
return 0;
}
/* actually do a job */
strtolower(argv[1]);
iInt = Text2Interrupt(argv[1]);
if(iInt < 0)
{
sprintf(pBueffel,"ERROR: %s not recognized as Interrupt code",
argv[1]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
assert(pCon);
assert(pSics);
/* we are interested in the interrupt pending in the executor. If
not specified, use our very own
*/
pDev = GetExecutor();
assert(pDev);
pOwner = GetExeOwner(pDev);
if (pOwner) {
Interrupt2Text(SCGetInterrupt(pOwner), pBueffel, 131);
SCWrite(pCon, pBueffel, eValue);
} else {
Interrupt2Text(SCGetInterrupt(pCon), pBueffel, 131);
SCWrite(pCon, pBueffel, eValue);
}
return 1;
}
/*-------------------------------------------------------------------------*/
int SetSICSInterrupt(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
int iInt;
char pBueffel[132];
SConnection *pOwner = NULL;
pExeList pDev = NULL;
assert(pCon);
assert(pSics);
/* minimum user privelege */
if (!SCMatchRights(pCon, usUser)) {
SCWrite(pCon, "ERROR: you are not priviledged to set interrupts",
eError);
return 0;
}
/* only in script processing */
if (!SCinMacro(pCon)) {
SCWrite(pCon, "ERROR: Interrupt manipulation only permitted in Macros",
eError);
return 0;
}
/* is there a value ? */
if (argc < 2) {
SCWrite(pCon, "ERROR: missing parameter for SetInterrupt", eError);
return 0;
}
/* actually do a job */
strtolower(argv[1]);
iInt = Text2Interrupt(argv[1]);
if (iInt < 0) {
sprintf(pBueffel, "ERROR: %s not recognized as Interrupt code",
argv[1]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
/* we want to change the interrupt pending in the executor. If none
there, charnge our own.
*/
pDev = GetExecutor();
assert(pDev);
pOwner = GetExeOwner(pDev);
if (pOwner) {
SCSetInterrupt(pOwner, iInt);
} else {
SCSetInterrupt(pCon, iInt);
}
SCSendOK(pCon);
return 1;
}
/*-------------------------------------------------------------------------*/
int SetSICSStatus(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
int iInt;
char pBueffel[132];
assert(pCon);
assert(pSics);
/* minimum user privelege */
if (!SCMatchRights(pCon, usUser)) {
SCWrite(pCon, "ERROR: you are not priviledged to set status", eError);
return 0;
}
/* only in script processing */
if (!SCinMacro(pCon)) {
SCWrite(pCon, "ERROR: status manipulation only permitted in Macros",
eError);
return 0;
}
/* is there a value ? */
if (argc < 2) {
SCWrite(pCon, "ERROR: missing parameter for SetStatus", eError);
return 0;
}
/* actually do a job */
strtolower(argv[1]);
iInt = SetStatusFromText(argv[1]);
if (iInt) {
SCSendOK(pCon);
return 1;
} else {
sprintf(pBueffel, "ERROR: %s not recognized as status code", argv[1]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
}
/* we want to change the interrupt pending in the executor. If none
there, charnge our own.
*/
pDev = GetExecutor();
assert(pDev);
pOwner = GetExeOwner(pDev);
if(pOwner)
{
SCSetInterrupt(pOwner,iInt);
}
else
{
SCSetInterrupt(pCon,iInt);
}
SCSendOK(pCon);
return 1;
}
/*-------------------------------------------------------------------------*/
int SetSICSStatus(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])
{
int iInt;
char pBueffel[132];
assert(pCon);
assert(pSics);
/* minimum user privelege */
if(!SCMatchRights(pCon,usUser))
{
SCWrite(pCon,"ERROR: you are not priviledged to set status",eError);
return 0;
}
/* only in script processing */
if(!SCinMacro(pCon))
{
SCWrite(pCon,"ERROR: status manipulation only permitted in Macros",
eError);
return 0;
}
/* is there a value ? */
if(argc < 2)
{
SCWrite(pCon,"ERROR: missing parameter for SetStatus",eError);
return 0;
}
/* actually do a job */
strtolower(argv[1]);
iInt = SetStatusFromText(argv[1]);
if(iInt)
{
SCSendOK(pCon);
return 1;
}
else
{
sprintf(pBueffel,"ERROR: %s not recognized as status code",argv[1]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
}
/*-----------------------------------------------------------------------*/
static int isNum(char *pText)
{
int i;
int iRet = 1;
for(i = 0; i < strlen(pText); i++)
{
if(!isdigit(pText[i]))
{
if(!((pText[i] == '+') || (pText[i] == '-') || (pText[i] == '.')))
{
iRet = 0;
break;
}
}
static int isNum(char *pText)
{
int i;
int iRet = 1;
for (i = 0; i < strlen(pText); i++) {
if (!isdigit(pText[i])) {
if (!((pText[i] == '+') || (pText[i] == '-') || (pText[i] == '.'))) {
iRet = 0;
break;
}
return iRet;
}
}
}
return iRet;
}
/*--------------------------- Type Checking -------------------------------
classifies a given string: numeric, countable, drivable, sicsobject, text
*/
int SICSType(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])
{
CommandList *pCom = NULL;
Dummy *pDum = NULL;
char pBueffel[132];
assert(pCon);
assert(pSics);
/* is there a parameter anyway */
if(argc < 2)
{
SCWrite(pCon,"ERROR: no object to test specified!",eError);
return 0;
}
/* test, one by one */
strtolower(argv[1]);
if(isNum(argv[1]))
{
SCWrite(pCon,"NUM",eValue);
int SICSType(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
CommandList *pCom = NULL;
Dummy *pDum = NULL;
char pBueffel[132];
assert(pCon);
assert(pSics);
/* is there a parameter anyway */
if (argc < 2) {
SCWrite(pCon, "ERROR: no object to test specified!", eError);
return 0;
}
/* test, one by one */
strtolower(argv[1]);
if (isNum(argv[1])) {
SCWrite(pCon, "NUM", eValue);
return 1;
}
pCom = FindCommand(pSics, argv[1]);
if (pCom) {
pDum = (Dummy *) pCom->pData;
if (pDum) {
if (pDum->pDescriptor->GetInterface(pDum, DRIVEID)) {
SCWrite(pCon, "DRIV", eValue);
return 1;
}
pCom = FindCommand(pSics,argv[1]);
if(pCom)
{
pDum = (Dummy *)pCom->pData;
if(pDum)
{
if(pDum->pDescriptor->GetInterface(pDum,DRIVEID))
{
SCWrite(pCon,"DRIV",eValue);
return 1;
}
if(pDum->pDescriptor->GetInterface(pDum,COUNTID))
{
SCWrite(pCon,"COUNT",eValue);
return 1;
}
}
SCWrite(pCon,"COM",eValue);
return 1;
}
SCWrite(pCon,"TEXT",eValue);
return 1;
}
}
if (pDum->pDescriptor->GetInterface(pDum, COUNTID)) {
SCWrite(pCon, "COUNT", eValue);
return 1;
}
}
SCWrite(pCon, "COM", eValue);
return 1;
}
SCWrite(pCon, "TEXT", eValue);
return 1;
}
/*----------------- Bounds checking for all driveables ---------------------*/
int SICSBounds(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])
{
CommandList *pCom = NULL;
pIDrivable pInt = NULL;
Dummy *pDum = NULL;
char pBueffel[132];
float fVal;
int iRet;
assert(pCon);
assert(pSics);
if(argc < 3)
{
SCWrite(pCon,"ERROR: not enough parameters specified",eError);
return 0;
}
/* argv[1] should be drivable */
pCom = FindCommand(pSics,argv[1]);
if(!pCom)
{
sprintf(pBueffel,"ERROR: %s is no Sics Object",argv[1]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
pDum = (Dummy *)pCom->pData;
if(!pDum)
{
sprintf(pBueffel,"ERROR: %s is no valid Sics Object",argv[1]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
pInt = pDum->pDescriptor->GetInterface(pDum,DRIVEID);
if(!pInt)
{
sprintf(pBueffel,"ERROR: %s is not drivable!",argv[1]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
/* argv[2] should be a numeric */
if(!isNum(argv[2]))
{
sprintf(pBueffel,"ERROR: %s is not a number!",argv[2]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
/* do a job */
fVal = atof(argv[2]);
iRet = pInt->CheckLimits(pCom->pData,fVal,pBueffel,131);
if(iRet)
{
SCWrite(pCon,"OK",eValue);
return 1;
}
else
{
SCWrite(pCon,pBueffel,eWarning);
return 0;
}
return 0; /* not reached */
}
int SICSBounds(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
CommandList *pCom = NULL;
pIDrivable pInt = NULL;
Dummy *pDum = NULL;
char pBueffel[132];
float fVal;
int iRet;
assert(pCon);
assert(pSics);
if (argc < 3) {
SCWrite(pCon, "ERROR: not enough parameters specified", eError);
return 0;
}
/* argv[1] should be drivable */
pCom = FindCommand(pSics, argv[1]);
if (!pCom) {
sprintf(pBueffel, "ERROR: %s is no Sics Object", argv[1]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
pDum = (Dummy *) pCom->pData;
if (!pDum) {
sprintf(pBueffel, "ERROR: %s is no valid Sics Object", argv[1]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
pInt = pDum->pDescriptor->GetInterface(pDum, DRIVEID);
if (!pInt) {
sprintf(pBueffel, "ERROR: %s is not drivable!", argv[1]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
/* argv[2] should be a numeric */
if (!isNum(argv[2])) {
sprintf(pBueffel, "ERROR: %s is not a number!", argv[2]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
/* do a job */
fVal = atof(argv[2]);
iRet = pInt->CheckLimits(pCom->pData, fVal, pBueffel, 131);
if (iRet) {
SCWrite(pCon, "OK", eValue);
return 1;
} else {
SCWrite(pCon, pBueffel, eWarning);
return 0;
}
return 0; /* not reached */
}
/*----------------- Status checking for Sics Objects ---------------------*/
int SICSStatus(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])
{
CommandList *pCom = NULL;
Dummy *pDum = NULL;
pIDrivable pDInt = NULL;
pICountable pCInt = NULL;
char pBueffel[132];
float fVal;
int iRet;
assert(pCon);
assert(pSics);
if(argc < 2)
{
SCWrite(pCon,"ERROR: not enough parameters specified",eError);
return 0;
}
/* argv[1] should be drivable */
pCom = FindCommand(pSics,argv[1]);
if(!pCom)
{
sprintf(pBueffel,"ERROR: %s is no Sics Object",argv[1]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
pDum = (Dummy *)pCom->pData;
if(!pDum)
{
sprintf(pBueffel,"ERROR: %s is no valid Sics Object",argv[1]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
pDInt = pDum->pDescriptor->GetInterface(pDum,DRIVEID);
pCInt = pDum->pDescriptor->GetInterface(pDum,COUNTID);
if(pDInt)
{
iRet = pDInt->CheckStatus(pDum,pCon);
sprintf(pBueffel,"%d",iRet);
SCWrite(pCon,pBueffel,eValue);
return 1;
}
else if(pCInt)
{
iRet = pCInt->CheckCountStatus(pDum,pCon);
sprintf(pBueffel,"%d",iRet);
SCWrite(pCon,pBueffel,eValue);
return 1;
}
else
{
sprintf(pBueffel,"ERROR: %s is neither drivable nor countable",argv[1]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
/* not reached */
return 0;
int SICSStatus(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
CommandList *pCom = NULL;
Dummy *pDum = NULL;
pIDrivable pDInt = NULL;
pICountable pCInt = NULL;
char pBueffel[132];
float fVal;
int iRet;
}
/*--------------------------------------------------------------------------*/
int SICSDebug(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])
{
char pBueffel[256];
Tcl_Interp *pTcl = NULL;
int iRet;
char *cmd;
assert(pCon);
assert(pSics);
if(!SCMatchRights(pCon,usInternal))
{
SCWrite(pCon,"ERROR: no privilege to interact with Tcl for you",
eError);
return 0;
}
pTcl = InterpGetTcl(pSics);
assert(pTcl);
cmd = Arg2Tcl(argc-1,&argv[1],pBueffel,sizeof pBueffel);
if (!cmd) {
SCWrite(pCon,"ERROR: no more memory",eError);
return 0;
}
iRet = Tcl_Eval(pTcl,cmd);
if (cmd != pBueffel) free(cmd);
if(strlen(pTcl->result) > 1)
{
SCWrite(pCon,pTcl->result,eValue);
}
return iRet;
}
/*--------------------------------------------------------------------------*/
int SICSTime(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])
{
char pBueffel[256];
assert(pCon);
assert(pSics);
if (argc < 2) {
SCWrite(pCon, "ERROR: not enough parameters specified", eError);
return 0;
}
/* argv[1] should be drivable */
pCom = FindCommand(pSics, argv[1]);
if (!pCom) {
sprintf(pBueffel, "ERROR: %s is no Sics Object", argv[1]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
pDum = (Dummy *) pCom->pData;
if (!pDum) {
sprintf(pBueffel, "ERROR: %s is no valid Sics Object", argv[1]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
pDInt = pDum->pDescriptor->GetInterface(pDum, DRIVEID);
pCInt = pDum->pDescriptor->GetInterface(pDum, COUNTID);
if (pDInt) {
iRet = pDInt->CheckStatus(pDum, pCon);
sprintf(pBueffel, "%d", iRet);
SCWrite(pCon, pBueffel, eValue);
return 1;
} else if (pCInt) {
iRet = pCInt->CheckCountStatus(pDum, pCon);
sprintf(pBueffel, "%d", iRet);
SCWrite(pCon, pBueffel, eValue);
return 1;
} else {
sprintf(pBueffel, "ERROR: %s is neither drivable nor countable",
argv[1]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
/* not reached */
return 0;
}
/*--------------------------------------------------------------------------*/
int SICSDebug(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
char pBueffel[256];
Tcl_Interp *pTcl = NULL;
int iRet;
char *cmd;
assert(pCon);
assert(pSics);
if (!SCMatchRights(pCon, usInternal)) {
SCWrite(pCon, "ERROR: no privilege to interact with Tcl for you",
eError);
return 0;
}
pTcl = InterpGetTcl(pSics);
assert(pTcl);
cmd = Arg2Tcl(argc - 1, &argv[1], pBueffel, sizeof pBueffel);
if (!cmd) {
SCWrite(pCon, "ERROR: no more memory", eError);
return 0;
}
iRet = Tcl_Eval(pTcl, cmd);
if (cmd != pBueffel)
free(cmd);
if (strlen(pTcl->result) > 1) {
SCWrite(pCon, pTcl->result, eValue);
}
return iRet;
}
/*--------------------------------------------------------------------------*/
int SICSTime(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
char pBueffel[256];
SNXFormatTime(pBueffel, 255);
SCWrite(pCon, pBueffel, eValue);
return 1;
}
SNXFormatTime(pBueffel,255);
SCWrite(pCon,pBueffel,eValue);
return 1;
}
/*--------------------------------------------------------------------------
Kill a command from SICS
*/
int SICSKill(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])
{
CommandList *pCom = NULL, *pCurrent = NULL;
void *pDat = NULL;
char *pPtr = NULL;
if(!SCMatchRights(pCon,usMugger))
{
SCWrite(pCon,"ERROR: you may not kill commands here, no privilege",
eError);
return 0;
}
if(argc < 2)
{
SCWrite(pCon,"ERROR: need name of command to kill",eError);
return 0;
}
*/
int SICSKill(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
CommandList *pCom = NULL, *pCurrent = NULL;
void *pDat = NULL;
char *pPtr = NULL;
if (!SCMatchRights(pCon, usMugger)) {
SCWrite(pCon, "ERROR: you may not kill commands here, no privilege",
eError);
return 0;
}
if (argc < 2) {
SCWrite(pCon, "ERROR: need name of command to kill", eError);
return 0;
}
/* memorise data for alias search */
pCom = FindCommand(pSics, argv[1]);
if (pCom) {
pDat = pCom->pData;
} else {
pDat = NULL;
}
RemoveCommand(pSics, argv[1]);
if (!pDat) { /* no data, no alias */
SCSendOK(pCon);
return 0;
}
/* kill aliases */
pPtr = FindAlias(pSics, pDat);
while (pPtr) {
RemoveCommand(pSics, pPtr);
pPtr = FindAlias(pSics, pDat);
}
SCSendOK(pCon);
return 1;
}
/* memorise data for alias search */
pCom = FindCommand(pSics,argv[1]);
if(pCom)
{
pDat = pCom->pData;
}
else
{
pDat = NULL;
}
RemoveCommand(pSics,argv[1]);
if(!pDat) /* no data, no alias */
{
SCSendOK(pCon);
return 0;
}
/* kill aliases */
pPtr = FindAlias(pSics,pDat);
while(pPtr)
{
RemoveCommand(pSics,pPtr);
pPtr = FindAlias(pSics,pDat);
}
SCSendOK(pCon);
return 1;
}
/*------------------------------------------------------------------------*/
int SicsPrompt(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])
{
char pBueffel[512];
int iRet;
int SicsPrompt(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
char pBueffel[512];
int iRet;
/* all arguments are optional */
if (argc < 1) {
iRet = SCPrompt(pCon, "SICS> ", pBueffel, 511);
} else {
iRet = SCPrompt(pCon, argv[1], pBueffel, 511);
}
if (iRet == 1) {
SCWrite(pCon, pBueffel, eValue);
return 1;
} else {
SCWrite(pCon, "ERROR: Interrupted while waiting for data", eError);
return 0;
}
}
/* all arguments are optional */
if(argc < 1)
{
iRet = SCPrompt(pCon, "SICS> ",
pBueffel, 511);
}
else
{
iRet = SCPrompt(pCon, argv[1],
pBueffel, 511);
}
if(iRet == 1)
{
SCWrite(pCon,pBueffel,eValue);
return 1;
}
else
{
SCWrite(pCon,"ERROR: Interrupted while waiting for data",eError);
return 0;
}
}
/*----------------------- get object descriptor name -------------------------------
get the name of the object descriptor
*/
int SICSDescriptor(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])
{
CommandList *pCom = NULL;
Dummy *pDum = NULL;
char pBueffel[132];
assert(pCon);
assert(pSics);
/* is there a parameter anyway */
if(argc < 2)
{
SCWrite(pCon,"ERROR: no object specified!",eError);
return 0;
}
pCom = FindCommand(pSics,argv[1]);
if(pCom)
{
pDum = (Dummy *)pCom->pData;
if(pDum)
{
SCWrite(pCon,pDum->pDescriptor->name,eValue);
return 1;
}
SCWrite(pCon,"empty",eValue);
return 1;
}
SCWrite(pCon,"notfound",eValue);
return 1;
}
int SICSDescriptor(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
CommandList *pCom = NULL;
Dummy *pDum = NULL;
char pBueffel[132];
assert(pCon);
assert(pSics);
/* is there a parameter anyway */
if (argc < 2) {
SCWrite(pCon, "ERROR: no object specified!", eError);
return 0;
}
pCom = FindCommand(pSics, argv[1]);
if (pCom) {
pDum = (Dummy *) pCom->pData;
if (pDum) {
SCWrite(pCon, pDum->pDescriptor->name, eValue);
return 1;
}
SCWrite(pCon, "empty", eValue);
return 1;
}
SCWrite(pCon, "notfound", eValue);
return 1;
}