Пример #1
0
static const char * hb_i18n_description( PHB_I18N_TRANS pI18N, PHB_ITEM pItem )
{
   if( pI18N )
   {
      PHB_ITEM pKey = hb_itemPutCConst( NULL, "DESCRIPTION" ), pValue;

      pValue = hb_hashGetItemPtr( pI18N->table, pKey, 0 );
      if( pItem )
      {
         if( HB_IS_STRING( pItem ) )
         {
            if( pValue )
               hb_itemCopy( pValue, pItem );
            else
            {
               hb_hashAdd( pI18N->table, pKey, pItem );
               pValue = hb_hashGetItemPtr( pI18N->table, pKey, 0 );
            }
         }
      }
      hb_itemRelease( pKey );

      return hb_itemGetCPtr( pValue );
   }

   return NULL;
}
Пример #2
0
PHB_ITEM hb_i18n_gettext( PHB_ITEM pMsgID, PHB_ITEM pContext )
{
   PHB_I18N_TRANS pI18N = hb_i18n_table();
   PHB_CODEPAGE cdpage = NULL;
   PHB_ITEM pMsgDst = pMsgID;

   if( pI18N )
   {
      PHB_ITEM pTable = pContext && pI18N->context_table ?
                        hb_hashGetItemPtr( pI18N->context_table, pContext, 0 ) :
                        pI18N->default_context;

      cdpage = pI18N->base_cdpage;
      if( pTable )
      {
         pTable = hb_hashGetItemPtr( pTable, pMsgID, 0 );
         if( pTable )
         {
            if( HB_IS_ARRAY( pTable ) )
               pTable = hb_arrayGetItemPtr( pTable, 1 );
            if( pTable && HB_IS_STRING( pTable ) )
            {
               pMsgID = pTable;
               cdpage = pI18N->cdpage;
            }
         }
      }
   }

   if( pMsgID )
   {
      if( HB_IS_STRING( pMsgID ) )
      {
         if( cdpage )
         {
            PHB_CODEPAGE cdp = hb_vmCDP();
            if( cdp && cdp != cdpage )
            {
               if( pMsgDst != pMsgID )
               {
                  hb_itemCopy( pMsgDst, pMsgID );
                  pMsgID = pMsgDst;
               }
               hb_i18n_transitm( pMsgID, cdpage, cdp );
            }
         }
      }
      else
         pMsgID = NULL;
   }

   return pMsgID;
}
Пример #3
0
static PHB_I18N_TRANS hb_i18n_initialize( PHB_ITEM pTable )
{
   PHB_I18N_TRANS pI18N = NULL;

   if( HB_IS_HASH( pTable ) )
   {
      PHB_ITEM pKey, pContext, pDefContext = NULL, pValue;

      pKey = hb_itemPutCConst( NULL, "CONTEXT" );
      pContext = hb_hashGetItemPtr( pTable, pKey, 0 );
      if( pContext )
      {
         pKey = hb_itemPutC( pKey, NULL );
         pDefContext = hb_hashGetItemPtr( pContext, pKey, 0 );
      }

      if( pContext && pDefContext )
      {
         pI18N = ( PHB_I18N_TRANS ) hb_xgrabz( sizeof( HB_I18N_TRANS ) );
         hb_atomic_set( &pI18N->iUsers, 1 );
         pI18N->table = pTable;
         pI18N->context_table = hb_itemNew( pContext );
         pI18N->default_context = hb_itemNew( pDefContext );

         pKey = hb_itemPutCConst( pKey, "BASE_CODEPAGE" );
         pValue = hb_hashGetItemPtr( pTable, pKey, 0 );
         if( pValue )
            pI18N->base_cdpage = hb_cdpFind( hb_itemGetCPtr( pValue ) );

         pKey = hb_itemPutCConst( pKey, "CODEPAGE" );
         pValue = hb_hashGetItemPtr( pTable, pKey, 0 );
         if( pValue )
            pI18N->cdpage = hb_cdpFind( hb_itemGetCPtr( pValue ) );

         pKey = hb_itemPutCConst( pKey, "BASE_LANG" );
         pValue = hb_hashGetItemPtr( pTable, pKey, 0 );
         if( pValue )
            pI18N->base_plural_form = hb_i18n_pluralformfind( hb_itemGetCPtr( pValue ) );

         pKey = hb_itemPutCConst( pKey, "LANG" );
         pValue = hb_hashGetItemPtr( pTable, pKey, 0 );
         if( pValue )
            pI18N->plural_form = hb_i18n_pluralformfind( hb_itemGetCPtr( pValue ) );

         pKey = hb_itemPutCConst( pKey, "BASE_PLURAL_EXP" );
         pValue = hb_hashGetItemPtr( pTable, pKey, 0 );
         if( pValue )
            pI18N->base_plural_block = hb_i18n_pluralexp_compile( pValue );

         pKey = hb_itemPutCConst( pKey, "PLURAL_EXP" );
         pValue = hb_hashGetItemPtr( pTable, pKey, 0 );
         if( pValue )
            pI18N->plural_block = hb_i18n_pluralexp_compile( pValue );
      }
      hb_itemRelease( pKey );
   }

   return pI18N;
}
Пример #4
0
static PHB_ITEM hb_i18n_serialize( PHB_I18N_TRANS pI18N )
{
   if( pI18N )
   {
      HB_SIZE nSize;
      HB_U32 ulCRC;
      char * pBuffer = hb_itemSerialize( pI18N->table, 0, &nSize );
      char * pI18Nbuffer;
      PHB_ITEM pKey, pValue;

      ulCRC = hb_crc32( 0, pBuffer, nSize );
      pI18Nbuffer = ( char * ) memset( hb_xgrab( nSize + HB_I18N_HEADER_SIZE + 1 ),
                                       0, HB_I18N_HEADER_SIZE );
      memcpy( pI18Nbuffer + HB_I18N_HEADER_SIZE, pBuffer, nSize );
      hb_xfree( pBuffer );

      memcpy( pI18Nbuffer, s_signature, HB_I18N_SIG_SIZE );
      HB_PUT_LE_UINT32( &pI18Nbuffer[ HB_I18N_SIZE_OFFSET ], nSize );
      HB_PUT_LE_UINT32( &pI18Nbuffer[ HB_I18N_CRC_OFFSET ], ulCRC );

      pKey = hb_itemPutCConst( NULL, "DESCRIPTION" );
      pValue = hb_hashGetItemPtr( pI18N->table, pKey, 0 );
      if( pValue )
         hb_strncpy( &pI18Nbuffer[ HB_I18N_TXT_OFFSET ],
                     hb_itemGetCPtr( pValue ), HB_I18N_TXT_SIZE );

      return hb_itemPutCLPtr( pKey, pI18Nbuffer, nSize + HB_I18N_HEADER_SIZE );
   }

   return NULL;
}
Пример #5
0
static HB_BOOL amf3_decode_reference( PHB_ITEM pHash, int val, PHB_ITEM pRefItem )
{
   /* Check for index reference */
   if( ( val & REFERENCE_BIT ) == 0 )
   {
      PHB_ITEM pKey = hb_itemNew( NULL );
      hb_itemPutNI( pKey, val >> 1 );

      pRefItem = hb_hashGetItemPtr( pHash, pKey, 0 );

      hb_itemRelease( pKey );
      return HB_TRUE;
   }
Пример #6
0
static void hb_i18n_addtext( PHB_I18N_TRANS pI18N, PHB_ITEM pMsgID,
                             PHB_ITEM pTrans, PHB_ITEM pContext )
{
   PHB_ITEM pTable = pContext ? hb_hashGetItemPtr( pI18N->context_table,
                                       pContext, 0 ) : pI18N->default_context;

   if( ! pTable )
   {
      pTable = hb_hashNew( hb_itemNew( NULL ) );
      hb_hashAdd( pTable, pMsgID, pTrans );
      hb_hashAdd( pI18N->context_table, pContext, pTable );
      hb_itemRelease( pTable );
   }
   else
      hb_hashAdd( pTable, pMsgID, pTrans );
}
Пример #7
0
static HRESULT STDMETHODCALLTYPE Invoke( IDispatch * lpThis, DISPID dispid, REFIID riid,
                                         LCID lcid, WORD wFlags, DISPPARAMS * pParams,
                                         VARIANT * pVarResult, EXCEPINFO * pExcepInfo,
                                         UINT * puArgErr )
{
   PHB_ITEM pAction;
   HRESULT hr;

   HB_SYMBOL_UNUSED( lcid );
   HB_SYMBOL_UNUSED( wFlags );
   HB_SYMBOL_UNUSED( pExcepInfo );
   HB_SYMBOL_UNUSED( puArgErr );

   if( ! IsEqualIID( riid, HB_ID_REF( IID_NULL ) ) )
      return DISP_E_UNKNOWNINTERFACE;

   hr = DISP_E_MEMBERNOTFOUND;

   pAction = ( ( ISink * ) lpThis )->pItemHandler;
   if( pAction )
   {
      PHB_ITEM pKey = hb_itemPutNL( hb_stackAllocItem(), ( long ) dispid );

      if( pAction && HB_IS_HASH( pAction ) )
      {
         pAction = hb_hashGetItemPtr( pAction, pKey, 0 );
         pKey = NULL;
      }

      if( pAction && hb_oleDispInvoke( NULL, pAction, pKey,
                                       pParams, pVarResult, NULL,
                                       ( ( ISink * ) lpThis )->uiClass ) )
         hr = S_OK;

      hb_stackPop();
   }

   return hr;
}
Пример #8
0
static HRESULT STDMETHODCALLTYPE Invoke( IDispatch * lpThis, DISPID dispid, REFIID riid,
                                         LCID lcid, WORD wFlags, DISPPARAMS * pParams,
                                         VARIANT * pVarResult, EXCEPINFO * pExcepInfo,
                                         UINT * puArgErr )
{
   PHB_DYNS pDynSym;
   PHB_ITEM pAction;
   HB_USHORT uiClass = 0;

   HB_SYMBOL_UNUSED( lcid );
   HB_SYMBOL_UNUSED( pExcepInfo );
   HB_SYMBOL_UNUSED( puArgErr );

   if( ! IsEqualIID( riid, HB_ID_REF( IID_NULL ) ) )
      return DISP_E_UNKNOWNINTERFACE;

   pAction = ( ( IHbOleServer * ) lpThis )->pAction;
   if( ! pAction )
      pAction = s_pAction;

   if( pAction )
   {
      HB_BOOL fResult = HB_FALSE;

      if( s_pMsgHash )
      {
         if( ( wFlags & DISPATCH_METHOD ) != 0 ||
             ( ( wFlags & DISPATCH_PROPERTYGET ) != 0 && pParams->cArgs == 0 ) ||
             ( ( wFlags & DISPATCH_PROPERTYPUT ) != 0 && pParams->cArgs == 1 ) )
         {
            fResult = hb_oleDispInvoke( NULL, pAction,
                                        hb_hashGetKeyAt( s_pMsgHash, ( HB_SIZE ) dispid ),
                                        pParams, pVarResult, s_objItemToVariant, uiClass );
         }
      }
      else if( HB_IS_HASH( pAction ) )
      {
         PHB_ITEM pItem;

         if( ( ( IHbOleServer * ) lpThis )->fGuids )
         {
            PHB_ITEM pKey = hb_itemPutNL( hb_stackAllocItem(), ( long ) dispid );
            pItem = hb_hashGetItemPtr( pAction, pKey, 0 );
            hb_stackPop();
         }
         else
            pItem = hb_hashGetValueAt( pAction, ( HB_SIZE ) dispid );

         if( pItem )
         {
            if( HB_IS_EVALITEM( pItem ) )
            {
               if( ( wFlags & DISPATCH_METHOD ) != 0 )
               {
                  PHB_SYMB pSym = hb_itemGetSymbol( pItem );
                  fResult = hb_oleDispInvoke( pSym, pSym ? pAction : pItem, NULL,
                                              pParams, pVarResult,
                                              s_objItemToVariant, uiClass );
               }
            }
            else if( ( wFlags & DISPATCH_PROPERTYGET ) != 0 &&
                     pParams->cArgs == 0 )
            {
               if( pVarResult )
                  hb_oleItemToVariantEx( pVarResult, pItem, s_objItemToVariant );
               fResult = HB_TRUE;
            }
            else if( ( wFlags & DISPATCH_PROPERTYPUT ) != 0 &&
                     pParams->cArgs == 1 )
            {
               hb_oleVariantToItemEx( pItem, &pParams->rgvarg[ 0 ], uiClass );
               fResult = HB_TRUE;
            }
         }
      }
      else if( HB_IS_OBJECT( pAction ) )
      {
         pDynSym = hb_dispIdToDynsym( dispid );
         if( pDynSym && ( wFlags & DISPATCH_PROPERTYPUT ) != 0 )
         {
            if( pParams->cArgs == 1 )
            {
               char szName[ HB_SYMBOL_NAME_LEN + 1 ];
               szName[ 0 ] = '_';
               hb_strncpy( szName + 1, hb_dynsymName( pDynSym ), sizeof( szName ) - 2 );
               pDynSym = hb_dynsymFindName( szName );
            }
            else
               pDynSym = NULL;
         }
         if( pDynSym && hb_objHasMessage( pAction, pDynSym ) )
         {
            fResult = hb_oleDispInvoke( hb_dynsymSymbol( pDynSym ),
                                        pAction, NULL, pParams, pVarResult,
                                        s_objItemToVariant, uiClass );
         }
      }
      if( ! fResult )
         return DISP_E_MEMBERNOTFOUND;
   }
   else
   {
      pDynSym = hb_dispIdToDynsym( dispid );
      if( ! pDynSym )
         return DISP_E_MEMBERNOTFOUND;

      if( wFlags & DISPATCH_PROPERTYPUT )
      {
         if( pParams->cArgs == 1 && hb_dynsymIsMemvar( pDynSym ) )
         {
            PHB_ITEM pItem = hb_stackAllocItem();

            hb_oleVariantToItemEx( pItem, &pParams->rgvarg[ 0 ], uiClass );
            hb_memvarSetValue( hb_dynsymSymbol( pDynSym ), pItem );
            hb_stackPop();
            return S_OK;
         }
         else
            return DISP_E_MEMBERNOTFOUND;
      }
      else if( ( wFlags & DISPATCH_PROPERTYGET ) &&
               pParams->cArgs == 0 && hb_dynsymIsMemvar( pDynSym ) )
      {
         if( pVarResult )
         {
            PHB_ITEM pItem = hb_stackAllocItem();
            hb_memvarGet( pItem, hb_dynsymSymbol( pDynSym ) );
            hb_oleItemToVariantEx( pVarResult, pItem, s_objItemToVariant );
            hb_stackPop();
         }
         return S_OK;
      }
      else if( ( wFlags & DISPATCH_METHOD ) == 0 ||
               ! hb_dynsymIsFunction( pDynSym ) )
         return DISP_E_MEMBERNOTFOUND;
      else if( ! hb_oleDispInvoke( hb_dynsymSymbol( pDynSym ),
                                   NULL, NULL, pParams, pVarResult,
                                   s_objItemToVariant, uiClass ) )
         return DISP_E_MEMBERNOTFOUND;
   }

   return S_OK;
}
Пример #9
0
PHB_ITEM hb_i18n_ngettext( PHB_ITEM pNum, PHB_ITEM pMsgID, PHB_ITEM pContext )
{
   PHB_I18N_TRANS pI18N = hb_i18n_table();
   PHB_CODEPAGE cdpage = NULL;
   PHB_ITEM pMsgDst = pMsgID;
   PHB_ITEM pBlock = NULL;
   int iPluralForm = 0;

   if( pI18N )
   {
      PHB_ITEM pTable = pContext && pI18N->context_table ?
                        hb_hashGetItemPtr( pI18N->context_table, pContext, 0 ) :
                        pI18N->default_context;

      cdpage = pI18N->base_cdpage;
      pBlock = pI18N->base_plural_block;
      iPluralForm = pI18N->base_plural_form;

      if( pTable )
      {
         PHB_ITEM pMsg = HB_IS_ARRAY( pMsgID ) ?
                         hb_arrayGetItemPtr( pMsgID, 1 ) : pMsgID;
         pTable = pMsg && HB_IS_STRING( pMsg ) ?
                  hb_hashGetItemPtr( pTable, pMsg, 0 ) : NULL;
         if( pTable )
         {
            if( HB_IS_STRING( pTable ) ||
                ( HB_IS_ARRAY( pTable ) &&
                  ( hb_arrayGetType( pTable, 1 ) & HB_IT_STRING ) != 0 ) )
            {
               pMsgID = pTable;
               cdpage = pI18N->cdpage;
               pBlock = pI18N->plural_block;
               iPluralForm = pI18N->plural_form;
            }
         }
      }
   }

   if( pMsgID && HB_IS_ARRAY( pMsgID ) )
   {
      long lIndex;

      if( ! pNum )
         lIndex = 1;
      else if( pBlock )
      {
         hb_evalBlock1( pBlock, pNum );
         lIndex = hb_parnl( -1 );
      }
      else
         lIndex = hb_i18n_pluralindex( iPluralForm, pNum );

      if( lIndex < 1 || ( lIndex != 1 &&
            ( hb_arrayGetType( pMsgID, lIndex ) & HB_IT_STRING ) == 0 ) )
         lIndex = 1;

      pMsgID = hb_arrayGetItemPtr( pMsgID, lIndex );
   }

   if( pMsgID )
   {
      if( HB_IS_STRING( pMsgID ) )
      {
         if( cdpage )
         {
            PHB_CODEPAGE cdp = hb_vmCDP();
            if( cdp && cdp != cdpage )
            {
               if( pMsgDst != pMsgID )
               {
                  hb_itemCopy( pMsgDst, pMsgID );
                  pMsgID = pMsgDst;
               }
               hb_i18n_transitm( pMsgID, cdpage, cdp );
            }
         }
      }
      else
         pMsgID = NULL;
   }

   return pMsgID;
}