- Adapted indenation to new agreed upon system
- Added support for second generation scriptcontext based counter
This commit is contained in:
301
obpar.c
301
obpar.c
@ -47,169 +47,162 @@
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
int ObParLength(ObPar *self)
|
||||
{
|
||||
int i = 0;
|
||||
int ObParLength(ObPar * self)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
assert(self);
|
||||
|
||||
while(self[i].iCode != -100)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
assert(self);
|
||||
|
||||
while (self[i].iCode != -100) {
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
ObPar *ObParCreate(int iArrayLong)
|
||||
{
|
||||
ObPar *pRes = NULL;
|
||||
int i;
|
||||
|
||||
assert(iArrayLong > 0);
|
||||
|
||||
/* allocate memory */
|
||||
pRes = (ObPar *)malloc((iArrayLong + 1)*sizeof(ObPar));
|
||||
if(!pRes)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* initialise all to 0 */
|
||||
for(i = 0; i < iArrayLong; i++)
|
||||
{
|
||||
pRes[i].name = NULL;
|
||||
pRes[i].fVal = .0;
|
||||
pRes[i].iCode = usSpy;
|
||||
}
|
||||
|
||||
/* have a sentinel at the end */
|
||||
pRes[iArrayLong].iCode = -100;
|
||||
|
||||
return pRes;
|
||||
ObPar *ObParCreate(int iArrayLong)
|
||||
{
|
||||
ObPar *pRes = NULL;
|
||||
int i;
|
||||
|
||||
assert(iArrayLong > 0);
|
||||
|
||||
/* allocate memory */
|
||||
pRes = (ObPar *) malloc((iArrayLong + 1) * sizeof(ObPar));
|
||||
if (!pRes) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* initialise all to 0 */
|
||||
for (i = 0; i < iArrayLong; i++) {
|
||||
pRes[i].name = NULL;
|
||||
pRes[i].fVal = .0;
|
||||
pRes[i].iCode = usSpy;
|
||||
}
|
||||
|
||||
/* have a sentinel at the end */
|
||||
pRes[iArrayLong].iCode = -100;
|
||||
|
||||
return pRes;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void ObParDelete(ObPar *self)
|
||||
{
|
||||
int i;
|
||||
int iLong;
|
||||
|
||||
assert(self);
|
||||
|
||||
/* free the names */
|
||||
iLong = ObParLength(self);
|
||||
for(i = 0; i < iLong; i++)
|
||||
{
|
||||
if(self[i].name)
|
||||
free(self[i].name);
|
||||
void ObParDelete(ObPar * self)
|
||||
{
|
||||
int i;
|
||||
int iLong;
|
||||
|
||||
assert(self);
|
||||
|
||||
/* free the names */
|
||||
iLong = ObParLength(self);
|
||||
for (i = 0; i < iLong; i++) {
|
||||
if (self[i].name)
|
||||
free(self[i].name);
|
||||
}
|
||||
|
||||
free(self);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ObPar *ObParFind(ObPar * self, char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
assert(self);
|
||||
|
||||
for (i = 0; self[i].iCode != -100; i++) {
|
||||
if (strcmp(name, self[i].name) == 0) {
|
||||
return &self[i];
|
||||
}
|
||||
|
||||
free(self);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ObPar *ObParFind(ObPar *self, char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
assert(self);
|
||||
|
||||
for(i = 0; self[i].iCode != -100; i++)
|
||||
{
|
||||
if(strcmp(name,self[i].name) == 0)
|
||||
{
|
||||
return &self[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int ObParIndex(ObPar *self, char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
assert(self);
|
||||
|
||||
for(i = 0; self[i].iCode != -100; i++)
|
||||
{
|
||||
if(strcmp(name,self[i].name) == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int ObParInit(ObPar *self, int i, char *name, float fVal, int iCode)
|
||||
{
|
||||
|
||||
assert(self);
|
||||
|
||||
/* check i */
|
||||
if( (i < 0) && ( i >= ObParLength(self) ))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(self[i].name)
|
||||
{
|
||||
free(self[i].name);
|
||||
}
|
||||
self[i].name = strdup(name);
|
||||
self[i].fVal = fVal;
|
||||
self[i].iCode = iCode;
|
||||
return 1;
|
||||
int ObParIndex(ObPar * self, char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
assert(self);
|
||||
|
||||
for (i = 0; self[i].iCode != -100; i++) {
|
||||
if (strcmp(name, self[i].name) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
int ObParSet(ObPar *self, char *obname, char *name, float fVal,
|
||||
SConnection *pCon)
|
||||
{
|
||||
char pBueffel[512];
|
||||
ObPar *pPar = NULL;
|
||||
Status eStat;
|
||||
|
||||
assert(self);
|
||||
|
||||
/* find the parameter */
|
||||
pPar = ObParFind(self,name);
|
||||
if(pPar == NULL)
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: %s.%s parameter not found",
|
||||
obname,name);
|
||||
SCWrite(pCon, pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* are we running? */
|
||||
eStat = GetStatus();
|
||||
if(!((eStat == eEager) || (eStat == eBatch)) )
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: Cannot change parameter while running");
|
||||
SCWrite(pCon, pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check permission */
|
||||
if(!SCMatchRights(pCon,pPar->iCode))
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: Insufficient privilege to change %s.%s",
|
||||
obname, name);
|
||||
SCWrite(pCon, pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* passed all tests: do It! */
|
||||
pPar->fVal = fVal;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int ObParInit(ObPar * self, int i, char *name, float fVal, int iCode)
|
||||
{
|
||||
|
||||
assert(self);
|
||||
|
||||
/* check i */
|
||||
if ((i < 0) && (i >= ObParLength(self))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self[i].name) {
|
||||
free(self[i].name);
|
||||
}
|
||||
self[i].name = strdup(name);
|
||||
self[i].fVal = fVal;
|
||||
self[i].iCode = iCode;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
int ObParSet(ObPar * self, char *obname, char *name, float fVal,
|
||||
SConnection * pCon)
|
||||
{
|
||||
char pBueffel[512];
|
||||
ObPar *pPar = NULL;
|
||||
Status eStat;
|
||||
|
||||
assert(self);
|
||||
|
||||
/* find the parameter */
|
||||
pPar = ObParFind(self, name);
|
||||
if (pPar == NULL) {
|
||||
sprintf(pBueffel, "ERROR: %s.%s parameter not found", obname, name);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* are we running? */
|
||||
eStat = GetStatus();
|
||||
if (!((eStat == eEager) || (eStat == eBatch))) {
|
||||
sprintf(pBueffel, "ERROR: Cannot change parameter while running");
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check permission */
|
||||
if (!SCMatchRights(pCon, pPar->iCode)) {
|
||||
sprintf(pBueffel, "ERROR: Insufficient privilege to change %s.%s",
|
||||
obname, name);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* passed all tests: do It! */
|
||||
pPar->fVal = fVal;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
float ObVal(ObPar *self, int i)
|
||||
{
|
||||
assert(self);
|
||||
assert(i > -1);
|
||||
assert( i < ObParLength(self));
|
||||
|
||||
return self[i].fVal;
|
||||
}
|
||||
float ObVal(ObPar * self, int i)
|
||||
{
|
||||
assert(self);
|
||||
assert(i > -1);
|
||||
assert(i < ObParLength(self));
|
||||
|
||||
return self[i].fVal;
|
||||
}
|
||||
|
Reference in New Issue
Block a user