Esempio n. 1
0
static void hb_fileReturn( PHB_FILE pFile )
{
   if( pFile )
      hb_fileItemPut( hb_param( -1, HB_IT_ANY ), pFile );
   else
      hb_ret();
}
Esempio n. 2
0
static void s_listenRet( HB_SOCKET sd, const char * szRootPath, HB_BOOL rpc )
{
   if( sd != HB_NO_SOCKET )
   {
      PHB_LISTENSD lsd, * lsd_ptr;
      int iLen;

      lsd = ( PHB_LISTENSD ) memset( hb_xgrab( sizeof( HB_LISTENSD ) ),
                                            0, sizeof( HB_LISTENSD ) );
      lsd->sd = sd;
      lsd->rpc = rpc;
      if( szRootPath )
         hb_strncpy( lsd->rootPath, szRootPath, sizeof( lsd->rootPath ) - 1 );
      else
         hb_fsBaseDirBuff( lsd->rootPath );
      iLen = ( int ) strlen( lsd->rootPath );
      if( iLen > 0 )
      {
         if( ! s_isDirSep( lsd->rootPath[ iLen - 1 ] ) )
         {
            if( iLen == sizeof( lsd->rootPath ) - 1 )
               --iLen;
            lsd->rootPath[ iLen ] = HB_OS_PATH_DELIM_CHR;
         }
      }
      lsd_ptr = ( PHB_LISTENSD * ) hb_gcAllocate( sizeof( PHB_LISTENSD ),
                                                  &s_gcListensdFuncs );
      *lsd_ptr = lsd;
      hb_retptrGC( lsd_ptr );
   }
   else
      hb_ret();
}
Esempio n. 3
0
static void s_consrvRet( PHB_CONSRV conn )
{
   if( conn )
   {
      PHB_CONSRV * conn_ptr = ( PHB_CONSRV * ) hb_gcAllocate( sizeof( PHB_CONSRV ),
                                                              &s_gcConSrvFuncs );
      *conn_ptr = conn;
      hb_retptrGC( conn_ptr );
   }
   else
      hb_ret();
}
Esempio n. 4
0
static void hb_fileReturn( PHB_FILE pFile )
{
   if( pFile )
   {
      PHB_FILE * fileHolder = ( PHB_FILE * ) hb_gcAllocate( sizeof( PHB_FILE ),
                                                            &s_gcFileFuncs );
      * fileHolder = pFile;
      hb_retptrGC( fileHolder );
   }
   else
      hb_ret();
}
Esempio n. 5
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();
   }
}
Esempio n. 6
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();
   }
}
Esempio n. 7
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;

}
Esempio n. 8
0
File: replace.c Progetto: AMHF/core
/* 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();
   }
}