Exemplo n.º 1
0
Arquivo: adsx.c Projeto: SBCamus/core
static PMIXKEY mixKeyNew( PHB_ITEM pItem, HB_ULONG ulRecNo, HB_BYTE bType, HB_USHORT uiLen )
{
   PMIXKEY pKey;
   double  dbl;
   HB_BYTE buf[ 8 ];

   pKey = ( PMIXKEY ) hb_xgrab( sizeof( HB_ULONG ) + uiLen );
   pKey->rec = ulRecNo;

   switch( bType )
   {
      case 'C':
      {
         HB_SIZE ul = hb_itemGetCLen( pItem );
         if( ul > ( HB_SIZE ) uiLen )
            ul = uiLen;
         memcpy( pKey->val, hb_itemGetCPtr( pItem ), ul );
         if( ul < ( HB_SIZE ) uiLen )
            memset( pKey->val + ul, ' ', ( HB_SIZE ) uiLen - ul );
         break;
      }
      case 'N':
         dbl = hb_itemGetND( pItem );
         HB_DBL2ORD( &dbl, buf );
         memcpy( pKey->val, buf, 8 );
         break;

      case 'D':
         dbl = ( double ) hb_itemGetDL( pItem );
         HB_DBL2ORD( &dbl, buf );
         memcpy( pKey->val, buf, 8 );
         break;

      case 'L':
         pKey->val[ 0 ] = ( HB_BYTE ) ( hb_itemGetL( pItem ) ? 'T' : 'F' );
         break;

      default:
         memset( pKey->val, ' ', uiLen );
   }
   return pKey;
}
Exemplo n.º 2
0
// 26/07/2008 - 11:32:47
static
void printf_add_conv( PPrintInfo pInfo, PHB_ITEM pItem )
{
    char flag = 0;
    int width = 0;
    int precision = 0;
    char specifier = '\0';
    char m = '\0';
    char c;
    char mask[20];
    const char *t1;
    const char *t2;

    char * cValue;
    double dValue;
    ULONG  Length;

    /*
     * Procura por uma string de conversao com o formato:
     *        0       1        2         3      4
     *     %[flags][width][.precision][length]specifier
     *
     */
    t1 = pInfo->Mask;
    mask[0] = '\0';

    pInfo->Mask ++;
    pInfo->msk_len--;

    /*
     * Se nao tem nenhum item de argumento, e o proximo caracter de escape nao for
     * o "%", entao temos que abortar a rotina... indicando erro de argumento!
     */
    if (pInfo->msk_len &&
            // pInfo->Mask[0] != '%' &&
            !pItem)
    {
        pInfo->error =  FAILURE;
        return;
    }

    /* processamos a string como um todo */
    while (pInfo->error == NONE   &&
            pInfo->msk_len         &&
            pInfo->Mask[0] )
    {
        c = pInfo->Mask[0];

        // setou o flag?
        if (strchr( "-+ #0", c ))
        {
            flag = c;
            c = 'A';
        }

        // setar o width?
        if (strchr( "1234567890", c ))
        {
            char *t = (char *) hb_xgrab(15);
            char *s = t;

            do
            {
                *t = c;
                t++;
                pInfo->Mask ++;
                pInfo->msk_len--;
                c = pInfo->Mask[0];

            } while (pInfo->msk_len && strchr( "1234567890", c ));

            *t = '\0';
            width = atoi( s );
            hb_xfree(s);
        }

        // setar precision?
        if (c == '.')
        {
            char *t = (char *) hb_xgrab(15);
            char *s = t;

            pInfo->Mask ++;
            pInfo->msk_len--;
            c = pInfo->Mask[0];

            while (pInfo->msk_len && strchr( "1234567890", c ))
            {
                *t = c;
                t++;
                pInfo->Mask ++;
                pInfo->msk_len--;
                c = pInfo->Mask[0];
            }

            *t = '\0';
            precision = atoi( s );
            hb_xfree(s);

            c = pInfo->Mask[0];
        }

        if (c == 'l' && strchr( "idouxX", pInfo->Mask[1] ))
            m = c;
        if (c == 'h' && strchr( "idouxX", pInfo->Mask[1] ))
            m = c;
        if (c == 'L' && strchr( "eEfgG", pInfo->Mask[1] ))
            m = c;

        // Chegou no tipo?
        if (strchr( "cdieEfgGosuxXpn%", c ))
        {
            specifier = c;
            pInfo->Mask ++;
            pInfo->msk_len--;

            t2 = pInfo->Mask;

            switch( specifier )
            {
            case '%':
            {
                printf_add_str( pInfo, "%", 1L );
                break;
            }
            case 'c':
                //  O argumento é tratado como um inteiro, e mostrado como o caractere ASCII correspondente.
            {
                char s[2];
                memset( s, 0, 2 );

                if (HB_IS_STRING( pItem ))
                {
                    const char *t = hb_itemGetCPtr( pItem );
                    s[0] = ((t) ? t[0] : 0);
                } else if( HB_IS_NUMERIC( pItem ) )
                {
                    s[0] = (char) hb_itemGetNI( pItem );
                }

                printf_add_str( pInfo, s, 1L );
                break;
            }
            case 's':
            {
                Length = t2-t1;
                width  = max( hb_itemGetCLen( pItem ), (ULONG) width );
                cValue = (char *) hb_xgrab( width + 1 );

                memmove( mask, t1, Length );
                mask[Length] = '\0';

                cValue[0] = '\0';
                Length = sprintf( cValue, mask, hb_itemGetCPtr( pItem ) );
                printf_add_str( pInfo, cValue, Length );
                hb_xfree( cValue );
                break;
            }
            case 'p':
            {
                char s[9];
                s[0] = '\0';
                sprintf( s, "%p", hb_itemGetPtr( pItem ) );
                printf_add_str( pInfo, s, 8);
                break;
            }

            /*
             * Separamos aqui as operações sobre inteiros
             */
            case 'i':
            case 'd':
            // O argumento é tratado como um INTEIRO, e mostrado como um número decimal com sinal.
            case 'o':
            // O argumento é tratado com um INTEIRO, e mostrado como un número octal.
            case 'u':
            // O argumento é tratado com um INTEIRO, e mostrado como um número decimal sem sinal.
            case 'x':
            // O argumento é tratado como um INTEIRO, e mostrado como um número hexadecimal (com as letras minúsculas).
            case 'X':
                // O argumento é tratado como um INTEIRO, e mostrado como um número hexadecimal (com as letras maiúsculas).
            {
                Length = t2-t1;
                width  = ((width) ? width : 32 );
                cValue = (char *) hb_xgrab( width + 1 );

                memmove( mask, t1, Length );
                mask[Length] = '\0';
                cValue[0] = '\0';

                if (m == '\0')
                    Length = sprintf( cValue, mask, (int) hb_itemGetNI( pItem ));
                if (m == 'l')
                    Length = sprintf( cValue, mask, (LONG) hb_itemGetNL( pItem )); // como LONG ???
                if (m == 'h')
                    Length = sprintf( cValue, mask, (LONG) hb_itemGetNL( pItem )); // como LONG ???

                printf_add_str( pInfo, cValue, Length );
                hb_xfree( cValue );
                break;
            }

            /*
             * Separamos aqui as operações com numeros flutuantes
             */
            case 'e' :
            // O argumento é tratado como notação científica (e.g. 1.2e+2).
            case 'E' :
            // O argumento é tratado como notação científica (e.g. 1.2e+2).
            case 'f' :
            // O argumento é tratado como um float, e mostrado como um número de ponto flutuante.
            case 'F' :
                // O argumento é tratado como um float, e mostrado como um número de ponto flutuante.
            {
                Length = t2-t1;
                width  = ((width) ? width : 64 );
                dValue = (double) hb_itemGetND( pItem );     // converting double --> float ???
                cValue = (char *) hb_xgrab( width + 1 );

                memmove( mask, t1, Length );
                mask[Length] = '\0';

                sprintf( cValue, mask, dValue );
                printf_add_str( pInfo, cValue, strlen( cValue ) );
                hb_xfree( cValue );
                break;
            }

            default:
                break;
            }
            break;
        } else {
            pInfo->Mask ++;
            pInfo->msk_len--;
        }
    }
}
Exemplo n.º 3
0
//------------------------------------------------------------------------------
// IEventHandler's Invoke()
// self is where the action happens
// self function receives events (by their ID number) and distributes the processing
// or them or ignores them
static ULONG STDMETHODCALLTYPE Invoke( IEventHandler *self, DISPID dispid, REFIID riid,
   LCID lcid, WORD wFlags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *pexcepinfo,
   UINT *puArgErr )
{
   PHB_ITEM pItem;
   int iArg, i;
   PHB_ITEM pItemArray[32]; // max 32 parameters?
   PHB_ITEM *pItems;
   ULONG ulRefMask = 0;
   ULONG ulPos;
   PHB_ITEM Key;

   Key = hb_itemNew( NULL );

   // We implement only a "default" interface
   if ( !IsEqualIID( riid, &IID_NULL ) )
      return( DISP_E_UNKNOWNINTERFACE );

   HB_SYMBOL_UNUSED(lcid);
   HB_SYMBOL_UNUSED(wFlags);
   HB_SYMBOL_UNUSED(result);
   HB_SYMBOL_UNUSED(pexcepinfo);
   HB_SYMBOL_UNUSED(puArgErr);

   // delegate work to somewhere else in PRG
   //***************************************

#ifdef __USEHASHEVENTS

   if ( hb_hashScan( ((MyRealIEventHandler* ) self)->pEvents, hb_itemPutNL( Key, dispid ),
      &ulPos ) )
   {
      PHB_ITEM pArray = hb_hashGetValueAt( ((MyRealIEventHandler* ) self)->pEvents, ulPos );

#else

   ulPos = hb_arrayScan( ((MyRealIEventHandler* ) self)->pEvents, hb_itemPutNL( Key, dispid ),
      NULL, NULL, 0
   #ifdef __XHARBOUR__
      , 0
   #endif
      );

   if ( ulPos )
   {
      PHB_ITEM pArray = hb_arrayGetItemPtr( ((MyRealIEventHandler* ) self)->pEventsExec, ulPos );

#endif

      PHB_ITEM pExec  = hb_arrayGetItemPtr( pArray, 01 );

      if ( pExec )
      {
         hb_vmRequestReenter();

         switch ( hb_itemType( pExec ) )
         {
            case HB_IT_BLOCK:
            {
               hb_vmPushSymbol( &hb_symEval );
               hb_vmPush( pExec );
               break;
            }
            case HB_IT_STRING:
            {
               PHB_ITEM pObject = hb_arrayGetItemPtr( pArray, 2 );
               hb_vmPushSymbol( hb_dynsymSymbol( hb_dynsymFindName( hb_itemGetCPtr( pExec ) ) ) );

               if ( HB_IS_OBJECT( pObject ) )
                  hb_vmPush( pObject );
               else
                  hb_vmPushNil();
               break;
            }
            case HB_IT_POINTER:
            {
               hb_vmPushSymbol( hb_dynsymSymbol( ( (PHB_SYMB) pExec ) -> pDynSym ) );
               hb_vmPushNil();
               break;
            }
         }

         iArg = params->cArgs;
         for( i = 1; i<= iArg; i++ )
         {
            pItem = hb_itemNew(NULL);
            hb_oleVariantToItem( pItem, &(params->rgvarg[iArg-i]) );
            pItemArray[i-1] = pItem;
            // set bit i
            ulRefMask |= ( 1L << (i-1) );
         }

         if( iArg )
         {
            pItems = pItemArray;
            hb_itemPushList( ulRefMask, iArg, &pItems );
         }

         // execute
         hb_vmDo( (USHORT) iArg );

         // En caso de que los parametros sean pasados por referencia
         for( i=iArg; i > 0; i-- )
         {
            if( ( (&(params->rgvarg[iArg-i]))->n1.n2.vt & VT_BYREF ) == VT_BYREF )
            {
               switch( (&(params->rgvarg[iArg-i]))->n1.n2.vt )
               {
                  //case VT_UI1|VT_BYREF:
                  //   *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pbVal) = va_arg(argList,unsigned char*);  //pItemArray[i-1]
                  //   break;
                  case VT_I2|VT_BYREF:
                     *((&(params->rgvarg[iArg-i]))->n1.n2.n3.piVal)    = (short)          hb_itemGetNI(pItemArray[i-1]);
                     break;
                  case VT_I4|VT_BYREF:
                     *((&(params->rgvarg[iArg-i]))->n1.n2.n3.plVal)    = (long)           hb_itemGetNL(pItemArray[i-1]);
                     break;
                  case VT_R4|VT_BYREF:
                     *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pfltVal)  = (float)          hb_itemGetND(pItemArray[i-1]);
                     break;
                  case VT_R8|VT_BYREF:
                     *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pdblVal)  = (double)         hb_itemGetND(pItemArray[i-1]);
                     break;
                  case VT_BOOL|VT_BYREF:
                     *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pboolVal) =  (VARIANT_BOOL)  ( hb_itemGetL( pItemArray[i-1] ) ? 0xFFFF : 0 );
                     break;
                  //case VT_ERROR|VT_BYREF:
                  //   *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pscode) = va_arg(argList, SCODE*);
                  //   break;
                  case VT_DATE|VT_BYREF:
                     *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pdate)    = (DATE) (double) (hb_itemGetDL(pItemArray[i-1])-2415019 );
                     break;
                  //case VT_CY|VT_BYREF:
                  //   *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pcyVal) = va_arg(argList, CY*);
                  //   break;
                  //case VT_BSTR|VT_BYREF:
                  //   *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pbstrVal = va_arg(argList, BSTR*);
                  //   break;
                  //case VT_UNKNOWN|VT_BYREF:
                  //   pArg->ppunkVal = va_arg(argList, LPUNKNOWN*);
                  //   break;
                  //case VT_DISPATCH|VT_BYREF:
                  //   pArg->ppdispVal = va_arg(argList, LPDISPATCH*);
                  //   break;
               } // EOF switch( (&(params->rgvarg[iArg-i]))->n1.n2.vt )
            } // EOF if( (&(params->rgvarg[iArg-i]))->n1.n2.vt & VT_BYREF == VT_BYREF )
         } // EOF for( i=iArg; i > 0; i-- )

         hb_vmRequestRestore();
      } // EOF if ( pExec )
   }  // EOF If Scan

   hb_itemRelease( Key );

   return S_OK;
}  // EOF invoke

//------------------------------------------------------------------------------
// Here's IEventHandler's VTable. It never changes so we can declare it static
static const IEventHandlerVtbl IEventHandler_Vtbl = {
   QueryInterface,
   AddRef,
   Release,
   GetTypeInfoCount,
   GetTypeInfo,
   GetIDsOfNames,
   Invoke
};

//------------------------------------------------------------------------------
// constructor
// params:
// device_interface        - refers to the interface type of the COM object (whose event we are trying to receive).
// device_event_interface  - indicates the interface type of the outgoing interface supported by the COM object.
//                           This will be the interface that must be implemented by the Sink object.
//                           is essentially derived from IDispatch, our Sink object (self IEventHandler)
//                           is also derived from IDispatch.

typedef IEventHandler device_interface;

// Hash  // SetupConnectionPoint( oOle:hObj, @hSink, hEvents )             -> nError
// Array // SetupConnectionPoint( oOle:hObj, @hSink, aEvents, aExecEvent ) -> nError

HB_FUNC( SETUPCONNECTIONPOINT )
{
   IConnectionPointContainer*  pIConnectionPointContainerTemp = NULL;
   IUnknown*                   pIUnknown = NULL;
   IConnectionPoint*           m_pIConnectionPoint;
   IEnumConnectionPoints*      m_pIEnumConnectionPoints;
   HRESULT                     hr; //,r;
   IID                         rriid;
   register IEventHandler *    selfobj;
   DWORD                       dwCookie = 0;

   device_interface*           pdevice_interface = (device_interface*) HB_PARNL( 1 );
   MyRealIEventHandler*        pThis;

   // Allocate our IEventHandler object (actually a MyRealIEventHandler)
   // intentional misrepresentation of size

   selfobj = ( IEventHandler *) GlobalAlloc( GMEM_FIXED, sizeof( MyRealIEventHandler ) );

   if ( ! selfobj )
   {
      hr = E_OUTOFMEMORY;
   }
   else
   {
      // Store IEventHandler's VTable in the object
      selfobj->lpVtbl = (IEventHandlerVtbl *) &IEventHandler_Vtbl;

      // Increment the reference count so we can call Release() below and
      // it will deallocate only if there is an error with QueryInterface()
      ((MyRealIEventHandler *) selfobj)->count = 0;

      //((MyRealIEventHandler *) selfobj)->device_event_interface_iid = &riid;
      ((MyRealIEventHandler *) selfobj)->device_event_interface_iid = IID_IDispatch;

      // Query self object itself for its IUnknown pointer which will be used
      // later to connect to the Connection Point of the device_interface object.
      hr = selfobj->lpVtbl->QueryInterface( selfobj, &IID_IUnknown, (void**) (void *) &pIUnknown );
      if ( hr == S_OK && pIUnknown )
      {
         // Query the pdevice_interface for its connection point.
         hr = pdevice_interface->lpVtbl->QueryInterface( pdevice_interface,
            &IID_IConnectionPointContainer, (void**) (void *) &pIConnectionPointContainerTemp );

         if ( hr == S_OK && pIConnectionPointContainerTemp )
         {
            // start uncomment
            hr = pIConnectionPointContainerTemp->lpVtbl->EnumConnectionPoints( pIConnectionPointContainerTemp, &m_pIEnumConnectionPoints );

            if ( hr == S_OK && m_pIEnumConnectionPoints )
            {
               do
               {
                  hr = m_pIEnumConnectionPoints->lpVtbl->Next( m_pIEnumConnectionPoints, 1, &m_pIConnectionPoint , NULL);
                  if( hr == S_OK )
                  {
                     if ( m_pIConnectionPoint->lpVtbl->GetConnectionInterface( m_pIConnectionPoint, &rriid ) == S_OK )
                     {
                        break;
                     }
                  }

               } while( hr == S_OK );
               m_pIEnumConnectionPoints->lpVtbl->Release(m_pIEnumConnectionPoints);
            }
            // end uncomment

            //hr = pIConnectionPointContainerTemp ->lpVtbl->FindConnectionPoint(pIConnectionPointContainerTemp ,  &IID_IDispatch, &m_pIConnectionPoint);
            pIConnectionPointContainerTemp->lpVtbl->Release( pIConnectionPointContainerTemp );
            pIConnectionPointContainerTemp = NULL;
         }

         if ( hr == S_OK && m_pIConnectionPoint )
         {
            //OutputDebugString("getting iid");
            //Returns the IID of the outgoing interface managed by self connection point.
            //hr = m_pIConnectionPoint->lpVtbl->GetConnectionInterface(m_pIConnectionPoint, &rriid );
            //OutputDebugString("called");

            if( hr == S_OK )
            {
               ((MyRealIEventHandler *) selfobj)->device_event_interface_iid = rriid;
            }
            else
               OutputDebugString("error getting iid");

            //OutputDebugString("calling advise");
            hr = m_pIConnectionPoint->lpVtbl->Advise( m_pIConnectionPoint, pIUnknown, &dwCookie );
            ((MyRealIEventHandler *) selfobj)->pIConnectionPoint = m_pIConnectionPoint;
            ((MyRealIEventHandler *) selfobj)->dwEventCookie = dwCookie;
         }

         pIUnknown->lpVtbl->Release(pIUnknown);
         pIUnknown = NULL;
      }
   }

   if( selfobj )
   {
      pThis = (MyRealIEventHandler *) selfobj;

#ifndef __USEHASHEVENTS
      pThis->pEventsExec = hb_itemNew( hb_param( 4, HB_IT_ANY ) );
#endif

      pThis->pEvents = hb_itemNew( hb_param( 3, HB_IT_ANY ) );
      HB_STORNL2( (LONG_PTR) pThis, 2 );
   }

   HWNDret( hr );
}

//------------------------------------------------------------------------------
HB_FUNC( SHUTDOWNCONNECTIONPOINT )
{
   MyRealIEventHandler *self = ( MyRealIEventHandler * ) HB_PARNL( 1 );
   if( self->pIConnectionPoint )
   {
      self->pIConnectionPoint->lpVtbl->Unadvise( self->pIConnectionPoint, self->dwEventCookie );
      self->dwEventCookie = 0;
      self->pIConnectionPoint->lpVtbl->Release( self->pIConnectionPoint );
      self->pIConnectionPoint = NULL;
   }
}

//------------------------------------------------------------------------------
HB_FUNC( RELEASEDISPATCH )
{
   IDispatch * pObj;
   pObj = ( IDispatch * ) HWNDparam( 1 );
   pObj->lpVtbl->Release( pObj );
}
Exemplo n.º 4
0
Arquivo: math.c Projeto: emazv72/core
/* Harbour default math error handling routine */
static int hb_matherr( HB_MATH_EXCEPTION * pexc )
{
   int mode = hb_mathGetErrMode();
   int iRet = 1;

   HB_TRACE( HB_TR_DEBUG, ( "hb_matherr(%p)", ( void * ) pexc ) );

   if( pexc == NULL || pexc->handled != 0 )
   {
      /* error already handled by other handlers ! */
      return 1;
   }

   if( mode == HB_MATH_ERRMODE_USER || mode == HB_MATH_ERRMODE_USERDEFAULT ||
       mode == HB_MATH_ERRMODE_USERCDEFAULT )
   {
      PHB_ITEM pArg1, pArg2, pError;
      PHB_ITEM pMatherrResult;

      /* create an error object */
      /* NOTE: In case of HB_MATH_ERRMODE_USER[C]DEFAULT, I am setting both
               EF_CANSUBSTITUTE and EF_CANDEFAULT to .T. here.
               This is forbidden according to the original Cl*pper docs, but
               I think this reflects the situation best here:
               The error handler can either substitute the erroneous value
               (by returning a numeric value) or choose the default error
               handling (by returning .F., as usual) [martin vogel] */
      pError = hb_errRT_New_Subst( ES_ERROR, "MATH", EG_NUMERR, pexc->type,
                                   pexc->error, pexc->funcname, 0, EF_CANSUBSTITUTE |
                                   ( mode == HB_MATH_ERRMODE_USER ? 0 : EF_CANDEFAULT ) );

      /* Assign the new array to the object data item. */
      /* NOTE: Unfortunately, we cannot decide whether one or two parameters
               have been used when the math function has been called, so we
               always take two */
      pArg1 = hb_itemPutND( NULL, pexc->arg1 );
      pArg2 = hb_itemPutND( NULL, pexc->arg2 );
      hb_errPutArgs( pError, 2, pArg1, pArg2 );
      hb_itemRelease( pArg1 );
      hb_itemRelease( pArg2 );

      /* launch error codeblock */
      pMatherrResult = hb_errLaunchSubst( pError );
      hb_errRelease( pError );

      if( pMatherrResult )
      {
         if( HB_IS_NUMERIC( pMatherrResult ) )
         {
            pexc->retval = hb_itemGetND( pMatherrResult );
            hb_itemGetNLen( pMatherrResult, &pexc->retvalwidth, &pexc->retvaldec );
            pexc->handled = 1;
         }
         hb_itemRelease( pMatherrResult );
      }
   }

   /* math exception not handled by Harbour error routine above ? */
   if( pexc->handled == 0 )
   {
      switch( mode )
      {
         case HB_MATH_ERRMODE_USER:
            /* user failed to handle the math exception, so quit the app
               [yes, that's the meaning of this mode !!] */
            iRet = 0;
            hb_vmRequestQuit();
            break;

         case HB_MATH_ERRMODE_DEFAULT:
         case HB_MATH_ERRMODE_USERDEFAULT:
            /* return 1 to suppress C RTL error msgs, but leave error
               handling to the calling Harbour routine */
            break;

         case HB_MATH_ERRMODE_CDEFAULT:
         case HB_MATH_ERRMODE_USERCDEFAULT:
            /* use the correction value supplied in pexc->retval */
            pexc->handled = 1;
            break;
      }
   }

   return iRet;  /* error handling successful */
}
Exemplo n.º 5
0
Arquivo: math.c Projeto: emazv72/core
static int hb_matherrblock( HB_MATH_EXCEPTION * pexc )
{
   PHB_MATHERRDATA pMathErr = hb_mathErrData();
   int retval;

   /* call codeblock for both case: handled and unhandled exceptions */

   if( pMathErr->block )
   {
      PHB_ITEM pArray, pRet;
      PHB_ITEM pType, pFuncname, pError, pArg1, pArg2, pRetval, pHandled;
      const char * funcname = pexc->funcname;

      if( funcname == HB_ERR_FUNCNAME )
      {
         PHB_SYMB pSym = hb_itemGetSymbol( hb_stackBaseItem() );
         if( pSym )
            funcname = pSym->szName;
      }

      pType = hb_itemPutNI( NULL, pexc->type );
      pFuncname = hb_itemPutC( NULL, funcname );
      pError = hb_itemPutC( NULL, pexc->error );
      pArg1 = hb_itemPutND( NULL, pexc->arg1 );
      pArg2 = hb_itemPutND( NULL, pexc->arg2 );
      pRetval = hb_itemPutNDLen( NULL, pexc->retval, pexc->retvalwidth, pexc->retvaldec );
      pHandled = hb_itemPutL( NULL, pexc->handled );

      pArray = hb_itemArrayNew( 2 );
      hb_itemArrayPut( pArray, 1, pRetval );
      hb_itemArrayPut( pArray, 2, pHandled );

      /* launch error codeblock that can
         a) change the members of the array = {dRetval, lHandled} to set the
            return value of the math C RTL routine and the <exception handled
            flag> and it
         b) can return an integer value to set the return value of matherr().
         NOTE that these values are only used if lHandled was .F. and is set
         to .T. within the codeblock */
      pRet = hb_itemDo( pMathErr->block, 6, pType, pFuncname, pError, pArg1, pArg2, pArray );

      hb_itemRelease( pType );
      hb_itemRelease( pFuncname );
      hb_itemRelease( pError );
      hb_itemRelease( pArg1 );
      hb_itemRelease( pArg2 );
      hb_itemRelease( pRetval );
      hb_itemRelease( pHandled );

      if( pexc->handled )
      {
         /* math exception has already been handled, so codeblock call above
            was only informative */
         retval = 1;
      }
      else
      {
         /* exception handled by codeblock ? */
         pHandled = hb_itemArrayGet( pArray, 2 );
         if( pHandled )
         {
            pexc->handled = hb_itemGetL( pHandled );
            hb_itemRelease( pHandled );
         }

         if( pexc->handled )
         {
            /* YES ! */
            /* extract retval for math routine and matherr() */
            pRetval = hb_itemArrayGet( pArray, 1 );
            if( pRetval )
            {
               pexc->retval = hb_itemGetND( pRetval );
               hb_itemGetNLen( pRetval, &pexc->retvalwidth, &pexc->retvaldec );
               hb_itemRelease( pRetval );
            }
            if( pRet && HB_IS_NUMERIC( pRet ) )
            {
               retval = hb_itemGetNI( pRet );  /* block may also return 0 to force C math lib warnings */
               hb_itemRelease( pRet );
            }
            else
            {
               retval = 1;  /* default return value to suppress C math lib warnings */
            }
         }
         else
         {
            /* NO ! */
            retval = 1;
         }
      }
      hb_itemRelease( pArray );
   }
   else
   {
      retval = 1;  /* default return value to suppress C math lib warnings */
   }

   if( pMathErr->prevHandler )
   {
      if( pexc->handled )
      {
         /* the error is handled, so simply inform the previous handler */
         ( *pMathErr->prevHandler )( pexc );
      }
      else
      {
         /* else go on error handling within previous handler */
         retval = ( *pMathErr->prevHandler )( pexc );
      }
   }
   return retval;
}
Exemplo n.º 6
0
static HB_UINT SCItm( char * cBuffer, HB_UINT ulMaxBuf, char * cParFrm, int iCOut, int IsIndW,
                      int iIndWidth, int IsIndP, int iIndPrec,
                      PHB_ITEM pItmPar )
{
   HB_UINT s;

   if( IsIndW && IsIndP )
   {
      switch( iCOut )
      {
         case 'p':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iIndWidth, iIndPrec, hb_itemGetPtr( pItmPar ) );
            break;
         case 's': case 'S':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iIndWidth, iIndPrec, hb_itemGetCPtr( pItmPar ) );
            break;
         case 'e': case 'E': case 'f': case 'g': case 'G': case 'a': case 'A':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iIndWidth, iIndPrec, hb_itemGetND( pItmPar ) );
            break;
         /* case 'c': case 'C': case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': */
         default:
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iIndWidth, iIndPrec,
                             HB_IS_LONG( pItmPar ) ? hb_itemGetNL( pItmPar ) : hb_itemGetNI( pItmPar ) );
      }
   }
   else if( IsIndW || IsIndP )
   {
      int iInd = ( IsIndW ? iIndWidth : iIndPrec );

      switch( iCOut )
      {
         case 'p':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iInd, hb_itemGetPtr( pItmPar ) );
            break;
         case 's': case 'S':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iInd, hb_itemGetCPtr( pItmPar ) );
            break;
         case 'e': case 'E': case 'f': case 'g': case 'G': case 'a': case 'A':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iInd, hb_itemGetND( pItmPar ) );
            break;
         /* case 'c': case 'C': case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': */
         default:
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iInd,
                             HB_IS_LONG( pItmPar ) ? hb_itemGetNL( pItmPar ) : hb_itemGetNI( pItmPar ) );
      }
   }
   else
   {
      switch( iCOut )
      {
         case 'p':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, hb_itemGetPtr( pItmPar ) );
            break;
         case 's': case 'S':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, hb_itemGetCPtr( pItmPar ) );
            break;
         case 'e': case 'E': case 'f': case 'g': case 'G': case 'a': case 'A':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, hb_itemGetND( pItmPar ) );
            break;
         /* case 'c': case 'C': case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': */
         default:
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm,
                             HB_IS_LONG( pItmPar ) ? hb_itemGetNL( pItmPar ) : hb_itemGetNI( pItmPar ) );
      }
   }
   return s;
}
Exemplo n.º 7
0
static long hb_i18n_pluralindex( int iForm, PHB_ITEM pNum )
{
   double n = hb_numRound( hb_itemGetND( pNum ), 10 ), n10, n100;

   switch( iForm )
   {
      case HB_I18N_PLURAL_PL:
         n10  = fmod( n, 10.0 );
         n100 = fmod( n, 100.0 );
         return n == 1 ? 1 : ( n10 >= 2 && n10 <= 4 &&
                               ( n100 < 10 || n100 >= 20 ) ? 2 : 3 );

      case HB_I18N_PLURAL_RO:
         n100 = fmod( n, 100.0 );
         return n == 1 ? 1 : ( n == 0 || ( n100 > 0 && n100 < 20 ) ) ? 2 : 3;

      case HB_I18N_PLURAL_HR:
      case HB_I18N_PLURAL_SR:
      case HB_I18N_PLURAL_RU:
      case HB_I18N_PLURAL_UK:
         n10  = fmod( n, 10.0 );
         n100 = fmod( n, 100.0 );
         return n10 == 1 && n100 != 11 ? 1 : n10 >= 2 && n10 <= 4 && ( n100 < 10 || n100 >= 20 ) ? 2 : 3;

      case HB_I18N_PLURAL_CS:
      case HB_I18N_PLURAL_SK:
         return n == 1 ? 1 : ( ( n >= 2 && n <= 4 ) ? 2 : 3 );

      case HB_I18N_PLURAL_SL:
         n100 = fmod( n, 100.0 );
         return n100 == 1 ? 1 : ( n100 == 2 ? 1 : ( n100 == 3 || n100 == 4 ? 3 : 4 ) );

      case HB_I18N_PLURAL_LT:
         n10  = fmod( n, 10.0 );
         n100 = fmod( n, 100.0 );
         return n10 == 1 && n100 != 11 ? 1 : ( n10 != 0 && ( n100 < 10 || n100 >= 20 ) ? 2 : 3 );

      case HB_I18N_PLURAL_LV:
         n10  = fmod( n, 10.0 );
         n100 = fmod( n, 100.0 );
         return ( n10 == 1 && n100 != 11 ) ? 1 : ( n != 0 ? 2 : 3 );

      case HB_I18N_PLURAL_GA:
         return n == 1 ? 1 : ( n == 2 ? 2 : 3 );

      case HB_I18N_PLURAL_JA:
      case HB_I18N_PLURAL_KO:
      case HB_I18N_PLURAL_VI:
      case HB_I18N_PLURAL_TR:
         return 1;

      case HB_I18N_PLURAL_FR:
      case HB_I18N_PLURAL_PT_BR:
         return n <= 1 ? 1 : 2;

      case HB_I18N_PLURAL_EN:
      case HB_I18N_PLURAL_HU:
      default:
         return n == 1 ? 1 : 2;
   }
}
Exemplo n.º 8
0
Arquivo: adsx.c Projeto: SBCamus/core
static HB_ERRCODE adsxOrderInfo( ADSXAREAP pArea, HB_USHORT uiIndex, LPDBORDERINFO pOrderInfo )
{
   PMIXTAG pTag = pArea->pTagCurrent;

   /* resolve any pending relations */
   if( pArea->adsarea.lpdbPendingRel )
      SELF_FORCEREL( ( AREAP ) pArea );

   /* all others need an index handle */
   if( uiIndex != DBOI_ORDERCOUNT )
   {
      if( pOrderInfo->itmOrder )
      {
         if( HB_IS_STRING( pOrderInfo->itmOrder ) )
         {
            pTag = pArea->pTagList;
            while( pTag )
            {
               if( ! hb_stricmp( hb_itemGetCPtr( pOrderInfo->itmOrder ), pTag->szName ) )
                  break;

               pTag = pTag->pNext;
            }
         }
         else if( HB_IS_NUMERIC( pOrderInfo->itmOrder ) )
         {
            UNSIGNED16 usOrder = 0, usSearch = ( UNSIGNED16 ) hb_itemGetNI( pOrderInfo->itmOrder );

            AdsGetNumIndexes( pArea->adsarea.hTable, &usOrder );

            pTag = usSearch <= usOrder ? NULL : pArea->pTagList;
            while( pTag )
            {
               if( ++usOrder == usSearch )
                  break;

               pTag = pTag->pNext;
            }
         }
      }

      if( ! pTag )
         return SUPER_ORDINFO( ( AREAP ) pArea, uiIndex, pOrderInfo );
   }

   switch( uiIndex )
   {
      case DBOI_CONDITION:
         hb_itemPutC( pOrderInfo->itmResult, pTag->szForExpr );
         break;

      case DBOI_EXPRESSION:
         hb_itemPutC( pOrderInfo->itmResult, pTag->szKeyExpr );
         break;

      case DBOI_ISCOND:
         hb_itemPutL( pOrderInfo->itmResult, pTag->pForItem != NULL );
         break;

      case DBOI_ISDESC:
         hb_itemPutL( pOrderInfo->itmResult, HB_FALSE );
         break;

      case DBOI_UNIQUE:
         hb_itemPutL( pOrderInfo->itmResult, HB_FALSE );
         break;

      case DBOI_KEYTYPE:
         hb_itemPutCL( pOrderInfo->itmResult, ( char * ) &pTag->bType, 1 );
         break;

      case DBOI_KEYSIZE:
         hb_itemPutNI( pOrderInfo->itmResult, pTag->uiLen );
         break;

      case DBOI_KEYVAL:
      {
         PHB_ITEM pItem;
         PHB_CODEPAGE pCodepage = hb_cdpSelect( pArea->adsarea.area.cdPage );

         pItem = hb_vmEvalBlockOrMacro( pTag->pKeyItem );
         hb_cdpSelect( pCodepage );
         hb_itemMove( pOrderInfo->itmResult, pItem );
         break;
      }
      case DBOI_KEYCOUNT:
      case DBOI_KEYCOUNTRAW:            /* ignore filter but RESPECT SCOPE */
         hb_itemPutNL( pOrderInfo->itmResult, pTag->ulRecCount );
         break;

      case DBOI_POSITION:
      case DBOI_RECNO:
      case DBOI_KEYNORAW:
         if( uiIndex == DBOI_POSITION && pOrderInfo->itmNewVal && HB_IS_NUMERIC( pOrderInfo->itmNewVal ) )
         {
            HB_ULONG ulPos;

            ulPos = hb_itemGetNL( pOrderInfo->itmNewVal );

            if( ulPos > 0 && ulPos <= pTag->ulRecCount )
               SELF_GOTO( ( AREAP ) pArea, pTag->pKeys[ ulPos - 1 ]->rec );

            pOrderInfo->itmResult = hb_itemPutL( pOrderInfo->itmResult, ! pArea->adsarea.area.fEof );
         }
         else
         {
            PMIXKEY  pKey;
            HB_ULONG ulKeyPos;

            if( ! pArea->adsarea.fPositioned )
               SELF_GOTO( ( AREAP ) pArea, pArea->adsarea.ulRecNo );
            else
               pArea->adsarea.area.fEof = HB_FALSE;

            pKey = mixKeyEval( pTag, pArea );

            hb_itemPutNL( pOrderInfo->itmResult,
                          mixFindKey( pTag, pKey, &ulKeyPos ) ? ( ulKeyPos + 1 ) : 0 );
            mixKeyFree( pKey );
         }
         break;

      case DBOI_RELKEYPOS:
         if( pOrderInfo->itmNewVal && HB_IS_NUMERIC( pOrderInfo->itmNewVal ) )
         {
            HB_ULONG ulPos;

            ulPos = ( HB_ULONG ) ( hb_itemGetND( pOrderInfo->itmNewVal ) * ( double ) pTag->ulRecCount );

            if( ulPos > 0 && ulPos <= pTag->ulRecCount )
               SELF_GOTO( ( AREAP ) pArea, pTag->pKeys[ ulPos - 1 ]->rec );

            pOrderInfo->itmResult = hb_itemPutL( pOrderInfo->itmResult, ! pArea->adsarea.area.fEof );
         }
         else
         {
            PMIXKEY  pKey;
            HB_ULONG ulKeyPos;

            if( ! pArea->adsarea.fPositioned )
               SELF_GOTO( ( AREAP ) pArea, pArea->adsarea.ulRecNo );
            else
               pArea->adsarea.area.fEof = HB_FALSE;

            pKey = mixKeyEval( pTag, pArea );

            if( ! mixFindKey( pTag, pKey, &ulKeyPos + 1 ) )
               ulKeyPos = 0;

            mixKeyFree( pKey );

            pOrderInfo->itmResult = hb_itemPutND( pOrderInfo->itmResult,
                                                  ( double ) ulKeyPos / ( double ) pTag->ulRecCount );
         }
         break;

      case DBOI_NAME:
         hb_itemPutC( pOrderInfo->itmResult, pTag->szName );
         break;

      case DBOI_BAGNAME:
         hb_itemPutC( pOrderInfo->itmResult, NULL );
         break;

      case DBOI_FULLPATH:
         hb_itemPutC( pOrderInfo->itmResult, NULL );
         break;

      case DBOI_BAGEXT:
         hb_itemPutC( pOrderInfo->itmResult, "mix" );
         break;

      case DBOI_ORDERCOUNT:
      {
         UNSIGNED16 usOrder = 0;

         AdsGetNumIndexes( pArea->adsarea.hTable, &usOrder );
         pTag = pArea->pTagList;
         while( pTag )
         {
            pTag = pTag->pNext;
            usOrder++;
         }
         hb_itemPutNI( pOrderInfo->itmResult, ( int ) usOrder );
         break;
      }

      case DBOI_NUMBER:
      {
         PMIXTAG    pTag2;
         UNSIGNED16 usOrder = 0;

         AdsGetNumIndexes( pArea->adsarea.hTable, &usOrder );
         pTag2 = pArea->pTagList;
         usOrder++;
         while( pTag2 && pTag != pTag2 )
         {
            pTag2 = pTag2->pNext;
            usOrder++;
         }
         hb_itemPutNI( pOrderInfo->itmResult, ( int ) usOrder );
         break;
      }

      case DBOI_CUSTOM:
         hb_itemPutL( pOrderInfo->itmResult, HB_FALSE );
         break;

      case DBOI_OPTLEVEL:
         hb_itemPutNI( pOrderInfo->itmResult, DBOI_OPTIMIZED_NONE );
         break;

      case DBOI_KEYADD:
         hb_itemPutL( pOrderInfo->itmResult, HB_FALSE );
         break;

      case DBOI_KEYDELETE:
         hb_itemPutL( pOrderInfo->itmResult, HB_FALSE );
         break;

      case DBOI_AUTOOPEN:
         hb_itemPutL( pOrderInfo->itmResult, HB_FALSE );
         break;

      default:
         return SUPER_ORDINFO( ( AREAP ) pArea, uiIndex, pOrderInfo );
   }
   return HB_SUCCESS;
}