- Fixed a bug in splitter.c

- Added hupdate and hzipget to Hipadaba
This commit is contained in:
koennecke
2006-12-19 14:30:29 +00:00
parent cd2d07690c
commit 826b13d890
2 changed files with 129 additions and 17 deletions

View File

@ -152,8 +152,9 @@ static int SICSNotifyCallback(void *userData, void *callData, pHdb node,
cbInfo = (HdbCBInfo *)userData;
pPath = GetHipadabaPath(node);
printedData = formatValue(v);
result = CreateDynString(128,128);
if(v.arrayLength < 100){
printedData = formatValue(v);
if(pPath == NULL || printedData == NULL || result == NULL){
SCWriteInContext(cbInfo->pCon,"ERROR: out of memory formatting data" ,
eEvent,cbInfo->context);
@ -168,9 +169,15 @@ static int SICSNotifyCallback(void *userData, void *callData, pHdb node,
DynStringConcat(result,GetCharArray(printedData));
SCWriteInContext(cbInfo->pCon,GetCharArray(result),
eEvent,cbInfo->context);
DeleteDynString(printedData);
} else {
DynStringCopy(result,"!!datachange!! = ");
DynStringConcat(result,pPath);
SCWriteInContext(cbInfo->pCon,GetCharArray(result),
eEvent,cbInfo->context);
}
free(pPath);
DeleteDynString(result);
DeleteDynString(printedData);
return 1;
}
@ -1591,6 +1598,56 @@ static int SetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
}
return status;
}
/*---------------------------------------------------------------------------*/
static int UpdateHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]){
pHdb targetNode = NULL;
hdbValue newValue;
pDynString parData = NULL;
char error[512];
int i, status;
if(!SCMatchRights(pCon,usUser)){
return 0;
}
if(argc < 3) {
SCWrite(pCon,"ERROR: insufficient number of arguments to UpdateHdbNode",
eError);
return 0;
}
targetNode = locateSICSNode(pSics,pCon,argv[1]);
if(targetNode == NULL){
return 0;
}
if(!cloneHdbValue(&targetNode->value,&newValue)){
SCWrite(pCon,"ERROR: out of mmeory cloning node",
eError);
return 0;
}
parData = CreateDynString(64,64);
if(parData == NULL){
SCWrite(pCon,"ERROR: out of memory reading parameter",eError);
return 0;
}
for(i = 2; i < argc; i++){
DynStringConcat(parData," ");
DynStringConcat(parData, argv[i]);
}
strcpy(error,"ERROR: ");
if(!readHdbValue(&newValue, GetCharArray(parData),
error+7,512-7)){
SCWrite(pCon,error, eError);
return 0;
}
status = UpdateHipadabaPar(targetNode,newValue,pCon);
ReleaseHdbValue(&newValue);
if(status == 1){
SCSendOK(pCon);
}
return status;
}
/*-----------------------------------------------------------------------------*/
static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]){
@ -1625,6 +1682,59 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
return 1;
}
/*-----------------------------------------------------------------------------*/
static int ZipGetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]){
pHdb targetNode = NULL;
hdbValue newValue;
char error[512], oriPath[512];
int i, status;
int *iData = NULL;
if(argc < 2) {
SCWrite(pCon,"ERROR: need path to node",eError);
return 0;
}
strncpy(oriPath,argv[1], 511);
targetNode = locateSICSNode(pSics,pCon,argv[1]);
if(targetNode == NULL){
return 0;
}
memset(&newValue,0,sizeof(hdbValue));
GetHipadabaPar(targetNode, &newValue, pCon);
switch(newValue.dataType){
case HIPINTAR:
case HIPINTVARAR:
for(i = 0; i < newValue.arrayLength; i++){
newValue.v.intArray[i] = htonl(newValue.v.intArray[i]);
}
SCWriteZipped(pCon,oriPath, newValue.v.intArray,
newValue.arrayLength*sizeof(int));
break;
case HIPFLOATAR:
case HIPFLOATVARAR:
iData = (int *)malloc(newValue.arrayLength*sizeof(int));
if(iData == NULL){
SCWrite(pCon,"ERROR: out of memory in ZipGetHdbNode",eError);
return 0;
}
memset(iData,0,newValue.arrayLength*sizeof(int));
for(i = 0; i < newValue.arrayLength; i++){
iData[i] = htonl((int)newValue.v.floatArray[i]*65536.);
}
SCWriteZipped(pCon,oriPath, iData,
newValue.arrayLength*sizeof(int));
free(iData);
break;
default:
SCWrite(pCon,"ERROR: zipped writing not supported for this datatype",
eError);
return 0;
}
ReleaseHdbValue(&newValue);
return 1;
}
/*--------------------------------------------------------------------------*/
static int countChildren(pHdb node){
pHdb current = NULL;
@ -2150,7 +2260,9 @@ int InstallSICSHipadaba(SConnection *pCon, SicsInterp *pSics, void *pData,
AddCommand(pSics,"hattach", SICSHdbAdapter, NULL, NULL);
AddCommand(pSics,"hdel", DeleteHdbNode, NULL, NULL);
AddCommand(pSics,"hset", SetHdbNode, NULL, NULL);
AddCommand(pSics,"hupdate", UpdateHdbNode, NULL, NULL);
AddCommand(pSics,"hget", GetHdbNode, NULL, NULL);
AddCommand(pSics,"hzipget",ZipGetHdbNode, NULL, NULL);
AddCommand(pSics,"hlist", ListHdbNode, NULL, NULL);
AddCommand(pSics,"hnotify", AutoNotifyHdbNode, NULL, NULL);
AddCommand(pSics,"hdelcb", RemoveHdbCallback, NULL, NULL);

View File

@ -114,7 +114,7 @@ typedef enum _CharType {eSpace, eNum,eeText,eQuote} CharType;
{
TokenList *pList = NULL;
TokenList *pCurrent;
char pBueffel[132];
char pBueffel[256];
char *pChar;
CharType eWhat;
int i, n;
@ -141,7 +141,7 @@ typedef enum _CharType {eSpace, eNum,eeText,eQuote} CharType;
{
i = 0;
pChar++;
while( (isEnd(*pChar) != 2) && (CheckSpecial(pChar) != eQuote))
while( (isEnd(*pChar) != 2) && (CheckSpecial(pChar) != eQuote) && i < 250)
{
if (*pChar == '\\') {
pBueffel[i] = Tcl_Backslash(pChar, &n);