コード例 #1
0
ファイル: hbdbsort.c プロジェクト: ItamarLins/harbour-core
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 );
}
コード例 #2
0
ファイル: ctstrfil.c プロジェクト: NaldoDj/core
static HB_SIZE ct_StrFile( const char * pFileName, const char * pcStr, HB_SIZE nLen,
                           HB_BOOL bOverwrite, HB_FOFFSET nOffset, HB_BOOL bTrunc )
{
   HB_FHANDLE hFile;
   HB_BOOL bOpen = HB_FALSE;
   HB_BOOL bFile = hb_fsFile( pFileName );
   HB_SIZE nWrite = 0;

   if( bFile && bOverwrite )
   {
      hFile = hb_fsOpen( pFileName, FO_READWRITE );
      bOpen = HB_TRUE;
   }
   else if( ! bFile || ! ct_getsafety() )
      hFile = hb_fsCreate( pFileName, ct_getfcreate() );
   else
      hFile = FS_ERROR;

   if( hFile != FS_ERROR )
   {
      if( nOffset )
         hb_fsSeekLarge( hFile, nOffset, FS_SET );
      else if( bOpen )
         hb_fsSeek( hFile, 0, FS_END );

      nWrite = hb_fsWriteLarge( hFile, pcStr, nLen );
      if( ( nWrite == nLen ) && bOpen && bTrunc )
         hb_fsWrite( hFile, NULL, 0 );

      hb_fsClose( hFile );
   }
   return nWrite;
}
コード例 #3
0
ファイル: hbdbsort.c プロジェクト: ItamarLins/harbour-core
HB_BOOL hb_dbQSortAdvance( LPDBQUICKSORT pQuickSort, HB_USHORT uiCount )
{
   HB_USHORT uiSize;

   /* Write chunk */
   uiSize = uiCount * pQuickSort->uiRecordLen;
   return hb_fsWrite( pQuickSort->hFile, pQuickSort->pBuffer, uiSize ) == uiSize;
}
コード例 #4
0
ファイル: fttext.c プロジェクト: antonioscherrer/harbour-core
/* 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 ];
}
コード例 #5
0
ファイル: fttext.c プロジェクト: antonioscherrer/harbour-core
/* 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 ];
}
コード例 #6
0
ファイル: console.c プロジェクト: CsBela/core
static void hb_conDevPos( int iRow, int iCol )
{
   HB_FHANDLE hFile;

   HB_TRACE( HB_TR_DEBUG, ( "hb_conDevPos(%d, %d)", iRow, iCol ) );

   /* Position printer if SET DEVICE TO PRINTER and valid printer file
      otherwise position console */

   if( ( hFile = hb_setGetPrinterHandle( HB_SET_PRN_DEV ) ) != FS_ERROR )
   {
      int iPRow = iRow;
      int iPCol = iCol + hb_setGetMargin();
      PHB_PRNPOS pPrnPos = hb_prnPos();

      if( pPrnPos->row != iPRow || pPrnPos->col != iPCol )
      {
         char buf[ 256 ];
         int iPtr = 0;

         if( pPrnPos->row != iPRow )
         {
            if( ++pPrnPos->row > iPRow )
            {
               memcpy( &buf[ iPtr ], "\x0C\x0D\x00\x00", 2 );  /* Source buffer is 4 bytes to make CodeGuard happy */
               iPtr += 2;
               pPrnPos->row = 0;
            }
            else
            {
               memcpy( &buf[ iPtr ], s_szCrLf, s_iCrLfLen );
               iPtr += s_iCrLfLen;
            }

            while( pPrnPos->row < iPRow )
            {
               if( iPtr + s_iCrLfLen > ( int ) sizeof( buf ) )
               {
                  hb_fsWrite( hFile, buf, ( HB_USHORT ) iPtr );
                  iPtr = 0;
               }
               memcpy( &buf[ iPtr ], s_szCrLf, s_iCrLfLen );
               iPtr += s_iCrLfLen;
               ++pPrnPos->row;
            }
            pPrnPos->col = 0;
         }
         else if( pPrnPos->col > iPCol )
         {
            buf[ iPtr++ ] = '\x0D';
            pPrnPos->col = 0;
         }

         while( pPrnPos->col < iPCol )
         {
            if( iPtr == ( int ) sizeof( buf ) )
            {
               hb_fsWrite( hFile, buf, ( HB_USHORT ) iPtr );
               iPtr = 0;
            }
            buf[ iPtr++ ] = ' ';
            ++pPrnPos->col;
         }

         if( iPtr )
            hb_fsWrite( hFile, buf, ( HB_USHORT ) iPtr );
      }
   }
   else
      hb_gtSetPos( iRow, iCol );
}
コード例 #7
0
ファイル: copyfile.c プロジェクト: ggargano/hbtest2
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;
}