Пример #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
static HB_BOOL hb_i18n_getpluralform( PHB_I18N_TRANS pI18N, PHB_ITEM pOldForm,
                                      HB_BOOL fBase )
{
   HB_BOOL fResult = HB_FALSE;

   if( pI18N )
   {
      if( pOldForm )
      {
         PHB_ITEM pBlock;
         int iForm;

         if( fBase )
         {
            pBlock = pI18N->base_plural_block;
            iForm = pI18N->base_plural_form;
         }
         else
         {
            pBlock = pI18N->plural_block;
            iForm = pI18N->plural_form;
         }

         if( pBlock )
            hb_itemCopy( pOldForm, pBlock );
         else if( iForm )
            hb_itemPutC( pOldForm, hb_i18n_pluralformid( iForm ) );
         else
            hb_itemPutCConst( pOldForm, "EN" ); /* default is ENGLISH */
      }
      fResult = HB_TRUE;
   }
   return fResult;
}
Пример #3
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;
}
Пример #4
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;
}
Пример #5
0
static PHB_I18N_TRANS hb_i18n_new( void )
{
   PHB_I18N_TRANS pI18N;
   PHB_ITEM pKey;

   pI18N = ( PHB_I18N_TRANS ) hb_xgrabz( sizeof( HB_I18N_TRANS ) );
   hb_atomic_set( &pI18N->iUsers, 1 );
   pI18N->table = hb_hashNew( hb_itemNew( NULL ) );
   pI18N->context_table = hb_hashNew( hb_itemNew( NULL ) );
   pI18N->default_context = hb_hashNew( hb_itemNew( NULL ) );
   pKey = hb_itemPutCConst( NULL, "CONTEXT" );
   hb_hashAdd( pI18N->table, pKey, pI18N->context_table );
   pKey = hb_itemPutC( pKey, NULL );
   hb_hashAdd( pI18N->context_table, pKey, pI18N->default_context );
   hb_itemRelease( pKey );

   return pI18N;
}
Пример #6
0
static amqp_response_type_enum s_process_response( int iParam, amqp_rpc_reply_t x )
{
   if( HB_ISBYREF( iParam ) )
   {
      PHB_ITEM hResponse = hb_hashNew( NULL );

      PHB_ITEM pKey = hb_itemNew( NULL );
      PHB_ITEM pVal = hb_itemNew( NULL );

      char szName[ HB_SYMBOL_NAME_LEN + HB_SYMBOL_NAME_LEN + 5 ];

      hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "cAPI" ), hb_itemPutC( pVal, hb_procname( 0, szName, HB_FALSE ) ) );
      hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReplyType" ), hb_itemPutNI( pVal, ( int ) x.reply_type ) );
      hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nLibraryError" ), hb_itemPutNI( pVal, x.library_error ) );
      hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "cLibraryError" ), hb_itemPutC( pVal, amqp_error_string2( x.library_error ) ) );

      switch( x.reply_type )
      {
         case AMQP_RESPONSE_NORMAL:
            /* fallthrough */
         case AMQP_RESPONSE_LIBRARY_EXCEPTION:
            /* fallthrough */
         case AMQP_RESPONSE_NONE:
            break;
         case AMQP_RESPONSE_SERVER_EXCEPTION:

            hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReplyID" ), hb_itemPutNI( pVal, ( int ) x.reply.id ) );

            switch( x.reply.id )
            {
               case AMQP_CONNECTION_CLOSE_METHOD:
               {
                  amqp_connection_close_t * m = ( amqp_connection_close_t * ) x.reply.decoded;
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_Code" ), hb_itemPutNL( pVal, ( long ) m->reply_code ) );
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_Text" ), hb_itemPutCL( pVal, m->reply_text.bytes, m->reply_text.len ) );
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_ClassID" ), hb_itemPutNL( pVal, ( long ) m->class_id ) );
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_MethodID" ), hb_itemPutNL( pVal, ( long ) m->method_id ) );
                  break;
               }
               case AMQP_CHANNEL_CLOSE_METHOD:
               {
                  amqp_channel_close_t * m = ( amqp_channel_close_t * ) x.reply.decoded;
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_Code" ), hb_itemPutNL( pVal, ( long ) m->reply_code ) );
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_Text" ), hb_itemPutCL( pVal, m->reply_text.bytes, m->reply_text.len ) );
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_ClassID" ), hb_itemPutNL( pVal, ( long ) m->class_id ) );
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_MethodID" ), hb_itemPutNL( pVal, ( long ) m->method_id ) );
                  break;
               }
            }
            break;
      }

      if( ! hb_itemParamStoreRelease( iParam, hResponse ) )
         hb_itemRelease( hResponse );

      hb_itemRelease( pVal );
      hb_itemRelease( pKey );
   }

   return x.reply_type;
}