diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 341d4058ec..a9d36ab7e5 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,21 @@ The license applies to all entries newer than 2009-04-28. */ +2010-07-07 14:50 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/src/rtl/cdpapi.c + % removed one redundant if() condition + * replaced not working HB_CDP_[UN]LOCK used in hb_cdpList() + function with simple counter as protection against possible + overflow. + + * harbour/src/compiler/complex.c + + added support also for "." as date delimiters in VFP compatible + date[time] constant values. + + * harbour/doc/xhb-diff.txt + * updated description of date[time] constant values syntax + to follow current Harbour and xHarbour behavior. + 2010-07-07 12:52 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbide/idemisc.prg * contrib/hbide/ideprojmanager.prg diff --git a/harbour/doc/xhb-diff.txt b/harbour/doc/xhb-diff.txt index a89b11f43f..78661b100f 100644 --- a/harbour/doc/xhb-diff.txt +++ b/harbour/doc/xhb-diff.txt @@ -1074,10 +1074,10 @@ goal of DATETIME values and their arithmetic in xHarbour VM for the future. Both compilers tries to support VFP like datetime constant values in the following format: { ^ [ YYYY-MM-DD [,] ] [ HH[:MM[:SS][.FFF]] [AM|PM] ] } -In Harbour the following characters can be used as date delimiters: "-", "/". -Dot "." as date delimiter is not supported. +In Harbour and VFP the following characters can be used as date delimiters: +"-", "/" and "." xHarbour supports only "/" as date delimiter. -There is no limit on number of characters in YYYY, MM, DD, HH, MM, SS, FFF +There is no limit on number of digits in YYYY, MM, DD, HH, MM, SS, FFF parts. Important is only their value. This is the format in semi PP notation: { ^ [[] [ [ : [ : [ . ] ] ] [AM|PP] ] } @@ -1093,10 +1093,6 @@ Harbour supports VFP syntax only in Compiler. It's not supported in macrocompiler and it can be disabled in the future so it's not suggested to use with Harbour programs. -Both compilers supports also date constants in the form 0dYYYYMMDD f.e.: - 0d20090520. -It's also supported by macrocompilers. - Only Harbour supports date constant (in compiler and macrocompiler) in the form d"YYYY-MM-DD" f.e.: d"2009-05-20" @@ -1116,6 +1112,10 @@ f.e.: The following characters can be used as date delimiters: "-", "/", "." if PM or AM is used HH is in range < 1 : 12 > otherwise in range < 0 : 23 > +Harbour compiler and macrocompiler support also date constants in the +form 0dYYYYMMDD f.e.: + 0d20090520. + ### EXTENDED LITERAL STRING IN COMPILER AND MACROCOMPILER ### diff --git a/harbour/src/compiler/complex.c b/harbour/src/compiler/complex.c index 51b1ea5886..69d5a0097b 100644 --- a/harbour/src/compiler/complex.c +++ b/harbour/src/compiler/complex.c @@ -379,13 +379,10 @@ static int hb_comp_dayTimeDecode( PHB_COMP_LEX pLex, PHB_PP_TOKEN pToken, * to follow the hours with a colon. * { ^ [[] * [ [ : [ : [ . ] ] ] [AM|PP] ] } - * We will not accept dot as date delimiter to avoid possible - * conflicts with PP. */ - /* Now support for dates constatns: {^YYYY/MM/DD} or {^YYYY-MM-DD} */ - PHB_PP_TOKEN pYear, pMonth, pDay; - HB_MAXINT lYear, lMonth, lDay; + PHB_PP_TOKEN pYear, pMonth, pDay, pTime = NULL; + HB_MAXINT lYear = 0, lMonth = 0, lDay = 0; long lDate = 0, lTime = 0; double dNumber; int iDec, iWidth, iType = 0; @@ -412,21 +409,48 @@ static int hb_comp_dayTimeDecode( PHB_COMP_LEX pLex, PHB_PP_TOKEN pToken, !hb_compStrToNum( pDay->value, pDay->len, &lDay, &dNumber, &iDec, &iWidth ) ) { - pDay = pDay->pNext; - lDate = hb_dateEncode( ( long ) lYear, ( long ) lMonth, ( long ) lDay ); - if( lDate != 0 || ( lYear == 0 && lMonth == 0 && lDay == 0 ) ) + pTime = pDay->pNext; + } + } + } + else if( HB_PP_TOKEN_TYPE( pYear->pNext->type ) == HB_PP_TOKEN_NUMBER && + pYear->pNext->pNext ) + { + if( hb_compStrToNum( pYear->value, pYear->len, &lYear, &dNumber, + &iDec, &iWidth ) ) + { + if( iDec == 2 ) + { + lYear = ( HB_MAXINT ) dNumber; + lMonth = ( HB_MAXINT ) ( dNumber * 100 + 0.1 ) % 100; + pDay = pYear->pNext; + if( hb_compStrToNum( pDay->value, pDay->len, &lDay, &dNumber, + &iDec, &iWidth ) ) { - iType = NUM_DATE; - if( HB_PP_TOKEN_TYPE( pDay->type ) != HB_PP_TOKEN_RIGHT_CB ) + if( iDec == 2 ) { - if( HB_PP_TOKEN_TYPE( pDay->type ) == HB_PP_TOKEN_COMMA ) - pDay = pDay->pNext; - iType = hb_comp_timeDecode( pDay, &lTime ) ? TIMESTAMP : 0; + lDay = ( HB_MAXINT ) ( dNumber * 100 + 0.1 ); + pTime = pDay->pNext; } } } } } + + if( pTime ) + { + lDate = hb_dateEncode( ( long ) lYear, ( long ) lMonth, ( long ) lDay ); + if( lDate != 0 || ( lYear == 0 && lMonth == 0 && lDay == 0 ) ) + { + iType = NUM_DATE; + if( HB_PP_TOKEN_TYPE( pTime->type ) != HB_PP_TOKEN_RIGHT_CB ) + { + if( HB_PP_TOKEN_TYPE( pTime->type ) == HB_PP_TOKEN_COMMA ) + pTime = pTime->pNext; + iType = hb_comp_timeDecode( pTime, &lTime ) ? TIMESTAMP : 0; + } + } + } else if( hb_comp_timeDecode( pYear, &lTime ) ) iType = TIMESTAMP; } diff --git a/harbour/src/rtl/cdpapi.c b/harbour/src/rtl/cdpapi.c index 26735e01df..685147c07b 100644 --- a/harbour/src/rtl/cdpapi.c +++ b/harbour/src/rtl/cdpapi.c @@ -2087,14 +2087,11 @@ static PHB_CODEPAGE * hb_cdpFindPos( const char * id ) cdp_ptr = &s_cdpList; - if( id ) + while( *cdp_ptr ) { - while( *cdp_ptr ) - { - if( strcmp( ( *cdp_ptr )->id, id ) == 0 ) - break; - cdp_ptr = &( *cdp_ptr )->next; - } + if( strcmp( ( *cdp_ptr )->id, id ) == 0 ) + break; + cdp_ptr = &( *cdp_ptr )->next; } return cdp_ptr; @@ -2212,11 +2209,9 @@ const char * hb_cdpSelectID( const char * id ) const char ** hb_cdpList( void ) { PHB_CODEPAGE cdp; - int iCount; + int iCount, iPos; const char ** list; - HB_CDP_LOCK - cdp = s_cdpList; iCount = 0; while( cdp ) @@ -2228,15 +2223,13 @@ const char ** hb_cdpList( void ) list = ( const char ** ) hb_xgrab( ( iCount + 1 ) * sizeof( char * ) ); cdp = s_cdpList; - iCount = 0; - while( cdp ) + iPos = 0; + while( cdp && iPos < iCount ) { - list[ iCount++ ] = cdp->id; + list[ iPos++ ] = cdp->id; cdp = cdp->next; } - list[ iCount ] = NULL; - - HB_CDP_UNLOCK + list[ iPos ] = NULL; return list; }