static void hb_dbQSortSwap( LPDBQUICKSORT pQuickSort, HB_ULONG ulRecNo1, HB_ULONG ulRecNo2 ) { /* Swap records */ hb_fsSeek( pQuickSort->hFile, ( ulRecNo1 - 1 ) * pQuickSort->uiRecordLen, FS_SET ); hb_fsRead( pQuickSort->hFile, pQuickSort->pSwapBufferA, pQuickSort->uiRecordLen ); hb_fsSeek( pQuickSort->hFile, ( ulRecNo2 - 1 ) * pQuickSort->uiRecordLen, FS_SET ); hb_fsRead( pQuickSort->hFile, pQuickSort->pSwapBufferB, pQuickSort->uiRecordLen ); hb_fsSeek( pQuickSort->hFile, ( ulRecNo1 - 1 ) * pQuickSort->uiRecordLen, FS_SET ); hb_fsWrite( pQuickSort->hFile, pQuickSort->pSwapBufferB, pQuickSort->uiRecordLen ); hb_fsSeek( pQuickSort->hFile, ( ulRecNo2 - 1 ) * pQuickSort->uiRecordLen, FS_SET ); hb_fsWrite( pQuickSort->hFile, pQuickSort->pSwapBufferA, pQuickSort->uiRecordLen ); }
/* deletes xxx bytes from the current file, beginning at the current record */ static int _del_buff( PFT_TEXT ft_text, HB_ISIZ iLen ) { char * WriteBuff = ( char * ) hb_xgrab( BUFFSIZE ); HB_FOFFSET fpRead, fpWrite; HB_ISIZ WriteLen; HB_ISIZ SaveLen; /* initialize file pointers */ fpWrite = ft_text->offset[ ft_text->area ]; fpRead = ft_text->offset[ ft_text->area ] + iLen; /* do initial load of buffer */ hb_fsSeekLarge( ft_text->handles[ ft_text->area ], fpRead, FS_SET ); WriteLen = hb_fsRead( ft_text->handles[ ft_text->area ], WriteBuff, BUFFSIZE ); fpRead += WriteLen; ft_text->error[ ft_text->area ] = 0; while( WriteLen > 0 ) { /* position to beginning of write area */ hb_fsSeekLarge( ft_text->handles[ ft_text->area ], fpWrite, FS_SET ); SaveLen = hb_fsWriteLarge( ft_text->handles[ ft_text->area ], WriteBuff, WriteLen ); /* move write pointer */ fpWrite += SaveLen; if( SaveLen != WriteLen ) { /* error, fetch errcode and quit */ ft_text->error[ ft_text->area ] = hb_fsError(); break; } /* return to read area and read another buffer */ hb_fsSeekLarge( ft_text->handles[ ft_text->area ], fpRead, FS_SET ); WriteLen = hb_fsRead( ft_text->handles[ ft_text->area ], WriteBuff, BUFFSIZE ); fpRead += WriteLen; } /* store length in bytes, set legacy EOF marker */ ft_text->lastbyte[ ft_text->area ] = hb_fsSeekLarge( ft_text->handles[ ft_text->area ], fpWrite, FS_SET ); hb_fsWrite( ft_text->handles[ ft_text->area ], WriteBuff, 0 ); /* clear last_rec so next gobot will recount the records */ ft_text->last_rec[ ft_text->area ] = 0; hb_fsSeekLarge( ft_text->handles[ ft_text->area ], ft_text->offset[ ft_text->area ], FS_SET ); hb_xfree( WriteBuff ); return ft_text->error[ ft_text->area ]; }
void hb_dbQSortComplete( LPDBQUICKSORT pQuickSort ) { HB_ULONG ulRecCount; AREAP pArea; ulRecCount = hb_fsSeek( pQuickSort->hFile, 0, FS_END ) / pQuickSort->uiRecordLen; if( ulRecCount >= 1 ) { hb_dbQSortDo( pQuickSort, 1, ulRecCount ); pArea = pQuickSort->pSortInfo->dbtri.lpaDest; hb_fsSeek( pQuickSort->hFile, 0, FS_SET ); while( ulRecCount-- > 0 ) { /* Read sorted record */ hb_fsRead( pQuickSort->hFile, pQuickSort->pSwapBufferA, pQuickSort->uiRecordLen ); /* Remove deleted flag */ pQuickSort->pSwapBufferA[ 0 ] = ' '; if( pArea->cdPage != hb_vmCDP() ) { hb_dbfTranslateRec( ( DBFAREAP ) pArea, ( HB_BYTE * ) pQuickSort->pSwapBufferA, hb_vmCDP(), pArea->cdPage ); } /* Append a new record and copy data */ if( SELF_APPEND( pArea, HB_TRUE ) == HB_FAILURE || SELF_PUTREC( pArea, pQuickSort->pSwapBufferA ) == HB_FAILURE ) break; } } hb_dbQSortExit( pQuickSort ); }
static const char * s_findFileMimeType( HB_FHANDLE fileIn ) { char buf[ 512 ]; int iLen; HB_FOFFSET nPos; nPos = hb_fsSeekLarge( fileIn, 0, FS_RELATIVE ); hb_fsSeek( fileIn, 0, FS_SET ); iLen = hb_fsRead( fileIn, buf, sizeof( buf ) ); if( iLen > 0 ) { hb_fsSeekLarge( fileIn, nPos, FS_SET ); return s_findStringMimeType( buf, iLen ); } return NULL; }
static char *s_findFileMimeType( FHANDLE fileIn ) { char buf[512]; int iLen; ULONG ulPos; ulPos = hb_fsSeek( fileIn, 0, SEEK_CUR ); hb_fsSeek( fileIn, 0, SEEK_SET ); iLen = hb_fsRead( fileIn, ( BYTE * ) buf, 512 ); if ( iLen > 0 ) { hb_fsSeek( fileIn, ulPos, SEEK_SET ); return s_findStringMimeType( buf, iLen ); } return NULL; }
/* internal routine to do buffer skips. Passing a positive value performs a downward skip, a negative number does an upward skip. Passing 0 skips to the end of file. Returns a long indicating the number of records skipped */ static long _ft_skip( long iRecs ) { PFT_TEXT ft_text = ( PFT_TEXT ) hb_stackGetTSD( &s_ft_text ); HB_ISIZ iByteCount; HB_ISIZ iBytesRead, iBytesRemaining; char * cPtr; long iSkipped = 0; char * cBuff = ( char * ) hb_xgrab( BUFFSIZE ); HB_FOFFSET fpOffset = ft_text->offset[ ft_text->area ]; ft_text->isBof[ ft_text->area ] = HB_FALSE; ft_text->isEof[ ft_text->area ] = HB_FALSE; ft_text->error[ ft_text->area ] = 0; /* iRecs is zero if they want to find the EOF, start a top of file */ if( iRecs == 0 ) { fpOffset = 0; ft_text->recno[ ft_text->area ] = 1; } if( iRecs >= 0 ) { do { cPtr = cBuff; /* position file pointer to beginning of current record */ hb_fsSeekLarge( ft_text->handles[ ft_text->area ], fpOffset, FS_SET ); /* read a chunk */ iBytesRead = hb_fsRead( ft_text->handles[ ft_text->area ], cBuff, BUFFSIZE ); if( ! iBytesRead ) { /* buffer is empty thus EOF, set vars and quit */ ft_text->isEof[ ft_text->area ] = HB_TRUE; ft_text->last_rec[ ft_text->area ] = ft_text->recno[ ft_text->area ]; ft_text->last_off[ ft_text->area ] = ft_text->offset[ ft_text->area ]; ft_text->error[ ft_text->area ] = hb_fsError(); break; } iBytesRemaining = iBytesRead; /* parse the buffer while there's still stuff in it */ do { /* get count of chars in this line */ iByteCount = _findeol( cPtr, iBytesRemaining, NULL ); if( iByteCount > 0 && iByteCount != iBytesRemaining ) { /* found an EOL, iByteCount points to first char of next record */ iBytesRemaining -= iByteCount; fpOffset += iByteCount; cPtr += iByteCount; ft_text->offset[ ft_text->area ] = fpOffset; ft_text->recno[ ft_text->area ]++; iSkipped++; if( iRecs && ( iSkipped == iRecs ) ) iBytesRemaining = iBytesRead = 0; } else { /* no more EOLs in this buffer, or EOL is last chars in the buffer */ /* check for EOF */ if( iBytesRead != BUFFSIZE ) { /* buffer was not full, thus EOF, set vars and quit */ iBytesRemaining = 0; ft_text->last_rec[ ft_text->area ] = ft_text->recno[ ft_text->area ]; ft_text->last_off[ ft_text->area ] = ft_text->offset[ ft_text->area ]; if( iRecs ) ft_text->isEof[ ft_text->area ] = HB_TRUE; } else { /* buffer was full, so probably not EOF, but maybe EOL straddled end of buffer, so back up pointer a bit before doing the next read */ fpOffset = hb_fsSeekLarge( ft_text->handles[ ft_text->area ], 0, FS_RELATIVE ) - 1; iBytesRemaining = 0; } } } while( iBytesRemaining > 0 ); } while( iBytesRead == BUFFSIZE ); } else { /* skip backwards */ iRecs = -iRecs; if( ft_text->recno[ ft_text->area ] > iRecs ) { do { /* calc offset to read area of file ahead of current pointer */ fpOffset = HB_MAX( ft_text->offset[ ft_text->area ] - BUFFSIZE, 0 ); /* move file pointer */ hb_fsSeekLarge( ft_text->handles[ ft_text->area ], fpOffset, FS_SET ); /* read a chunk */ iBytesRead = hb_fsRead( ft_text->handles[ ft_text->area ], cBuff, BUFFSIZE ); if( ! iBytesRead ) { /* buffer is empty thus file is zero len, set vars and quit */ ft_text->isBof[ ft_text->area ] = HB_TRUE; ft_text->isEof[ ft_text->area ] = HB_TRUE; ft_text->recno[ ft_text->area ] = 0; ft_text->offset[ ft_text->area ] = 0; ft_text->last_rec[ ft_text->area ] = 0; ft_text->error[ ft_text->area ] = hb_fsError(); break; } /* set pointer within buffer */ iBytesRemaining = ( int ) ( ft_text->offset[ ft_text->area ] - fpOffset ); cPtr = cBuff + iBytesRemaining; /* parse the buffer while there's still stuff in it */ do { /* get count of chars in this line */ iByteCount = _findbol( cPtr, iBytesRemaining ); if( iByteCount > 0 ) { /* found an EOL, iByteCount points to first char of next record */ iBytesRemaining -= iByteCount; ft_text->offset[ ft_text->area ] -= iByteCount; cPtr -= iByteCount; fpOffset = ft_text->offset[ ft_text->area ]; ft_text->recno[ ft_text->area ]--; iSkipped++; if( iSkipped == iRecs ) iBytesRemaining = iBytesRead = 0; } else { /* no more EOLs in this buffer so we're either at BOF or record crosses buffer boundary */ /* check for BOF */ if( iBytesRead != BUFFSIZE ) { /* buffer was not full, thus BOF, set vars and quit */ iBytesRemaining = 0; ft_text->offset[ ft_text->area ] = 0; ft_text->recno[ ft_text->area ] = 1; ft_text->isBof[ ft_text->area ] = HB_TRUE; } else { /* buffer was full, so not BOF */ iBytesRemaining = 0; } } } while( iBytesRemaining > 0 ); } while( fpOffset > 0 && iBytesRead == BUFFSIZE ); } else { ft_text->offset[ ft_text->area ] = 0; ft_text->recno[ ft_text->area ] = 1; ft_text->isBof[ ft_text->area ] = HB_TRUE; } } hb_xfree( cBuff ); return iSkipped; }
/* the contents of the inserted bytes are indeterminate, i.e. you'll have to write to them before they mean anything */ static int _ins_buff( PFT_TEXT ft_text, HB_ISIZ iLen ) { char * ReadBuff = ( char * ) hb_xgrab( BUFFSIZE ); char * WriteBuff = ( char * ) hb_xgrab( BUFFSIZE ); char * SaveBuff; HB_FOFFSET fpRead, fpWrite; HB_ISIZ WriteLen, ReadLen; HB_ISIZ SaveLen; HB_ISIZ iLenRemaining = iLen; /* set target move distance, this allows iLen to be greater than BUFFSIZE */ iLen = HB_MIN( iLenRemaining, BUFFSIZE ); iLenRemaining -= iLen; /* initialize file pointers */ fpRead = ft_text->offset[ ft_text->area ]; fpWrite = ft_text->offset[ ft_text->area ] + iLen; /* do initial load of both buffers */ hb_fsSeekLarge( ft_text->handles[ ft_text->area ], fpRead, FS_SET ); WriteLen = hb_fsRead( ft_text->handles[ ft_text->area ], WriteBuff, BUFFSIZE ); fpRead += WriteLen; ReadLen = hb_fsRead( ft_text->handles[ ft_text->area ], ReadBuff, BUFFSIZE ); fpRead += ReadLen; ft_text->error[ ft_text->area ] = 0; while( ! ft_text->error[ ft_text->area ] && iLen > 0 ) { while( WriteLen > 0 ) { /* position to beginning of write area */ if( hb_fsSeekLarge( ft_text->handles[ ft_text->area ], fpWrite, FS_SET ) != fpWrite ) { ft_text->error[ ft_text->area ] = hb_fsError(); break; } SaveLen = hb_fsWriteLarge( ft_text->handles[ ft_text->area ], WriteBuff, WriteLen ); if( ! SaveLen ) { ft_text->error[ ft_text->area ] = hb_fsError(); break; } /* move write pointer */ fpWrite += SaveLen; if( SaveLen != WriteLen ) { /* error, fetch errcode and quit */ ft_text->error[ ft_text->area ] = hb_fsError(); break; } #if 0 WriteLen = SaveLen; #endif /* swap buffers */ SaveBuff = WriteBuff; WriteBuff = ReadBuff; ReadBuff = SaveBuff; WriteLen = ReadLen; /* return to read area and read another buffer */ hb_fsSeekLarge( ft_text->handles[ ft_text->area ], fpRead, FS_SET ); ReadLen = hb_fsRead( ft_text->handles[ ft_text->area ], ReadBuff, BUFFSIZE ); fpRead += ReadLen; } iLen = HB_MIN( iLenRemaining, BUFFSIZE ); iLenRemaining -= iLen; } /* store length in bytes, set legacy EOF marker */ ft_text->lastbyte[ ft_text->area ] = hb_fsSeekLarge( ft_text->handles[ ft_text->area ], fpWrite, FS_SET ); hb_fsWrite( ft_text->handles[ ft_text->area ], WriteBuff, 0 ); /* clear last_rec so next gobot will recount the records */ ft_text->last_rec[ ft_text->area ] = 0; hb_fsSeekLarge( ft_text->handles[ ft_text->area ], ft_text->offset[ ft_text->area ], FS_SET ); hb_xfree( ReadBuff ); hb_xfree( WriteBuff ); return ft_text->error[ ft_text->area ]; }
static HB_BOOL hb_copyfile( const char * szSource, const char * szDest ) { HB_BOOL bRetVal = HB_FALSE; HB_FHANDLE fhndSource; PHB_ITEM pError = NULL; HB_TRACE( HB_TR_DEBUG, ( "hb_copyfile(%s, %s)", szSource, szDest ) ); do { fhndSource = hb_fsExtOpen( szSource, NULL, FO_READ | FXO_DEFAULTS | FXO_SHARELOCK, NULL, pError ); if( fhndSource == FS_ERROR ) { pError = hb_errRT_FileError( pError, NULL, EG_OPEN, 2012, szSource ); if( hb_errLaunch( pError ) != E_RETRY ) break; } } while( fhndSource == FS_ERROR ); if( fhndSource != FS_ERROR ) { HB_FHANDLE fhndDest; do { fhndDest = hb_fsExtOpen( szDest, NULL, FXO_TRUNCATE | FO_READWRITE | FO_EXCLUSIVE | FXO_DEFAULTS | FXO_SHARELOCK, NULL, pError ); if( fhndDest == FS_ERROR ) { pError = hb_errRT_FileError( pError, NULL, EG_CREATE, 2012, szDest ); if( hb_errLaunch( pError ) != E_RETRY ) break; } } while( fhndDest == FS_ERROR ); if( fhndDest != FS_ERROR ) { #if defined( HB_OS_UNIX ) struct stat struFileInfo; int iSuccess = fstat( fhndSource, &struFileInfo ); #endif void * buffer; HB_USHORT usRead; buffer = hb_xgrab( BUFFER_SIZE ); bRetVal = HB_TRUE; while( ( usRead = hb_fsRead( fhndSource, buffer, BUFFER_SIZE ) ) != 0 ) { while( hb_fsWrite( fhndDest, buffer, usRead ) != usRead ) { pError = hb_errRT_FileError( pError, NULL, EG_WRITE, 2016, szDest ); if( hb_errLaunch( pError ) != E_RETRY ) { bRetVal = HB_FALSE; break; } } } hb_xfree( buffer ); #if defined( HB_OS_UNIX ) if( iSuccess == 0 ) fchmod( fhndDest, struFileInfo.st_mode ); #endif hb_fsClose( fhndDest ); } hb_fsClose( fhndSource ); } if( pError ) hb_itemRelease( pError ); return bRetVal; }
static int hb_gt_std_ReadKey( PHB_GT pGT, int iEventMask ) { PHB_GTSTD pGTSTD; int ch = 0; HB_TRACE(HB_TR_DEBUG, ("hb_gt_std_ReadKey(%p,%d)", pGT, iEventMask)); HB_SYMBOL_UNUSED( iEventMask ); pGTSTD = HB_GTSTD_GET( pGT ); #if defined( HB_OS_UNIX_COMPATIBLE ) || defined( __DJGPP__ ) { struct timeval tv; fd_set rfds; tv.tv_sec = 0; tv.tv_usec = 0; FD_ZERO( &rfds ); FD_SET( pGTSTD->hStdin, &rfds ); if( select( pGTSTD->hStdin + 1, &rfds, NULL, NULL, &tv ) > 0 ) { BYTE bChar; if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = pGTSTD->keyTransTbl[ bChar ]; } } #elif defined( _MSC_VER ) && !defined( HB_WINCE ) if( pGTSTD->fStdinConsole ) { if( _kbhit() ) { ch = _getch(); if( ( ch == 0 || ch == 224 ) && _kbhit() ) { /* It was a function key lead-in code, so read the actual function key and then offset it by 256 */ ch = _getch() + 256; } ch = hb_gt_dos_keyCodeTranslate( ch ); if( ch > 0 && ch <= 255 ) ch = pGTSTD->keyTransTbl[ ch ]; } } else if( !_eof( pGTSTD->hStdin ) ) { BYTE bChar; if( _read( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = pGTSTD->keyTransTbl[ bChar ]; } #elif defined( HB_WIN32_IO ) if( !pGTSTD->fStdinConsole || WaitForSingleObject( ( HANDLE ) hb_fsGetOsHandle( pGTSTD->hStdin ), 0 ) == 0x0000 ) { BYTE bChar; if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = pGTSTD->keyTransTbl[ bChar ]; } #elif defined( __WATCOMC__ ) if( pGTSTD->fStdinConsole ) { if( kbhit() ) { ch = getch(); if( ( ch == 0 || ch == 224 ) && kbhit() ) { /* It was a function key lead-in code, so read the actual function key and then offset it by 256 */ ch = getch() + 256; } ch = hb_gt_dos_keyCodeTranslate( ch ); if( ch > 0 && ch <= 255 ) ch = pGTSTD->keyTransTbl[ ch ]; } } else if( !eof( pGTSTD->hStdin ) ) { BYTE bChar; if( read( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = pGTSTD->keyTransTbl[ bChar ]; } #else { int TODO; /* TODO: */ } #endif return ch; }
static HB_BOOL hb_dbQSortIsLess( LPDBQUICKSORT pQuickSort, HB_ULONG ulRecNo1, HB_ULONG ulRecNo2 ) { HB_USHORT uiCount, uiField; DBFAREAP pArea; LPFIELD pField; HB_BOOL bAscending, bIgnoreCase; int iResult; pArea = ( DBFAREAP ) pQuickSort->pSortInfo->dbtri.lpaSource; /* Read records */ hb_fsSeek( pQuickSort->hFile, ( ulRecNo1 - 1 ) * pQuickSort->uiRecordLen, FS_SET ); hb_fsRead( pQuickSort->hFile, pQuickSort->pSwapBufferA, pQuickSort->uiRecordLen ); hb_fsSeek( pQuickSort->hFile, ( ulRecNo2 - 1 ) * pQuickSort->uiRecordLen, FS_SET ); hb_fsRead( pQuickSort->hFile, pQuickSort->pSwapBufferB, pQuickSort->uiRecordLen ); /* Compare fields */ for( uiCount = 0; uiCount < pQuickSort->pSortInfo->uiItemCount; uiCount++ ) { /* Sort flags */ bIgnoreCase = ( ( pQuickSort->pSortInfo->lpdbsItem[ uiCount ].uiFlags & SF_CASE ) == SF_CASE ); bAscending = ( ( pQuickSort->pSortInfo->lpdbsItem[ uiCount ].uiFlags & SF_ASCEND ) == SF_ASCEND ); uiField = pQuickSort->pSortInfo->lpdbsItem[ uiCount ].uiField - 1; pField = pArea->area.lpFields + uiField; if( pField->uiType == HB_IT_MEMO ) continue; if( pField->uiType == HB_IT_LOGICAL ) { if( pQuickSort->pSwapBufferA[ pArea->pFieldOffset[ uiField ] ] == 'T' || pQuickSort->pSwapBufferA[ pArea->pFieldOffset[ uiField ] ] == 't' || pQuickSort->pSwapBufferA[ pArea->pFieldOffset[ uiField ] ] == 'Y' || pQuickSort->pSwapBufferA[ pArea->pFieldOffset[ uiField ] ] == 'y' ) * pQuickSort->pCmpBufferA = '1'; else * pQuickSort->pCmpBufferA = '0'; if( pQuickSort->pSwapBufferB[ pArea->pFieldOffset[ uiField ] ] == 'T' || pQuickSort->pSwapBufferB[ pArea->pFieldOffset[ uiField ] ] == 't' || pQuickSort->pSwapBufferB[ pArea->pFieldOffset[ uiField ] ] == 'Y' || pQuickSort->pSwapBufferB[ pArea->pFieldOffset[ uiField ] ] == 'y' ) * pQuickSort->pCmpBufferB = '1'; else * pQuickSort->pCmpBufferB = '0'; } else { memcpy( pQuickSort->pCmpBufferA, pQuickSort->pSwapBufferA + pArea->pFieldOffset[ uiField ], pField->uiLen ); memcpy( pQuickSort->pCmpBufferB, pQuickSort->pSwapBufferB + pArea->pFieldOffset[ uiField ], pField->uiLen ); } pQuickSort->pCmpBufferA[ pField->uiLen ] = 0; pQuickSort->pCmpBufferB[ pField->uiLen ] = 0; /* Compare buffers */ if( bIgnoreCase ) iResult = hb_stricmp( ( const char * ) pQuickSort->pCmpBufferA, ( const char * ) pQuickSort->pCmpBufferB ); else iResult = strcmp( ( const char * ) pQuickSort->pCmpBufferA, ( const char * ) pQuickSort->pCmpBufferB ); if( iResult == 0 ) continue; else if( bAscending ) return iResult < 0; else return iResult > 0; } return HB_FALSE; }
static int hb_gt_std_ReadKey( PHB_GT pGT, int iEventMask ) { PHB_GTSTD pGTSTD; int ch = 0; HB_TRACE( HB_TR_DEBUG, ( "hb_gt_std_ReadKey(%p,%d)", pGT, iEventMask ) ); HB_SYMBOL_UNUSED( iEventMask ); pGTSTD = HB_GTSTD_GET( pGT ); #if defined( HB_HAS_TERMIOS ) { struct timeval tv; fd_set rfds; tv.tv_sec = 0; tv.tv_usec = 0; FD_ZERO( &rfds ); FD_SET( pGTSTD->hStdin, &rfds ); if( select( pGTSTD->hStdin + 1, &rfds, NULL, NULL, &tv ) > 0 ) { HB_BYTE bChar; if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = bChar; } } #elif defined( _MSC_VER ) && ! defined( HB_OS_WIN_CE ) if( pGTSTD->fStdinConsole ) { if( _kbhit() ) { ch = _getch(); if( ( ch == 0 || ch == 224 ) && _kbhit() ) { /* It was a function key lead-in code, so read the actual function key and then offset it by 256 */ ch = _getch() + 256; } ch = hb_gt_dos_keyCodeTranslate( ch ); } } else if( ! _eof( ( int ) pGTSTD->hStdin ) ) { HB_BYTE bChar; if( _read( ( int ) pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = bChar; } #elif defined( HB_OS_WIN ) if( ! pGTSTD->fStdinConsole ) { HB_BYTE bChar; if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = bChar; } else if( WaitForSingleObject( ( HANDLE ) hb_fsGetOsHandle( pGTSTD->hStdin ), 0 ) == WAIT_OBJECT_0 ) { #if defined( HB_OS_WIN_CE ) HB_BYTE bChar; if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = bChar; #else INPUT_RECORD ir; DWORD dwEvents; while( PeekConsoleInput( ( HANDLE ) hb_fsGetOsHandle( pGTSTD->hStdin ), &ir, 1, &dwEvents ) && dwEvents == 1 ) { if( ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown ) { HB_BYTE bChar; if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = bChar; } else /* Remove from the input queue */ ReadConsoleInput( ( HANDLE ) hb_fsGetOsHandle( pGTSTD->hStdin ), &ir, 1, &dwEvents ); } #endif } #elif defined( __WATCOMC__ ) if( pGTSTD->fStdinConsole ) { if( kbhit() ) { ch = getch(); if( ( ch == 0 || ch == 224 ) && kbhit() ) { /* It was a function key lead-in code, so read the actual function key and then offset it by 256 */ ch = getch() + 256; } ch = hb_gt_dos_keyCodeTranslate( ch ); } } else if( ! eof( pGTSTD->hStdin ) ) { HB_BYTE bChar; if( read( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = bChar; } #else { if( ! pGTSTD->fStdinConsole ) { HB_BYTE bChar; if( hb_fsRead( pGTSTD->hStdin, &bChar, 1 ) == 1 ) ch = bChar; } else { int iTODO; /* TODO: */ } } #endif if( ch ) { int u = HB_GTSELF_KEYTRANS( pGT, ch ); if( u ) ch = HB_INKEY_NEW_UNICODE( u ); } return ch; }