From e2ef86bf9b5789a944a844cc19014c54cde1e763 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Tue, 4 Nov 2008 08:39:45 +0000 Subject: [PATCH] 2008-11-04 09:40 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbgtcore.h ! added missing 'extern' in hb_gt_dos_keyCodeTranslate() declaration * harbour/source/rtl/gtstd/gtstd.c * harbour/source/rtl/gtpca/gtpca.c + added support for console input in OpenWatcom builds * harbour/source/vm/vmmt/Makefile ! removed mainpm.c * harbour/contrib/xhb/hbcrypt.c ! fixed casting --- harbour/ChangeLog | 14 +++++++ harbour/contrib/xhb/hbcrypt.c | 42 ++++++++++---------- harbour/include/hbgtcore.h | 2 +- harbour/source/rtl/gtpca/gtpca.c | 56 ++++++++++++++++++++------ harbour/source/rtl/gtstd/gtstd.c | 67 +++++++++++++++++++++----------- harbour/source/vm/vmmt/Makefile | 2 +- 6 files changed, 126 insertions(+), 57 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f2ca29c9fa..63bb5d5eff 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,20 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-11-04 09:40 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbgtcore.h + ! added missing 'extern' in hb_gt_dos_keyCodeTranslate() declaration + + * harbour/source/rtl/gtstd/gtstd.c + * harbour/source/rtl/gtpca/gtpca.c + + added support for console input in OpenWatcom builds + + * harbour/source/vm/vmmt/Makefile + ! removed mainpm.c + + * harbour/contrib/xhb/hbcrypt.c + ! fixed casting + 2008-11-04 02:12 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/rtl/seconds.c + added #include to OpenWatcom OS2 builds. diff --git a/harbour/contrib/xhb/hbcrypt.c b/harbour/contrib/xhb/hbcrypt.c index 8a8f33974f..85a3dee418 100644 --- a/harbour/contrib/xhb/hbcrypt.c +++ b/harbour/contrib/xhb/hbcrypt.c @@ -82,7 +82,7 @@ void nxs_crypt( const unsigned char *source, ULONG srclen, const unsigned char *key, ULONG keylen, - BYTE *cipher ) + unsigned char *cipher ) { if( keylen > NXS_MAX_KEYLEN ) @@ -110,7 +110,7 @@ void nxs_crypt( void nxs_decrypt( const unsigned char *cipher, ULONG cipherlen, const unsigned char *key, ULONG keylen, - BYTE *result ) + unsigned char *result ) { if( keylen > NXS_MAX_KEYLEN ) { @@ -135,7 +135,7 @@ void nxs_decrypt( void nxs_scramble( const unsigned char *source, ULONG srclen, const unsigned char *key, ULONG keylen, - BYTE *cipher ) + unsigned char *cipher ) { int scramble[ NXS_MAX_KEYLEN ]; ULONG len; @@ -164,7 +164,7 @@ void nxs_scramble( void nxs_partial_scramble( - const unsigned char *source, BYTE *cipher, + const unsigned char *source, unsigned char *cipher, int *scramble, ULONG len, ULONG keylen ) { @@ -187,7 +187,7 @@ void nxs_partial_scramble( /* Reversing scramble process */ void nxs_unscramble( - BYTE *cipher, ULONG cipherlen, + unsigned char *cipher, ULONG cipherlen, const unsigned char *key, ULONG keylen) { int scramble[ NXS_MAX_KEYLEN ]; @@ -217,13 +217,13 @@ void nxs_unscramble( void nxs_partial_unscramble( - BYTE *cipher, + unsigned char *cipher, int *scramble, ULONG len, ULONG keylen ) { ULONG pos; USHORT kpos; - BYTE buf[ NXS_MAX_KEYLEN ]; + unsigned char buf[ NXS_MAX_KEYLEN ]; pos = 0l; kpos = 0; @@ -243,12 +243,12 @@ void nxs_partial_unscramble( /* pass two: xor the source with the key threebit mutual shift is done also here */ void nxs_xorcode( - BYTE *cipher, ULONG cipherlen, + unsigned char *cipher, ULONG cipherlen, const unsigned char *key, ULONG keylen ) { ULONG pos = 0l; USHORT keypos = 0; - BYTE c_bitrest; + unsigned char c_bitrest; c_bitrest = cipher[ 0 ] >>5; @@ -278,12 +278,12 @@ void nxs_xorcode( } void nxs_xordecode( - BYTE *cipher, ULONG cipherlen, + unsigned char *cipher, ULONG cipherlen, const unsigned char *key, ULONG keylen ) { ULONG pos = 0l; USHORT keypos = 0; - BYTE c_bitrest, c_bitleft; + unsigned char c_bitrest, c_bitleft; /* A very short block? */ if ( keylen > cipherlen - pos ) @@ -320,7 +320,7 @@ void nxs_xordecode( /* pass three: xor the source with the cyclic key */ void nxs_xorcyclic( - BYTE *cipher, ULONG cipherlen, + unsigned char *cipher, ULONG cipherlen, const unsigned char *key, ULONG keylen ) { ULONG pos=0l, crcpos=0l; @@ -341,16 +341,16 @@ void nxs_xorcyclic( if ( crcpos < 4 ) { /* this ensures portability across platforms */ - cipher[ pos ] ^= (BYTE) (crc1l % 256 ); + cipher[ pos ] ^= (unsigned char) (crc1l % 256 ); crc1l /= 256l; } else if ( crcpos < 8 ) { - cipher[ pos ] ^= (BYTE) (crc2l % 256 ); + cipher[ pos ] ^= (unsigned char) (crc2l % 256 ); crc2l /= 256l; } else { - cipher[ pos ] ^= (BYTE) (crc3l % 256 ); + cipher[ pos ] ^= (unsigned char) (crc3l % 256 ); crc3l /= 256l; } crcpos++; @@ -420,11 +420,11 @@ HB_FUNC( HB_CRYPT ) PHB_ITEM pSource = hb_param( 1, HB_IT_ANY ); PHB_ITEM pKey = hb_param( 2, HB_IT_ANY ); - BYTE * cRes = ( BYTE * ) hb_xgrab( hb_itemGetCLen( pSource ) + 8 ); + unsigned char * cRes = ( unsigned char * ) hb_xgrab( hb_itemGetCLen( pSource ) + 8 ); nxs_crypt( - ( BYTE * ) hb_itemGetCPtr( pSource ), hb_itemGetCLen( pSource ), - ( BYTE * ) hb_itemGetCPtr( pKey ), hb_itemGetCLen( pKey ), + ( unsigned char * ) hb_itemGetCPtr( pSource ), hb_itemGetCLen( pSource ), + ( unsigned char * ) hb_itemGetCPtr( pKey ), hb_itemGetCLen( pKey ), cRes ); hb_retclenAdopt( ( char * ) cRes, hb_itemGetCLen( pSource ) ); @@ -441,11 +441,11 @@ HB_FUNC( HB_DECRYPT ) PHB_ITEM pSource = hb_param( 1, HB_IT_ANY ); PHB_ITEM pKey = hb_param( 2, HB_IT_ANY ); - BYTE * cRes = ( BYTE * ) hb_xgrab( hb_itemGetCLen( pSource ) + 8 ); + unsigned char * cRes = ( unsigned char * ) hb_xgrab( hb_itemGetCLen( pSource ) + 8 ); nxs_decrypt( - ( BYTE * ) hb_itemGetCPtr( pSource ), hb_itemGetCLen( pSource ), - ( BYTE * ) hb_itemGetCPtr( pKey ), hb_itemGetCLen( pKey ), + ( unsigned char * ) hb_itemGetCPtr( pSource ), hb_itemGetCLen( pSource ), + ( unsigned char * ) hb_itemGetCPtr( pKey ), hb_itemGetCLen( pKey ), cRes ); hb_retclenAdopt( ( char * ) cRes, hb_itemGetCLen( pSource ) ); diff --git a/harbour/include/hbgtcore.h b/harbour/include/hbgtcore.h index e485dca678..b9a36efd82 100644 --- a/harbour/include/hbgtcore.h +++ b/harbour/include/hbgtcore.h @@ -618,7 +618,7 @@ extern void hb_gt_w32_setKbdState( int kbdShifts ); extern void hb_gt_w32_tone( double dFrequency, double dDuration ); #endif /* HB_OS_WIN_32 */ #if defined( HB_OS_DOS ) || defined( HB_OS_WIN_32 ) || defined( HB_OS_OS2 ) -int hb_gt_dos_keyCodeTranslate( int iKey ); +extern int hb_gt_dos_keyCodeTranslate( int iKey ); #endif /* HB_OS_DOS || HB_OS_WIN_32 || HB_OS_OS2 */ HB_EXTERN_END diff --git a/harbour/source/rtl/gtpca/gtpca.c b/harbour/source/rtl/gtpca/gtpca.c index df7cd85c3d..1b4a8aebdb 100644 --- a/harbour/source/rtl/gtpca/gtpca.c +++ b/harbour/source/rtl/gtpca/gtpca.c @@ -81,12 +81,12 @@ #include #include #else - #if defined( HB_WIN32_IO ) - #include - #endif - #if defined( _MSC_VER ) && !defined( HB_WINCE ) - #include - #endif +# if defined( HB_WIN32_IO ) +# include +# endif +# if ( defined( _MSC_VER ) || defined( __WATCOMC__ ) ) && !defined( HB_WINCE ) +# include +# endif #endif static int s_GtId; @@ -586,6 +586,21 @@ static int hb_gt_pca_ReadKey( PHB_GT pGT, int iEventMask ) ch = hb_gt_dos_keyCodeTranslate( ch ); if( ch > 0 && ch <= 255 ) ch = s_keyTransTbl[ ch ]; +#elif defined( HB_OS_UNIX_COMPATIBLE ) || defined( __DJGPP__ ) + { + struct timeval tv; + fd_set rfds; + tv.tv_sec = 0; + tv.tv_usec = 0; + FD_ZERO( &rfds ); + FD_SET( s_hFilenoStdin, &rfds ); + if( select( s_hFilenoStdin + 1, &rfds, NULL, NULL, &tv ) > 0 ) + { + BYTE bChar; + if( hb_fsRead( s_hFilenoStdin, &bChar, 1 ) == 1 ) + ch = s_keyTransTbl[ bChar ]; + } + } #elif defined( _MSC_VER ) && !defined( HB_WINCE ) if( s_bStdinConsole ) { @@ -609,12 +624,6 @@ static int hb_gt_pca_ReadKey( PHB_GT pGT, int iEventMask ) if( _read( s_hFilenoStdin, &bChar, 1 ) == 1 ) ch = s_keyTransTbl[ bChar ]; } -#elif defined( HB_OS_UNIX_COMPATIBLE ) || defined( __DJGPP__ ) - { - BYTE bChar; - if( hb_fsRead( s_hFilenoStdin, &bChar, 1 ) == 1 ) - ch = s_keyTransTbl[ bChar ]; - } #elif defined( HB_WIN32_IO ) if( !s_bStdinConsole || WaitForSingleObject( ( HANDLE ) hb_fsGetOsHandle( s_hFilenoStdin ), 0 ) == 0x0000 ) @@ -623,6 +632,29 @@ static int hb_gt_pca_ReadKey( PHB_GT pGT, int iEventMask ) if( hb_fsRead( s_hFilenoStdin, &bChar, 1 ) == 1 ) ch = s_keyTransTbl[ bChar ]; } +#elif defined( __WATCOMC__ ) + if( s_bStdinConsole ) + { + if( kbhit() ) + { + ch = getch(); + if( ( ch == 0 || ch == 224 ) && kbhit() ) + { + /* It was a function key lead-in code, so read the actual + function key and then offset it by 256 */ + ch = getch() + 256; + } + ch = hb_gt_dos_keyCodeTranslate( ch ); + if( ch > 0 && ch <= 255 ) + ch = s_keyTransTbl[ ch ]; + } + } + else if( !eof( s_hFilenoStdin ) ) + { + BYTE bChar; + if( read( s_hFilenoStdin, &bChar, 1 ) == 1 ) + ch = s_keyTransTbl[ bChar ]; + } #else { int TODO; /* TODO: */ diff --git a/harbour/source/rtl/gtstd/gtstd.c b/harbour/source/rtl/gtstd/gtstd.c index dce9ec6b27..f9a4d3f999 100644 --- a/harbour/source/rtl/gtstd/gtstd.c +++ b/harbour/source/rtl/gtstd/gtstd.c @@ -72,12 +72,12 @@ #include #include #else - #if defined( HB_WIN32_IO ) - #include - #endif - #if defined( _MSC_VER ) && !defined( HB_WINCE ) - #include - #endif +# if defined( HB_WIN32_IO ) +# include +# endif +# if ( defined( _MSC_VER ) || defined( __WATCOMC__ ) ) && !defined( HB_WINCE ) +# include +# endif #endif static int s_GtId; @@ -338,7 +338,22 @@ static int hb_gt_std_ReadKey( PHB_GT pGT, int iEventMask ) pGTSTD = HB_GTSTD_GET( pGT ); -#if defined( _MSC_VER ) && !defined( HB_WINCE ) +#if defined( HB_OS_UNIX_COMPATIBLE ) || defined( __DJGPP__ ) + { + struct timeval tv; + fd_set rfds; + tv.tv_sec = 0; + tv.tv_usec = 0; + FD_ZERO( &rfds ); + FD_SET( pGTSTD->hStdin, &rfds ); + if( select( pGTSTD->hStdin + 1, &rfds, NULL, NULL, &tv ) > 0 ) + { + BYTE bChar; + if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) + ch = pGTSTD->keyTransTbl[ bChar ]; + } + } +#elif defined( _MSC_VER ) && !defined( HB_WINCE ) if( pGTSTD->fStdinConsole ) { if( _kbhit() ) @@ -361,21 +376,6 @@ static int hb_gt_std_ReadKey( PHB_GT pGT, int iEventMask ) if( _read( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = pGTSTD->keyTransTbl[ bChar ]; } -#elif defined( HB_OS_UNIX_COMPATIBLE ) || defined( __DJGPP__ ) - { - struct timeval tv; - fd_set rfds; - tv.tv_sec = 0; - tv.tv_usec = 0; - FD_ZERO( &rfds ); - FD_SET( pGTSTD->hStdin, &rfds); - if( select( pGTSTD->hStdin + 1, &rfds, NULL, NULL, &tv ) > 0 ) - { - BYTE bChar; - if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) - ch = pGTSTD->keyTransTbl[ bChar ]; - } - } #elif defined( HB_WIN32_IO ) if( !pGTSTD->fStdinConsole || WaitForSingleObject( ( HANDLE ) hb_fsGetOsHandle( pGTSTD->hStdin ), 0 ) == 0x0000 ) @@ -384,6 +384,29 @@ static int hb_gt_std_ReadKey( PHB_GT pGT, int iEventMask ) if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = pGTSTD->keyTransTbl[ bChar ]; } +#elif defined( __WATCOMC__ ) + if( pGTSTD->fStdinConsole ) + { + if( kbhit() ) + { + ch = getch(); + if( ( ch == 0 || ch == 224 ) && kbhit() ) + { + /* It was a function key lead-in code, so read the actual + function key and then offset it by 256 */ + ch = getch() + 256; + } + ch = hb_gt_dos_keyCodeTranslate( ch ); + if( ch > 0 && ch <= 255 ) + ch = pGTSTD->keyTransTbl[ ch ]; + } + } + else if( !eof( pGTSTD->hStdin ) ) + { + BYTE bChar; + if( read( pGTSTD->hStdin, &bChar, 1 ) == 1 ) + ch = pGTSTD->keyTransTbl[ bChar ]; + } #else { int TODO; /* TODO: */ diff --git a/harbour/source/vm/vmmt/Makefile b/harbour/source/vm/vmmt/Makefile index f70abdf168..0d16e1af5f 100644 --- a/harbour/source/vm/vmmt/Makefile +++ b/harbour/source/vm/vmmt/Makefile @@ -19,7 +19,7 @@ ifeq ($(HB_ARCHITECTURE),w32) endif else ifeq ($(HB_ARCHITECTURE),os2) - C_MAIN = mainstd.c mainpm.c + C_MAIN = mainstd.c else C_MAIN = main.c endif