ChangeLog 20000426-13:15 GMT+1

This commit is contained in:
Ryszard Glab
2000-04-26 11:10:44 +00:00
parent 807a8ac290
commit 91e200477b
12 changed files with 563 additions and 457 deletions

View File

@@ -1,3 +1,36 @@
20000426-13:15 GMT+1 Ryszard Glab <rglab@imid.med.pl>
*include/hbcomp.h
*source/compiler/genc.c
*source/compiler/harbour.c
*source/compiler/hbfix.c
*source/compiler/hbpcode.c
*source/vm/hvm.c
* fixed support for HB_P_(PUSH/POP)LOCALNEAR - it uses two
bytes again
* added function hb_compNOOPadd() to add position of HB_P_NOOP
opcode that will be later removed at the jump optimization
phase
* due to CVS conflicts I have cancelled the latest Ron changes
in hb_compCodeblockEnd - anyway I don't see any reason to create
a temporary buffer that is filled with some values and next
copied into pcode buffer - all these values can be copied directly
NOTE: All source code HAVE TO be recompiled!
*source/rtl/gtcrs/Makefile
*source/rtl/gtcrs/gtcrs.c
*source/rtl/gtcrs/kbdcrs.c
*source/rtl/gtcrs/mousecrs.c
* added new file kbdcrs.c with keyboard support - the separation
from terminal code will allow to use different modules for
keyboard handling (for example 'rawkeys' library)
*tests/Makefile
* all test modules that were using non-standard harbour functions
are moved to BAD_PRG section
20000426-02:12 DST Paul Tucker <ptucker@sympatico.ca>
* contrib/libmisc/make_vc.bat
* correct lib name.

View File

@@ -184,6 +184,7 @@ extern void hb_compFunCallCheck( char *, int );
extern void hb_compVariableAdd( char * szVarName, char cType ); /* add a new param, local, static variable to a function definition or a public or private */
extern PVAR hb_compVariableFind( PVAR pVars, USHORT wOrder ); /* returns a variable if defined or zero */
extern PVAR hb_compLocalVariableFind( PFUNCTION pFunc, USHORT wVar );
extern PCOMSYMBOL hb_compSymbolAdd( char *, USHORT * );
extern PCOMSYMBOL hb_compSymbolKill( PCOMSYMBOL ); /* releases all memory allocated by symbol and returns the next one */
@@ -315,6 +316,7 @@ extern void hb_compPrintLogo( void );
/* Misc functions defined in harbour.c */
extern void hb_compFinalizeFunction( void ); /* fixes all last defined function returns jumps offsets */
extern void hb_compNOOPadd( PFUNCTION pFunc, ULONG ulPos );
/* Misc functions defined in hbfix.c */
extern void hb_compFixFuncPCode( PFUNCTION );

View File

@@ -918,7 +918,7 @@ static HB_GENC_FUNC( hb_p_poplocal )
fprintf( cargo->yyc, "\t/* codeblockvar%i */", wVar );
}
else
fprintf( cargo->yyc, "\t/* %s */", hb_compVariableFind( pFunc->pLocals, wVar )->szName );
fprintf( cargo->yyc, "\t/* %s */", hb_compLocalVariableFind( pFunc, wVar )->szName );
}
fprintf( cargo->yyc, "\n" );
return 3;
@@ -926,7 +926,7 @@ static HB_GENC_FUNC( hb_p_poplocal )
static HB_GENC_FUNC( hb_p_poplocalnear )
{
fprintf( cargo->yyc, "\tHB_P_POPLOCALNEAR, %i, 0,",
fprintf( cargo->yyc, "\tHB_P_POPLOCALNEAR, %i,",
pFunc->pCode[ lPCodePos + 1 ] );
if( cargo->bVerbose )
{
@@ -945,10 +945,10 @@ static HB_GENC_FUNC( hb_p_poplocalnear )
fprintf( cargo->yyc, "\t/* codeblockvar%i */", wVar );
}
else
fprintf( cargo->yyc, "\t/* %s */", hb_compVariableFind( pFunc->pLocals, wVar )->szName );
fprintf( cargo->yyc, "\t/* %s */", hb_compLocalVariableFind( pFunc, wVar )->szName );
}
fprintf( cargo->yyc, "\n" );
return 3;
return 2;
}
static HB_GENC_FUNC( hb_p_popmemvar )
@@ -1074,7 +1074,7 @@ static HB_GENC_FUNC( hb_p_pushblock )
* in which function was defined this local variable
*/
if( ( pFunc->cScope & ( HB_FS_INIT | HB_FS_EXIT ) ) != ( HB_FS_INIT | HB_FS_EXIT ) )
if( cargo->bVerbose ) fprintf( cargo->yyc, "\t/* %s */", hb_compVariableFind( pFunc->pLocals, w )->szName );
if( cargo->bVerbose ) fprintf( cargo->yyc, "\t/* %s */", hb_compLocalVariableFind( pFunc, w )->szName );
fprintf( cargo->yyc, "\n" );
lPCodePos +=2;
}
@@ -1152,7 +1152,7 @@ static HB_GENC_FUNC( hb_p_pushlocal )
fprintf( cargo->yyc, "\t/* codeblockvar%i */", wVar );
}
else
fprintf( cargo->yyc, "\t/* %s */", hb_compVariableFind( pFunc->pLocals, wVar )->szName );
fprintf( cargo->yyc, "\t/* %s */", hb_compLocalVariableFind( pFunc, wVar )->szName );
}
fprintf( cargo->yyc, "\n" );
return 3;
@@ -1160,7 +1160,7 @@ static HB_GENC_FUNC( hb_p_pushlocal )
static HB_GENC_FUNC( hb_p_pushlocalnear )
{
fprintf( cargo->yyc, "\tHB_P_PUSHLOCALNEAR, %i, 0,",
fprintf( cargo->yyc, "\tHB_P_PUSHLOCALNEAR, %i,",
pFunc->pCode[ lPCodePos + 1 ] );
if( cargo->bVerbose )
{
@@ -1179,10 +1179,10 @@ static HB_GENC_FUNC( hb_p_pushlocalnear )
fprintf( cargo->yyc, "\t/* codeblockvar%i */", wVar );
}
else
fprintf( cargo->yyc, "\t/* %s */", hb_compVariableFind( pFunc->pLocals, wVar )->szName );
fprintf( cargo->yyc, "\t/* %s */", hb_compLocalVariableFind( pFunc, wVar )->szName );
}
fprintf( cargo->yyc, "\n" );
return 3;
return 2;
}
static HB_GENC_FUNC( hb_p_pushlocalref )
@@ -1207,7 +1207,7 @@ static HB_GENC_FUNC( hb_p_pushlocalref )
fprintf( cargo->yyc, "\t/* codeblockvar%i */", wVar );
}
else
fprintf( cargo->yyc, "\t/* %s */", hb_compVariableFind( pFunc->pLocals, wVar )->szName );
fprintf( cargo->yyc, "\t/* %s */", hb_compLocalVariableFind( pFunc, wVar )->szName );
}
fprintf( cargo->yyc, "\n" );
return 3;

View File

@@ -970,6 +970,16 @@ PFUNCTION hb_compFunctionFind( char * szFunctionName ) /* returns a previously d
return NULL;
}
/* return variable using its order after final fixing */
PVAR hb_compLocalVariableFind( PFUNCTION pFunc, USHORT wVar )
{
if( pFunc->wParamCount && !(pFunc->bFlags & FUN_USES_LOCAL_PARAMS) )
{
wVar -= pFunc->wParamCount;
}
return hb_compVariableFind( pFunc->pLocals, wVar );
}
PVAR hb_compVariableFind( PVAR pVars, USHORT wOrder ) /* returns variable if defined or zero */
{
USHORT w = 1;
@@ -1282,6 +1292,22 @@ USHORT hb_compFunctionGetPos( char * szFunctionName ) /* return 0 if not found o
return 0;
}
void hb_compNOOPadd( PFUNCTION pFunc, ULONG ulPos )
{
pFunc->iNOOPs++;
if( hb_comp_functions.pLast->pNOOPs )
{
pFunc->pNOOPs = ( ULONG * ) hb_xrealloc( pFunc->pNOOPs, sizeof( ULONG ) * pFunc->iNOOPs );
pFunc->pNOOPs[ pFunc->iNOOPs - 1 ] = ulPos;
}
else
{
pFunc->pNOOPs = ( ULONG * ) hb_xgrab( sizeof( ULONG ) );
pFunc->pNOOPs[ pFunc->iNOOPs - 1 ] = ulPos;
}
}
static void hb_compPrepareOptimize()
{
if( ! hb_comp_iJumpOptimize )
@@ -1313,34 +1339,12 @@ static void hb_compPrepareOptimize()
/* 3rd. Byte might be not used */
if( hb_comp_functions.pLast->pCode[ hb_comp_functions.pLast->lPCodePos - 1 ] == HB_P_NOOP )
{
hb_comp_functions.pLast->iNOOPs++;
if( hb_comp_functions.pLast->pNOOPs )
{
hb_comp_functions.pLast->pNOOPs = ( ULONG * ) hb_xrealloc( hb_comp_functions.pLast->pNOOPs, sizeof( ULONG ) * hb_comp_functions.pLast->iNOOPs );
hb_comp_functions.pLast->pNOOPs[ hb_comp_functions.pLast->iNOOPs - 1 ] = hb_comp_functions.pLast->lPCodePos - 1;
}
else
{
hb_comp_functions.pLast->pNOOPs = ( ULONG * ) hb_xgrab( sizeof( ULONG ) );
hb_comp_functions.pLast->pNOOPs[ hb_comp_functions.pLast->iNOOPs - 1 ] = hb_comp_functions.pLast->lPCodePos - 1;
}
hb_compNOOPadd( hb_comp_functions.pLast, hb_comp_functions.pLast->lPCodePos - 1 );
/* 2nd. Byte might be not used */
if( hb_comp_functions.pLast->pCode[ hb_comp_functions.pLast->lPCodePos - 2 ] == HB_P_NOOP )
{
hb_comp_functions.pLast->iNOOPs++;
if( hb_comp_functions.pLast->pNOOPs )
{
hb_comp_functions.pLast->pNOOPs = ( ULONG * ) hb_xrealloc( hb_comp_functions.pLast->pNOOPs, sizeof( ULONG ) * hb_comp_functions.pLast->iNOOPs );
hb_comp_functions.pLast->pNOOPs[ hb_comp_functions.pLast->iNOOPs - 1 ] = hb_comp_functions.pLast->lPCodePos - 2;
}
else
{
hb_comp_functions.pLast->pNOOPs = ( ULONG * ) hb_xgrab( sizeof( ULONG ) );
hb_comp_functions.pLast->pNOOPs[ hb_comp_functions.pLast->iNOOPs - 1 ] = hb_comp_functions.pLast->lPCodePos - 2;
}
hb_compNOOPadd( hb_comp_functions.pLast, hb_comp_functions.pLast->lPCodePos - 2 );
}
}
}
@@ -1498,7 +1502,7 @@ void hb_compGenJumpThere( ULONG ulFrom, ULONG ulTo )
break;
default:
printf( "\rPCode: %i", pCode[ ( ULONG ) ulFrom - 1 ] );
/* printf( "\rPCode: %i", pCode[ ( ULONG ) ulFrom - 1 ] ); */
hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_JUMP_NOT_FOUND, NULL, NULL );
break;
}
@@ -1511,34 +1515,12 @@ void hb_compGenJumpThere( ULONG ulFrom, ULONG ulTo )
/* Check if 3rd. Byte not used. */
if( pCode[ ( ULONG ) ( ulFrom + 2 ) ] == HB_P_NOOP )
{
hb_comp_functions.pLast->iNOOPs++;
if( hb_comp_functions.pLast->pNOOPs )
{
hb_comp_functions.pLast->pNOOPs = ( ULONG * ) hb_xrealloc( hb_comp_functions.pLast->pNOOPs, sizeof( ULONG ) * hb_comp_functions.pLast->iNOOPs );
hb_comp_functions.pLast->pNOOPs[ hb_comp_functions.pLast->iNOOPs - 1 ] = ( ULONG ) ulFrom + 2;
}
else
{
hb_comp_functions.pLast->pNOOPs = ( ULONG * ) hb_xgrab( sizeof( ULONG ) );
hb_comp_functions.pLast->pNOOPs[ 0 ] = ( ULONG ) ulFrom + 2;
}
hb_compNOOPadd( hb_comp_functions.pLast, ulFrom + 2 );
/* Check if 2nd. Byte not used. */
if( pCode[ ( ULONG ) ulFrom + 1 ] == HB_P_NOOP )
{
hb_comp_functions.pLast->iNOOPs++;
if( hb_comp_functions.pLast->pNOOPs )
{
hb_comp_functions.pLast->pNOOPs = ( ULONG * ) hb_xrealloc( hb_comp_functions.pLast->pNOOPs, sizeof( ULONG ) * hb_comp_functions.pLast->iNOOPs );
hb_comp_functions.pLast->pNOOPs[ hb_comp_functions.pLast->iNOOPs - 1 ] = ( ULONG ) ulFrom + 1;
}
else
{
hb_comp_functions.pLast->pNOOPs = ( ULONG * ) hb_xgrab( sizeof( ULONG ) );
hb_comp_functions.pLast->pNOOPs[ 0 ] = ( ULONG ) ulFrom + 1;
}
hb_compNOOPadd( hb_comp_functions.pLast, ulFrom + 1 );
}
}
}
@@ -1596,7 +1578,7 @@ void hb_compGenJumpThere( ULONG ulFrom, ULONG ulTo )
break;
default:
printf( "\rPCode: %i", pCode[ ( ULONG ) ulFrom - 1 ] );
/* printf( "\rPCode: %i", pCode[ ( ULONG ) ulFrom - 1 ] ); */
hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_JUMP_NOT_FOUND, NULL, NULL );
break;
}
@@ -1610,18 +1592,7 @@ void hb_compGenJumpThere( ULONG ulFrom, ULONG ulTo )
/* Check if 3rd. Byte not used. */
if( pCode[ ( ULONG ) ulFrom + 2 ] == HB_P_NOOP )
{
hb_comp_functions.pLast->iNOOPs++;
if( hb_comp_functions.pLast->pNOOPs )
{
hb_comp_functions.pLast->pNOOPs = ( ULONG * ) hb_xrealloc( hb_comp_functions.pLast->pNOOPs, sizeof( ULONG ) * hb_comp_functions.pLast->iNOOPs );
hb_comp_functions.pLast->pNOOPs[ hb_comp_functions.pLast->iNOOPs - 1 ] = ( ULONG ) ulFrom + 2;
}
else
{
hb_comp_functions.pLast->pNOOPs = ( ULONG * ) hb_xgrab( sizeof( ULONG ) );
hb_comp_functions.pLast->pNOOPs[ 0 ] = ( ULONG ) ulFrom + 2;
}
hb_compNOOPadd( hb_comp_functions.pLast, ulFrom + 2 );
}
}
else if( lOffset >= ( -8388608L ) && lOffset <= 8388607L )
@@ -1823,7 +1794,16 @@ void hb_compGenPopVar( char * szVarName ) /* generates the pcode to pop a value
/* local variable
*/
if( iVar >= -128 && iVar <= 127 )
hb_compGenPCode3( HB_P_POPLOCALNEAR, ( BYTE ) iVar, 0 );
{
/* local variables used in a coddeblock will not be adjusted
* if PARAMETERS statement will be used then it is safe to
* use 2 bytes for LOCALNEAR
*/
if( hb_comp_functions.pLast->szName )
hb_compGenPCode3( HB_P_POPLOCALNEAR, ( BYTE ) iVar, 0 );
else
hb_compGenPCode2( HB_P_POPLOCALNEAR, ( BYTE ) iVar );
}
else
hb_compGenPCode3( HB_P_POPLOCAL, HB_LOBYTE( iVar ), HB_HIBYTE( iVar ) );
}
@@ -1979,7 +1959,16 @@ void hb_compGenPushVar( char * szVarName )
/* local variable
*/
if( iVar >= -128 && iVar <= 127 )
hb_compGenPCode3( HB_P_PUSHLOCALNEAR, ( BYTE ) iVar, 0 );
{
/* local variables used in a coddeblock will not be adjusted
* if PARAMETERS statement will be used then it is safe to
* use 2 bytes for LOCALNEAR
*/
if( hb_comp_functions.pLast->szName )
hb_compGenPCode3( HB_P_PUSHLOCALNEAR, ( BYTE ) iVar, 0 );
else
hb_compGenPCode2( HB_P_PUSHLOCALNEAR, ( BYTE ) iVar );
}
else
hb_compGenPCode3( HB_P_PUSHLOCAL, HB_LOBYTE( iVar ), HB_HIBYTE( iVar ) );
}
@@ -2350,6 +2339,30 @@ void hb_compFinalizeFunction( void ) /* fixes all last defined function returns
hb_compGenPCode1( HB_P_ENDPROC );
}
if( pFunc->bFlags & FUN_USES_LOCAL_PARAMS )
{
int PCount = pFunc->wParamCount;
/* do not adjust if local parameters are used -remove NOOPs only */
pFunc->wParamCount = 0;
/* There was a PARAMETERS statement used.
* NOTE: This fixes local variables references in a case when
* there is PARAMETERS statement after a LOCAL variable declarations.
* All local variables are numbered from 1 - which means use first
* item from the eval stack. However if PARAMETERS statement is used
* then there are additional items on the eval stack - the
* function arguments. Then first local variable is at the position
* (1 + <number of arguments>). We cannot fix this numbering
* because the PARAMETERS statement can be used even at the end
* of function body when all local variables are already created.
*/
hb_compFixFuncPCode( pFunc );
pFunc->wParamCount = PCount;
}
else
hb_compFixFuncPCode( pFunc );
if( hb_comp_iJumpOptimize && pFunc->iNOOPs )
hb_compOptimizeJumps();
@@ -2383,22 +2396,6 @@ void hb_compFinalizeFunction( void ) /* fixes all last defined function returns
pFunc->szName, NULL );
}
if( pFunc->wParamCount && !(pFunc->bFlags & FUN_USES_LOCAL_PARAMS) )
{
/* There was a PARAMETERS statement used.
* NOTE: This fixes local variables references in a case when
* there is PARAMETERS statement after a LOCAL variable declarations.
* All local variables are numbered from 1 - which means use first
* item from the eval stack. However if PARAMETERS statement is used
* then there are additional items on the eval stack - the
* function arguments. Then first local variable is at the position
* (1 + <number of arguments>). We cannot fix this nnumbering
* because the PARAMETERS statement can be used even at the end
* of function body when all local variables are already created.
*/
hb_compFixFuncPCode( pFunc );
}
}
}
@@ -2450,7 +2447,17 @@ static void hb_compOptimizeFrames( PFUNCTION pFunc )
if( bLocals || pFunc->wParamCount )
{
pFunc->pCode[ 1 ] = ( BYTE )( bLocals );
if( pFunc->bFlags & FUN_USES_LOCAL_PARAMS )
{
pFunc->pCode[ 1 ] = ( BYTE )( bLocals ) - ( BYTE )( pFunc->wParamCount );
}
else
{
/* Parameters declared with PARAMETERS statement are not
* placed in the local variable list.
*/
pFunc->pCode[ 1 ] = ( BYTE )( bLocals );
}
pFunc->pCode[ 2 ] = ( BYTE )( pFunc->wParamCount );
bSkipFRAME = FALSE;
}
@@ -2793,8 +2800,6 @@ void hb_compCodeBlockEnd( void )
USHORT wLocals = 0; /* number of referenced local variables */
USHORT wPos;
PVAR pVar, pFree;
BYTE * pBuffer;
USHORT iOffset = 0;
if( hb_comp_iJumpOptimize &&
hb_comp_functions.pLast &&
@@ -2833,37 +2838,25 @@ void hb_compCodeBlockEnd( void )
/* NOTE: 8 = HB_P_PUSHBLOCK + USHORT( size ) + USHORT( wParams ) + USHORT( wLocals ) + _ENDBLOCK */
wSize = ( USHORT ) pCodeblock->lPCodePos + 8 + wLocals * 2;
pBuffer = hb_xgrab( wSize );
pBuffer[0] = HB_P_PUSHBLOCK;
pBuffer[1] = HB_LOBYTE( wSize );
pBuffer[2] = HB_HIBYTE( wSize );
pBuffer[3] = HB_LOBYTE( pCodeblock->wParamCount );
pBuffer[4] = HB_HIBYTE( pCodeblock->wParamCount );
pBuffer[5] = HB_LOBYTE( wLocals );
pBuffer[6] = HB_HIBYTE( wLocals );
hb_compGenPCode3( HB_P_PUSHBLOCK, HB_LOBYTE( wSize ), HB_HIBYTE( wSize ) );
hb_compGenPCode2( HB_LOBYTE( pCodeblock->wParamCount ), HB_HIBYTE( pCodeblock->wParamCount ) );
hb_compGenPCode2( HB_LOBYTE( wLocals ), HB_HIBYTE( wLocals ) );
/* generate the table of referenced local variables */
pVar = pCodeblock->pStatics;
while( wLocals-- )
{
wPos = hb_compVariableGetPos( pFunc->pLocals, pVar->szName );
pBuffer[ 7 + iOffset++ ] = HB_LOBYTE( wPos );
pBuffer[ 7 + iOffset++ ] = HB_HIBYTE( wPos );
hb_compGenPCode2( HB_LOBYTE( wPos ), HB_HIBYTE( wPos ) );
pFree = pVar;
hb_xfree( ( void * ) pFree->szName );
pVar = pVar->pNext;
hb_xfree( ( void * ) pFree );
}
memcpy( ( BYTE * )( &( pBuffer[ 7 + iOffset ] ) ), pCodeblock->pCode, pCodeblock->lPCodePos );
pBuffer[ wSize - 1 ] = HB_P_ENDBLOCK;
hb_compGenPCodeN( pBuffer, wSize );
hb_xfree( ( void * ) pBuffer );
hb_compGenPCodeN( pCodeblock->pCode, pCodeblock->lPCodePos );
hb_compGenPCode1( HB_P_ENDBLOCK ); /* finish the codeblock */
/* this fake-function is no longer needed */
hb_xfree( ( void * ) pCodeblock->pCode );

View File

@@ -168,7 +168,12 @@ static HB_FIX_FUNC( hb_p_poplocalnear )
SHORT * pVar = ( SHORT * ) &( pFunc->pCode )[ lPCodePos + 1 ];
*pVar += pFunc->wParamCount;
if( !( *pVar >= -128 && *pVar <= 127 ) )
if( *pVar >= -128 && *pVar <= 127 )
{
pFunc->pCode[ lPCodePos + 2 ] = HB_P_NOOP;
hb_compNOOPadd( pFunc, lPCodePos + 2 );
}
else
{
/* After fixing this variable cannot be accessed using near code
*/
@@ -188,7 +193,12 @@ static HB_FIX_FUNC( hb_p_pushlocalnear )
SHORT * pVar = ( SHORT * ) &( pFunc->pCode )[ lPCodePos + 1 ];
*pVar += pFunc->wParamCount;
if( !( *pVar >= -128 && *pVar <= 127 ) )
if( *pVar >= -128 && *pVar <= 127 )
{
pFunc->pCode[ lPCodePos + 2 ] = HB_P_NOOP;
hb_compNOOPadd( pFunc, lPCodePos + 2 );
}
else
{
/* After fixing this variable cannot be accessed using near code
*/

View File

@@ -115,7 +115,7 @@ static BYTE s_pcode_len[] = {
3, /* HB_P_POPALIASEDVAR, */
3, /* HB_P_POPFIELD, */
3, /* HB_P_POPLOCAL, */
3, /* HB_P_POPLOCALNEAR, */
2, /* HB_P_POPLOCALNEAR, */
3, /* HB_P_POPMEMVAR, */
3, /* HB_P_POPSTATIC, */
3, /* HB_P_POPVARIABLE, */
@@ -128,7 +128,7 @@ static BYTE s_pcode_len[] = {
2, /* HB_P_PUSHBYTE, */
3, /* HB_P_PUSHINT, */
3, /* HB_P_PUSHLOCAL, */
3, /* HB_P_PUSHLOCALNEAR, */
2, /* HB_P_PUSHLOCALNEAR, */
3, /* HB_P_PUSHLOCALREF, */
1+sizeof(long), /* HB_P_PUSHLONG, */
3, /* HB_P_PUSHMEMVAR, */

View File

@@ -7,6 +7,7 @@ ROOT = ../../../
C_SOURCES=\
gtcrs.c \
mousecrs.c \
kbdcrs.c \
LIBNAME=gtcrs

View File

@@ -39,14 +39,6 @@
#include "hbapigt.h"
#include "hbinit.h"
#include "inkey.ch"
/* functions defined in mousecrs.c
*/
extern int hb_mouse_xevent( char *, HB_inkey_enum );
extern int hb_mouse_key( void );
extern int hb_mouse_initialize( void );
/* static data
*/
static USHORT s_uiDispCount;
@@ -55,29 +47,15 @@ static void gt_GetMaxRC(int* r, int* c);
static void gt_GetRC(int* r, int* c);
static void gt_SetRC(int r, int c);
static void hb_gt_Add_terminfo_keymap( int, char * );
static void hb_gt_Add_keymap( int, char * );
/* max number of characters in a keymapped string */
#define HB_MAX_KEYMAP_CHARS 16
struct key_map_struc
{
int inkey_code;
int length;
char *key_string;
struct key_map_struc *Next;
};
#define HB_HASH_KEY 128
static struct key_map_struc * s_keymap_table[ HB_HASH_KEY ];
static unsigned s_attribmap_table[ 256 ]; /* mapping from DOS style attributes */
static BOOL s_under_xterm;
static int s_alternate_char_set;
static char s_xTermBox[ 10 ] = "lqkxjqmx ";
static char * s_mouse_event_seq;
static int s_mouse_event_len;
extern void hb_gt_Initialize_Mouse( void );
extern void hb_gt_Initialize_Keyboard( void );
extern void hb_gt_Exit_Mouse( void );
extern void hb_gt_Exit_Keyboard( void );
static void hb_gt_Initialize_Terminal( void )
{
@@ -149,277 +127,32 @@ static void hb_gt_Initialize_Terminal( void )
bkgdset( ' ' );
ripoffline( 0, NULL );
/* Mouse sub-sytem have to be initialized after ncurses initialization */
hb_mouse_initialize();
}
void hb_gt_Init( int iFilenoStdin, int iFilenoStdout, int iFilenoStderr )
{
int i;
HB_TRACE(HB_TR_DEBUG, ("hb_gt_Init()"));
s_uiDispCount = 0;
initscr();
hb_gt_Initialize_Terminal();
/* Initialize keycode table */
for( i = 0; i < HB_HASH_KEY; i++ )
s_keymap_table[ i ] = NULL;
if( s_under_xterm )
{
/* NOTE: under xterm \E[M is used as a leading code for a mouse event
Events are as follows:
\E[M - prefix
b0 - a byte with buttons state
b1 - column position of a mouse pointer
b2 - row position of a mouse pointer
*/
s_mouse_event_seq = tigetstr( "kmous" );
if( s_mouse_event_seq == NULL || s_mouse_event_seq == (char *)-1 )
s_mouse_event_len =0;
else
s_mouse_event_len = strlen( s_mouse_event_seq );
hb_gt_Add_terminfo_keymap( K_HOME, "kfnd" );
hb_gt_Add_terminfo_keymap( K_END, "kslt" );
/* workaraound for xterm bug */
hb_gt_Add_terminfo_keymap( K_UP, "cuu1" );
hb_gt_Add_terminfo_keymap( K_RIGHT, "cuf1" );
hb_gt_Add_keymap( K_LEFT, "\033[D" );
hb_gt_Add_keymap( K_DOWN, "\033[B" );
}
else
{
/* NOTE: ncurses doesn't report any mouse events when run under GPM
*/
s_mouse_event_len = 0;
}
hb_gt_Add_terminfo_keymap( K_ENTER, "kent" );
hb_gt_Add_terminfo_keymap( K_ENTER, "ind" );
hb_gt_Add_terminfo_keymap( K_TAB, "ht" );
hb_gt_Add_terminfo_keymap( K_DOWN, "kcud1" );
hb_gt_Add_terminfo_keymap( K_UP, "kcuu1" );
hb_gt_Add_terminfo_keymap( K_LEFT, "kcub1" );
hb_gt_Add_terminfo_keymap( K_RIGHT, "kcuf1" );
hb_gt_Add_terminfo_keymap( K_HOME, "khome" );
hb_gt_Add_terminfo_keymap( K_END, "kend" );
hb_gt_Add_terminfo_keymap( K_BS, "kbs" );
hb_gt_Add_terminfo_keymap( K_BS, "kcbt" );
hb_gt_Add_terminfo_keymap( K_INS, "kich1" );
hb_gt_Add_terminfo_keymap( K_DEL, "kdch1" );
hb_gt_Add_terminfo_keymap( K_PGDN, "knp" );
hb_gt_Add_terminfo_keymap( K_PGUP, "kpp" );
hb_gt_Add_terminfo_keymap( K_F1, "kf1" );
hb_gt_Add_terminfo_keymap( K_F2, "kf2" );
hb_gt_Add_terminfo_keymap( K_F3, "kf3" );
hb_gt_Add_terminfo_keymap( K_F4, "kf4" );
hb_gt_Add_terminfo_keymap( K_F5, "kf5" );
hb_gt_Add_terminfo_keymap( K_F6, "kf6" );
hb_gt_Add_terminfo_keymap( K_F7, "kf7" );
hb_gt_Add_terminfo_keymap( K_F8, "kf8" );
hb_gt_Add_terminfo_keymap( K_F9, "kf9" );
hb_gt_Add_terminfo_keymap( K_F10, "kf10" );
hb_gt_Add_terminfo_keymap( K_F11, "kf11" );
hb_gt_Add_terminfo_keymap( K_F12, "kf12" );
hb_gt_Add_terminfo_keymap( K_SH_F1, "kf13" );
hb_gt_Add_terminfo_keymap( K_SH_F2, "kf14" );
hb_gt_Add_terminfo_keymap( K_SH_F3, "kf15" );
hb_gt_Add_terminfo_keymap( K_SH_F4, "kf16" );
hb_gt_Add_terminfo_keymap( K_SH_F5, "kf17" );
hb_gt_Add_terminfo_keymap( K_SH_F6, "kf18" );
hb_gt_Add_terminfo_keymap( K_SH_F7, "kf19" );
hb_gt_Add_terminfo_keymap( K_SH_F8, "kf20" );
hb_gt_Add_terminfo_keymap( K_SH_F9, "kf21" );
hb_gt_Add_terminfo_keymap( K_SH_F10, "kf22" );
hb_gt_Add_terminfo_keymap( K_SH_F11, "kf23" );
hb_gt_Add_terminfo_keymap( K_SH_F12, "kf24" );
hb_gt_Add_terminfo_keymap( K_ALT_TAB, "kcbt" );
hb_gt_Add_terminfo_keymap( K_HOME, "ka1" );
hb_gt_Add_terminfo_keymap( K_PGUP, "ka3" );
hb_gt_Add_terminfo_keymap( K_END, "kc1" );
hb_gt_Add_terminfo_keymap( K_PGDN, "kc3" );
hb_gt_Add_keymap( K_ALT_A, "\033a" );
hb_gt_Add_keymap( K_ALT_A, "\033A" );
hb_gt_Add_keymap( K_ALT_B, "\033b" );
hb_gt_Add_keymap( K_ALT_B, "\033B" );
hb_gt_Add_keymap( K_ALT_C, "\033c" );
hb_gt_Add_keymap( K_ALT_C, "\033C" );
hb_gt_Add_keymap( K_ALT_D, "\033d" );
hb_gt_Add_keymap( K_ALT_D, "\033D" );
hb_gt_Add_keymap( K_ALT_E, "\033e" );
hb_gt_Add_keymap( K_ALT_E, "\033E" );
hb_gt_Add_keymap( K_ALT_F, "\033f" );
hb_gt_Add_keymap( K_ALT_F, "\033F" );
hb_gt_Add_keymap( K_ALT_G, "\033g" );
hb_gt_Add_keymap( K_ALT_G, "\033G" );
hb_gt_Add_keymap( K_ALT_H, "\033h" );
hb_gt_Add_keymap( K_ALT_H, "\033H" );
hb_gt_Add_keymap( K_ALT_I, "\033i" );
hb_gt_Add_keymap( K_ALT_I, "\033I" );
hb_gt_Add_keymap( K_ALT_J, "\033j" );
hb_gt_Add_keymap( K_ALT_J, "\033J" );
hb_gt_Add_keymap( K_ALT_K, "\033k" );
hb_gt_Add_keymap( K_ALT_K, "\033K" );
hb_gt_Add_keymap( K_ALT_L, "\033l" );
hb_gt_Add_keymap( K_ALT_L, "\033L" );
hb_gt_Add_keymap( K_ALT_M, "\033m" );
hb_gt_Add_keymap( K_ALT_M, "\033M" );
hb_gt_Add_keymap( K_ALT_N, "\033n" );
hb_gt_Add_keymap( K_ALT_N, "\033N" );
hb_gt_Add_keymap( K_ALT_O, "\033o" );
hb_gt_Add_keymap( K_ALT_O, "\033O" );
hb_gt_Add_keymap( K_ALT_P, "\033p" );
hb_gt_Add_keymap( K_ALT_P, "\033P" );
hb_gt_Add_keymap( K_ALT_Q, "\033q" );
hb_gt_Add_keymap( K_ALT_Q, "\033Q" );
hb_gt_Add_keymap( K_ALT_R, "\033r" );
hb_gt_Add_keymap( K_ALT_R, "\033R" );
hb_gt_Add_keymap( K_ALT_S, "\033s" );
hb_gt_Add_keymap( K_ALT_S, "\033S" );
hb_gt_Add_keymap( K_ALT_T, "\033t" );
hb_gt_Add_keymap( K_ALT_T, "\033T" );
hb_gt_Add_keymap( K_ALT_U, "\033u" );
hb_gt_Add_keymap( K_ALT_U, "\033U" );
hb_gt_Add_keymap( K_ALT_V, "\033v" );
hb_gt_Add_keymap( K_ALT_V, "\033V" );
hb_gt_Add_keymap( K_ALT_W, "\033w" );
hb_gt_Add_keymap( K_ALT_W, "\033W" );
hb_gt_Add_keymap( K_ALT_X, "\033x" );
hb_gt_Add_keymap( K_ALT_X, "\033X" );
hb_gt_Add_keymap( K_ALT_Y, "\033y" );
hb_gt_Add_keymap( K_ALT_Y, "\033Y" );
hb_gt_Add_keymap( K_ALT_Z, "\033z" );
hb_gt_Add_keymap( K_ALT_Z, "\033Z" );
hb_gt_Add_keymap( K_ALT_1, "\0331" );
hb_gt_Add_keymap( K_ALT_2, "\0332" );
hb_gt_Add_keymap( K_ALT_3, "\0333" );
hb_gt_Add_keymap( K_ALT_4, "\0334" );
hb_gt_Add_keymap( K_ALT_5, "\0335" );
hb_gt_Add_keymap( K_ALT_6, "\0336" );
hb_gt_Add_keymap( K_ALT_7, "\0337" );
hb_gt_Add_keymap( K_ALT_8, "\0338" );
hb_gt_Add_keymap( K_ALT_9, "\0339" );
hb_gt_Add_keymap( K_ALT_0, "\0330" );
hb_gt_Add_keymap( K_ALT_ENTER, "\033\n" );
hb_gt_Add_keymap( K_ALT_EQUALS, "\033=" );
/* Mouse sub-sytem have to be initialized after ncurses initialization */
hb_gt_Initialize_Mouse();
hb_gt_Initialize_Keyboard();
}
void hb_gt_Exit( void )
{
int i, k;
struct key_map_struc *tmp;
HB_TRACE(HB_TR_DEBUG, ("hb_gt_Exit()"));
noraw();
refresh();
endwin();
for( i = 0; i < HB_HASH_KEY; i++ )
{
tmp = s_keymap_table[ i ];
k = 0;
while( tmp )
{
s_keymap_table[ i ] = tmp->Next;
hb_xfree( tmp );
tmp = s_keymap_table[ i ];
k++;
}
}
}
int hb_gt_ReadKey( HB_inkey_enum eventmask )
{
static char key_codes[ HB_MAX_KEYMAP_CHARS+1 ]; /* buffer for multi-characters keycodes */
static int key_waiting = -1; /* position of next character from buffer if > 0 */
int ch;
HB_TRACE(HB_TR_DEBUG, ("hb_gt_ReadKey(%d)", (int) eventmask));
if( key_waiting >= 0 )
{
/* return next character from the buffer */
ch = key_codes[ key_waiting++ ];
if( key_codes[ key_waiting ] == 0 )
key_waiting = -1; /* the last character was retrieved */
return ch;
}
ch = getch();
if( ch == ERR )
ch = hb_mouse_key();
else
{
if( ch == 3 )
{
/* Ctrl-C was pressed */
ch = HB_BREAK_FLAG;
}
else
{
int i = 0;
BYTE sum;
key_codes[ 0 ] = sum = ch;
while( ( ch = getch() ) != ERR && i <= HB_MAX_KEYMAP_CHARS )
{
key_codes[ ++i ] = ch;
/*fprintf( stderr, "key%i=%i(%c)\n", i, ch, ch );
fflush( stderr );
*/
sum += ch;
}
key_codes[ ++i ] = 0;
sum &= HB_HASH_KEY - 1;
ch = 0;
if( s_keymap_table[ sum ] )
{
/* there is an entry in the hash table */
struct key_map_struc *tmp = s_keymap_table[ sum ];
while( (ch == 0) && tmp )
{
/* now look for exact match */
if( (i == tmp->length) && (memcmp( tmp->key_string, key_codes, i ) == 0 ) )
{
ch = tmp->inkey_code; /* keycode found */
tmp = NULL; /* NOTE: tmp->inkey_code can be set to 0 */
}
else
tmp = tmp->Next;
}
}
if( ch == 0 )
{
if( s_mouse_event_len )
{
/* check for mouse event */
if( memcmp( s_mouse_event_seq, key_codes, s_mouse_event_len ) == 0 )
{
/* Convert the mouse event into INKEY keycodes */
return hb_mouse_xevent( key_codes+s_mouse_event_len, eventmask );
}
}
/* keymap not found */
if( i == 1 )
ch = key_codes[ 0 ];
else
{
key_waiting = 0; /* return raw key sequence */
ch = K_HB_KEYCODES;
}
}
}
}
return ch;
hb_gt_Exit_Mouse();
hb_gt_Exit_Keyboard();
}
BOOL hb_gt_AdjustPos( BYTE * pStr, ULONG ulLen )
@@ -832,49 +565,6 @@ USHORT hb_gt_DispCount()
return s_uiDispCount;
}
static void hb_gt_Add_keymap( int InkeyCode, char *key_string )
{
struct key_map_struc *keymap;
int iLength = strlen( key_string );
int i = 0;
BYTE sum = 0;
if( iLength && iLength <= HB_MAX_KEYMAP_CHARS )
{
while( i < iLength )
sum += key_string[ i++ ];
sum &= HB_HASH_KEY-1;
keymap = hb_xgrab( sizeof( struct key_map_struc ) );
keymap->inkey_code = InkeyCode;
keymap->key_string = key_string;
keymap->length = iLength;
keymap->Next = NULL;
if( s_keymap_table[ sum ] )
{
struct key_map_struc *tmp = s_keymap_table[ sum ];
while( tmp->Next )
tmp =tmp->Next;
tmp->Next = keymap;
}
else
s_keymap_table[ sum ] = keymap;
}
}
static void hb_gt_Add_terminfo_keymap( int InkeyCode, char *capname )
{
char * code;
code = tigetstr( capname );
if( (code != NULL) && (code != (char *)-1) )
{
hb_gt_Add_keymap( InkeyCode, code );
}
}
void hb_gt_Replicate( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE byChar, ULONG nLength )
{
HB_TRACE(HB_TR_DEBUG, ("hb_gt_Replicate(%hu, %hu, %i, %i, %lu)", uiRow, uiCol, byAttr, byChar, nLength));

View File

@@ -0,0 +1,373 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* Video subsystem based on ncurses.
*
* Copyright 2000 Ryszard Glab <rglab@imid.med.pl>
* 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 of the License, or
* (at your option) any later version, with one exception:
*
* The exception is that if you link the Harbour Runtime Library (HRL)
* and/or the Harbour Virtual Machine (HVM) 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 HRL
* and/or HVM code into it.
*
* 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 program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
* their web site at http://www.gnu.org/).
*
*/
#include <curses.h>
#include <unistd.h>
#include "hbapigt.h"
#include "hbinit.h"
#include "inkey.ch"
/* functions defined in mousecrs.c
*/
extern int hb_mouse_xevent( char *, HB_inkey_enum );
extern int hb_mouse_key( void );
static void hb_gt_Add_terminfo_keymap( int, char * );
static void hb_gt_Add_keymap( int, char * );
/* max number of characters in a keymapped string */
#define HB_MAX_KEYMAP_CHARS 16
struct key_map_struc
{
int inkey_code;
int length;
char *key_string;
struct key_map_struc *Next;
};
#define HB_HASH_KEY 128
static struct key_map_struc * s_keymap_table[ HB_HASH_KEY ];
static BOOL s_under_xterm;
static char * s_mouse_event_seq;
static int s_mouse_event_len;
void hb_gt_Initialize_Keyboard( void )
{
int i;
HB_TRACE(HB_TR_DEBUG, ("hb_gt_Initialize_Keyboard()"));
/* Initialize keycode table */
for( i = 0; i < HB_HASH_KEY; i++ )
s_keymap_table[ i ] = NULL;
s_under_xterm = !strncmp( getenv("TERM"), "xterm", 5 );
if( s_under_xterm )
{
/* NOTE: under xterm \E[M is used as a leading code for a mouse event
Events are as follows:
\E[M - prefix
b0 - a byte with buttons state
b1 - column position of a mouse pointer
b2 - row position of a mouse pointer
*/
s_mouse_event_seq = tigetstr( "kmous" );
if( s_mouse_event_seq == NULL || s_mouse_event_seq == (char *)-1 )
s_mouse_event_len =0;
else
s_mouse_event_len = strlen( s_mouse_event_seq );
hb_gt_Add_terminfo_keymap( K_HOME, "kfnd" );
hb_gt_Add_terminfo_keymap( K_END, "kslt" );
/* workaraound for xterm bug */
hb_gt_Add_terminfo_keymap( K_UP, "cuu1" );
hb_gt_Add_terminfo_keymap( K_RIGHT, "cuf1" );
hb_gt_Add_keymap( K_LEFT, "\033[D" );
hb_gt_Add_keymap( K_DOWN, "\033[B" );
}
else
{
/* NOTE: ncurses doesn't report any mouse events when run under GPM
*/
s_mouse_event_len = 0;
}
hb_gt_Add_terminfo_keymap( K_ENTER, "kent" );
hb_gt_Add_terminfo_keymap( K_ENTER, "ind" );
hb_gt_Add_terminfo_keymap( K_TAB, "ht" );
hb_gt_Add_terminfo_keymap( K_DOWN, "kcud1" );
hb_gt_Add_terminfo_keymap( K_UP, "kcuu1" );
hb_gt_Add_terminfo_keymap( K_LEFT, "kcub1" );
hb_gt_Add_terminfo_keymap( K_RIGHT, "kcuf1" );
hb_gt_Add_terminfo_keymap( K_HOME, "khome" );
hb_gt_Add_terminfo_keymap( K_END, "kend" );
hb_gt_Add_terminfo_keymap( K_BS, "kbs" );
hb_gt_Add_terminfo_keymap( K_BS, "kcbt" );
hb_gt_Add_terminfo_keymap( K_INS, "kich1" );
hb_gt_Add_terminfo_keymap( K_DEL, "kdch1" );
hb_gt_Add_terminfo_keymap( K_PGDN, "knp" );
hb_gt_Add_terminfo_keymap( K_PGUP, "kpp" );
hb_gt_Add_terminfo_keymap( K_F1, "kf1" );
hb_gt_Add_terminfo_keymap( K_F2, "kf2" );
hb_gt_Add_terminfo_keymap( K_F3, "kf3" );
hb_gt_Add_terminfo_keymap( K_F4, "kf4" );
hb_gt_Add_terminfo_keymap( K_F5, "kf5" );
hb_gt_Add_terminfo_keymap( K_F6, "kf6" );
hb_gt_Add_terminfo_keymap( K_F7, "kf7" );
hb_gt_Add_terminfo_keymap( K_F8, "kf8" );
hb_gt_Add_terminfo_keymap( K_F9, "kf9" );
hb_gt_Add_terminfo_keymap( K_F10, "kf10" );
hb_gt_Add_terminfo_keymap( K_F11, "kf11" );
hb_gt_Add_terminfo_keymap( K_F12, "kf12" );
hb_gt_Add_terminfo_keymap( K_SH_F1, "kf13" );
hb_gt_Add_terminfo_keymap( K_SH_F2, "kf14" );
hb_gt_Add_terminfo_keymap( K_SH_F3, "kf15" );
hb_gt_Add_terminfo_keymap( K_SH_F4, "kf16" );
hb_gt_Add_terminfo_keymap( K_SH_F5, "kf17" );
hb_gt_Add_terminfo_keymap( K_SH_F6, "kf18" );
hb_gt_Add_terminfo_keymap( K_SH_F7, "kf19" );
hb_gt_Add_terminfo_keymap( K_SH_F8, "kf20" );
hb_gt_Add_terminfo_keymap( K_SH_F9, "kf21" );
hb_gt_Add_terminfo_keymap( K_SH_F10, "kf22" );
hb_gt_Add_terminfo_keymap( K_SH_F11, "kf23" );
hb_gt_Add_terminfo_keymap( K_SH_F12, "kf24" );
hb_gt_Add_terminfo_keymap( K_ALT_TAB, "kcbt" );
hb_gt_Add_terminfo_keymap( K_HOME, "ka1" );
hb_gt_Add_terminfo_keymap( K_PGUP, "ka3" );
hb_gt_Add_terminfo_keymap( K_END, "kc1" );
hb_gt_Add_terminfo_keymap( K_PGDN, "kc3" );
hb_gt_Add_keymap( K_ALT_A, "\033a" );
hb_gt_Add_keymap( K_ALT_A, "\033A" );
hb_gt_Add_keymap( K_ALT_B, "\033b" );
hb_gt_Add_keymap( K_ALT_B, "\033B" );
hb_gt_Add_keymap( K_ALT_C, "\033c" );
hb_gt_Add_keymap( K_ALT_C, "\033C" );
hb_gt_Add_keymap( K_ALT_D, "\033d" );
hb_gt_Add_keymap( K_ALT_D, "\033D" );
hb_gt_Add_keymap( K_ALT_E, "\033e" );
hb_gt_Add_keymap( K_ALT_E, "\033E" );
hb_gt_Add_keymap( K_ALT_F, "\033f" );
hb_gt_Add_keymap( K_ALT_F, "\033F" );
hb_gt_Add_keymap( K_ALT_G, "\033g" );
hb_gt_Add_keymap( K_ALT_G, "\033G" );
hb_gt_Add_keymap( K_ALT_H, "\033h" );
hb_gt_Add_keymap( K_ALT_H, "\033H" );
hb_gt_Add_keymap( K_ALT_I, "\033i" );
hb_gt_Add_keymap( K_ALT_I, "\033I" );
hb_gt_Add_keymap( K_ALT_J, "\033j" );
hb_gt_Add_keymap( K_ALT_J, "\033J" );
hb_gt_Add_keymap( K_ALT_K, "\033k" );
hb_gt_Add_keymap( K_ALT_K, "\033K" );
hb_gt_Add_keymap( K_ALT_L, "\033l" );
hb_gt_Add_keymap( K_ALT_L, "\033L" );
hb_gt_Add_keymap( K_ALT_M, "\033m" );
hb_gt_Add_keymap( K_ALT_M, "\033M" );
hb_gt_Add_keymap( K_ALT_N, "\033n" );
hb_gt_Add_keymap( K_ALT_N, "\033N" );
hb_gt_Add_keymap( K_ALT_O, "\033o" );
hb_gt_Add_keymap( K_ALT_O, "\033O" );
hb_gt_Add_keymap( K_ALT_P, "\033p" );
hb_gt_Add_keymap( K_ALT_P, "\033P" );
hb_gt_Add_keymap( K_ALT_Q, "\033q" );
hb_gt_Add_keymap( K_ALT_Q, "\033Q" );
hb_gt_Add_keymap( K_ALT_R, "\033r" );
hb_gt_Add_keymap( K_ALT_R, "\033R" );
hb_gt_Add_keymap( K_ALT_S, "\033s" );
hb_gt_Add_keymap( K_ALT_S, "\033S" );
hb_gt_Add_keymap( K_ALT_T, "\033t" );
hb_gt_Add_keymap( K_ALT_T, "\033T" );
hb_gt_Add_keymap( K_ALT_U, "\033u" );
hb_gt_Add_keymap( K_ALT_U, "\033U" );
hb_gt_Add_keymap( K_ALT_V, "\033v" );
hb_gt_Add_keymap( K_ALT_V, "\033V" );
hb_gt_Add_keymap( K_ALT_W, "\033w" );
hb_gt_Add_keymap( K_ALT_W, "\033W" );
hb_gt_Add_keymap( K_ALT_X, "\033x" );
hb_gt_Add_keymap( K_ALT_X, "\033X" );
hb_gt_Add_keymap( K_ALT_Y, "\033y" );
hb_gt_Add_keymap( K_ALT_Y, "\033Y" );
hb_gt_Add_keymap( K_ALT_Z, "\033z" );
hb_gt_Add_keymap( K_ALT_Z, "\033Z" );
hb_gt_Add_keymap( K_ALT_1, "\0331" );
hb_gt_Add_keymap( K_ALT_2, "\0332" );
hb_gt_Add_keymap( K_ALT_3, "\0333" );
hb_gt_Add_keymap( K_ALT_4, "\0334" );
hb_gt_Add_keymap( K_ALT_5, "\0335" );
hb_gt_Add_keymap( K_ALT_6, "\0336" );
hb_gt_Add_keymap( K_ALT_7, "\0337" );
hb_gt_Add_keymap( K_ALT_8, "\0338" );
hb_gt_Add_keymap( K_ALT_9, "\0339" );
hb_gt_Add_keymap( K_ALT_0, "\0330" );
hb_gt_Add_keymap( K_ALT_ENTER, "\033\n" );
hb_gt_Add_keymap( K_ALT_EQUALS, "\033=" );
}
void hb_gt_Exit_Keyboard( void )
{
int i, k;
struct key_map_struc *tmp;
HB_TRACE(HB_TR_DEBUG, ("hb_kbd_Exit()"));
for( i = 0; i < HB_HASH_KEY; i++ )
{
tmp = s_keymap_table[ i ];
k = 0;
while( tmp )
{
s_keymap_table[ i ] = tmp->Next;
hb_xfree( tmp );
tmp = s_keymap_table[ i ];
k++;
}
}
}
int hb_gt_ReadKey( HB_inkey_enum eventmask )
{
static char key_codes[ HB_MAX_KEYMAP_CHARS+1 ]; /* buffer for multi-characters keycodes */
static int key_waiting = -1; /* position of next character from buffer if > 0 */
int ch;
HB_TRACE(HB_TR_DEBUG, ("hb_gt_ReadKey(%d)", (int) eventmask));
if( key_waiting >= 0 )
{
/* return next character from the buffer */
ch = key_codes[ key_waiting++ ];
if( key_codes[ key_waiting ] == 0 )
key_waiting = -1; /* the last character was retrieved */
return ch;
}
ch = getch();
if( ch == ERR )
ch = hb_mouse_key();
else
{
if( ch == 3 )
{
/* Ctrl-C was pressed */
ch = HB_BREAK_FLAG;
}
else
{
int i = 0;
BYTE sum;
key_codes[ 0 ] = sum = ch;
while( ( ch = getch() ) != ERR && i <= HB_MAX_KEYMAP_CHARS )
{
key_codes[ ++i ] = ch;
/*fprintf( stderr, "key%i=%i(%c)\n", i, ch, ch );
fflush( stderr );
*/
sum += ch;
}
key_codes[ ++i ] = 0;
sum &= HB_HASH_KEY - 1;
ch = 0;
if( s_keymap_table[ sum ] )
{
/* there is an entry in the hash table */
struct key_map_struc *tmp = s_keymap_table[ sum ];
while( (ch == 0) && tmp )
{
/* now look for exact match */
if( (i == tmp->length) && (memcmp( tmp->key_string, key_codes, i ) == 0 ) )
{
ch = tmp->inkey_code; /* keycode found */
tmp = NULL; /* NOTE: tmp->inkey_code can be set to 0 */
}
else
tmp = tmp->Next;
}
}
if( ch == 0 )
{
if( s_mouse_event_len )
{
/* check for mouse event */
if( memcmp( s_mouse_event_seq, key_codes, s_mouse_event_len ) == 0 )
{
/* Convert the mouse event into INKEY keycodes */
return hb_mouse_xevent( key_codes+s_mouse_event_len, eventmask );
}
}
/* keymap not found */
if( i == 1 )
ch = key_codes[ 0 ];
else
{
key_waiting = 0; /* return raw key sequence */
ch = K_HB_KEYCODES;
}
}
}
}
return ch;
}
static void hb_gt_Add_keymap( int InkeyCode, char *key_string )
{
struct key_map_struc *keymap;
int iLength = strlen( key_string );
int i = 0;
BYTE sum = 0;
if( iLength && iLength <= HB_MAX_KEYMAP_CHARS )
{
while( i < iLength )
sum += key_string[ i++ ];
sum &= HB_HASH_KEY-1;
keymap = hb_xgrab( sizeof( struct key_map_struc ) );
keymap->inkey_code = InkeyCode;
keymap->key_string = key_string;
keymap->length = iLength;
keymap->Next = NULL;
if( s_keymap_table[ sum ] )
{
struct key_map_struc *tmp = s_keymap_table[ sum ];
while( tmp->Next )
tmp =tmp->Next;
tmp->Next = keymap;
}
else
s_keymap_table[ sum ] = keymap;
}
}
static void hb_gt_Add_terminfo_keymap( int InkeyCode, char *capname )
{
char * code;
code = tigetstr( capname );
if( (code != NULL) && (code != (char *)-1) )
{
hb_gt_Add_keymap( InkeyCode, code );
}
}

View File

@@ -148,7 +148,7 @@ int hb_mouse_key( void )
return 0;
}
void hb_mouse_initialize( void )
void hb_gt_Initialize_Mouse( void )
{
mmask_t mm;
@@ -160,6 +160,10 @@ void hb_mouse_initialize( void )
s_last_event = -1;
}
void hb_gt_Exit_Mouse( void )
{
}
void hb_mouse_Init( void )
{
}

View File

@@ -970,7 +970,7 @@ void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols )
case HB_P_PUSHLOCALNEAR:
hb_vmPushLocal( ( signed char ) pCode[ w + 1 ] );
w += 3; /* only first two bytes are used */
w += 2; /* only first two bytes are used */
break;
case HB_P_PUSHLOCALREF:
@@ -1059,7 +1059,7 @@ void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols )
case HB_P_POPLOCALNEAR:
hb_vmPopLocal( ( signed char ) pCode[ w + 1 ] );
w += 3; /* only first two bytes are used */
w += 2; /* only first two bytes are used */
break;
case HB_P_POPSTATIC:
@@ -1302,7 +1302,7 @@ void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols )
/*
* reload the address of recovery code
*/
w = ( USHORT ) hb_stack.pItems[ s_lRecoverBase + HB_RECOVER_ADDRESS ].item.asLong.value;
w = hb_stack.pItems[ s_lRecoverBase + HB_RECOVER_ADDRESS ].item.asLong.value;
/*
* leave the SEQUENCE envelope on the stack - it will
* be popped either in RECOVER or END opcode

View File

@@ -43,7 +43,6 @@ PRG_SOURCES=\
byref.prg \
calling.prg \
cdow.prg \
clasinit.prg \
classch.prg \
classes.prg \
clsdata.prg \
@@ -56,28 +55,22 @@ PRG_SOURCES=\
dates.prg \
dates2.prg \
dates3.prg \
dates4.prg \
db_brows.prg \
dbevalts.prg \
debugtst.prg \
devtest.prg \
dirtest.prg \
disptest.prg \
docase.prg \
dosshell.prg \
dynobj.prg \
dynsym.prg \
exittest.prg \
fib.prg \
fornext.prg \
fortest.prg \
fsplit.prg \
funcarr.prg \
hello.prg \
ifelse.prg \
ifinline.prg \
inherit.prg \
inifiles.prg \
initexit.prg \
inkeytst.prg \
inline.prg \
@@ -87,15 +80,12 @@ PRG_SOURCES=\
longdev.prg \
longstr.prg \
longstr2.prg \
mathtest.prg \
memfile.prg \
memory.prg \
memvar.prg \
menutest.prg \
multiarg.prg \
nums.prg \
objarr.prg \
objasign.prg \
objects.prg \
os.prg \
output.prg \
@@ -104,12 +94,10 @@ PRG_SOURCES=\
passref.prg \
procline.prg \
procname.prg \
readfile.prg \
readhrb.prg \
recursiv.prg \
returns.prg \
round.prg \
rtfclass.prg \
say.prg \
scroll.prg \
seconds.prg \
@@ -120,9 +108,7 @@ PRG_SOURCES=\
statfun.prg \
statics.prg \
strdelim.prg \
stripem.prg \
t1.prg \
test.prg \
test_all.prg \
testbrdb.prg \
testbrw.prg \
@@ -131,13 +117,9 @@ PRG_SOURCES=\
testdbf.prg \
testerro.prg \
testfor.prg \
testgt.prg \
testhbf.prg \
testhtml.prg \
testinc.prg \
testmem.prg \
teststr.prg \
testtok.prg \
testpre.prg \
testread.prg \
testrdd.prg \
@@ -161,19 +143,37 @@ PRG_HEADERS=\
BAD_PRG_SOURCES=\
alias.prg \
clasname.prg \
clasinit.prg \
dates4.prg \
debugtst.prg \
dupvars.prg \
dynobj.prg \
extend1.prg \
funcarr.prg \
inherit.prg \
inifiles.prg \
keywords.prg \
linecont.prg \
lnlenli1.prg \
lnlenli2.prg \
mathtest.prg \
objarr.prg \
objasign.prg \
readfile.prg \
rtfclass.prg \
setkeys.prg \
spawn.prg \
spawn2.prg \
statics1.prg \
statics2.prg \
stripem.prg \
test.prg \
test10.prg \
testgt.prg \
testid.prg \
testhbf.prg \
testhtml.prg \
testtok.prg \
tstprag.prg \
vec1.prg \