Exemplo n.º 1
0
static HB_BOOL hb_errGetNumCode( int * piValue, const char * szOperation )
{
   PHB_ITEM pItem = hb_param( 1, HB_IT_NUMERIC );

   if( pItem )
      *piValue = hb_itemGetNI( pItem );
   else
   {
      pItem = hb_errRT_BASE_Subst( EG_ARG, 0, NULL, szOperation,
                                   HB_ERR_ARGS_BASEPARAMS );
      if( ! pItem )
      {
         *piValue = 0;
         return HB_FALSE;
      }

      if( ! HB_IS_NUMERIC( pItem ) )
         hb_errInternal( HB_EI_ERRRECFAILURE, NULL, NULL, NULL );

      *piValue = hb_itemGetNI( pItem );
      hb_itemRelease( pItem );
   }

   return HB_TRUE;
}
Exemplo n.º 2
0
Arquivo: adsx.c Projeto: SBCamus/core
static PMIXTAG mixFindTag( ADSXAREAP pArea, PHB_ITEM pOrder )
{
   char    szTag[ MIX_MAXTAGNAMELEN + 1 ];
   PMIXTAG pTag;

   if( HB_IS_NUMBER( pOrder ) )
   {
      UNSIGNED16 usOrder = 0, usFind;

      usFind = ( UNSIGNED16 ) hb_itemGetNI( pOrder );

      AdsGetNumIndexes( pArea->adsarea.hTable, &usOrder );
      usOrder++;
      pTag = pArea->pTagList;
      while( pTag && usOrder != usFind )
         pTag = pTag->pNext;
   }
   else
   {
      hb_strncpyUpperTrim( szTag, hb_itemGetCPtr( pOrder ), MIX_MAXTAGNAMELEN );
      pTag = pArea->pTagList;
      while( pTag && hb_stricmp( szTag, pTag->szName ) )
         pTag = pTag->pNext;
   }

   return pTag;
}
Exemplo n.º 3
0
HB_BOOL hbamf_is_cls_externalizable( HB_USHORT uiClass )
{
    PHB_DYNS pSymbol = hb_dynsymGet( "__CLSMSGTYPE" );
    HB_BOOL  result  = HB_FALSE;

    /* as far as i know, there is no exported Harbour C level api for this */

    if( uiClass && pSymbol )
    {
        PHB_ITEM pRetCopy = hb_itemNew( NULL );

        hb_itemMove( pRetCopy, hb_stackReturnItem() );

        hb_vmPushDynSym( pSymbol );
        hb_vmPushNil();
        hb_vmPushInteger( uiClass );
        hb_vmPushString( "EXTERNALIZABLE", 14 );
        hb_vmDo( 2 );

        if( hb_itemGetNI( hb_stackReturnItem() ) == HB_OO_MSG_CLASSDATA )
            result = HB_TRUE;

        hb_itemMove( hb_stackReturnItem(), pRetCopy );
        hb_itemRelease( pRetCopy );
    }

    return result;
}
Exemplo n.º 4
0
int hb_MaxCol( BOOL bVisible )
{
   /* See the note about MaxRow(.t.) above */
   if( bVisible )
   {
      PHB_GT      pGT = hb_gt_Base();
      HB_GT_INFO  gtInfo;

      gtInfo.pNewVal = gtInfo.pResult = NULL;

      assert( pGT );

      HB_GTSELF_INFO( pGT, HB_GTI_VIEWPORTWIDTH, &gtInfo );

      if( gtInfo.pResult )
      {
         int iMaxCol = hb_itemGetNI( gtInfo.pResult );

         hb_itemRelease( gtInfo.pResult );
         return iMaxCol;
      }
      else
      {
         return hb_gtMaxCol();
      }
   }
   else
   {
      return hb_gtMaxCol();
   }
}
Exemplo n.º 5
0
static HB_BOOL hb_gt_gui_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_gt_gui_Info(%p,%d,%p)", pGT, iType, pInfo ) );

   switch( iType )
   {
#if defined( HB_OS_WIN )
      case HB_GTI_CLIPBOARDDATA:
         if( hb_itemType( pInfo->pNewVal ) & HB_IT_STRING )
#if defined( UNICODE )
            hb_gt_winapi_setClipboard( CF_UNICODETEXT, pInfo->pNewVal );
#else
            hb_gt_winapi_setClipboard( CF_TEXT, pInfo->pNewVal );
#endif
         else
         {
            if( pInfo->pResult == NULL )
               pInfo->pResult = hb_itemNew( NULL );
#if defined( UNICODE )
            hb_gt_winapi_getClipboard( CF_UNICODETEXT, pInfo->pResult );
#else
            hb_gt_winapi_getClipboard( CF_TEXT, pInfo->pResult );
#endif
         }
         break;

      case HB_GTI_KBDSHIFTS:
         pInfo->pResult = hb_itemPutNI( pInfo->pResult, hb_gt_winapi_getKbdState() );
         if( hb_itemType( pInfo->pNewVal ) & HB_IT_NUMERIC )
            hb_gt_winapi_setKbdState( hb_itemGetNI( pInfo->pNewVal ) );
         break;
#endif
      default:
         return HB_GTSUPER_INFO( pGT, iType, pInfo );
   }
Exemplo n.º 6
0
static void SetGet( int iFlag )
{
   int iState = 0;
   HB_GT_INFO gtInfo;

   memset( &gtInfo, 0, sizeof( gtInfo ) );

   hb_gtInfo( HB_GTI_KBDSHIFTS, &gtInfo );
   if( gtInfo.pResult )
   {
      iState = hb_itemGetNI( gtInfo.pResult );
      gtInfo.pNewVal = gtInfo.pResult;
      gtInfo.pResult = NULL;
   }

   if( HB_ISLOG( 1 ) )
   {
      gtInfo.pNewVal = hb_itemPutNI( gtInfo.pNewVal,
         hb_parl( 1 ) ? ( iState | iFlag ) : ( iState & ~iFlag ) );
      hb_gtInfo( HB_GTI_KBDSHIFTS, &gtInfo );
   }

   if( gtInfo.pNewVal )
      hb_itemRelease( gtInfo.pNewVal );
   if( gtInfo.pResult )
      hb_itemRelease( gtInfo.pResult );

   hb_retl( ( iState & iFlag ) != 0 );
}
Exemplo n.º 7
0
/*
 * Retrieve information about the current table/driver.
 */
static HB_ERRCODE hb_sdfInfo( SDFAREAP pArea, HB_USHORT uiIndex, PHB_ITEM pItem )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_sdfInfo(%p,%hu,%p)", pArea, uiIndex, pItem ) );

   switch( uiIndex )
   {
      case DBI_CANPUTREC:
         hb_itemPutL( pItem, pArea->fTransRec );
         break;

      case DBI_GETRECSIZE:
         hb_itemPutNL( pItem, pArea->uiRecordLen );
         break;

      case DBI_FULLPATH:
         hb_itemPutC( pItem, pArea->szFileName );
         break;

      case DBI_FILEHANDLE:
         hb_itemPutNInt( pItem, ( HB_NHANDLE ) hb_fileHandle( pArea->pFile ) );
         break;

      case DBI_SHARED:
         hb_itemPutL( pItem, pArea->fShared );
         break;

      case DBI_ISREADONLY:
         hb_itemPutL( pItem, pArea->fReadonly );
         break;

      case DBI_POSITIONED:
         hb_itemPutL( pItem, pArea->fPositioned );
         break;

      case DBI_DB_VERSION:
      case DBI_RDD_VERSION:
      {
         char szBuf[ 64 ];
         int iSub = hb_itemGetNI( pItem );

         if( iSub == 1 )
            hb_snprintf( szBuf, sizeof( szBuf ), "%d.%d (%s)", 0, 1, "SDF" );
         else if( iSub == 2 )
            hb_snprintf( szBuf, sizeof( szBuf ), "%d.%d (%s:%d)", 0, 1, "SDF", pArea->area.rddID );
         else
            hb_snprintf( szBuf, sizeof( szBuf ), "%d.%d", 0, 1 );
         hb_itemPutC( pItem, szBuf );
         break;
      }

      default:
         return SUPER_INFO( &pArea->area, uiIndex, pItem );
   }

   return HB_SUCCESS;
}
Exemplo n.º 8
0
void hb_socekxParamsGetStd( PHB_ITEM pParams,
                            const void ** pKeydata, int * pKeylen,
                            const void ** pIV, int * pIVlen,
                            int * pLevel, int * pStrategy )
{
   if( pParams && HB_IS_HASH( pParams ) )
   {
      PHB_ITEM pItem;

      if( pKeydata && pKeylen &&
          ( pItem = hb_hashGetCItemPtr( pParams, "key" ) ) != NULL &&
          HB_IS_STRING( pItem ) )
      {
         *pKeydata = hb_itemGetCPtr( pItem );
         *pKeylen  = ( int ) hb_itemGetCLen( pItem );
      }
      else if( pKeydata && pKeylen &&
               ( pItem = hb_hashGetCItemPtr( pParams, "pass" ) ) != NULL &&
               HB_IS_STRING( pItem ) )
      {
         *pKeydata = hb_itemGetCPtr( pItem );
         *pKeylen  = ( int ) hb_itemGetCLen( pItem );
      }
      if( pIV && pIVlen &&
          ( pItem = hb_hashGetCItemPtr( pParams, "iv" ) ) != NULL &&
          HB_IS_STRING( pItem ) )
      {
         *pIV    = hb_itemGetCPtr( pItem );
         *pIVlen = ( int ) hb_itemGetCLen( pItem );
      }
      if( pLevel &&
          ( pItem = hb_hashGetCItemPtr( pParams, "zlib" ) ) != NULL &&
          HB_IS_NUMERIC( pItem ) )
         *pLevel = hb_itemGetNI( pItem );
      if( pStrategy &&
          ( pItem = hb_hashGetCItemPtr( pParams, "zs" ) ) != NULL &&
          HB_IS_NUMERIC( pItem ) )
         *pStrategy = hb_itemGetNI( pItem );
   }
}
Exemplo n.º 9
0
static HB_BOOL s_fileConfigure( PHB_FILE pFile, int iIndex, PHB_ITEM pValue )
{
   switch( iIndex )
   {
      case HB_VF_TIMEOUT:
      {
         HB_MAXINT timeout = pFile->timeout;

         if( HB_IS_NUMERIC( pValue ) )
            pFile->timeout = hb_itemGetNInt( pValue );
         hb_itemPutNInt( pValue, timeout );
         return HB_TRUE;
      }
      case HB_VF_SHUTDOWN:
      {
         HB_SOCKET sd = hb_sockexGetHandle( pFile->sock );

         if( HB_IS_NUMERIC( pValue ) && sd != HB_NO_SOCKET )
         {
            switch( hb_itemGetNI( pValue ) )
            {
               case FO_READ:
                  hb_socketShutdown( sd, HB_SOCKET_SHUT_RD );
                  break;
               case FO_WRITE:
                  hb_socketShutdown( sd, HB_SOCKET_SHUT_WR );
                  break;
               case FO_READWRITE:
                  hb_socketShutdown( sd, HB_SOCKET_SHUT_RDWR );
                  break;
            }
         }
         hb_itemClear( pValue );
         return HB_TRUE;
      }
      case HB_VF_RDHANDLE:
      case HB_VF_WRHANDLE:
         hb_itemPutNInt( pValue, ( HB_NHANDLE ) hb_sockexGetHandle( pFile->sock ) );
         return HB_TRUE;
   }

   return HB_FALSE;
}
Exemplo n.º 10
0
void hb_socekxParamsInit( PHB_SOCKEX pSock, PHB_ITEM pParams )
{
   if( pParams && HB_IS_HASH( pParams ) )
   {
      PHB_ITEM pItem;

      if( ( pItem = hb_hashGetCItemPtr( pParams, "readahead" ) ) != NULL &&
          HB_IS_NUMERIC( pItem ) )
      {
         if( pSock->buffer == NULL )
            pSock->readahead = hb_itemGetNL( pItem );
      }
      if( ( pItem = hb_hashGetCItemPtr( pParams, "flush" ) ) != NULL &&
          HB_IS_NUMERIC( pItem ) )
         pSock->iAutoFlush = hb_itemGetNI( pItem );
      if( ( pItem = hb_hashGetCItemPtr( pParams, "redir" ) ) != NULL &&
          HB_IS_LOGICAL( pItem ) )
         pSock->fRedirAll = hb_itemGetL( pItem );
   }
}
Exemplo n.º 11
0
HB_USHORT
hbgi_hb_clsNew(const char *szClassName, int nDatas, PHB_ITEM pSuperArray)
{
   if (!s_pDyns__CLSNEW) {
      hbgihb_init(NULL);
   }
   hb_vmPushDynSym(s_pDyns__CLSNEW);
   hb_vmPushNil();
   hb_vmPushString(szClassName, strlen(szClassName));
   hb_vmPushNumInt(nDatas);
   if (!pSuperArray)
   {
      hb_vmPushNil();
   }
   else
   {
      hb_vmPush(pSuperArray);
   }
   hb_vmProc(3);
   return hb_itemGetNI(hb_stackReturnItem());
}
Exemplo n.º 12
0
int hb_MaxRow( BOOL bVisible )
{
   /*
    * if called with logical .T. parameter then return real screen high - 1
    * It gives exactly the same result in all standard GT drivers so we
    * are still Clipper compatible. The difference can appear in some extended
    * GT drivers which have additional functionality, f.e. CTW GT which
    * is upper level GT and add CTIII Window support. When it's activated
    * then MaxRow() will return current window max row and MaxRow(.t.) real
    * screen (window 0) max row what is the exact behavior of MaxRow()
    * in CT3, [druzus]
    */
   if( bVisible )
   {
      PHB_GT      pGT = hb_gt_Base();
      HB_GT_INFO  gtInfo;

      gtInfo.pNewVal = gtInfo.pResult = NULL;

      assert( pGT );

      HB_GTSELF_INFO( pGT, HB_GTI_VIEWPORTHEIGHT, &gtInfo );

      if( gtInfo.pResult )
      {
         int iMaxRow = hb_itemGetNI( gtInfo.pResult );

         hb_itemRelease( gtInfo.pResult );
         return iMaxRow;
      }
      else
      {
         return hb_gtMaxRow();
      }
   }
   else
   {
      return hb_gtMaxRow();
   }
}
Exemplo n.º 13
0
static HB_BOOL hb_sxSemName( char * szFileName )
{
   const char * szName = hb_parc( 1 );
   HB_BOOL fResult = HB_FALSE;

   if( szName && szName[ 0 ] )
   {
      hb_cdpnDup2Lower( hb_vmCDP(), szName, strlen( szName ),
                        szFileName, HB_PATH_MAX );
      szFileName[ HB_PATH_MAX - 1 ] = '\0';
      fResult = HB_TRUE;
   }
   else
   {
      AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer();

      if( pArea )
      {
         DBORDERINFO pOrderInfo;

         memset( &pOrderInfo, 0, sizeof( pOrderInfo ) );
         pOrderInfo.itmOrder = hb_param( 1, HB_IT_NUMERIC );
         if( pOrderInfo.itmOrder && hb_itemGetNI( pOrderInfo.itmOrder ) == 0 )
            pOrderInfo.itmOrder = NULL;
         pOrderInfo.itmResult = hb_itemPutC( NULL, NULL );
         SELF_ORDINFO( pArea, DBOI_NAME, &pOrderInfo );
         szName = hb_itemGetCPtr( pOrderInfo.itmResult );
         if( szName && szName[ 0 ] )
         {
            hb_cdpnDup2Lower( hb_vmCDP(), szName, strlen( szName ),
                              szFileName, HB_PATH_MAX );
            szFileName[ HB_PATH_MAX - 1 ] = '\0';
            fResult = HB_TRUE;
         }
         hb_itemRelease( pOrderInfo.itmResult );
      }
   }

   return fResult;
}
Exemplo n.º 14
0
/*
 * Retorna o valor INT de uma variavel numérica do xHarbour, criada via .PRG
 * 01/07/2008 - 08:46:31
 */
int wxMemvarGetNI( char * szVarName )
{
   HB_THREAD_STUB   
   HB_DYNS_PTR pDynVar;
   int result = 0;

   HB_TRACE(HB_TR_DEBUG, ("hb_memvarGetStrValuePtr(%s, %p)", szVarName, pulLen));

   #ifdef HB_THREAD_SUPPORT
      pDynVar = s_memvarThFindName( szVarName, &HB_VM_STACK );
   #else
      pDynVar = hb_dynsymFindName( szVarName );
   #endif

   if( pDynVar )
   {
      /* there is dynamic symbol with the requested name - check if it is
       * a memvar variable
       */
      if( pDynVar->hMemvar )
      {
         /* variable contains some data
          */
         HB_ITEM_PTR pItem = hb_memvarGetValueByHandle( pDynVar->hMemvar );

         if( HB_IS_BYREF( pItem ) )
         {
            pItem = hb_itemUnRef( pItem );   /* it is a PARAMETER variable */
         }

         if( HB_IS_NUMERIC( pItem ) )
         {
            result = hb_itemGetNI( pItem );
         }
      }
   }
   return result;
}
Exemplo n.º 15
0
BOOL xwt_gtk_base_setprop( PXWT_WIDGET widget, char *prop, PHB_ITEM pValue )
{
   BOOL ret = TRUE;
   XWT_GTK_BASE *wSelf = (PXWT_GTK_BASE) widget->widget_data;
   GtkWidget *wTop = wSelf->top_widget( widget );
   GtkWidget *wMain = wSelf->main_widget;
   char *szPropVal;

   if ( strcmp( prop, "x" ) == 0 )
   {
      wSelf->x = hb_itemGetNI(pValue);
      gtk_widget_set_uposition( wTop, wSelf->x , wSelf->y );
   }
   else if ( strcmp( prop, "y" ) == 0 )
   {
      wSelf->y = hb_itemGetNI(pValue);
      gtk_widget_set_uposition( wTop, wSelf->x , wSelf->y );
   }
   else if ( strcmp( prop, "width" ) == 0 )
   {
      wSelf->width = hb_itemGetNI(pValue);
      if ( wSelf->height > 0 )
      {
         gtk_widget_set_size_request( wTop, wSelf->width , wSelf->height );
      }
   }
   else if ( strcmp( prop, "height" ) == 0 )
   {
      wSelf->height = hb_itemGetNI(pValue);
      if ( wSelf->width > 0 )
      {
         gtk_widget_set_size_request( wTop, wSelf->width , wSelf->height );
      }
   }
   else if ( strcmp( prop, "id" ) == 0 )
   {
      wSelf->nId = hb_itemGetNI(pValue);
   }
   else if ( strcmp( prop, "broadcast" ) == 0 )
   {
      wSelf->bBroadcast = hb_itemGetL(pValue);
   }
   else if ( strcmp( prop, "visibility" ) == 0 )
   {
      szPropVal = hb_itemGetCPtr( pValue );
      if( szPropVal == NULL )
      {
         ret = FALSE;
      }
      else if ( strcmp( szPropVal, "normal" ) == 0 )
      {
         gtk_widget_show( wTop );
      }
      else if ( strcmp( szPropVal, "hidden" ) == 0 )
      {
         gtk_widget_hide( wTop );
      }
      else
      {
         ret = FALSE;
      }
   }
   else if ( strcmp( prop, "focus" ) == 0 )
   {
      if( hb_itemGetL( pValue ) )
      {
         gtk_widget_grab_focus( wTop );
      }
      else
      {
         ret = FALSE; // can't just give away focus
      }
   }
   // fgcolor
   else if ( strcmp( prop, "fgcolor" ) == 0 )
   {
   
     GdkColor color;
     szPropVal  = hb_itemGetCPtr( pValue ) ;
     if ( szPropVal )
     {
     wSelf->fgColor = hb_itemGetCPtr( pValue ) ;
     gdk_color_parse (wSelf->fgColor, &color);
     switch( widget->type )
     {

            case XWT_TYPE_TOGGLEBUTTON:
            case XWT_TYPE_RADIOBUTTON:
            case XWT_TYPE_CHECKBOX:
      	       widget_set_color(wTop, &color,1);
	       break;
            case XWT_TYPE_BUTTON:	    
	    case XWT_TYPE_LABEL:
      	       widget_set_color(wMain, &color,1);
	       break;
      }	

     }
     else
     { 
        ret = FALSE ; 
     }
   }
   
   else if ( strcmp( prop, "bgcolor" ) == 0 )
   {
   
     GdkColor color;
          szPropVal  = hb_itemGetCPtr( pValue ) ;
     if ( szPropVal ) 
     {
      wSelf->bgColor = hb_itemGetCPtr( pValue ) ;
     gdk_color_parse (wSelf->bgColor, &color);
//     widget_set_color(GTK_LABEL(wMain), &color,2 );
     switch( widget->type )
     {

            case XWT_TYPE_TOGGLEBUTTON:
            case XWT_TYPE_RADIOBUTTON:
            case XWT_TYPE_CHECKBOX:
      	       widget_set_color(wTop, &color,2);
	       break;
            case XWT_TYPE_BUTTON:	    
	    case XWT_TYPE_LABEL:	    
      	       widget_set_color(wMain, &color,2);
	       break;
      }	
}
     else
     { 
        ret = FALSE ; 
     }
   }

   else if ( strcmp( prop, "textcolor" ) == 0 )
   {
      GdkColor color;
       szPropVal  = hb_itemGetCPtr( pValue ) ;
     if ( szPropVal ) 

      {
            wSelf->textColor = hb_itemGetCPtr( pValue ) ;
      gdk_color_parse (wSelf->textColor, &color);

//      widget_set_color(GTK_LABEL(wMain), &color,4 );
     switch( widget->type )
     {

            case XWT_TYPE_TOGGLEBUTTON:
            case XWT_TYPE_RADIOBUTTON:
            case XWT_TYPE_CHECKBOX:
      	       widget_set_color(wTop, &color,4);
	       break;
            case XWT_TYPE_BUTTON:	    	    
	    case XWT_TYPE_LABEL:	    
      	       widget_set_color(wMain, &color,4);
	       break;
      }	

}
     else
     { 
        ret = FALSE ; 
     }
   }
   else if ( strcmp( prop, "basecolor" ) == 0 )
   {
      GdkColor color;
           szPropVal  = hb_itemGetCPtr( pValue ) ;
     if ( szPropVal ) {

    wSelf->baseColor = hb_itemGetCPtr( pValue ) ;
      gdk_color_parse (wSelf->baseColor, &color);

//      widget_set_color(GTK_LABEL(wMain), &color,3 );
      switch( widget->type )
      {

            case XWT_TYPE_TOGGLEBUTTON:
            case XWT_TYPE_RADIOBUTTON:
            case XWT_TYPE_CHECKBOX:
      	       widget_set_color(wTop, &color,3);
	       break;
            case XWT_TYPE_BUTTON:	    
	    case XWT_TYPE_LABEL:	    
      	       widget_set_color(wMain, &color,3);
	       break;
      }	
}
     else
     { 
        ret = FALSE ; 
     }      

   }

   else
   {
      ret = FALSE;
   }

   return ret;
}
Exemplo n.º 16
0
static void s_inetRecvPattern( const char * const * patterns, int * patternsizes,
                               int iPatternsCount, int iParam )
{
   PHB_SOCKET_STRUCT socket = HB_PARSOCKET( 1 );
   PHB_ITEM pResult         = hb_param( iParam, HB_IT_BYREF );
   PHB_ITEM pMaxSize        = hb_param( iParam + 1, HB_IT_NUMERIC );
   PHB_ITEM pBufferSize     = hb_param( iParam + 2, HB_IT_NUMERIC );

   char cChar = '\0';
   char * buffer;
   int iPaternFound = 0;
   int iTimeElapsed = 0;
   int iPos = 0;
   int iLen;
   int iAllocated, iBufferSize, iMax;
   int i;

   if( socket == NULL )
   {
      hb_inetErrRT();
      return;
   }
   else if( ! hb_inetIsOpen( socket ) )
   {
      if( pResult )
         hb_itemPutNI( pResult, -1 );
      hb_retc_null();
      return;
   }


   iBufferSize = pBufferSize ? hb_itemGetNI( pBufferSize ) : 80;
   iMax = pMaxSize ? hb_itemGetNI( pMaxSize ) : 0;

   socket->iError = HB_INET_ERR_OK;

   buffer = ( char * ) hb_xgrab( iBufferSize );
   iAllocated = iBufferSize;

   do
   {
      if( iPos == iAllocated - 1 )
      {
         iAllocated += iBufferSize;
         buffer = ( char * ) hb_xrealloc( buffer, iAllocated );
      }

      iLen = s_inetRecv( socket, &cChar, 1, HB_TRUE, socket->iTimeout );
      if( iLen == -1 && s_inetIsTimeout( socket ) )
      {
         iLen = -2;     /* this signals timeout */
         if( socket->pPeriodicBlock )
         {
            HB_BOOL fResult;

            iTimeElapsed += socket->iTimeout;
            hb_execFromArray( socket->pPeriodicBlock );
            fResult = hb_parl( -1 ) && hb_vmRequestQuery() == 0;

            if( fResult &&
                ( socket->iTimeLimit == -1 || iTimeElapsed < socket->iTimeLimit ) )
               iLen = 1;
         }
      }
      else if( iLen > 0 )
      {
         buffer[ iPos++ ] = cChar;
         for( i = 0; i < iPatternsCount; ++i )
         {
            if( patternsizes[ i ] <= iPos &&
                cChar == patterns[ i ][ patternsizes[ i ] - 1 ] )
            {
               if( memcmp( buffer + iPos - patternsizes[ i ],
                           patterns[ i ], patternsizes[ i ] ) == 0 )
               {
                  iPaternFound = i + 1;
                  break;
               }
            }
         }
      }
   }
   while( iLen > 0 && iPaternFound == 0 && ( iMax == 0 || iPos < iMax ) );

   if( iPaternFound )
   {
      socket->iCount = iPos;
      if( pResult )
         hb_itemPutNI( pResult, iPos );
      hb_retclen_buffer( buffer, iPos - patternsizes[ iPaternFound - 1 ] );
   }
   else
   {
      if( iLen == 0 )
         socket->iError = HB_INET_ERR_CLOSEDCONN;
      else if( iLen < 0 )
         hb_inetGetError( socket );
      else
      {
         socket->iError = HB_INET_ERR_BUFFOVERRUN;
         iLen = -1;
      }
      if( pResult )
         hb_itemPutNI( pResult, iLen );
      hb_xfree( buffer );
      hb_retc_null();
   }
}
Exemplo n.º 17
0
// 26/07/2008 - 11:32:47
static
void printf_add_conv( PPrintInfo pInfo, PHB_ITEM pItem )
{
    char flag = 0;
    int width = 0;
    int precision = 0;
    char specifier = '\0';
    char m = '\0';
    char c;
    char mask[20];
    const char *t1;
    const char *t2;

    char * cValue;
    double dValue;
    ULONG  Length;

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

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

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

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

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

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

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

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

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

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

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

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

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

            c = pInfo->Mask[0];
        }

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

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

            t2 = pInfo->Mask;

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

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

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

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

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

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

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

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

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

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

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

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

            default:
                break;
            }
            break;
        } else {
            pInfo->Mask ++;
            pInfo->msk_len--;
        }
    }
}
Exemplo n.º 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 );
}
Exemplo n.º 19
0
Arquivo: math.c Projeto: emazv72/core
static int hb_matherrblock( HB_MATH_EXCEPTION * pexc )
{
   PHB_MATHERRDATA pMathErr = hb_mathErrData();
   int retval;

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

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

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

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

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

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

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

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

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

   if( pMathErr->prevHandler )
   {
      if( pexc->handled )
      {
         /* the error is handled, so simply inform the previous handler */
         ( *pMathErr->prevHandler )( pexc );
      }
      else
      {
         /* else go on error handling within previous handler */
         retval = ( *pMathErr->prevHandler )( pexc );
      }
   }
   return retval;
}
Exemplo n.º 20
0
static void s_xhb_bitOper( int iOper )
{
   PHB_ITEM pItem1 = hb_param( 1, HB_IT_ANY ),
            pItem2 = hb_param( 2, HB_IT_ANY );
   HB_SIZE nLen1 = hb_itemGetCLen( pItem1 ),
           nLen2 = hb_itemGetCLen( pItem2 );

   if( pItem1 && pItem2 )
   {
      if( HB_IS_NUMERIC( pItem1 ) && ( HB_IS_NUMERIC( pItem2 ) || nLen2 == 1 ) )
      {
         HB_MAXINT nVal1 = hb_itemGetNInt( pItem1 ),
                   nVal2 = nLen2 == 1 ? ( HB_BYTE ) hb_itemGetCPtr( pItem1 )[ 0 ] :
                                        hb_itemGetNInt( pItem2 );
         switch( iOper )
         {
            case XHB_AND:
               nVal1 &= nVal2;
               break;
            case XHB_OR:
               nVal1 |= nVal2;
               break;
            default: /* XHB_XOR */
               nVal1 ^= nVal2;
               break;
         }
         hb_retnint( nVal1 );
         return;
      }

      if( HB_IS_STRING( pItem1 ) && HB_IS_STRING( pItem2 ) )
      {
         if( ( nLen1 | nLen2 ) != 0 )
         {
            const char * pStr1 = hb_itemGetCPtr( pItem1 ),
                       * pStr2 = hb_itemGetCPtr( pItem2 );
            char * pRet = ( char * ) hb_xmemdup( pStr1, nLen1 + 1 );
            HB_SIZE n1, n2;

            switch( iOper )
            {
               case XHB_AND:
                  for( n1 = n2 = 0; n1 < nLen1; n1++ )
                  {
                     pRet[ n1 ] &= pStr2[ n2 ];
                     if( ++n2 == nLen2 )
                        n2 = 0;
                  }
                  break;
               case XHB_OR:
                  for( n1 = n2 = 0; n1 < nLen1; n1++ )
                  {
                     pRet[ n1 ] |= pStr2[ n2 ];
                     if( ++n2 == nLen2 )
                        n2 = 0;
                  }
                  break;
               default: /* XHB_XOR */
                  for( n1 = n2 = 0; n1 < nLen1; n1++ )
                  {
                     pRet[ n1 ] ^= pStr2[ n2 ];
                     if( ++n2 == nLen2 )
                        n2 = 0;
                  }
                  break;
            }
            hb_retclen_buffer( pRet, nLen1 );
         }
         else
            hb_itemReturn( pItem1 );
         return;
      }

      if( HB_IS_STRING( pItem1 ) && ( HB_IS_NUMERIC( pItem2 ) || nLen2 == 1 ) )
      {
         if( nLen1 )
         {
            const char * pStr = hb_itemGetCPtr( pItem1 );
            char * pRet = ( char * ) hb_xmemdup( pStr, nLen1 + 1 );
            char cVal = nLen2 == 1 ? hb_itemGetCPtr( pItem2 )[ 0 ] :
                                     ( char ) hb_itemGetNI( pItem2 );

            nLen2 = nLen1;
            switch( iOper )
            {
               case XHB_AND:
                  while( nLen2-- )
                     pRet[ nLen2 ] &= cVal;
                  break;
               case XHB_OR:
                  while( nLen2-- )
                     pRet[ nLen2 ] |= cVal;
                  break;
               default: /* XHB_XOR */
                  while( nLen2-- )
                     pRet[ nLen2 ] ^= cVal;
                  break;
            }
            hb_retclen_buffer( pRet, nLen1 );
         }
         else
            hb_itemReturn( pItem1 );
         return;
      }

      if( ( HB_IS_NUMERIC( pItem1 ) || nLen1 == 1 ) && HB_IS_STRING( pItem2 ) )
      {
         const char * pStr = hb_itemGetCPtr( pItem2 );
         int iVal = nLen1 == 1 ? hb_itemGetCPtr( pItem1 )[ 0 ] :
                                 hb_itemGetNI( pItem1 );

         switch( iOper )
         {
            case XHB_AND:
               while( nLen2 )
                  iVal &= ( HB_UCHAR ) pStr[ --nLen2 ];
               break;
            case XHB_OR:
               while( nLen2 )
                  iVal |= ( HB_UCHAR ) pStr[ --nLen2 ];
               break;
            default: /* XHB_XOR */
               while( nLen2 )
                  iVal ^= ( HB_UCHAR ) pStr[ --nLen2 ];
               break;
         }
         hb_retni( iVal );
         return;
      }
   }

   hb_errRT_BASE_SubstR( EG_ARG, 1088, NULL,
                         iOper == XHB_AND ? "&" : ( iOper == XHB_OR ? "|" : "^^" ),
                         2, pItem1, pItem2 );
}
Exemplo n.º 21
0
static PHB_SOCKEX s_sockexNext( PHB_SOCKEX pSock, PHB_ITEM pParams )
{
   PHB_SOCKEX pSockNew = NULL;

   if( pSock )
   {
      HB_BOOL fDecompressIn = HB_TRUE, fCompressOut = HB_TRUE;
      int level = HB_ZLIB_COMPRESSION_DEFAULT,
          strategy = HB_ZLIB_STRATEGY_DEFAULT,
          windowBitsIn = MAX_WBITS, windowBitsOut = MAX_WBITS;

      if( pParams && HB_IS_HASH( pParams ) )
      {
         PHB_ITEM pItem;

         if( ( pItem = hb_hashGetCItemPtr( pParams, "zlib" ) ) != NULL &&
             HB_IS_NUMERIC( pItem ) )
            level = hb_itemGetNI( pItem );
         if( ( pItem = hb_hashGetCItemPtr( pParams, "zs" ) ) != NULL &&
             HB_IS_NUMERIC( pItem ) )
            strategy = hb_itemGetNI( pItem );

         if( ( pItem = hb_hashGetCItemPtr( pParams, "gzin" ) ) != NULL &&
             HB_IS_LOGICAL( pItem ) )
         {
            fDecompressIn = hb_itemGetL( pItem );
            if( fDecompressIn )
               windowBitsIn += 16;
         }
         if( ( pItem = hb_hashGetCItemPtr( pParams, "zin" ) ) != NULL &&
             HB_IS_LOGICAL( pItem ) )
         {
            if( windowBitsIn == MAX_WBITS )
               fDecompressIn = hb_itemGetL( pItem );
            else if( hb_itemGetL( pItem ) )
               windowBitsIn += 16;
         }

         if( ( pItem = hb_hashGetCItemPtr( pParams, "gzout" ) ) != NULL &&
             HB_IS_LOGICAL( pItem ) )
         {
            fCompressOut = hb_itemGetL( pItem );
            if( fCompressOut )
               windowBitsOut += 16;
         }
         if( ( pItem = hb_hashGetCItemPtr( pParams, "zout" ) ) != NULL &&
             HB_IS_LOGICAL( pItem ) && windowBitsOut == MAX_WBITS )
            fCompressOut = hb_itemGetL( pItem );
      }

      if( level != HB_ZLIB_COMPRESSION_DISABLE &&
          ( fDecompressIn || fCompressOut ) )
      {
         PHB_SOCKEX_Z pZ = ( PHB_SOCKEX_Z ) hb_xgrabz( sizeof( HB_SOCKEX_Z ) );

         pSockNew = ( PHB_SOCKEX ) hb_xgrabz( sizeof( HB_SOCKEX ) );
         pSockNew->sd = HB_NO_SOCKET;
         pSockNew->fRedirAll = HB_TRUE;
         pSockNew->pFilter = &s_sockFilter;

         pSockNew->cargo = ( void * ) pZ;
         pZ->z_read.zalloc = s_zsock_zalloc;
         pZ->z_read.zfree  = s_zsock_zfree;
         pZ->z_read.opaque = Z_NULL;

         pZ->z_write.zalloc = s_zsock_zalloc;
         pZ->z_write.zfree  = s_zsock_zfree;
         pZ->z_write.opaque = Z_NULL;

         pZ->z_read.next_in  = NULL;
         pZ->z_read.avail_in = 0;

         if( level != Z_DEFAULT_COMPRESSION &&
             !( level >= Z_NO_COMPRESSION && level <= Z_BEST_COMPRESSION ) )
            level = Z_DEFAULT_COMPRESSION;

         if( strategy != Z_FILTERED    &&
#if defined( Z_RLE )
             strategy != Z_RLE         &&
#endif
#if defined( Z_FIXED )
             strategy != Z_FIXED       &&
#endif
             strategy != Z_HUFFMAN_ONLY )
            strategy = Z_DEFAULT_STRATEGY;

         if( fDecompressIn && level != HB_ZLIB_COMPRESSION_DISABLE )
         {
            /* MAX_WBITS=15, decompression - support for formats:
             * -15: raw, 15: ZLIB, 31: GZIP, 47: ZLIB+GZIP
             */
            if( inflateInit2( &pZ->z_read, windowBitsIn ) == Z_OK )
            {
               pZ->fDecompressIn = HB_TRUE;
               pZ->rdbuf = ( HB_BYTE * ) hb_xgrab( HB_ZSOCK_RDBUFSIZE );
            }
            else
               level = HB_ZLIB_COMPRESSION_DISABLE;
         }

         if( fCompressOut && level != HB_ZLIB_COMPRESSION_DISABLE )
         {
            /* MAX_WBITS=15, compression format:
             * -15: raw, 15: ZLIB (+6 bytes), 31: GZIP(+18 bytes)
             */
            if( deflateInit2( &pZ->z_write, level,
                              Z_DEFLATED, windowBitsOut, HB_ZSOCK_MEM_LEVEL,
                              strategy ) == Z_OK )
            {
               pZ->fCompressOut = HB_TRUE;
               pZ->wrbuf = ( HB_BYTE * ) hb_xgrab( HB_ZSOCK_WRBUFSIZE );
               pZ->z_write.next_out  = ( Bytef * ) pZ->wrbuf;
               pZ->z_write.avail_out = HB_ZSOCK_WRBUFSIZE;
            }
            else
               level = HB_ZLIB_COMPRESSION_DISABLE;
         }

         if( level != HB_ZLIB_COMPRESSION_DISABLE )
         {
            pSockNew->sd = pSock->sd;
            pSockNew->fShutDown = pSock->fShutDown;
            pSockNew->iAutoFlush = pSock->iAutoFlush;
            pZ->sock = pSock;
            hb_socekxParamsInit( pSockNew, pParams );
         }
         else
         {
            s_sockexClose( pSockNew, HB_FALSE );
            pSockNew = NULL;
         }
      }
   }

   return pSockNew;
}
Exemplo n.º 22
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 );
      }
   }*/
}
Exemplo n.º 23
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
}
Exemplo n.º 24
0
static HB_UINT SCItm( char * cBuffer, HB_UINT ulMaxBuf, char * cParFrm, int iCOut, int IsIndW,
                      int iIndWidth, int IsIndP, int iIndPrec,
                      PHB_ITEM pItmPar )
{
   HB_UINT s;

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

      switch( iCOut )
      {
         case 'p':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iInd, hb_itemGetPtr( pItmPar ) );
            break;
         case 's': case 'S':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iInd, hb_itemGetCPtr( pItmPar ) );
            break;
         case 'e': case 'E': case 'f': case 'g': case 'G': case 'a': case 'A':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iInd, hb_itemGetND( pItmPar ) );
            break;
         /* case 'c': case 'C': case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': */
         default:
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iInd,
                             HB_IS_LONG( pItmPar ) ? hb_itemGetNL( pItmPar ) : hb_itemGetNI( pItmPar ) );
      }
   }
   else
   {
      switch( iCOut )
      {
         case 'p':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, hb_itemGetPtr( pItmPar ) );
            break;
         case 's': case 'S':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, hb_itemGetCPtr( pItmPar ) );
            break;
         case 'e': case 'E': case 'f': case 'g': case 'G': case 'a': case 'A':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, hb_itemGetND( pItmPar ) );
            break;
         /* case 'c': case 'C': case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': */
         default:
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm,
                             HB_IS_LONG( pItmPar ) ? hb_itemGetNL( pItmPar ) : hb_itemGetNI( pItmPar ) );
      }
   }
   return s;
}
Exemplo n.º 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;
}
Exemplo n.º 26
0
LOGFONT * hbwapi_par_LOGFONT( LOGFONT * p, int iParam, HB_BOOL bMandatory )
{
   PHB_ITEM pStru = hb_param( iParam, HB_IT_ANY );

   void * hfFaceName;
   LPCTSTR pfFaceName;
   HB_SIZE nLen;

   memset( p, 0, sizeof( LOGFONT ) );

   if( pStru && HB_IS_HASH( pStru ) )
   {
      p->lfHeight         = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "lfHeight"         ) );
      p->lfWidth          = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "lfWidth"          ) );
      p->lfEscapement     = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "lfEscapement"     ) );
      p->lfOrientation    = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "lfOrientation"    ) );
      p->lfWeight         = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "lfWeight"         ) );
      p->lfItalic         = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfItalic"         ) );
      p->lfUnderline      = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfUnderline"      ) );
      p->lfStrikeOut      = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfStrikeOut"      ) );
      p->lfCharSet        = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfCharSet"        ) );
      p->lfOutPrecision   = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfOutPrecision"   ) );
      p->lfClipPrecision  = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfClipPrecision"  ) );
      p->lfQuality        = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfQuality"        ) );
      p->lfPitchAndFamily = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfPitchAndFamily" ) );

      pfFaceName = HB_ITEMGETSTR( hb_hashGetCItemPtr( pStru, "lfFaceName" ), &hfFaceName, &nLen );

      if( nLen > ( LF_FACESIZE - 1 ) )
         nLen = LF_FACESIZE - 1;

      memcpy( p->lfFaceName, pfFaceName, nLen * sizeof( TCHAR ) );
      p->lfFaceName[ nLen ] = TEXT( '\0' );

      hb_strfree( hfFaceName );

      return p;
   }
   else if( pStru && HB_IS_ARRAY( pStru ) && hb_arrayLen( pStru ) >= 14 )
   {
      p->lfHeight         = ( LONG ) hb_arrayGetNL( pStru, 1 );
      p->lfWidth          = ( LONG ) hb_arrayGetNL( pStru, 2 );
      p->lfEscapement     = ( LONG ) hb_arrayGetNL( pStru, 3 );
      p->lfOrientation    = ( LONG ) hb_arrayGetNL( pStru, 4 );
      p->lfWeight         = ( LONG ) hb_arrayGetNL( pStru, 5 );
      p->lfItalic         = ( BYTE ) hb_arrayGetNI( pStru, 6 );
      p->lfUnderline      = ( BYTE ) hb_arrayGetNI( pStru, 7 );
      p->lfStrikeOut      = ( BYTE ) hb_arrayGetNI( pStru, 8 );
      p->lfCharSet        = ( BYTE ) hb_arrayGetNI( pStru, 9 );
      p->lfOutPrecision   = ( BYTE ) hb_arrayGetNI( pStru, 10 );
      p->lfClipPrecision  = ( BYTE ) hb_arrayGetNI( pStru, 11 );
      p->lfQuality        = ( BYTE ) hb_arrayGetNI( pStru, 12 );
      p->lfPitchAndFamily = ( BYTE ) hb_arrayGetNI( pStru, 13 );

      pfFaceName = HB_ARRAYGETSTR( pStru, 14, &hfFaceName, &nLen );

      if( nLen > ( LF_FACESIZE - 1 ) )
         nLen = LF_FACESIZE - 1;

      memcpy( p->lfFaceName, pfFaceName, nLen * sizeof( TCHAR ) );
      p->lfFaceName[ nLen ] = TEXT( '\0' );

      hb_strfree( hfFaceName );

      return p;
   }
   else if( bMandatory )
      return p;

   return NULL;
}
Exemplo n.º 27
0
/*
 * Retrieve information about the current table/driver.
 */
static HB_ERRCODE hb_delimInfo( DELIMAREAP pArea, HB_USHORT uiIndex, PHB_ITEM pItem )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_delimInfo(%p,%hu,%p)", pArea, uiIndex, pItem ) );

   switch( uiIndex )
   {
      case DBI_CANPUTREC:
         hb_itemPutL( pItem, pArea->fTransRec );
         break;

      case DBI_GETRECSIZE:
         hb_itemPutNL( pItem, pArea->uiRecordLen );
         break;

      case DBI_GETDELIMITER:
      {
         char szDelim[ 2 ];
         szDelim[ 0 ] = pArea->cDelim;
         szDelim[ 1 ] = '\0';
         hb_itemPutC( pItem, szDelim );
         break;
      }
      case DBI_SETDELIMITER:
         if( hb_itemType( pItem ) & HB_IT_STRING )
         {
            const char * szDelim = hb_itemGetCPtr( pItem );

            if( hb_stricmp( szDelim, "BLANK" ) == 0 )
            {
               pArea->cDelim = '\0';
               pArea->cSeparator = ' ';
            }
#ifndef HB_CLP_STRICT
            else if( hb_stricmp( szDelim, "PIPE" ) == 0 )
            {
               pArea->cDelim = '\0';
               pArea->cSeparator = '|';
            }
            else if( hb_stricmp( szDelim, "TAB" ) == 0 )
            {
               pArea->cDelim = '\0';
               pArea->cSeparator = '\t';
            }
            else
#else
            else if( *szDelim )
#endif
            {
               pArea->cDelim = *szDelim;
            }
         }
         /*
          * a small trick which allow to set character field delimiter and
          * field separator in COPY TO ... and APPEND FROM ... commands as
          * array. F.e.:
          *    COPY TO test DELIMITED WITH ({"","|"})
          */
#ifndef HB_CLP_STRICT
         else if( hb_itemType( pItem ) & HB_IT_ARRAY )
         {
            char cSeparator;

            if( hb_arrayGetType( pItem, 1 ) & HB_IT_STRING )
               pArea->cDelim = *hb_arrayGetCPtr( pItem, 1 );

            cSeparator = *hb_arrayGetCPtr( pItem, 2 );
            if( cSeparator )
               pArea->cSeparator = cSeparator;
         }
#endif
         break;

      case DBI_SEPARATOR:
      {
         char szSeparator[ 2 ];
         const char * szNew = hb_itemGetCPtr( pItem );
         szSeparator[ 0 ] = pArea->cSeparator;
         szSeparator[ 1 ]  = '\0';
         if( *szNew )
            pArea->cSeparator = *szNew;
         hb_itemPutC( pItem, szSeparator );
         break;
      }
      case DBI_FULLPATH:
         hb_itemPutC( pItem, pArea->szFileName);
         break;

      case DBI_FILEHANDLE:
         hb_itemPutNInt( pItem, ( HB_NHANDLE ) hb_fileHandle( pArea->pFile ) );
         break;

      case DBI_SHARED:
         hb_itemPutL( pItem, pArea->fShared );
         break;

      case DBI_ISREADONLY:
         hb_itemPutL( pItem, pArea->fReadonly );
         break;

      case DBI_POSITIONED:
         hb_itemPutL( pItem, pArea->fPositioned );
         break;

      case DBI_DB_VERSION:
      case DBI_RDD_VERSION:
      {
         char szBuf[ 64 ];
         int iSub = hb_itemGetNI( pItem );

         if( iSub == 1 )
            hb_snprintf( szBuf, sizeof( szBuf ), "%d.%d (%s)", 0, 1, "DELIM" );
         else if( iSub == 2 )
            hb_snprintf( szBuf, sizeof( szBuf ), "%d.%d (%s:%d)", 0, 1, "DELIM", pArea->area.rddID );
         else
            hb_snprintf( szBuf, sizeof( szBuf ), "%d.%d", 0, 1 );
         hb_itemPutC( pItem, szBuf );
         break;
      }

      default:
         return SUPER_INFO( &pArea->area, uiIndex, pItem );
   }
Exemplo n.º 28
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;
}
Exemplo n.º 29
0
Arquivo: adsx.c Projeto: SBCamus/core
static HB_ERRCODE adsxOrderInfo( ADSXAREAP pArea, HB_USHORT uiIndex, LPDBORDERINFO pOrderInfo )
{
   PMIXTAG pTag = pArea->pTagCurrent;

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

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

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

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

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

               pTag = pTag->pNext;
            }
         }
      }

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

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

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

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

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

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

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

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

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

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

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

            ulPos = hb_itemGetNL( pOrderInfo->itmNewVal );

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

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

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

            pKey = mixKeyEval( pTag, pArea );

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

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

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

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

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

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

            pKey = mixKeyEval( pTag, pArea );

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

            mixKeyFree( pKey );

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

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

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

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

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

      case DBOI_ORDERCOUNT:
      {
         UNSIGNED16 usOrder = 0;

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

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

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

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

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

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

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

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

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