From 1a4bdf74279f79f21283bf83ec521c062c9131bf Mon Sep 17 00:00:00 2001 From: Maurilio Longo Date: Thu, 8 Jun 2000 20:08:37 +0000 Subject: [PATCH] 20000608-22:10 GMT+2 Maurilio Longo --- harbour/ChangeLog | 10 ++++++ harbour/contrib/msql/dbf2msql.prg | 2 ++ harbour/source/rtl/teditor.prg | 6 ++-- harbour/source/rtl/teditorl.c | 52 ++++++++++++++++++++++++------- 4 files changed, 56 insertions(+), 14 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index c20458392a..3ae17cd418 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,13 @@ +20000608-22:10 GMT+2 Maurilio Longo + + * source/rtl/teditorl.c + + added __StrTkPtr() function to scan a string starting from a defined position instead + of restarting every time from beginning and scanning it completely till next token. + * source/rtl/tedior.prg + * changed to use __StrTkPtr() instead of __StrToken(). It is a LOT faster loading big files. + * contrib/msql/dbf2msql.prg + ! fixed memory leak due to resources not released + 2000-06-07 22:50 UTC-0800 Ron Pinkas * source/compiler/harbour.c diff --git a/harbour/contrib/msql/dbf2msql.prg b/harbour/contrib/msql/dbf2msql.prg index fe120823fe..b2262e9c9b 100644 --- a/harbour/contrib/msql/dbf2msql.prg +++ b/harbour/contrib/msql/dbf2msql.prg @@ -135,6 +135,8 @@ procedure main(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11) enddo dbffile->(dbCloseArea()) + oTable:Destroy() + oServer:Destroy() return diff --git a/harbour/source/rtl/teditor.prg b/harbour/source/rtl/teditor.prg index 680f6cc4df..fd0f1d9811 100644 --- a/harbour/source/rtl/teditor.prg +++ b/harbour/source/rtl/teditor.prg @@ -97,7 +97,7 @@ ENDCLASS STATIC function Text2Array(cString, nWordWrapCol) LOCAL cLine, nTokNum, aArray, cEOL, nEOLLen, nRetLen, ncSLen - LOCAL nFirstSpace, cSplittedLine + LOCAL nFirstSpace, cSplittedLine, nTokPos := 0 nTokNum := 1 aArray := {} @@ -112,9 +112,9 @@ STATIC function Text2Array(cString, nWordWrapCol) /* TOFIX: Note that __StrToken is not able to cope with delimiters longer than one char */ // Dos - OS/2 - Windows have CRLF as EOL if nEOLLen > 1 - cLine := StrTran(__StrToken(cString, nTokNum++, cEOL), SubStr(cEOL, 2), "") + cLine := StrTran(__StrTkPtr(cString, @nTokPos, cEOL), SubStr(cEOL, 2), "") else - cLine := __StrToken(cString, nTokNum++, cEOL) + cLine := __StrTkPtr(cString, @nTokPos, cEOL) endif nRetLen += Len(cLine) + nEOLLen diff --git a/harbour/source/rtl/teditorl.c b/harbour/source/rtl/teditorl.c index 6ea3db2fa7..0a07408abf 100644 --- a/harbour/source/rtl/teditorl.c +++ b/harbour/source/rtl/teditorl.c @@ -34,7 +34,12 @@ * */ +/* NOTE: we need this to prevent base types redefinition */ +#define _CLIPDEFS_H + #include "hbapi.h" +#include "extend.api" +#include "item.api" static char * hb_strToken( char * szText, long lText, long lIndex, @@ -44,13 +49,13 @@ static char * hb_strToken( char * szText, long lText, long lStart; long lEnd = 0; long lCounter = 0; - + HB_TRACE(HB_TR_DEBUG, ("hb_strToken(%s, %ld, %ld, %d, %p)", szText, lText, lIndex, (int) cDelimiter, plLen)); - + do { lStart = lEnd; - + if( cDelimiter != ' ' ) { if( szText[ lStart ] == cDelimiter ) @@ -61,11 +66,11 @@ static char * hb_strToken( char * szText, long lText, while( lStart < lText && szText[ lStart ] == cDelimiter ) lStart++; } - + if( lStart < lText && szText[ lStart ] != cDelimiter ) { lEnd = lStart + 1; - + while( lEnd < lText && szText[lEnd] != cDelimiter ) lEnd++; } @@ -74,7 +79,7 @@ static char * hb_strToken( char * szText, long lText, } while( lCounter++ < lIndex - 1 && lEnd < lText ); - + if( lCounter < lIndex ) { *plLen = 0; @@ -92,12 +97,37 @@ HB_FUNC( __STRTOKEN ) { char * pszText; long lLen; - - pszText = hb_strToken( hb_parc( 1 ), hb_parclen( 1 ), - hb_parnl( 2 ), - ISCHAR( 3 ) ? *hb_parc( 3 ) : ' ', + + pszText = hb_strToken( hb_parc( 1 ), hb_parclen( 1 ), + hb_parnl( 2 ), + ISCHAR( 3 ) ? *hb_parc( 3 ) : ' ', &lLen ); - + hb_retclen( pszText, lLen ); } + +/* like __STRTOKEN but returns next token starting from passed position (0 based) inside string + StrTkPtr(cString, @nTokPos, Chr(9)) +*/ +HB_FUNC(__STRTKPTR) +{ + char * pszString = hb_parc(1); + long lLen, lStrLen = hb_parclen(1); + long lPos = hb_parnl(2); + char * pszText; + + /* move start of string past last returned token */ + pszString = (char *) ((ULONG) pszString + (ULONG) lPos); + + /* decrease length of string consequently */ + lStrLen -= lPos + 1; + + pszText = hb_strToken(pszString, lStrLen, 1, ISCHAR(3) ? *hb_parc(3) : ' ', &lLen); + + /* return position to start next search from */ + _stornl((ULONG) lPos + ((ULONG) pszText - (ULONG) pszString + lLen + 1), 2); + + /* return token */ + hb_retclen(pszText, lLen); +}