diff --git a/harbour/ChangeLog b/harbour/ChangeLog index efbc5ea99e..734815e7c2 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,43 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-05-17 00:20 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/TODO + * removed some not longer necessary TODO/TOFIX + + * harbour/common.mak + * harbour/source/rtl/Makefile + - harbour/source/rtl/memoline.c + - harbour/source/rtl/mlcount.c + - harbour/source/rtl/mlctopos.c + - harbour/source/rtl/mlpos.c + - harbour/source/rtl/mpostolc.c + + harbour/source/rtl/mlcfunc.c + * new version of memo line functions: + MEMOLINE(), MLCOUNT(), MLPOS(), MLCTOPOS(), MPOSTOLC() + + * harbour/include/hbexpra.c + ! fixed in HB_COMPAT_XHB build hb_enumIndex() used inside internal + FOR/NEXT loop + + * harbour/include/hbpp.h + * harbour/source/pp/ppcore.c + ! removed some not longer necessary hack + % added some speed optimizations - it's not done in the way I want to + have in the final version but with some very small modifications it + should make people using a lot of #[x]translate (Enrico ;-)) happy. + + * harbour/source/rtl/set.c + * minor cleanup in HB_SET_EOL initialization + + * harbour/source/vm/hvm.c + * clean MEMO flag in array and hash items created by { MEMOFILED, ... } + or { "KEY" => MEMOFILED, ... } and optimized results of PLUS operation + + * harbour/utils/hbtest/rt_misc.prg + * SET EOL to CHR(13) + CHR( 10 ) before MLCTOPOS() tests to avoid false + alarm on platforms with differ default EOL + 2007-05-16 16:27 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * harbour/ChangeLog + Added one missing entry (2007-05-15 15:40 UTC+0300). diff --git a/harbour/TODO b/harbour/TODO index 82a1cb5505..378c4029eb 100644 --- a/harbour/TODO +++ b/harbour/TODO @@ -29,13 +29,6 @@ Status...: Is it still true? *** -Assign to: Ryszard, Przemek -Detail...: Debugger with basic interface written in C - it's enough to - borrow Phil's work from xHarbour. -Status...: Open. - -*** - Assign to: Detail...: Add missing Clipper virtual memory functions. Status...: Open. @@ -90,12 +83,6 @@ Status...: Open. *** -Assign to: -Detail...: Add support for INET sockets. -Status...: Open. - -*** - Assign to: Detail...: Add support for virtual file handles and registering some meta handles so it will be possible to make: @@ -172,12 +159,6 @@ Status...: Working on it. *** -Assign to: Ryszard -Detail...: Hash. -Status...: Working on it. - -*** - Assign to: Ryszard Detail...: Real strong typing in the compiler. Status...: Open. diff --git a/harbour/common.mak b/harbour/common.mak index ac2836283b..b038ca04f7 100644 --- a/harbour/common.mak +++ b/harbour/common.mak @@ -399,12 +399,8 @@ RTL_LIB_OBJS = \ $(OBJ_DIR)\math.obj \ $(OBJ_DIR)\maxrow.obj \ $(OBJ_DIR)\memofile.obj \ - $(OBJ_DIR)\memoline.obj \ $(OBJ_DIR)\minmax.obj \ - $(OBJ_DIR)\mlcount.obj \ - $(OBJ_DIR)\mlpos.obj \ - $(OBJ_DIR)\mlctopos.obj \ - $(OBJ_DIR)\mpostolc.obj \ + $(OBJ_DIR)\mlcfunc.obj \ $(OBJ_DIR)\mod.obj \ $(OBJ_DIR)\mouseapi.obj \ $(OBJ_DIR)\mousex.obj \ diff --git a/harbour/include/hbexpra.c b/harbour/include/hbexpra.c index f36d93fd1b..1decc2e053 100644 --- a/harbour/include/hbexpra.c +++ b/harbour/include/hbexpra.c @@ -140,18 +140,24 @@ HB_EXPR_PTR hb_compExprNewFunCall( HB_EXPR_PTR pName, HB_EXPR_PTR pParms, HB_COM #if !defined( HB_MACRO_SUPPORT ) && defined( HB_COMPAT_XHB ) if( strcmp( "HB_ENUMINDEX", pName->value.asSymbol ) == 0 ) { - HB_ENUMERATOR_PTR pEnumVar; - pEnumVar = HB_COMP_PARAM->functions.pLast->pEnum; - if( pEnumVar ) + HB_ENUMERATOR_PTR pForVar, pEnumVar = NULL; + pForVar = HB_COMP_PARAM->functions.pLast->pEnum; + if( pForVar ) { - while( pEnumVar->pNext ) - pEnumVar = pEnumVar->pNext; - - HB_COMP_EXPR_DELETE( pParms ); - HB_COMP_EXPR_DELETE( pName ); - return hb_compExprNewMethodCall( hb_compExprNewSend( + while( pForVar ) + { + if( pForVar->bForEach ) + pEnumVar = pForVar; + pForVar = pForVar->pNext; + } + if( pEnumVar ) + { + HB_COMP_EXPR_DELETE( pParms ); + HB_COMP_EXPR_DELETE( pName ); + return hb_compExprNewMethodCall( hb_compExprNewSend( hb_compExprNewVar( pEnumVar->szName, HB_COMP_PARAM ), "__ENUMINDEX", NULL, HB_COMP_PARAM ), NULL ); + } } } #endif diff --git a/harbour/include/hbpp.h b/harbour/include/hbpp.h index 976ed62c56..8952422a7f 100644 --- a/harbour/include/hbpp.h +++ b/harbour/include/hbpp.h @@ -402,6 +402,11 @@ HB_PP_TOKEN, * PHB_PP_TOKEN; /* Clipper allows only 16 nested includes */ #define HB_PP_MAX_INCLUDED_FILES 64 +#define HB_PP_HASHID(t) ( ( UCHAR ) HB_PP_UPPER( (t)->value[0] ) ) +#define HB_PP_HASHID_MAX 256 +#define HB_PP_DEFINE 1 +#define HB_PP_TRANSLATE 2 +#define HB_PP_COMMAND 4 /* comparision modes */ #define HB_PP_CMP_ADDR 0 /* compare token addresses */ @@ -448,7 +453,8 @@ HB_PP_TOKEN, * PHB_PP_TOKEN; #define HB_PP_ISFIRSTIDCHAR(c) ( ( (c) >= 'A' && (c) <= 'Z' ) || \ ( (c) >= 'a' && (c) <= 'z' ) || (c) == '_' ) #define HB_PP_ISNEXTIDCHAR(c) ( HB_PP_ISFIRSTIDCHAR(c) || HB_PP_ISDIGIT(c) ) - +#define HB_PP_UPPER(c) ( (c) >= 'a' && (c) <= 'z' ? \ + (c) - ( 'a' - 'A' ) : (c) ) typedef struct _HB_PP_RESULT { struct _HB_PP_RESULT * pNext; @@ -554,6 +560,7 @@ typedef struct int iDefinitions; /* number of rules in pDefinitions */ int iTranslations; /* number of rules in pTranslations */ int iCommands; /* number of rules in pCommands */ + BYTE pMap[ HB_PP_HASHID_MAX ]; /* translation map */ PHB_PP_TOKEN pTokenOut; /* preprocessed tokens */ PHB_PP_TOKEN * pNextTokenPtr; /* pointer to the last NULL pointer in token list */ diff --git a/harbour/source/pp/ppcore.c b/harbour/source/pp/ppcore.c index b135932df9..c9f6aca4c8 100644 --- a/harbour/source/pp/ppcore.c +++ b/harbour/source/pp/ppcore.c @@ -59,8 +59,6 @@ #include "hbpp.h" #include "hbdate.h" #include -#include - #define HB_PP_WARN_DEFINE_REDEF 1 /* C1005 */ @@ -693,7 +691,6 @@ static void hb_pp_readLine( PHB_PP_STATE pState ) static BOOL hb_pp_canQuote( BOOL fQuote, char * pBuffer, ULONG ulLen, ULONG * pulAt ) { ULONG ul = 0; - BOOL fQ1 = FALSE, fQ2 = FALSE; /* * TODO: this is Clipper compatible but it breaks valid code so we may @@ -704,12 +701,8 @@ static BOOL hb_pp_canQuote( BOOL fQuote, char * pBuffer, ULONG ulLen, ULONG * pu if( pBuffer[ ul ] == ']' ) { * pulAt = ul; - return fQuote || fQ1 || fQ2; + return fQuote; } - else if( pBuffer[ ul ] == '\'' ) - fQ1 = !fQ1; - else if( pBuffer[ ul ] == '"' ) - fQ2 = !fQ2; ++ul; } return FALSE; @@ -1614,6 +1607,15 @@ static void hb_pp_ruleSetStd( PHB_PP_RULE pRule ) } } +static void hb_pp_ruleSetId( PHB_PP_STATE pState, PHB_PP_RULE pRule, BYTE id ) +{ + while( pRule ) + { + pState->pMap[ HB_PP_HASHID( pRule->pMatch ) ] |= id; + pRule = pRule->pPrev; + } +} + static PHB_PP_RULE hb_pp_defineFind( PHB_PP_STATE pState, PHB_PP_TOKEN pToken ) { PHB_PP_RULE pRule = pState->pDefinitions; @@ -1655,6 +1657,7 @@ static void hb_pp_defineAdd( PHB_PP_STATE pState, USHORT mode, pState->pDefinitions = pRule; pState->iDefinitions++; } + pState->pMap[ HB_PP_HASHID( pMatch ) ] |= HB_PP_DEFINE; } static void hb_pp_defineDel( PHB_PP_STATE pState, PHB_PP_TOKEN pToken ) @@ -3113,12 +3116,14 @@ static void hb_pp_directiveNew( PHB_PP_STATE pState, PHB_PP_TOKEN pToken, pRule->pPrev = pState->pCommands; pState->pCommands = pRule; pState->iCommands++; + pState->pMap[ HB_PP_HASHID( pMatch ) ] |= HB_PP_COMMAND; } else { pRule->pPrev = pState->pTranslations; pState->pTranslations = pRule; pState->iTranslations++; + pState->pMap[ HB_PP_HASHID( pMatch ) ] |= HB_PP_TRANSLATE; } pMatch = pResult = NULL; } @@ -3959,7 +3964,8 @@ static BOOL hb_pp_processDefine( PHB_PP_STATE pState, PHB_PP_TOKEN * pFirstPtr ) fRepeat = FALSE; while( !HB_PP_TOKEN_ISEOS( * pFirstPtr ) ) { - if( HB_PP_TOKEN_TYPE( ( * pFirstPtr )->type ) == HB_PP_TOKEN_KEYWORD ) + if( HB_PP_TOKEN_TYPE( ( * pFirstPtr )->type ) == HB_PP_TOKEN_KEYWORD && + ( pState->pMap[ HB_PP_HASHID( * pFirstPtr ) ] & HB_PP_DEFINE ) ) { PHB_PP_RULE pRule = hb_pp_defineFind( pState, * pFirstPtr ); if( pRule ) @@ -4003,24 +4009,27 @@ static BOOL hb_pp_processTranslate( PHB_PP_STATE pState, PHB_PP_TOKEN * pFirstPt fRepeat = FALSE; while( !HB_PP_TOKEN_ISEOS( * pTokenPtr ) ) { - PHB_PP_RULE pRule = pState->pTranslations; - while( pRule ) + if( pState->pMap[ HB_PP_HASHID( * pTokenPtr ) ] & HB_PP_TRANSLATE ) { - if( hb_pp_patternCmp( pRule, * pTokenPtr, FALSE ) ) + PHB_PP_RULE pRule = pState->pTranslations; + while( pRule ) { - hb_pp_patternReplace( pState, pRule, pTokenPtr, "translate" ); - fSubst = fRepeat = TRUE; - if( ++pState->iCycle > pState->iMaxCycles || - ++iCycle > HB_PP_MAX_REPATS + pState->iTranslations ) + if( hb_pp_patternCmp( pRule, * pTokenPtr, FALSE ) ) { - pState->iCycle = pState->iMaxCycles + 1; - hb_pp_error( pState, 'E', HB_PP_ERR_CYCLIC_TRANSLATE, pRule->pMatch->value ); - return TRUE; + hb_pp_patternReplace( pState, pRule, pTokenPtr, "translate" ); + fSubst = fRepeat = TRUE; + if( ++pState->iCycle > pState->iMaxCycles || + ++iCycle > HB_PP_MAX_REPATS + pState->iTranslations ) + { + pState->iCycle = pState->iMaxCycles + 1; + hb_pp_error( pState, 'E', HB_PP_ERR_CYCLIC_TRANSLATE, pRule->pMatch->value ); + return TRUE; + } + pRule = pState->pTranslations; + continue; } - pRule = pState->pTranslations; - continue; + pRule = pRule->pPrev; } - pRule = pRule->pPrev; } iCycle = 0; pTokenPtr = &( * pTokenPtr )->pNext; @@ -4037,7 +4046,8 @@ static BOOL hb_pp_processCommand( PHB_PP_STATE pState, PHB_PP_TOKEN * pFirstPtr BOOL fSubst = FALSE, fRepeat = TRUE; int iCycle = 0; - while( fRepeat && !HB_PP_TOKEN_ISEOC( * pFirstPtr ) ) + while( fRepeat && !HB_PP_TOKEN_ISEOC( * pFirstPtr ) && + pState->pMap[ HB_PP_HASHID( * pFirstPtr ) ] & HB_PP_COMMAND ) { fRepeat = FALSE; pRule = pState->pCommands; @@ -4913,6 +4923,10 @@ void hb_pp_setStdBase( PHB_PP_STATE pState ) hb_pp_ruleSetStd( pState->pDefinitions ); hb_pp_ruleSetStd( pState->pTranslations ); hb_pp_ruleSetStd( pState->pCommands ); + memset( pState->pMap, 0, sizeof( pState->pMap ) ); + hb_pp_ruleSetId( pState, pState->pDefinitions, HB_PP_DEFINE ); + hb_pp_ruleSetId( pState, pState->pTranslations, HB_PP_TRANSLATE ); + hb_pp_ruleSetId( pState, pState->pCommands, HB_PP_COMMAND ); } /* @@ -5483,7 +5497,7 @@ void hb_pp_tokenUpper( PHB_PP_TOKEN pToken ) if( pToken->len <= 1 ) { - UCHAR ucVal = ( UCHAR ) ( pToken->len ? toupper( ( UCHAR ) pToken->value[ 0 ] ) : 0 ); + UCHAR ucVal = ( UCHAR ) HB_PP_UPPER( pToken->value[ 0 ] ); if( HB_PP_TOKEN_ALLOC( pToken->type ) ) { hb_xfree( pToken->value ); diff --git a/harbour/source/rtl/Makefile b/harbour/source/rtl/Makefile index 09d43e7756..76e0cf49fd 100644 --- a/harbour/source/rtl/Makefile +++ b/harbour/source/rtl/Makefile @@ -69,15 +69,11 @@ C_SOURCES=\ math.c \ maxrow.c \ memofile.c \ - memoline.c \ minmax.c \ - mlcount.c \ - mlctopos.c \ - mlpos.c \ + mlcfunc.c \ mod.c \ mouseapi.c \ mousex.c \ - mpostolc.c \ mtran.c \ natmsg.c \ net.c \ diff --git a/harbour/source/rtl/memoline.c b/harbour/source/rtl/memoline.c deleted file mode 100644 index a989bb93b3..0000000000 --- a/harbour/source/rtl/memoline.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * MEMOLINE() function - * - * Copyright 1999 Ignacio Ortiz de ZŁniga - * www - http://www.harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - - -#include "hbapi.h" - -HB_FUNC( MEMOLINE ) -{ - char * pszString = hb_parc( 1 ); - ULONG ulLineLength = ISNUM( 2 ) ? hb_parni( 2 ) : 79; - ULONG ulLineNumber = ISNUM( 3 ) ? hb_parni( 3 ) : 1; - ULONG ulTabLength = ISNUM( 4 ) ? hb_parni( 4 ) : 4; - BOOL bWordWrap = ISLOG( 5 ) ? hb_parl( 5 ) : TRUE; - ULONG ulLen = hb_parclen( 1 ); - ULONG ulLastSpace = 0; - ULONG ulCurLength = 0; - ULONG ulLines = 0; - ULONG ulPos = 0; - ULONG ulLineBegin; - ULONG ulLineEnd; - - if( ulLineLength < 4 ) - ulLineLength = 79; - -#if defined( HB_C52_STRICT ) - if( ulLineLength > 254 ) - ulLineLength = 79; -#endif - - if( ulTabLength > ulLineLength ) - ulTabLength = ulLineLength - 1; - - ulLineBegin = ulPos; - ulLineEnd = 0; - - - while( ulPos < ulLen && ulLines < ulLineNumber ) - { - switch( pszString[ ulPos ] ) - { - case HB_CHAR_HT: - ulCurLength = ( ( ULONG ) ( ulCurLength / ulTabLength ) * ulTabLength ) + ulTabLength; - ulLastSpace = ulCurLength; - break; - - case HB_CHAR_LF: - if( !( pszString[ ulPos - 1 ] == HB_CHAR_SOFT1 ) ) - { - ulCurLength = 0; - ulLastSpace = 0; - ulLineEnd = ( ulPos >= OS_EOL_LEN ) ? ( ulPos - OS_EOL_LEN ) : ulLineBegin; - ulLines++; - if( ulLines < ulLineNumber ) - { - ulLineBegin = ulPos + 1; - ulLineEnd = 0; - } - } - break; - - case HB_CHAR_CR: - break; - - case ' ': - ulCurLength++; - ulLastSpace = ulCurLength; - break; - - default: - ulCurLength++; - } - - if( ulCurLength > ulLineLength ) - { - if( bWordWrap ) - { - if( ulLastSpace == 0 || ulLastSpace == ulCurLength ) - { - ulCurLength = 1; - ulLineEnd = ulPos - 1; - } - else - { - ulCurLength = ulCurLength - ulLastSpace; - ulLineEnd = ulPos - ulCurLength ; - } - } - else - { - ulCurLength = 1; - ulLineEnd = ulPos - 1; - } - - ulLines++; - ulLastSpace = 0; - - if( ulLines < ulLineNumber ) - { - if( ulPos < ulLen && pszString[ ulPos ] == ' ' ) - ulPos++; /* Ignore a single trailing blank (same as Cl*pper) */ - - ulLineBegin = ulPos - ulCurLength + 1; - ulLineEnd = 0; - } - } - - ulPos++; - } - - if( ulLineEnd == 0 ) - { - ulLines++; - ulLineEnd = ( ulPos == 0 ) ? 0 : ( ulPos - 1 ); - } - - if( ulPos < ulLen || (ulLineNumber == ulLines && ulLineEnd >= ulLineBegin) ) - { - ULONG ulSpAdded = 0; - char * pszLine = ( char * ) hb_xgrab( ulLineLength + 1 ); - - memset( pszLine, ' ', ulLineLength ); - - if ( ulLineEnd >= ulLineBegin && ulLen > 0 ) - { - for( ulPos = 0; ulPos <= ( ulLineEnd - ulLineBegin ); ulPos++ ) - { - if( pszString[ ulLineBegin + ulPos ] == HB_CHAR_HT ) - ulSpAdded += ( ( ULONG ) ( ulPos / ulTabLength ) * ulTabLength ) + ulTabLength - ulPos - 2; - else - if( pszString[ ulLineBegin + ulPos ] == HB_CHAR_SOFT1 || pszString[ ulLineBegin + ulPos ] == HB_CHAR_CR || pszString[ ulLineBegin + ulPos ] == HB_CHAR_LF ) - ulSpAdded--; - else - * ( pszLine + ulPos + ulSpAdded ) = * ( pszString + ulLineBegin + ulPos ); - - } - - } - - hb_retclen_buffer( pszLine, ulLineLength ); - } - else - hb_retc( NULL ); -} diff --git a/harbour/source/rtl/mlcfunc.c b/harbour/source/rtl/mlcfunc.c new file mode 100644 index 0000000000..13d9dfc35a --- /dev/null +++ b/harbour/source/rtl/mlcfunc.c @@ -0,0 +1,433 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * memo line functions: MEMOLINE(), MLCOUNT(), MLPOS(), MLCTOPOS(), MPOSTOLC() + * + * Copyright 2007 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" +#include "hbapiitm.h" +#include "hbset.h" + +typedef struct +{ + char * szEOL; + ULONG ulLen; +} HB_EOL_INFO, * PHB_EOL_INFO; + +static ULONG hb_mlGetLine( char * pszString, ULONG ulLen, ULONG ulOffset, + ULONG ulLineLength, ULONG ulTabSize, ULONG ulMaxPos, + BOOL fWordWrap, PHB_EOL_INFO pEOLs, int iEOLs, + ULONG * pulLen, ULONG * pulEOL ) +{ + ULONG ulCol = 0, ulBlankCol = 0, ulBlankPos = 0; + int i; + + if( pulEOL ) + * pulEOL = 0; + + while( ulOffset < ulLen && ( ulMaxPos == 0 || ulOffset < ulMaxPos ) ) + { + for( i = 0; i < iEOLs; ++i ) + { + if( ulLen - ulOffset >= pEOLs[ i ].ulLen && + memcmp( pszString + ulOffset, pEOLs[ i ].szEOL, pEOLs[ i ].ulLen ) == 0 ) + { + if( ulMaxPos ) + ulCol += pEOLs[ i ].ulLen; + else + ulOffset += pEOLs[ i ].ulLen; + * pulLen = ulCol; + if( pulEOL ) + * pulEOL = pEOLs[ i ].ulLen; + return ulOffset; + } + } + + if( pszString[ ulOffset ] == ' ' || pszString[ ulOffset ] == HB_CHAR_HT ) + { + ulBlankCol = ulCol; + ulBlankPos = ulOffset; + } + + if( pszString[ ulOffset ] == HB_CHAR_HT ) + ulCol += ulTabSize - ( ulCol % ulTabSize ); + else if( pszString[ ulOffset ] == HB_CHAR_SOFT1 && + pszString[ ulOffset + 1 ] == HB_CHAR_SOFT2 ) + { + ulOffset++; + if( !fWordWrap ) + { + ulOffset++; + * pulLen = ulCol; + break; + } + } + else + ulCol++; + + ulOffset++; + if( ulCol >= ulLineLength ) + { + if( fWordWrap ) + { + if( ulBlankCol == 0 || pszString[ ulOffset ] == ' ' || + pszString[ ulOffset ] == HB_CHAR_HT ) + { + ulCol = ulLineLength; + if( pszString[ ulOffset ] == ' ' ) + ++ulOffset; + } + else + { + ulCol = ulBlankCol; + ulOffset = ulBlankPos + 1; + } + } + else + { + if( ulCol > ulLineLength ) + --ulOffset; + ulCol = ulLineLength; + } + break; + } + } + * pulLen = ulCol; + + return ulOffset; +} + +static PHB_EOL_INFO hb_mlGetEOLs( int iParam, int * piEOLs ) +{ + PHB_EOL_INFO pEOLs = NULL; + int iEOLs = 0; + char * szEOL; + +#ifndef HB_C52_STRICT + ULONG ulLen, ul; + + szEOL = hb_parc( iParam ); + if( szEOL ) + { + ulLen = hb_parclen( iParam ); + if( ulLen ) + { + pEOLs = ( PHB_EOL_INFO ) hb_xgrab( sizeof( HB_EOL_INFO ) ); + pEOLs->szEOL = szEOL; + pEOLs->ulLen = ulLen; + iEOLs = 1; + } + } + else if( ISARRAY( iParam ) ) + { + PHB_ITEM pArray = hb_param( iParam, HB_IT_ARRAY ); + ULONG ulSize = hb_arrayLen( pArray ); + for( ul = 1; ul <= ulSize; ++ul ) + { + if( hb_arrayGetCLen( pArray, ul ) > 0 ) + ++iEOLs; + } + if( iEOLs ) + { + iEOLs = 0; + pEOLs = ( PHB_EOL_INFO ) hb_xgrab( sizeof( HB_EOL_INFO ) * iEOLs ); + for( ul = 1; ul <= ulSize; ++ul ) + { + ULONG ulLen = hb_arrayGetCLen( pArray, ul ); + if( ulLen > 0 ) + { + pEOLs[ iEOLs ].szEOL = hb_arrayGetCPtr( pArray, ul ); + pEOLs[ iEOLs ].ulLen = ulLen; + ++iEOLs; + } + } + } + } +#endif + + if( iEOLs == 0 ) + { + pEOLs = ( PHB_EOL_INFO ) hb_xgrab( sizeof( HB_EOL_INFO ) ); + if( hb_set.HB_SET_EOL && strlen( hb_set.HB_SET_EOL ) > 0 ) + pEOLs->szEOL = hb_set.HB_SET_EOL; + else + pEOLs->szEOL = hb_conNewLine(); + pEOLs->ulLen = strlen( hb_set.HB_SET_EOL ); + iEOLs = pEOLs->ulLen ? 1 : 0; + } + + * piEOLs = iEOLs; + return pEOLs; +} + +static char * hb_mlGetParams( int iParAdd, ULONG * pulLen, ULONG * pulLineLength, + ULONG * pulTabSize, BOOL * pfWordWrap, + PHB_EOL_INFO * pEOLs, int * piEOLs ) +{ + char * pszString = hb_parc( 1 ); + if( pszString ) + { + if( ISNUM( 2 ) ) + { + if( hb_parnd( 2 ) <= 0 ) + return NULL; + * pulLineLength = hb_parnl( 2 ); + } + else + * pulLineLength = 79; + * pulLen = hb_parclen( 1 ); + * pulTabSize = ISNUM( 3 + iParAdd ) ? hb_parnl( 3 + iParAdd ) : 4; + * pfWordWrap = ISLOG( 4 + iParAdd ) ? hb_parl( 4 + iParAdd ) : TRUE; + * pEOLs = hb_mlGetEOLs( 5 + iParAdd, piEOLs ); +#ifdef HB_C52_STRICT + if( * pulLineLength > 254 ) + * pulLineLength = 79; +#endif + if( * pulTabSize >= * pulLineLength ) + * pulTabSize = * pulLineLength - 1; + else if( * pulTabSize == 0 ) + * pulTabSize = 1; + } + return pszString; +} + +HB_FUNC( MEMOLINE ) +{ + ULONG ulLen, ulLineLength, ulTabSize; + BOOL fWordWrap; + PHB_EOL_INFO pEOLs; + int iEOLs; + char * pszString = hb_mlGetParams( 1, &ulLen, &ulLineLength, + &ulTabSize, &fWordWrap, &pEOLs, &iEOLs ); + char * szLine; + ULONG ulLine = hb_parnl( 3 ); + ULONG ulOffset = 0; + ULONG ulCols = 0; + + if( !pszString ) + { + hb_retc( NULL ); + return; + } + + if( ulLine == 0 ) + ulLine = 1; + + while( --ulLine && ulOffset < ulLen ) + { + ulOffset = hb_mlGetLine( pszString, ulLen, ulOffset, + ulLineLength, ulTabSize, 0, fWordWrap, + pEOLs, iEOLs, &ulCols, NULL ); + } + if( ulOffset < ulLen ) + { + ULONG ulCol = 0; + hb_mlGetLine( pszString, ulLen, ulOffset, + ulLineLength, ulTabSize, 0, fWordWrap, + pEOLs, iEOLs, &ulCols, NULL ); + szLine = ( char * ) hb_xgrab( ulLineLength + 1 ); + while( ulCol < ulCols ) + { + if( pszString[ ulOffset ] == HB_CHAR_HT ) + { + ULONG ul = ulTabSize - ( ulCol % ulTabSize ); + do + szLine[ ulCol++ ] = ' '; + while( --ul && ulCol < ulCols ); + } + else if( pszString[ ulOffset ] == HB_CHAR_SOFT1 && + pszString[ ulOffset + 1 ] == HB_CHAR_SOFT2 ) + ulOffset++; + else + szLine[ ulCol++ ] = pszString[ ulOffset ]; + ulOffset++; + } + if( ulCols < ulLineLength ) + memset( szLine + ulCols, ' ', ulLineLength - ulCols ); + szLine[ ulLineLength ] = 0; + hb_retclen_buffer( szLine, ulLineLength ); + } + else + hb_retc( NULL ); + hb_xfree( pEOLs ); +} + +HB_FUNC( MLCOUNT ) +{ + ULONG ulLen, ulLineLength, ulTabSize; + BOOL fWordWrap; + PHB_EOL_INFO pEOLs; + int iEOLs; + char * pszString = hb_mlGetParams( 0, &ulLen, &ulLineLength, + &ulTabSize, &fWordWrap, &pEOLs, &iEOLs ); + ULONG ulLines = 0; + ULONG ulOffset = 0; + ULONG ulCols = 0; + + if( pszString ) + { + while( ulOffset < ulLen ) + { + ++ulLines; + ulOffset = hb_mlGetLine( pszString, ulLen, ulOffset, + ulLineLength, ulTabSize, 0, fWordWrap, + pEOLs, iEOLs, &ulCols, NULL ); + } + hb_xfree( pEOLs ); + } + hb_retnl( ulLines ); +} + +HB_FUNC( MLPOS ) +{ + ULONG ulLen, ulLineLength, ulTabSize; + BOOL fWordWrap; + PHB_EOL_INFO pEOLs; + int iEOLs; + char * pszString = hb_mlGetParams( 1, &ulLen, &ulLineLength, + &ulTabSize, &fWordWrap, &pEOLs, &iEOLs ); + ULONG ulLine = hb_parnl( 3 ); + ULONG ulOffset = 0; + ULONG ulCols = 0; + + if( pszString ) + { + if( ulLine == 0 ) + ulLine = 1; + while( --ulLine && ulOffset < ulLen ) + ulOffset = hb_mlGetLine( pszString, ulLen, ulOffset, + ulLineLength, ulTabSize, 0, fWordWrap, + pEOLs, iEOLs, &ulCols, NULL ); + if( ulOffset < ulLen ) + ++ulOffset; + hb_xfree( pEOLs ); + } + hb_retnl( ulOffset ); +} + +HB_FUNC( MLCTOPOS ) +{ + ULONG ulLen, ulLineLength, ulTabSize; + BOOL fWordWrap; + PHB_EOL_INFO pEOLs; + int iEOLs; + char * pszString = hb_mlGetParams( 2, &ulLen, &ulLineLength, + &ulTabSize, &fWordWrap, &pEOLs, &iEOLs ); + ULONG ulLine = hb_parnl( 3 ); + ULONG ulCol = hb_parnl( 4 ); + ULONG ulOffset = 0; + ULONG ulCols = 0; + + if( pszString ) + { + if( ulLineLength > 4 && ulLine && ISNUM( 4 ) ) + { + while( --ulLine && ulOffset < ulLen ) + ulOffset = hb_mlGetLine( pszString, ulLen, ulOffset, + ulLineLength, ulTabSize, 0, fWordWrap, + pEOLs, iEOLs, &ulCols, NULL ); + if( ulOffset < ulLen && ulCol ) + ulOffset = hb_mlGetLine( pszString, ulLen, ulOffset, + ulCol, ulTabSize, ulLen, FALSE, + pEOLs, iEOLs, &ulCols, NULL ); + } + hb_xfree( pEOLs ); + } + ++ulOffset; + hb_retnl( ulOffset ); +} + +HB_FUNC( MPOSTOLC ) +{ + ULONG ulLen, ulLineLength, ulTabSize; + BOOL fWordWrap; + PHB_EOL_INFO pEOLs; + int iEOLs; + char * pszString = hb_mlGetParams( 1, &ulLen, &ulLineLength, + &ulTabSize, &fWordWrap, &pEOLs, &iEOLs ); + ULONG ulPos = hb_parnl( 3 ); + ULONG ulOffset = 0; + ULONG ulLine = 0; + ULONG ulCol = 0; + ULONG ulEOL = 0; + + if( pszString ) + { + if( ulPos && ulLen ) + { + if( --ulPos ) + { + do + { + ++ulLine; + ulOffset = hb_mlGetLine( pszString, ulLen, ulOffset, + ulLineLength, ulTabSize, ulPos, fWordWrap, + pEOLs, iEOLs, &ulCol, &ulEOL ); + if( ulEOL ) + { + if( ulOffset + ulEOL == ulPos ) + { + ulCol = 0; + ++ulLine; + break; + } + ulOffset += ulEOL; + } + } + while( ulOffset < ulLen && ulOffset < ulPos ); + } + else + ++ulLine; + } + hb_xfree( pEOLs ); + } + hb_reta( 2 ); + hb_stornl( ulLine, -1, 1 ); + hb_stornl( ulCol, -1, 2 ); +} diff --git a/harbour/source/rtl/mlcount.c b/harbour/source/rtl/mlcount.c deleted file mode 100644 index fc1b29cebf..0000000000 --- a/harbour/source/rtl/mlcount.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * MLCOUNT() function - * - * Copyright 1999 Ignacio Ortiz de ZŁniga - * www - http://www.harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -#include "hbapi.h" - -HB_FUNC( MLCOUNT ) -{ - char * pszString = hb_parc( 1 ); - ULONG ulLineLength = ISNUM( 2 ) ? hb_parni( 2 ) : 79; - ULONG ulTabLength = ISNUM( 3 ) ? hb_parni( 3 ) : 4; - ULONG ulLastSpace = 0; - ULONG ulCurLength = 0; - BOOL bWordWrap = ISLOG( 4 ) ? hb_parl( 4 ) : TRUE; - ULONG ulLen = hb_parclen( 1 ); - ULONG ulLines = 0; - ULONG ulPos; - - if( ulLineLength < 4 ) - ulLineLength = 79; - -#if defined( HB_C52_STRICT ) - if( ulLineLength > 254 ) - ulLineLength = 79; -#endif - - if( ulTabLength > ulLineLength ) - ulTabLength = ulLineLength - 1; - - for( ulPos = 0; ulPos < ulLen; ulPos++ ) - { - switch( pszString[ ulPos ] ) - { - case HB_CHAR_HT: - ulCurLength = ( ( ULONG ) ( ulCurLength / ulTabLength ) * ulTabLength ) + ulTabLength; - ulLastSpace = ulCurLength; - break; - - case HB_CHAR_LF: - if( !( pszString[ ulPos - 1 ] == HB_CHAR_SOFT1 ) ) - { - ulCurLength = 0; - ulLastSpace = 0; - ulLines++; - } - break; - - case HB_CHAR_CR: - break; - - case ' ': - ulCurLength++; - ulLastSpace = ulCurLength; - break; - - default: - ulCurLength++; - } - - if( ulCurLength > ulLineLength ) - { - if( bWordWrap ) - { - if( ulLastSpace == 0 || ulLastSpace == ulCurLength ) - ulCurLength = 1; - else - ulCurLength = ulCurLength - ulLastSpace; - } - else - ulCurLength = 1; - - ulLines++; - ulLastSpace = 0; - } - } - - if( ulCurLength > 0 ) - ulLines++; - - hb_retnl( ulLines ); -} diff --git a/harbour/source/rtl/mlctopos.c b/harbour/source/rtl/mlctopos.c deleted file mode 100644 index be52998c88..0000000000 --- a/harbour/source/rtl/mlctopos.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * MLCTOPOS() function - * - * Copyright 2001 Ignacio Ortiz de ZŁniga - * www - http://www.harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -/* - TOFIX: The function is still not compatible, TAB's in the ulLine are not - expanded, and there are other problems. HBTest show some of the - differences. 2007-05-08 [ckedem] - */ - -#include "hbapi.h" - -HB_FUNC( MLCTOPOS ) -{ - char * pszString = hb_parc( 1 ); - ULONG ulLineLength = ISNUM( 2 ) ? hb_parni( 2 ) : 79; - ULONG ulLine = ISNUM( 3 ) ? hb_parnl( 3 ) : 1; - ULONG ulCol = ISNUM( 4 ) ? hb_parnl( 4 ) : 0; - ULONG ulTabLength = ISNUM( 5 ) ? hb_parni( 5 ) : 4; - ULONG ulLastSpace = 0; - ULONG ulCurLength = 0; - BOOL bWordWrap = ISLOG( 6 ) ? hb_parl( 6 ) : TRUE; - ULONG ulLen = hb_parclen( 1 ); - ULONG ulLines = 1; - ULONG ulPos; - ULONG ulBegOfLine = 0; -/* ULONG ulLastLen = 0; */ - - if( ulLineLength < 4 || ulLineLength > 254 ) - ulLineLength = 79; - - if( ulTabLength > ulLineLength ) - ulTabLength = ulLineLength - 1; - - for( ulPos = 0; ulPos < ulLen && ulLine > ulLines; ulPos++ ) - { - switch( pszString[ ulPos ] ) - { - case HB_CHAR_HT: - ulCurLength = ( ( ULONG ) ( ulCurLength / ulTabLength ) * ulTabLength ) + ulTabLength; - ulLastSpace = ulCurLength; - break; - - case HB_CHAR_LF: - ulBegOfLine = ulPos - ulCurLength; -/* ulLastLen = ulCurLength; */ - ulCurLength = 0; - ulLastSpace = 0; - ulLines++; - break; - - case HB_CHAR_CR: - break; - - case ' ': - ulCurLength++; - ulLastSpace = ulCurLength; - break; - - default: - ulCurLength++; - } - - if( ulCurLength > ulLineLength ) - { - if( bWordWrap ) - { - if( ulLastSpace == 0 ) - ulCurLength = 1; - else - ulCurLength = ulCurLength - ulLastSpace; - } - else - ulCurLength = 1; - - ulLines++; - ulLastSpace = 0; - ulBegOfLine = ulPos - ulCurLength; -/* ulLastLen = ulCurLength ; */ - } - } - - if( ulCurLength > 0 ) - { - ulBegOfLine = ulPos - ulCurLength; -/* ulLastLen = ulCurLength ; */ - } - - ulLen++; - - if( ulLine == ulLines ) - { -#if 0 - if( ulLastLen ) - ulLastLen--; /* Column is zero based */ - ulPos = ulBegOfLine + 1 + ( ( ulCol < ulLastLen ) ? ulCol : ulLastLen ); -#endif - ulPos = ulBegOfLine + 1 + ulCol; - - /* When wordwrap is active, skip the first space if not on the first line */ - if( bWordWrap && !ulCol && ulLine > 1 ) - if( pszString[ ulPos - 1 ] == ' ' || pszString[ ulPos - 1 ] == HB_CHAR_HT ) - ulPos++; - if( ulPos > ulLen ) - ulPos = ulLen; - hb_retnl( ulPos ); - } - else - hb_retnl( ulLen ); -} - diff --git a/harbour/source/rtl/mlpos.c b/harbour/source/rtl/mlpos.c deleted file mode 100644 index 6bab259152..0000000000 --- a/harbour/source/rtl/mlpos.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * MLPOS() function - * - * Copyright 2000 Ignacio Ortiz de ZŁniga - * www - http://www.harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -#include "hbapi.h" - -HB_FUNC( MLPOS ) -{ - char * pszString = hb_parc( 1 ); - ULONG ulLineLength = hb_parni( 2 ); - ULONG ulLine = hb_parni( 3 ); - ULONG ulTabLength = ISNUM( 4 ) ? hb_parni( 4 ) : 4; - ULONG ulLastSpace = 0; - ULONG ulCurLength = 0; - ULONG ulLen = hb_parclen( 1 ); - ULONG ulLines = 1; - ULONG ulPos = 0; - BOOL bWordWrap = ISLOG( 5 ) ? hb_parl( 5 ) : TRUE; - - if( ulLineLength < 4 || ulLineLength > 254 ) - ulLineLength = 79; - - if( ulTabLength > ulLineLength ) - ulTabLength = ulLineLength - 1; - - while( ulPos < ulLen && ulLines < ulLine ) - { - switch( pszString[ ulPos ] ) - { - case HB_CHAR_HT: - ulCurLength = ( ( ULONG ) ( ulCurLength / ulTabLength ) * ulTabLength ) + ulTabLength; - break; - - case HB_CHAR_LF: - ulCurLength = 0; - ulLastSpace = 0; - ulLines++; - break; - - case HB_CHAR_CR: - break; - - case ' ': - ulCurLength++; - ulLastSpace = ulCurLength; - break; - - default: - ulCurLength++; - } - - if( ulCurLength > ulLineLength ) - { - if( bWordWrap ) - { - if( ulLastSpace == 0 ) - ulCurLength = 1; - else - ulCurLength = ulCurLength - ulLastSpace; - } - else - ulCurLength = 1; - - ulLines++; - ulLastSpace = 0; - } - - ulPos++; - } - - if( ulCurLength > 0 ) - ulLines++; - - if( ulLines == ulLine ) - hb_retnl( ulPos - ulCurLength + 1); - else - hb_retnl( ulLen ); -} - diff --git a/harbour/source/rtl/mpostolc.c b/harbour/source/rtl/mpostolc.c deleted file mode 100644 index 6518b6e54f..0000000000 --- a/harbour/source/rtl/mpostolc.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * MPOSTOLC() function - * - * Copyright 2001 Ignacio Ortiz de ZŁniga - * www - http://www.harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -#include "hbapi.h" - -HB_FUNC( MPOSTOLC ) -{ - char * pszString = hb_parc( 1 ); - ULONG ulLineLength = ISNUM( 2 ) ? hb_parni( 2 ) : 79; - ULONG ulPos = ISNUM( 3 ) ? hb_parnl( 3 ) : 1; - ULONG ulTabLength = ISNUM( 4 ) ? hb_parni( 4 ) : 4; - ULONG ulLastSpace = 0; - ULONG ulCurLength = 0; - BOOL bWordWrap = ISLOG( 5 ) ? hb_parl( 5 ) : TRUE; - ULONG ulLen = hb_parclen( 1 ); - ULONG ulLines = 1; - ULONG ulCurPos; - - if( ulLineLength < 4 || ulLineLength > 254 ) - ulLineLength = 79; - - if( ulTabLength > ulLineLength ) - ulTabLength = ulLineLength - 1; - - ulPos--; - - if ( ulPos > ulLen ) - ulPos = ulLen; - - for( ulCurPos = 0; ulCurPos <= ulPos ; ulCurPos++ ) - { - switch( pszString[ ulCurPos ] ) - { - case HB_CHAR_HT: - ulCurLength = ( ( ULONG ) ( ulCurLength / ulTabLength ) * ulTabLength ) + ulTabLength; - ulLastSpace = ulCurLength; - break; - - case HB_CHAR_LF: - ulCurLength = 0; - ulLastSpace = 0; - ulLines++; - break; - - case HB_CHAR_CR: - break; - - case ' ': - ulCurLength++; - ulLastSpace = ulCurLength; - break; - - default: - ulCurLength++; - } - - if( ulCurLength > ulLineLength ) - { - if( bWordWrap ) - { - if( ulLastSpace == 0 ) - ulCurLength = 1; - else - ulCurLength = ulCurLength - ulLastSpace; - } - else - ulCurLength = 1; - - ulLines++; - ulLastSpace = 0; - } - } - - hb_reta( 2 ); - hb_stornl( ulLines, -1, 1 ); - hb_stornl( ulCurLength ? ulCurLength - 1 : 0, -1, 2 ); -} diff --git a/harbour/source/rtl/set.c b/harbour/source/rtl/set.c index d261a6773f..89232ba661 100644 --- a/harbour/source/rtl/set.c +++ b/harbour/source/rtl/set.c @@ -1004,8 +1004,7 @@ void hb_setInitialize( void ) hb_set.HB_SET_WRAP = FALSE; hb_set.HB_SET_DBFLOCKSCHEME = 0; hb_set.HB_SET_DEFEXTENSIONS = TRUE; - hb_set.HB_SET_EOL = ( char * ) hb_xgrab( 3 ); - memcpy( hb_set.HB_SET_EOL, hb_conNewLine(), 3 ); + hb_set.HB_SET_EOL = hb_strdup( hb_conNewLine() ); sp_sl_first = sp_sl_last = NULL; s_next_listener = 1; diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index f96c373b93..b0ecbebc6b 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -2457,6 +2457,7 @@ static void hb_vmPlus( HB_ITEM_PTR pResult, HB_ITEM_PTR pItem1, HB_ITEM_PTR pIte } else if( pResult != pItem1 ) hb_itemCopy( pResult, pItem1 ); + pResult->type &= ~HB_IT_MEMOFLAG; } else if( HB_IS_DATE( pItem1 ) && HB_IS_DATE( pItem2 ) ) { @@ -4222,6 +4223,7 @@ static void hb_vmArrayPop( void ) PHB_ITEM pDest = hb_hashGetItemPtr( pArray, pIndex ); if( pDest ) { + pValue->type &= ~HB_IT_MEMOFLAG; hb_itemMoveFromRef( pDest, pValue ); hb_stackPop(); hb_stackPop(); @@ -4321,9 +4323,11 @@ static void hb_vmArrayGen( ULONG ulElements ) /* generates an ulElements Array a { /* move items from HVM stack to created array */ for( ulPos = 0; ulPos < ulElements; ulPos++ ) - hb_itemMove( pArray->item.asArray.value->pItems + ulPos, - hb_stackItemFromTop( ( int ) ( ulPos - ulElements - 1 ) ) ); - + { + PHB_ITEM pValue = hb_stackItemFromTop( ( int ) ( ulPos - ulElements - 1 ) ); + pValue->type &= ~HB_IT_MEMOFLAG; + hb_itemMove( pArray->item.asArray.value->pItems + ulPos, pValue ); + } /* move the new array to position of first parameter */ hb_itemMove( hb_stackItemFromTop( ( int ) ( -1 - ulElements ) ), pArray ); @@ -7434,7 +7438,6 @@ HB_EXPORT BOOL hb_xvmLocalAdd( int iLocal ) hb_vmPlus( pLocal, hb_stackItemFromTop( -2 ), hb_stackItemFromTop( -1 ) ); hb_stackPop(); hb_stackPop(); - pLocal->type &= ~HB_IT_MEMOFLAG; HB_XVM_RETURN } @@ -7451,7 +7454,6 @@ HB_EXPORT BOOL hb_xvmStaticAdd( USHORT uiStatic ) hb_vmPlus( pStatic, hb_stackItemFromTop( -2 ), hb_stackItemFromTop( -1 ) ); hb_stackPop(); hb_stackPop(); - pStatic->type &= ~HB_IT_MEMOFLAG; HB_XVM_RETURN } @@ -8751,6 +8753,7 @@ static void hb_vmArrayItemPop( ULONG ulIndex ) if( pDest ) { + pValue->type &= ~HB_IT_MEMOFLAG; hb_itemMoveRef( pDest, pValue ); hb_stackPop(); hb_stackPop(); diff --git a/harbour/utils/hbtest/rt_misc.prg b/harbour/utils/hbtest/rt_misc.prg index b7c3d3c3fe..04d4a45145 100644 --- a/harbour/utils/hbtest/rt_misc.prg +++ b/harbour/utils/hbtest/rt_misc.prg @@ -58,7 +58,7 @@ #include "rt_vars.ch" FUNCTION Main_MISC() - LOCAL oError + LOCAL oError, cEOL /* Some random error object tests taken from the separate test source */ @@ -715,6 +715,7 @@ FUNCTION Main_MISC() #endif /* MLCTOPOS() */ + cEOL := SET( _SET_EOL, CHR(13) + CHR( 10 ) ) TEST_LINE( MLCTOPOS( 'A message from me', 10, 2, 0 ) , 11 ) TEST_LINE( MLCTOPOS( 'A message from me', 5, 2, 0, 4, .F. ) , 6 ) @@ -762,6 +763,8 @@ FUNCTION Main_MISC() TEST_LINE( MLCTOPOS( , , , ) , 1 ) TEST_LINE( MLCTOPOS( , .T., , ) , 1 ) + SET( _SET_EOL, cEOL ) + RETURN NIL #ifdef __HARBOUR__