diff --git a/harbour/ChangeLog b/harbour/ChangeLog index cb08b756e7..224539d1a1 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,29 @@ +19990614-15:40 EDT David G. Holm + * include/extend.h + - Added declaration for hb_stricmp() + * include/version.h + - Changed revision code to "b" + * source/rtl/classes.c + - Now uses hb_stricmp() instead of stricmp() + * source/rtl/console.c + - Now uses hb_stricmp() instead of stricmp() + * source/rtl/dates.c + - Fixed several bugs reported by Jose Lalin, who included + the appropriate fix for most of them. + * source/rtl/files.c + - Removed test code that was accidentally included in CVS + - Added default #define for O_BINARY + * source/rtl/set.c + - Now uses hb_stricmp() instead of stricmp() + - Added default #define for O_BINARY + * source/rtl/strcmp.c + - Added new hb_stricmp() function, because stricmp() is not + an ANSI C function. If stricmp() exists, it is used, else + if strcasecmp exists, then it is used, otherwise use byte + by byte comparision. + * tests/working/dates3.prg + - Added more test cases + 19990614 11:50 CET Eddie Runia * source/compiler/harbour.y help text changed diff --git a/harbour/include/extend.h b/harbour/include/extend.h index 86a5225cdf..9db658b8c0 100644 --- a/harbour/include/extend.h +++ b/harbour/include/extend.h @@ -159,6 +159,7 @@ void hb_arrayAdd( PHB_ITEM pArray, PHB_ITEM pItemValue ); int hb_itemStrCmp( PHB_ITEM pFirst, PHB_ITEM pSecond, BOOL bForceExact ); /* our string compare */ char * hb_str( PHB_ITEM pNumber, PHB_ITEM pWidth, PHB_ITEM pDec ); /* convert number to string */ +int hb_stricmp( const char *s1, const char *s2 ); BOOL hb_strempty( char * szText, ULONG ulLen ); long hb_dateEncode( long lDay, long lMonth, long lYear ); void hb_dateDecode( long julian, long * plDay, long * plMonth, long * plYear ); diff --git a/harbour/include/version.h b/harbour/include/version.h index 74f00c5646..9d70b61ff8 100644 --- a/harbour/include/version.h +++ b/harbour/include/version.h @@ -17,7 +17,7 @@ #define hb_major 0 /* Major version number */ #define hb_minor 0 /* Minor version number */ - #define hb_revision "a" /* Revision letter */ + #define hb_revision "b" /* Revision letter */ #define hb_build 26 /* Build number */ #define hb_year 1999 /* Build year */ #define hb_month 6 /* Build month */ diff --git a/harbour/source/rtl/classes.c b/harbour/source/rtl/classes.c index 89e595bcad..1aa9aa2745 100644 --- a/harbour/source/rtl/classes.c +++ b/harbour/source/rtl/classes.c @@ -970,7 +970,7 @@ HARBOUR HB___INSTSUPER( void ) for( w = 0; !bFound && w < wClasses; w++ ) { /* Locate the entry */ - if( !stricmp( pString->value.szText, pClasses[ w ].szName ) ) + if( !hb_stricmp( pString->value.szText, pClasses[ w ].szName ) ) { _retni( w + 1 ); /* Entry + 1 = ClassH */ bFound = TRUE; diff --git a/harbour/source/rtl/console.c b/harbour/source/rtl/console.c index 3d11898bc8..df38835fbd 100644 --- a/harbour/source/rtl/console.c +++ b/harbour/source/rtl/console.c @@ -204,7 +204,7 @@ static void hb_altout( char * fpStr, WORD uiLen ) { #ifdef USE_GTAPI _gtWriteCon( fpStr, uiLen ); - if( stricmp( hb_set.HB_SET_DEVICE, "PRINTER" ) || hb_set_printhan < 0 ) + if( hb_stricmp( hb_set.HB_SET_DEVICE, "PRINTER" ) || hb_set_printhan < 0 ) _gtGetPos( &dev_row, &dev_col ); #else WORD uiCount; @@ -229,7 +229,7 @@ static void hb_altout( char * fpStr, WORD uiLen ) /* Output an item to the screen and/or printer */ static void hb_devout( char * fpStr, WORD uiLen ) { - if( stricmp( hb_set.HB_SET_DEVICE, "PRINTER" ) == 0 && hb_set_printhan >= 0 ) + if( hb_stricmp( hb_set.HB_SET_DEVICE, "PRINTER" ) == 0 && hb_set_printhan >= 0 ) { /* Display to printer if SET DEVICE TO PRINTER and valid printer file */ write( hb_set_printhan, fpStr, uiLen ); @@ -260,7 +260,7 @@ void hb_devpos( USHORT row, USHORT col ) int count; /* Position printer if SET DEVICE TO PRINTER and valid printer file otherwise position console */ - if( stricmp( hb_set.HB_SET_DEVICE, "PRINTER" ) == 0 && hb_set_printhan >= 0 ) + if( hb_stricmp( hb_set.HB_SET_DEVICE, "PRINTER" ) == 0 && hb_set_printhan >= 0 ) { if( row < p_row ) { @@ -368,7 +368,7 @@ HARBOUR HB_DEVOUT( void ) /* writes a single values to the current device (scree HARBOUR HB_EJECT( void ) /* Ejects the current page from the printer */ { - if( stricmp( hb_set.HB_SET_DEVICE, "PRINTER" ) == 0 && hb_set_printhan >= 0 ) + if( hb_stricmp( hb_set.HB_SET_DEVICE, "PRINTER" ) == 0 && hb_set_printhan >= 0 ) { write( hb_set_printhan, "\x0C", 1 ); p_row = p_col = 0; diff --git a/harbour/source/rtl/dates.c b/harbour/source/rtl/dates.c index 25c5b6f833..e32d1cff9f 100644 --- a/harbour/source/rtl/dates.c +++ b/harbour/source/rtl/dates.c @@ -14,11 +14,6 @@ #define _OPTIMIZE_DTOS #endif -/* -ADJ is 7 for ISO, 6 for no ISO -*/ -#define ADJ 7 - extern STACK stack; /* In msgxxx.c modules */ @@ -69,20 +64,9 @@ long hb_dateEncode( long lDay, long lMonth, long lYear ) { /* Month, year, and lower day limits are simple, but upper day limit is dependent upon month and leap year */ - BOOL bLeapYear = FALSE; int aiDayLimit [12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - if( lYear % 4 == 0 ) - { - /* Check for leap year (every year that is evenly divisible by 4, - except for centuries, which must be evenly divisible by 400 */ - if( lYear % 100 == 0 ) - { - if( lYear % 400 == 0) bLeapYear = TRUE; /* Leap century */ - } - else bLeapYear = TRUE; /* Leap year */ - - if( bLeapYear ) aiDayLimit[ 1 ] = 29; - } + if( (( lYear % 4 == 0 && lYear % 100 != 0 ) || lYear % 400 == 0 ) ) + aiDayLimit[ 1 ] = 29; if( lDay <= (long)aiDayLimit[ (int)lMonth - 1 ] ) bValid = TRUE; } if( bValid ) @@ -97,16 +81,25 @@ void hb_dateDecode( long julian, long * plDay, long * plMonth, long * plYear ) { long U, V, W, X; - julian += 68569; - W = ( julian * 4 ) / 146097; - julian -= ( ( 146097 * W ) + 3 ) / 4; - X = 4000 * ( julian + 1 ) / 1461001; - julian -= ( ( 1461 * X ) / 4 ) - 31; - V = 80 * julian / 2447; - U = V / 11; - if( plDay ) * plDay = julian - ( 2447 * V / 80 ); - if( plMonth ) * plMonth = V + 2 - ( U * 12 ); - if( plYear ) * plYear = X + U + ( W - 49 ) * 100; + if( julian > 0 ) + { + julian += 68569; + W = ( julian * 4 ) / 146097; + julian -= ( ( 146097 * W ) + 3 ) / 4; + X = 4000 * ( julian + 1 ) / 1461001; + julian -= ( ( 1461 * X ) / 4 ) - 31; + V = 80 * julian / 2447; + U = V / 11; + if( plDay ) * plDay = julian - ( 2447 * V / 80 ); + if( plMonth ) * plMonth = V + 2 - ( U * 12 ); + if( plYear ) * plYear = X + U + ( W - 49 ) * 100; + } + else + { + * plDay = 0; + * plMonth = 0; + * plYear = 0; + } } HARBOUR HB_CTOD( void ) @@ -170,14 +163,14 @@ HARBOUR HB_CTOD( void ) y_value = (y_value * 10) + digit - '0'; } } - else + else if( digit != ' ' ) { d_pos--; m_pos--; y_pos--; } } - if (y_value < 100) + if (y_value > 0 && y_value < 100) { count = hb_set.HB_SET_EPOCH % 100; digit = hb_set.HB_SET_EPOCH / 100; @@ -504,7 +497,7 @@ long hb_dow( long d, long m, long y ) else m++; - return ( d + 26 * m / 10 + y + y / 4 - y / 100 + y / 400 + ADJ ) % 7; + return ( ( d + 26 * m / 10 + y + y / 4 - y / 100 + y / 400 + 6 ) % 7 + 1 ); } HARBOUR HB_DOW( void ) @@ -514,8 +507,13 @@ HARBOUR HB_DOW( void ) if( pDate ) { - hb_dateDecode( pDate->value.lDate, &lDay, &lMonth, &lYear ); - _retni( hb_dow( lDay, lMonth, lYear ) ); + if( pDate->value.lDate ) + { + hb_dateDecode( pDate->value.lDate, &lDay, &lMonth, &lYear ); + _retni( hb_dow( lDay, lMonth, lYear ) ); + } + else + _retni( 0 ); stack.Return.wLength = 3; } else diff --git a/harbour/source/rtl/files.c b/harbour/source/rtl/files.c index 4f62fa7a0f..bfeb4a5f1c 100644 --- a/harbour/source/rtl/files.c +++ b/harbour/source/rtl/files.c @@ -56,6 +56,9 @@ #define PATH_SEPARATOR '\\' #endif +#ifndef O_BINARY + #define O_BINARY 0 /* O_BINARY not defined on Linux */ +#endif #ifndef S_IEXEC #define S_IEXEC 0x0040 /* owner may execute */ diff --git a/harbour/source/rtl/set.c b/harbour/source/rtl/set.c index cbc72a5aab..cea879bdc1 100644 --- a/harbour/source/rtl/set.c +++ b/harbour/source/rtl/set.c @@ -14,6 +14,10 @@ #include #include +#ifndef O_BINARY + #define O_BINARY 0 /* O_BINARY not defined on Linux */ +#endif + HB_set_struct hb_set; BOOL hb_set_century; @@ -122,13 +126,6 @@ static int open_handle (char * file_name, BOOL bMode, char * def_ext) handle = open (path, O_BINARY|O_WRONLY|O_CREAT|(bMode?O_APPEND:O_TRUNC), S_IWRITE ); - if (handle < 0) - { - printf("\nError %d creating %s", errno, path); -#if !defined(__GNUC__) && !defined(__DJGPP__) - printf(" (DOS error %02x)", _doserrno); -#endif - } if (handle < 0) { char error_message [32]; @@ -332,7 +329,7 @@ HARBOUR HB_SET (void) { /* If the print file is not already open, open it. */ hb_set.HB_SET_DEVICE = set_string (pArg2, hb_set.HB_SET_DEVICE); - if (stricmp (hb_set.HB_SET_DEVICE, "PRINTER") == 0 && hb_set_printhan < 0 + if (hb_stricmp (hb_set.HB_SET_DEVICE, "PRINTER") == 0 && hb_set_printhan < 0 && hb_set.HB_SET_PRINTFILE && strlen (hb_set.HB_SET_PRINTFILE) > 0) hb_set_printhan = open_handle (hb_set.HB_SET_PRINTFILE, bFlag, ".prn"); } diff --git a/harbour/source/rtl/strcmp.c b/harbour/source/rtl/strcmp.c index 302c1af0a3..1f59a56f7b 100644 --- a/harbour/source/rtl/strcmp.c +++ b/harbour/source/rtl/strcmp.c @@ -5,6 +5,37 @@ #include #include +int hb_stricmp( const char *s1, const char *s2 ) +{ +#ifdef stricmp + return( stricmp( s1, s2 ) ); +#else +#ifdef strcasecmp + return( strcasecmp( s1, s2 ) ); +#else + int rc = 0; + USHORT c1, c2, count; + c1 = strlen( s1 ); + c2 = strlen( s2 ); + if( c1 < c2 ) count = c1; + else count = c2; + while( rc == 0 && count > 0 ) + { + if( *s1 != *s2 ) rc = ( *s1 < *s2 ? -1 : 1 ); + s1++; + s2++; + count--; + } + if( rc == 0 && c1 != c2 ) + { + if( c1 < c2 ) rc = -1; + else rc = 1; + } + return rc; +#endif +#endif +} + /* Check whether two strings are equal (0), smaller (-1), or greater (1) */ int hb_itemStrCmp( PHB_ITEM pFirst, PHB_ITEM pSecond, BOOL bForceExact ) { diff --git a/harbour/tests/working/dates3.prg b/harbour/tests/working/dates3.prg index 546c2ca5a5..26a445a268 100644 --- a/harbour/tests/working/dates3.prg +++ b/harbour/tests/working/dates3.prg @@ -4,7 +4,7 @@ function main() - LOCAL dDate + LOCAL dDate, i set( _SET_DATEFORMAT, "dd/mm/yyyy" ) dDate := cToD( "25/05/1999" ) @@ -31,6 +31,14 @@ function main() dDate += 4 OutStd( dDate, dow( dDate ), chr( 10 ) ) + + OutStd( chr( 10 ) ) + dDate := DATE () + FOR i := 1 TO 7 + OutStd( dDate, dow( dDate ), chr( 10 ) ) + dDate++ + NEXT + OutStd( ctod( "" ), dow( ctod( "" ) ), chr( 10 ) ) return nil