Makefile.am Added cmTextTemplate.c/h cmText.c/h Added CmTextReplaceFirst()
This commit is contained in:
parent
2db35f046a
commit
dd8ef2dbe6
@ -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
|
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
|
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
|
cmHDR += src/libcm/cmLib.h src/libcm/cmText.h src/libcm/cmTextTemplate.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
|
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
|
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
|
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
|
||||||
|
32
cmCtx.h
32
cmCtx.h
@ -3,13 +3,13 @@
|
|||||||
// cmCtx_t is used to hold application supplied cmRpt_t, cmErr_t and
|
// cmCtx_t is used to hold application supplied cmRpt_t, cmErr_t and
|
||||||
// other global values for easy distribution throughtout a cm based application.
|
// 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
|
// to initialize their own internal cmErr_t error class. Likewise classes which
|
||||||
// use a cmLHeapH_t based internal heap manager require application wide memory
|
// use a cmLHeapH_t based internal heap manager require application wide memory
|
||||||
// manager configuration information. The cmCtx_t packages this information and
|
// manager configuration information. The cmCtx_t packages this information and
|
||||||
// allows it to be easily distributed. The applicaton and its constituent objects
|
// 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
|
// 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
|
#ifndef cmCtx_h
|
||||||
@ -24,24 +24,24 @@ extern "C" {
|
|||||||
// cmCtx_t data type.
|
// cmCtx_t data type.
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
cmRpt_t rpt; //< Application supplied global reporter. This reporter is also use by \ref err.
|
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.
|
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 guardByteCnt; // Guard byte count in use by \ref cmMallocDebug.h .
|
||||||
unsigned alignByteCnt; //< Align byte count used by the \ref cmMallocDebug.h
|
unsigned alignByteCnt; // Align byte count used by the \ref cmMallocDebug.h
|
||||||
unsigned mmFlags; //< Initialization flags used by \ref cmMallocDebug.h.
|
unsigned mmFlags; // Initialization flags used by \ref cmMallocDebug.h.
|
||||||
void* userDefPtr; //< Application defined pointer.
|
void* userDefPtr; // Application defined pointer.
|
||||||
} cmCtx_t;
|
} cmCtx_t;
|
||||||
|
|
||||||
// cmCtx_t initialization function.
|
// cmCtx_t initialization function.
|
||||||
void cmCtxSetup(
|
void cmCtxSetup(
|
||||||
cmCtx_t* ctx, //< The cmCtx_t to initialize.
|
cmCtx_t* ctx, // The cmCtx_t to initialize.
|
||||||
const cmChar_t* title, //< The cmCtx_t error label. See cmErrSetup().
|
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 prtFunc, // The printFunc() to assign to the cmCtx_t.rpt.
|
||||||
cmRptPrintFunc_t errFunc, //< The errFunc() to assign to cmCtx_t.rpt.
|
cmRptPrintFunc_t errFunc, // The errFunc() to assign to cmCtx_t.rpt.
|
||||||
void* cbPtr, //< Callback data to use with prtFunc() and errFunc().
|
void* cbPtr, // Callback data to use with prtFunc() and errFunc().
|
||||||
unsigned guardByteCnt,//< Guard byte count used to configure \ref cmMallocDebug.h
|
unsigned guardByteCnt,// Guard byte count used to configure \ref cmMallocDebug.h
|
||||||
unsigned alignByteCnt,//< Align 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
|
unsigned mmFlags // Initialization flags used to configure \ref cmMallocDebug.h
|
||||||
);
|
);
|
||||||
//)
|
//)
|
||||||
//}
|
//}
|
||||||
|
25
cmLex.c
25
cmLex.c
@ -431,7 +431,7 @@ cmLexH cmLexInit( const cmChar_t* cp, unsigned cn, unsigned flags, cmRpt_t* rpt
|
|||||||
|
|
||||||
cmRC_t cmLexFinal( cmLexH* hp )
|
cmRC_t cmLexFinal( cmLexH* hp )
|
||||||
{
|
{
|
||||||
if( hp == NULL )
|
if( hp == NULL || cmLexIsValid(*hp)==false )
|
||||||
return cmOkRC;
|
return cmOkRC;
|
||||||
|
|
||||||
cmLex* p = _cmLexHandleToPtr(*hp);
|
cmLex* p = _cmLexHandleToPtr(*hp);
|
||||||
@ -835,21 +835,18 @@ const cmChar_t* cmLexRcToMsg( unsigned rc )
|
|||||||
// cmLexTest() gives a simple cmLex example.
|
// cmLexTest() gives a simple cmLex example.
|
||||||
//)
|
//)
|
||||||
|
|
||||||
//[
|
//(
|
||||||
void cmLexTest( cmRpt_t* rpt)
|
void cmLexTest( cmRpt_t* rpt)
|
||||||
{
|
{
|
||||||
cmChar_t buf[] =
|
cmChar_t buf[] =
|
||||||
"123ident0\n\
|
"123ident0\n 123.456\nident0\n"
|
||||||
123.456\n\
|
"0xa12+.2\n"
|
||||||
ident0\n\
|
"// comment \n"
|
||||||
0xa12+.2\n\
|
"/* block \n"
|
||||||
// comment \n\
|
"comment */"
|
||||||
/* block \n\
|
"\"quoted string\""
|
||||||
comment */\
|
"ident1"
|
||||||
\"quoted string\"\
|
"// last line comment";
|
||||||
ident1\
|
|
||||||
// last line comment\
|
|
||||||
";
|
|
||||||
|
|
||||||
// initialize a lexer with a buffer of text
|
// initialize a lexer with a buffer of text
|
||||||
cmLexH h = cmLexInit(buf,strlen(buf),
|
cmLexH h = cmLexInit(buf,strlen(buf),
|
||||||
@ -906,5 +903,5 @@ ident1\
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//]
|
//)
|
||||||
//}
|
//}
|
||||||
|
10
cmMem.c
10
cmMem.c
@ -166,6 +166,12 @@ cmMmRC_t _cmMmFreeP( cmMm_t* p, void* dataPtr )
|
|||||||
// if no tracking recd was found
|
// if no tracking recd was found
|
||||||
if( rp == NULL )
|
if( rp == NULL )
|
||||||
return cmErrMsg(&p->err,kMissingRecdMmRC,"Unable to locate a tracking record associated with released data area pointer:%p.",dataPtr);
|
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 this block was already freed then this is a double free
|
||||||
if( cmIsFlag(rp->flags,kFreedMmFl) )
|
if( cmIsFlag(rp->flags,kFreedMmFl) )
|
||||||
@ -437,12 +443,14 @@ void* cmMmAllocate(
|
|||||||
cmMm_t* p = _cmMmHandleToPtr(h);
|
cmMm_t* p = _cmMmHandleToPtr(h);
|
||||||
unsigned newByteCnt = newEleCnt * newEleByteCnt;
|
unsigned newByteCnt = newEleCnt * newEleByteCnt;
|
||||||
void* ndp = _cmMmAllocate(p,orgDataPtr,newByteCnt,flags);
|
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);
|
cmErrMsg(&p->err,kOkMmRC,"Breakpoint for memory allocation id:%i.",p->nextId);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// if we are tracking changes
|
// if we are tracking changes
|
||||||
if( cmIsFlag(p->flags,kTrackMmFl) )
|
if( cmIsFlag(p->flags,kTrackMmFl) )
|
||||||
{
|
{
|
||||||
|
17
cmText.c
17
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 )
|
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)); }
|
{ 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'.
|
// we will go into an endless loop if 't' is contained in 'u' and n > 1.
|
||||||
assert( s!= NULL && t!=NULL && u!=NULL && strstr(u,t) == NULL );
|
assert( s!= NULL && t!=NULL && u!=NULL && (n==1 || strstr(u,t) == NULL) );
|
||||||
|
|
||||||
int tn = strlen(t);
|
int tn = strlen(t);
|
||||||
cmChar_t* c = NULL;
|
cmChar_t* c = NULL;
|
||||||
|
unsigned i = 0;
|
||||||
|
|
||||||
while( (c = strstr(s,t)) != NULL )
|
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);
|
assert(s!=NULL);
|
||||||
|
|
||||||
|
++i;
|
||||||
|
if( n!=cmInvalidCnt && i>=n)
|
||||||
|
break;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return s;
|
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 )
|
cmChar_t* cmTextInsertSN( cmChar_t* s, const cmChar_t* t, const cmChar_t* u, unsigned un )
|
||||||
{
|
{
|
||||||
unsigned n = strlen(s)+1;
|
unsigned n = strlen(s)+1;
|
||||||
|
3
cmText.h
3
cmText.h
@ -170,6 +170,9 @@ extern "C" {
|
|||||||
// Replace all occurrences of t[] with u[] in s[].
|
// Replace all occurrences of t[] with u[] in s[].
|
||||||
cmChar_t* cmTextReplaceAll( cmChar_t* s, const cmChar_t* t, const cmChar_t* u );
|
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[].
|
// Insert u[un] at before t in s[].
|
||||||
cmChar_t* cmTextInsertSN( cmChar_t* s, const cmChar_t* t, const cmChar_t* u, unsigned un );
|
cmChar_t* cmTextInsertSN( cmChar_t* s, const cmChar_t* t, const cmChar_t* u, unsigned un );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user