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; }
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 ); }
static const char * _hb_jsonDecode( const char * szSource, PHB_ITEM pValue ) { if( *szSource == '\"' ) { char * szDest, * szHead; HB_SIZE nAlloc = 16; szHead = szDest = ( char * ) hb_xgrab( nAlloc ); szSource++; while( *szSource != '\"' ) { if( szHead + 6 >= szDest + nAlloc ) { HB_SIZE nLen = szHead - szDest; nAlloc += nAlloc << 1; szDest = ( char * ) hb_xrealloc( szDest, nAlloc ); szHead = szDest + nLen; } if( *szSource == '\\' ) { szSource++; switch( *szSource ) { case '\"': *szHead++ = '\"'; break; case '\\': *szHead++ = '\\'; break; case '/': *szHead++ = '/'; break; case 'b': *szHead++ = '\b'; break; case 'f': *szHead++ = '\f'; break; case 'n': *szHead++ = '\n'; break; case 'r': *szHead++ = '\r'; break; case 't': *szHead++ = '\t'; break; case 'u': { HB_WCHAR wc = 0; int i; for( i = 0; i < 4; i++ ) { char c = *++szSource; wc <<= 4; if( c >= '0' && c <= '9' ) wc += c - '0'; else if( c >= 'A' && c <= 'F' ) wc += c - 'A' + 10; else if( c >= 'a' && c <= 'f' ) wc += c - 'a' + 10; else { hb_xfree( szDest ); return NULL; } } szHead += hb_cdpU16ToStr( hb_vmCDP(), HB_CDP_ENDIAN_NATIVE, &wc, 1, szHead, szDest + nAlloc - szHead ); break; } default: hb_xfree( szDest ); return NULL; } szSource++; } else if( *( const unsigned char * ) szSource >= ' ' ) *szHead++ = *szSource++; else { hb_xfree( szDest ); return NULL; } } hb_itemPutCL( pValue, szDest, szHead - szDest ); hb_xfree( szDest ); return szSource + 1; } else if( *szSource == '-' || ( *szSource >= '0' && *szSource <= '9' ) ) { /* NOTE: this function is much less strict to number format than JSON syntax definition. This is allowed behaviour [Mindaugas] */ HB_MAXINT nValue = 0; double dblValue = 0; HB_BOOL fNeg, fDbl = HB_FALSE; int iDec = 0; fNeg = *szSource == '-'; if( fNeg ) szSource++; while( *szSource >= '0' && *szSource <= '9' ) { nValue = nValue * 10 + *szSource - '0'; szSource++; } if( *szSource == '.' ) { double mult = 1; dblValue = ( double ) nValue; fDbl = HB_TRUE; szSource++; while( *szSource >= '0' && *szSource <= '9' ) { mult /= 10; dblValue += ( ( double ) ( *szSource - '0' ) ) * mult; szSource++; iDec++; } } if( *szSource == 'e' || *szSource == 'E' ) { HB_BOOL fNegExp; int iExp = 0; szSource++; fNegExp = *szSource == '-'; if( fNegExp ) szSource++; while( *szSource >= '0' && *szSource <= '9' ) { iExp = iExp * 10 + *szSource - '0'; szSource++; } if( ! fDbl ) { dblValue = ( double ) nValue; fDbl = HB_TRUE; } if( fNegExp ) iDec += iExp; dblValue = hb_numExpConv( dblValue, fNegExp ? iExp : -iExp ); } if( fDbl ) hb_itemPutNDDec( pValue, hb_numRound( fNeg ? -dblValue : dblValue, iDec ), iDec ); else hb_itemPutNInt( pValue, fNeg ? -nValue : nValue ); return szSource; } else if( ! strncmp( szSource, "null", 4 ) ) { hb_itemClear( pValue ); return szSource + 4; } else if( ! strncmp( szSource, "true", 4 ) ) { hb_itemPutL( pValue, HB_TRUE ); return szSource + 4; } else if( ! strncmp( szSource, "false", 5 ) ) { hb_itemPutL( pValue, HB_FALSE ); return szSource + 5; } else if( *szSource == '[' ) { hb_arrayNew( pValue, 0 ); szSource = _skipws( szSource + 1 ); if( *szSource != ']' ) { PHB_ITEM pItem = hb_itemNew( NULL ); for( ;; ) { szSource = _hb_jsonDecode( szSource, pItem ); if( ! szSource ) { hb_itemRelease( pItem ); return NULL; } hb_arrayAddForward( pValue, pItem ); szSource = _skipws( szSource ); if( *szSource == ',' ) { szSource = _skipws( szSource + 1 ); continue; } else if( *szSource == ']' ) break; else { hb_itemRelease( pItem ); return NULL; } } hb_itemRelease( pItem ); } return szSource + 1; } else if( *szSource == '{' ) { hb_hashNew( pValue ); szSource = _skipws( szSource + 1 ); if( *szSource != '}' ) { PHB_ITEM pItemKey = hb_itemNew( NULL ); PHB_ITEM pItemValue = hb_itemNew( NULL ); for( ;; ) { /* Do we need to check if key does not exist yet? */ if( ( szSource = _hb_jsonDecode( szSource, pItemKey ) ) == NULL || ! HB_IS_STRING( pItemKey ) || * ( szSource = _skipws( szSource ) ) != ':' || ( szSource = _hb_jsonDecode( _skipws( szSource + 1 ), pItemValue ) ) == NULL) { hb_itemRelease( pItemKey ); hb_itemRelease( pItemValue ); return NULL; } hb_hashAdd( pValue, pItemKey, pItemValue ); szSource = _skipws( szSource ); if( *szSource == ',' ) { szSource = _skipws( szSource + 1 ); continue; } else if( *szSource == '}' ) break; else { hb_itemRelease( pItemKey ); hb_itemRelease( pItemValue ); return NULL; } } hb_itemRelease( pItemKey ); hb_itemRelease( pItemValue ); } return szSource + 1; } return NULL; }
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; }