From 1c9e28bcfbca720c19bb181958d04cc0afe65b22 Mon Sep 17 00:00:00 2001 From: Kevin Larke Date: Wed, 9 Dec 2015 12:44:51 -0500 Subject: [PATCH] cmXml.h/c, Makefile.am : Initial, incomplete, implementation of cmXml.h/c. --- Makefile.am | 4 +-- cmXml.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++ cmXml.h | 48 +++++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 cmXml.c create mode 100644 cmXml.h diff --git a/Makefile.am b/Makefile.am index 3fc4ff1..12c1567 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,8 +18,8 @@ cmSRC += src/libcm/cmData.c src/libcm/cmLib.c src/libcm/cmText.c src/libcm/cmTex cmHDR += src/libcm/cmMath.h src/libcm/cmGnuPlot.h src/libcm/cmKeyboard.h src/libcm/cmStrStream.h cmSRC += src/libcm/cmMath.c src/libcm/cmGnuPlot.c src/libcm/cmKeyboard.c src/libcm/cmStrStream.c -cmHDR += src/libcm/cmLinkedHeap.h src/libcm/cmMallocDebug.h src/libcm/cmLex.h src/libcm/cmJson.h src/libcm/cmPrefs.h src/libcm/cmStack.h src/libcm/cmArray.h -cmSRC += src/libcm/cmLinkedHeap.c src/libcm/cmMallocDebug.c src/libcm/cmLex.c src/libcm/cmJson.c src/libcm/cmPrefs.c src/libcm/cmStack.c src/libcm/cmArray.c +cmHDR += src/libcm/cmLinkedHeap.h src/libcm/cmMallocDebug.h src/libcm/cmLex.h src/libcm/cmJson.h src/libcm/cmXml.h src/libcm/cmPrefs.h src/libcm/cmStack.h src/libcm/cmArray.h +cmSRC += src/libcm/cmLinkedHeap.c src/libcm/cmMallocDebug.c src/libcm/cmLex.c src/libcm/cmJson.c src/libcm/cmXml.c src/libcm/cmPrefs.c src/libcm/cmStack.c src/libcm/cmArray.c cmHDR += src/libcm/cmUdpPort.h src/libcm/cmUdpNet.h src/libcm/cmVirtNet.h cmSRC += src/libcm/cmUdpPort.c src/libcm/cmUdpNet.c src/libcm/cmVirtNet.c diff --git a/cmXml.c b/cmXml.c new file mode 100644 index 0000000..63596ea --- /dev/null +++ b/cmXml.c @@ -0,0 +1,96 @@ +#include "cmPrefix.h" +#include "cmGlobal.h" +#include "cmFloatTypes.h" +#include "cmRpt.h" +#include "cmErr.h" +#include "cmCtx.h" +#include "cmJson.h" +#include "cmMem.h" +#include "cmMallocDebug.h" +#include "cmLex.h" +#include "cmLinkedHeap.h" +#include "cmFile.h" +#include "cmXml.h" + +cmXmlH_t cmXmlNullHandle = cmSTATIC_NULL_HANDLE; + +typedef struct +{ + cmErr_t err; // + cmLHeapH_t heapH; // linked heap stores all node memory + cmXmlNode_t* root; +} cmXml_t; + +cmXml_t* _cmXmlHandleToPtr( cmXmlH_t h ) +{ + cmXml_t* p = (cmXml_t*)h.h; + assert( p != NULL ); + return p; +} + +cmXmlRC_t _cmXmlFree( cmXml_t* p ) +{ + // free the internal heap object + cmLHeapDestroy( &p->heapH ); + +} + +cmXmlRC_t cmXmlAlloc( cmCtx_t* ctx, cmXmlH_t* hp, const cmChar_t* fn ) +{ + cmXmlRC_t rc = kOkXmlRC; + cmXml_t* p = NULL; + + // finalize before initialize + if((rc = cmXmlFree(hp)) != kOkJsRC ) + return rc; + + // allocate the main object record + if((p = cmMemAllocZ( cmXml_t, 1 )) == NULL ) + return cmErrMsg(&ctx->err,kMemAllocErrXmlRC,"Object memory allocation failed."); + + cmErrSetup(&p->err,&ctx->rpt,"XML Parser"); + + // allocate the linked heap mgr + if( cmLHeapIsValid(p->heapH = cmLHeapCreate(1024,ctx)) == false ) + { + rc = cmErrMsg(&p->err,kMemAllocErrXmlRC,"Linked heap object allocation failed."); + goto errLabel; + } + + hp->h = p; + + errLabel: + if(rc != kOkXmlRC ) + _cmXmlFree(p); + + return rc; +} + +cmXmlRC_t cmXmlFree( cmXmlH_t* hp ) +{ + cmXmlRC_t rc = kOkXmlRC; + + if( hp!=NULL || cmXmlIsValid(*hp)==false ) + return kOkXmlRC; + + cmXml_t* p = _cmXmlHandleToPtr(*hp); + + if((rc = _cmXmlFree(p)) != kOkXmlRC ) + return rc; + + hp->h = NULL; + + return rc; +} + +bool cmXmlIsValid( cmXmlH_t h ) +{ return h.h != NULL; } + + +cmXmlRC_t cmXmlParse( cmXmlH_t h, const cmChar_t* fn ) +{ +} + +cmXmlRC_t cmXmlClear( cmXmlH_t h ) +{ +} diff --git a/cmXml.h b/cmXml.h new file mode 100644 index 0000000..ee9211d --- /dev/null +++ b/cmXml.h @@ -0,0 +1,48 @@ +#ifndef cmXml_h +#define cmXml_h + +#ifdef __cpluspus +extern "C" { +#endif + + enum + { + kOkXmlRC = cmOkRC, + kMemAllocErrXmlRC, + kLHeapXmlRC + }; + + typedef struct cmXmlAttr_str + { + const cmChar_t* label; + const cmChar_t* value; + struct cmXmlAttr_str* link; + } cmXmlAttr_t; + + typedef struct cmXmlNode_str + { + struct cmXmlNode_str* parent; + struct cmXmlNode_str* children; + struct cmXmlNode_str* sibling; + cmXmlAttr_t* attr; + } cmXmlNode_t; + + typedef cmHandle_t cmXmlH_t; + typedef cmRC_t cmXmlRC_t; + + extern cmXmlH_t cmXmlNullHandle; + + cmXmlRC_t cmXmlAlloc( cmCtx_t* ctx, cmXmlH_t* hh, const cmChar_t* fn ); + cmXmlRC_t cmXmlFree( cmXmlH_t* hh ); + bool cmXmlIsValid( cmXmlH_t h ); + + cmXmlRC_t cmXmlParse( cmXmlH_t h, const cmChar_t* fn ); + cmXmlRC_t cmXmlClear( cmXmlH_t h ); + + + +#ifdef __cpluspus +} +#endif + +#endif