Ejemplo n.º 1
0
static LPTSTR s_StringList( int iParam )
{
   PHB_ITEM pItem = hb_param( iParam, HB_IT_ARRAY | HB_IT_STRING ), pArrItem;
   LPTSTR lpStr = NULL;

   if( pItem )
   {
      HB_SIZE nLen, nSize, nTotal, n, n1;

      if( HB_IS_ARRAY( pItem ) )
      {
         nSize = hb_arrayLen( pItem );
         for( n = nLen = 0; n < nSize; ++n )
         {
            pArrItem = hb_arrayGetItemPtr( pItem, n + 1 );
            if( HB_IS_STRING( pArrItem ) )
            {
               n1 = HB_ITEMCOPYSTR( pArrItem, NULL, 0 );
               if( n1 )
                  nLen += n1 + 1;
            }
         }
         if( nLen )
         {
            nTotal = nLen + 1;
            lpStr = ( LPTSTR ) hb_xgrab( nTotal * sizeof( TCHAR ) );
            for( n = nLen = 0; n < nSize; ++n )
            {
               pArrItem = hb_arrayGetItemPtr( pItem, n + 1 );
               if( HB_IS_STRING( pArrItem ) )
               {
                  n1 = HB_ITEMCOPYSTR( pArrItem,
                                       lpStr + nLen, nTotal - nLen );
                  if( n1 )
                     nLen += n1 + 1;
               }
            }
            lpStr[ nLen ] = 0;
         }
      }
      else
      {
         nLen = HB_ITEMCOPYSTR( pItem, NULL, 0 );
         if( nLen )
         {
            lpStr = ( LPTSTR ) hb_xgrab( ( nLen + 1 ) * sizeof( TCHAR ) );
            HB_ITEMCOPYSTR( pItem, lpStr, nLen );
            lpStr[ nLen ] = 0;
         }
      }
   }

   return lpStr;
}
Ejemplo n.º 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;
}
Ejemplo n.º 3
0
int hb_sockexSelect( PHB_ITEM pArrayRD, HB_BOOL fSetRD,
                     PHB_ITEM pArrayWR, HB_BOOL fSetWR,
                     PHB_ITEM pArrayEX, HB_BOOL fSetEX,
                     HB_MAXINT timeout, HB_SOCKET_FUNC pFunc )
{
   int iResult;
   HB_SIZE nRead = 0, nWrite = 0, nLen, nPos;
   PHB_SOCKEX pSock;

   if( pArrayRD )
   {
      nLen = hb_arrayLen( pArrayRD );
      for( nPos = 1; nPos <= nLen; ++nPos )
      {
         pSock = hb_sockexItemGet( hb_arrayGetItemPtr( pArrayRD, nPos ) );
         if( pSock && pSock->pFilter->CanRead( pSock, HB_TRUE, 0 ) > 0 )
         {
            ++nRead;
            if( fSetRD && nRead != nPos )
               hb_itemMove( hb_arrayGetItemPtr( pArrayRD, nRead ),
                            hb_arrayGetItemPtr( pArrayRD, nPos ) );
         }
      }
   }
   if( pArrayWR )
   {
      nLen = hb_arrayLen( pArrayWR );
      for( nPos = 1; nPos <= nLen; ++nPos )
      {
         pSock = hb_sockexItemGet( hb_arrayGetItemPtr( pArrayWR, nPos ) );
         if( pSock && pSock->pFilter->CanWrite( pSock, HB_TRUE, 0 ) > 0 )
         {
            ++nWrite;
            if( fSetWR && nWrite != nPos )
               hb_itemMove( hb_arrayGetItemPtr( pArrayWR, nWrite ),
                            hb_arrayGetItemPtr( pArrayWR, nPos ) );
         }
      }
   }

   if( nRead > 0 || nWrite > 0 )
   {
      if( fSetRD && pArrayRD )
         hb_arraySize( pArrayRD, nRead );
      if( fSetWR && pArrayWR )
         hb_arraySize( pArrayWR, nWrite );
      if( fSetEX && pArrayEX )
         hb_arraySize( pArrayEX, 0 );
      iResult = ( int ) ( nRead + nWrite );
   }
   else
   {
      if( pFunc == NULL )
         pFunc = s_socketSelectCallback;
      iResult = hb_socketSelect( pArrayRD, fSetRD, pArrayWR, fSetWR, pArrayEX, fSetEX,
                                 timeout, pFunc );
   }

   return iResult;
}
Ejemplo n.º 4
0
void hb_tblStructure( AREAP pArea, PHB_ITEM pStruct, HB_USHORT uiSize )
{
   HB_USHORT uiFields, uiCount;

   if( SELF_FIELDCOUNT( pArea, &uiFields ) == HB_SUCCESS )
   {
      if( hb_arraySize( pStruct, uiFields ) )
      {
         for( uiCount = 1; uiCount <= uiFields; ++uiCount )
            hb_fldStructure( pArea, uiCount, uiSize,
                             hb_arrayGetItemPtr( pStruct, uiCount ) );
      }
   }
}
Ejemplo n.º 5
0
/* This function creates an array item using 'iDimension' as an index
 * to retrieve the number of elements from the parameter list.
 */
static void hb_arrayNewRagged( PHB_ITEM pArray, int iDimension )
{
   HB_SIZE nElements;

   HB_TRACE( HB_TR_DEBUG, ( "hb_arrayNewRagged(%p, %d)", pArray, iDimension ) );

   nElements = hb_parns( iDimension );

   /* create an array */
   hb_arrayNew( pArray, nElements );

   if( ++iDimension <= hb_pcount() )
   {
      /* call self recursively to create next dimensions
       */
      while( nElements )
         hb_arrayNewRagged( hb_arrayGetItemPtr( pArray, nElements-- ), iDimension );
   }
}
Ejemplo n.º 6
0
static const char * hb_dbTransFieldPos( PHB_ITEM pFields, HB_USHORT uiField )
{
   const char * szField = NULL;
   PHB_ITEM pItem;

   pItem = hb_arrayGetItemPtr( pFields, uiField );
   if( pItem )
   {
      if( HB_IS_ARRAY( pItem ) )
         szField = hb_arrayGetCPtr( pItem, DBS_NAME );
      else
         szField = hb_itemGetCPtr( pItem );

      if( *szField == '\0' )
         szField = NULL;
   }

   return szField;
}
Ejemplo n.º 7
0
HB_EXPORT HB_FOFFSET hb_fileSizeGet( const char * pszFileName, HB_BOOL bUseDirEntry )
{
   int i = s_fileFindDrv( pszFileName );

   if( i >= 0 )
   {
      HB_ERRCODE uiError;
      HB_FOFFSET nSize = 0;

      if( bUseDirEntry )
      {
         PHB_ITEM pDir = hb_fileDirectory( pszFileName, "HS" );

         uiError = hb_fsError();
         if( pDir )
         {
            PHB_ITEM pEntry = hb_arrayGetItemPtr( pDir, 1 );

            if( pEntry )
               nSize = hb_arrayGetNInt( pEntry, F_SIZE );
            hb_itemRelease( pDir );
         }
      }
      else
      {
         PHB_FILE pFile = hb_fileExtOpen( pszFileName, NULL, FO_READ | FO_COMPAT, NULL, NULL );
         if( pFile )
         {
            nSize = hb_fileSize( pFile );
            uiError = hb_fsError();
            hb_fileClose( pFile );
         }
         else
            uiError = hb_fsError();
      }
      hb_fsSetFError( uiError );

      return nSize;
   }

   return hb_fsFSize( pszFileName, bUseDirEntry );
}
Ejemplo n.º 8
0
/*
 * Add <pItem> to array <pReturn> at pos <uiPos>
 * AddToArray( <pItem>, <pReturn>, <uiPos> )
 */
static void AddToArray( PHB_ITEM pItem, PHB_ITEM pReturn, HB_SIZE nPos )
{
   HB_TRACE( HB_TR_DEBUG, ( "AddToArray(%p, %p, %" HB_PFS "u)", pItem, pReturn, nPos ) );

   if( HB_IS_SYMBOL( pItem ) )                  /* Symbol is pushed as text */
   {
      PHB_ITEM pArrayItem = hb_arrayGetItemPtr( pReturn, nPos );

      if( pArrayItem )
      {
         HB_SIZE nLen = strlen( pItem->item.asSymbol.value->szName ) + 2;
         char * szBuff = ( char * ) hb_xgrab( nLen + 1 );

         hb_snprintf( szBuff, nLen + 1, "[%s]", pItem->item.asSymbol.value->szName );
         hb_itemPutCLPtr( pArrayItem, szBuff, nLen );
      }
   }
   else                                         /* Normal types             */
      hb_itemArrayPut( pReturn, nPos, pItem );
}
Ejemplo n.º 9
0
static void hb_fldStructure( AREAP pArea, HB_USHORT uiField, HB_USHORT uiSize,
                             PHB_ITEM pField )
{
#ifdef DBS_FLAG
   static const HB_USHORT s_uiActions[] =
            { DBS_NAME, DBS_TYPE, DBS_LEN, DBS_DEC, DBS_FLAG };
#else
   static const HB_USHORT s_uiActions[] =
            { DBS_NAME, DBS_TYPE, DBS_LEN, DBS_DEC };
#endif
   HB_USHORT uiCount;

   if( uiSize == 0 || uiSize > HB_SIZEOFARRAY( s_uiActions ) )
      uiSize = HB_SIZEOFARRAY( s_uiActions );

   hb_arrayNew( pField, uiSize );
   for( uiCount = 0; uiCount < uiSize; ++uiCount )
   {
      SELF_FIELDINFO( pArea, uiField, s_uiActions[ uiCount ],
                      hb_arrayGetItemPtr( pField, uiCount + 1 ) );
   }
}
Ejemplo n.º 10
0
/* --- SDD METHODS --- */
static HB_ERRCODE mysqlConnect( SQLDDCONNECTION * pConnection, PHB_ITEM pItem )
{
   MYSQL *  pMySql;
   PHB_ITEM pItemUnixSocket = hb_arrayGetItemPtr( pItem, 7 );

   pMySql = mysql_init( NULL );
   if( ! mysql_real_connect( pMySql,
                             hb_arrayGetCPtr( pItem, 2 ) /* host */,
                             hb_arrayGetCPtr( pItem, 3 ) /* user */,
                             hb_arrayGetCPtr( pItem, 4 ) /* password */,
                             hb_arrayGetCPtr( pItem, 5 ) /* db */,
                             hb_arrayGetNI( pItem, 6 ) /* port */,
                             pItemUnixSocket && HB_IS_STRING( pItemUnixSocket ) ? hb_itemGetCPtr( pItemUnixSocket ) : NULL,
                             hb_arrayGetNI( pItem, 8 ) /* flags*/ ) )
   {
      hb_rddsqlSetError( mysql_errno( pMySql ), mysql_error( pMySql ), NULL, NULL, 0 );
      mysql_close( pMySql );
      return HB_FAILURE;
   }
   pConnection->pSDDConn = hb_xgrab( sizeof( SDDCONN ) );
   ( ( SDDCONN * ) pConnection->pSDDConn )->pMySql = pMySql;
   return HB_SUCCESS;
}
Ejemplo n.º 11
0
HB_ERRCODE hb_dbTransStruct( AREAP lpaSource, AREAP lpaDest,
                             LPDBTRANSINFO lpdbTransInfo,
                             PHB_ITEM * pStruct, PHB_ITEM pFields )
{
   HB_USHORT uiFields, uiSize, uiCount, uiPosSrc, uiPosDst, uiSizeSrc, uiSizeDst;
   HB_ERRCODE errCode;
   const char * szField;
   HB_BOOL fAll;

   errCode = SELF_FIELDCOUNT( lpaSource, &uiSizeSrc );
   if( errCode != HB_SUCCESS )
      return errCode;

   if( lpaDest )
   {
      errCode = SELF_FIELDCOUNT( lpaDest, &uiSizeDst );
      if( errCode != HB_SUCCESS )
         return errCode;
      uiSize = HB_MIN( uiSizeDst, uiSizeSrc );
   }
   else
   {
      uiSize = uiSizeDst = uiSizeSrc;
   }

   if( ! uiSize )
      return HB_FAILURE;
   if( hb_itemType( pFields ) & HB_IT_ARRAY )
   {
      uiFields = ( HB_USHORT ) hb_arrayLen( pFields );
      if( uiFields )
         uiSize = uiFields;
   }
   else
      uiFields = 0;

   fAll = ( uiSizeDst == uiSizeSrc );

   lpdbTransInfo->lpaSource    = lpaSource;
   lpdbTransInfo->lpaDest      = lpaDest;
   lpdbTransInfo->lpTransItems = ( LPDBTRANSITEM )
                                    hb_xgrab( uiSize * sizeof( DBTRANSITEM ) );

   if( ! lpaDest )
   {
      *pStruct = hb_itemNew( NULL );
      hb_arrayNew( *pStruct, 0 );
   }

   if( uiFields == 0 )
   {
      if( lpaDest )
      {
         PHB_ITEM pItem = hb_itemNew( NULL );
         uiSize = 0;
         for( uiCount = 1; uiCount <= uiSizeSrc; ++uiCount )
         {
            if( SELF_FIELDINFO( lpaSource, uiCount, DBS_NAME, pItem ) != HB_SUCCESS )
            {
               uiSize = 0;
               break;
            }
            szField = hb_itemGetCPtr( pItem );
            uiPosDst = hb_rddFieldExpIndex( lpaDest, szField );
            if( uiPosDst != uiCount )
               fAll = HB_FALSE;
            if( uiPosDst )
            {
               HB_USHORT ui;

               /* check for replicated field names in source area */
               for( ui = 0; ui < uiSize; ++ui )
               {
                  if( lpdbTransInfo->lpTransItems[ ui ].uiDest == uiPosDst )
                     break;
               }
               if( ui == uiSize )
               {
                  lpdbTransInfo->lpTransItems[ uiSize ].uiSource = uiCount;
                  lpdbTransInfo->lpTransItems[ uiSize++ ].uiDest = uiPosDst;
               }
            }
         }
         hb_itemRelease( pItem );
      }
      else
      {
         hb_tblStructure( lpaSource, *pStruct, 0 );
         uiSize = ( HB_USHORT ) hb_arrayLen( *pStruct );
         for( uiCount = 0; uiCount < uiSize; ++uiCount )
         {
            lpdbTransInfo->lpTransItems[ uiCount ].uiSource =
            lpdbTransInfo->lpTransItems[ uiCount ].uiDest = uiCount + 1;
         }
      }
   }
   else
   {
      uiSize = 0;
      for( uiCount = 1; uiCount <= uiFields; ++uiCount )
      {
         szField = hb_dbTransFieldPos( pFields, uiCount );
         if( szField )
         {
            uiPosSrc = hb_rddFieldExpIndex( lpaSource, szField );
            if( ! uiPosSrc )
               continue;
            if( lpaDest )
               uiPosDst = hb_rddFieldExpIndex( lpaDest, szField );
            else
               uiPosDst = uiSize + 1;
            if( uiPosDst )
            {
               if( uiPosSrc != uiPosDst )
                  fAll = HB_FALSE;
               lpdbTransInfo->lpTransItems[ uiSize ].uiSource = uiPosSrc;
               lpdbTransInfo->lpTransItems[ uiSize++ ].uiDest = uiPosDst;
               if( ! lpaDest )
               {
                  hb_arraySize( *pStruct, uiSize );
                  hb_fldStructure( lpaSource, uiPosSrc, 0,
                                   hb_arrayGetItemPtr( *pStruct, uiSize ) );
               }
            }
         }
      }
   }

   if( uiSize != uiSizeSrc )
      fAll = HB_FALSE;

   if( fAll && lpaDest )
   {
      PHB_ITEM pSrcItm = hb_itemNew( NULL ),
               pDstItm = hb_itemNew( NULL );
      /*
       * if fAll is HB_TRUE here then it means that all fields are included
       * and they are on the same positions in both tables, so now check
       * if their types and sizes are also equal
       */
      for( uiCount = 1; uiCount <= uiSize; ++uiCount )
      {
         if( SELF_FIELDINFO( lpaSource, uiCount, DBS_TYPE, pSrcItm ) != HB_SUCCESS ||
             SELF_FIELDINFO( lpaDest,   uiCount, DBS_TYPE, pDstItm ) != HB_SUCCESS )
         {
            uiSize = 0;
            break;
         }
         if( hb_stricmp( hb_itemGetCPtr( pSrcItm ),
                         hb_itemGetCPtr( pDstItm ) ) != 0 )
         {
            fAll = HB_FALSE;
            break;
         }
         if( SELF_FIELDINFO( lpaSource, uiCount, DBS_LEN, pSrcItm ) != HB_SUCCESS ||
             SELF_FIELDINFO( lpaDest,   uiCount, DBS_LEN, pDstItm ) != HB_SUCCESS )
         {
            uiSize = 0;
            break;
         }
         if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) )
         {
            fAll = HB_FALSE;
            break;
         }
         if( SELF_FIELDINFO( lpaSource, uiCount, DBS_DEC, pSrcItm ) != HB_SUCCESS ||
             SELF_FIELDINFO( lpaDest,   uiCount, DBS_DEC, pDstItm ) != HB_SUCCESS )
         {
            uiSize = 0;
            break;
         }
         if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) )
         {
            fAll = HB_FALSE;
            break;
         }
#ifdef DBS_FLAG
         if( SELF_FIELDINFO( lpaSource, uiCount, DBS_FLAG, pSrcItm ) != HB_SUCCESS ||
             SELF_FIELDINFO( lpaDest,   uiCount, DBS_FLAG, pDstItm ) != HB_SUCCESS )
         {
            uiSize = 0;
            break;
         }
         if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) )
         {
            fAll = HB_FALSE;
            break;
         }
#endif
      }
      hb_itemRelease( pSrcItm );
      hb_itemRelease( pDstItm );
   }

   lpdbTransInfo->uiFlags = fAll ? DBTF_MATCH : 0;
   lpdbTransInfo->uiItemCount = uiSize;

   return uiSize ? HB_SUCCESS : HB_FAILURE;
}
Ejemplo n.º 12
0
static const char * hb_i18n_setcodepage( PHB_I18N_TRANS pI18N,
                                         const char * szCdpID,
                                         HB_BOOL fBase, HB_BOOL fTranslate )
{
   const char * szOldCdpID = NULL, * szKey;

   if( pI18N )
   {
      PHB_CODEPAGE cdp = szCdpID ? hb_cdpFind( szCdpID ) : NULL, cdpage;

      cdpage = fBase ? pI18N->base_cdpage : pI18N->cdpage;
      if( cdpage )
         szOldCdpID = cdpage->id;
      if( cdp && cdp != cdpage )
      {
         if( fTranslate && cdpage )
         {
            HB_SIZE nHashLen = hb_hashLen( pI18N->context_table ), ul;
            for( ul = 1; ul <= nHashLen; ++ul )
            {
               PHB_ITEM pContext = hb_hashGetValueAt( pI18N->context_table, ul );
               HB_SIZE nCount = hb_hashLen( pContext ), u;

               for( u = 1; u <= nCount; ++u )
               {
                  if( fBase )
                  {
                     hb_i18n_transitm( hb_hashGetKeyAt( pContext, u ),
                                       cdpage, cdp );
                  }
                  else
                  {
                     PHB_ITEM pResult = hb_hashGetValueAt( pContext, u );
                     if( HB_IS_STRING( pResult ) )
                     {
                        hb_i18n_transitm( pResult, cdpage, cdp );
                     }
                     else if( HB_IS_ARRAY( pResult ) )
                     {
                        HB_SIZE nTrans = hb_arrayLen( pResult ), u2;
                        for( u2 = 1; u2 <= nTrans; ++u2 )
                        {
                           hb_i18n_transitm( hb_arrayGetItemPtr( pResult, u2 ),
                                             cdpage, cdp );
                        }
                     }
                  }
               }
               if( fBase )
               {
                  hb_i18n_transitm( hb_hashGetKeyAt( pI18N->context_table, ul ),
                                    cdpage, cdp );
                  hb_hashSetFlags( pContext, HB_HASH_RESORT );
               }
            }
            if( fBase )
               hb_hashSetFlags( pI18N->context_table, HB_HASH_RESORT );
         }

         if( fBase )
         {
            pI18N->base_cdpage = cdp;
            szKey = "BASE_CODEPAGE";
         }
         else
         {
            pI18N->cdpage = cdp;
            szKey = "CODEPAGE";
         }
         hb_i18n_setitem( pI18N->table, szKey, szCdpID );
      }
   }

   return szOldCdpID;
}
Ejemplo n.º 13
0
static void _hb_jsonEncode( PHB_ITEM pValue, PHB_JSON_ENCODE_CTX pCtx,
                            HB_SIZE nLevel, HB_BOOL fEOL, PHB_CODEPAGE cdp )
{
   /* Protection against recursive structures */
   if( ( HB_IS_ARRAY( pValue ) || HB_IS_HASH( pValue ) ) && hb_itemSize( pValue ) > 0 )
   {
      void * id = HB_IS_HASH( pValue ) ? hb_hashId( pValue ) : hb_arrayId( pValue );
      HB_SIZE nIndex;

      for( nIndex = 0; nIndex < nLevel; nIndex++ )
      {
         if( pCtx->pId[ nIndex ] == id )
         {
            if( ! fEOL && pCtx->fHuman )
               _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );
            _hb_jsonCtxAdd( pCtx, "null", 4 );
            return;
         }
      }
      if( nLevel >= pCtx->nAllocId )
      {
         pCtx->nAllocId += 8;
         pCtx->pId = ( void ** ) hb_xrealloc( pCtx->pId, sizeof( void * ) * pCtx->nAllocId );
      }
      pCtx->pId[ nLevel ] = id;
   }

   if( fEOL )
   {
      --pCtx->pHead;
      _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
   }

   if( HB_IS_STRING( pValue ) )
   {
      HB_SIZE nPos, nLen = hb_itemGetCLen( pValue );
      const char * szString = hb_itemGetCPtr( pValue );
      char buf[ 8 ];

      _hb_jsonCtxAdd( pCtx, "\"", 1 );

      if( cdp )
      {
         HB_WCHAR wc;

         nPos = 0;
         while( HB_CDPCHAR_GET( cdp, szString, nLen, &nPos, &wc ) )
         {
            if( wc >= ' ' && wc < 0x7F && wc != '\\' && wc != '\"' )
            {
               buf[ 0 ] = ( char ) wc;
               _hb_jsonCtxAdd( pCtx, buf, 1 );
               continue;
            }
            switch( wc )
            {
               case '\\':
                  _hb_jsonCtxAdd( pCtx, "\\\\", 2 );
                  break;
               case '\"':
                  _hb_jsonCtxAdd( pCtx, "\\\"", 2 );
                  break;
               case '\b':
                  _hb_jsonCtxAdd( pCtx, "\\b", 2 );
                  break;
               case '\f':
                  _hb_jsonCtxAdd( pCtx, "\\f", 2 );
                  break;
               case '\n':
                  _hb_jsonCtxAdd( pCtx, "\\n", 2 );
                  break;
               case '\r':
                  _hb_jsonCtxAdd( pCtx, "\\r", 2 );
                  break;
               case '\t':
                  _hb_jsonCtxAdd( pCtx, "\\t", 2 );
                  break;
               default:
                  hb_snprintf( buf, sizeof( buf ), "\\u%04X", wc );
                  _hb_jsonCtxAdd( pCtx, buf, 6 );
                  break;
            }
         }
      }
      else
      {
         nPos = 0;
         while( nPos < nLen )
         {
            unsigned char uch = szString[ nPos ];
            HB_SIZE nPos2 = nPos;
            while( uch >= ' ' && uch != '\\' && uch != '\"' )
               uch = szString[ ++nPos2 ];
            if( nPos2 > nPos )
            {
               _hb_jsonCtxAdd( pCtx, szString + nPos, nPos2 - nPos );
               if( nPos2 >= nLen )
                  break;
               nPos = nPos2;
            }

            switch( uch )
            {
               case '\\':
                  _hb_jsonCtxAdd( pCtx, "\\\\", 2 );
                  break;
               case '\"':
                  _hb_jsonCtxAdd( pCtx, "\\\"", 2 );
                  break;
               case '\b':
                  _hb_jsonCtxAdd( pCtx, "\\b", 2 );
                  break;
               case '\f':
                  _hb_jsonCtxAdd( pCtx, "\\f", 2 );
                  break;
               case '\n':
                  _hb_jsonCtxAdd( pCtx, "\\n", 2 );
                  break;
               case '\r':
                  _hb_jsonCtxAdd( pCtx, "\\r", 2 );
                  break;
               case '\t':
                  _hb_jsonCtxAdd( pCtx, "\\t", 2 );
                  break;
               default:
                  hb_snprintf( buf, sizeof( buf ), "\\u00%02X", uch );
                  _hb_jsonCtxAdd( pCtx, buf, 6 );
                  break;
            }
            nPos++;
         }
      }
      _hb_jsonCtxAdd( pCtx, "\"", 1 );
   }
   else if( HB_IS_NUMINT( pValue ) )
   {
      char buf[ 24 ];
      HB_MAXINT nVal = hb_itemGetNInt( pValue );
      HB_BOOL fNeg = nVal < 0;
      int i = 0;

      if( fNeg )
         nVal = -nVal;
      do
         buf[ sizeof( buf ) - ++i ] = ( nVal % 10 ) + '0';
      while( ( nVal /= 10 ) != 0 );
      if( fNeg )
         buf[ sizeof( buf ) - ++i ] = '-';
      _hb_jsonCtxAdd( pCtx, &buf[ sizeof( buf ) - i ], i );
   }
   else if( HB_IS_NUMERIC( pValue ) )
   {
      char buf[ 64 ];
      int iDec;
      double dblValue = hb_itemGetNDDec( pValue, &iDec );

      hb_snprintf( buf, sizeof( buf ), "%.*f", iDec, dblValue );
      _hb_jsonCtxAdd( pCtx, buf, strlen( buf ) );
   }
   else if( HB_IS_NIL( pValue ) )
   {
      _hb_jsonCtxAdd( pCtx, "null", 4 );
   }
   else if( HB_IS_LOGICAL( pValue ) )
   {
      if( hb_itemGetL( pValue ) )
         _hb_jsonCtxAdd( pCtx, "true", 4 );
      else
         _hb_jsonCtxAdd( pCtx, "false", 5 );

   }
   else if( HB_IS_DATE( pValue ) )
   {
      char szBuffer[ 10 ];

      hb_itemGetDS( pValue, szBuffer + 1 );
      szBuffer[ 0 ] = '\"';
      szBuffer[ 9 ] = '\"';
      _hb_jsonCtxAdd( pCtx, szBuffer, 10 );
   }
   else if( HB_IS_TIMESTAMP( pValue ) )
   {
      char szBuffer[ 19 ];
      hb_itemGetTS( pValue, szBuffer + 1 );
      szBuffer[ 0 ] = '\"';
      szBuffer[ 18 ] = '\"';
      _hb_jsonCtxAdd( pCtx, szBuffer, 19 );
   }
   else if( HB_IS_ARRAY( pValue ) )
   {
      HB_SIZE nLen = hb_itemSize( pValue );

      if( nLen )
      {
         HB_SIZE nIndex;

         if( pCtx->fHuman )
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );

         _hb_jsonCtxAdd( pCtx, "[", 1 );

         for( nIndex = 1; nIndex <= nLen; nIndex++ )
         {
            PHB_ITEM pItem = hb_arrayGetItemPtr( pValue, nIndex );

            if( nIndex > 1 )
               _hb_jsonCtxAdd( pCtx, ",", 1 );

            if( pCtx->fHuman )
               _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );

            if( pCtx->fHuman &&
                ! ( ( HB_IS_ARRAY( pItem ) || HB_IS_HASH( pItem ) ) &&
                    hb_itemSize( pItem ) > 0 ) )
               _hb_jsonCtxAddIndent( pCtx, ( nLevel + 1 ) * INDENT_SIZE );

            _hb_jsonEncode( pItem, pCtx, nLevel + 1, HB_FALSE, cdp );
         }
         if( pCtx->fHuman )
         {
            _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );
         }
         _hb_jsonCtxAdd( pCtx, "]", 1 );
      }
      else
         _hb_jsonCtxAdd( pCtx, "[]", 2 );
   }
   else if( HB_IS_HASH( pValue ) )
   {
      HB_SIZE nLen = hb_hashLen( pValue );

      if( nLen )
      {
         HB_SIZE nIndex;

         if( pCtx->fHuman )
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );

         _hb_jsonCtxAdd( pCtx, "{", 1 );

         for( nIndex = 1; nIndex <= nLen; nIndex++ )
         {
            PHB_ITEM pKey = hb_hashGetKeyAt( pValue, nIndex );

            if( HB_IS_STRING( pKey ) )
            {
               PHB_ITEM pItem = hb_hashGetValueAt( pValue, nIndex );

               if( nIndex > 1 )
                  _hb_jsonCtxAdd( pCtx, ",", 1 );

               if( pCtx->fHuman )
               {
                  _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
                  _hb_jsonCtxAddIndent( pCtx, ( nLevel + 1 ) * INDENT_SIZE );
               }
               _hb_jsonEncode( pKey, pCtx, nLevel + 1, HB_FALSE, cdp );

               if( pCtx->fHuman )
               {
                  _hb_jsonCtxAdd( pCtx, ": ", 2 );
                  fEOL = ( HB_IS_ARRAY( pItem ) || HB_IS_HASH( pItem ) ) && hb_itemSize( pItem ) > 0;
               }
               else
               {
                  _hb_jsonCtxAdd( pCtx, ":", 1 );
                  fEOL = HB_FALSE;
               }

               _hb_jsonEncode( pItem, pCtx, nLevel + 1, fEOL, cdp );
            }
         }
         if( pCtx->fHuman )
         {
            _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );
         }
         _hb_jsonCtxAdd( pCtx, "}", 1 );
      }
      else
         _hb_jsonCtxAdd( pCtx, "{}", 2 );
   }
   else
   {
      /* All unsupported types are replacd by null */
      _hb_jsonCtxAdd( pCtx, "null", 4 );
   }
}
Ejemplo n.º 14
0
PHB_ITEM hb_errGetArgs( PHB_ITEM pError )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_errGetArgs(%p)", pError ) );

   return hb_arrayGetItemPtr( pError, HB_TERROR_ARGS );
}
Ejemplo n.º 15
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;
}
Ejemplo n.º 16
0
static HB_BOOL hb_regex( int iRequest )
{
   HB_REGMATCH aMatches[ HB_REGMATCH_SIZE( REGEX_MAX_GROUPS ) ];
   PHB_ITEM pRetArray, pMatch, pString;
   int i, iMatches, iMaxMatch;
   HB_BOOL fResult = HB_FALSE;
   PHB_REGEX pRegEx;
   const char * pszString;
   HB_SIZE nLen;

   pString = hb_param( 2, HB_IT_STRING );
   if( ! pString )
   {
      hb_errRT_BASE_SubstR( EG_ARG, 3014, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
      return HB_FALSE;
   }
   pRegEx = hb_regexGet( hb_param( 1, HB_IT_ANY ),
                         ( ! hb_parldef( 3, 1 ) ? HBREG_ICASE : 0 ) |
                         ( hb_parl( 4 ) ? HBREG_NEWLINE : 0 ) );
   if( ! pRegEx )
      return HB_FALSE;

   pszString = hb_itemGetCPtr( pString );
   nLen      = hb_itemGetCLen( pString );
   iMaxMatch = iRequest == 0 || iRequest == 4 || iRequest == 5 ?
               REGEX_MAX_GROUPS : 1;
   iMatches = hb_regexec( pRegEx, pszString, nLen, iMaxMatch, aMatches );
   if( iMatches > 0 )
   {
      switch( iRequest )
      {
         case 0:
            pRetArray = hb_itemArrayNew( iMatches );
            for( i = 0; i < iMatches; i++ )
            {
               if( HB_REGMATCH_EO( aMatches, i ) > -1 )
                  hb_arraySetCL( pRetArray, i + 1,
                                 pszString + HB_REGMATCH_SO( aMatches, i ),
                                 HB_REGMATCH_EO( aMatches, i ) -
                                 HB_REGMATCH_SO( aMatches, i ) );
               else
                  hb_arraySetCL( pRetArray, i + 1, NULL, 0 );
            }
            hb_itemReturnRelease( pRetArray );
            fResult = HB_TRUE;
            break;

         case 1: /* LIKE */
            fResult = HB_REGMATCH_SO( aMatches, 0 ) == 0 &&
                      ( HB_SIZE ) HB_REGMATCH_EO( aMatches, 0 ) == nLen;
            break;

         case 2: /* MATCH ( HAS ) */
            fResult = HB_TRUE;
            break;

         case 3: /* SPLIT */
            iMaxMatch = hb_parni( 5 );
            pRetArray = hb_itemArrayNew( 0 );
            pMatch = hb_itemNew( NULL );
            iMatches = 0;
            do
            {
               hb_itemPutCL( pMatch, pszString, HB_REGMATCH_SO( aMatches, 0 ) );
               hb_arrayAddForward( pRetArray, pMatch );
               nLen -= HB_REGMATCH_EO( aMatches, 0 );
               pszString += HB_REGMATCH_EO( aMatches, 0 );
               iMatches++;
            }
            while( HB_REGMATCH_EO( aMatches, 0 ) > 0 && nLen &&
                   ( iMaxMatch == 0 || iMatches < iMaxMatch ) &&
                   hb_regexec( pRegEx, pszString, nLen, 1, aMatches ) > 0 );

            /* last match must be done also in case that pszString is empty;
               this would mean an empty split field at the end of the string */
            /* if( nLen ) */
            {
               hb_itemPutCL( pMatch, pszString, nLen );
               hb_arrayAddForward( pRetArray, pMatch );
            }
            hb_itemRelease( pMatch );

            hb_itemReturnRelease( pRetArray );
            fResult = HB_TRUE;
            break;

         case 4: /* results AND positions */
            pRetArray = hb_itemArrayNew( iMatches );

            for( i = 0; i < iMatches; i++ )
            {
               int iSO = HB_REGMATCH_SO( aMatches, i ),
                   iEO = HB_REGMATCH_EO( aMatches, i );
               pMatch = hb_arrayGetItemPtr( pRetArray, i + 1 );
               hb_arrayNew( pMatch, 3 );
               if( iEO != -1 )
               {
                  /* matched string */
                  hb_arraySetCL( pMatch, 1, pszString + iSO, iEO - iSO );
                  /* begin of match */
                  hb_arraySetNS( pMatch, 2, iSO + 1 );
                  /* End of match */
                  hb_arraySetNS( pMatch, 3, iEO );
               }
               else
               {
                  hb_arraySetCL( pMatch, 1, NULL, 0 );
                  hb_arraySetNS( pMatch, 2, 0 );
                  hb_arraySetNS( pMatch, 3, 0 );
               }
            }
            hb_itemReturnRelease( pRetArray );
            fResult = HB_TRUE;
            break;

         case 5: /* _ALL_ results AND positions */
         {
            PHB_ITEM pAtxArray;
            int      iMax       = hb_parni( 5 );   /* max nuber of matches I want, 0 = unlimited */
            int      iGetMatch  = hb_parni( 6 );   /* Gets if want only one single match or a sub-match */
            HB_BOOL  fOnlyMatch = hb_parldef( 7, 1 ); /* if HB_TRUE returns only matches and sub-matches, not positions */
            HB_SIZE  nOffset    = 0;
            int      iCount     = 0;
            int      iSO, iEO;

            /* Set new array */
            pRetArray = hb_itemArrayNew( 0 );
            do
            {
               /* If I want all matches */
               if( iGetMatch == 0 || /* Check boundaries */
                   ( iGetMatch < 0 || iGetMatch > iMatches ) )
               {
                  pAtxArray = hb_itemArrayNew( iMatches );
                  for( i = 0; i < iMatches; i++ )
                  {
                     iSO = HB_REGMATCH_SO( aMatches, i );
                     iEO = HB_REGMATCH_EO( aMatches, i );
                     pMatch = hb_arrayGetItemPtr( pAtxArray, i + 1 );
                     if( ! fOnlyMatch )
                     {
                        hb_arrayNew( pMatch, 3 );
                        if( iEO != -1 )
                        {
                           /* matched string */
                           hb_arraySetCL( pMatch, 1, pszString + iSO, iEO - iSO );
                           /* begin of match */
                           hb_arraySetNS( pMatch, 2, nOffset + iSO + 1 );
                           /* End of match */
                           hb_arraySetNS( pMatch, 3, nOffset + iEO );
                        }
                        else
                        {
                           hb_arraySetCL( pMatch, 1, NULL, 0 );
                           hb_arraySetNS( pMatch, 2, 0 );
                           hb_arraySetNS( pMatch, 3, 0 );
                        }
                     }
                     else
                     {
                        if( iEO != -1 )
                           /* matched string */
                           hb_itemPutCL( pMatch, pszString + iSO, iEO - iSO );
                        else
                           hb_itemPutC( pMatch, NULL );
                     }
                  }
                  hb_arrayAddForward( pRetArray, pAtxArray );
                  hb_itemRelease( pAtxArray );
               }
               else /* Here I get only single matches */
               {
                  i = iGetMatch - 1;
                  iSO = HB_REGMATCH_SO( aMatches, i );
                  iEO = HB_REGMATCH_EO( aMatches, i );
                  pMatch = hb_itemNew( NULL );
                  if( ! fOnlyMatch )
                  {
                     hb_arrayNew( pMatch, 3 );
                     if( iEO != -1 )
                     {
                        /* matched string */
                        hb_arraySetCL( pMatch, 1, pszString + iSO, iEO - iSO );
                        /* begin of match */
                        hb_arraySetNS( pMatch, 2, nOffset + iSO + 1 );
                        /* End of match */
                        hb_arraySetNS( pMatch, 3, nOffset + iEO );
                     }
                     else
                     {
                        hb_arraySetCL( pMatch, 1, NULL, 0 );
                        hb_arraySetNS( pMatch, 2, 0 );
                        hb_arraySetNS( pMatch, 3, 0 );
                     }
                  }
                  else
                  {
                     if( iEO != -1 )
                        /* matched string */
                        hb_itemPutCL( pMatch, pszString + iSO, iEO - iSO );
                     else
                        hb_itemPutC( pMatch, NULL );
                  }
                  hb_arrayAddForward( pRetArray, pMatch );
                  hb_itemRelease( pMatch );
               }

               iEO = HB_REGMATCH_EO( aMatches, 0 );
               if( iEO == -1 )
                  break;
               nLen -= iEO;
               pszString += iEO;
               nOffset += iEO;
               iCount++;
            }
            while( iEO && nLen && ( iMax == 0 || iCount < iMax ) &&
                   ( iMatches = hb_regexec( pRegEx, pszString, nLen, iMaxMatch, aMatches ) ) > 0 );
            hb_itemReturnRelease( pRetArray );
            fResult = HB_TRUE;
            break;
         }
      }
   }
   else if( iRequest == 3 )
   {
      pRetArray = hb_itemArrayNew( 1 );
      hb_arraySet( pRetArray, 1, pString );
      hb_itemReturnRelease( pRetArray );
      fResult = HB_TRUE;
   }

   hb_regexFree( pRegEx );
   return fResult;
}
Ejemplo n.º 17
0
PHB_ITEM hb_errGetCargo( PHB_ITEM pError )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_errGetCargo(%p)", pError ) );

   return hb_arrayGetItemPtr( pError, HB_TERROR_CARGO );
}
Ejemplo n.º 18
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 );
}
Ejemplo n.º 19
0
static HB_ERRCODE sqlite3Open( SQLBASEAREAP pArea )
{
   sqlite3 *      pDb = ( ( SDDCONN * ) pArea->pConnection->pSDDConn )->pDb;
   sqlite3_stmt * st  = NULL;
   SDDDATA *      pSDDData;
   const char *   pszQuery;
   HB_SIZE        nQueryLen;
   void *         hQuery;
   HB_USHORT      uiFields, uiIndex;
   PHB_ITEM       pItemEof, pItem, pName = NULL;
   HB_ERRCODE     errCode;
   char *         szError;
   HB_BOOL        bError;

   pArea->pSDDData = memset( hb_xgrab( sizeof( SDDDATA ) ), 0, sizeof( SDDDATA ) );
   pSDDData        = ( SDDDATA * ) pArea->pSDDData;

   pItem    = hb_itemPutC( NULL, pArea->szQuery );
   pszQuery = S_HB_ITEMGETSTR( pItem, &hQuery, &nQueryLen );

   if( sqlite3_prepare_v2( pDb, pszQuery, ( int ) nQueryLen, &st, NULL ) != SQLITE_OK )
   {
      hb_strfree( hQuery );
      hb_itemRelease( pItem );
      szError = sqlite3GetError( pDb, &errCode );
      hb_errRT_SQLT3DD( EG_OPEN, ESQLDD_INVALIDQUERY, szError, pArea->szQuery, errCode );
      sqlite3_finalize( st );
      hb_xfree( szError );
      return HB_FAILURE;
   }
   else
   {
      hb_strfree( hQuery );
      hb_itemRelease( pItem );
   }

   if( sqlite3_step( st ) != SQLITE_ROW )
   {
      szError = sqlite3GetError( pDb, &errCode );
      hb_errRT_SQLT3DD( EG_OPEN, ESQLDD_INVALIDQUERY, szError, pArea->szQuery, errCode );
      sqlite3_finalize( st );
      hb_xfree( szError );
      return HB_FAILURE;
   }

   uiFields = ( HB_USHORT ) sqlite3_column_count( st );
   SELF_SETFIELDEXTENT( &pArea->area, uiFields );

   errCode = 0;
   bError  = HB_FALSE;
   pItemEof = hb_itemArrayNew( uiFields );
   for( uiIndex = 0; uiIndex < uiFields; ++uiIndex )
   {
      DBFIELDINFO dbFieldInfo;

      memset( &dbFieldInfo, 0, sizeof( dbFieldInfo ) );
      pName = S_HB_ITEMPUTSTR( pName, sqlite3_column_name( st, uiIndex ) );
      dbFieldInfo.atomName = hb_itemGetCPtr( pName );
      dbFieldInfo.uiType = sqlite3DeclType( st, uiIndex );
      pItem = hb_arrayGetItemPtr( pItemEof, uiIndex + 1 );

      switch( dbFieldInfo.uiType )
      {
         case HB_FT_STRING:
         {
            int iSize = sqlite3_column_bytes( st, uiIndex );
            char * pStr;

            dbFieldInfo.uiLen = ( HB_USHORT ) HB_MAX( iSize, 10 );
            pStr = ( char * ) hb_xgrab( ( HB_SIZE ) dbFieldInfo.uiLen + 1 );
            memset( pStr, ' ', dbFieldInfo.uiLen );
            hb_itemPutCLPtr( pItem, pStr, dbFieldInfo.uiLen );
            break;
         }
         case HB_FT_BLOB:
            dbFieldInfo.uiLen = 4;
            hb_itemPutC( pItem, NULL );
            break;

         case HB_FT_INTEGER:
            dbFieldInfo.uiLen = 8;
            hb_itemPutNInt( pItem, 0 );
            break;

         case HB_FT_LONG:
            dbFieldInfo.uiLen = 20;
            dbFieldInfo.uiDec = ( HB_USHORT ) hb_setGetDecimals();
            hb_itemPutNDDec( pItem, 0.0, dbFieldInfo.uiDec );
            break;

         case HB_FT_ANY:
            dbFieldInfo.uiLen = 6;
            break;

         default:
            bError = HB_TRUE;
      }

      if( ! bError )
         bError = ( SELF_ADDFIELD( &pArea->area, &dbFieldInfo ) == HB_FAILURE );

      if( bError )
         break;
   }
   hb_itemRelease( pName );

   if( bError )
   {
      hb_itemRelease( pItemEof );
      sqlite3_finalize( st );
      hb_errRT_SQLT3DD( EG_CORRUPTION, ESQLDD_INVALIDFIELD, "Invalid field type", pArea->szQuery, errCode );
      return HB_FAILURE;
   }

   pArea->ulRecCount = 0;
   pArea->ulRecMax   = SQLDD_ROWSET_INIT;

   pArea->pRow = ( void ** ) hb_xgrab( SQLDD_ROWSET_INIT * sizeof( void * ) );
   pArea->pRowFlags = ( HB_BYTE * ) hb_xgrab( SQLDD_ROWSET_INIT * sizeof( HB_BYTE ) );

   pArea->pRow[ 0 ]      = pItemEof;
   pArea->pRowFlags[ 0 ] = SQLDD_FLAG_CACHED;

   pSDDData->pStmt = st;
   return HB_SUCCESS;
}
Ejemplo n.º 20
0
static void _hb_jsonEncode( PHB_ITEM pValue, PHB_JSON_ENCODE_CTX pCtx,
                            HB_SIZE nLevel, HB_BOOL fEOL )
{
   /* Protection against recursive structures */
   if( ( HB_IS_ARRAY( pValue ) || HB_IS_HASH( pValue ) ) && hb_itemSize( pValue ) > 0 )
   {
      void * id = HB_IS_HASH( pValue ) ? hb_hashId( pValue ) : hb_arrayId( pValue );
      HB_SIZE nIndex;

      for( nIndex = 0; nIndex < nLevel; nIndex++ )
      {
         if( pCtx->pId[ nIndex ] == id )
         {
            if( ! fEOL && pCtx->fHuman )
               _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );
            _hb_jsonCtxAdd( pCtx, "null", 4 );
            return;
         }
      }
      if( nLevel >= pCtx->nAllocId )
      {
         pCtx->nAllocId += 8;
         pCtx->pId = ( void ** ) hb_xrealloc( pCtx->pId, sizeof( void * ) * pCtx->nAllocId );
      }
      pCtx->pId[ nLevel ] = id;
   }

   if( fEOL )
   {
      --pCtx->pHead;
      _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
   }

   if( HB_IS_STRING( pValue ) )
   {
      const char * szString = hb_itemGetCPtr( pValue );
      HB_SIZE nPos, nPos2, nLen = hb_itemGetCLen( pValue );

      _hb_jsonCtxAdd( pCtx, "\"", 1 );

      nPos = 0;
      while( nPos < nLen )
      {
         nPos2 = nPos;
         while( *( ( const unsigned char * ) szString + nPos2 ) >= ' ' &&
                szString[ nPos2 ] != '\\' && szString[ nPos2 ] != '\"' )
            nPos2++;
         if( nPos2 > nPos )
         {
            _hb_jsonCtxAdd( pCtx, szString + nPos, nPos2 - nPos );
            nPos = nPos2;
            continue;
         }

         switch( szString[ nPos ] )
         {
            case '\\':
               _hb_jsonCtxAdd( pCtx, "\\\\", 2 );
               break;
            case '\"':
               _hb_jsonCtxAdd( pCtx, "\\\"", 2 );
               break;
            case '\b':
               _hb_jsonCtxAdd( pCtx, "\\b", 2 );
               break;
            case '\f':
               _hb_jsonCtxAdd( pCtx, "\\f", 2 );
               break;
            case '\n':
               _hb_jsonCtxAdd( pCtx, "\\n", 2 );
               break;
            case '\r':
               _hb_jsonCtxAdd( pCtx, "\\r", 2 );
               break;
            case '\t':
               _hb_jsonCtxAdd( pCtx, "\\t", 2 );
               break;
            default:
            {
               char buf[ 8 ];
               hb_snprintf( buf, sizeof( buf ), "\\u00%02X", ( unsigned char ) szString[ nPos ] );
               _hb_jsonCtxAdd( pCtx, buf, 6 );
               break;
            }
         }
         nPos++;
      }
      _hb_jsonCtxAdd( pCtx, "\"", 1 );
   }
   else if( HB_IS_NUMINT( pValue ) )
   {
      char buf[ 32 ];

      hb_snprintf( buf, sizeof( buf ), "%" PFHL "d", hb_itemGetNInt( pValue ) );
      _hb_jsonCtxAdd( pCtx, buf, strlen( buf ) );
   }
   else if( HB_IS_NUMERIC( pValue ) )
   {
      char buf[ 64 ];
      int iDec;
      double dblValue = hb_itemGetNDDec( pValue, &iDec );

      hb_snprintf( buf, sizeof( buf ), "%.*f", iDec, dblValue );
      _hb_jsonCtxAdd( pCtx, buf, strlen( buf ) );
   }
   else if( HB_IS_NIL( pValue ) )
   {
      _hb_jsonCtxAdd( pCtx, "null", 4 );
   }
   else if( HB_IS_LOGICAL( pValue ) )
   {
      if( hb_itemGetL( pValue ) )
         _hb_jsonCtxAdd( pCtx, "true", 4 );
      else
         _hb_jsonCtxAdd( pCtx, "false", 5 );

   }
   else if( HB_IS_DATE( pValue ) )
   {
      char szBuffer[ 10 ];

      hb_itemGetDS( pValue, szBuffer + 1 );
      szBuffer[ 0 ] = '\"';
      szBuffer[ 9 ] = '\"';
      _hb_jsonCtxAdd( pCtx, szBuffer, 10 );
   }
   else if( HB_IS_TIMESTAMP( pValue ) )
   {
      char szBuffer[ 19 ];
      hb_itemGetTS( pValue, szBuffer + 1 );
      szBuffer[ 0 ] = '\"';
      szBuffer[ 18 ] = '\"';
      _hb_jsonCtxAdd( pCtx, szBuffer, 19 );
   }
   else if( HB_IS_ARRAY( pValue ) )
   {
      HB_SIZE nLen = hb_itemSize( pValue );

      if( nLen )
      {
         HB_SIZE nIndex;

         if( pCtx->fHuman )
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );

         _hb_jsonCtxAdd( pCtx, "[", 1 );

         for( nIndex = 1; nIndex <= nLen; nIndex++ )
         {
            PHB_ITEM pItem = hb_arrayGetItemPtr( pValue, nIndex );

            if( nIndex > 1 )
               _hb_jsonCtxAdd( pCtx, ",", 1 );

            if( pCtx->fHuman )
               _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );

            if( pCtx->fHuman &&
                ! ( ( HB_IS_ARRAY( pItem ) || HB_IS_HASH( pItem ) ) &&
                    hb_itemSize( pItem ) > 0 ) )
               _hb_jsonCtxAddIndent( pCtx, ( nLevel + 1 ) * INDENT_SIZE );

            _hb_jsonEncode( pItem, pCtx, nLevel + 1, HB_FALSE );
         }
         if( pCtx->fHuman )
         {
            _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );
         }
         _hb_jsonCtxAdd( pCtx, "]", 1 );
      }
      else
         _hb_jsonCtxAdd( pCtx, "[]", 2 );
   }
   else if( HB_IS_HASH( pValue ) )
   {
      HB_SIZE nLen = hb_hashLen( pValue );

      if( nLen )
      {
         HB_SIZE nIndex;

         if( pCtx->fHuman )
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );

         _hb_jsonCtxAdd( pCtx, "{", 1 );

         for( nIndex = 1; nIndex <= nLen; nIndex++ )
         {
            PHB_ITEM pKey = hb_hashGetKeyAt( pValue, nIndex );

            if( HB_IS_STRING( pKey ) )
            {
               PHB_ITEM pItem = hb_hashGetValueAt( pValue, nIndex );
               HB_BOOL fEOL = HB_FALSE;

               if( nIndex > 1 )
                  _hb_jsonCtxAdd( pCtx, ",", 1 );

               if( pCtx->fHuman )
               {
                  _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
                  _hb_jsonCtxAddIndent( pCtx, ( nLevel + 1 ) * INDENT_SIZE );
               }
               _hb_jsonEncode( pKey, pCtx, nLevel + 1, HB_FALSE );

               if( pCtx->fHuman )
               {
                  _hb_jsonCtxAdd( pCtx, ": ", 2 );
                  fEOL = ( HB_IS_ARRAY( pItem ) || HB_IS_HASH( pItem ) ) && hb_itemSize( pItem ) > 0;
               }
               else
                  _hb_jsonCtxAdd( pCtx, ":", 1 );

               _hb_jsonEncode( pItem, pCtx, nLevel + 1, fEOL );
            }
         }
         if( pCtx->fHuman )
         {
            _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );
         }
         _hb_jsonCtxAdd( pCtx, "}", 1 );
      }
      else
         _hb_jsonCtxAdd( pCtx, "{}", 2 );
   }
   else
   {
      /* All unsupported types are replacd by null */
      _hb_jsonCtxAdd( pCtx, "null", 4 );
   }
}
Ejemplo n.º 21
0
static LPTSTR s_dialogPairs( int iParam, DWORD * pdwIndex )
{
   PHB_ITEM pItem = hb_param( iParam, HB_IT_ARRAY | HB_IT_STRING ), pArrItem;
   LPTSTR lpStr = NULL;
   DWORD dwMaxIndex = 0;

   if( pItem )
   {
      HB_SIZE nLen, nSize, nTotal, n, n1, n2;

      if( HB_IS_ARRAY( pItem ) )
      {
         nSize = hb_arrayLen( pItem );
         for( n = nLen = 0; n < nSize; ++n )
         {
            pArrItem = hb_arrayGetItemPtr( pItem, n + 1 );
            if( HB_IS_STRING( pArrItem ) )
            {
               n1 = HB_ITEMCOPYSTR( pArrItem, NULL, 0 );
               if( n1 )
                  nLen += n1 * 2 + 2;
            }
            else if( hb_arrayLen( pArrItem ) >= 2 )
            {
               n1 = HB_ITEMCOPYSTR( hb_arrayGetItemPtr( pArrItem, 1 ), NULL, 0 );
               n2 = HB_ITEMCOPYSTR( hb_arrayGetItemPtr( pArrItem, 2 ), NULL, 0 );
               if( n1 && n2 )
                  nLen += n1 + n2 + 2;
            }
         }
         if( nLen )
         {
            nTotal = nLen + 1;
            lpStr = ( LPTSTR ) hb_xgrab( nTotal * sizeof( TCHAR ) );
            for( n = nLen = 0; n < nSize; ++n )
            {
               pArrItem = hb_arrayGetItemPtr( pItem, n + 1 );
               if( HB_IS_STRING( pArrItem ) )
               {
                  n1 = HB_ITEMCOPYSTR( pArrItem,
                                       lpStr + nLen, nTotal - nLen );
                  if( n1 )
                  {
                     nLen += n1 + 1;
                     n1 = HB_ITEMCOPYSTR( pArrItem,
                                          lpStr + nLen, nTotal - nLen );
                     nLen += n1 + 1;
                     dwMaxIndex++;
                  }
               }
               else if( hb_arrayLen( pArrItem ) >= 2 )
               {
                  n1 = HB_ITEMCOPYSTR( hb_arrayGetItemPtr( pArrItem, 1 ),
                                       lpStr + nLen, nTotal - nLen );
                  if( n1 )
                  {
                     n2 = HB_ITEMCOPYSTR( hb_arrayGetItemPtr( pArrItem, 2 ),
                                          lpStr + nLen + n1 + 1,
                                          nTotal - nLen - n1 - 1 );
                     if( n2 )
                     {
                        nLen += n1 + n2 + 2;
                        dwMaxIndex++;
                     }
                  }
               }
            }
            lpStr[ nLen ] = 0;
         }
      }
      else
      {
         nLen = HB_ITEMCOPYSTR( pItem, NULL, 0 );
         if( nLen )
         {
            lpStr = ( LPTSTR ) hb_xgrab( ( nLen * 2 + 3 ) * sizeof( TCHAR ) );
            HB_ITEMCOPYSTR( pItem, lpStr, nLen + 1 );
            for( n = n1 = 0; n < nLen; ++n )
            {
               if( lpStr[ n ] == 0 )
               {
                  ++n1;
                  if( lpStr[ n + 1 ] == 0 )
                     break;
               }
            }
            if( n1 == 0 )
            {
               HB_ITEMCOPYSTR( pItem, lpStr + nLen + 1, nLen + 1 );
               lpStr[ nLen * 2 + 2 ] = 0;
               dwMaxIndex = 1;
            }
            else
            {
               if( n == nLen && lpStr[ n - 1 ] != 0 )
               {
                  lpStr[ n + 1 ] = 0;
                  ++n1;
               }
               if( ( n1 & 1 ) == 0 )
                  dwMaxIndex = ( DWORD ) n1;
               else
               {
                  hb_xfree( lpStr );
                  lpStr = NULL;
               }
            }
         }
      }
   }

   if( pdwIndex )
   {
      if( dwMaxIndex < *pdwIndex )
         *pdwIndex = dwMaxIndex;
      else if( dwMaxIndex && *pdwIndex == 0 )
         *pdwIndex = 1;
   }

   return lpStr;
}
Ejemplo n.º 22
0
PHB_ITEM
hbgi_hb_clsGetInitData(HB_USHORT uiClass, HB_SIZE uiIndex)
{
   PHB_ITEM instance = hbgi_hb_clsInst(uiClass);
   return hb_arrayGetItemPtr(instance, uiIndex);
}
Ejemplo n.º 23
0
static void s_signalHandler( int sig, siginfo_t *info, void *v )
#endif
{
   UINT uiMask;
   UINT uiSig;
   PHB_ITEM pFunction, pExecArray, pRet;
   ULONG ulPos;
   int iRet;

   #if !( defined( HB_OS_OS2_GCC ) || defined( __WATCOMC__ ) )
   HB_SYMBOL_UNUSED(v);
   #endif

   // let's find the right signal handler.
   HB_CRITICAL_LOCK( s_ServiceMutex );

   // avoid working if PRG signal handling has been disabled
   if ( ! bSignalEnabled )
   {
      HB_CRITICAL_UNLOCK( s_ServiceMutex );
      return;
   }

   bSignalEnabled = FALSE;
   ulPos = hb_arrayLen( sp_hooks );
   // subsig not necessary
   uiSig = (UINT) s_translateSignal( (UINT)sig, 0 );

   while( ulPos > 0 )
   {
      pFunction = hb_arrayGetItemPtr( sp_hooks, ulPos );
      uiMask = (UINT) hb_arrayGetNI( pFunction, 1 );
      if ( uiMask & uiSig)
      {
         // we don't unlock the mutex now, even if it is
         // a little dangerous. But we are in a signal hander...
         // for now just 2 parameters
         pExecArray = hb_itemArrayNew( 3 );
         hb_arraySet( pExecArray, 1, hb_arrayGetItemPtr( pFunction, 2 ) );
         hb_arraySetNI( pExecArray, 2, uiSig );

         // the third parameter is an array:

         pRet = hb_arrayGetItemPtr( pExecArray, 3);
         #if defined( HB_OS_OS2_GCC ) || defined( __WATCOMC__ )
         hb_arrayNew( pRet, 1 );
         #elif defined( HB_OS_BSD )
         hb_arrayNew( pRet, info ? 6 : 1 );
         #else
         hb_arrayNew( pRet, 6 );
         #endif
         hb_arraySetNI( pRet, HB_SERVICE_OSSIGNAL, sig );
         #if !( defined( HB_OS_OS2_GCC ) || defined( __WATCOMC__ ) )
         #if defined( HB_OS_BSD )
         if (info)
         #endif
         {
            hb_arraySetNI( pRet, HB_SERVICE_OSSUBSIG, info->si_code );
            hb_arraySetNI( pRet, HB_SERVICE_OSERROR, info->si_errno );
            hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, (void *) info->si_addr );
            hb_arraySetNI( pRet, HB_SERVICE_PROCESS, info->si_pid );
            hb_arraySetNI( pRet, HB_SERVICE_UID, info->si_uid );
         }
         #endif

         pRet = hb_itemDo( pExecArray, 0 );
         iRet = hb_itemGetNI( pRet );
         hb_itemRelease( pRet );
         hb_itemRelease( pExecArray );

         switch( iRet )
         {
            case HB_SERVICE_HANDLED:
               bSignalEnabled = TRUE;
               HB_CRITICAL_UNLOCK( s_ServiceMutex );
               return;

            case HB_SERVICE_QUIT:
               bSignalEnabled = FALSE;
               HB_CRITICAL_UNLOCK( s_ServiceMutex );
               //TODO: A service cleanup routine
               hb_vmRequestQuit();
               #ifndef HB_THREAD_SUPPORT
                  hb_vmQuit();
                  exit(0);
               #else
                  /* Allow signals to go through pthreads */
                  s_serviceSetDflSig();
                  /* NOTICE: should be pthread_exit(0), but a bug in linuxthread prevents it:
                     calling pthread exit from a signal handler will cause infinite wait for
                     restart signal.
                     This solution is rude, while the other would allow clean VM termination...
                     but it works.
                  */
                  exit(0);
               #endif
         }
      }
      ulPos--;
   }

   bSignalEnabled = TRUE;
   /*s_serviceSetHBSig();*/

   /* TODO
   if ( uiSig != HB_SIGNAL_UNKNOWN )
   {
      if ( sa_oldAction[ sig ].sa_flags & SA_SIGINFO )
      {
         sa_oldAction[ sig ].sa_sigaction( sig, info, v );
      }
      else
      {
         sa_oldAction[ sig ].sa_handler( sig );
      }
   }*/
}
Ejemplo n.º 24
0
HB_BOOL hb_execFromArray( PHB_ITEM pParam )
{
   PHB_ITEM pArray = NULL;
   PHB_ITEM pSelf = NULL;
   HB_ULONG ulParamOffset = 0;

   if( pParam && HB_IS_ARRAY( pParam ) && ! HB_IS_OBJECT( pParam ) )
   {
      pArray = pParam;
      pParam = hb_arrayGetItemPtr( pArray, 1 );
      if( HB_IS_OBJECT( pParam ) )
      {
         pSelf = pParam;
         pParam = hb_arrayGetItemPtr( pArray, 2 );
         ulParamOffset = 2;
      }
      else
         ulParamOffset = 1;
   }

   if( pParam )
   {
      PHB_SYMB pExecSym = NULL;

      if( HB_IS_SYMBOL( pParam ) )
         pExecSym = hb_itemGetSymbol( pParam );
      else if( HB_IS_STRING( pParam ) )
         pExecSym = hb_dynsymGet( hb_itemGetCPtr( pParam ) )->pSymbol;
      else if( HB_IS_BLOCK( pParam ) && ! pSelf )
      {
         pSelf = pParam;
         pExecSym = &hb_symEval;
      }

      if( pExecSym )
      {
         int iPCount = 0;

         hb_vmPushSymbol( pExecSym );
         if( pSelf )
            hb_vmPush( pSelf );
         else
            hb_vmPushNil();

         if( pArray )
         {
            pParam = hb_arrayGetItemPtr( pArray, ++ulParamOffset );
            while( pParam && iPCount < 255 )
            {
               hb_vmPush( pParam );
               ++iPCount;
               pParam = hb_arrayGetItemPtr( pArray, ++ulParamOffset );
            }
         }

         if( pSelf )
            hb_vmSend( ( HB_USHORT ) iPCount );
         else
            hb_vmProc( ( HB_USHORT ) iPCount );

         return HB_TRUE;
      }
   }

   hb_errRT_BASE_SubstR( EG_ARG, 1099, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );

   return HB_FALSE;
}
Ejemplo n.º 25
0
/* Manager of signals for windows */
static LONG s_signalHandler( int type, int sig, PEXCEPTION_RECORD exc )
{
   HB_SIZE  nPos;
   HB_UINT  uiSig;

   /* let's find the right signal handler. */
   hb_threadEnterCriticalSectionGC( &s_ServiceMutex );

   /* avoid working if PRG signal handling has been disabled */
   if( ! s_bSignalEnabled )
   {
      hb_threadLeaveCriticalSection( &s_ServiceMutex );
      return EXCEPTION_EXECUTE_HANDLER;
   }

   s_bSignalEnabled = HB_FALSE;
   nPos = hb_arrayLen( s_pHooks );
   /* subsig not necessary */
   uiSig = ( HB_UINT ) s_translateSignal( ( HB_UINT ) type, ( HB_UINT ) sig );

   while( nPos > 0 )
   {
      PHB_ITEM pFunction;
      HB_UINT  uiMask;

      pFunction = hb_arrayGetItemPtr( s_pHooks, nPos );
      uiMask    = ( HB_UINT ) hb_arrayGetNI( pFunction, 1 );
      if( ( uiMask & uiSig ) == uiSig )
      {
         PHB_ITEM pExecArray, pRet;
         int      iRet;

         /* we don't unlock the mutex now, even if it is
            a little dangerous. But we are in a signal hander...
            for now just 2 parameters */
         pExecArray = hb_itemArrayNew( 3 );
         hb_arraySetForward( pExecArray, 1, hb_arrayGetItemPtr( pFunction, 2 ) );
         hb_arraySetNI( pExecArray, 2, uiSig );

         /* the third parameter is an array:
          * 1: low-level signal
          * 2: low-level subsignal
          * 3: low-level system error
          * 4: address that rose the signal
          * 5: process id of the signal riser
          * 6: UID of the riser
          */

         pRet = hb_arrayGetItemPtr( pExecArray, 3 );
         hb_arrayNew( pRet, 6 );

         hb_arraySetNI( pRet, HB_SERVICE_OSSIGNAL, type );
         hb_arraySetNI( pRet, HB_SERVICE_OSSUBSIG, sig );
         /* could be meaningless, but does not matter here */
         hb_arraySetNI( pRet, HB_SERVICE_OSERROR, GetLastError() );

         if( type == 0 ) /* exception */
            hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, ( void * ) exc->ExceptionAddress );
         else
            hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, NULL );

         /* TODO: */
         hb_arraySetNI( pRet, HB_SERVICE_PROCESS, GetCurrentThreadId() );
         /* TODO: */
         hb_arraySetNI( pRet, HB_SERVICE_UID, 0 );

         pRet = hb_itemDo( pExecArray, 0 );
         iRet = hb_itemGetNI( pRet );
         hb_itemRelease( pRet );
         hb_itemRelease( pExecArray );

         switch( iRet )
         {
            case HB_SERVICE_HANDLED:
               s_bSignalEnabled = HB_TRUE;
               hb_threadLeaveCriticalSection( &s_ServiceMutex );
               return EXCEPTION_CONTINUE_EXECUTION;

            case HB_SERVICE_QUIT:
               s_bSignalEnabled = HB_FALSE;
               hb_threadLeaveCriticalSection( &s_ServiceMutex );
               hb_vmRequestQuit();
#ifndef HB_THREAD_SUPPORT
               hb_vmQuit();
               exit( 0 );
#else
               hb_threadCancelInternal();
#endif
         }
      }
      nPos--;
   }

   s_bSignalEnabled = HB_TRUE;
   return EXCEPTION_EXECUTE_HANDLER;
}
Ejemplo n.º 26
0
static void s_signalHandler( int sig, siginfo_t * info, void * v )
#endif
{
   HB_UINT  uiSig;
   HB_SIZE  nPos;

   #if ! ( defined( HB_OS_OS2_GCC ) || defined( __WATCOMC__ ) )
   HB_SYMBOL_UNUSED( v );
   #endif

   /* let's find the right signal handler. */
   hb_threadEnterCriticalSectionGC( &s_ServiceMutex );

   /* avoid working if PRG signal handling has been disabled */
   if( ! s_bSignalEnabled )
   {
      hb_threadLeaveCriticalSection( &s_ServiceMutex );
      return;
   }

   s_bSignalEnabled = HB_FALSE;
   nPos = hb_arrayLen( s_pHooks );
   /* subsig not necessary */
   uiSig = ( HB_UINT ) s_translateSignal( ( HB_UINT ) sig, 0 );

   while( nPos > 0 )
   {
      PHB_ITEM pFunction;
      HB_UINT  uiMask;

      pFunction = hb_arrayGetItemPtr( s_pHooks, nPos );
      uiMask    = ( HB_UINT ) hb_arrayGetNI( pFunction, 1 );
      if( uiMask & uiSig )
      {
         PHB_ITEM pExecArray, pRet;
         int iRet;

         /* we don't unlock the mutex now, even if it is
            a little dangerous. But we are in a signal hander...
            for now just 2 parameters */
         pExecArray = hb_itemArrayNew( 3 );
         hb_arraySet( pExecArray, 1, hb_arrayGetItemPtr( pFunction, 2 ) );
         hb_arraySetNI( pExecArray, 2, uiSig );

         /* the third parameter is an array: */

         pRet = hb_arrayGetItemPtr( pExecArray, 3 );
         #if defined( HB_OS_OS2_GCC ) || defined( __WATCOMC__ )
         hb_arrayNew( pRet, 1 );
         #elif defined( HB_OS_BSD )
         hb_arrayNew( pRet, info ? 6 : 1 );
         #else
         hb_arrayNew( pRet, 6 );
         #endif
         hb_arraySetNI( pRet, HB_SERVICE_OSSIGNAL, sig );
         #if ! ( defined( HB_OS_OS2_GCC ) || defined( __WATCOMC__ ) )
         #if defined( HB_OS_BSD )
         if( info )
         #endif
         {
            hb_arraySetNI( pRet, HB_SERVICE_OSSUBSIG, info->si_code );
            #if ! defined( HB_OS_VXWORKS )
            hb_arraySetNI( pRet, HB_SERVICE_OSERROR, info->si_errno );
            hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, ( void * ) info->si_addr );
            hb_arraySetNI( pRet, HB_SERVICE_PROCESS, info->si_pid );
            hb_arraySetNI( pRet, HB_SERVICE_UID, info->si_uid );
            #endif
         }
         #endif

         pRet = hb_itemDo( pExecArray, 0 );
         iRet = hb_itemGetNI( pRet );
         hb_itemRelease( pRet );
         hb_itemRelease( pExecArray );

         switch( iRet )
         {
            case HB_SERVICE_HANDLED:
               s_bSignalEnabled = HB_TRUE;
               hb_threadLeaveCriticalSection( &s_ServiceMutex );
               return;

            case HB_SERVICE_QUIT:
               s_bSignalEnabled = HB_FALSE;
               hb_threadLeaveCriticalSection( &s_ServiceMutex );
               /* TODO: A service cleanup routine */
               hb_vmRequestQuit();
               /* Allow signals to go through pthreads */
               s_serviceSetDflSig();
               /* NOTICE: should be pthread_exit(0), but a bug in Linux threading prevents it:
                  calling pthread exit from a signal handler will cause infinite wait for
                  restart signal.
                  This solution is rude, while the other would allow clean VM termination...
                  but it works.
                */
               exit( 0 );
         }
      }
      nPos--;
   }

   s_bSignalEnabled = HB_TRUE;
   #if 0
   s_serviceSetHBSig();
   #endif

   #if 0
   if( uiSig != HB_SIGNAL_UNKNOWN )
   {
      if( s_aOldAction[ sig ].sa_flags & SA_SIGINFO )
         s_aOldAction[ sig ].sa_sigaction( sig, info, v );
      else
         s_aOldAction[ sig ].sa_handler( sig );
   }
   #endif
}
Ejemplo n.º 27
0
//-------------------------------
// Manager of signals for windows
//
static LONG s_signalHandler( int type, int sig, PEXCEPTION_RECORD exc )
{
   PHB_ITEM pFunction, pExecArray, pRet;
   ULONG ulPos;
   UINT uiSig, uiMask;
   int iRet;

   // let's find the right signal handler.
   HB_CRITICAL_LOCK( s_ServiceMutex );

   // avoid working if PRG signal handling has been disabled
   if ( ! bSignalEnabled )
   {
      HB_CRITICAL_UNLOCK( s_ServiceMutex );
      return EXCEPTION_EXECUTE_HANDLER;
   }

   bSignalEnabled = FALSE;
   ulPos = hb_arrayLen( sp_hooks );
   // subsig not necessary
   uiSig = (UINT) s_translateSignal( (UINT)type, (UINT)sig );

   while( ulPos > 0 )
   {
      pFunction = hb_arrayGetItemPtr( sp_hooks, ulPos );
      uiMask = (UINT) hb_arrayGetNI( pFunction, 1 );
      if ( (uiMask & uiSig) == uiSig )
      {
         // we don't unlock the mutex now, even if it is
         // a little dangerous. But we are in a signal hander...
         // for now just 2 parameters
         pExecArray = hb_itemArrayNew( 3 );
         hb_arraySetForward( pExecArray, 1, hb_arrayGetItemPtr( pFunction, 2 ) );
         hb_arraySetNI( pExecArray, 2, uiSig );

         /* the third parameter is an array:
         * 1: low-level signal
         * 2: low-level subsignal
         * 3: low-level system error
         * 4: address that rised the signal
         * 5: process id of the signal riser
         * 6: UID of the riser
         */

         pRet = hb_arrayGetItemPtr( pExecArray, 3);
         hb_arrayNew( pRet, 6 );

         hb_arraySetNI( pRet, HB_SERVICE_OSSIGNAL, type );
         hb_arraySetNI( pRet, HB_SERVICE_OSSUBSIG, sig );
         //could be meaningless, but does not matter here
         hb_arraySetNI( pRet, HB_SERVICE_OSERROR, GetLastError() );

         if (type == 0 ) //exception
         {
            hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, ( void * ) exc->ExceptionAddress );
         }
         else
         {
            hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, NULL );
         }
         //TODO:
         hb_arraySetNI( pRet, HB_SERVICE_PROCESS, GetCurrentThreadId() );
         //TODO:
         hb_arraySetNI( pRet, HB_SERVICE_UID, 0 );

         pRet = hb_itemDo( pExecArray, 0 );
         iRet = hb_itemGetNI( pRet );
         hb_itemRelease( pRet );
         hb_itemRelease( pExecArray );

         switch( iRet )
         {
            case HB_SERVICE_HANDLED:
               bSignalEnabled = TRUE;
               HB_CRITICAL_UNLOCK( s_ServiceMutex );
               return EXCEPTION_CONTINUE_EXECUTION;

            case HB_SERVICE_QUIT:
               bSignalEnabled = FALSE;
               HB_CRITICAL_UNLOCK( s_ServiceMutex );
               hb_vmRequestQuit();
               #ifndef HB_THREAD_SUPPORT
                  hb_vmQuit();
                  exit(0);
               #else
                  hb_threadCancelInternal();
               #endif

         }
      }
      ulPos--;
   }

   bSignalEnabled = TRUE;
   return EXCEPTION_EXECUTE_HANDLER;
}
Ejemplo n.º 28
0
Archivo: eval.c Proyecto: xharbour/core
BOOL hb_execFromArray( PHB_ITEM pFirst )
{
   register ULONG i;
   HB_SIZE        ulLen;
   ULONG          ulStart  = 1;
   PHB_ITEM       pArgs;
   PHB_ITEM       pString;
   PHB_ITEM       pSelf    = NULL;
   PHB_DYNS       pExecSym = NULL;
   PHB_SYMB       pSymbol  = NULL;

   if( pFirst == NULL || pFirst->type != HB_IT_ARRAY )
      return FALSE;

   pString  = hb_arrayGetItemPtr( pFirst, 1 );
   pArgs    = pFirst;

   if( HB_IS_OBJECT( pString ) && hb_arrayLen( pFirst ) >= 2 )
   {
      pSelf    = pString;
      pString  = hb_arrayGetItemPtr( pFirst, 2 );

      if( pString->type == HB_IT_STRING )
         pExecSym = hb_dynsymFindName( pString->item.asString.value );
      else if( pString->type == HB_IT_POINTER )
         pSymbol = ( PHB_SYMB ) hb_itemGetPtr( pString );

      ulStart = 3;
   }
   else if( pString->type == HB_IT_STRING )
   {
      pExecSym = hb_dynsymFindName( pString->item.asString.value );
      ulStart  = 2;
   }
   else if( pString->type == HB_IT_POINTER )
   {
      pSymbol  = ( PHB_SYMB ) hb_itemGetPtr( pString );
      ulStart  = 2;
   }
   else if( HB_IS_BLOCK( pString ) )
   {
      pSymbol  = &hb_symEval;
      ulStart  = 2;
   }

   if( pExecSym )
      pSymbol = pExecSym->pSymbol;

   if( pSymbol == NULL )
      return FALSE;

   hb_vmPushSymbol( pSymbol );

   if( pSelf )
      hb_vmPush( pSelf );
   else
      hb_vmPushNil();

   ulLen = hb_arrayLen( pArgs );

   /* pushing the contents of the array
    */
   for( i = ulStart; i <= ulLen; i++ )
      hb_vmPush( hb_arrayGetItemPtr( pArgs, i ) );

   if( pSelf )
      hb_vmSend( ( USHORT ) ( ulLen - ulStart + 1 ) );
   else
      hb_vmDo( ( USHORT ) ( ulLen - ulStart + 1 ) );

   return TRUE;
}