static HB_BOOL hb_ctGetWinCord( int * piTop, int * piLeft, int * piBottom, int * piRight ) { int iMaxRow = hb_gtMaxRow(); int iMaxCol = hb_gtMaxCol(); hb_gtGetPosEx( piTop, piLeft ); if( HB_ISNUM( 1 ) ) *piTop = hb_parni( 1 ); if( HB_ISNUM( 2 ) ) *piLeft = hb_parni( 2 ); if( HB_ISNUM( 3 ) ) { *piBottom = hb_parni( 3 ); if( *piBottom > iMaxRow ) *piBottom = iMaxRow; } else *piBottom = iMaxRow; if( HB_ISNUM( 4 ) ) { *piRight = hb_parni( 4 ); if( *piRight > iMaxCol ) *piRight = iMaxCol; } else *piRight = iMaxCol; return *piTop >= 0 && *piLeft >= 0 && *piTop <= *piBottom && *piLeft <= *piRight; }
static void s_GetFileName( HB_BOOL fSave ) { void * hInitDir, * hTitle, * hDefExt; LPTSTR lpstrFilter; OPENFILENAME ofn; memset( &ofn, 0, sizeof( ofn ) ); #if defined( OPENFILENAME_SIZE_VERSION_400 ) ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; #else ofn.lStructSize = sizeof( ofn ); #endif ofn.hwndOwner = GetActiveWindow(); ofn.hInstance = GetModuleHandle( NULL ); ofn.nFilterIndex = hbwapi_par_DWORD( 6 ); ofn.lpstrFilter = lpstrFilter = s_dialogPairs( 5, &ofn.nFilterIndex ); ofn.nMaxFile = hbwapi_par_DWORD( 7 ); if( ofn.nMaxFile < 0x400 ) ofn.nMaxFile = ofn.nMaxFile == 0 ? 0x10000 : 0x400; ofn.lpstrFile = ( LPTSTR ) memset( hb_xgrab( ofn.nMaxFile * sizeof( TCHAR ) ), 0, ofn.nMaxFile * sizeof( TCHAR ) ); ofn.lpstrInitialDir = HB_PARSTR( 3, &hInitDir, NULL ); ofn.lpstrTitle = HB_PARSTR( 2, &hTitle, NULL ); ofn.Flags = HB_ISNUM( 1 ) ? hbwapi_par_DWORD( 1 ) : ( OFN_EXPLORER | OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR ); ofn.lpstrDefExt = HB_PARSTR( 4, &hDefExt, NULL ); if( ofn.lpstrDefExt && ofn.lpstrDefExt[ 0 ] == '.' ) ++ofn.lpstrDefExt; HB_ITEMCOPYSTR( hb_param( 8, HB_IT_ANY ), ofn.lpstrFile, ofn.nMaxFile ); if( fSave ? GetSaveFileName( &ofn ) : GetOpenFileName( &ofn ) ) { HB_SIZE nLen; for( nLen = 0; nLen < ofn.nMaxFile; ++nLen ) { if( ofn.lpstrFile[ nLen ] == 0 && ( nLen + 1 == ofn.nMaxFile || ofn.lpstrFile[ nLen + 1 ] == 0 ) ) break; } hb_stornint( ofn.Flags, 1 ); hb_stornint( ofn.nFilterIndex, 6 ); HB_RETSTRLEN( ofn.lpstrFile, nLen ); } else hb_retc_null(); hb_xfree( ofn.lpstrFile ); if( lpstrFilter ) hb_xfree( lpstrFilter ); hb_strfree( hInitDir ); hb_strfree( hTitle ); hb_strfree( hDefExt ); }
static void hb_PEM_read_bio( PEM_READ_BIO * func ) { BIO * bio; if( hb_BIO_is( 1 ) ) bio = hb_BIO_par( 1 ); else if( HB_ISCHAR( 1 ) ) bio = BIO_new_file( hb_parc( 1 ), "r" ); else if( HB_ISNUM( 1 ) ) bio = BIO_new_fd( hb_parni( 1 ), BIO_NOCLOSE ); else bio = NULL; if( bio ) { PHB_ITEM pPassCallback = hb_param( 2, HB_IT_EVALITEM ); if( pPassCallback ) { hb_retptr( ( *func )( bio, NULL, hb_ssl_pem_password_cb, pPassCallback ) ); } else { /* NOTE: Dropping 'const' qualifier. [vszakats] */ hb_retptr( ( *func )( bio, NULL, NULL, ( void * ) hb_parc( 2 ) ) ); } if( ! hb_BIO_is( 1 ) ) BIO_free( bio ); } else hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); }
static void hb_PEM_read_bio( PEM_READ_BIO * func, HB_PEM_TYPES type ) { BIO * bio; if( hb_BIO_is( 1 ) ) bio = hb_BIO_par( 1 ); else if( HB_ISCHAR( 1 ) ) bio = BIO_new_file( hb_parc( 1 ), "r" ); else if( HB_ISNUM( 1 ) ) bio = BIO_new_fd( hb_parni( 1 ), BIO_NOCLOSE ); else bio = NULL; if( bio ) { PHB_ITEM pPassCallback = hb_param( 2, HB_IT_EVALITEM ); pem_password_cb * cb; void * cargo, * result; if( pPassCallback ) { cb = hb_ssl_pem_password_cb; cargo = pPassCallback; } else { cb = NULL; cargo = ( void * ) hb_parc( 2 ); /* NOTE: Dropping 'const' qualifier. [vszakats] */ } result = ( *func )( bio, NULL, cb, cargo ); if( result ) { switch( type ) { case hb_PEM_X509: hb_X509_ret( ( X509 * ) result, HB_TRUE ); break; case hb_PEM_EVP_PKEY: hb_EVP_PKEY_ret( ( EVP_PKEY * ) result ); break; case hb_PEM_ANY: hb_retptr( NULL ); break; } } else hb_retptr( NULL ); if( ! hb_BIO_is( 1 ) ) BIO_free( bio ); } else hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); }
static HB_BOOL hb_numParam( int iParam, HB_MAXINT * plNum ) { if( HB_ISNUM( iParam ) ) { *plNum = hb_parnint( iParam ); return HB_TRUE; } hb_errRT_BASE_SubstR( EG_ARG, 1089, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); *plNum = 0; return HB_FALSE; }
static void hb_PEM_read_bio( PEM_READ_BIO * func, HB_BOOL fX509 ) { BIO * bio = NULL; HB_BYTE * pBuffer = NULL; HB_SIZE nSize = 0; if( hb_BIO_is( 1 ) ) bio = hb_BIO_par( 1 ); else if( HB_ISCHAR( 1 ) ) { pBuffer = hb_fileLoad( hb_parc( 1 ), 0, &nSize ); if( pBuffer ) bio = BIO_new_mem_buf( ( char * ) pBuffer, ( int ) nSize ); } else if( HB_ISNUM( 1 ) ) bio = BIO_new_fd( hb_parni( 1 ), BIO_NOCLOSE ); if( bio ) { PHB_ITEM pPassCallback = hb_param( 2, HB_IT_EVALITEM ); pem_password_cb * cb; void * cargo, * result; if( pPassCallback ) { cb = hb_ssl_pem_password_cb; cargo = pPassCallback; } else { cb = NULL; cargo = HB_UNCONST( hb_parc( 2 ) ); /* NOTE: Discarding 'const' qualifier, OpenSSL will memcpy() it */ } result = ( *func )( bio, NULL, cb, cargo ); if( fX509 && result ) hb_X509_ret( ( X509 * ) result, HB_TRUE ); else hb_retptr( result ); if( ! hb_BIO_is( 1 ) ) BIO_free( bio ); if( pBuffer ) { OPENSSL_cleanse( pBuffer, ( size_t ) nSize ); hb_xfree( pBuffer ); } } else hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); }
static int hb_ctGetClearChar( int iParam ) { int iChar; if( HB_ISNUM( iParam ) ) iChar = hb_parni( iParam ); else if( HB_ISCHAR( iParam ) ) iChar = ( HB_UCHAR ) hb_parc( iParam )[ 0 ]; else iChar = ( int ) hb_gtGetClearChar(); return iChar; }
static int hb_ctComCharParam( int iParam ) { const char * pszParam = hb_parc( iParam ); if( pszParam ) { if( hb_parclen( iParam ) > 0 ) return ( unsigned char ) pszParam[ 0 ]; } else if( HB_ISNUM( iParam ) ) return ( unsigned char ) hb_parni( iParam ); return -1; }
static PHB_FFIND _hb_fileStart( HB_BOOL fNext, HB_FATTR ulAttr ) { PHB_FFDATA pFFData = HB_GET_FFDATA(); if( hb_pcount() > 0 ) { const char * szFile = hb_parc( 1 ); if( pFFData->ffind ) { hb_fsFindClose( pFFData->ffind ); pFFData->ffind = NULL; } if( szFile ) { if( HB_ISNUM( 2 ) ) ulAttr = ( HB_FATTR ) hb_parnl( 2 ); pFFData->ulAttr = hb_parl( 3 ) ? ulAttr : HB_FA_ALL; pFFData->ffind = hb_fsFindFirst( szFile, ulAttr ); while( pFFData->ffind && pFFData->ulAttr && pFFData->ffind->attr != pFFData->ulAttr ) { if( ! hb_fsFindNext( pFFData->ffind ) ) { hb_fsFindClose( pFFData->ffind ); pFFData->ffind = NULL; } } } } else if( fNext && pFFData->ffind ) { do { if( ! hb_fsFindNext( pFFData->ffind ) ) { hb_fsFindClose( pFFData->ffind ); pFFData->ffind = NULL; break; } } while( pFFData->ulAttr && pFFData->ffind->attr != pFFData->ulAttr ); } return pFFData->ffind; }
static int hb_ctColorParam( int iParam, int iDefault ) { int iColor; if( HB_ISNUM( iParam ) ) iColor = hb_parni( iParam ); else if( hb_parclen( iParam ) > 0 ) { iColor = hb_gtColorToN( hb_parc( iParam ) ); if( iColor == -1 ) iColor = iDefault; } else iColor = iDefault; return iColor; }
static int hb_ctGetClearColor( int iParam ) { int iColor; if( HB_ISNUM( iParam ) ) iColor = hb_parni( iParam ); else if( HB_ISCHAR( iParam ) ) { iColor = hb_gtColorToN( hb_parc( iParam ) ); if( iColor == -1 ) iColor = 0; } else iColor = hb_gtGetClearColor(); return iColor; }
static void s_getPathName( _HB_GETPATHNAME getPathName ) { void * hLongPath; DWORD length = 0; LPCTSTR lpszLongPath = HB_PARSTR( 1, &hLongPath, NULL ); if( lpszLongPath ) { if( HB_ISBYREF( 2 ) ) { TCHAR buffer[ HB_PATH_MAX ]; DWORD cchBuffer = ( DWORD ) HB_SIZEOFARRAY( buffer ); LPTSTR lpszShortPath = buffer; HB_BOOL fSize = HB_ISNUM( 3 ); if( fSize ) /* the size of buffer is limited by user */ { cchBuffer = ( DWORD ) hb_parnl( 3 ); if( cchBuffer == 0 ) lpszShortPath = NULL; else if( cchBuffer > ( DWORD ) HB_SIZEOFARRAY( buffer ) ) lpszShortPath = ( LPTSTR ) hb_xgrab( cchBuffer * sizeof( TCHAR ) ); } length = getPathName( lpszLongPath, lpszShortPath, cchBuffer ); if( ! fSize && length > cchBuffer ) /* default buffer size was too small */ { cchBuffer = length; lpszShortPath = ( LPTSTR ) hb_xgrab( cchBuffer * sizeof( TCHAR ) ); length = getPathName( lpszLongPath, lpszShortPath, cchBuffer ); } hbwapi_SetLastError( GetLastError() ); HB_STORSTRLEN( lpszShortPath, length > cchBuffer ? 0 : length, 2 ); if( lpszShortPath && lpszShortPath != buffer ) hb_xfree( lpszShortPath ); } else if( getPathName ) { length = getPathName( lpszLongPath, NULL, 0 ); hbwapi_SetLastError( GetLastError() ); } } hb_retnl( length ); hb_strfree( hLongPath ); }
/* returns the numeric value of a character string representation of a number */ static void hb_val( HB_BOOL fExt ) { PHB_ITEM pText = hb_param( 1, HB_IT_STRING ); if( pText ) { const char * szText = hb_itemGetCPtr( pText ); int iWidth, iDec, iLen = ( int ) hb_itemGetCLen( pText ); HB_BOOL fDbl; HB_MAXINT lValue; double dValue; fDbl = hb_valStrnToNum( szText, iLen, &lValue, &dValue, &iDec, &iWidth ); if( fExt ) { if( HB_ISNUM( 2 ) ) iLen = hb_parni( 2 ); if( fDbl && iDec > 0 ) iLen -= iDec + 1; if( iLen > iWidth ) iWidth = iLen; else if( iLen > 0 ) { while( iWidth > iLen && *szText == ' ' ) { iWidth--; szText++; } } } if( ! fDbl ) hb_retnintlen( lValue, iWidth ); else hb_retndlen( dValue, iWidth, iDec ); } else hb_errRT_BASE_SubstR( EG_ARG, 1098, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); }
static HB_BOOL hb_sxOrdParam( LPDBORDERINFO pInfo ) { memset( pInfo, 0, sizeof( DBORDERINFO ) ); if( HB_ISCHAR( 1 ) ) { pInfo->itmOrder = hb_param( 1, HB_IT_STRING ); pInfo->atomBagName = hb_param( 2, HB_IT_STRING ); } else if( HB_ISNUM( 1 ) ) { pInfo->itmOrder = hb_param( 1, HB_IT_NUMERIC ); if( ! HB_ISNIL( 2 ) ) /* hb_pcount() > 2 */ { pInfo->atomBagName = hb_param( 2, HB_IT_NUMERIC ); if( hb_parni( 2 ) <= 0 ) return HB_FALSE; } } return HB_TRUE; }
static void hb_PEM_read_bio( PEM_READ_BIO * func ) { BIO * bio = NULL; HB_BYTE * pBuffer = NULL; HB_SIZE nSize = 0; if( hb_BIO_is( 1 ) ) bio = hb_BIO_par( 1 ); else if( HB_ISCHAR( 1 ) ) { pBuffer = hb_fileLoad( hb_parc( 1 ), 0, &nSize ); if( pBuffer ) bio = BIO_new_mem_buf( ( char * ) pBuffer, ( int ) nSize ); } else if( HB_ISNUM( 1 ) ) bio = BIO_new_fd( hb_parni( 1 ), BIO_NOCLOSE ); if( bio ) { PHB_ITEM pPassCallback = hb_param( 2, HB_IT_EVALITEM ); if( pPassCallback ) hb_retptr( ( *func )( bio, NULL, hb_ssl_pem_password_cb, pPassCallback ) ); else hb_retptr( ( *func )( bio, NULL, NULL, ( void * ) hb_parc( 2 ) ) ); /* NOTE: Dropping 'const' qualifier. [vszakats] */ if( ! hb_BIO_is( 1 ) ) BIO_free( bio ); if( pBuffer ) { OPENSSL_cleanse( pBuffer, ( size_t ) nSize ); hb_xfree( pBuffer ); } } else hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); }
/* helper function for the pad functions */ static void do_pad( int iSwitch ) { if( HB_ISCHAR( 1 ) && HB_ISNUM( 2 ) ) { const char * pcString = hb_parc( 1 ); HB_SIZE sStrLen = hb_parclen( 1 ); char * pcRet, * pc; HB_ISIZ nRetLen; HB_SIZE sRetLen; char cFill; nRetLen = hb_parns( 2 ); if( nRetLen <= 0 ) { int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) ct_error( ( HB_USHORT ) iArgErrorMode, EG_ARG, iSwitch == DO_PAD_PADLEFT ? CT_ERROR_PADLEFT : CT_ERROR_PADRIGHT, NULL, HB_ERR_FUNCNAME, 0, EF_CANDEFAULT, HB_ERR_ARGS_BASEPARAMS ); hb_retc_null(); return; } sRetLen = ( HB_SIZE ) nRetLen; if( hb_parclen( 3 ) > 0 ) cFill = *( hb_parc( 3 ) ); else if( HB_ISNUM( 3 ) ) cFill = ( char ) ( hb_parnl( 3 ) % 256 ); else cFill = 0x20; pcRet = ( char * ) hb_xgrab( sRetLen + 1 ); if( iSwitch == DO_PAD_PADLEFT ) { if( sRetLen > sStrLen ) { /* fill with cFill */ for( pc = pcRet; pc < pcRet + ( sRetLen - sStrLen ); pc++ ) *pc = cFill; hb_xmemcpy( pcRet + ( sRetLen - sStrLen ), pcString, sStrLen ); } else hb_xmemcpy( pcRet, pcString + ( sStrLen - sRetLen ), sRetLen ); } else { hb_xmemcpy( pcRet, pcString, ( sRetLen < sStrLen ? sRetLen : sStrLen ) ); if( sRetLen > sStrLen ) { /* fill with cFill */ for( pc = pcRet + sStrLen; pc < pcRet + sRetLen; pc++ ) *pc = cFill; } } hb_retclen_buffer( pcRet, sRetLen ); } else { PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, iSwitch == DO_PAD_PADLEFT ? CT_ERROR_PADLEFT : CT_ERROR_PADRIGHT, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else hb_retc_null(); } }
/* helper function for the replxxx functions */ static void do_replace( int iSwitch ) { /* suppressing return value ? */ int iNoRet = ct_getref() && HB_ISBYREF( 1 ); /* param check */ if( HB_ISCHAR( 1 ) && ( hb_parclen( 2 ) > 0 || HB_ISNUM( 2 ) ) ) { const char * pcString = hb_parc( 1 ); HB_SIZE sStrLen = hb_parclen( 1 ); char * pcRet, * pc; char cSearch, cReplace; if( sStrLen == 0 ) { if( iNoRet ) hb_ret(); else hb_retc_null(); return; } if( HB_ISNUM( 2 ) ) cReplace = ( char ) ( hb_parnl( 2 ) % 256 ); else cReplace = *( ( const char * ) hb_parc( 2 ) ); if( hb_parclen( 3 ) > 0 ) cSearch = *( ( const char * ) hb_parc( 3 ) ); else if( HB_ISNUM( 3 ) ) cSearch = ( char ) ( hb_parnl( 3 ) % 256 ); else cSearch = 0x20; pcRet = ( char * ) hb_xgrab( sStrLen + 1 ); hb_xmemcpy( pcRet, pcString, sStrLen ); if( iSwitch != DO_REPLACE_REPLRIGHT ) { pc = pcRet; while( *pc == cSearch && pc < pcRet + sStrLen ) { *pc = cReplace; pc++; } } if( iSwitch != DO_REPLACE_REPLLEFT ) { pc = pcRet + sStrLen - 1; while( *pc == cSearch && pc >= pcRet ) { *pc = cReplace; pc--; } } hb_storclen( pcRet, sStrLen, 1 ); if( iNoRet ) { hb_xfree( pcRet ); hb_ret(); } else hb_retclen_buffer( pcRet, sStrLen ); } else { PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, sulErrorSubcodes[ iSwitch ], NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else if( iNoRet ) hb_ret(); else hb_retc_null(); } }
/* helper function for the justxxx() functions */ static void do_justify( int iSwitch ) { int iNoRet = ct_getref() && HB_ISBYREF( 1 ); if( HB_ISCHAR( 1 ) ) { const char * pcString = hb_parc( 1 ); HB_SIZE sStrLen = hb_parclen( 1 ); char cJustChar; const char * pc; char * pcRet, * pcw; HB_SIZE sJustOffset; if( sStrLen == 0 ) { if( iNoRet ) hb_ret(); else hb_retc_null(); return; } if( hb_parclen( 2 ) > 0 ) cJustChar = *( hb_parc( 2 ) ); else if( HB_ISNUM( 2 ) ) cJustChar = ( char ) ( hb_parnl( 2 ) % 256 ); else cJustChar = 0x20; pcRet = ( char * ) hb_xgrab( sStrLen + 1 ); switch( iSwitch ) { case DO_JUSTIFY_JUSTLEFT: pc = pcString; sJustOffset = 0; while( *pc == cJustChar && pc < ( pcString + sStrLen ) ) { sJustOffset++; pc++; } hb_xmemcpy( pcRet, pcString + sJustOffset, sStrLen - sJustOffset ); for( pcw = pcRet + sStrLen - sJustOffset; pcw < pcRet + sStrLen; pcw++ ) *pcw = cJustChar; break; case DO_JUSTIFY_JUSTRIGHT: pc = pcString + sStrLen - 1; sJustOffset = 0; while( *pc == cJustChar && pc >= pcString ) { sJustOffset++; pc--; } for( pcw = pcRet; pcw < pcRet + sJustOffset; pcw++ ) *pcw = cJustChar; hb_xmemcpy( pcRet + sJustOffset, pcString, sStrLen - sJustOffset ); break; } hb_storclen( pcRet, sStrLen, 1 ); if( iNoRet ) { hb_ret(); hb_xfree( pcRet ); } else hb_retclen_buffer( pcRet, sStrLen ); } else { PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, iSwitch == DO_JUSTIFY_JUSTLEFT ? CT_ERROR_JUSTLEFT : CT_ERROR_JUSTRIGHT, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else if( iNoRet ) hb_ret(); else hb_retc_null(); } }
/* helper function for the token function group I */ static void do_token1( int iSwitch ) { PCT_TOKEN ct_token = ( PCT_TOKEN ) hb_stackGetTSD( &s_ct_token ); int iParamCheck = 0; int iNoRef = ct_getref() && HB_ISBYREF( 1 ); switch( iSwitch ) { case DO_TOKEN1_TOKEN: ct_token->iPreSeparator = ct_token->iPostSeparator = -1; /* no "break" here !! */ case DO_TOKEN1_ATTOKEN: case DO_TOKEN1_NUMTOKEN: case DO_TOKEN1_TOKENLOWER: case DO_TOKEN1_TOKENUPPER: iParamCheck = ( HB_ISCHAR( 1 ) ); break; } if( iParamCheck ) { const char * pcString = hb_parc( 1 ); HB_SIZE sStrLen = hb_parclen( 1 ); const char * pcSeparatorStr; HB_SIZE sSeparatorStrLen; HB_SIZE nTokenCounter = 0; HB_SIZE nSkip; const char * pcSubStr; char * pcRet = NULL; HB_SIZE sSubStrLen; HB_SIZE sRetStrLen = 0; HB_SIZE nToken = 0; HB_SIZE nSkipCnt; const char * pc; /* separator string */ sSeparatorStrLen = hb_parclen( 2 ); if( sSeparatorStrLen != 0 ) pcSeparatorStr = hb_parc( 2 ); else { pcSeparatorStr = sc_pcSeparatorStr; sSeparatorStrLen = sc_sSeparatorStrLen; } /* token counter */ if( iSwitch != DO_TOKEN1_NUMTOKEN ) nTokenCounter = hb_parns( 3 ); if( nTokenCounter == 0 ) nTokenCounter = HB_SIZE_MAX; /* skip width */ if( iSwitch == DO_TOKEN1_NUMTOKEN ) { if( HB_ISNUM( 3 ) ) nSkip = hb_parns( 3 ); else nSkip = HB_SIZE_MAX; } else { if( HB_ISNUM( 4 ) ) nSkip = hb_parns( 4 ); else nSkip = HB_SIZE_MAX; } if( nSkip == 0 ) nSkip = HB_SIZE_MAX; /* prepare return value for TOKENUPPER/TOKENLOWER */ if( iSwitch == DO_TOKEN1_TOKENLOWER || iSwitch == DO_TOKEN1_TOKENUPPER ) { if( sStrLen == 0 ) { if( iNoRef ) hb_retl( HB_FALSE ); else hb_retc_null(); return; } sRetStrLen = sStrLen; pcRet = ( char * ) hb_xgrab( sRetStrLen + 1 ); hb_xmemcpy( pcRet, pcString, sRetStrLen ); } /* find the <nTokenCounter>th token */ pcSubStr = pcString; sSubStrLen = sStrLen; /* scan start condition */ pc = pcSubStr - 1; while( nToken < nTokenCounter ) { HB_SIZE sMatchedPos = sSeparatorStrLen; /* Skip the left nSkip successive separators */ nSkipCnt = 0; do { sSubStrLen -= ( pc - pcSubStr ) + 1; pcSubStr = pc + 1; pc = ct_at_charset_forward( pcSubStr, sSubStrLen, pcSeparatorStr, sSeparatorStrLen, &sMatchedPos ); if( iSwitch == DO_TOKEN1_TOKEN ) { ct_token->iPreSeparator = ct_token->iPostSeparator; if( sMatchedPos < sSeparatorStrLen ) ct_token->iPostSeparator = pcSeparatorStr[ sMatchedPos ]; else ct_token->iPostSeparator = -1; } nSkipCnt++; } while( nSkipCnt < nSkip && pc == pcSubStr ); if( sSubStrLen == 0 ) { /* string ends with tokenizer (null string after tokenizer at end of string is not a token) */ switch( iSwitch ) { case DO_TOKEN1_TOKEN: { char cRet; hb_retc_null(); if( HB_ISBYREF( 5 ) ) { cRet = ( char ) ct_token->iPreSeparator; hb_storclen( &cRet, ( ct_token->iPreSeparator != -1 ? 1 : 0 ), 5 ); } if( HB_ISBYREF( 6 ) ) { cRet = ( char ) ct_token->iPostSeparator; hb_storclen( &cRet, ( ct_token->iPostSeparator != -1 ? 1 : 0 ), 6 ); } break; } case DO_TOKEN1_NUMTOKEN: hb_retns( nToken ); break; case DO_TOKEN1_ATTOKEN: hb_retns( 0 ); break; case DO_TOKEN1_TOKENLOWER: case DO_TOKEN1_TOKENUPPER: hb_storclen( pcRet, sRetStrLen, 1 ); if( iNoRef ) { hb_xfree( pcRet ); hb_retl( HB_FALSE ); } else hb_retclen_buffer( pcRet, sRetStrLen ); break; } return; } switch( iSwitch ) { case DO_TOKEN1_TOKEN: case DO_TOKEN1_NUMTOKEN: case DO_TOKEN1_ATTOKEN: break; case DO_TOKEN1_TOKENLOWER: if( pcSubStr != pc ) /* letters can be tokenizers, too, but they should not be lowercase'd */ *( pcRet + ( pcSubStr - pcString ) ) = ( char ) hb_charLower( ( HB_UCHAR ) *pcSubStr ); break; case DO_TOKEN1_TOKENUPPER: if( pcSubStr != pc ) /* letters can be tokenizers, too, but they should not be uppercase'd */ *( pcRet + ( pcSubStr - pcString ) ) = ( char ) hb_charUpper( ( HB_UCHAR ) *pcSubStr ); break; default: break; } nToken++; if( pc == NULL ) { /* little trick for return values */ pc = pcSubStr + sSubStrLen; /* we must leave the while loop even if we have not yet found the <nTokenCounter>th token */ break; } /* should we find the last token, but string ends with tokenizer, i.e. pc points to the last character at the moment ? -> break here ! */ if( nTokenCounter == HB_SIZE_MAX ) { if( nSkip == HB_SIZE_MAX ) { const char * t; HB_BOOL bLast = HB_TRUE; for( t = pc + 1; t < pcString + sStrLen; t++ ) { if( ! memchr( pcSeparatorStr, *t, sSeparatorStrLen ) ) { bLast = HB_FALSE; break; } } if( bLast ) break; } else if( pc + 1 == pcString + sStrLen ) break; } } switch( iSwitch ) { case DO_TOKEN1_TOKEN: { char cRet; if( nTokenCounter == HB_SIZE_MAX || nToken == nTokenCounter ) hb_retclen( pcSubStr, pc - pcSubStr ); else hb_retc_null(); if( HB_ISBYREF( 5 ) ) { cRet = ( char ) ct_token->iPreSeparator; hb_storclen( &cRet, ( ct_token->iPreSeparator != -1 ? 1 : 0 ), 5 ); } if( HB_ISBYREF( 6 ) ) { cRet = ( char ) ct_token->iPostSeparator; hb_storclen( &cRet, ( ct_token->iPostSeparator != -1 ? 1 : 0 ), 6 ); } break; } case DO_TOKEN1_NUMTOKEN: hb_retns( nToken ); break; case DO_TOKEN1_ATTOKEN: if( nTokenCounter == HB_SIZE_MAX || nToken == nTokenCounter ) hb_retns( pcSubStr - pcString + 1 ); else hb_retns( 0 ); break; case DO_TOKEN1_TOKENLOWER: case DO_TOKEN1_TOKENUPPER: hb_storclen( pcRet, sRetStrLen, 1 ); if( iNoRef ) { hb_xfree( pcRet ); hb_retl( HB_FALSE ); } else hb_retclen_buffer( pcRet, sRetStrLen ); break; } } else { switch( iSwitch ) { case DO_TOKEN1_TOKEN: { PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(); char cRet; if( HB_ISBYREF( 5 ) ) { cRet = ( char ) ct_token->iPreSeparator; hb_storclen( &cRet, ( ct_token->iPreSeparator != -1 ? 1 : 0 ), 5 ); } if( HB_ISBYREF( 6 ) ) { cRet = ( char ) ct_token->iPostSeparator; hb_storclen( &cRet, ( ct_token->iPostSeparator != -1 ? 1 : 0 ), 6 ); } if( iArgErrorMode != CT_ARGERR_IGNORE ) pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_TOKEN, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else if( ! iNoRef ) hb_retc_null(); else hb_retl( HB_FALSE ); break; } case DO_TOKEN1_TOKENLOWER: case DO_TOKEN1_TOKENUPPER: { PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, iSwitch == DO_TOKEN1_TOKENLOWER ? CT_ERROR_TOKENLOWER : CT_ERROR_TOKENUPPER, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else if( ! iNoRef ) hb_retc_null(); else hb_retl( HB_FALSE ); break; } case DO_TOKEN1_NUMTOKEN: case DO_TOKEN1_ATTOKEN: { PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, iSwitch == DO_TOKEN1_NUMTOKEN ? CT_ERROR_NUMTOKEN : CT_ERROR_ATTOKEN, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else hb_retns( 0 ); break; } } } }
static void s_inetSendInternal( HB_BOOL lAll ) { PHB_SOCKET_STRUCT socket = HB_PARSOCKET( 1 ); PHB_ITEM pBuffer = hb_param( 2, HB_IT_STRING ); const char * buffer; int iLen, iSent, iSend; long lLastSnd = 1; if( socket == NULL || pBuffer == NULL ) hb_inetErrRT(); else if( ! hb_inetIsOpen( socket ) ) hb_retni( -1 ); else { buffer = hb_itemGetCPtr( pBuffer ); iSend = ( int ) hb_itemGetCLen( pBuffer ); if( HB_ISNUM( 3 ) ) { iLen = hb_parni( 3 ); if( iLen < iSend ) iSend = iLen; } socket->iError = HB_INET_ERR_OK; iSent = iLen = 0; while( iSent < iSend ) { if( socket->sendFunc ) { iLen = socket->sendFunc( socket->stream, socket->sd, buffer + iSent, iSend - iSent, socket->iTimeout, &lLastSnd ); if( lLastSnd <= 0 && iLen > 0 ) { iSent += iLen; iLen = ( int ) lLastSnd; } } else iLen = hb_socketSend( socket->sd, buffer + iSent, iSend - iSent, 0, socket->iTimeout ); if( iLen > 0 ) { iSent += iLen; if( ! lAll ) break; } else { hb_inetGetError( socket ); break; } } socket->iCount = iSent; if( socket->flushFunc && ( lLastSnd > 0 || ( lLastSnd == -1 && socket->iTimeout >= 0 && socket->iTimeout < 10000 && s_inetIsTimeout( socket ) ) ) ) { /* TODO: safe information about unflushed data and try to call flush before entering receive wait sate */ socket->flushFunc( socket->stream, socket->sd, socket->iTimeout < 0 ? socket->iTimeout : HB_MAX( socket->iTimeout, 10000 ), HB_FALSE ); } hb_retni( iSent > 0 ? iSent : iLen ); } }
static void s_inetRecvInternal( int iMode ) { PHB_SOCKET_STRUCT socket = HB_PARSOCKET( 1 ); PHB_ITEM pBuffer = hb_param( 2, HB_IT_STRING ); if( socket == NULL || pBuffer == NULL || ! HB_ISBYREF( 2 ) ) hb_inetErrRT(); else if( ! hb_inetIsOpen( socket ) ) hb_retni( -1 ); else { int iLen, iMaxLen, iReceived, iTimeElapsed; char * buffer; HB_SIZE nLen; if( hb_itemGetWriteCL( pBuffer, &buffer, &nLen ) ) iLen = ( int ) nLen; else { iLen = 0; buffer = NULL; } if( HB_ISNUM( 3 ) ) { iMaxLen = hb_parni( 3 ); if( iMaxLen < 0 ) iMaxLen = 0; else if( iLen < iMaxLen ) iMaxLen = iLen; } else iMaxLen = iLen; iReceived = iTimeElapsed = 0; socket->iError = HB_INET_ERR_OK; do { iLen = s_inetRecv( socket, buffer + iReceived, iMaxLen - iReceived, HB_FALSE, socket->iTimeout ); if( iLen >= 0 ) { iReceived += iLen; if( iMode == 0 ) /* Called from hb_inetRecv()? */ break; } else if( iLen == -1 && s_inetIsTimeout( socket ) ) { /* if we have a pPeriodicBlock, timeLimit is our REAL timeout */ if( socket->pPeriodicBlock ) { /* timed out; let's see if we have to run a cb routine */ iTimeElapsed += socket->iTimeout; hb_execFromArray( socket->pPeriodicBlock ); /* do we continue? */ if( hb_parl( -1 ) && hb_vmRequestQuery() == 0 && ( socket->iTimeLimit == -1 || iTimeElapsed < socket->iTimeLimit ) ) iLen = 1; /* Declare success to continue loop */ } } } while( iReceived < iMaxLen && iLen > 0 ); socket->iCount = iReceived; if( iLen == 0 ) socket->iError = HB_INET_ERR_CLOSEDCONN; else if( iLen < 0 ) hb_inetGetError( socket ); hb_retni( iReceived > 0 ? iReceived : iLen ); } }
/* helper function for the remxxx functions */ static void do_remove( int iSwitch ) { /* param check */ if( HB_ISCHAR( 1 ) ) { const char * pcString = hb_parc( 1 ); HB_SIZE sStrLen = hb_parclen( 1 ); const char * pcRet; const char * pc; HB_SIZE sRetLen; char cSearch; if( hb_parclen( 2 ) > 0 ) cSearch = *( hb_parc( 2 ) ); else if( HB_ISNUM( 2 ) ) cSearch = ( char ) ( hb_parnl( 2 ) % 256 ); else cSearch = 0x20; sRetLen = sStrLen; pcRet = pcString; if( iSwitch != DO_REMOVE_REMRIGHT ) { while( ( *pcRet == cSearch ) && ( pcRet < pcString + sStrLen ) ) { pcRet++; sRetLen--; } } if( iSwitch != DO_REMOVE_REMLEFT ) { pc = pcString + sStrLen - 1; while( ( *pc == cSearch ) && ( pc >= pcRet ) ) { pc--; sRetLen--; } } if( sRetLen == 0 ) hb_retc_null(); else hb_retclen( pcRet, sRetLen ); } else { PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, sulErrorSubcodes[ iSwitch ], NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else hb_retc_null(); } }
/* helper function for the Count*() functions */ static void do_count( int iSwitch ) { /* param check */ if( HB_ISCHAR( 1 ) ) { const char * pcString = hb_parc( 1 ); HB_SIZE sStrLen = hb_parclen( 1 ); HB_SIZE sRetVal; const char * pc; char cSearch; if( hb_parclen( 2 ) > 0 ) cSearch = *( hb_parc( 2 ) ); else if( HB_ISNUM( 2 ) ) cSearch = ( char ) ( hb_parnl( 2 ) % 256 ); else cSearch = 0x20; sRetVal = 0; switch( iSwitch ) { case DO_COUNT_COUNTLEFT: pc = pcString; while( *pc == cSearch && pc < ( pcString + sStrLen ) ) { sRetVal++; pc++; } break; case DO_COUNT_COUNTRIGHT: pc = pcString + sStrLen - 1; while( *pc == cSearch && pc >= pcString ) { sRetVal++; pc--; } break; } hb_retns( sRetVal ); } else { PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, iSwitch == DO_COUNT_COUNTLEFT ? CT_ERROR_COUNTLEFT : CT_ERROR_COUNTRIGHT, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else hb_retns( 0 ); } }
HB_BOOL hb_EVP_MD_is( int iParam ) { return HB_ISCHAR( iParam ) || HB_ISNUM( iParam ); }
int hb_EVP_CIPHER_is( int iParam ) { return HB_ISCHAR( iParam ) || HB_ISNUM( iParam ); }
/* helper function */ static void do_atnum( int iSwitch ) { if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) ) { const char * pcStringToMatch = hb_parc( 1 ); HB_SIZE sStrToMatchLen = hb_parclen( 1 ); const char * pcString = hb_parc( 2 ); HB_SIZE sStrLen = hb_parclen( 2 ); int iMultiPass = ct_getatmupa(); int iAtLike = ct_getatlike(); char cAtLike = ct_getatlikechar(); HB_SIZE sIgnore = hb_parnsdef( 4, 0 ); /* eventually ignore some characters */ HB_SIZE sMatchStrLen = 0; HB_SIZE nCounter; const char * pc = NULL; if( sIgnore >= sStrLen ) { switch( iSwitch ) { case DO_ATNUM_AFTERATNUM: { /* AFTERATNUM */ int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) ct_error( ( HB_USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_AFTERATNUM, NULL, HB_ERR_FUNCNAME, 0, EF_CANDEFAULT, HB_ERR_ARGS_BASEPARAMS ); hb_retc_null(); break; } case DO_ATNUM_BEFORATNUM: { /* BEFORATNUM */ int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) ct_error( ( HB_USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_BEFORATNUM, NULL, HB_ERR_FUNCNAME, 0, EF_CANDEFAULT, HB_ERR_ARGS_BASEPARAMS ); hb_retc_null(); break; } case DO_ATNUM_ATNUM: { /* ATNUM */ int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) ct_error( ( HB_USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_ATNUM, NULL, HB_ERR_FUNCNAME, 0, EF_CANDEFAULT, HB_ERR_ARGS_BASEPARAMS ); hb_retns( 0 ); break; } } return; } else { pcString += sIgnore; sStrLen -= sIgnore; } /* nth match or last match ? */ if( HB_ISNUM( 3 ) && ( nCounter = hb_parns( 3 ) ) != 0 ) { /* find the <nCounter>th match */ const char * pcSubStr; HB_SIZE sSubStrLen; HB_SIZE nMatchCounter = 0; pcSubStr = pcString; sSubStrLen = sStrLen; while( nMatchCounter < nCounter ) { switch( iAtLike ) { case CT_SETATLIKE_EXACT: pc = ct_at_exact_forward( pcSubStr, sSubStrLen, pcStringToMatch, sStrToMatchLen, &sMatchStrLen ); break; case CT_SETATLIKE_WILDCARD: pc = ct_at_wildcard_forward( pcSubStr, sSubStrLen, pcStringToMatch, sStrToMatchLen, cAtLike, &sMatchStrLen ); break; default: pc = NULL; } if( pc == NULL ) { /* no match found; if this happens at this point, there are no <nCounter> matches, so return an empty string */ switch( iSwitch ) { case DO_ATNUM_AFTERATNUM: case DO_ATNUM_BEFORATNUM: /* AFTERATNUM */ /* BEFORATNUM */ hb_retc_null(); break; case DO_ATNUM_ATNUM: /* ATNUM */ hb_retns( 0 ); break; } return; } nMatchCounter++; if( iMultiPass ) pcSubStr = pc + 1; else pcSubStr = pc + sMatchStrLen; sSubStrLen = sStrLen - ( pcSubStr - pcString ); } } else { /* we have to find the last match and return the string after that last match */ switch( iAtLike ) { case CT_SETATLIKE_EXACT: pc = ct_at_exact_backward( pcString, sStrLen, pcStringToMatch, sStrToMatchLen, &sMatchStrLen ); break; case CT_SETATLIKE_WILDCARD: pc = ct_at_wildcard_backward( pcString, sStrLen, pcStringToMatch, sStrToMatchLen, cAtLike, &sMatchStrLen ); break; default: pc = NULL; } if( pc == NULL ) { /* no matches found */ switch( iSwitch ) { case DO_ATNUM_AFTERATNUM: case DO_ATNUM_BEFORATNUM: /* AFTERATNUM */ /* BEFORATNUM */ hb_retc_null(); break; case DO_ATNUM_ATNUM: /* ATNUM */ hb_retns( 0 ); break; } return; } } switch( iSwitch ) { case DO_ATNUM_AFTERATNUM: /* AFTERATNUM */ if( pc + sMatchStrLen >= pcString + sStrLen ) hb_retc_null(); else hb_retclen( pc + sMatchStrLen, sStrLen - ( pc + sMatchStrLen - pcString ) ); break; case DO_ATNUM_BEFORATNUM: /* BEFORATNUM */ hb_retclen( pcString - sIgnore, pc - ( pcString - sIgnore ) ); break; case DO_ATNUM_ATNUM: /* ATNUM */ #if defined( __POCC__ ) && ( __POCC__ >= 500 ) && defined( HB_OS_WIN_64 ) /* NOTE: Workaround for Pelles C 5.00.13 AMD64 mode internal error: 'fatal error: Internal error: reduce_tree()' [vszakats]. */ hb_retns( pc - pcString + sIgnore + 1 ); #else hb_retns( pc - ( pcString - sIgnore ) + 1 ); #endif break; } } else { switch( iSwitch ) { case DO_ATNUM_AFTERATNUM: case DO_ATNUM_BEFORATNUM: { /* AFTERATNUM */ PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, iSwitch == DO_ATNUM_AFTERATNUM ? CT_ERROR_AFTERATNUM : CT_ERROR_BEFORATNUM, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else hb_retc_null(); break; } case DO_ATNUM_ATNUM: { /* ATNUM */ PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_ATNUM, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else hb_retns( 0 ); break; } } } }