gtsln

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  
c:\harbour\source\rtl\gtsln
gtsln.c
TypeFunctionSourceLine
STATIC VOIDsigwinch_handler( int iSig )
static void sigwinch_handler( int iSig )
{
   HB_SYMBOL_UNUSED( iSig );

   hb_sln_bScreen_Size_Changed = TRUE;
   SLsignal( SIGWINCH, sigwinch_handler );
}
gtsln.c129
STATIC VOIDhb_sln_colorTrans( void )
static void hb_sln_colorTrans( void )
{
   int i, clr, fg, bg;

   for( i = 0; i < 256; i++ )
   {
      fg = ( i & 0x0F );
      /*
       * bit 7 is a blinking attribute - not used when console is not in
       * UTF-8 mode because we are using it for changing into ACSC
       * In SLANG 2.0 the character attributes are hold in USHORT not BYTE
       * so we can use all colors, blinking bit and ACSC switch without
       * any problems also when console is not in UTF-8 mode.
       */
#ifdef HB_SLN_UTF8 /* slang 2.0 */
      bg = ( i >> 4 ) & 0x0F;
#else
      bg = ( i >> 4 ) & ( hb_sln_Is_Unicode ? 0x0F : 0x07 );
#endif
      /*
       * in Clipper default color i 0x07 when in Slang 0x00,
       * we make a small trick with XOR 7 to make default colors
       * the same.
       */
      clr = ( bg << 4 ) | ( fg ^ 0x07 );
      SLtt_set_color( clr, ( char * ) NULL, ( char * ) s_colorNames[ fg ],
                                            ( char * ) s_colorNames[ bg ] );
#ifdef HB_SLN_UTF8
      s_colorTab[ i ] = clr;
#else
      HB_SLN_BUILD_RAWCHAR( s_colorTab[ i ], 0, clr );
#endif
   }
}
gtsln.c140
STATIC VOIDhb_sln_setSingleBox( void )
static void hb_sln_setSingleBox( void )
{
   /* convert all box chars into Clipper _B_SINBLE */
   s_outputTab[ 186 ] = s_outputTab[ 179 ];
   s_outputTab[ 205 ] = s_outputTab[ 196 ];

   s_outputTab[ 181 ] = s_outputTab[ 180 ];
   s_outputTab[ 182 ] = s_outputTab[ 180 ];
   s_outputTab[ 185 ] = s_outputTab[ 180 ];

   s_outputTab[ 183 ] = s_outputTab[ 191 ];
   s_outputTab[ 184 ] = s_outputTab[ 191 ];
   s_outputTab[ 187 ] = s_outputTab[ 191 ];

   s_outputTab[ 200 ] = s_outputTab[ 192 ];
   s_outputTab[ 211 ] = s_outputTab[ 192 ];
   s_outputTab[ 212 ] = s_outputTab[ 192 ];

   s_outputTab[ 202 ] = s_outputTab[ 193 ];
   s_outputTab[ 207 ] = s_outputTab[ 193 ];
   s_outputTab[ 208 ] = s_outputTab[ 193 ];

   s_outputTab[ 203 ] = s_outputTab[ 194 ];
   s_outputTab[ 209 ] = s_outputTab[ 194 ];
   s_outputTab[ 210 ] = s_outputTab[ 194 ];

   s_outputTab[ 198 ] = s_outputTab[ 195 ];
   s_outputTab[ 199 ] = s_outputTab[ 195 ];
   s_outputTab[ 204 ] = s_outputTab[ 195 ];

   s_outputTab[ 206 ] = s_outputTab[ 197 ];
   s_outputTab[ 215 ] = s_outputTab[ 197 ];
   s_outputTab[ 216 ] = s_outputTab[ 197 ];

   s_outputTab[ 188 ] = s_outputTab[ 217 ];
   s_outputTab[ 189 ] = s_outputTab[ 217 ];
   s_outputTab[ 190 ] = s_outputTab[ 217 ];

   s_outputTab[ 201 ] = s_outputTab[ 218 ];
   s_outputTab[ 213 ] = s_outputTab[ 218 ];
   s_outputTab[ 214 ] = s_outputTab[ 218 ];
}
gtsln.c177
STATIC VOIDhb_sln_setACSCtrans( void )
static void hb_sln_setACSCtrans( void )
{
   unsigned char * p, ch;
   SLsmg_Char_Type chBoard[3], chArrow[4];

   memset( &chArrow, 0, sizeof( chArrow ) );
   memset( &chBoard, 0, sizeof( chBoard ) );

   HB_SLN_BUILD_RAWCHAR( chBoard[ 0 ], 0, 0 );
   HB_SLN_BUILD_RAWCHAR( chBoard[ 1 ], 0, 0 );
   HB_SLN_BUILD_RAWCHAR( chBoard[ 2 ], 0, 0 );

   HB_SLN_BUILD_RAWCHAR( chArrow[ 0 ], '<', 0 );
   HB_SLN_BUILD_RAWCHAR( chArrow[ 1 ], '>', 0 );
   HB_SLN_BUILD_RAWCHAR( chArrow[ 2 ], 'v', 0 );
   HB_SLN_BUILD_RAWCHAR( chArrow[ 3 ], '^', 0 );

   /* init an alternate chars table */
   if( ( p = ( unsigned char * ) SLtt_Graphics_Char_Pairs ) )
   {
      SLsmg_Char_Type SLch;
      int i, len = strlen( ( char * ) p );

      memset( &SLch, 0, sizeof( SLsmg_Char_Type ) );
      for( i = 0; i < len; i += 2 )
      {
         ch = *p++;
         HB_SLN_BUILD_RAWCHAR( SLch, *p++, 0 );
         HB_SLN_SET_ACSC( SLch );
         switch( ch )
         {
#ifdef HB_SLN_UNICODE
            case SLSMG_HLINE_CHAR_TERM   :   s_outputTab[ 196 ] = SLch; break;
            case SLSMG_VLINE_CHAR_TERM   :   s_outputTab[ 179 ] = SLch; break;
            case SLSMG_ULCORN_CHAR_TERM  :   s_outputTab[ 218 ] = SLch; break;
            case SLSMG_URCORN_CHAR_TERM  :   s_outputTab[ 191 ] = SLch; break;
            case SLSMG_LLCORN_CHAR_TERM  :   s_outputTab[ 192 ] = SLch; break;
            case SLSMG_LRCORN_CHAR_TERM  :   s_outputTab[ 217 ] = SLch; break;
            case SLSMG_RTEE_CHAR_TERM    :   s_outputTab[ 180 ] = SLch; break;
            case SLSMG_LTEE_CHAR_TERM    :   s_outputTab[ 195 ] = SLch; break;
            case SLSMG_UTEE_CHAR_TERM    :   s_outputTab[ 194 ] = SLch; break;
            case SLSMG_DTEE_CHAR_TERM    :   s_outputTab[ 193 ] = SLch; break;
            case SLSMG_PLUS_CHAR_TERM    :   s_outputTab[ 197 ] = SLch; break;
/*
            case SLSMG_DEGREE_CHAR_TERM  :   s_outputTab[    ] = SLch; break;
            case SLSMG_PLMINUS_CHAR_TERM :   s_outputTab[    ] = SLch; break;
            case SLSMG_BULLET_CHAR_TERM  :   s_outputTab[    ] = SLch; break;
*/
            case SLSMG_DIAMOND_CHAR_TERM :   s_outputTab[ 04 ] = SLch; break;
            case SLSMG_LARROW_CHAR_TERM  :   chArrow[ 0 ] = SLch; break;
            case SLSMG_RARROW_CHAR_TERM  :   chArrow[ 1 ] = SLch; break;
            case SLSMG_DARROW_CHAR_TERM  :   chArrow[ 2 ] = SLch; break;
            case SLSMG_UARROW_CHAR_TERM  :   chArrow[ 3 ] = SLch; break;
            case SLSMG_BOARD_CHAR_TERM   :   chBoard[ 0 ] = SLch; break;
            case SLSMG_CKBRD_CHAR_TERM   :   chBoard[ 1 ] = SLch; break;
            case SLSMG_BLOCK_CHAR_TERM   :   chBoard[ 2 ] = SLch; break;
#else
            case SLSMG_HLINE_CHAR   :   s_outputTab[ 196 ] = SLch; break;
            case SLSMG_VLINE_CHAR   :   s_outputTab[ 179 ] = SLch; break;
            case SLSMG_ULCORN_CHAR  :   s_outputTab[ 218 ] = SLch; break;
            case SLSMG_URCORN_CHAR  :   s_outputTab[ 191 ] = SLch; break;
            case SLSMG_LLCORN_CHAR  :   s_outputTab[ 192 ] = SLch; break;
            case SLSMG_LRCORN_CHAR  :   s_outputTab[ 217 ] = SLch; break;
            case SLSMG_RTEE_CHAR    :   s_outputTab[ 180 ] = SLch; break;
            case SLSMG_LTEE_CHAR    :   s_outputTab[ 195 ] = SLch; break;
            case SLSMG_UTEE_CHAR    :   s_outputTab[ 194 ] = SLch; break;
            case SLSMG_DTEE_CHAR    :   s_outputTab[ 193 ] = SLch; break;
            case SLSMG_PLUS_CHAR    :   s_outputTab[ 197 ] = SLch; break;
/*
            case SLSMG_DEGREE_CHAR; :   s_outputTab[    ] = SLch; break;
            case SLSMG_PLMINUS_CHAR :   s_outputTab[    ] = SLch; break;
            case SLSMG_BULLET_CHAR  :   s_outputTab[    ] = SLch; break;
*/
            case SLSMG_DIAMOND_CHAR :   s_outputTab[ 04 ] = SLch; break;
            case SLSMG_LARROW_CHAR  :   chArrow[ 0 ] = SLch; break;
            case SLSMG_RARROW_CHAR  :   chArrow[ 1 ] = SLch; break;
            case SLSMG_DARROW_CHAR  :   chArrow[ 2 ] = SLch; break;
            case SLSMG_UARROW_CHAR  :   chArrow[ 3 ] = SLch; break;
            case SLSMG_BOARD_CHAR   :   chBoard[ 0 ] = SLch; break;
            case SLSMG_CKBRD_CHAR   :   chBoard[ 1 ] = SLch; break;
            case SLSMG_BLOCK_CHAR   :   chBoard[ 2 ] = SLch; break;
#endif
         }
      }

      HB_SLN_BUILD_RAWCHAR( SLch, 0, 0 );
      for ( i = 0; i < 3 && !HB_SLN_IS_CHAR( SLch ); i++ )
         SLch = chBoard[ i ];
      if ( !HB_SLN_IS_CHAR( SLch ) )
         HB_SLN_BUILD_RAWCHAR( SLch, '#', 0 );
      for ( i = 0; i < 3; i++ )
      {
         if ( !HB_SLN_IS_CHAR( chBoard[ i ] ) )
            chBoard[ i ] = SLch;
      }
      s_outputTab[ 176 ] = chBoard[ 0 ];
      s_outputTab[ 177 ] = chBoard[ 1 ];
      s_outputTab[ 178 ] = chBoard[ 2 ];
      s_outputTab[ 219 ] = chBoard[ 2 ];

      s_outputTab[ 17 ] = s_outputTab[ 27 ] = chArrow[ 0 ];
      s_outputTab[ 16 ] = s_outputTab[ 26 ] = chArrow[ 1 ];
      s_outputTab[ 25 ] = s_outputTab[ 31 ] = chArrow[ 2 ];
      s_outputTab[ 24 ] = s_outputTab[ 30 ] = chArrow[ 3 ];

#ifdef HB_SLN_UNICODE
      /*
       * There is a bug in SLANG lib patched for UTF-8 support
       * SLSMG_UTEE_CHAR_TERM is reverted with SLSMG_DTEE_CHAR_TERM
       * They should be mapped:
       *    SLSMG_UTEE_CHAR_TERM = 'w'
       *    SLSMG_DTEE_CHAR_TERM = 'v'
       * Below it's a hack for this version of slang which fix the
       * problem.
       */
      if ( SLSMG_UTEE_CHAR_TERM == 'v' )
      {
         SLch = s_outputTab[ 193 ];
         s_outputTab[ 193 ] = s_outputTab[ 194 ];
         s_outputTab[ 194 ] = SLch;
      }
#endif
   }
}
gtsln.c222
STATIC VOIDhb_sln_setCharTrans( PHB_CODEPAGE cdpHost, PHB_CODEPAGE cdpTerm, BOOL fBox )
static void hb_sln_setCharTrans( PHB_CODEPAGE cdpHost, PHB_CODEPAGE cdpTerm, BOOL fBox )
{
   int i, iSrc, iDst;

#ifdef HB_CDP_SUPPORT_OFF
   HB_SYMBOL_UNUSED( cdpHost );
   HB_SYMBOL_UNUSED( cdpTerm );
   HB_SYMBOL_UNUSED( fBox );
   HB_SYMBOL_UNUSED( iSrc );
#endif

   /* build a conversion chars table */
   for( i = 0; i < 256; i++ )
   {
#ifndef HB_CDP_SUPPORT_OFF
      if( hb_sln_Is_Unicode )
         iDst = hb_cdpGetU16( cdpHost, TRUE, ( BYTE ) i );
      else
#endif
         iDst = i;

      if( iDst < 32 )
         /* under Unix control-chars are not visible in a general meaning */
         HB_SLN_BUILD_RAWCHAR( s_outputTab[ i ], '.', 0 );
      else if( ! hb_sln_Is_Unicode && i >= 128 )
      {
         HB_SLN_BUILD_RAWCHAR( s_outputTab[ i ], iDst, 0 );
         HB_SLN_SET_ACSC( s_outputTab[ i ] );
      }
      else
         HB_SLN_BUILD_RAWCHAR( s_outputTab[ i ], iDst, 0 );
      s_outboxTab[ i ] = s_outputTab[ i ];
   }


   if( ! hb_sln_Is_Unicode )
   {
      hb_sln_setACSCtrans();

      /* QUESTION: do we have double, single-double, ... frames under xterm ? */
      if( hb_sln_UnderXterm )
         hb_sln_setSingleBox();

      memcpy( s_outboxTab, s_outputTab, sizeof( s_outputTab ) );

#ifndef HB_CDP_SUPPORT_OFF
      if( cdpHost && cdpHost->nChars )
      {
#ifdef HB_SLN_UNICODE
         HB_SYMBOL_UNUSED( cdpTerm );
#else
         BOOL fTrans = cdpTerm && cdpTerm->nChars == cdpHost->nChars;
#endif

         for( i = 0; i < cdpHost->nChars; i++ )
         {
            iSrc = ( unsigned char ) cdpHost->CharsUpper[ i ];
#ifdef HB_SLN_UNICODE
            iDst = hb_cdpGetU16( cdpHost, TRUE, ( BYTE ) iSrc );
#else
            iDst = fTrans ? ( unsigned char ) cdpTerm->CharsUpper[ i ] : iSrc;
#endif
            HB_SLN_BUILD_RAWCHAR( s_outputTab[ iSrc ], iDst, 0 );
            if( fBox )
               s_outboxTab[ iSrc ] = s_outputTab[ iSrc ];

            iSrc = ( unsigned char ) cdpHost->CharsLower[ i ];
#ifdef HB_SLN_UNICODE
            iDst = hb_cdpGetU16( cdpHost, TRUE, ( BYTE ) iSrc );
#else
            iDst = fTrans ? ( unsigned char ) cdpTerm->CharsLower[ i ] : iSrc;
#endif
            HB_SLN_BUILD_RAWCHAR( s_outputTab[ iSrc ], iDst, 0 );
            if( fBox )
               s_outboxTab[ iSrc ] = s_outputTab[ iSrc ];
         }
      }
#endif
   }
}
gtsln.c349
STATIC VOIDhb_sln_setKeyTrans( PHB_CODEPAGE cdpHost, PHB_CODEPAGE cdpTerm )
static void hb_sln_setKeyTrans( PHB_CODEPAGE cdpHost, PHB_CODEPAGE cdpTerm )
{
   char *p;
   int i;

   for ( i = 0; i < 256; i++ )
      hb_sln_inputTab[ i ] = ( unsigned char ) i;

#ifndef HB_CDP_SUPPORT_OFF
   if ( cdpHost && cdpTerm && cdpTerm->nChars == cdpHost->nChars )
   {
      int iSrc, iDst;

      for ( i = 0; i < cdpHost->nChars; i++ )
      {
         iSrc = ( unsigned char ) cdpTerm->CharsUpper[ i ];
         iDst = ( unsigned char ) cdpHost->CharsUpper[ i ];
         hb_sln_inputTab[ iSrc ] = iDst;

         iSrc = ( unsigned char ) cdpTerm->CharsLower[ i ];
         iDst = ( unsigned char ) cdpHost->CharsLower[ i ];
         hb_sln_inputTab[ iSrc ] = iDst;
      }
   }
   hb_sln_cdpIN = cdpTerm ? cdpTerm : cdpHost;
#else
   HB_SYMBOL_UNUSED( cdpHost );
   HB_SYMBOL_UNUSED( cdpTerm );
#endif

   /* init national chars */
   p = hb_getenv( hb_NationCharsEnvName );
   if( p )
   {
      int len = strlen( p ) >> 1, ch;

      /* no more than 128 National chars are allowed */
      if( len > 128 ) len = 128;

      /* the first element contains a number of Dead keys defined in an ENVAR */
      hb_sln_convKDeadKeys[ 0 ] = ( unsigned char ) len;

      len <<= 1;
      for( i = 0; i < len; i += 2 )
      {
         ch = ( unsigned char ) p[ i + 1 ];
         hb_sln_convKDeadKeys[ i + 1 ] = ( unsigned char ) p[ i ];
         hb_sln_convKDeadKeys[ i + 2 ] = ch;
         hb_sln_inputTab[ ch ] = ch;
      }
      hb_xfree( ( void * ) p );
   }
}
gtsln.c430
STATIC VOIDhb_sln_SetCursorStyle( int iStyle )
static void hb_sln_SetCursorStyle( int iStyle )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_sln_SetCursorStyle(%d)", iStyle));

   if( s_iCursorStyle == SC_UNAVAIL )
      return;

   if( s_iCursorStyle >= SC_NONE && s_iCursorStyle <= SC_SPECIAL2 )
   {
      SLtt_set_cursor_visibility( iStyle != SC_NONE );

      /* NOTE: cursor apearence works only under linux console */
      if( hb_sln_UnderLinuxConsole && s_iCursorStyle != iStyle )
      {
         /* keyseq to define cursor shape under linux console */
         char cursDefseq[] = { 27, '[', '?', '1', 'c', 0 };

         switch( iStyle )
         {
            case SC_NONE:
               cursDefseq[ 3 ] = '1';
               break;

            case SC_NORMAL:
               cursDefseq[ 3 ] = '2';
               break;

            case SC_INSERT:
               cursDefseq[ 3 ] = '4';
               break;

            case SC_SPECIAL1:
               cursDefseq[ 3 ] = '8';
               break;

            case SC_SPECIAL2:
               /* TODO: find a proper sequqnce to set a cursor
                  to SC_SPECIAL2 under Linux console  */
               cursDefseq[ 3 ] = '4';
               break;
         }
         SLtt_write_string( cursDefseq );
      }
      s_iCursorStyle = iStyle;
   }
}
gtsln.c487
STATIC INThb_sln_isUTF8( int iStdOut, int iStdIn )
static int hb_sln_isUTF8( int iStdOut, int iStdIn )
{
   if( isatty( iStdOut ) && isatty( iStdIn ) )
   {
      const char * szBuf = "\r\303\255\033[6n";
      struct timeval tv;
      fd_set rdfds;

      write( iStdOut, szBuf, strlen( szBuf ) );
      FD_ZERO( &rdfds );
      FD_SET( iStdIn, &rdfds );
      tv.tv_sec = 2;
      tv.tv_usec = 0;
      if( select( iStdIn + 1, &rdfds, NULL, NULL, &tv ) > 0 )
      {
         char rdbuf[ 100 ];
         int n, y, x;
         n = read( iStdIn, rdbuf, sizeof( rdbuf ) - 1 );
         if( n >= 6 )
         {
            rdbuf[ n ] = '\0';
            if( sscanf( rdbuf, "\033[%d;%dR", &y, &x ) == 2 )
            {
               return x == 2 ? 1 : 0;
            }
         }
      }
   }
   return -1;
}
gtsln.c536
STATIC VOIDhb_gt_sln_Init( PHB_GT pGT, HB_FHANDLE hFilenoStdin, HB_FHANDLE hFilenoStdout, HB_FHANDLE hFilenoStderr )
static void hb_gt_sln_Init( PHB_GT pGT, HB_FHANDLE hFilenoStdin, HB_FHANDLE hFilenoStdout, HB_FHANDLE hFilenoStderr )
{
   BOOL gt_Inited = FALSE;

   HB_TRACE(HB_TR_DEBUG, ("hb_gt_sln_Init(%p,%p,%p,%p)", pGT, hFilenoStdin, hFilenoStdout, hFilenoStderr));

   /* stdin && stdout && stderr */
   s_hStdIn  = hFilenoStdin;
   s_hStdOut = hFilenoStdout;
   s_hStdErr = hFilenoStderr;

   s_fStdInTTY  = isatty( s_hStdIn );
   s_fStdOutTTY = isatty( s_hStdOut );
   s_fStdErrTTY = isatty( s_hStdErr );

   /* Slang file descriptors */
   SLang_TT_Read_FD  = -1;
   SLang_TT_Write_FD = -1;

   /* read a terminal descripion from a terminfo database */
   SLtt_get_terminfo();

   /* initialize higher-level Slang routines */
   if( SLkp_init() != -1 )
   {
      /* initialize a terminal stuff and a Slang
         keyboard subsystem for the first time */
      if( hb_sln_Init_Terminal( 0 ) )
      {
         /* fix an OutStd()/OutErr() output */
         if( !isatty( hFilenoStdout ) )
             SLang_TT_Write_FD = SLang_TT_Read_FD;

#ifdef HB_SLN_UTF8
         hb_sln_Is_Unicode = SLutf8_enable(
                        hb_sln_isUTF8( SLang_TT_Write_FD, SLang_TT_Read_FD ) );
#endif
#ifdef HB_SLN_UNICODE
            /* SLsmg_Setlocale = 0; */
#endif
            /* initialize a screen handling subsytem */
         if( SLsmg_init_smg() != -1 )
         {
            /* install window resize handler */
            SLsignal( SIGWINCH, sigwinch_handler );

            /* do not indicate USER_BREAK in SLang_Error - ??? */
            SLang_Ignore_User_Abort = 1;

            /* no default abort procesing */
            SLang_set_abort_signal( NULL );

            /* NOTE: this is incompatible with CLIPPER
               but under Unix we should assume cursor is
               visible on startup because we cannot figure
               out a current cursor state */

            /* turn on a cursor visibility */
            if( SLtt_set_cursor_visibility( 1 ) == -1 )
                s_iCursorStyle = SC_UNAVAIL;

            /* NOTE: this driver is implemented in a way that it is
               imposible to get intensity/blinking background mode.
               The reason is the way Slang is written.
               This is incompatible with Clipper.
               But when the console is in UTF-8 mode we don't need
               to switch into ACSC because we can display all supported
               characters using it's UNICODE values so we can use
               blink bit as in Clipper.
               In SLANG 2.0 the character attributes are hold in USHORT
               not BYTE so we can use all colors, blinking bit and ACSC
               switch without any problems also when console is not in
               UTF-8 mode.
             */
#ifdef HB_SLN_UTF8
            SLtt_Blink_Mode = 1;
            SLtt_Use_Blink_For_ACS = 0;
#else
#  ifdef HB_SLN_UNICODE
            hb_sln_Is_Unicode = SLsmg_Is_Unicode;
#  endif
            if( hb_sln_Is_Unicode )
            {
               SLtt_Blink_Mode = 1;
               SLtt_Use_Blink_For_ACS = 1;
            }
            else
            {
               SLtt_Blink_Mode = 0;
               SLtt_Use_Blink_For_ACS = 0;
            }
#endif
            SLsmg_Display_Eight_Bit = 128;
            SLsmg_Newline_Behavior = SLSMG_NEWLINE_SCROLLS;

            /* initialize conversion tables */
            hb_sln_colorTrans();
            hb_sln_setCharTrans( hb_vmCDP(), NULL, TRUE );
            hb_sln_setKeyTrans( hb_vmCDP(), NULL );

            /* ensure we are in a normal chars set */
            SLtt_set_alt_char_set( 0 );

             /* set the normal Slang color */
            SLsmg_set_color( 0 );

            /* NOTE: due to a work of a Slang library which does not
               prepare its internal screen buffer properly, a screen
               must be cleared before normal work. This is not
               compatible with Clipper */
            SLsmg_cls();
            SLsmg_gotorc( 0, 0 );
            SLsmg_refresh();

            gt_Inited = TRUE;
         }
      }
   }

   if( ! gt_Inited )
   {
      /* something went wrong - restore default settings */
      SLang_reset_tty();
      hb_errInternal( 9997, "Internal error: screen driver initialization failure", NULL, NULL );
   }

   s_fActive = TRUE;
   hb_gt_sln_mouse_Init();
   HB_GTSUPER_INIT( pGT, hFilenoStdin, hFilenoStdout, hFilenoStderr );
   HB_GTSELF_RESIZE( pGT, SLtt_Screen_Rows, SLtt_Screen_Cols );
   HB_GTSELF_SETFLAG( pGT, HB_GTI_COMPATBUFFER, FALSE );
   HB_GTSELF_SETFLAG( pGT, HB_GTI_STDOUTCON, s_fStdOutTTY );
   HB_GTSELF_SETFLAG( pGT, HB_GTI_STDERRCON, s_fStdErrTTY );

   HB_GTSELF_SETBLINK( pGT, TRUE );
   HB_GTSELF_SETPOS( pGT, SLsmg_get_row(), SLsmg_get_column() );
}
gtsln.c569
STATIC VOIDhb_gt_sln_Exit( PHB_GT pGT )
static void hb_gt_sln_Exit( PHB_GT pGT )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_gt_sln_Exit(%p)", pGT));

   /* restore a standard bell frequency and duration */
   if( hb_sln_UnderLinuxConsole )
   {
      SLtt_write_string( ( char * ) "\033[10]" );
      SLtt_write_string( ( char * ) "\033[11]" );
      SLtt_flush_output();
   }

   HB_GTSELF_REFRESH( pGT );
   hb_gt_sln_mouse_Exit();
   /* NOTE: This is incompatible with Clipper - on exit leave a cursor visible */
   hb_sln_SetCursorStyle( SC_NORMAL );

   SLsmg_refresh();
   SLsmg_reset_smg();
   SLang_reset_tty();

   s_fStdInTTY = s_fStdOutTTY = s_fStdErrTTY = s_fActive = FALSE;

   HB_GTSUPER_EXIT( pGT );
}
gtsln.c710
STATIC BOOLhb_gt_sln_SetMode( PHB_GT pGT, int iRows, int iCols )
static BOOL hb_gt_sln_SetMode( PHB_GT pGT, int iRows, int iCols )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_gt_sln_SetMode(%p,%d,%d)", pGT, iRows, iCols));

   HB_SYMBOL_UNUSED( pGT );
   HB_SYMBOL_UNUSED( iRows );
   HB_SYMBOL_UNUSED( iCols );

   /* TODO: How to change the size of the screen? */
   return FALSE;
}
gtsln.c738
STATIC BOOLhb_gt_sln_IsColor( PHB_GT pGT )
static BOOL hb_gt_sln_IsColor( PHB_GT pGT )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_gt_sln_IsColor(%p)", pGT));

   HB_SYMBOL_UNUSED( pGT );

   return SLtt_Use_Ansi_Colors;
}
gtsln.c752
STATIC VOIDhb_gt_sln_SetBlink( PHB_GT pGT, BOOL fBlink )
static void hb_gt_sln_SetBlink( PHB_GT pGT, BOOL fBlink )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_gt_sln_SetBlink(%p,%d)", pGT, (int) fBlink));

   /*
    * We cannot switch remote terminal between blinking and highlight mode
    * for server side using standard termcap/terminfo codes - few rather
    * exotic terminals have such capabilities but this are non standard
    * extensions which can be hard coded only for given hardware (or
    * software terminal emulator). I think that if it's necessary then
    * user should add such tricks yourself to his programs using
    * outstd(  )
    * The only one thing I can make in portable way which will always
    * work is disabling sending BLINK attribute to remote terminal. So
    * in GTSLN like in GTCRS the function SetBlink( .f. ) does it, [Druzus]
    */

   SLtt_Blink_Mode = fBlink ? 1 : 0;
   HB_GTSUPER_SETBLINK( pGT, fBlink );
}
gtsln.c763
STATIC VOIDhb_gt_sln_Tone( PHB_GT pGT, double dFrequency, double dDuration )
static void hb_gt_sln_Tone( PHB_GT pGT, double dFrequency, double dDuration )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_gt_sln_Tone(%p,%lf,%lf)", pGT, dFrequency, dDuration));

   /* TODO: Implement this for other consoles than linux ? */

   HB_SYMBOL_UNUSED( pGT );

   if( hb_sln_UnderLinuxConsole )
   {
      char escstr[ 64 ];

      dFrequency = HB_MIN( HB_MAX( 0.0, dFrequency ), 32767.0 );
      snprintf( escstr, 63, "\033[10;%hd]", ( int )dFrequency );
      SLtt_write_string( escstr );
      snprintf( escstr, 63, "\033[11;%hd]", ( int )( dDuration * 1000.0 / 18.2 ) );
      SLtt_write_string( escstr );
      SLtt_flush_output();
   }
   else
   {
      SLtt_beep();
   }

   if( hb_sln_UnderLinuxConsole )
   {
      /* The conversion from Clipper (DOS) timer tick units to
         milliseconds is * 1000.0 / 18.2. */
      dDuration /= 18.2;
      hb_idleSleep( dDuration );
   }
}
gtsln.c786
STATIC CONST CHAR *hb_gt_sln_Version( PHB_GT pGT, int iType )
static const char * hb_gt_sln_Version( PHB_GT pGT, int iType )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_gt_sln_Version(%p)", pGT ) );

   HB_SYMBOL_UNUSED( pGT );

   if ( iType == 0 )
      return HB_GT_DRVNAME( HB_GT_NAME );

   return "Harbour Terminal: Slang";
}

/* *********************************************************************** */

gtsln.c821
STATIC BOOLhb_gt_sln_Suspend( PHB_GT pGT )
static BOOL hb_gt_sln_Suspend( PHB_GT pGT )
{
   HB_SYMBOL_UNUSED( pGT );

   if( ! s_bSuspended )
   {
      if( SLsmg_suspend_smg() != -1 )
      {
         SLang_reset_tty();
         s_bSuspended = TRUE;
      }
   }

   return s_bSuspended;
}
gtsln.c840
STATIC BOOLhb_gt_sln_Resume( PHB_GT pGT )
static BOOL hb_gt_sln_Resume( PHB_GT pGT )
{
   HB_SYMBOL_UNUSED( pGT );

   if( s_bSuspended && SLsmg_resume_smg() != -1 &&
       hb_sln_Init_Terminal( 1 ) != -1 )
   {
      SLsmg_refresh(); /* reinitialize a terminal */
#ifdef HAVE_GPM_H
      hb_gt_sln_mouse_FixTrash();
#endif
      s_bSuspended = FALSE;
   }

   return( !s_bSuspended );
}
gtsln.c858
STATIC BOOLhb_gt_sln_PreExt( PHB_GT pGT )
static BOOL hb_gt_sln_PreExt( PHB_GT pGT )
{
   HB_SYMBOL_UNUSED( pGT );

   SLsmg_refresh();
#ifdef HAVE_GPM_H
   hb_gt_sln_mouse_FixTrash();
#endif
   return TRUE;
}
gtsln.c877
STATIC BOOLhb_gt_sln_PostExt( PHB_GT pGT )
static BOOL hb_gt_sln_PostExt( PHB_GT pGT )
{
   HB_SYMBOL_UNUSED( pGT );

   return TRUE;
}
gtsln.c890
STATIC BOOLhb_gt_sln_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo )
static BOOL hb_gt_sln_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_gt_sln_Info(%p,%d,%p)", pGT, iType, pInfo ) );

   switch ( iType )
   {
      case HB_GTI_FULLSCREEN:
      case HB_GTI_KBDSUPPORT:
         pInfo->pResult = hb_itemPutL( pInfo->pResult, TRUE );
         break;

      case HB_GTI_ISUNICODE:
         pInfo->pResult = hb_itemPutL( pInfo->pResult, hb_sln_Is_Unicode );
         break;

      case HB_GTI_ESCDELAY:
         pInfo->pResult = hb_itemPutNI( pInfo->pResult, hb_sln_escDelay );
         if( hb_itemType( pInfo->pNewVal ) & HB_IT_NUMERIC )
            hb_sln_escDelay = hb_itemGetNI( pInfo->pNewVal );
         break;

      default:
         return HB_GTSUPER_INFO( pGT, iType, pInfo );
   }

   return TRUE;
}
gtsln.c899
STATIC BOOLhb_gt_sln_SetDispCP( PHB_GT pGT, char * pszTermCDP, char * pszHostCDP, BOOL fBox )
static BOOL hb_gt_sln_SetDispCP( PHB_GT pGT, char * pszTermCDP, char * pszHostCDP, BOOL fBox )
{
#ifndef HB_CDP_SUPPORT_OFF
   PHB_CODEPAGE cdpTerm = NULL, cdpHost = NULL;

   cdpHost = hb_cdpFind( pszHostCDP );
   if ( pszHostCDP && *pszHostCDP )
      cdpHost = hb_cdpFind( pszHostCDP );
   if ( ! cdpHost )
      cdpHost = hb_vmCDP();

   if ( pszTermCDP && *pszTermCDP )
      cdpTerm = hb_cdpFind( pszTermCDP );

   hb_sln_setCharTrans( cdpHost, cdpTerm, fBox );
#endif

   HB_GTSUPER_SETDISPCP( pGT, pszTermCDP, pszHostCDP, fBox );

   return TRUE;
}
gtsln.c930
STATIC BOOLhb_gt_sln_SetKeyCP( PHB_GT pGT, char * pszTermCDP, char * pszHostCDP )
static BOOL hb_gt_sln_SetKeyCP( PHB_GT pGT, char * pszTermCDP, char * pszHostCDP )
{
#ifndef HB_CDP_SUPPORT_OFF
   PHB_CODEPAGE cdpTerm = NULL, cdpHost = NULL;

   cdpHost = hb_cdpFind( pszHostCDP );
   if ( pszHostCDP && *pszHostCDP )
      cdpHost = hb_cdpFind( pszHostCDP );
   if ( ! cdpHost )
      cdpHost = hb_vmCDP();

   if ( pszTermCDP && *pszTermCDP )
      cdpTerm = hb_cdpFind( pszTermCDP );

   hb_sln_setKeyTrans( cdpHost, cdpTerm );
#endif

   HB_GTSUPER_SETKEYCP( pGT, pszTermCDP, pszHostCDP );

   return TRUE;
}
gtsln.c954
STATIC VOIDhb_gt_sln_Redraw( PHB_GT pGT, int iRow, int iCol, int iSize )
static void hb_gt_sln_Redraw( PHB_GT pGT, int iRow, int iCol, int iSize )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_gt_sln_Redraw(%p,%d,%d,%d)", pGT, iRow, iCol, iSize ) );

   if( s_fActive )
   {
      SLsmg_Char_Type SLchar;
      BYTE bColor, bAttr;
      USHORT usChar;

      while( iSize-- > 0 )
      {
         if( !HB_GTSELF_GETSCRCHAR( pGT, iRow, iCol, &bColor, &bAttr, &usChar ) )
            break;
         SLsmg_gotorc( iRow, iCol );
         HB_SLN_BUILD_CHAR( SLchar, usChar & 0xff, bColor, bAttr );
         SLsmg_write_raw( &SLchar, 1 );
         ++iCol;
      }
   }
}
gtsln.c978
STATIC VOIDhb_gt_sln_Refresh( PHB_GT pGT )
static void hb_gt_sln_Refresh( PHB_GT pGT )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_gt_sln_Refresh(%p)", pGT ) );

   HB_GTSUPER_REFRESH( pGT );
   if( s_fActive )
   {
      int iRow, iCol, iStyle;

      HB_GTSELF_GETSCRCURSOR( pGT, &iRow, &iCol, &iStyle );
      if( iStyle != SC_NONE && ( iRow < 0 || iCol < 0 ||
                      iRow >= SLtt_Screen_Rows || iCol >= SLtt_Screen_Cols ) )
         iStyle = SC_NONE;
      SLsmg_gotorc( iRow, iCol );
      hb_sln_SetCursorStyle( iStyle );
      SLsmg_refresh();
   }
}
gtsln.c1002
STATIC BOOLhb_gt_FuncInit( PHB_GT_FUNCS pFuncTable )
static BOOL hb_gt_FuncInit( PHB_GT_FUNCS pFuncTable )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_gt_FuncInit(%p)", pFuncTable));

   pFuncTable->Init                       = hb_gt_sln_Init;
   pFuncTable->Exit                       = hb_gt_sln_Exit;
   pFuncTable->IsColor                    = hb_gt_sln_IsColor;
   pFuncTable->SetMode                    = hb_gt_sln_SetMode;
   pFuncTable->Redraw                     = hb_gt_sln_Redraw;
   pFuncTable->Refresh                    = hb_gt_sln_Refresh;
   pFuncTable->SetBlink                   = hb_gt_sln_SetBlink;
   pFuncTable->Version                    = hb_gt_sln_Version;
   pFuncTable->Suspend                    = hb_gt_sln_Suspend;
   pFuncTable->Resume                     = hb_gt_sln_Resume;
   pFuncTable->PreExt                     = hb_gt_sln_PreExt;
   pFuncTable->PostExt                    = hb_gt_sln_PostExt;
   pFuncTable->Tone                       = hb_gt_sln_Tone;
   pFuncTable->Info                       = hb_gt_sln_Info;
   pFuncTable->SetDispCP                  = hb_gt_sln_SetDispCP;
   pFuncTable->SetKeyCP                   = hb_gt_sln_SetKeyCP;

   pFuncTable->ReadKey                    = hb_gt_sln_ReadKey;

   pFuncTable->MouseIsPresent             = hb_gt_sln_mouse_IsPresent;
   pFuncTable->MouseShow                  = hb_gt_sln_mouse_Show;
   pFuncTable->MouseHide                  = hb_gt_sln_mouse_Hide;
   pFuncTable->MouseGetPos                = hb_gt_sln_mouse_GetPos;
   pFuncTable->MouseSetPos                = hb_gt_sln_mouse_SetPos;
   pFuncTable->MouseButtonState           = hb_gt_sln_mouse_ButtonState;
   pFuncTable->MouseCountButton           = hb_gt_sln_mouse_CountButton;

   return TRUE;
}

/* ********************************************************************** */

static const HB_GT_INIT gtInit = { HB_GT_DRVNAME( HB_GT_NAME ),
                                   hb_gt_FuncInit,
                                   HB_GTSUPER,
                                   HB_GTID_PTR };

HB_GT_ANNOUNCE( HB_GT_NAME )

HB_CALL_ON_STARTUP_BEGIN( _hb_startup_gt_Init_ )
   hb_gtRegister( >Init );
HB_CALL_ON_STARTUP_END( _hb_startup_gt_Init_ )

#if defined( HB_PRAGMA_STARTUP )
   #pragma startup _hb_startup_gt_Init_
#elif defined( HB_MSC_STARTUP )
   #if defined( HB_OS_WIN_64 )
      #pragma section( HB_MSC_START_SEGMENT, long, read )
   #endif
   #pragma data_seg( HB_MSC_START_SEGMENT )
   static HB_$INITSYM hb_vm_auto__hb_startup_gt_Init_ = _hb_startup_gt_Init_;
gtsln.c1023
kbsln.c
TypeFunctionSourceLine
STATIC VOIDhb_sln_Init_TermType()
static void hb_sln_Init_TermType()
{
   char * Env;
    
   /* an uncertain way to check if we run under linux console */
   Env = hb_getenv( "TERM" );
   if( Env )
   {
      hb_sln_UnderLinuxConsole = *Env && ( strncmp( Env, "linux", 5 ) == 0 );
      hb_xfree( ( void * ) Env );
   } 
   /* an uncertain way to check if we run under xterm */
   Env = hb_getenv( "TERM" );
   if( Env )
   {
      hb_sln_UnderXterm = *Env && ( strstr( Env, "xterm" ) != NULL ||
                                    strncmp( Env, "rxvt", 4 ) == 0 );
      hb_xfree( ( void * ) Env );
   }
}
kbsln.c138
STATIC VOIDhb_sln_Init_KeyTranslations()
static void hb_sln_Init_KeyTranslations()
{
   char ch, keyname[ SLANG_MAX_KEYMAP_KEY_SEQ + 1 ];
   int  keynum, i;
   char * keyseq;
 
   /* for defining ^[ sequences - this simulates Alt+Keys */
   char AltChars[][ 2 ] =
   {
      { '0',   '9' },
      { 'A',   'Z' },
      { 'a',   'z' }
   };
 
   /* on Unix systems ESC is a special key so let
      assume ESC is a doble pressed ESC key    */
   SLkp_define_keysym( ( char * ) "^[^[", SL_KEY_ESC );
 
   /* try to define Shft-Fn and Ctrl-Fn keys.
      Because we assume terminal has only 10 Fkeys
      so F11-F30 is generated with Shift & Ctrl.
      This is not guaranteed to work in all cases */
   keynum = 11;
   keyname[ 0 ] = 'F';
   keyname[ 2 ] = 0;
 
   /* Shft & Ctrl FKeys definition takes place in two
      phases : from '1' to '9' and from 'A' to 'K' */
   for( i = 1; i <= 2; i++ )
   {
      for( ch = ( i == 1 ? '1' : 'A' ); ch <= ( i == 1 ? '9' : 'K' ); ch++ )
      {
         keyname[ 1 ] = ch;
         keyseq = SLtt_tgetstr( keyname );
         if( keyseq != NULL && keyseq[ 0 ] != 0 )
            SLkp_define_keysym( keyseq, SL_KEY_F( keynum ) );
         keynum++;
      }
   }
 
   /* We assume Esc key is a Meta key which is treated as an Alt key.
      Also pressing Alt+Key on linux console and linux xterm gives the
      same key sequences as with Meta key so we are happy */
 
   keyname[ 0 ] = 033;
   keyname[ 2 ] = 0;
 
   /* Alt+Letter & Alt+digit definition takes place in three phases :
      from '0' to '9', from 'A' to 'Z' and from 'a' to 'z' */
   for( i = 0; i < 3; i++ )
   {
      for( ch = AltChars[ i ][ 0 ]; ch <= AltChars[ i ][ 1 ]; ch++ )
      {
         /* fprintf( stderr, "%d %c\n", i, ch ); */
         keyname[ 1 ] = ch;
   
         /* QUESTION: why Slang reports error for defining Alt+O ???.
                      Have I any hidden error in key definitiions ??? */
         if( ch != 'O' )
            SLkp_define_keysym( keyname, SL_KEY_ALT( ch ) );
      }
   }
 
   /* mouse events under xterm */
   if( hb_sln_UnderXterm )
   {
      keyseq = SLtt_tgetstr( ( char * ) "Km" );
      if( ( keyseq != NULL ) && ( keyseq[ 0 ] != 0 ) )
      {
         /* fprintf( stderr, "%s\r\n", keyseq ); */
         SLkp_define_keysym( keyseq, SL_KEY_MOU );
      }
   }
   
   /* five on numeric console */
   /* SLkp_define_keysym( "^[[G", SL_KEY_NUM_5 ); */
}
kbsln.c161
INThb_sln_Init_Terminal( int phase )
int hb_sln_Init_Terminal( int phase )
{
   struct termios newTTY;
   unsigned char * p;
   int ret = 0;

   /* first time init phase - we don't want this after
      return from system command ( see run.c )      */
   if( phase == 0 )
   {
      /* check if we run under linux console or under xterm */
      hb_sln_Init_TermType();

#ifdef HB_OS_LINUX
      /* for Linux console */
      if( hb_sln_UnderLinuxConsole )
         s_hb_sln_Abort_key = 0;
#endif

      /* get Dead key definition */
      p = ( unsigned char * ) hb_getenv( hb_DeadKeyEnvName );

      if( p && p[ 0 ] != '\0' )
      {
         int len = strlen( ( char * ) p );
         if( len > 0 )
            hb_DeadKey = ( int ) *p;
      }
      if( p )
         hb_xfree( ( void * ) p );
 
      /* number of keys dealing with a Dead key */
      hb_sln_convKDeadKeys[ 0 ] = 0;
   }

   /* Ctrl+\ to abort, no flow-control, no output processing */
   if( SLang_init_tty( s_hb_sln_Abort_key, 0, 0 ) != -1 )
   {
      /* do missing disable of start/stop processing */
      if( tcgetattr( SLang_TT_Read_FD, &newTTY ) == 0 )
      {
         newTTY.c_cc[ VSTOP ]  = 255;  /* disable ^S start/stop processing */
         newTTY.c_cc[ VSTART ] = 255;  /* disable ^Q start/stop processing */
         newTTY.c_cc[ VSUSP ]  = 255;  /* disable ^Z suspend processing */
         /* already done in Slang library */
         /* newTTY.c_cc[ VDSUSP ] = 255; */  /* disable ^Y delayed suspend processing */

         if( tcsetattr( SLang_TT_Read_FD, TCSADRAIN, &newTTY ) == 0 )
            /* everything looks ok so far */
            ret = 1;
      }
   }

   /* first time init phase - we don't want this after
      return from system command ( see run.c )      */
   if( ret && ( phase == 0 ) )
   {
      /* define keyboard translations */
      hb_sln_Init_KeyTranslations();

      /* for binary search of key translations */
      hb_sln_SortKeyTranslationTable();
   }

   return( ret );
}
kbsln.c241
INThb_gt_sln_ReadKey( PHB_GT pGT, int iEventMask )
int hb_gt_sln_ReadKey( PHB_GT pGT, int iEventMask )
{
   static int InDeadState = FALSE;
   unsigned int ch, tmp, kbdflags;
   BOOL fInput;
   int iKey;

   HB_TRACE(HB_TR_DEBUG, ("hb_gt_sln_ReadKey(%p,%d)", pGT, (int) iEventMask));

   /* user AbortKey break */
   if( SLKeyBoard_Quit == 1 )
      return HB_BREAK_FLAG;

   /* has screen size changed ? */
   if( hb_sln_bScreen_Size_Changed )
   {
      hb_sln_bScreen_Size_Changed = FALSE;
      SLtt_get_screen_size();
#if SLANG_VERSION > 10202
      SLsmg_reinit_smg();
#endif

      /* TODO: we need here some kind of screen redrawing */
      /*SLsmg_refresh();*/
      HB_GTSELF_RESIZE( pGT, SLtt_Screen_Rows, SLtt_Screen_Cols );
   }

   fInput = SLang_input_pending( 0 ) != 0;
   iKey = hb_gt_sln_mouse_Inkey( iEventMask, !fInput );
   if( !fInput || iKey != 0 )
      return iKey;

#if HB_GT_KBD_MODIF_MASK
   kbdflags = hb_sln_try_get_Kbd_State();
#else
   kbdflags = 0;
#endif

/* ------- one key ESC handling ----------------- */
   /* NOTE: This will probably not work on slow terminals
      or on very busy lines (i.e. modem lines ) */
   ch = SLang_getkey();
   if( ch == 033 )   /* escape char received, check for any pending chars */
   {
      if( hb_sln_escDelay == 0 )
      {
         /* standard acction, wait a 1 second for next char and if not then exit */
         if( 0 == SLang_input_pending( 10 ) )
            return( 0 );
      }
      else
      {
         /* wait hb_sln_escDelay milisec for next char and in not return ESC keycode */
         if( 0 == SLang_input_pending( - HB_MAX( hb_sln_escDelay, 0 ) ) )
            return( 033 );
      }
   }

   /* user AbortKey break */
   if( (int) ch == s_hb_sln_Abort_key )
      return HB_BREAK_FLAG;

   SLang_ungetkey( ch );
/* ------------------------------------------------- */

   ch = SLkp_getkey();

   /* unrecognized character */
   if( ch == SL_KEY_ERR )
      return( 0 );

   /* Dead key handling */
   if( InDeadState )
   {
      InDeadState = FALSE;
      if( (int) ch == hb_DeadKey ) /* double press Dead key */
         return( ch );
      if( ch < 256 )  /* is this needed ??? */
      {
         int i;
         for( i=0; i < ( int ) hb_sln_convKDeadKeys[ 0 ]; i++ )
            if( ( int ) hb_sln_convKDeadKeys[ 2 * i + 1 ] == (int) ch )
               return( ( int ) hb_sln_convKDeadKeys[ 2 * i + 2 ] );
      }
      return( 0 );
   }
   else if( (int) ch == hb_DeadKey )
   {
      /* entering Dead key state */
      InDeadState = TRUE;
      return( 0 );
   }

   /* any special key ? */
   if( ( tmp = ( ch | ( kbdflags << 16 ) ) ) > 256 )
   {
      if( tmp == SL_KEY_MOU )
      {
         hb_gt_sln_mouse_ProcessTerminalEvent();
         return hb_gt_sln_mouse_Inkey( iEventMask, FALSE );
      }

      if( ( iEventMask & INKEY_RAW ) != 0 )
         return tmp;

      tmp = hb_sln_FindKeyTranslation( tmp );
      if( tmp != 0 )
         return tmp;

      /* TOFIX: this code is broken - needs a diffrent aproach */
      tmp = hb_sln_FindKeyTranslation( ch );
      if( tmp != 0 || ch > 256 )
         return tmp;
   }

#if !defined( HB_CDP_SUPPORT_OFF ) && ( defined( HB_SLN_UTF8 ) || defined( HB_SLN_UNICODE ) )
   if ( hb_sln_Is_Unicode && ch < 256 )
   {
      int n = 0;
      USHORT uc = 0;

      if ( hb_cdpGetFromUTF8( hb_sln_cdpIN, FALSE, (BYTE) ch, &n, &uc ) )
      {
         unsigned int buf[ 10 ], i = 0;

         while ( n > 0 )
         {
            if( SLang_input_pending( hb_sln_escDelay == 0 ? -100 :
                                         - HB_MAX( hb_sln_escDelay, 0 ) ) == 0 )
               break;
            buf[ i++ ] = SLang_getkey();
            if ( !hb_cdpGetFromUTF8( hb_sln_cdpIN, FALSE, (BYTE) buf[ i - 1 ], &n, &uc ) )
               break;
         }
         if ( n > 0 )
         {
            while ( i > 0 )
               SLang_ungetkey( buf[ --i ] );
         }
         else
            ch = uc;
      }
   }
#endif

   /* standard ASCII key */
   return ch < 256 ? hb_sln_inputTab[ ch ] : ch;
}
kbsln.c310
STATIC INThb_sln_try_get_Kbd_State( void )
static int hb_sln_try_get_Kbd_State( void )
{
#if defined(__linux__)
   unsigned char modifiers = 6;

   if( ioctl( 0, TIOCLINUX, &modifiers ) < 0 )
      return 0;
 
   return ( int ) modifiers;
 
#elif defined(M_UNIX)
 
   int modifiers = 0;
   int IOcommand = 0;
 
   if( ioctl( 0, TCGETSC, &IOcommand ) >= 0 )
   {
      /* if keyboard is not in SCANCODE mode */
      if( IOcommand == KB_XSCANCODE )
      {
         /* try to set it to SCANCODE mode */
         IOcommand = KB_ISSCANCODE;
         if( ioctl( 0, TCSETSC, &IOcommand ) >= 0 )
         {
            /* if SCANCODE mode is set corectly try get KBD state */
            if( ioctl( 0, KDGKBSTATE, &modifiers ) < 0 )
               modifiers = 0;
    
            /* turn a keyboard to a normal mode ( translation mode ) */
            IOcommand = KB_XSCANCODE;
            ( void ) ioctl( 0, TCSETSC, &IOcommand )
         }
      }
      /* keyboard is already in SCANCODE mode */
      else if( ioctl( 0, KDGKBSTATE, &modifiers ) < 0 )
         modifiers = 0;

      return modifiers;
   }
#endif

   return 0;
}
kbsln.c461
INThb_sln_Shft_Pressed()
int hb_sln_Shft_Pressed()
{
   return ( hb_sln_try_get_Kbd_State() & SHIFT_PRESSED ) != 0;
}
kbsln.c507
INThb_sln_Ctrl_Pressed()
int hb_sln_Ctrl_Pressed()
{
   return ( hb_sln_try_get_Kbd_State() & CONTROL_PRESSED ) != 0;
}
kbsln.c514
INThb_sln_Alt_Pressed()
int hb_sln_Alt_Pressed()
{
   return ( hb_sln_try_get_Kbd_State() & ALT_PRESSED ) != 0;
}
kbsln.c521
INThb_sln_Kbd_State()
int hb_sln_Kbd_State()
{
   return hb_sln_try_get_Kbd_State();
}
kbsln.c528
keytrans.c
TypeFunctionSourceLine
( SIZEOF( KEYTRANSLATIONTABLE ) / ( 2 * SIZEOF ( INT ) ) ) STATIC VOIDhb_sln_SortKeyTranslationTable( void )
static void hb_sln_SortKeyTranslationTable( void )
{
   int i, j, min, KeyTmp[ 2 ];

   for ( i = 0; i < ( (int) KeyTranslationTableSize - 1 ); i++ )
   {
      min = i;

      for ( j = i + 1; j < (int) KeyTranslationTableSize; j++ )
      {
         if ( KeyTranslationTable[ j ][ 0 ] < KeyTranslationTable[ min ][ 0 ] )
            min = j;
      }

      if ( min > i )
      {
         KeyTmp[ 0 ] = KeyTranslationTable[ i ][ 0 ];
         KeyTmp[ 1 ] = KeyTranslationTable[ i ][ 1 ];

         KeyTranslationTable[ i ][ 0 ] = KeyTranslationTable[ min ][ 0 ];
         KeyTranslationTable[ i ][ 1 ] = KeyTranslationTable[ min ][ 1 ];

         KeyTranslationTable[ min ][ 0 ] = KeyTmp[ 0 ];
         KeyTranslationTable[ min ][ 1 ] = KeyTmp[ 1 ];
      }
   }

/*
   for ( i = 0; i < KeyTranslationTableSize; i++ )
      fprintf( stderr, "%02x %8x %8x\n", i, KeyTranslationTable[ i ][ 0 ], KeyTranslationTable[ i ][ 1 ] );
*/

}
keytrans.c393
STATIC INThb_sln_FindKeyTranslation( int SlangKey )
static int hb_sln_FindKeyTranslation( int SlangKey )
{
   int Start,Stop,CurPos;

   if ( ( SlangKey >= KeyTranslationTable[ 0 ][ 0 ] ) &&
        ( SlangKey <= KeyTranslationTable[ KeyTranslationTableSize - 1 ][ 0 ] ) )
   {
      Start = 0; Stop = KeyTranslationTableSize - 1;

      while( Start <= Stop )
      {
         CurPos = ( Start + Stop ) / 2;

         /* fprintf( stderr, "%d %d %d\n", i, KeyTranslationTable[ i ][ 0 ], KeyTranslationTable[ i ][ 1 ] ); */

         if( SlangKey == KeyTranslationTable[ CurPos ][ 0 ] )
            return( KeyTranslationTable[ CurPos ][ 1 ] );

         else if( SlangKey < KeyTranslationTable[ CurPos ][ 0 ] )
            Stop = CurPos - 1;

         else if( SlangKey > KeyTranslationTable[ CurPos ][ 0 ] )
            Start = CurPos + 1;
      }
   }

   /* return( SlangKey ); */
   return( 0 );
}
keytrans.c430
INThb_sln_SetKeyInKeyTranslationTable( int SlangKey, int ClipKey )
int hb_sln_SetKeyInKeyTranslationTable( int SlangKey, int ClipKey )
{
   int i, Found = 0;

   if ( ( SlangKey >= KeyTranslationTable[ 0 ][ 0 ] ) &&
        ( SlangKey <= KeyTranslationTable[ KeyTranslationTableSize - 1 ][ 0 ] ) )
   {
      for ( i = 0; i < (int) KeyTranslationTableSize; i++ )
      {
         if ( SlangKey == KeyTranslationTable[ i ][ 0 ] )
            KeyTranslationTable[ i ][ 1 ] = ClipKey;
       Found = 1;
            /* we don't break here because SlangKey can be defined more than once */
      }
   }

   return( Found );
}
keytrans.c463
mousesln.c
TypeFunctionSourceLine
STATIC BOOLGetGpmEvent( Gpm_Event *Evt )
static BOOL GetGpmEvent( Gpm_Event *Evt )
{
   if( s_bMousePresent && gpm_fd >= 0 )
   {
      struct timeval tv = { 0, 0 };
      fd_set ReadFD;

      FD_ZERO( &ReadFD ); 
      FD_SET( gpm_fd, &ReadFD );

      if( select( gpm_fd+1, &ReadFD, NULL, NULL, &tv ) > 0 )
         if( FD_ISSET( gpm_fd, &ReadFD ) ) 
            return Gpm_GetEvent( Evt ) > 0;
   }

   return FALSE;
}
mousesln.c84
STATIC BOOLGetXtermEvent( int *Btn, int *Col, int *Row )
static BOOL GetXtermEvent( int *Btn, int *Col, int *Row )
{
   /* Xterm mouse event consists of three chars */
   if( SLang_input_pending( 0 ) > 0 )
   {
      *Btn = SLang_getkey() - 0x20;

      if( SLang_input_pending( 0 ) > 0 )
      {
         *Col = SLang_getkey() - 0x21;
         if( SLang_input_pending( 0 ) > 0 )
         {
            *Row = SLang_getkey() - 0x21;
            return TRUE;
         }
      }
   }
    
   return FALSE;
}
mousesln.c105
STATIC VOIDhb_sln_CheckDoubleClick()
static void hb_sln_CheckDoubleClick()
{
   USHORT usNewButtons = ( s_usMouseState & ~s_usLastMouseState ) & M_BUTTON_KEYMASK;

   if( usNewButtons != 0 )
   {
      struct timeval evtTime;

      TIMEVAL_GET( evtTime );
      if( usNewButtons & M_BUTTON_LEFT )
      {
         if ( TIMEVAL_LESS( evtTime, mLeftDblckTime ) )
            s_usMouseState |= M_BUTTON_LDBLCK;
         TIMEVAL_ADD( mLeftDblckTime, evtTime, hb_mouseGetDoubleClickSpeed() );
      }
      if( usNewButtons & M_BUTTON_MIDDLE )
      {
         if ( TIMEVAL_LESS( evtTime, mMiddleDblckTime ) )
            s_usMouseState |= M_BUTTON_MDBLCK;
         TIMEVAL_ADD( mMiddleDblckTime, evtTime, hb_mouseGetDoubleClickSpeed() );
      }
      if( usNewButtons & M_BUTTON_RIGHT )
      {
         if ( TIMEVAL_LESS( evtTime, mRightDblckTime ) )
            s_usMouseState |= M_BUTTON_RDBLCK;
         TIMEVAL_ADD( mRightDblckTime, evtTime, hb_mouseGetDoubleClickSpeed() );
      }
   }
}
mousesln.c128
VOIDhb_gt_sln_mouse_ProcessTerminalEvent( void )
void hb_gt_sln_mouse_ProcessTerminalEvent( void )
{
   int Btn, Col, Row;

   if( GetXtermEvent( &Btn, &Col, &Row ) )
   {
      if( s_iMouseRow != Row || s_iMouseCol != Col )
         s_usMouseState |= M_CURSOR_MOVE;

      s_iMouseRow = Row;
      s_iMouseCol = Col;

      switch( Btn & 0xE3 )
      {
         case 0:
            s_usMouseState |= M_BUTTON_LEFT;
            break;
         case 1:
            s_usMouseState |= M_BUTTON_MIDDLE;
            break;
         case 2:
            s_usMouseState |= M_BUTTON_RIGHT;
            break;
         case 3:
            s_usMouseState &= ~M_BUTTON_KEYMASK;
            break;
         case 0x40:
            s_usMouseState |= M_BUTTON_WHEELUP;
            break;
         case 0x41:
            s_usMouseState |= M_BUTTON_WHEELDOWN;
            break;
      }
      hb_sln_CheckDoubleClick();
   }
}
mousesln.c160
INThb_gt_sln_mouse_Inkey( int iEventMask, BOOL fCheckNew )
int hb_gt_sln_mouse_Inkey( int iEventMask, BOOL fCheckNew )
{
   if( s_usMouseState != s_usLastMouseState )
   {
      if( s_usMouseState & M_CURSOR_MOVE )
      {
         s_usMouseState &= ~M_CURSOR_MOVE;
         return K_MOUSEMOVE;
      }
      else if( s_usMouseState & M_BUTTON_WHEELUP )
      {
         s_usMouseState &= ~M_BUTTON_WHEELUP;
         return K_MWFORWARD;
      }
      else if( s_usMouseState & M_BUTTON_WHEELDOWN )
      {
         s_usMouseState &= ~M_BUTTON_WHEELDOWN;
         return K_MWBACKWARD;
      }
      else
      {
         USHORT usKeyDiff = ( s_usMouseState ^ s_usLastMouseState );

         if( usKeyDiff & M_BUTTON_LEFT )
         {
            s_usLastMouseState ^= M_BUTTON_LEFT;
            if( s_usMouseState & M_BUTTON_LEFT )
            {
               if( s_usMouseState & M_BUTTON_LDBLCK )
               {
                  s_usMouseState &= ~M_BUTTON_LDBLCK;
                  return K_LDBLCLK;
               }
               else
                  return K_LBUTTONDOWN;
            }
            else
               return K_LBUTTONUP;
         }
         else if( usKeyDiff & M_BUTTON_MIDDLE )
         {
            s_usLastMouseState ^= M_BUTTON_MIDDLE;
            if( s_usMouseState & M_BUTTON_MIDDLE )
            {
               if( s_usMouseState & M_BUTTON_MDBLCK )
               {
                  s_usMouseState &= ~M_BUTTON_MDBLCK;
                  return K_MDBLCLK;
               }
               else
                  return K_MBUTTONDOWN;
            }
            else
               return K_MBUTTONUP;
         }
         else if( usKeyDiff & M_BUTTON_RIGHT )
         {
            s_usLastMouseState ^= M_BUTTON_RIGHT;
            if( s_usMouseState & M_BUTTON_RIGHT )
            {
               if( s_usMouseState & M_BUTTON_RDBLCK )
               {
                  s_usMouseState &= ~M_BUTTON_RDBLCK;
                  return K_RDBLCLK;
               }
               else
                  return K_RBUTTONDOWN;
            }
            else
               return K_RBUTTONUP;
         }
         s_usLastMouseState = s_usMouseState;
      }
   }

#ifdef HAVE_GPM_H

#define CHECK_BUTTON_DOWN(Mask,GpmBtn,InkBtn,InkDbl)              \
   if( ( iEventMask & Mask ) && ( Evt.buttons & GpmBtn ) )        \
   {                                                              \
      if( Evt.type & GPM_SINGLE )                                 \
         return( InkBtn );                                        \
      else if( Evt.type & GPM_DOUBLE || Evt.type & GPM_TRIPLE )   \
         return( InkDbl );                                        \
   }

   else if( hb_sln_UnderLinuxConsole && fCheckNew )
   {
      Gpm_Event Evt;

      if( GetGpmEvent( &Evt ) )
      {
         /* get the mouse event position */
         s_iMouseRow = Evt.y;
         s_iMouseCol = Evt.x;

         if( ( Evt.type & GPM_MOVE ) && ( iEventMask & INKEY_MOVE ) )
            return( K_MOUSEMOVE );

         else if( Evt.type & GPM_DOWN )
         {
            CHECK_BUTTON_DOWN(INKEY_LDOWN,GPM_B_LEFT,K_LBUTTONDOWN,K_LDBLCLK)
            else
            CHECK_BUTTON_DOWN(INKEY_RDOWN,GPM_B_RIGHT,K_RBUTTONDOWN,K_RDBLCLK)
            else
            CHECK_BUTTON_DOWN(INKEY_MMIDDLE,GPM_B_MIDDLE,K_MBUTTONDOWN,K_MDBLCLK)
         }

         else if( Evt.type & GPM_UP )
         {
            if( ( iEventMask & INKEY_LUP ) && ( Evt.buttons & GPM_B_LEFT ) )
               return( K_LBUTTONUP );
            else if( ( iEventMask & INKEY_RUP ) && ( Evt.buttons & GPM_B_RIGHT ) )
               return( K_RBUTTONUP );
            else if( ( iEventMask & INKEY_MMIDDLE ) && ( Evt.buttons & GPM_B_MIDDLE ) )
               return( K_MBUTTONUP );
         }
      }
   }
#else
   HB_SYMBOL_UNUSED( fCheckNew );
   HB_SYMBOL_UNUSED( iEventMask );
#endif

   return 0;
}
mousesln.c199
VOIDhb_gt_sln_mouse_Init( void )
void hb_gt_sln_mouse_Init( void )
{
   if( hb_sln_UnderXterm )
   {
      const char * SaveHilit = "\033[?1001s"; /* save old hilit tracking */
      const char * EnabTrack = "\033[?1000h"; /* enable mouse tracking */

      /* force mouse usage under xterm */
      (void)SLtt_set_mouse_mode( 1, 1 );

      /* initial xterm settings */
      SLtt_write_string( ( char * ) SaveHilit );
      SLtt_write_string( ( char * ) EnabTrack );
      SLtt_flush_output();

      s_iMouseButtons = SLtt_tgetnum( ( char * ) "BT" );

      /* force two buttons mouse under xterm */
      if( s_iMouseButtons < 1 )
         s_iMouseButtons = 3;

      s_bMousePresent = TRUE;
   }
#ifdef HAVE_GPM_H
   else if( hb_sln_UnderLinuxConsole )
   {
#ifdef HB_GPM_NOICE_DISABLE
      int iNull, iErr;

      iErr = dup( 2 );
      iNull = open( "/dev/null", O_RDWR );
      dup2( iNull, 2 );
      close( iNull );
#endif
      Conn.eventMask = GPM_MOVE | GPM_UP | GPM_DOWN | GPM_DRAG | GPM_DOUBLE;
      /* give me move events but handle them anyway */
      Conn.defaultMask= GPM_MOVE | GPM_HARD; 
      /* only pure mouse events, no Ctrl,Alt,Shft events */
      Conn.minMod = 0;    Conn.maxMod = 0;
      gpm_zerobased = 1;  gpm_visiblepointer = 1;

      if( Gpm_Open( &Conn, 0 ) >= 0 && gpm_fd >= 0 )
      {
         Gpm_Event Evt;

         s_bMousePresent = TRUE;

         while( GetGpmEvent( &Evt ) );
         {
            s_iMouseRow = Evt.y;
            s_iMouseCol = Evt.x;
         }

         /*
          * In recent GPM versions it produce unpleasure noice on the screen
          * so I covered it with this macro, [druzus]
          */         
#ifdef HB_GPM_USE_XTRA
         s_iMouseButtons = Gpm_GetSnapshot( NULL );
#else
         s_iMouseButtons = 3;
#endif
         hb_gt_sln_mouse_FixTrash();
      }
#ifdef HB_GPM_NOICE_DISABLE
      dup2( iErr, 2 );
      close( iErr );
#endif
   }
#endif
}
mousesln.c328
VOIDhb_gt_sln_mouse_Exit( void )
void hb_gt_sln_mouse_Exit( void )
{
   if( s_bMousePresent )
   {
      if( hb_sln_UnderXterm )
      {
         const char * DisabTrack = "\033[?1000l"; /* disable mouse tracking */
         const char * RestoHilit = "\033[?1001r"; /* restore old hilittracking */

         /* restore xterm settings */
         SLtt_write_string( ( char * ) DisabTrack );
         SLtt_write_string( ( char * ) RestoHilit );
         SLtt_flush_output();

         /* force mouse usage under xterm */
         (void)SLtt_set_mouse_mode( 0, 1 );
      }
#ifdef HAVE_GPM_H
      else if( hb_sln_UnderLinuxConsole )
      {
         if( gpm_fd >= 0 )
            Gpm_Close();
      }
#endif
      s_bMousePresent = FALSE;
   }
}
mousesln.c402
BOOLhb_gt_sln_mouse_IsPresent( PHB_GT pGT )
BOOL hb_gt_sln_mouse_IsPresent( PHB_GT pGT )
{
   HB_SYMBOL_UNUSED( pGT );

   return s_bMousePresent;
}
mousesln.c432
VOIDhb_gt_sln_mouse_Show( PHB_GT pGT )
void hb_gt_sln_mouse_Show( PHB_GT pGT )
{
   HB_SYMBOL_UNUSED( pGT );

#ifdef HAVE_GPM_H
   gpm_visiblepointer = 1;
   if( hb_sln_UnderLinuxConsole && s_bMousePresent )
      Gpm_DrawPointer( s_iMouseCol, s_iMouseRow, gpm_consolefd );
#endif
   ;
}
mousesln.c441
VOIDhb_gt_sln_mouse_Hide( PHB_GT pGT )
void hb_gt_sln_mouse_Hide( PHB_GT pGT )
{
   HB_SYMBOL_UNUSED( pGT );

#ifdef HAVE_GPM_H
   gpm_visiblepointer = 0;
#endif
   ;
}
mousesln.c455
VOIDhb_gt_sln_mouse_GetPos( PHB_GT pGT, int * piRow, int * piCol )
void hb_gt_sln_mouse_GetPos( PHB_GT pGT, int * piRow, int * piCol )
{
   HB_SYMBOL_UNUSED( pGT );

   *piRow = s_iMouseRow;
   *piCol = s_iMouseCol;
}
mousesln.c467
VOIDhb_gt_sln_mouse_SetPos( PHB_GT pGT, int iRow, int iCol )
void hb_gt_sln_mouse_SetPos( PHB_GT pGT, int iRow, int iCol )
{
   HB_SYMBOL_UNUSED( pGT );

   /* it does really nothing */
   s_iMouseRow = iRow;
   s_iMouseCol = iCol;
#ifdef HAVE_GPM_H
   if( hb_sln_UnderLinuxConsole )
      if( s_bMousePresent && gpm_visiblepointer )
         Gpm_DrawPointer( iCol, iRow, gpm_consolefd );
#endif
}
mousesln.c477
BOOLhb_gt_sln_mouse_ButtonState( PHB_GT pGT, int iButton )
BOOL hb_gt_sln_mouse_ButtonState( PHB_GT pGT, int iButton )
{
   HB_SYMBOL_UNUSED( pGT );

   switch( iButton )
   {
      case 0:
         return ( s_usMouseState & M_BUTTON_LEFT ) != 0;
      case 1:
         return ( s_usMouseState & M_BUTTON_RIGHT ) != 0;
      case 2:
         return ( s_usMouseState & M_BUTTON_MIDDLE ) != 0;
   }

   return FALSE;
}
mousesln.c493
INThb_gt_sln_mouse_CountButton( PHB_GT pGT )
int hb_gt_sln_mouse_CountButton( PHB_GT pGT )
{
   HB_SYMBOL_UNUSED( pGT );

   return s_iMouseButtons;
}
mousesln.c512
VOIDhb_gt_sln_mouse_FixTrash( void )
void hb_gt_sln_mouse_FixTrash( void )
{
#ifdef HAVE_GPM_H
   if( hb_sln_UnderLinuxConsole )
      if( s_bMousePresent && gpm_visiblepointer )
         Gpm_DrawPointer( s_iMouseCol, s_iMouseRow, gpm_consolefd );
#endif
}
mousesln.c521

Page url: http://www.yourdomain.com/help/index.html?gtsln.htm