Ejemplo n.º 1
0
/* performs all tasks defined for idle state */
void hb_idleState( void )
{
   PHB_IDLEDATA pIdleData = ( PHB_IDLEDATA ) hb_stackGetTSD( &s_idleData );

   if( ! pIdleData->fIamIdle )
   {
      pIdleData->fIamIdle = HB_TRUE;

      hb_releaseCPU();
      if( hb_vmRequestQuery() == 0 )
      {
         if( pIdleData->fCollectGarbage )
         {
            hb_gcCollectAll( HB_FALSE );
            pIdleData->fCollectGarbage = HB_FALSE;
         }

         if( pIdleData->pIdleTasks && pIdleData->iIdleTask < pIdleData->iIdleMaxTask )
         {
            hb_itemRelease( hb_itemDo( pIdleData->pIdleTasks[ pIdleData->iIdleTask ], 0 ) );
            ++pIdleData->iIdleTask;
            if( pIdleData->iIdleTask == pIdleData->iIdleMaxTask && hb_setGetIdleRepeat() )
            {
               pIdleData->iIdleTask = 0;    /* restart processing of idle tasks */
               pIdleData->fCollectGarbage = HB_TRUE;
            }
         }
      }
      pIdleData->fIamIdle = HB_FALSE;
   }
}
Ejemplo n.º 2
0
static TOKEN_ENVIRONMENT sTokGet( int iParam, HB_BOOL fReadOnly )
{
   if( iParam < 0 || ( iParam > 0 && HB_ISCHAR( iParam ) ) )
   {
      if( iParam < 0 || fReadOnly || HB_ISBYREF( iParam ) )
      {
         HB_SIZE nLen;

         if( iParam < 0 )
            iParam = -iParam;

         nLen = hb_parclen( iParam );
         if( nLen >= sizeof( TOKEN_POSITION ) * 2 )
         {
            TOKEN_ENVIRONMENT env = ( TOKEN_ENVIRONMENT ) HB_UNCONST( hb_parc( iParam ) );

            if( sTokEnvGetSize( env ) == nLen )
               return fReadOnly ? env : ( TOKEN_ENVIRONMENT ) hb_xmemdup( env, nLen + 1 );
         }
      }
      return NULL;
   }
   else
      return * ( TOKEN_ENVIRONMENT * ) hb_stackGetTSD( &s_token );
}
Ejemplo n.º 3
0
void ct_setsafety( HB_BOOL bSafety )
{
   CT_STRFIL * strfil = ( CT_STRFIL * ) hb_stackGetTSD( &s_strfil );

   HB_TRACE( HB_TR_DEBUG, ( "ct_setsafety(%i)", bSafety ) );

   strfil->bSafety = bSafety;
}
Ejemplo n.º 4
0
void ct_setargerrormode( int iMode )
{
   int * iArgErrMode = ( int * ) hb_stackGetTSD( &s_iArgErrMode );

   HB_TRACE( HB_TR_DEBUG, ( "ct_setargerrormode(%i)", iMode ) );

   *iArgErrMode = iMode;
}
Ejemplo n.º 5
0
void ct_setfcreate( HB_FATTR nFileAttr )
{
   CT_STRFIL * strfil = ( CT_STRFIL * ) hb_stackGetTSD( &s_strfil );

   HB_TRACE( HB_TR_DEBUG, ( "ct_setfcreate(%u)", nFileAttr ) );

   strfil->nFileAttr = nFileAttr;
}
Ejemplo n.º 6
0
HB_FATTR ct_getfcreate( void )
{
   CT_STRFIL * strfil = ( CT_STRFIL * ) hb_stackGetTSD( &s_strfil );

   HB_TRACE( HB_TR_DEBUG, ( "ct_getfcreate()" ) );

   return strfil->nFileAttr;
}
Ejemplo n.º 7
0
HB_BOOL ct_getsafety( void )
{
   CT_STRFIL * strfil = ( CT_STRFIL * ) hb_stackGetTSD( &s_strfil );

   HB_TRACE( HB_TR_DEBUG, ( "ct_getsafety()" ) );

   return strfil->bSafety;
}
Ejemplo n.º 8
0
int ct_getargerrormode( void )
{
   int * iArgErrMode = ( int * ) hb_stackGetTSD( &s_iArgErrMode );

   HB_TRACE( HB_TR_DEBUG, ( "ct_getargerrormode()" ) );

   return *iArgErrMode;
}
Ejemplo n.º 9
0
static void sTokSet( TOKEN_ENVIRONMENT env )
{
   TOKEN_ENVIRONMENT * penv = ( TOKEN_ENVIRONMENT * ) hb_stackGetTSD( &s_token );

   if( *penv )
      sTokEnvDel( *penv );

   *penv = env;
}
Ejemplo n.º 10
0
void hb_idleReset( void )
{
   PHB_IDLEDATA pIdleData = ( PHB_IDLEDATA ) hb_stackGetTSD( &s_idleData );

   if( pIdleData->iIdleTask == pIdleData->iIdleMaxTask && ! hb_setGetIdleRepeat() )
      pIdleData->iIdleTask = 0;

   pIdleData->fCollectGarbage = HB_TRUE;
}
Ejemplo n.º 11
0
PHB_ITEM hb_errorBlock( void )
{
   PHB_ERRDATA pErrData = ( PHB_ERRDATA ) hb_stackGetTSD( &s_errData );

   if( ! pErrData->errorBlock )
      pErrData->errorBlock = hb_itemNew( NULL );

   return pErrData->errorBlock;
}
Ejemplo n.º 12
0
/* set new low-level error launcher (C function) and return
 * handler currently active
 */
PHB_ERROR_INFO hb_errorHandler( PHB_ERROR_INFO pNewHandler )
{
   PHB_ERRDATA pErrData = ( PHB_ERRDATA ) hb_stackGetTSD( &s_errData );
   PHB_ERROR_INFO pOld = pErrData->errorHandler;

   if( pNewHandler )
      pNewHandler->Previous = pErrData->errorHandler;
   pErrData->errorHandler = pNewHandler;

   return pOld;
}
Ejemplo n.º 13
0
int extern _LNK_CONV
#else
static int
#endif
_hb_do_sortdescend( const void * p1, const void * p2 )
{
   PCT_CHARSORT charsort = ( PCT_CHARSORT ) hb_stackGetTSD( &s_charsort );

   return -strncmp( ( const char * ) p1 + charsort->sElementPos,
                    ( const char * ) p2 + charsort->sElementPos,
                    charsort->sCompareLen );
}
Ejemplo n.º 14
0
static PHB_PRNPOS hb_prnPos( void )
{
   return ( PHB_PRNPOS ) hb_stackGetTSD( &s_prnPos );
}
Ejemplo n.º 15
0
/* 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;

         /* read a chunk */
         if( ( iBytesRead = hb_fileResult( hb_fileReadAt( ft_text->handles[ ft_text->area ], cBuff, BUFFSIZE, fpOffset ) ) ) == 0 )
         {
            /* 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_fileSeek( 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 );

            /* read a chunk */
            if( ( iBytesRead = hb_fileResult( hb_fileReadAt( ft_text->handles[ ft_text->area ], cBuff, BUFFSIZE, fpOffset ) ) ) == 0 )
            {
               /* 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;
}
Ejemplo n.º 16
0
/* helper function for the token function group I */
static void do_token1( int iSwitch )
{
   PCT_TOKEN ct_token = ( PCT_TOKEN ) hb_stackGetTSD( &s_ct_token );

   int iParamCheck = 0;
   int iNoRef = ct_getref() && HB_ISBYREF( 1 );

   switch( iSwitch )
   {
      case DO_TOKEN1_TOKEN:
         ct_token->iPreSeparator = ct_token->iPostSeparator = -1;
         /* no "break" here !! */
      case DO_TOKEN1_ATTOKEN:
      case DO_TOKEN1_NUMTOKEN:
      case DO_TOKEN1_TOKENLOWER:
      case DO_TOKEN1_TOKENUPPER:
         iParamCheck = HB_ISCHAR( 1 );
         break;
   }

   if( iParamCheck )
   {
      const char * pcString = hb_parc( 1 );
      HB_SIZE sStrLen = hb_parclen( 1 );
      const char * pcSeparatorStr;
      HB_SIZE sSeparatorStrLen;
      HB_SIZE nTokenCounter;
      HB_SIZE nSkip;
      const char * pcSubStr;
      char * pcRet = NULL;
      HB_SIZE sSubStrLen;
      HB_SIZE sRetStrLen = 0;
      HB_SIZE nToken = 0;
      HB_SIZE nSkipCnt;
      const char * pc;

      /* separator string */
      sSeparatorStrLen = hb_parclen( 2 );
      if( sSeparatorStrLen != 0 )
         pcSeparatorStr = hb_parc( 2 );
      else
      {
         pcSeparatorStr = sc_pcSeparatorStr;
         sSeparatorStrLen = sc_sSeparatorStrLen;
      }

      if( iSwitch == DO_TOKEN1_NUMTOKEN )
      {
         /* token counter */
         nTokenCounter = HB_SIZE_MAX;
         /* skip width */
         nSkip = hb_parns( 3 );
      }
      else
      {
         /* token counter */
         nTokenCounter = hb_parns( 3 );
         /* skip width */
         nSkip = hb_parns( 4 ); /* HB_EXTENSION for AtToken()/TokenLower()/TokenUpper() */
      }

      if( nTokenCounter == 0 )
         nTokenCounter = HB_SIZE_MAX;
      if( nSkip == 0 )
         nSkip = HB_SIZE_MAX;

      /* prepare return value for TokenUpper()/TokenLower() */
      if( iSwitch == DO_TOKEN1_TOKENLOWER || iSwitch == DO_TOKEN1_TOKENUPPER )
      {
         if( sStrLen == 0 )
         {
            if( iNoRef )
               hb_retl( HB_FALSE );
            else
               hb_retc_null();
            return;
         }
         sRetStrLen = sStrLen;
         pcRet = ( char * ) hb_xgrab( sRetStrLen + 1 );
         hb_xmemcpy( pcRet, pcString, sRetStrLen );
      }

      /* find the <nTokenCounter>th token */
      pcSubStr = pcString;
      sSubStrLen = sStrLen;

      /* scan start condition */
      pc = pcSubStr - 1;

      while( nToken < nTokenCounter )
      {
         HB_SIZE sMatchedPos = sSeparatorStrLen;

         /* Skip the left nSkip successive separators */
         nSkipCnt = 0;
         do
         {
            sSubStrLen -= ( pc - pcSubStr ) + 1;
            pcSubStr = pc + 1;
            pc = ct_at_charset_forward( pcSubStr, sSubStrLen,
                                        pcSeparatorStr, sSeparatorStrLen, &sMatchedPos );
            if( iSwitch == DO_TOKEN1_TOKEN )
            {
               ct_token->iPreSeparator = ct_token->iPostSeparator;
               if( sMatchedPos < sSeparatorStrLen )
                  ct_token->iPostSeparator = pcSeparatorStr[ sMatchedPos ];
               else
                  ct_token->iPostSeparator = -1;
            }
            nSkipCnt++;
         }
         while( nSkipCnt < nSkip && pc == pcSubStr );

         if( sSubStrLen == 0 )
         {
            /* string ends with tokenizer (null string after tokenizer at
               end of string is not a token) */
            switch( iSwitch )
            {
               case DO_TOKEN1_TOKEN:
               {
                  char cRet;

                  hb_retc_null();
                  if( HB_ISBYREF( 5 ) ) /* HB_EXTENSION */
                  {
                     cRet = ( char ) ct_token->iPreSeparator;
                     hb_storclen( &cRet, ( ct_token->iPreSeparator != -1 ? 1 : 0 ), 5 );
                  }
                  if( HB_ISBYREF( 6 ) ) /* HB_EXTENSION */
                  {
                     cRet = ( char ) ct_token->iPostSeparator;
                     hb_storclen( &cRet, ( ct_token->iPostSeparator != -1 ? 1 : 0 ), 6 );
                  }
                  break;
               }
               case DO_TOKEN1_NUMTOKEN:
                  hb_retns( nToken );
                  break;

               case DO_TOKEN1_ATTOKEN:
                  hb_retns( 0 );
                  break;

               case DO_TOKEN1_TOKENLOWER:
               case DO_TOKEN1_TOKENUPPER:
                  hb_storclen( pcRet, sRetStrLen, 1 );

                  if( iNoRef )
                  {
                     hb_xfree( pcRet );
                     hb_retl( HB_FALSE );
                  }
                  else
                     hb_retclen_buffer( pcRet, sRetStrLen );
                  break;
            }
            return;
         }

         switch( iSwitch )
         {
            case DO_TOKEN1_TOKEN:
            case DO_TOKEN1_NUMTOKEN:
            case DO_TOKEN1_ATTOKEN:
               break;

            case DO_TOKEN1_TOKENLOWER:
               if( pcSubStr != pc )     /* letters can be tokenizers, too,
                                           but they should not be lowercase'd */
                  *( pcRet + ( pcSubStr - pcString ) ) = ( char ) hb_charLower( ( HB_UCHAR ) *pcSubStr );
               break;

            case DO_TOKEN1_TOKENUPPER:
               if( pcSubStr != pc )     /* letters can be tokenizers, too,
                                           but they should not be uppercase'd */
                  *( pcRet + ( pcSubStr - pcString ) ) = ( char ) hb_charUpper( ( HB_UCHAR ) *pcSubStr );
               break;

            default:
               break;
         }

         nToken++;

         if( pc == NULL )
         {
            /* little trick for return values */
            pc = pcSubStr + sSubStrLen;
            /* we must leave the while loop even if we have not
               yet found the <nTokenCounter>th token */
            break;
         }

         /* should we find the last token, but string ends with tokenizer, i.e.
            pc points to the last character at the moment ?
            -> break here ! */
         if( nTokenCounter == HB_SIZE_MAX )
         {
            if( nSkip == HB_SIZE_MAX )
            {
               const char * t;
               HB_BOOL bLast = HB_TRUE;

               for( t = pc + 1; t < pcString + sStrLen; t++ )
               {
                  if( ! memchr( pcSeparatorStr, *t, sSeparatorStrLen ) )
                  {
                     bLast = HB_FALSE;
                     break;
                  }
               }
               if( bLast )
                  break;
            }
            else if( pc + 1 == pcString + sStrLen )
               break;
         }
      }

      switch( iSwitch )
      {
         case DO_TOKEN1_TOKEN:
         {
            char cRet;

            if( nTokenCounter == HB_SIZE_MAX ||
                nToken == nTokenCounter )
               hb_retclen( pcSubStr, pc - pcSubStr );
            else
               hb_retc_null();

            if( HB_ISBYREF( 5 ) ) /* HB_EXTENSION */
            {
               cRet = ( char ) ct_token->iPreSeparator;
               hb_storclen( &cRet, ( ct_token->iPreSeparator != -1 ? 1 : 0 ), 5 );
            }
            if( HB_ISBYREF( 6 ) ) /* HB_EXTENSION */
            {
               cRet = ( char ) ct_token->iPostSeparator;
               hb_storclen( &cRet, ( ct_token->iPostSeparator != -1 ? 1 : 0 ), 6 );
            }
            break;
         }
         case DO_TOKEN1_NUMTOKEN:
            hb_retns( nToken );
            break;

         case DO_TOKEN1_ATTOKEN:
            if( nTokenCounter == HB_SIZE_MAX ||
                nToken == nTokenCounter )
               hb_retns( pcSubStr - pcString + 1 );
            else
               hb_retns( 0 );
            break;

         case DO_TOKEN1_TOKENLOWER:
         case DO_TOKEN1_TOKENUPPER:
            hb_storclen( pcRet, sRetStrLen, 1 );

            if( iNoRef )
            {
               hb_xfree( pcRet );
               hb_retl( HB_FALSE );
            }
            else
               hb_retclen_buffer( pcRet, sRetStrLen );
            break;
      }
   }
   else
   {
      switch( iSwitch )
      {
         case DO_TOKEN1_TOKEN:
         {
            PHB_ITEM pSubst = NULL;
            int iArgErrorMode = ct_getargerrormode();
            char cRet;

            if( HB_ISBYREF( 5 ) ) /* HB_EXTENSION */
            {
               cRet = ( char ) ct_token->iPreSeparator;
               hb_storclen( &cRet, ( ct_token->iPreSeparator != -1 ? 1 : 0 ), 5 );
            }
            if( HB_ISBYREF( 6 ) ) /* HB_EXTENSION */
            {
               cRet = ( char ) ct_token->iPostSeparator;
               hb_storclen( &cRet, ( ct_token->iPostSeparator != -1 ? 1 : 0 ), 6 );
            }

            if( iArgErrorMode != CT_ARGERR_IGNORE )
               pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG,
                                        CT_ERROR_TOKEN, NULL, HB_ERR_FUNCNAME, 0,
                                        EF_CANSUBSTITUTE,
                                        HB_ERR_ARGS_BASEPARAMS );

            if( pSubst != NULL )
               hb_itemReturnRelease( pSubst );
            else if( ! iNoRef )
               hb_retc_null();
            else
               hb_retl( HB_FALSE );
            break;
         }
         case DO_TOKEN1_TOKENLOWER:
         case DO_TOKEN1_TOKENUPPER:
         {
            PHB_ITEM pSubst = NULL;
            int iArgErrorMode = ct_getargerrormode();

            if( iArgErrorMode != CT_ARGERR_IGNORE )
               pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG,
                                        iSwitch == DO_TOKEN1_TOKENLOWER ?
                                        CT_ERROR_TOKENLOWER : CT_ERROR_TOKENUPPER,
                                        NULL, HB_ERR_FUNCNAME, 0,
                                        EF_CANSUBSTITUTE,
                                        HB_ERR_ARGS_BASEPARAMS );

            if( pSubst != NULL )
               hb_itemReturnRelease( pSubst );
            else if( ! iNoRef )
               hb_retc_null();
            else
               hb_retl( HB_FALSE );
            break;
         }
         case DO_TOKEN1_NUMTOKEN:
         case DO_TOKEN1_ATTOKEN:
         {
            PHB_ITEM pSubst = NULL;
            int iArgErrorMode = ct_getargerrormode();

            if( iArgErrorMode != CT_ARGERR_IGNORE )
               pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG,
                                        iSwitch == DO_TOKEN1_NUMTOKEN ?
                                        CT_ERROR_NUMTOKEN : CT_ERROR_ATTOKEN,
                                        NULL, HB_ERR_FUNCNAME, 0,
                                        EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS );

            if( pSubst != NULL )
               hb_itemReturnRelease( pSubst );
            else
               hb_retns( 0 );
            break;
         }
      }
   }
}
Ejemplo n.º 17
0
PHB_ITEM hb_errLaunchSubst( PHB_ITEM pError )
{
   PHB_ITEM pResult;

   HB_TRACE( HB_TR_DEBUG, ( "hb_errLaunchSubst(%p)", pError ) );

   if( pError )
   {
      PHB_ERRDATA pErrData = ( PHB_ERRDATA ) hb_stackGetTSD( &s_errData );
      HB_USHORT uiFlags = hb_errGetFlags( pError );

      /* Check if we have a valid error handler */
      if( ! pErrData->errorBlock || ! HB_IS_EVALITEM( pErrData->errorBlock ) )
         hb_errInternal( HB_EI_ERRNOBLOCK, NULL, NULL, NULL );

      /* Check if the error launcher was called too many times recursively */
      if( pErrData->iLaunchCount == HB_ERROR_LAUNCH_MAX )
         hb_errInternal( HB_EI_ERRTOOMANY, NULL, NULL, NULL );

      /* Launch the error handler: "xResult := Eval( ErrorBlock(), oError )" */
      pErrData->iLaunchCount++;

      /* set DosError() to last OS error code */
      pErrData->uiErrorDOS = ( int ) hb_errGetOsCode( pError );

      /* Add one try to the counter. */
      if( uiFlags & EF_CANRETRY )
         hb_errPutTries( pError, ( HB_USHORT ) ( hb_errGetTries( pError ) + 1 ) );

      if( pErrData->errorHandler )
      {
         /* there is a low-level error handler defined - use it instead
          * of normal Harbour level one
          */
         pErrData->errorHandler->Error = pError;
         pErrData->errorHandler->ErrorBlock = pErrData->errorBlock;
         pResult = ( pErrData->errorHandler->Func )( pErrData->errorHandler );
         pErrData->errorHandler->Error = NULL;
      }
      else
         pResult = hb_itemDo( pErrData->errorBlock, 1, pError );

      pErrData->iLaunchCount--;

      /* Check results */
      if( hb_vmRequestQuery() != 0 )
      {
         if( pResult )
            hb_itemRelease( pResult );
         pResult = NULL;
      }
      else
      {
         /* If the canSubstitute flag has not been set,
            consider it as a failure. */
         if( ! ( uiFlags & EF_CANSUBSTITUTE ) )
            hb_errInternal( HB_EI_ERRRECFAILURE, NULL, NULL, NULL );
      }
   }
   else
      pResult = hb_itemNew( NULL );

   return pResult;
}
Ejemplo n.º 18
0
HB_USHORT hb_errLaunch( PHB_ITEM pError )
{
   HB_USHORT uiAction = E_DEFAULT; /* Needed to avoid GCC -O2 warning */

   HB_TRACE( HB_TR_DEBUG, ( "hb_errLaunch(%p)", pError ) );

   if( pError )
   {
      PHB_ERRDATA pErrData = ( PHB_ERRDATA ) hb_stackGetTSD( &s_errData );
      HB_USHORT uiFlags = hb_errGetFlags( pError );
      PHB_ITEM pResult;

      /* Check if we have a valid error handler */
      if( ! pErrData->errorBlock || ! HB_IS_EVALITEM( pErrData->errorBlock ) )
         hb_errInternal( HB_EI_ERRNOBLOCK, NULL, NULL, NULL );

      /* Check if the error launcher was called too many times recursively */
      if( pErrData->iLaunchCount == HB_ERROR_LAUNCH_MAX )
         hb_errInternal( HB_EI_ERRTOOMANY, NULL, NULL, NULL );

      /* Launch the error handler: "lResult := Eval( ErrorBlock(), oError )" */
      pErrData->iLaunchCount++;

      /* set DosError() to last OS error code */
      pErrData->uiErrorDOS = ( int ) hb_errGetOsCode( pError );

      /* Add one try to the counter. */
      if( uiFlags & EF_CANRETRY )
         hb_errPutTries( pError, ( HB_USHORT ) ( hb_errGetTries( pError ) + 1 ) );

      if( pErrData->errorHandler )
      {
         /* there is a low-level error handler defined - use it instead
          * of normal Harbour level one
          */
         pErrData->errorHandler->Error = pError;
         pErrData->errorHandler->ErrorBlock = pErrData->errorBlock;
         pResult = ( pErrData->errorHandler->Func )( pErrData->errorHandler );
         pErrData->errorHandler->Error = NULL;
      }
      else
         pResult = hb_itemDo( pErrData->errorBlock, 1, pError );

      pErrData->iLaunchCount--;

      /* Check results */
      if( hb_vmRequestQuery() != 0 )
      {
         if( pResult )
            hb_itemRelease( pResult );
         uiAction = E_BREAK;
      }
      else if( pResult )
      {
         HB_BOOL bFailure = HB_FALSE;

         /* If the error block didn't return a logical value, */
         /* or the canSubstitute flag has been set, consider it as a failure */
         if( ! HB_IS_LOGICAL( pResult ) || ( uiFlags & EF_CANSUBSTITUTE ) )
            bFailure = HB_TRUE;
         else
         {
            uiAction = hb_itemGetL( pResult ) ? E_RETRY : E_DEFAULT;

            if( ( uiAction == E_DEFAULT && !( uiFlags & EF_CANDEFAULT ) ) ||
                ( uiAction == E_RETRY   && !( uiFlags & EF_CANRETRY ) ) )
               bFailure = HB_TRUE;
         }

         hb_itemRelease( pResult );

         if( bFailure )
            hb_errInternal( HB_EI_ERRRECFAILURE, NULL, NULL, NULL );

      }
      else
         hb_errInternal( HB_EI_ERRRECFAILURE, NULL, NULL, NULL );
   }
   else
      uiAction = E_RETRY;  /* Clipper does this, undocumented */

   return uiAction;
}
Ejemplo n.º 19
0
static char * hb_acceptBuffer( void )
{
    return ( char * ) hb_stackGetTSD( &s_szAcceptResult );
}
Ejemplo n.º 20
0
void hbwapi_SetLastError( DWORD dwLastError )
{
   PHB_WAPIERRDATA pWinErrData = ( PHB_WAPIERRDATA ) hb_stackGetTSD( &s_wapierrData );

   pWinErrData->dwLastError = dwLastError;
}
Ejemplo n.º 21
0
DWORD hbwapi_GetLastError( void )
{
   PHB_WAPIERRDATA pWinErrData = ( PHB_WAPIERRDATA ) hb_stackGetTSD( &s_wapierrData );

   return pWinErrData->dwLastError;
}