From 778e95cb1fee27da99b803f1e36893b3638e922a Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 23 May 2013 14:09:47 -0700 Subject: [PATCH] cmDspSys.h/c: Completed and tested cmDspRsrcWriteString(). --- dsp/cmDspSys.c | 41 +++++++++++++++++++++++++++++++++-------- dsp/cmDspSys.h | 1 + 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/dsp/cmDspSys.c b/dsp/cmDspSys.c index 2bb6da3..d5834f8 100644 --- a/dsp/cmDspSys.c +++ b/dsp/cmDspSys.c @@ -1870,8 +1870,12 @@ cmDspRC_t _cmDspRsrcWritePath( cmDspSysH_t h, cmChar_t** pathStrRef, cmChar_t** break; if( prevStr != NULL ) - path = cmTextAppendSS(path,"/"); - path = cmTextAppendSS(path,prevStr); + { + if( path != NULL ) + path = cmTextAppendSS(path,"/"); + + path = cmTextAppendSS(path,prevStr); + } prevStr = str; } @@ -2333,21 +2337,42 @@ cmDspRC_t cmDspRsrcStringArray( cmDspSysH_t h, unsigned* np, const cmChar_t*** v return rc; } +cmDspRC_t _cmDspWritePathAndParent( cmDspSysH_t h, cmChar_t** pathRef, cmChar_t** varLabelRef, cmJsonNode_t** parentRef, va_list vl ) +{ + cmDsp_t* p = _cmDspHandleToPtr(h); + cmJsonH_t jsH = cmDspSysPgmRsrcHandle(h); + cmDspRC_t rc; + + if((rc = _cmDspRsrcWritePath(h,pathRef,varLabelRef,vl)) != kOkDspRC ) + goto errLabel; + + if( *pathRef == NULL ) + *parentRef = cmJsonRoot(jsH); + else + *parentRef = cmJsonFindPathValue( jsH, *pathRef, cmJsonRoot(jsH), kPairTId ); + + if( *parentRef == NULL ) + { + rc = cmErrMsg(&p->err,kJsonFailDspRC,"The parent object '%s' for variable '%s' could not be found.",cmStringNullGuard(*pathRef),cmStringNullGuard(*varLabelRef)); + goto errLabel; + } + + errLabel: + return rc; +} + cmDspRC_t cmDspRsrcWriteStringV( cmDspSysH_t h, const cmChar_t* v, va_list vl ) { cmDsp_t* p = _cmDspHandleToPtr(h); - cmChar_t* pathStr = NULL; - cmChar_t* varStr = NULL; cmJsonH_t jsH = cmDspSysPgmRsrcHandle(h); + cmChar_t* varStr = NULL; + cmChar_t* pathStr = NULL; cmJsonNode_t* parentObjNodePtr = NULL; cmDspRC_t rc; - if((rc = _cmDspRsrcWritePath(h,&pathStr,&varStr,vl)) != kOkDspRC ) + if((rc = _cmDspWritePathAndParent(h, &pathStr, &varStr, &parentObjNodePtr, vl )) != kOkDspRC ) goto errLabel; - if((parentObjNodePtr = cmJsonFindPathValue( jsH, pathStr, cmJsonRoot(jsH), kPairTId )) == NULL ) - rc = cmErrMsg(&p->err,kJsonFailDspRC,"The parent object '%s' for variable '%s' could not be found.",cmStringNullGuard(pathStr),cmStringNullGuard(varStr)); - if( cmJsonInsertOrReplacePairString( jsH, parentObjNodePtr, varStr, kStringTId, v ) != kOkJsRC ) rc = cmErrMsg(&p->err,kJsonFailDspRC,"Write 'string' resource value failed for path '%s' and variable '%s'",cmStringNullGuard(pathStr),cmStringNullGuard(varStr)); diff --git a/dsp/cmDspSys.h b/dsp/cmDspSys.h index 523d5df..45d3d3c 100644 --- a/dsp/cmDspSys.h +++ b/dsp/cmDspSys.h @@ -268,6 +268,7 @@ extern "C" { cmDspRC_t cmDspRsrcWriteStringV( cmDspSysH_t h, const cmChar_t* v, va_list vl ); + cmDspRC_t cmDspRsrcWriteString( cmDspSysH_t h, const cmChar_t* v, ... );