cmXml.h/c, Makefile.am : Initial, incomplete, implementation of cmXml.h/c.

This commit is contained in:
Kevin Larke 2015-12-09 12:44:51 -05:00
parent 31d71cb5f1
commit 1c9e28bcfb
3 changed files with 146 additions and 2 deletions

View File

@ -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 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 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 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/cmPrefs.c src/libcm/cmStack.c src/libcm/cmArray.c 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 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 cmSRC += src/libcm/cmUdpPort.c src/libcm/cmUdpNet.c src/libcm/cmVirtNet.c

96
cmXml.c Normal file
View File

@ -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 )
{
}

48
cmXml.h Normal file
View File

@ -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