Explorar el Código

Makefile.am Added cmTextTemplate.c/h cmText.c/h Added CmTextReplaceFirst()

master
kpl hace 12 años
padre
commit
dd8ef2dbe6
Se han modificado 6 ficheros con 61 adiciones y 39 borrados
  1. 5
    2
      Makefile.am
  2. 19
    19
      cmCtx.h
  3. 11
    14
      cmLex.c
  4. 9
    1
      cmMem.c
  5. 14
    3
      cmText.c
  6. 3
    0
      cmText.h

+ 5
- 2
Makefile.am Ver fichero

@@ -9,8 +9,11 @@ cmSRC += src/libcm/cmErr.c src/libcm/cmCtx.c src/libcm/cmRpt.c src/libcm/cmGloba
9 9
 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
10 10
 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
11 11
 
12
-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
13
-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
12
+cmHDR += src/libcm/cmLib.h src/libcm/cmText.h src/libcm/cmTextTemplate.h
13
+cmSRC += src/libcm/cmLib.c src/libcm/cmText.c src/libcm/cmTextTemplate.c
14
+
15
+cmHDR += src/libcm/cmMath.h src/libcm/cmOp.h src/libcm/cmGnuPlot.h src/libcm/cmKeyboard.h
16
+cmSRC += src/libcm/cmMath.c src/libcm/cmOp.c src/libcm/cmGnuPlot.c src/libcm/cmKeyboard.c
14 17
 
15 18
 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
16 19
 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

+ 19
- 19
cmCtx.h Ver fichero

@@ -3,13 +3,13 @@
3 3
 // cmCtx_t is used to hold application supplied cmRpt_t, cmErr_t and
4 4
 // other global values for easy distribution throughtout a cm based application.
5 5
 //
6
-//  Most the cm components need at least an application supplied cmRpt_t function
6
+//  Most the libcm components need at least an application supplied cmRpt_t function
7 7
 //  to initialize their own internal cmErr_t error class.  Likewise classes which
8 8
 //  use a cmLHeapH_t based internal heap manager require application wide memory 
9 9
 // manager configuration information.  The cmCtx_t packages this information and
10 10
 // allows it to be easily distributed.  The applicaton and its constituent objects
11 11
 // then need only maintain and pass pointers to a single cmCtx_t object to have access to 
12
-// this all the global program information.
12
+// all the global program information.
13 13
 //)
14 14
 
15 15
 #ifndef cmCtx_h
@@ -22,26 +22,26 @@ extern "C" {
22 22
   //(
23 23
 
24 24
   // cmCtx_t data type.
25
-typedef struct
26
-{
27
-  cmRpt_t  rpt;           //< Application supplied global reporter. This reporter is also use by \ref err.
28
-  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.
29
-  unsigned guardByteCnt;  //< Guard byte count in use by \ref cmMallocDebug.h .
30
-  unsigned alignByteCnt;  //< Align byte count used by the \ref cmMallocDebug.h
31
-  unsigned mmFlags;       //< Initialization flags used by \ref cmMallocDebug.h.
32
-  void*    userDefPtr;    //< Application defined pointer.
33
-} cmCtx_t;
25
+  typedef struct
26
+  {
27
+    cmRpt_t  rpt;           // Application supplied global reporter. This reporter is also use by \ref err.
28
+    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.
29
+    unsigned guardByteCnt;  // Guard byte count in use by \ref cmMallocDebug.h .
30
+    unsigned alignByteCnt;  // Align byte count used by the \ref cmMallocDebug.h
31
+    unsigned mmFlags;       // Initialization flags used by \ref cmMallocDebug.h.
32
+    void*    userDefPtr;    // Application defined pointer.
33
+  } cmCtx_t;
34 34
 
35 35
   // cmCtx_t initialization function.
36 36
   void cmCtxSetup( 
37
-    cmCtx_t*         ctx,         //< The cmCtx_t to initialize.
38
-    const cmChar_t*  title,       //<  The cmCtx_t error label. See cmErrSetup().
39
-    cmRptPrintFunc_t prtFunc,     //<  The printFunc() to assign to the cmCtx_t.rpt.
40
-    cmRptPrintFunc_t errFunc,     //<  The errFunc() to assign to cmCtx_t.rpt.
41
-    void*            cbPtr,       //<  Callback data to use with prtFunc() and errFunc().
42
-    unsigned         guardByteCnt,//<  Guard byte count used to configure \ref cmMallocDebug.h
43
-    unsigned         alignByteCnt,//<  Align byte count used to configure \ref cmMallocDebug.h
44
-    unsigned         mmFlags      //<  Initialization flags used to configure \ref cmMallocDebug.h
37
+    cmCtx_t*         ctx,         // The cmCtx_t to initialize.
38
+    const cmChar_t*  title,       //  The cmCtx_t error label. See cmErrSetup().
39
+    cmRptPrintFunc_t prtFunc,     //  The printFunc() to assign to the cmCtx_t.rpt.
40
+    cmRptPrintFunc_t errFunc,     //  The errFunc() to assign to cmCtx_t.rpt.
41
+    void*            cbPtr,       //  Callback data to use with prtFunc() and errFunc().
42
+    unsigned         guardByteCnt,//  Guard byte count used to configure \ref cmMallocDebug.h
43
+    unsigned         alignByteCnt,//  Align byte count used to configure \ref cmMallocDebug.h
44
+    unsigned         mmFlags      //  Initialization flags used to configure \ref cmMallocDebug.h
45 45
                    );
46 46
   //)
47 47
   //}

+ 11
- 14
cmLex.c Ver fichero

@@ -431,7 +431,7 @@ cmLexH cmLexInit( const cmChar_t* cp, unsigned cn, unsigned flags, cmRpt_t* rpt
431 431
 
432 432
 cmRC_t cmLexFinal( cmLexH* hp )
433 433
 {
434
-  if( hp == NULL )
434
+  if( hp == NULL || cmLexIsValid(*hp)==false )
435 435
     return cmOkRC;
436 436
 
437 437
   cmLex* p = _cmLexHandleToPtr(*hp);
@@ -835,21 +835,18 @@ const cmChar_t* cmLexRcToMsg( unsigned rc )
835 835
 // cmLexTest() gives a simple cmLex example.
836 836
 //)
837 837
 
838
-//[
838
+//(
839 839
 void cmLexTest( cmRpt_t* rpt)
840 840
 {
841 841
   cmChar_t buf[] =
842
-"123ident0\n\
843
- 123.456\n\
844
-ident0\n\
845
-0xa12+.2\n\
846
-// comment \n\
847
-/* block \n\
848
-comment */\
849
-\"quoted string\"\
850
-ident1\
851
-// last line comment\
852
-";
842
+"123ident0\n 123.456\nident0\n"
843
+"0xa12+.2\n"
844
+"// comment \n"
845
+"/* block \n"
846
+"comment */"
847
+"\"quoted string\""
848
+"ident1"
849
+"// last line comment";
853 850
 
854 851
   // initialize a lexer with a buffer of text
855 852
   cmLexH h = cmLexInit(buf,strlen(buf),
@@ -906,5 +903,5 @@ ident1\
906 903
 
907 904
 }
908 905
 
909
-//]
906
+//)
910 907
 //}

+ 9
- 1
cmMem.c Ver fichero

@@ -166,6 +166,12 @@ cmMmRC_t _cmMmFreeP( cmMm_t* p, void* dataPtr )
166 166
     // if no tracking recd was found
167 167
     if( rp == NULL )
168 168
       return cmErrMsg(&p->err,kMissingRecdMmRC,"Unable to locate a tracking record associated with released data area pointer:%p.",dataPtr);
169
+    /*
170
+    if( rp->uniqueId == 176690 )
171
+    {
172
+      cmErrMsg(&p->err,kOkMmRC,"Breakpoint for memory free id:%i.",rp->uniqueId);
173
+    }
174
+    */
169 175
 
170 176
     // if this block was already freed then this is a double free
171 177
     if( cmIsFlag(rp->flags,kFreedMmFl) )
@@ -437,12 +443,14 @@ void* cmMmAllocate(
437 443
    cmMm_t*  p          = _cmMmHandleToPtr(h); 
438 444
    unsigned newByteCnt = newEleCnt * newEleByteCnt;
439 445
    void*    ndp        = _cmMmAllocate(p,orgDataPtr,newByteCnt,flags);
446
+   
440 447
    /*
441
-   if( p->nextId == 1575 )
448
+   if( p->nextId == 189114 )
442 449
    {
443 450
      cmErrMsg(&p->err,kOkMmRC,"Breakpoint for memory allocation id:%i.",p->nextId);
444 451
    }
445 452
    */
453
+
446 454
    // if we are tracking changes
447 455
    if( cmIsFlag(p->flags,kTrackMmFl) )
448 456
    {

+ 14
- 3
cmText.c Ver fichero

@@ -522,13 +522,14 @@ cmChar_t* cmTextReplaceSN( cmChar_t* s, const cmChar_t* t, unsigned tn, const cm
522 522
 cmChar_t* cmTextReplaceS( cmChar_t* s, const cmChar_t* t, unsigned tn, const cmChar_t* u )
523 523
 { return cmTextReplaceSN(s,t,tn,u,u==NULL ? 0 : strlen(u)); }
524 524
 
525
-cmChar_t* cmTextReplaceAll( cmChar_t* s, const cmChar_t* t, const cmChar_t* u )
525
+cmChar_t* _cmTextReplace( cmChar_t* s, const cmChar_t* t, const cmChar_t* u, unsigned n )
526 526
 {
527
-  // we will go into an endless loop if 't' is contained in 'u'.
528
-  assert( s!= NULL && t!=NULL && u!=NULL && strstr(u,t) == NULL );
527
+  // we will go into an endless loop if 't' is contained in 'u' and n > 1.
528
+  assert( s!= NULL && t!=NULL && u!=NULL && (n==1 || strstr(u,t) == NULL) );
529 529
 
530 530
   int       tn = strlen(t);
531 531
   cmChar_t* c  = NULL;
532
+  unsigned  i  = 0;
532 533
 
533 534
   while( (c = strstr(s,t)) != NULL ) 
534 535
   {
@@ -536,11 +537,21 @@ cmChar_t* cmTextReplaceAll( cmChar_t* s, const cmChar_t* t, const cmChar_t* u )
536 537
 
537 538
     assert(s!=NULL);
538 539
 
540
+    ++i;
541
+    if( n!=cmInvalidCnt && i>=n)
542
+      break;
543
+
539 544
   };
540 545
 
541 546
   return s;
542 547
 }
543 548
 
549
+cmChar_t* cmTextReplaceAll( cmChar_t* s, const cmChar_t* t, const cmChar_t* u )
550
+{ return _cmTextReplace(s,t,u,cmInvalidCnt); }
551
+
552
+cmChar_t* cmTextReplaceFirst( cmChar_t* s, const cmChar_t* t, const cmChar_t* u )
553
+{ return _cmTextReplace(s,t,u,1); }
554
+
544 555
 cmChar_t* cmTextInsertSN(  cmChar_t* s, const cmChar_t* t, const cmChar_t* u, unsigned un )
545 556
 {
546 557
   unsigned n = strlen(s)+1;

+ 3
- 0
cmText.h Ver fichero

@@ -169,6 +169,9 @@ extern "C" {
169 169
   
170 170
   // Replace all occurrences of t[] with u[] in s[].
171 171
   cmChar_t* cmTextReplaceAll( cmChar_t* s, const cmChar_t* t, const cmChar_t* u );
172
+  
173
+  // Replace the first occurence of t[] in s[] with u[].
174
+  cmChar_t* cmTextReplaceFirst( cmChar_t* s, const cmChar_t* t, const cmChar_t* u );
172 175
 
173 176
   // Insert u[un] at before t in s[].
174 177
   cmChar_t* cmTextInsertSN(  cmChar_t* s, const cmChar_t* t, const cmChar_t* u, unsigned un );

Loading…
Cancelar
Guardar