work in progress

This commit is contained in:
Douglas Clowes
2012-11-30 09:24:22 +11:00
parent 441550b546
commit cacc490e59
2 changed files with 44 additions and 10 deletions

View File

@ -25,9 +25,9 @@ static void listAllObjects(SConnection * pCon, SicsInterp * pSics)
while (pCom != NULL) { while (pCom != NULL) {
Tcl_DStringAppend(&lst, pCom->pName, -1); Tcl_DStringAppend(&lst, pCom->pName, -1);
pCom = pCom->pNext; pCom = pCom->pNext;
Tcl_DStringAppend(&lst, ",", -1); Tcl_DStringAppend(&lst, " ", -1); //ffr "," -> " "
} }
Tcl_DStringAppend(&lst, "ENDLIST", -1); Tcl_DStringAppend(&lst, " ", -1);
SCWrite(pCon, Tcl_DStringValue(&lst), eValue); SCWrite(pCon, Tcl_DStringValue(&lst), eValue);
Tcl_DStringFree(&lst); Tcl_DStringFree(&lst);
} }
@ -79,7 +79,7 @@ static void listAllObjectData(SConnection * pCon, char *name, pDummy data)
prop = prop->pNext; prop = prop->pNext;
} }
} }
Tcl_DStringAppend(&lst, "ENDLIST", -1); Tcl_DStringAppend(&lst, " ", -1);
SCWrite(pCon, Tcl_DStringValue(&lst), eValue); SCWrite(pCon, Tcl_DStringValue(&lst), eValue);
Tcl_DStringFree(&lst); Tcl_DStringFree(&lst);
} }
@ -169,6 +169,18 @@ static int printObjectData(SConnection * pCon, pDummy obj, char *key)
} }
} }
static int existsObjectData(SConnection * pCon, pDummy obj, char *key)
{
char *ptr = NULL;
ptr = IFindOption(obj->pDescriptor->pKeys, key);
if (ptr != NULL)
SCPrintf(pCon, eValue, "%s", "true");
else
SCPrintf(pCon, eValue, "%s", "false");
return 1;
}
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
* this function implements a set on top of a list. This means that * this function implements a set on top of a list. This means that
* the list is first searched for the occurence of name. name is only * the list is first searched for the occurence of name. name is only
@ -203,7 +215,7 @@ static void listToString(int list, Tcl_DString * txt)
pPtr = (char *) LLDnodePtr(list); pPtr = (char *) LLDnodePtr(list);
if (pPtr != NULL) { if (pPtr != NULL) {
Tcl_DStringAppend(txt, pPtr, -1); Tcl_DStringAppend(txt, pPtr, -1);
Tcl_DStringAppend(txt, ",", -1); Tcl_DStringAppend(txt, " ", -1); //ffr "," -> " "
} }
status = LLDnodePtr2Next(list); status = LLDnodePtr2Next(list);
} }
@ -234,7 +246,7 @@ static void printKeyTypes(SicsInterp * pSics, SConnection * pCon,
} }
pCom = pCom->pNext; pCom = pCom->pNext;
} }
LLDstringAppend(list, "ENDLIST"); LLDstringAppend(list, " ");
listToString(list, &result); listToString(list, &result);
SCWrite(pCon, Tcl_DStringValue(&result), eValue); SCWrite(pCon, Tcl_DStringValue(&result), eValue);
@ -271,11 +283,11 @@ static void printObjectsMatchingKeyVal(SicsInterp * pSics,
} }
if (status == 1) { if (status == 1) {
Tcl_DStringAppend(&result, pCom->pName, -1); Tcl_DStringAppend(&result, pCom->pName, -1);
Tcl_DStringAppend(&result, ",", -1); Tcl_DStringAppend(&result, " ", -1); //ffr "," -> " "
} }
pCom = pCom->pNext; pCom = pCom->pNext;
} }
Tcl_DStringAppend(&result, "ENDLIST", -1); Tcl_DStringAppend(&result, " ", -1);
SCWrite(pCon, Tcl_DStringValue(&result), eValue); SCWrite(pCon, Tcl_DStringValue(&result), eValue);
Tcl_DStringFree(&result); Tcl_DStringFree(&result);
} }
@ -395,7 +407,7 @@ static int printServer(SConnection * pCon)
Tcl_DStringAppend(&txt, buffer, -1); Tcl_DStringAppend(&txt, buffer, -1);
current = current->pNext; current = current->pNext;
} }
Tcl_DStringAppend(&txt, "ENDLIST", -1); Tcl_DStringAppend(&txt, " ", -1);
SCWrite(pCon, Tcl_DStringValue(&txt), eValue); SCWrite(pCon, Tcl_DStringValue(&txt), eValue);
Tcl_DStringFree(&txt); Tcl_DStringFree(&txt);
return 1; return 1;
@ -465,11 +477,11 @@ static void printMatch(SConnection * pCon, SicsInterp * pSics, char *mask)
while (current != NULL) { while (current != NULL) {
if (!match(mask, current->pName)) { if (!match(mask, current->pName)) {
Tcl_DStringAppend(&txt, current->pName, -1); Tcl_DStringAppend(&txt, current->pName, -1);
Tcl_DStringAppend(&txt, ",", -1); Tcl_DStringAppend(&txt, " ", -1); //ffr "," -> " "
} }
current = current->pNext; current = current->pNext;
} }
Tcl_DStringAppend(&txt, "ENDLIST", -1); Tcl_DStringAppend(&txt, " ", -1);
SCWrite(pCon, Tcl_DStringValue(&txt), eValue); SCWrite(pCon, Tcl_DStringValue(&txt), eValue);
Tcl_DStringFree(&txt); Tcl_DStringFree(&txt);
} }
@ -518,6 +530,21 @@ int SicsList(SConnection * pCon, SicsInterp * pSics, void *pData,
} }
} }
if (strcmp(argv[1], "exists") == 0) {
if (argc < 4) {
SCWrite(pCon, "ERROR: not enough arguments", eError);
return 0;
} else {
pCom = FindCommand(pSics, argv[2]);
if (pCom == NULL) {
SCWrite(pCon, "ERROR: Object doesn't exist", eError);
return 0;
} else
return existsObjectData(pCon, (pDummy) pCom->pData, argv[3]);
}
}
/* /*
* object properties * object properties
*/ */

View File

@ -244,6 +244,12 @@ static int SimSetPar(void *self, SConnection * pCon, char *name,
return 0; return 0;
} }
static int SimGetTextPar(void *pData, char *name, char *textPar)
{
snprintf(textPar, 8, "unknown");
return 1;
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void KillSIM(void *pData) void KillSIM(void *pData)
{ {
@ -336,6 +342,7 @@ MotorDriver *CreateSIM(SConnection * pCon, int argc, char *argv[])
pDriv->fSpeed = .01; pDriv->fSpeed = .01;
pDriv->iTime = 0; pDriv->iTime = 0;
pDriv->KillPrivate = KillSIM; pDriv->KillPrivate = KillSIM;
pDriv->GetDriverTextPar = SimGetTextPar;
/* check for optional speed paramter */ /* check for optional speed paramter */
pCurrent = pCurrent->pNext; pCurrent = pCurrent->pNext;