diff --git a/Makefile.am b/Makefile.am index 982bd72..d06cfa7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,8 +9,11 @@ cmSRC += src/libcm/cmErr.c src/libcm/cmCtx.c src/libcm/cmRpt.c src/libcm/cmGloba cmHDR += src/libcm/cmSerialize.h src/libcm/cmSymTbl.h src/libcm/cmFileSys.h src/libcm/cmFile.h src/libcm/cmMem.h src/libcm/cmTime.h src/libcm/cmPgmOpts.h cmSRC += src/libcm/cmSerialize.c src/libcm/cmSymTbl.c src/libcm/cmFileSys.c src/libcm/cmFile.c src/libcm/cmMem.c src/libcm/cmTime.c src/libcm/cmPgmOpts.c -cmHDR += src/libcm/cmLib.h src/libcm/cmText.h src/libcm/cmMath.h src/libcm/cmOp.h src/libcm/cmGnuPlot.h src/libcm/cmKeyboard.h -cmSRC += src/libcm/cmLib.c src/libcm/cmText.c src/libcm/cmMath.c src/libcm/cmOp.c src/libcm/cmGnuPlot.c src/libcm/cmKeyboard.c +cmHDR += src/libcm/cmLib.h src/libcm/cmText.h src/libcm/cmTextTemplate.h +cmSRC += src/libcm/cmLib.c src/libcm/cmText.c src/libcm/cmTextTemplate.c + +cmHDR += src/libcm/cmMath.h src/libcm/cmOp.h src/libcm/cmGnuPlot.h src/libcm/cmKeyboard.h +cmSRC += src/libcm/cmMath.c src/libcm/cmOp.c src/libcm/cmGnuPlot.c src/libcm/cmKeyboard.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 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 diff --git a/cmCtx.h b/cmCtx.h index bc41128..fc89c10 100644 --- a/cmCtx.h +++ b/cmCtx.h @@ -3,13 +3,13 @@ // cmCtx_t is used to hold application supplied cmRpt_t, cmErr_t and // other global values for easy distribution throughtout a cm based application. // -// Most the cm components need at least an application supplied cmRpt_t function +// Most the libcm components need at least an application supplied cmRpt_t function // to initialize their own internal cmErr_t error class. Likewise classes which // use a cmLHeapH_t based internal heap manager require application wide memory // manager configuration information. The cmCtx_t packages this information and // allows it to be easily distributed. The applicaton and its constituent objects // then need only maintain and pass pointers to a single cmCtx_t object to have access to -// this all the global program information. +// all the global program information. //) #ifndef cmCtx_h @@ -22,26 +22,26 @@ extern "C" { //( // cmCtx_t data type. -typedef struct -{ - cmRpt_t rpt; //< Application supplied global reporter. This reporter is also use by \ref err. - cmErr_t err; //< Application error reporter which can be used to report errors prior to the client object being initialized to the point where it can use it's own cmErr_t. - unsigned guardByteCnt; //< Guard byte count in use by \ref cmMallocDebug.h . - unsigned alignByteCnt; //< Align byte count used by the \ref cmMallocDebug.h - unsigned mmFlags; //< Initialization flags used by \ref cmMallocDebug.h. - void* userDefPtr; //< Application defined pointer. -} cmCtx_t; + typedef struct + { + cmRpt_t rpt; // Application supplied global reporter. This reporter is also use by \ref err. + cmErr_t err; // Application error reporter which can be used to report errors prior to the client object being initialized to the point where it can use it's own cmErr_t. + unsigned guardByteCnt; // Guard byte count in use by \ref cmMallocDebug.h . + unsigned alignByteCnt; // Align byte count used by the \ref cmMallocDebug.h + unsigned mmFlags; // Initialization flags used by \ref cmMallocDebug.h. + void* userDefPtr; // Application defined pointer. + } cmCtx_t; // cmCtx_t initialization function. void cmCtxSetup( - cmCtx_t* ctx, //< The cmCtx_t to initialize. - const cmChar_t* title, //< The cmCtx_t error label. See cmErrSetup(). - cmRptPrintFunc_t prtFunc, //< The printFunc() to assign to the cmCtx_t.rpt. - cmRptPrintFunc_t errFunc, //< The errFunc() to assign to cmCtx_t.rpt. - void* cbPtr, //< Callback data to use with prtFunc() and errFunc(). - unsigned guardByteCnt,//< Guard byte count used to configure \ref cmMallocDebug.h - unsigned alignByteCnt,//< Align byte count used to configure \ref cmMallocDebug.h - unsigned mmFlags //< Initialization flags used to configure \ref cmMallocDebug.h + cmCtx_t* ctx, // The cmCtx_t to initialize. + const cmChar_t* title, // The cmCtx_t error label. See cmErrSetup(). + cmRptPrintFunc_t prtFunc, // The printFunc() to assign to the cmCtx_t.rpt. + cmRptPrintFunc_t errFunc, // The errFunc() to assign to cmCtx_t.rpt. + void* cbPtr, // Callback data to use with prtFunc() and errFunc(). + unsigned guardByteCnt,// Guard byte count used to configure \ref cmMallocDebug.h + unsigned alignByteCnt,// Align byte count used to configure \ref cmMallocDebug.h + unsigned mmFlags // Initialization flags used to configure \ref cmMallocDebug.h ); //) //} diff --git a/cmLex.c b/cmLex.c index fe80463..f938c50 100644 --- a/cmLex.c +++ b/cmLex.c @@ -431,7 +431,7 @@ cmLexH cmLexInit( const cmChar_t* cp, unsigned cn, unsigned flags, cmRpt_t* rpt cmRC_t cmLexFinal( cmLexH* hp ) { - if( hp == NULL ) + if( hp == NULL || cmLexIsValid(*hp)==false ) return cmOkRC; cmLex* p = _cmLexHandleToPtr(*hp); @@ -835,21 +835,18 @@ const cmChar_t* cmLexRcToMsg( unsigned rc ) // cmLexTest() gives a simple cmLex example. //) -//[ +//( void cmLexTest( cmRpt_t* rpt) { cmChar_t buf[] = -"123ident0\n\ - 123.456\n\ -ident0\n\ -0xa12+.2\n\ -// comment \n\ -/* block \n\ -comment */\ -\"quoted string\"\ -ident1\ -// last line comment\ -"; +"123ident0\n 123.456\nident0\n" +"0xa12+.2\n" +"// comment \n" +"/* block \n" +"comment */" +"\"quoted string\"" +"ident1" +"// last line comment"; // initialize a lexer with a buffer of text cmLexH h = cmLexInit(buf,strlen(buf), @@ -906,5 +903,5 @@ ident1\ } -//] +//) //} diff --git a/cmMem.c b/cmMem.c index 4e3738d..1f0a42a 100644 --- a/cmMem.c +++ b/cmMem.c @@ -166,6 +166,12 @@ cmMmRC_t _cmMmFreeP( cmMm_t* p, void* dataPtr ) // if no tracking recd was found if( rp == NULL ) return cmErrMsg(&p->err,kMissingRecdMmRC,"Unable to locate a tracking record associated with released data area pointer:%p.",dataPtr); + /* + if( rp->uniqueId == 176690 ) + { + cmErrMsg(&p->err,kOkMmRC,"Breakpoint for memory free id:%i.",rp->uniqueId); + } + */ // if this block was already freed then this is a double free if( cmIsFlag(rp->flags,kFreedMmFl) ) @@ -437,12 +443,14 @@ void* cmMmAllocate( cmMm_t* p = _cmMmHandleToPtr(h); unsigned newByteCnt = newEleCnt * newEleByteCnt; void* ndp = _cmMmAllocate(p,orgDataPtr,newByteCnt,flags); + /* - if( p->nextId == 1575 ) + if( p->nextId == 189114 ) { cmErrMsg(&p->err,kOkMmRC,"Breakpoint for memory allocation id:%i.",p->nextId); } */ + // if we are tracking changes if( cmIsFlag(p->flags,kTrackMmFl) ) { diff --git a/cmText.c b/cmText.c index f88ce49..8922193 100644 --- a/cmText.c +++ b/cmText.c @@ -522,13 +522,14 @@ cmChar_t* cmTextReplaceSN( cmChar_t* s, const cmChar_t* t, unsigned tn, const cm cmChar_t* cmTextReplaceS( cmChar_t* s, const cmChar_t* t, unsigned tn, const cmChar_t* u ) { return cmTextReplaceSN(s,t,tn,u,u==NULL ? 0 : strlen(u)); } -cmChar_t* cmTextReplaceAll( cmChar_t* s, const cmChar_t* t, const cmChar_t* u ) +cmChar_t* _cmTextReplace( cmChar_t* s, const cmChar_t* t, const cmChar_t* u, unsigned n ) { - // we will go into an endless loop if 't' is contained in 'u'. - assert( s!= NULL && t!=NULL && u!=NULL && strstr(u,t) == NULL ); + // we will go into an endless loop if 't' is contained in 'u' and n > 1. + assert( s!= NULL && t!=NULL && u!=NULL && (n==1 || strstr(u,t) == NULL) ); int tn = strlen(t); cmChar_t* c = NULL; + unsigned i = 0; while( (c = strstr(s,t)) != NULL ) { @@ -536,11 +537,21 @@ cmChar_t* cmTextReplaceAll( cmChar_t* s, const cmChar_t* t, const cmChar_t* u ) assert(s!=NULL); + ++i; + if( n!=cmInvalidCnt && i>=n) + break; + }; return s; } +cmChar_t* cmTextReplaceAll( cmChar_t* s, const cmChar_t* t, const cmChar_t* u ) +{ return _cmTextReplace(s,t,u,cmInvalidCnt); } + +cmChar_t* cmTextReplaceFirst( cmChar_t* s, const cmChar_t* t, const cmChar_t* u ) +{ return _cmTextReplace(s,t,u,1); } + cmChar_t* cmTextInsertSN( cmChar_t* s, const cmChar_t* t, const cmChar_t* u, unsigned un ) { unsigned n = strlen(s)+1; diff --git a/cmText.h b/cmText.h index c4b8b73..3e4d521 100644 --- a/cmText.h +++ b/cmText.h @@ -169,6 +169,9 @@ extern "C" { // Replace all occurrences of t[] with u[] in s[]. cmChar_t* cmTextReplaceAll( cmChar_t* s, const cmChar_t* t, const cmChar_t* u ); + + // Replace the first occurence of t[] in s[] with u[]. + cmChar_t* cmTextReplaceFirst( cmChar_t* s, const cmChar_t* t, const cmChar_t* u ); // Insert u[un] at before t in s[]. cmChar_t* cmTextInsertSN( cmChar_t* s, const cmChar_t* t, const cmChar_t* u, unsigned un );