PSI sics-cvs-psi-2008-10-02
This commit is contained in:
157
SCinter.c
157
SCinter.c
@@ -41,7 +41,7 @@
|
||||
Mark Koennecke, August 2001, modified SicsWriteStatus to write motor
|
||||
positions on demand.
|
||||
|
||||
Made ListObjects moe intelligent: list objects according to interface etc.
|
||||
Made ListObjects more intelligent: list objects according to interface etc.
|
||||
Mark Koennecke, December 2003
|
||||
|
||||
Extended 'dir' command (function ListObjects) to list via typename from
|
||||
@@ -50,6 +50,8 @@
|
||||
|
||||
Modified printXXX functions to fix duplicate write of last buffer line.
|
||||
Paul Hathaway, May 2004
|
||||
|
||||
Added FindAlias function, Mark Koennecke, January 2007
|
||||
---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -57,6 +59,8 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <tcl.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#include "fortify.h"
|
||||
#include "sics.h"
|
||||
#include "splitter.h"
|
||||
@@ -66,6 +70,7 @@
|
||||
#include "motor.h"
|
||||
#include "obdes.h"
|
||||
#include "lld.h"
|
||||
#include "dynstring.h"
|
||||
|
||||
/* M.Z. */
|
||||
#include "definealias.h"
|
||||
@@ -133,6 +138,7 @@ static void freeList(int listID);
|
||||
SICSLogWrite(pBueffel,eInternal);
|
||||
return 0;
|
||||
}
|
||||
memset(pNew,0,sizeof(CommandList));
|
||||
|
||||
/* if no data given, initialise with Dummy struct */
|
||||
if(!pData)
|
||||
@@ -151,6 +157,7 @@ static void freeList(int listID);
|
||||
pNew->pData = pData;
|
||||
pNew->pNext = NULL;
|
||||
pNew->startupOnly = startupOnly;
|
||||
pNew->stat = StatisticsNew(pBueffel);
|
||||
|
||||
/* find end of list */
|
||||
tail = NULL;
|
||||
@@ -232,10 +239,14 @@ static void freeList(int listID);
|
||||
{
|
||||
pInterp->pCList = pVictim->pNext;
|
||||
}
|
||||
if (pVictim->stat) {
|
||||
StatisticsKill(pVictim->stat);
|
||||
}
|
||||
free(pVictim);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
#define MAXLEN 256
|
||||
#define MAXCOM 50
|
||||
extern char *stptok(char *s, char *tok, unsigned int toklen, char *brk);
|
||||
@@ -252,6 +263,7 @@ extern char *SkipSpace(char *pPtr);
|
||||
char *pPtr;
|
||||
char **argv = NULL;
|
||||
commandContext comCon;
|
||||
Statistics *old;
|
||||
|
||||
|
||||
assert(self);
|
||||
@@ -307,7 +319,9 @@ extern char *SkipSpace(char *pPtr);
|
||||
Tcl_ResetResult((Tcl_Interp *)self->pTcl);
|
||||
MacroPush(pCon);
|
||||
pCon->conStatus = 0;
|
||||
old = StatisticsBegin(pCommand->stat);
|
||||
iRet = pCommand->OFunc(pCon, self, pCommand->pData, argc, argv);
|
||||
StatisticsEnd(old);
|
||||
/* If a task is registered with the dev exec then conStatus is HWBusy*/
|
||||
if (pCon->conStatus != HWBusy) {
|
||||
comCon = SCGetContext(pCon);
|
||||
@@ -422,7 +436,7 @@ extern char *SkipSpace(char *pPtr);
|
||||
}
|
||||
if(fVal > -990.)
|
||||
{
|
||||
fprintf(fd,"run %s %f\n",pCurrent->pName, fVal);
|
||||
fprintf(fd,"drive %s %f\n",pCurrent->pName, fVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -444,29 +458,47 @@ extern char *SkipSpace(char *pPtr);
|
||||
void DeleteInterp(SicsInterp *self)
|
||||
{
|
||||
CommandList *pCurrent = NULL;
|
||||
CommandList *pTemp;
|
||||
CommandList *pTemp, *tail;
|
||||
Tcl_Interp *pTcl = NULL;
|
||||
int i;
|
||||
|
||||
assert(self);
|
||||
self->iDeleting = 1;
|
||||
|
||||
/* delete Commandlist */
|
||||
/* find end of list */
|
||||
tail = NULL;
|
||||
pCurrent = self->pCList;
|
||||
while(pCurrent)
|
||||
while(pCurrent != NULL)
|
||||
{
|
||||
if(pCurrent->KFunc)
|
||||
tail = pCurrent;
|
||||
pCurrent = pCurrent->pNext;
|
||||
}
|
||||
|
||||
/* delete Commandlist (reversed order) */
|
||||
if (tail) {
|
||||
pCurrent = tail;
|
||||
while(pCurrent)
|
||||
{
|
||||
pCurrent->KFunc(pCurrent->pData);
|
||||
/* the line below fixes problems with kill functions
|
||||
* traversing the command list
|
||||
*/
|
||||
pCurrent->pNext = NULL;
|
||||
if(pCurrent->KFunc)
|
||||
{
|
||||
pCurrent->KFunc(pCurrent->pData);
|
||||
}
|
||||
if(pCurrent->pName)
|
||||
{
|
||||
/* printf("Deleting %s\n",pCurrent->pName); */
|
||||
free(pCurrent->pName);
|
||||
}
|
||||
if (pCurrent->stat) {
|
||||
StatisticsKill(pCurrent->stat);
|
||||
}
|
||||
pTemp = pCurrent->pPrevious;
|
||||
free(pCurrent);
|
||||
pCurrent = pTemp;
|
||||
}
|
||||
if(pCurrent->pName)
|
||||
{
|
||||
/* printf("Deleting %s\n",pCurrent->pName); */
|
||||
free(pCurrent->pName);
|
||||
}
|
||||
pTemp = pCurrent->pNext;
|
||||
free(pCurrent);
|
||||
pCurrent = pTemp;
|
||||
}
|
||||
|
||||
FreeAliasList(&self->AList); /* M.Z. */
|
||||
@@ -949,6 +981,11 @@ static void printType(SicsInterp *pSics, SConnection *pCon, char *typeName)
|
||||
if(!pCom->pData)
|
||||
return NULL;
|
||||
|
||||
if (cclass == NULL)
|
||||
{
|
||||
return pCom->pData;
|
||||
}
|
||||
|
||||
pDum = (pDummy)pCom->pData;
|
||||
if(strcmp(pDum->pDescriptor->name,cclass) == 0)
|
||||
{
|
||||
@@ -956,6 +993,19 @@ static void printType(SicsInterp *pSics, SConnection *pCon, char *typeName)
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
pObjectDescriptor FindCommandDescriptor(SicsInterp *pSics, char *name)
|
||||
{
|
||||
CommandList *pCom;
|
||||
|
||||
pCom = FindCommand(pSics,name);
|
||||
if(pCom == NULL || pCom->pData == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ((pDummy)pCom->pData)->pDescriptor;
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
void *FindDrivable(SicsInterp *pSics, char *name){
|
||||
pIDrivable pDriv;
|
||||
@@ -1021,3 +1071,80 @@ static void freeList(int listID)
|
||||
pCurrent = pNext;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
||||
char *FindAliases(SicsInterp *pSics, char *name)
|
||||
{
|
||||
pDynString result = NULL;
|
||||
CommandList *pOri = NULL, *pCom = NULL;
|
||||
char *pTrans = NULL, *charResult = NULL;
|
||||
int first;
|
||||
|
||||
pOri = FindCommand(pSics, name);
|
||||
if(pOri == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if(pOri->pData == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = CreateDynString(64,64);
|
||||
if(result == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* try first to locate Markus style aliases */
|
||||
pTrans = TranslateAlias(&pSics->AList,name);
|
||||
if(strcmp(pTrans,name) != 0)
|
||||
{
|
||||
DynStringCopy(result,pTrans);
|
||||
charResult = strdup(GetCharArray(result));
|
||||
DeleteDynString(result);
|
||||
return charResult;
|
||||
}
|
||||
|
||||
/*
|
||||
* locate SicsAlias style aliases by comparing the original
|
||||
* data pointer with the data pointers of other commands
|
||||
*/
|
||||
first = 1;
|
||||
pCom = pSics->pCList;
|
||||
while(pCom != NULL)
|
||||
{
|
||||
if(pCom != pOri && pCom->pData == pOri->pData)
|
||||
{
|
||||
if(first)
|
||||
{
|
||||
DynStringCopy(result,pCom->pName);
|
||||
first = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
DynStringConcat(result,",");
|
||||
DynStringConcat(result,pCom->pName);
|
||||
}
|
||||
}
|
||||
pCom = pCom->pNext;
|
||||
}
|
||||
charResult = strdup(GetCharArray(result));
|
||||
DeleteDynString(result);
|
||||
return charResult;
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
||||
void ForEachCommand(int (*scanFunction)(char *name, pDummy object, void *userData)
|
||||
, void *userData)
|
||||
{
|
||||
CommandList *pCurrent;
|
||||
|
||||
|
||||
for(pCurrent = pServ->pSics->pCList;
|
||||
pCurrent != NULL;
|
||||
pCurrent = pCurrent->pNext)
|
||||
{
|
||||
if(scanFunction(pCurrent->pName, pCurrent->pData, userData) == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user