PHB_ITEM hb_errPutArgsArray( PHB_ITEM pError, PHB_ITEM pArgs ) { HB_TRACE( HB_TR_DEBUG, ( "hb_errPutArgsArray(%p, %p)", pError, pArgs ) ); hb_arraySet( pError, HB_TERROR_ARGS, pArgs ); return pError; }
PHB_ITEM hb_errPutCargo( PHB_ITEM pError, PHB_ITEM pCargo ) { HB_TRACE( HB_TR_DEBUG, ( "hb_errPutCargo(%p, %p)", pError, pCargo ) ); hb_arraySet( pError, HB_TERROR_CARGO, pCargo ); return pError; }
PHB_ITEM hbgi_hb_paramSlice(int start, int end) { PHB_ITEM args = hb_itemArrayNew(end - start); int i; for (i = start; i < end; i++) { hb_arraySet(args, i - start + 1, hb_itemParam(i)); } return args; }
static HB_ERRCODE sqlbasePutValue( SQLBASEAREAP pArea, HB_USHORT uiIndex, PHB_ITEM pItem ) { LPFIELD pField; HB_ERRCODE errCode; if( uiIndex == 0 || uiIndex > pArea->area.uiFieldCount ) return HB_FAILURE; if( ! pArea->fPositioned ) return HB_SUCCESS; if( ! pArea->fRecordChanged && SELF_GOHOT( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; errCode = HB_SUCCESS; pField = pArea->area.lpFields + ( uiIndex - 1 ); if( ( ( HB_IS_MEMO( pItem ) || HB_IS_STRING( pItem ) ) && ( pField->uiType == HB_FT_STRING || pField->uiType == HB_FT_MEMO ) ) || ( HB_IS_DATE( pItem ) && pField->uiType == HB_FT_DATE ) || ( HB_IS_TIMESTAMP( pItem ) && pField->uiType == HB_FT_TIMESTAMP ) || ( HB_IS_NUMBER( pItem ) && ( pField->uiType == HB_FT_INTEGER || pField->uiType == HB_FT_LONG || pField->uiType == HB_FT_FLOAT || pField->uiType == HB_FT_DOUBLE ) ) || ( HB_IS_LOGICAL( pItem ) && pField->uiType == HB_FT_LOGICAL ) || HB_IS_NIL( pItem ) ) { hb_arraySet( ( PHB_ITEM ) pArea->pRecord, uiIndex, pItem ); } else { PHB_ITEM pError; pError = hb_errNew(); hb_errPutGenCode( pError, EG_DATATYPE ); hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_DATATYPE ) ); hb_errPutOperation( pError, hb_dynsymName( ( PHB_DYNS ) pField->sym ) ); hb_errPutSubCode( pError, errCode ); hb_errPutFlags( pError, EF_CANDEFAULT ); errCode = SELF_ERROR( ( AREAP ) pArea, pError ); hb_itemRelease( pError ); return errCode == E_DEFAULT ? HB_SUCCESS : HB_FAILURE; } return HB_SUCCESS; }
/* $Doc$ * $FuncName$ AddToArray( <pItem>, <pReturn>, <uiPos> ) * $Description$ Add <pItem> to array <pReturn> at pos <uiPos> * $End$ */ static void AddToArray( PHB_ITEM pItem, PHB_ITEM pReturn, ULONG ulPos ) { HB_ITEM_NEW( Temp ); HB_TRACE(HB_TR_DEBUG, ("AddToArray(%p, %p, %lu)", pItem, pReturn, ulPos)); if( pItem->type == HB_IT_SYMBOL ) { int iLen = strlen( pItem->item.asSymbol.value->szName ) + 2; char *sTemp = (char *) hb_xgrab( iLen + 1 ); hb_snprintf( sTemp, iLen + 1, "[%s]", pItem->item.asSymbol.value->szName ); hb_itemPutCPtr( &Temp, sTemp, iLen ); hb_arraySetForward( pReturn, ulPos, &Temp ); // hb_itemRelease( pTemp ); /* Get rid of temporary str.*/ } else /* Normal types */ { hb_arraySet( pReturn, ulPos, pItem ); } }
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 ); } }*/ }
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; }
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 }