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 TOKEN_ENVIRONMENT sTokGet( int iParam, HB_BOOL fReadOnly ) { if( iParam < 0 || ( iParam > 0 && HB_ISCHAR( iParam ) ) ) { if( iParam < 0 || fReadOnly || HB_ISBYREF( iParam ) ) { HB_SIZE nLen; if( iParam < 0 ) iParam = -iParam; nLen = hb_parclen( iParam ); if( nLen >= sizeof( TOKEN_POSITION ) * 2 ) { TOKEN_ENVIRONMENT env = ( TOKEN_ENVIRONMENT ) HB_UNCONST( hb_parc( iParam ) ); if( sTokEnvGetSize( env ) == nLen ) return fReadOnly ? env : ( TOKEN_ENVIRONMENT ) hb_xmemdup( env, nLen + 1 ); } } return NULL; } else return * ( TOKEN_ENVIRONMENT * ) hb_stackGetTSD( &s_token ); }
/* helper function */ static void do_charevod( int iSwitch ) { if( HB_ISCHAR( 1 ) ) { const char * pcString = hb_parc( 1 ); HB_SIZE sLen = hb_parclen( 1 ); char * pcResult; HB_SIZE sPos, sResultPos; if( sLen == 0 ) { int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) ct_error( ( HB_USHORT ) iArgErrorMode, EG_ARG, iSwitch == DO_CHAREVOD_CHAREVEN ? CT_ERROR_CHAREVEN : CT_ERROR_CHARODD, NULL, HB_ERR_FUNCNAME, 0, EF_CANDEFAULT, HB_ERR_ARGS_BASEPARAMS ); hb_retc_null(); return; } pcResult = ( char * ) hb_xgrab( ( sLen + 1 ) / 2 ); if( iSwitch == DO_CHAREVOD_CHAREVEN ) sPos = 1; else sPos = 0; sResultPos = 0; for( ; sPos < sLen; sPos += 2 ) pcResult[ sResultPos++ ] = pcString[ sPos ]; if( sResultPos == 0 ) hb_retc_null(); else hb_retclen( pcResult, sResultPos ); hb_xfree( pcResult ); } 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_CHAREVOD_CHAREVEN ? CT_ERROR_CHAREVEN : CT_ERROR_CHARODD, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else hb_retc_null(); } }
HB_EXTERN_END HB_FUNC( HB_BLATSEND ) { if( HB_ISCHAR( 1 ) ) hb_retni( cSend( hb_parc( 1 ) ) ); else hb_errRT_BASE_SubstR( EG_ARG, 0, 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 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; }
const EVP_MD * hb_EVP_MD_par( int iParam ) { const EVP_MD * p; if( HB_ISCHAR( iParam ) ) return EVP_get_digestbyname( hb_parc( iParam ) ); switch( hb_parni( iParam ) ) { case HB_EVP_MD_MD_NULL: p = EVP_md_null(); break; #ifndef OPENSSL_NO_MD4 case HB_EVP_MD_MD4: p = EVP_md4(); break; #endif #ifndef OPENSSL_NO_MD5 case HB_EVP_MD_MD5: p = EVP_md5(); break; #endif #ifndef OPENSSL_NO_SHA #if OPENSSL_VERSION_NUMBER < 0x10100000L && \ ! defined( LIBRESSL_VERSION_NUMBER ) case HB_EVP_MD_SHA: p = EVP_sha(); break; #endif case HB_EVP_MD_SHA1: p = EVP_sha1(); break; #if OPENSSL_VERSION_NUMBER < 0x10100000L case HB_EVP_MD_DSS: p = EVP_dss(); break; case HB_EVP_MD_DSS1: p = EVP_dss1(); break; #endif #if OPENSSL_VERSION_NUMBER >= 0x00908000L && \ OPENSSL_VERSION_NUMBER < 0x10100000L case HB_EVP_MD_ECDSA: p = EVP_ecdsa(); break; #endif #endif #ifndef OPENSSL_NO_SHA256 case HB_EVP_MD_SHA224: p = EVP_sha224(); break; case HB_EVP_MD_SHA256: p = EVP_sha256(); break; #endif #ifndef OPENSSL_NO_SHA512 case HB_EVP_MD_SHA384: p = EVP_sha384(); break; case HB_EVP_MD_SHA512: p = EVP_sha512(); break; #endif #ifndef OPENSSL_NO_RIPEMD case HB_EVP_MD_RIPEMD160: p = EVP_ripemd160(); break; #endif default: p = NULL; } return p; }
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; }
HB_EXTERN_END #endif HB_FUNC( HB_BLATSEND ) { if( HB_ISCHAR( 1 ) ) { #if defined( HBMK_HAS_BLAT ) void * hCmdLine = NULL; hb_retni( cSend( HB_PARSTR( 1, &hCmdLine, NULL ) ) ); hb_strfree( hCmdLine ); #else hb_retni( cSend( hb_parc( 1 ) ) ); #endif } else hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); }
/* helper function */ static void do_ascpos( int iSwitch ) { if( HB_ISCHAR( 1 ) ) { HB_SIZE sStrSize = hb_parclen( 1 ); const HB_BYTE * pcString = ( const HB_BYTE * ) hb_parc( 1 ); HB_SIZE sPos = hb_parnsdef( 2, sStrSize ); if( sPos == 0 || sPos > sStrSize ) hb_retni( 0 ); else { if( iSwitch == DO_ASCPOS_VALPOS ) { if( HB_ISDIGIT( ( HB_UCHAR ) pcString[ sPos - 1 ] ) ) hb_retni( pcString[ sPos - 1 ] - '0' ); else hb_retni( 0 ); } else hb_retni( pcString[ sPos - 1 ] ); } } 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_ASCPOS_VALPOS ? CT_ERROR_VALPOS : CT_ERROR_ASCPOS, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else hb_retni( 0 ); } }
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 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; 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; } if( iSwitch == DO_TOKEN1_NUMTOKEN ) { /* token counter */ nTokenCounter = HB_SIZE_MAX; /* skip width */ nSkip = hb_parns( 3 ); } else { /* token counter */ nTokenCounter = hb_parns( 3 ); /* skip width */ nSkip = hb_parns( 4 ); /* HB_EXTENSION for AtToken()/TokenLower()/TokenUpper() */ } if( nTokenCounter == 0 ) nTokenCounter = 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 ) ) /* HB_EXTENSION */ { cRet = ( char ) ct_token->iPreSeparator; hb_storclen( &cRet, ( ct_token->iPreSeparator != -1 ? 1 : 0 ), 5 ); } if( HB_ISBYREF( 6 ) ) /* HB_EXTENSION */ { 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 ) ) /* HB_EXTENSION */ { cRet = ( char ) ct_token->iPreSeparator; hb_storclen( &cRet, ( ct_token->iPreSeparator != -1 ? 1 : 0 ), 5 ); } if( HB_ISBYREF( 6 ) ) /* HB_EXTENSION */ { 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 ) ) /* HB_EXTENSION */ { cRet = ( char ) ct_token->iPreSeparator; hb_storclen( &cRet, ( ct_token->iPreSeparator != -1 ? 1 : 0 ), 5 ); } if( HB_ISBYREF( 6 ) ) /* HB_EXTENSION */ { 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; } } } }
/* helper function for the charswap and wordswap functions */ static void do_charswap( int iSwitch ) { /* suppress return value ? */ int iNoRet = ct_getref() && HB_ISBYREF( 1 ); /* param check */ if( HB_ISCHAR( 1 ) ) { const char * pcString = hb_parc( 1 ); HB_SIZE sStrLen = hb_parclen( 1 ); char * pcRet; HB_SIZE sRetIndex = 0; int iShift, iMod; const char * pcSub; if( sStrLen == 0 ) { if( iNoRet ) hb_ret(); else hb_retc_null(); return; } if( iSwitch == DO_CHARSWAP_WORDSWAP ) { iShift = 4; if( hb_parl( 2 ) ) iSwitch = DO_CHARSWAP_WORDSWAP_CHARSWAP; } else iShift = 2; pcRet = ( char * ) hb_xgrab( sStrLen ); for( pcSub = pcString; pcSub < pcString + sStrLen + 1 - iShift; pcSub += iShift ) { switch( iSwitch ) { case DO_CHARSWAP_WORDSWAP: pcRet[ sRetIndex++ ] = pcSub[ 2 ]; pcRet[ sRetIndex++ ] = pcSub[ 3 ]; pcRet[ sRetIndex++ ] = pcSub[ 0 ]; pcRet[ sRetIndex++ ] = pcSub[ 1 ]; break; case DO_CHARSWAP_WORDSWAP_CHARSWAP: pcRet[ sRetIndex++ ] = pcSub[ 3 ]; pcRet[ sRetIndex++ ] = pcSub[ 2 ]; /* no 'break' here !! */ case DO_CHARSWAP_CHARSWAP: pcRet[ sRetIndex++ ] = pcSub[ 1 ]; pcRet[ sRetIndex++ ] = pcSub[ 0 ]; } } /* copy rest of string */ if( iSwitch == DO_CHARSWAP_WORDSWAP || iSwitch == DO_CHARSWAP_WORDSWAP_CHARSWAP ) iMod = sStrLen % 4; else iMod = sStrLen % 2; for( pcSub = pcString + sStrLen - iMod; pcSub < pcString + sStrLen; pcSub++ ) pcRet[ sRetIndex++ ] = *pcSub; /* return string */ hb_storclen( pcRet, sRetIndex, 1 ); if( iNoRet ) hb_retl( HB_FALSE ); else hb_retclen( pcRet, sRetIndex ); hb_xfree( pcRet ); } else { PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) { if( iSwitch == DO_CHARSWAP_CHARSWAP ) pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_CHARSWAP, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); else pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_WORDSWAP, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); } if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else if( iNoRet ) hb_retl( HB_FALSE ); else hb_retc_null(); } }
const EVP_CIPHER * hb_EVP_CIPHER_par( int iParam ) { const EVP_CIPHER * p; if( HB_ISCHAR( iParam ) ) return EVP_get_cipherbyname( hb_parc( iParam ) ); switch( hb_parni( iParam ) ) { case HB_EVP_CIPHER_ENC_NULL: p = EVP_enc_null(); break; #ifndef OPENSSL_NO_DES case HB_EVP_CIPHER_DES_ECB: p = EVP_des_ecb(); break; case HB_EVP_CIPHER_DES_EDE: p = EVP_des_ede(); break; case HB_EVP_CIPHER_DES_EDE3: p = EVP_des_ede3(); break; #if OPENSSL_VERSION_NUMBER >= 0x00907000L case HB_EVP_CIPHER_DES_EDE_ECB: p = EVP_des_ede_ecb(); break; case HB_EVP_CIPHER_DES_EDE3_ECB: p = EVP_des_ede3_ecb(); break; #endif case HB_EVP_CIPHER_DES_CFB: p = EVP_des_cfb(); break; case HB_EVP_CIPHER_DES_EDE_CFB: p = EVP_des_ede_cfb(); break; case HB_EVP_CIPHER_DES_EDE3_CFB: p = EVP_des_ede3_cfb(); break; #if OPENSSL_VERSION_NUMBER >= 0x00907050L case HB_EVP_CIPHER_DES_CFB1: p = EVP_des_cfb1(); break; case HB_EVP_CIPHER_DES_CFB8: p = EVP_des_cfb8(); break; case HB_EVP_CIPHER_DES_CFB64: p = EVP_des_cfb64(); break; case HB_EVP_CIPHER_DES_EDE_CFB64: p = EVP_des_ede_cfb64(); break; case HB_EVP_CIPHER_DES_EDE3_CFB1: p = EVP_des_ede3_cfb1(); break; case HB_EVP_CIPHER_DES_EDE3_CFB8: p = EVP_des_ede3_cfb8(); break; case HB_EVP_CIPHER_DES_EDE3_CFB64: p = EVP_des_ede3_cfb64(); break; #endif case HB_EVP_CIPHER_DES_OFB: p = EVP_des_ofb(); break; case HB_EVP_CIPHER_DES_EDE_OFB: p = EVP_des_ede_ofb(); break; case HB_EVP_CIPHER_DES_EDE3_OFB: p = EVP_des_ede3_ofb(); break; case HB_EVP_CIPHER_DES_CBC: p = EVP_des_cbc(); break; case HB_EVP_CIPHER_DES_EDE_CBC: p = EVP_des_ede_cbc(); break; case HB_EVP_CIPHER_DES_EDE3_CBC: p = EVP_des_ede3_cbc(); break; case HB_EVP_CIPHER_DESX_CBC: p = EVP_desx_cbc(); break; #endif #ifndef OPENSSL_NO_RC4 case HB_EVP_CIPHER_RC4: p = EVP_rc4(); break; case HB_EVP_CIPHER_RC4_40: p = EVP_rc4_40(); break; #endif #ifndef OPENSSL_NO_IDEA case HB_EVP_CIPHER_IDEA_ECB: p = EVP_idea_ecb(); break; case HB_EVP_CIPHER_IDEA_CFB64: p = EVP_idea_cfb64(); break; case HB_EVP_CIPHER_IDEA_CFB: p = EVP_idea_cfb(); break; case HB_EVP_CIPHER_IDEA_OFB: p = EVP_idea_ofb(); break; case HB_EVP_CIPHER_IDEA_CBC: p = EVP_idea_cbc(); break; #endif #ifndef OPENSSL_NO_RC2 case HB_EVP_CIPHER_RC2_ECB: p = EVP_rc2_ecb(); break; case HB_EVP_CIPHER_RC2_CBC: p = EVP_rc2_cbc(); break; case HB_EVP_CIPHER_RC2_40_CBC: p = EVP_rc2_40_cbc(); break; case HB_EVP_CIPHER_RC2_64_CBC: p = EVP_rc2_64_cbc(); break; #if OPENSSL_VERSION_NUMBER >= 0x00907050L case HB_EVP_CIPHER_RC2_CFB64: p = EVP_rc2_cfb64(); break; #endif case HB_EVP_CIPHER_RC2_CFB: p = EVP_rc2_cfb(); break; case HB_EVP_CIPHER_RC2_OFB: p = EVP_rc2_ofb(); break; #endif #ifndef OPENSSL_NO_BF case HB_EVP_CIPHER_BF_ECB: p = EVP_bf_ecb(); break; case HB_EVP_CIPHER_BF_CBC: p = EVP_bf_cbc(); break; #if OPENSSL_VERSION_NUMBER >= 0x00907050L case HB_EVP_CIPHER_BF_CFB64: p = EVP_bf_cfb64(); break; #endif case HB_EVP_CIPHER_BF_CFB: p = EVP_bf_cfb(); break; case HB_EVP_CIPHER_BF_OFB: p = EVP_bf_ofb(); break; #endif #ifndef OPENSSL_NO_CAST case HB_EVP_CIPHER_CAST5_ECB: p = EVP_cast5_ecb(); break; case HB_EVP_CIPHER_CAST5_CBC: p = EVP_cast5_cbc(); break; #if OPENSSL_VERSION_NUMBER >= 0x00907050L case HB_EVP_CIPHER_CAST5_CFB64: p = EVP_cast5_cfb64(); break; #endif case HB_EVP_CIPHER_CAST5_CFB: p = EVP_cast5_cfb(); break; case HB_EVP_CIPHER_CAST5_OFB: p = EVP_cast5_ofb(); break; #endif #ifndef OPENSSL_NO_RC5 case HB_EVP_CIPHER_RC5_32_12_16_CBC: p = EVP_rc5_32_12_16_cbc(); break; case HB_EVP_CIPHER_RC5_32_12_16_ECB: p = EVP_rc5_32_12_16_ecb(); break; case HB_EVP_CIPHER_RC5_32_12_16_CFB: p = EVP_rc5_32_12_16_cfb(); break; case HB_EVP_CIPHER_RC5_32_12_16_OFB: p = EVP_rc5_32_12_16_ofb(); break; #if OPENSSL_VERSION_NUMBER >= 0x00907050L case HB_EVP_CIPHER_RC5_32_12_16_CFB64: p = EVP_rc5_32_12_16_cfb64(); break; #endif #endif #ifndef OPENSSL_NO_AES #if OPENSSL_VERSION_NUMBER >= 0x10001000L case HB_EVP_CIPHER_AES_128_GCM: p = EVP_aes_128_gcm(); break; #endif case HB_EVP_CIPHER_AES_128_ECB: p = EVP_aes_128_ecb(); break; case HB_EVP_CIPHER_AES_128_CBC: p = EVP_aes_128_cbc(); break; #if OPENSSL_VERSION_NUMBER >= 0x00907050L case HB_EVP_CIPHER_AES_128_CFB1: p = EVP_aes_128_cfb1(); break; case HB_EVP_CIPHER_AES_128_CFB8: p = EVP_aes_128_cfb8(); break; case HB_EVP_CIPHER_AES_128_CFB128: p = EVP_aes_128_cfb128(); break; #endif case HB_EVP_CIPHER_AES_128_CFB: p = EVP_aes_128_cfb(); break; case HB_EVP_CIPHER_AES_128_OFB: p = EVP_aes_128_ofb(); break; #if OPENSSL_VERSION_NUMBER >= 0x10001000L case HB_EVP_CIPHER_AES_192_GCM: p = EVP_aes_192_gcm(); break; #endif case HB_EVP_CIPHER_AES_192_ECB: p = EVP_aes_192_ecb(); break; case HB_EVP_CIPHER_AES_192_CBC: p = EVP_aes_192_cbc(); break; #if OPENSSL_VERSION_NUMBER >= 0x00907050L case HB_EVP_CIPHER_AES_192_CFB1: p = EVP_aes_192_cfb1(); break; case HB_EVP_CIPHER_AES_192_CFB8: p = EVP_aes_192_cfb8(); break; case HB_EVP_CIPHER_AES_192_CFB128: p = EVP_aes_192_cfb128(); break; #endif case HB_EVP_CIPHER_AES_192_CFB: p = EVP_aes_192_cfb(); break; case HB_EVP_CIPHER_AES_192_OFB: p = EVP_aes_192_ofb(); break; #if OPENSSL_VERSION_NUMBER >= 0x10001000L case HB_EVP_CIPHER_AES_256_GCM: p = EVP_aes_256_gcm(); break; #endif case HB_EVP_CIPHER_AES_256_ECB: p = EVP_aes_256_ecb(); break; case HB_EVP_CIPHER_AES_256_CBC: p = EVP_aes_256_cbc(); break; #if OPENSSL_VERSION_NUMBER >= 0x00907050L case HB_EVP_CIPHER_AES_256_CFB1: p = EVP_aes_256_cfb1(); break; case HB_EVP_CIPHER_AES_256_CFB8: p = EVP_aes_256_cfb8(); break; case HB_EVP_CIPHER_AES_256_CFB128: p = EVP_aes_256_cfb128(); break; #endif case HB_EVP_CIPHER_AES_256_CFB: p = EVP_aes_256_cfb(); break; case HB_EVP_CIPHER_AES_256_OFB: p = EVP_aes_256_ofb(); break; #endif #ifndef OPENSSL_NO_CAMELLIA case HB_EVP_CIPHER_CAMELLIA_128_ECB: p = EVP_camellia_128_ecb(); break; case HB_EVP_CIPHER_CAMELLIA_128_CBC: p = EVP_camellia_128_cbc(); break; case HB_EVP_CIPHER_CAMELLIA_128_CFB1: p = EVP_camellia_128_cfb1(); break; case HB_EVP_CIPHER_CAMELLIA_128_CFB8: p = EVP_camellia_128_cfb8(); break; case HB_EVP_CIPHER_CAMELLIA_128_CFB128: p = EVP_camellia_128_cfb128(); break; case HB_EVP_CIPHER_CAMELLIA_128_CFB: p = EVP_camellia_128_cfb(); break; case HB_EVP_CIPHER_CAMELLIA_128_OFB: p = EVP_camellia_128_ofb(); break; case HB_EVP_CIPHER_CAMELLIA_192_ECB: p = EVP_camellia_192_ecb(); break; case HB_EVP_CIPHER_CAMELLIA_192_CBC: p = EVP_camellia_192_cbc(); break; case HB_EVP_CIPHER_CAMELLIA_192_CFB1: p = EVP_camellia_192_cfb1(); break; case HB_EVP_CIPHER_CAMELLIA_192_CFB8: p = EVP_camellia_192_cfb8(); break; case HB_EVP_CIPHER_CAMELLIA_192_CFB128: p = EVP_camellia_192_cfb128(); break; case HB_EVP_CIPHER_CAMELLIA_192_CFB: p = EVP_camellia_192_cfb(); break; case HB_EVP_CIPHER_CAMELLIA_192_OFB: p = EVP_camellia_192_ofb(); break; case HB_EVP_CIPHER_CAMELLIA_256_ECB: p = EVP_camellia_256_ecb(); break; case HB_EVP_CIPHER_CAMELLIA_256_CBC: p = EVP_camellia_256_cbc(); break; case HB_EVP_CIPHER_CAMELLIA_256_CFB1: p = EVP_camellia_256_cfb1(); break; case HB_EVP_CIPHER_CAMELLIA_256_CFB8: p = EVP_camellia_256_cfb8(); break; case HB_EVP_CIPHER_CAMELLIA_256_CFB128: p = EVP_camellia_256_cfb128(); break; case HB_EVP_CIPHER_CAMELLIA_256_CFB: p = EVP_camellia_256_cfb(); break; case HB_EVP_CIPHER_CAMELLIA_256_OFB: p = EVP_camellia_256_ofb(); break; #endif #ifndef OPENSSL_NO_SEED case HB_EVP_CIPHER_SEED_ECB: p = EVP_seed_ecb(); break; case HB_EVP_CIPHER_SEED_CBC: p = EVP_seed_cbc(); break; case HB_EVP_CIPHER_SEED_CFB128: p = EVP_seed_cfb128(); break; case HB_EVP_CIPHER_SEED_CFB: p = EVP_seed_cfb(); break; case HB_EVP_CIPHER_SEED_OFB: p = EVP_seed_ofb(); break; #endif default: p = NULL; } return p; }
int hb_EVP_CIPHER_is( int iParam ) { return HB_ISCHAR( iParam ) || HB_ISNUM( iParam ); }
/* helper function for the Pos*() functions */ static void do_pos1( int iSwitch ) { if( HB_ISCHAR( 1 ) && /* all functions need string as 1st param */ ( iSwitch != DO_POS1_POSRANGE || /* that's the only condition for all functions _except_ PosRange() */ ( iSwitch == DO_POS1_POSRANGE && /* In addition, PosRange() needs .. */ HB_ISCHAR( 2 ) && /* .. string as 2nd .. */ HB_ISCHAR( 3 ) ) ) ) /* .. and 3rd param */ { const unsigned char * pcString, * puc; HB_SIZE sStrLen; unsigned char ucChar1 = ' ', ucChar2 = ' '; int iMode; HB_SIZE sIgnore; int iParamShift = 0; if( iSwitch == DO_POS1_POSRANGE ) { if( hb_parclen( 1 ) == 0 ) { hb_retns( 0 ); return; } else ucChar1 = *( hb_parc( 1 ) ); if( hb_parclen( 2 ) == 0 ) { hb_retns( 0 ); return; } else ucChar2 = *( hb_parc( 2 ) ); iParamShift += 2; } pcString = ( const unsigned char * ) hb_parc( iParamShift + 1 ); sStrLen = hb_parclen( iParamShift + 1 ); iMode = hb_parl( iParamShift + 2 ); sIgnore = hb_parnsdef( iParamShift + 3, 0 ); for( puc = pcString + sIgnore; puc < pcString + sStrLen; puc++ ) { int iDoRet = 0; switch( iSwitch ) { case DO_POS1_POSALPHA: iDoRet = hb_charIsAlpha( ( HB_UCHAR ) *puc ); break; case DO_POS1_POSLOWER: iDoRet = hb_charIsLower( ( HB_UCHAR ) *puc ); break; case DO_POS1_POSRANGE: iDoRet = ( ucChar1 <= *puc && ucChar2 >= *puc ); break; case DO_POS1_POSUPPER: iDoRet = hb_charIsUpper( ( HB_UCHAR ) *puc ); break; } if( ( iMode && ! iDoRet ) || ( ! iMode && iDoRet ) ) { hb_retns( puc - pcString + 1 ); return; } } hb_retns( 0 ); } else { PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) { HB_ERRCODE iError = 0; switch( iSwitch ) { case DO_POS1_POSALPHA: iError = CT_ERROR_POSALPHA; break; case DO_POS1_POSLOWER: iError = CT_ERROR_POSLOWER; break; case DO_POS1_POSRANGE: iError = CT_ERROR_POSRANGE; break; case DO_POS1_POSUPPER: iError = CT_ERROR_POSUPPER; break; } pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, iError, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); } if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else hb_retns( 0 ); } }
/* 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 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 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 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 ); }
static int hb_BIO_METHOD_is( int iParam ) { return HB_ISCHAR( iParam ); }
/* 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(); } }
static int hb_zipStoreFile( zipFile hZip, int iParamFileName, int iParamZipName, const char * szPassword, int iParamComment, HB_BOOL fUnicode ) { const char * szFileName = hb_parc( iParamFileName ); const char * szName = hb_parc( iParamZipName ); char * pString; HB_FHANDLE hFile; HB_SIZE nLen; HB_FATTR ulExtAttr; zip_fileinfo zfi; int iResult; HB_BOOL fError; HB_BOOL fText; HB_U32 ulCRC; uLong flags = 0; void * hZipName = NULL; void * hComment = NULL; char * szZipName; const char * szComment; memset( &zfi, 0, sizeof( zfi ) ); fError = HB_FALSE; ulExtAttr = 0; #if defined( HB_OS_WIN ) { LPTSTR lpFileNameFree; LPCTSTR lpFileName = HB_FSNAMECONV( szFileName, &lpFileNameFree ); DWORD attr = GetFileAttributes( lpFileName ); if( attr != INVALID_FILE_ATTRIBUTES ) { ulExtAttr = hb_translateExtAttr( szFileName, attr & ( FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_ARCHIVE ) ); } else fError = HB_TRUE; if( lpFileNameFree ) hb_xfree( lpFileNameFree ); } #elif defined( HB_OS_UNIX ) { struct stat statbuf; struct tm st; time_t ftime; char * pszFree; if( stat( hb_fsNameConv( szFileName, &pszFree ), &statbuf ) == 0 ) { if( S_ISDIR( statbuf.st_mode ) ) { ulExtAttr |= 0x40000000; ulExtAttr |= 0x10; /* FILE_ATTRIBUTE_DIRECTORY */ } else { ulExtAttr |= 0x80000000; ulExtAttr |= 0x20; /* FILE_ATTRIBUTE_ARCHIVE */ } ulExtAttr |= ( ( statbuf.st_mode & S_IXOTH ) ? 0x00010000 : 0 ) | ( ( statbuf.st_mode & S_IWOTH ) ? 0x00020000 : 0 ) | ( ( statbuf.st_mode & S_IROTH ) ? 0x00040000 : 0 ) | ( ( statbuf.st_mode & S_IXGRP ) ? 0x00080000 : 0 ) | ( ( statbuf.st_mode & S_IWGRP ) ? 0x00100000 : 0 ) | ( ( statbuf.st_mode & S_IRGRP ) ? 0x00200000 : 0 ) | ( ( statbuf.st_mode & S_IXUSR ) ? 0x00400000 : 0 ) | ( ( statbuf.st_mode & S_IWUSR ) ? 0x00800000 : 0 ) | ( ( statbuf.st_mode & S_IRUSR ) ? 0x01000000 : 0 ); ftime = statbuf.st_mtime; # if defined( HB_HAS_LOCALTIME_R ) localtime_r( &ftime, &st ); # else st = *localtime( &ftime ); # endif zfi.tmz_date.tm_sec = st.tm_sec; zfi.tmz_date.tm_min = st.tm_min; zfi.tmz_date.tm_hour = st.tm_hour; zfi.tmz_date.tm_mday = st.tm_mday; zfi.tmz_date.tm_mon = st.tm_mon; zfi.tmz_date.tm_year = st.tm_year; } else fError = HB_TRUE; if( pszFree ) hb_xfree( pszFree ); } #elif defined( HB_OS_DOS ) { # if defined( __DJGPP__ ) || defined( __RSX32__ ) || defined( __GNUC__ ) int attr; char * pszFree; attr = _chmod( hb_fsNameConv( szFileName, &pszFree ), 0, 0 ); if( pszFree ) hb_xfree( pszFree ); if( attr != -1 ) # else HB_FATTR attr; if( hb_fsGetAttr( szFileName, &attr ) ) # endif { ulExtAttr = attr & ( HB_FA_READONLY | HB_FA_HIDDEN | HB_FA_SYSTEM | HB_FA_DIRECTORY | HB_FA_ARCHIVE ); ulExtAttr = hb_translateExtAttr( szFileName, ulExtAttr ); } else fError = HB_TRUE; } #elif defined( HB_OS_OS2 ) { FILESTATUS3 fs3; APIRET ulrc; HB_FATTR ulAttr; char * pszFree; ulrc = DosQueryPathInfo( ( PCSZ ) hb_fsNameConv( szFileName, &pszFree ), FIL_STANDARD, &fs3, sizeof( fs3 ) ); if( pszFree ) hb_xfree( pszFree ); if( ulrc == NO_ERROR ) { ulAttr = 0; if( fs3.attrFile & FILE_READONLY ) ulAttr |= HB_FA_READONLY; if( fs3.attrFile & FILE_HIDDEN ) ulAttr |= HB_FA_HIDDEN; if( fs3.attrFile & FILE_SYSTEM ) ulAttr |= HB_FA_SYSTEM; if( fs3.attrFile & FILE_DIRECTORY ) ulAttr |= HB_FA_DIRECTORY; if( fs3.attrFile & FILE_ARCHIVED ) ulAttr |= HB_FA_ARCHIVE; ulExtAttr = hb_translateExtAttr( szFileName, ulAttr ); zfi.tmz_date.tm_sec = fs3.ftimeLastWrite.twosecs * 2; zfi.tmz_date.tm_min = fs3.ftimeLastWrite.minutes; zfi.tmz_date.tm_hour = fs3.ftimeLastWrite.hours; zfi.tmz_date.tm_mday = fs3.fdateLastWrite.day; zfi.tmz_date.tm_mon = fs3.fdateLastWrite.month; zfi.tmz_date.tm_year = fs3.fdateLastWrite.year + 1980; } else fError = HB_TRUE; } #else { HB_FATTR attr; if( ! hb_fsGetAttr( szFileName, &attr ) ) ulExtAttr = 0x81B60020; /* FILE_ATTRIBUTE_ARCHIVE | rw-rw-rw- */ else { ulExtAttr = attr & ( HB_FA_READONLY | HB_FA_HIDDEN | HB_FA_SYSTEM | HB_FA_DIRECTORY | HB_FA_ARCHIVE ); ulExtAttr = hb_translateExtAttr( szFileName, ulExtAttr ); } } #endif if( fError ) return -200; if( ! HB_ISCHAR( iParamZipName ) ) iParamZipName = iParamFileName; if( fUnicode ) { szZipName = hb_strdup( hb_parstr_utf8( iParamZipName, &hZipName, NULL ) ); szComment = hb_parstr_utf8( iParamComment, &hComment, NULL ); flags |= _ZIP_FLAG_UNICODE; } else { szZipName = hb_strdup( hb_parc( iParamZipName ) ); szComment = hb_parc( iParamComment ); } if( szName ) { /* change path separators to '/' */ nLen = strlen( szZipName ); pString = szZipName; while( nLen-- ) { if( pString[ nLen ] == '\\' ) pString[ nLen ] = '/'; } } else { /* get file name */ szZipName = hb_strdup( szFileName ); nLen = strlen( szZipName ); pString = szZipName; while( nLen-- ) { if( pString[ nLen ] == '/' || pString[ nLen ] == '\\' ) { memmove( szZipName, &pString[ nLen + 1 ], strlen( szZipName ) - nLen ); break; } } } fText = HB_FALSE; ulCRC = 0; zfi.external_fa = ulExtAttr; /* TODO: zip.exe test: 0 for binary file, 1 for text. Does not depend on extension. We should analyse content of file to determine this??? */ zfi.internal_fa = 0; if( ulExtAttr & 0x40000000 ) { iResult = zipOpenNewFileInZip4( hZip, szZipName, &zfi, NULL, 0, NULL, 0, szComment, Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, szPassword, ulCRC, _version_made_by( fUnicode ), flags ); if( iResult == 0 ) zipCloseFileInZip( hZip ); } else { hFile = hb_fsOpen( szFileName, FO_READ ); if( hFile != FS_ERROR ) { #if defined( HB_OS_WIN ) { FILETIME ftutc, ft; SYSTEMTIME st; if( GetFileTime( ( HANDLE ) hb_fsGetOsHandle( hFile ), NULL, NULL, &ftutc ) && FileTimeToLocalFileTime( &ftutc, &ft ) && FileTimeToSystemTime( &ft, &st ) ) { zfi.tmz_date.tm_sec = st.wSecond; zfi.tmz_date.tm_min = st.wMinute; zfi.tmz_date.tm_hour = st.wHour; zfi.tmz_date.tm_mday = st.wDay; zfi.tmz_date.tm_mon = st.wMonth - 1; zfi.tmz_date.tm_year = st.wYear; } } #endif if( szPassword ) { if( hb_zipGetFileInfo( szFileName, &ulCRC, &fText ) ) zfi.internal_fa = fText ? 1 : 0; } iResult = zipOpenNewFileInZip4( hZip, szZipName, &zfi, NULL, 0, NULL, 0, szComment, Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, szPassword, ulCRC, _version_made_by( fUnicode ), flags ); if( iResult == 0 ) { pString = ( char * ) hb_xgrab( HB_Z_IOBUF_SIZE ); while( ( nLen = hb_fsReadLarge( hFile, pString, HB_Z_IOBUF_SIZE ) ) > 0 ) zipWriteInFileInZip( hZip, pString, ( unsigned ) nLen ); hb_xfree( pString ); zipCloseFileInZip( hZip ); } hb_fsClose( hFile ); } else iResult = -200 - hb_fsError(); } hb_xfree( szZipName ); if( fUnicode ) { hb_strfree( hZipName ); hb_strfree( hComment ); } return iResult; }
/* helper function for the *one functions */ static void do_charonly( int iSwitch ) { /* param check */ if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) ) { const char * pcString = hb_parc( 2 ); HB_SIZE sStrLen = hb_parclen( 2 ); const char * pcOnlySet = hb_parc( 1 ); HB_SIZE sOnlySetLen = hb_parclen( 1 ); char * pcRet; HB_SIZE sRetStrLen = 0; int iShift, iBool; const char * pcSub, * pc; /* check for zero-length strings */ switch( iSwitch ) { case DO_CHARONLY_CHARONLY: case DO_CHARONLY_WORDONLY: if( sStrLen == 0 || sOnlySetLen == 0 ) { hb_retc_null(); return; } break; case DO_CHARONLY_CHARREM: case DO_CHARONLY_WORDREM: if( sStrLen == 0 ) { hb_retc_null(); return; } if( sOnlySetLen == 0 ) { hb_retclen( pcString, sStrLen ); return; } break; } if( iSwitch == DO_CHARONLY_WORDONLY || iSwitch == DO_CHARONLY_WORDREM ) iShift = 2; else iShift = 1; pcRet = ( char * ) hb_xgrab( sStrLen ); for( pcSub = pcString; pcSub < pcString + sStrLen + 1 - iShift; pcSub += iShift ) { pc = ct_at_exact_forward( pcOnlySet, sOnlySetLen, pcSub, iShift, NULL ); iBool = ( ( pc != NULL ) && ( ( ( pc - pcOnlySet ) % iShift ) == 0 ) ); if( iBool ? ( iSwitch == DO_CHARONLY_CHARONLY || iSwitch == DO_CHARONLY_WORDONLY ) : ( iSwitch == DO_CHARONLY_CHARREM || iSwitch == DO_CHARONLY_WORDREM ) ) { for( pc = pcSub; pc < pcSub + iShift; pc++ ) pcRet[ sRetStrLen++ ] = *pc; } } /* copy last character if string len is odd */ if( iShift == 2 && sStrLen % 2 == 1 ) pcRet[ sRetStrLen++ ] = pcString[ sStrLen - 1 ]; hb_retclen( pcRet, sRetStrLen ); hb_xfree( pcRet ); } else { PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(), iError = 0; if( iArgErrorMode != CT_ARGERR_IGNORE ) { switch( iSwitch ) { case DO_CHARONLY_CHARONLY: iError = CT_ERROR_CHARONLY; break; case DO_CHARONLY_WORDONLY: iError = CT_ERROR_WORDONLY; break; case DO_CHARONLY_CHARREM: iError = CT_ERROR_CHARREM; break; case DO_CHARONLY_WORDREM: iError = CT_ERROR_WORDREM; break; } pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, iError, 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 *one functions */ static void do_charone( int iSwitch ) { const char * pcString; HB_SIZE sStrLen; const char * pcDeleteSet; HB_SIZE sDeleteSetLen; /* param check */ if( HB_ISCHAR( 1 ) ) { if( HB_ISCHAR( 2 ) ) { pcString = hb_parc( 2 ); sStrLen = hb_parclen( 2 ); pcDeleteSet = hb_parc( 1 ); sDeleteSetLen = hb_parclen( 1 ); } else { pcString = hb_parc( 1 ); sStrLen = hb_parclen( 1 ); pcDeleteSet = NULL; sDeleteSetLen = 0; } switch( iSwitch ) { case DO_CHARONE_CHARONE: if( sStrLen > 1 ) { const char * pcSub; char * pcRet; HB_SIZE sRetStrLen = 0; char cCurrent = *pcString; pcRet = ( char * ) hb_xgrab( sStrLen ); /* copy first char */ pcRet[ sRetStrLen++ ] = cCurrent; for( pcSub = pcString + 1; pcSub < pcString + sStrLen; pcSub++ ) { if( *pcSub != cCurrent ) { cCurrent = *pcSub; pcRet[ sRetStrLen++ ] = cCurrent; } else if( pcDeleteSet != NULL && ! ct_at_exact_forward( pcDeleteSet, sDeleteSetLen, pcSub, 1, NULL ) ) { pcRet[ sRetStrLen++ ] = cCurrent; } } hb_retclen( pcRet, sRetStrLen ); hb_xfree( pcRet ); } else { /* algorithm does nothing to 1-char-strings */ hb_retclen( pcString, sStrLen ); } break; case DO_CHARONE_WORDONE: if( sStrLen > 3 && ( pcDeleteSet == NULL || sDeleteSetLen >= 2 ) ) { const char * pcSub; char * pcRet; HB_SIZE sRetStrLen = 0; char cCurrent1 = pcString[ 0 ]; char cCurrent2 = pcString[ 1 ]; pcRet = ( char * ) hb_xgrab( sStrLen ); /* copy first double char */ pcRet[ sRetStrLen++ ] = cCurrent1; pcRet[ sRetStrLen++ ] = cCurrent2; for( pcSub = pcString + 2; pcSub < pcString + sStrLen - 1; pcSub += 2 ) { if( ! ( pcSub[ 0 ] == cCurrent1 && pcSub[ 1 ] == cCurrent2 ) ) { cCurrent1 = pcSub[ 0 ]; cCurrent2 = pcSub[ 1 ]; pcRet[ sRetStrLen++ ] = cCurrent1; pcRet[ sRetStrLen++ ] = cCurrent2; } else if( pcDeleteSet != NULL ) { const char * pc = NULL; const char * pStart = pcDeleteSet; HB_SIZE sLen = sDeleteSetLen; while( sLen >= 2 && ( pc = ct_at_exact_forward( pStart, sLen, pcSub, 2, NULL ) ) != 0 && ( pc - pcDeleteSet ) % 2 == 1 ) { pStart = pc + 1; sLen = sDeleteSetLen - ( pStart - pcDeleteSet ); } if( pc == NULL ) { pcRet[ sRetStrLen++ ] = cCurrent1; pcRet[ sRetStrLen++ ] = cCurrent2; } } } /* copy last character if string len is odd */ if( sStrLen & 1 ) pcRet[ sRetStrLen++ ] = pcString[ sStrLen - 1 ]; hb_retclen( pcRet, sRetStrLen ); hb_xfree( pcRet ); } else { /* algorithm does nothing to 3-char-strings */ hb_retclen( pcString, sStrLen ); } break; } } 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_CHARONE_CHARONE ? CT_ERROR_CHARONE : CT_ERROR_WORDONE, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else hb_retc_null(); } }
/* 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; } } } }