Beispiel #1
0
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 );
}
Beispiel #2
0
static int hb_ssl_pem_password_cb( char * buf, int size, int rwflag, void * userdata )
{
   int retsize = 0;

   if( size > 0 && userdata && hb_vmRequestReenter() )
   {
      hb_vmPushEvalSym();
      hb_vmPush( ( PHB_ITEM ) userdata );
      hb_vmPushLogical( rwflag );
      hb_vmSend( 1 );

      buf[ 0 ] = '\0';

      retsize = ( int ) hb_parclen( -1 );

      if( retsize > 0 )
      {
         if( retsize > size )
            retsize = size;

         memcpy( buf, hb_parc( -1 ), retsize );
      }

      hb_vmRequestRestore();
   }

   return retsize;
}
Beispiel #3
0
static void hb_inetConnectInternal( HB_BOOL fResolve )
{
   const char * szHost = hb_parc( 1 );
   char * szAddr = NULL;
   PHB_SOCKET_STRUCT socket = HB_PARSOCKET( 3 );
   PHB_ITEM pSocket = NULL;
   int iPort = hb_parni( 2 );

   if( szHost == NULL || iPort == 0 || ( socket == NULL && ! HB_ISNIL( 3 ) ) )
      hb_inetErrRT();
   else
   {
      if( ! socket )
         HB_SOCKET_INIT( socket, pSocket );
      else if( socket->sd != HB_NO_SOCKET )
         hb_inetCloseSocket( socket, HB_FALSE );

      if( fResolve )
         szHost = szAddr = hb_socketResolveAddr( szHost, HB_SOCKET_AF_INET );

      if( fResolve && ! szAddr )
      {
         hb_inetGetError( socket );
         if( socket->iError == 0 )
            socket->iError = HB_SOCKET_ERR_WRONGADDR;
      }
      else
      {
         /* Creates comm socket */
         socket->sd = hb_socketOpen( HB_SOCKET_PF_INET, HB_SOCKET_PT_STREAM, 0 );
         if( socket->sd == HB_NO_SOCKET )
            hb_inetGetError( socket );
         else
         {
            if( socket->remote )
               hb_xfree( socket->remote );
            if( hb_socketInetAddr( &socket->remote, &socket->remotelen,
                                   szHost, iPort ) )
            {
               hb_socketSetKeepAlive( socket->sd, HB_TRUE );
               if( hb_socketConnect( socket->sd, socket->remote, socket->remotelen,
                                     socket->iTimeout ) != 0 )
                  hb_inetGetError( socket );
               else
                  socket->iError = HB_INET_ERR_OK;
            }
            else
               hb_inetGetError( socket );
         }
         if( szAddr )
            hb_xfree( szAddr );
      }
      if( pSocket )
         hb_itemReturnRelease( pSocket );
      else
         hb_itemReturn( hb_param( 3, HB_IT_ANY ) );
   }
}
Beispiel #4
0
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 );
}
Beispiel #5
0
static PHB_CODEPAGE _hb_jsonCdpPar( int iParam )
{
   if( hb_pcount() >= iParam )
   {
      const char * szCdp = hb_parc( iParam );

      if( szCdp )
         return hb_cdpFindExt( szCdp );
   }
   return NULL;
}
Beispiel #6
0
static char * s_fileLinkRead( PHB_FILE_FUNCS pFuncs, const char * pszFileName )
{
   PHB_IOUSR pIO = ( PHB_IOUSR ) pFuncs;
   const char * pszLink;

   s_pushMethod( pIO, IOUSR_LINKREAD );
   hb_vmPushString( pszFileName, strlen( pszFileName ) );
   hb_vmDo( 1 );

   pszLink = hb_parc( -1 );
   return pszLink != NULL ? hb_strdup( pszLink ) : NULL;
}
Beispiel #7
0
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;
}
Beispiel #8
0
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 );
}
Beispiel #9
0
static PHB_CODEPAGE _hb_jsonCdpPar( int iParam, HB_BOOL lVmCp )
{
   if( hb_pcount() >= iParam )
   {
      const char * szCdp = hb_parc( iParam );

      if( szCdp )
         return hb_cdpFindExt( szCdp );
   }
   else if( lVmCp )
      return hb_vmCDP();

   return NULL;
}
Beispiel #10
0
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;
}
Beispiel #11
0
static char * sz_callhrb_i( char * szName, int iParam1 )
{
   PHB_DYNS pSym_onEvent = hb_dynsymFindName( szName );

   if( pSym_onEvent )
   {
      hb_vmPushSymbol( hb_dynsymSymbol( pSym_onEvent ) );
      hb_vmPushNil();
      hb_vmPushInteger( iParam1 );
      hb_vmDo( 1 );
      return (char *) hb_parc(-1);
   }
   else
      return "";
}
Beispiel #12
0
static char * sz_callhrb_sz( char * szName, char * szParam1 )
{
   PHB_DYNS pSym_onEvent = hb_dynsymFindName( szName );

   if( pSym_onEvent )
   {
      hb_vmPushSymbol( hb_dynsymSymbol( pSym_onEvent ) );
      hb_vmPushNil();
      hb_vmPushString( szParam1, strlen( szParam1 ) );
      hb_vmDo( 1 );
      return (char *) hb_parc(-1);
   }
   else
      return "";
}
Beispiel #13
0
static const char * s_hb_padGet( PHB_CODEPAGE cdp, HB_SIZE * pnPad )
{
   const char * szPad = hb_parc( 3 );

   *pnPad = 1;
   if( szPad == NULL )
      szPad = " ";
   else if( HB_CDP_ISCHARIDX( cdp ) )
   {
      *pnPad = hb_cdpTextPos( cdp, szPad, hb_parclen( 3 ), 1 );
      if( *pnPad == 0 )
         szPad = "";
   }
   return szPad;
}
Beispiel #14
0
Datei: files.c Projekt: AMHF/core
static PHB_FFIND _hb_fileStart( HB_BOOL fNext, HB_BOOL fAny )
{
   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 )
      {
         HB_FATTR ulAttr;

         ulAttr = ( HB_FATTR ) hb_parnldef( 2, fAny ? HB_FA_ANY : HB_FA_ALL );
         pFFData->ulAttr = hb_parl( 3 ) ? ulAttr : 0;
         pFFData->ffind  = hb_fsFindFirst( szFile, ulAttr );
         while( pFFData->ffind && pFFData->ulAttr &&
                HB_FF_ATTR( pFFData->ffind ) != 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 && HB_FF_ATTR( pFFData->ffind ) != pFFData->ulAttr );
   }

   return pFFData->ffind;
}
Beispiel #15
0
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;
}
Beispiel #16
0
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;
}
Beispiel #17
0
static AREAP s_foxAreaPointer( int iParam )
{
   if( HB_ISNIL( iParam ) )
      return ( AREAP ) hb_rddGetCurrentWorkAreaPointer();
   else
   {
      const char * szAlias = hb_parc( iParam );
      int iArea;

      if( szAlias )
         hb_rddGetAliasNumber( szAlias, &iArea );
      else
         iArea = hb_parni( iParam );

      return ( AREAP ) hb_rddGetWorkAreaPointer( iArea );
   }
}
Beispiel #18
0
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;
}
Beispiel #19
0
   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 );
}
Beispiel #20
0
static HB_BOOL hb_memowrit( HB_BOOL bHandleEOF )
{
   const char * pszFileName = hb_parc( 1 );
   PHB_ITEM pString   = hb_param( 2, HB_IT_STRING );
   HB_BOOL bRetVal    = HB_FALSE;

   if( pszFileName && pString )
   {
      PHB_FILE pFile = hb_fileExtOpen( pszFileName, NULL,
                                       FO_READWRITE | FO_EXCLUSIVE | FO_PRIVATE |
                                       FXO_TRUNCATE | FXO_SHARELOCK,
                                       NULL, NULL );

      if( pFile != NULL )
      {
         HB_SIZE nSize = hb_itemGetCLen( pString );
         const char * pData = hb_itemGetCPtr( pString );

         while( nSize > 0 )
         {
            HB_SIZE nWritten = hb_fileWrite( pFile, pData, nSize, 0 );
            if( nWritten == 0 || nWritten == ( HB_SIZE ) FS_ERROR )
               break;
            nSize -= nWritten;
            pData += nWritten;
         }
         bRetVal = nSize == 0;

         /* NOTE: CA-Cl*pper will add the EOF even if the write failed. [vszakats] */
         /* NOTE: CA-Cl*pper will not return .F. when the EOF could not be written. [vszakats] */
         if( bHandleEOF && bRetVal )  /* if true, then write EOF */
         {
            char cEOF = HB_CHAR_EOF;
            hb_fileWrite( pFile, &cEOF, sizeof( char ), -1 );
         }

         hb_fileClose( pFile );
      }
   }

   return bRetVal;
}
Beispiel #21
0
/* 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 );
   }
}
Beispiel #22
0
static void hb_memoread( HB_BOOL bHandleEOF )
{
   const char * pszFileName = hb_parc( 1 );

   if( pszFileName )
   {
      PHB_FILE pFile = hb_fileExtOpen( pszFileName, NULL,
                                       FO_READ | FO_SHARED | FO_PRIVATE |
                                       FXO_SHARELOCK | FXO_NOSEEKPOS,
                                       NULL, NULL );

      if( pFile != NULL )
      {
         HB_SIZE nSize = ( HB_SIZE ) hb_fileSize( pFile );

         if( nSize != 0 )
         {
            char * pbyBuffer = ( char * ) hb_xgrab( nSize + 1 );

            nSize = hb_fileReadAt( pFile, pbyBuffer, nSize, 0 );

            /* Don't read the file terminating EOF character */
            if( bHandleEOF && nSize > 0 )
            {
               if( pbyBuffer[ nSize - 1 ] == HB_CHAR_EOF )
                  --nSize;
            }

            hb_retclen_buffer( pbyBuffer, nSize );
         }
         else
            hb_retc_null();

         hb_fileClose( pFile );
      }
      else
         hb_retc_null();
   }
   else
      hb_retc_null();
}
Beispiel #23
0
static HB_BOOL hb_sxSemName( char * szFileName )
{
   const char * szName = hb_parc( 1 );
   HB_BOOL fResult = HB_FALSE;

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

      if( pArea )
      {
         DBORDERINFO pOrderInfo;

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

   return fResult;
}
Beispiel #24
0
/* helper function for the justxxx() functions */
static void do_justify( int iSwitch )
{
   int iNoRet;

   iNoRet = ct_getref() && ISBYREF( 1 );

   if( 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( 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, (size_t) ( 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, (size_t) ( sStrLen - sJustOffset ) );
            break;
      }

      if( ISBYREF( 1 ) )
         hb_storclen( pcRet, sStrLen, 1 );

      if( iNoRet )
      {
         hb_ret();
         hb_xfree( pcRet );
      }
      else
         hb_retclen_buffer( pcRet, sStrLen );
   }
   else  /* ISCHAR( 1 ) */
   {
      PHB_ITEM pSubst         = NULL;
      int      iArgErrorMode  = ct_getargerrormode();

      if( iArgErrorMode != CT_ARGERR_IGNORE )
      {
         pSubst = ct_error_subst( ( 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();
   }
}
Beispiel #25
0
/* 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();
   }
}
Beispiel #26
0
/* 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();
   }
}
Beispiel #27
0
/* 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 );
   }
}
Beispiel #28
0
/* helper function */
static void do_atnum( int iSwitch )
{
   if( ( ISCHAR( 1 ) ) && ( 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, sMatchStrLen = 0;
      ULONG          ulCounter;
      const char *   pc                = NULL;

      /* eventually ignore some characters */
      if( ISNUM( 4 ) )
         sIgnore = ( size_t ) hb_parnl( 4 );
      else
         sIgnore = 0;

      if( sIgnore >= sStrLen )
      {
         switch( iSwitch )
         {
            case DO_ATNUM_AFTERATNUM:
            {
               /* AFTERATNUM */
               int iArgErrorMode = ct_getargerrormode();
               if( iArgErrorMode != CT_ARGERR_IGNORE )
               {
                  ct_error( ( USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_AFTERATNUM,
                            NULL, "AFTERATNUM", 0, EF_CANDEFAULT, 4,
                            hb_paramError( 1 ), hb_paramError( 2 ),
                            hb_paramError( 3 ), hb_paramError( 4 ) );
               }
               ;
               hb_retc( "" );
            }; break;

            case DO_ATNUM_BEFORATNUM:
            {
               /* BEFORATNUM */
               int iArgErrorMode = ct_getargerrormode();
               if( iArgErrorMode != CT_ARGERR_IGNORE )
               {
                  ct_error( ( USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_BEFORATNUM,
                            NULL, "BEFORATNUM", 0, EF_CANDEFAULT, 4,
                            hb_paramError( 1 ), hb_paramError( 2 ),
                            hb_paramError( 3 ), hb_paramError( 4 ) );
               }
               ;
               hb_retc( "" );
            }; break;

            case DO_ATNUM_ATNUM:
            {
               /* ATNUM */
               int iArgErrorMode = ct_getargerrormode();
               if( iArgErrorMode != CT_ARGERR_IGNORE )
               {
                  ct_error( ( USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_ATNUM,
                            NULL, "ATNUM", 0, EF_CANDEFAULT, 4,
                            hb_paramError( 1 ), hb_paramError( 2 ),
                            hb_paramError( 3 ), hb_paramError( 4 ) );
               }
               ;
               hb_retnl( 0 );
            }; break;
         }

         return;
      }
      else
      {
         pcString += sIgnore;
         sStrLen  -= sIgnore;
      }

      /* nth match or last match ? */
      if( ISNUM( 3 ) && ( ( ulCounter = hb_parnl( 3 ) ) != 0 ) )
      {
         /* find the <ulCounter>th match */
         const char *   pcSubStr;
         HB_SIZE        sSubStrLen;
         ULONG          ulMatchCounter = 0;

         pcSubStr    = pcString;
         sSubStrLen  = sStrLen;

         while( ulMatchCounter < ulCounter )
         {
            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 <ulCounter> matches, so return an empty string */
               switch( iSwitch )
               {
                  case DO_ATNUM_AFTERATNUM:
                  case DO_ATNUM_BEFORATNUM:
                  {
                     /* AFTERATNUM */
                     /* BEFORATNUM */
                     hb_retc( "" );
                  }; break;

                  case DO_ATNUM_ATNUM:
                  {
                     /* ATNUM */
                     hb_retnl( 0 );
                  }; break;
               }

               return;
            }

            ulMatchCounter++;

            if( iMultiPass )
               pcSubStr = pc + 1;
            else
               pcSubStr = pc + sMatchStrLen;
            sSubStrLen = sStrLen - ( pcSubStr - pcString );
         }

      }
      else /* (ISNUM (3) && ((ulCounter = hb_parnl (3)) != 0) */
      {
         /* 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( "" );
               }; break;

               case DO_ATNUM_ATNUM:
               {
                  /* ATNUM */
                  hb_retnl( 0 );
               }; break;
            }

            return;
         }

      }

      switch( iSwitch )
      {
         case DO_ATNUM_AFTERATNUM:
         {
            /* AFTERATNUM */
            if( pc + sMatchStrLen >= pcString + sStrLen )
               hb_retc( "" );
            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 */
            hb_retns( pc - ( pcString - sIgnore ) + 1 );
         }; break;
      }

   }
   else /* ((ISCHAR (1)) && (ISCHAR (2))) */
   {
      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( ( USHORT ) iArgErrorMode, EG_ARG,
                                        ( iSwitch == DO_ATNUM_AFTERATNUM ? CT_ERROR_AFTERATNUM : CT_ERROR_BEFORATNUM ),
                                        NULL,
                                        ( iSwitch == DO_ATNUM_AFTERATNUM ? "AFTERATNUM" : "BEFORATNUM" ),
                                        0, EF_CANSUBSTITUTE, 4,
                                        hb_paramError( 1 ), hb_paramError( 2 ),
                                        hb_paramError( 3 ), hb_paramError( 4 ) );
            }

            if( pSubst != NULL )
            {
               hb_itemRelease( hb_itemReturnForward( pSubst ) );
            }
            else
            {
               hb_retc( "" );
            }
         }; break;

         case DO_ATNUM_ATNUM:
         {
            /* ATNUM */
            PHB_ITEM pSubst         = NULL;
            int      iArgErrorMode  = ct_getargerrormode();
            if( iArgErrorMode != CT_ARGERR_IGNORE )
            {
               pSubst = ct_error_subst( ( USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_ATNUM,
                                        NULL, "ATNUM", 0, EF_CANSUBSTITUTE, 4,
                                        hb_paramError( 1 ), hb_paramError( 2 ),
                                        hb_paramError( 3 ), hb_paramError( 4 ) );
            }

            if( pSubst != NULL )
            {
               hb_itemRelease( hb_itemReturnForward( pSubst ) );
            }
            else
            {
               hb_retnl( 0 );
            }
         }; break;
      }
   }
}
Beispiel #29
0
/* 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();
   }
}
Beispiel #30
0
/* helper function for the justxxx() functions */
static void do_justify (int iSwitch)
{

  int iNoRet;

  iNoRet = ct_getref() && ISBYREF( 1 );

  if (ISCHAR (1))
  {

    char *pcString = hb_parc (1);
    size_t sStrLen = hb_parclen (1);
    char cJustChar;
    char *pc, *pcRet;
    size_t sJustOffset;

    if ( sStrLen == 0 )
    {
       if (iNoRet)
       {
          hb_ret();
       }
       else
       {
          hb_retc( "" );
       }
       return;
    }

    if (hb_parclen (2) > 0)
      cJustChar = *(hb_parc (2));
    else if (ISNUM (2))
      cJustChar = (char)( hb_parnl (2) % 256 );
    else
      cJustChar = 0x20;

    pcRet = ( char *)hb_xgrab (sStrLen);

    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 (pc = pcRet+sStrLen-sJustOffset; pc < pcRet+sStrLen; pc++)
        {
          *pc = cJustChar;
        }

      }; break;

      case DO_JUSTIFY_JUSTRIGHT:
      {
        pc = pcString+sStrLen-1;
        sJustOffset = 0;
        while ((*pc == cJustChar) && (pc >= pcString))
        {
          sJustOffset++;
          pc--;
        }

        for (pc = pcRet; pc < pcRet+sJustOffset; pc++)
        {
          *pc = cJustChar;
        }
        hb_xmemcpy (pcRet+sJustOffset, pcString, sStrLen-sJustOffset);

      }; break;

    }

    if (ISBYREF (1))
      hb_storclen (pcRet, sStrLen, 1);

    if (iNoRet)
      hb_ret();
    else
      hb_retclen (pcRet, sStrLen);

    hb_xfree (pcRet);

  }
  else /* ISCHAR (1) */
  {
    PHB_ITEM pSubst = NULL;
    int iArgErrorMode = ct_getargerrormode();
    if (iArgErrorMode != CT_ARGERR_IGNORE)
    {
      pSubst = ct_error_subst ((USHORT)iArgErrorMode, EG_ARG,
                               (iSwitch == DO_JUSTIFY_JUSTLEFT ? CT_ERROR_JUSTLEFT : CT_ERROR_JUSTRIGHT),
                               NULL,
                               (iSwitch == DO_JUSTIFY_JUSTLEFT ? "JUSTLEFT" : "JUSTRIGHT"),
                               0, EF_CANSUBSTITUTE, 2,
                               hb_paramError (1), hb_paramError (2));
    }

    if (pSubst != NULL)
    {
      hb_itemRelease( hb_itemReturnForward( pSubst ) );
    }
    else
    {
      if (iNoRet)
        hb_ret();
      else
        hb_retc ("");
    }
  }

  return;

}