From 625273cb88cefe2d4ff0e72c6ccfa9255c11f127 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 27 Aug 1999 05:02:18 +0000 Subject: [PATCH] 19990826-06:50 GMT+1 --- harbour/ChangeLog | 16 +++++- harbour/include/inkey.h | 1 + harbour/source/rtl/inkey.c | 101 ++++++++++++++++++++++++++++--------- 3 files changed, 92 insertions(+), 26 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index c2cf6f5392..5ac95ae7b2 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,17 @@ +19990826-06:50 GMT+1 Victor Szel + + * source/rtl/inkey.c + include/inkey.h + + hb_inkeyPut() added, see next. + + __KEYPUT() added. This function is able to insert *any* inkey codes + (not just the 0-255 range) to the keyboard buffer one by one. + ! __KEYBOARD() allowed to insert zero codes into the buffer which made + INKEY() hang. It's now using hb_inkeyPut() to avoid this. + % __KEYBOARD() uses ISCHAR() instead of two hb_p*() calls. Eliminated + one of the two hb_parclen() calls. + * hb_inkeyPoll() now calls hb_inkeyPut() to insert the new code. + ! INKEY() fixed parameter count checking bug introduced a few hours ago. + 19990826-06:00 GMT+1 Victor Szel * include/mouseapi.h @@ -74,7 +88,7 @@ include/hbpp.h + Standalone PP is now showing the line numbers in errors and warnings. * source/compiler/harbour.y - source/hbpp/hbplib.c + source/hbpp/hbpplib.c source/hbpp/stdalone/hbpp.c source/rtl/errorapi.c % GenError(), GenWarning(), hb_errInternel() no longer need sprintf() diff --git a/harbour/include/inkey.h b/harbour/include/inkey.h index 8ed49473cb..be71506e8c 100644 --- a/harbour/include/inkey.h +++ b/harbour/include/inkey.h @@ -47,6 +47,7 @@ /* Harbour keyboard support functions */ extern int hb_inkey ( double seconds, HB_inkey_enum event_mask, BOOL wait, BOOL forever ); /* Wait for keyboard input */ extern int hb_inkeyGet( void ); /* Extract the next key from the Harbour keyboard buffer */ +extern void hb_inkeyPut( int ch ); /* Inserts an inkey code into the keyboard buffer */ extern int hb_inkeyLast( void ); /* Return the value of the last key that was extracted */ extern int hb_inkeyNext( void ); /* Return the next key without extracting it */ extern void hb_inkeyPoll( void ); /* Poll the console keyboard to stuff the Harbour buffer */ diff --git a/harbour/source/rtl/inkey.c b/harbour/source/rtl/inkey.c index 7cdc95dda6..b20fc442e7 100644 --- a/harbour/source/rtl/inkey.c +++ b/harbour/source/rtl/inkey.c @@ -397,19 +397,8 @@ void hb_inkeyPoll( void ) /* Poll the console keyboard to stuff the Harbour #else /* TODO: Support for other platforms, such as Mac */ #endif - if( ch ) - { - if( hb_set.HB_SET_TYPEAHEAD ) - { - /* Proper typeahead support is set */ - int head = s_inkeyHead; - s_inkeyBuffer[ head++ ] = ch; - if( head >= hb_set.HB_SET_TYPEAHEAD ) head = 0; - if( head != s_inkeyTail ) s_inkeyHead = head; - else /* TODO: Add error sound */ ; - } - else s_inkeyForce = ch; /* Typeahead support is disabled */ - } + + hb_inkeyPut( ch ); } } @@ -516,7 +505,7 @@ HARBOUR HB_INKEY( void ) double seconds; HB_inkey_enum event_mask = hb_set.HB_SET_EVENTMASK; /* Default to the SET input event mask */ - if( args < 1 || args > 2 ) + if( args > 2 ) hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "INKEY" ); /* NOTE: Clipper catches this at compile time! */ if( args == 1 || ( args > 1 && hb_param( 1, IT_NUMERIC ) ) ) @@ -593,25 +582,87 @@ HARBOUR HB___KEYBOARD( void ) { /* Clear the typeahead buffer without reallocating the keyboard buffer */ hb_inkeyReset( FALSE ); - if( hb_pcount() > 0 && hb_param( 1, IT_STRING ) && hb_parclen( 1 ) ) + + if( ISCHAR( 1 ) ) { - /* Stuff the string */ - char *fPtr = hb_parc( 1 ); long size = hb_parclen( 1 ); - if( size >= hb_set.HB_SET_TYPEAHEAD ) + if( size != 0 ) { - /* Have to allow for a zero size typehead buffer */ - if( hb_set.HB_SET_TYPEAHEAD ) size = hb_set.HB_SET_TYPEAHEAD - 1; - else size = 0; - } - while( size-- ) - { - s_inkeyBuffer[ s_inkeyHead++ ] = *fPtr++; + /* Stuff the string */ + char *fPtr = hb_parc( 1 ); + + if( size >= hb_set.HB_SET_TYPEAHEAD ) + { + /* Have to allow for a zero size typehead buffer */ + if( hb_set.HB_SET_TYPEAHEAD ) size = hb_set.HB_SET_TYPEAHEAD - 1; + else size = 0; + } + + while( size-- ) + hb_inkeyPut( *fPtr++ ); } } } +void hb_inkeyPut( int ch ) +{ + if( ch ) + { + if( hb_set.HB_SET_TYPEAHEAD ) + { + /* Proper typeahead support is set */ + int head = s_inkeyHead; + s_inkeyBuffer[ head++ ] = ch; + if( head >= hb_set.HB_SET_TYPEAHEAD ) head = 0; + if( head != s_inkeyTail ) s_inkeyHead = head; + else /* TODO: Add error sound */ ; + } + else s_inkeyForce = ch; /* Typeahead support is disabled */ + } +} + +/* $DOC$ + * $FUNCNAME$ + * __KEYPUT() + * $CATEGORY$ + * Console input + * $ONELINER$ + * Put an inkey code to the keyboard buffer + * $SYNTAX$ + * __keyPut( ) + * $ARGUMENTS$ + * is the inkey code, which should be inserted into the + * keyboard buffer. + * $RETURNS$ + * There is no return value + * $DESCRIPTION$ + * Inserts an inkey code to the string buffer. The buffer is *not* + * cleared in this operation. This function allows to insert such + * inkey codes which are not in the range of 0 to 255. To insert more + * than one code, call the function repeatedly. The zero code cannot + * be inserted. + * $EXAMPLES$ + * // Stuff an Alt+PgDn key into the keyboard buffer + * __keyPut( K_ALT_PGDN ) + * $TESTS$ + * __keyPut( K_ALT_PGDN ) ; ? INKEY() ==> 417 + * __keyPut( K_F11 ) ; ? INKEY() ==> -40 + * $STATUS$ + * C + * $COMPLIANCE$ + * Was not part of Clipper + * $SEEALSO$ + * KEYBOARD, CLEAR TYPEAHEAD, INKEY + * $END$ + */ + +HARBOUR HB___KEYPUT( void ) +{ + if( ISNUM( 1 ) ) + hb_inkeyPut( hb_parni( 1 ) ); +} + /* $DOC$ * $FUNCNAME$ * NEXTKEY()