From faec15b5f6b409b7fdad20854dd40ba8d669915a Mon Sep 17 00:00:00 2001 From: koennecke Date: Fri, 2 Feb 2007 05:48:07 +0000 Subject: [PATCH] - Some fixes to the hipadaba code. SKIPPED: psi/libpsi.a psi/hardsup/libhlib.a psi/tecs/libtecsl.a --- matrix/libmatrix.a | Bin 45884 -> 45884 bytes mcstas/dmc/vdmcstatus.tcl | 8 +-- outcode.c | 2 + sicshipadaba.c | 110 ++++++++++++++++++++++++-------------- 4 files changed, 77 insertions(+), 43 deletions(-) diff --git a/matrix/libmatrix.a b/matrix/libmatrix.a index 23564feb247f02608ef939ead1d897af7e225077..9d6aa14e0e56a51eff47c006dbd9517b5c95ac28 100644 GIT binary patch delta 216 zcmdn z4=z_OzPZsbTL8{i7T?V2l+BOeOKhGL_=y+Bf7d0xd13ryZWvz=s6H_JI+Sm+S+9JT mFhtG-=ny$BD0}j|E{V-rQ>~ErKzrw(hq}=OET6aX947!7C_x1P delta 216 zcmdndBy=HP@1Ox9Bt+pNR$M+~MwPuYwQ zE>|wTxzR9N0M1ty-^}Th&5z(qY@QVOi5JFy*CoDrVfpSics, "protocol","Protocol"); ProtocolGet(pCon, pData, proName, 128); if (strcmp(proName, "json") == 0) - return 1; + return json_protocol; else - return 0; + return normal_protocol; } -int formatNameValue(int jsonSet, char *name, char *value, pDynString result) { - if (name == NULL) { - if (jsonSet) { - } else { - } - } else if (value == NULL) { - if (jsonSet) { - DynStringInsert(result,"\": ", 0); - DynStringInsert(result,name,0); - DynStringInsert(result,"{\"", 0); - DynStringConcat(result,"}"); - } else { - DynStringInsert(result," =",0); - DynStringInsert(result,name,0); - } - } else { - if (jsonSet) { - DynStringCopy(result,"{\""); - DynStringConcat(result,name); - DynStringConcat(result,"\": "); - DynStringConcat(result,value); - DynStringConcat(result,"}"); - } else { +/* Format a name,value pair according to the given protocol */ +int formatNameValue(Protocol protocol, char *name, char *value, pDynString result, int hdtype) { + char *char_arr, *ptr; + + switch(protocol) { + case normal_protocol: DynStringCopy(result,name); DynStringConcat(result," = "); DynStringConcat(result,value); + break; + case json_protocol: + switch(hdtype){ + case HIPNONE: + break; + case HIPINT: + case HIPFLOAT: + DynStringCopy(result,"{\""); + DynStringConcat(result,name); + DynStringConcat(result,"\": "); + DynStringConcat(result,value); + DynStringConcat(result,"}"); + break; + case HIPTEXT: + DynStringCopy(result,"{\""); + DynStringConcat(result,name); + DynStringConcat(result,"\": \""); + DynStringConcat(result,value); + DynStringConcat(result,"\"}"); + break; + case HIPINTAR: + case HIPINTVARAR: + case HIPFLOATAR: + case HIPFLOATVARAR: + char_arr = ptr = strdup(trim(value)); + while(*ptr != '\0') { + if (isspace(*ptr)) + *ptr=','; + ptr++; + } + DynStringCopy(result,"{\""); + DynStringConcat(result,name); + DynStringConcat(result,"\": [ "); + DynStringConcat(result,char_arr); + DynStringConcat(result," ]}"); + if (char_arr != NULL ) free(char_arr); + break; + } } - } - return jsonSet; + return protocol; } /*----------------------------------------------------------------------------------------*/ @@ -203,7 +228,8 @@ static int SICSNotifyCallback(void *userData, void *callData, pHdb node, pDynString printedData = NULL; pDynString result = NULL; char *pPath = NULL; - int protocol = 0, outCode; + Protocol protocol = normal_protocol; + int outCode; cbInfo = (HdbCBInfo *)userData; pPath = GetHipadabaPath(node); @@ -224,12 +250,12 @@ static int SICSNotifyCallback(void *userData, void *callData, pHdb node, */ return 1; } - formatNameValue(protocol, pPath, GetCharArray(printedData), result); + formatNameValue(protocol, pPath, GetCharArray(printedData), result, v.dataType); SCWriteInContext(cbInfo->pCon,GetCharArray(result), outCode,cbInfo->context); DeleteDynString(printedData); } else { - formatNameValue(protocol,"!!datachange!!", pPath, result); + formatNameValue(protocol, pPath,"!!datachange!!", result, HIPTEXT); SCWriteInContext(cbInfo->pCon,GetCharArray(result), outCode,cbInfo->context); } @@ -256,7 +282,8 @@ static int TreeChangeCallback(void *userData, void *callData, pHdb node, char *path = NULL; char buffer[1024]; pDynString result = NULL; - int protocol = 0, outCode; + Protocol protocol = normal_protocol; + int outCode; result = CreateDynString(128,128); HdbCBInfo *cbInfo = (HdbCBInfo *)userData; @@ -267,7 +294,7 @@ static int TreeChangeCallback(void *userData, void *callData, pHdb node, outCode = eHdbEvent; else outCode = eEvent; - formatNameValue(protocol, "treechange", path, result); + formatNameValue(protocol, "treechange", path, result, v.dataType); SCWriteInContext(cbInfo->pCon,GetCharArray(result),outCode,cbInfo->context); DeleteDynString(result); free(path); @@ -1152,7 +1179,6 @@ void SaveSICSHipadaba(FILE *fd, pHdb node, char *prefix){ currentChild = node->child; while(currentChild != NULL){ if(currentChild->value.dataType != HIPNONE && !isSICSHdbRO(currentChild)){ - GetHipadabaPar(currentChild,&v,NULL); data = formatValue(currentChild->value); if(data != NULL){ fprintf(fd,"%s%s %s\n", prefix, currentChild->name, GetCharArray(data)); @@ -1742,10 +1768,11 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]){ pHdb targetNode = NULL; hdbValue newValue; - pDynString parData = NULL; + pDynString parData = NULL, result = NULL; char error[512], oriPath[512];; int i, status; - int protocol = 0, outCode; + Protocol protocol = normal_protocol; + int outCode; if(argc < 2) { SCWrite(pCon,"ERROR: need path to node to print",eError); @@ -1769,9 +1796,11 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, else outCode = eEvent; - formatNameValue(protocol, oriPath, NULL, parData); - SCWrite(pCon,GetCharArray(parData),outCode); + result = CreateDynString(128,128); + formatNameValue(protocol, oriPath, GetCharArray(parData), result, newValue.dataType); + SCWrite(pCon,GetCharArray(result),outCode); DeleteDynString(parData); + DeleteDynString(result); ReleaseHdbValue(&newValue); return 1; @@ -2075,7 +2104,8 @@ static int ListHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, pHdb node = NULL; int pathArg = 1; pDynString listData = NULL; - int protocol = 0, outCode; + Protocol protocol = normal_protocol; + int outCode; if(argc < 2) { SCWrite(pCon,"ERROR: need path to node to print",eError);