예제 #1
0
static char * hb_mlGetParams( int iParAdd, ULONG * pulLen, ULONG * pulLineLength,
                              ULONG * pulTabSize, BOOL * pfWordWrap,
                              PHB_EOL_INFO * pEOLs, int * piEOLs )
{
   char * pszString = hb_parc( 1 );
   if( pszString )
   {
      if( ISNUM( 2 ) )
      {
         if( hb_parnd( 2 ) <= 0 )
            return NULL;
         * pulLineLength = hb_parnl( 2 );
      }
      else
         * pulLineLength = 79;
      * pulLen = hb_parclen( 1 );
      * pulTabSize = ISNUM( 3 + iParAdd ) ? hb_parnl( 3 + iParAdd ) : 4;
      * pfWordWrap = ISLOG( 4 + iParAdd ) ? hb_parl( 4 + iParAdd ) : TRUE;
      * pEOLs = hb_mlGetEOLs( 5 + iParAdd, piEOLs );
#ifdef HB_C52_STRICT
      if( * pulLineLength > 254 )
         * pulLineLength = 79;
#endif
      if( * pulTabSize >= * pulLineLength )
         * pulTabSize = * pulLineLength - 1;
      else if( * pulTabSize == 0 )
         * pulTabSize = 1;
   }
   return pszString;
}
예제 #2
0
파일: files.c 프로젝트: ggargano/hbtest2
static PHB_FFIND _hb_fileStart( HB_BOOL fNext, HB_FATTR ulAttr )
{
   PHB_FFDATA pFFData = HB_GET_FFDATA();

   if( hb_pcount() > 0 )
   {
      const char * szFile = hb_parc( 1 );

      if( pFFData->ffind )
      {
         hb_fsFindClose( pFFData->ffind );
         pFFData->ffind = NULL;
      }

      if( szFile )
      {
         if( HB_ISNUM( 2 ) )
            ulAttr = ( HB_FATTR ) hb_parnl( 2 );
         pFFData->ulAttr = hb_parl( 3 ) ? ulAttr : HB_FA_ALL;
         pFFData->ffind  = hb_fsFindFirst( szFile, ulAttr );
         while( pFFData->ffind && pFFData->ulAttr &&
                pFFData->ffind->attr != pFFData->ulAttr )
         {
            if( ! hb_fsFindNext( pFFData->ffind ) )
            {
               hb_fsFindClose( pFFData->ffind );
               pFFData->ffind = NULL;
            }
         }
      }
   }
   else if( fNext && pFFData->ffind )
   {
      do
      {
         if( ! hb_fsFindNext( pFFData->ffind ) )
         {
            hb_fsFindClose( pFFData->ffind );
            pFFData->ffind = NULL;
            break;
         }
      }
      while( pFFData->ulAttr && pFFData->ffind->attr != pFFData->ulAttr );
   }

   return pFFData->ffind;
}
예제 #3
0
static void s_getPathName( _HB_GETPATHNAME getPathName )
{
   void * hLongPath;
   DWORD length = 0;
   LPCTSTR lpszLongPath = HB_PARSTR( 1, &hLongPath, NULL );

   if( lpszLongPath )
   {
      if( HB_ISBYREF( 2 ) )
      {
         TCHAR buffer[ HB_PATH_MAX ];
         DWORD cchBuffer = ( DWORD ) HB_SIZEOFARRAY( buffer );
         LPTSTR lpszShortPath = buffer;
         HB_BOOL fSize = HB_ISNUM( 3 );

         if( fSize )    /* the size of buffer is limited by user */
         {
            cchBuffer = ( DWORD ) hb_parnl( 3 );
            if( cchBuffer == 0 )
               lpszShortPath = NULL;
            else if( cchBuffer > ( DWORD ) HB_SIZEOFARRAY( buffer ) )
               lpszShortPath = ( LPTSTR ) hb_xgrab( cchBuffer * sizeof( TCHAR ) );
         }

         length = getPathName( lpszLongPath, lpszShortPath, cchBuffer );
         if( ! fSize && length > cchBuffer )  /* default buffer size was too small */
         {
            cchBuffer = length;
            lpszShortPath = ( LPTSTR ) hb_xgrab( cchBuffer * sizeof( TCHAR ) );
            length = getPathName( lpszLongPath, lpszShortPath, cchBuffer );
         }
         hbwapi_SetLastError( GetLastError() );
         HB_STORSTRLEN( lpszShortPath, length > cchBuffer ? 0 : length, 2 );
         if( lpszShortPath && lpszShortPath != buffer )
            hb_xfree( lpszShortPath );
      }
      else if( getPathName )
      {
         length = getPathName( lpszLongPath, NULL, 0 );
         hbwapi_SetLastError( GetLastError() );
      }
   }
   hb_retnl( length );
   hb_strfree( hLongPath );
}
예제 #4
0
/*
    wxSocketBase_ReadBase
    Teo. Mexico 2009
*/
void wxSocketBase_ReadBase( HB_BYTE type )
{
    PHB_ITEM pSelf = hb_stackSelfItem();
    wx_SocketBase* socketBase = (wx_SocketBase*) xho_itemListGet_XHO( pSelf );

    PHB_ITEM pBuffer = hb_param( 1, HB_IT_STRING );

    if( pBuffer == NULL || !HB_ISBYREF( 1 ) )
    {
        hb_errRT_BASE_SubstR( EG_ARG, WXH_ERRBASE + 10, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
        return;
    }

    if( socketBase )
    {
        pBuffer = hb_itemUnShareString( pBuffer );

        wxUint32 nbytes = HB_ISNIL( 2 ) ?  hb_itemGetCLen( pBuffer ) : hb_parnl( 2 );

        if( nbytes > 0 )
        {
            if( nbytes > hb_itemGetCLen( pBuffer ) )
                hb_itemReSizeString( pBuffer, nbytes );

            if( type == '0' )
                socketBase->Read( (char *) hb_itemGetCPtr( pBuffer ), nbytes );
            else
                socketBase->ReadMsg( (char *) hb_itemGetCPtr( pBuffer ), nbytes );

            wxUint32 uiLastCount = socketBase->LastCount();

            if( uiLastCount < hb_itemGetCLen( pBuffer ) )
//         hb_itemGetCLen( pBuffer ) = uiLastCount;
                hb_itemReSizeString( pBuffer, uiLastCount );

        }else
            hb_errRT_BASE_SubstR( EG_ARG, WXH_ERRBASE + 10, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );

        hb_itemReturn( pSelf );
    }
}
예제 #5
0
파일: wvgwing.c 프로젝트: NaldoDj/core
BOOL CALLBACK WvgDialogProcChooseFont( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
   HB_BOOL  bret  = HB_FALSE;
   HB_BOOL  binit = HB_FALSE;
   PHB_ITEM block;

   if( msg == WM_INITDIALOG )
   {
      CHOOSEFONT * cf     = ( CHOOSEFONT * ) lParam;
      PHB_ITEM     pBlock = ( PHB_ITEM ) hb_itemNew( ( PHB_ITEM ) cf->lCustData );
      SetProp( hwnd, TEXT( "DIALOGPROC" ), pBlock );
      binit = HB_TRUE;
   }

   block = ( PHB_ITEM ) GetProp( hwnd, TEXT( "DIALOGPROC" ) );

   if( block )
   {
      hb_vmPushEvalSym();
      hb_vmPush( block );
      hb_vmPushNumInt( ( HB_PTRUINT ) hwnd );
      hb_vmPushInteger( msg );
      hb_vmPushNumInt( ( HB_PTRUINT ) wParam );
      hb_vmPushNumInt( ( HB_PTRUINT ) lParam );
      hb_vmDo( 4 );
      bret = hb_parnl( -1 );

      if( msg == WM_NCDESTROY )
      {
         RemoveProp( hwnd, TEXT( "DIALOGPROC" ) );
         hb_itemRelease( block );
      }
   }
   if( binit )
      return HB_TRUE;

   return bret;
}
예제 #6
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;

}
예제 #7
0
파일: remove.c 프로젝트: jiangxilong/core
/* 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();
    }
}
예제 #8
0
파일: count.c 프로젝트: NaldoDj/core
/* 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 );
   }
}
예제 #9
0
파일: replace.c 프로젝트: 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();
   }
}
예제 #10
0
파일: pos1.c 프로젝트: xharbour/core
/* helper function for the posxxx() functions */
static void do_pos1( int iSwitch )
{

   if( ( ISCHAR( 1 ) )                       /* all functions need string as 1st param */
       &&
       ( ( iSwitch != DO_POS1_POSRANGE )     /* that's the only condition for all funcs _except_ POSRANGE */
         ||
         ( ( iSwitch == DO_POS1_POSRANGE )   /* In addition, POSRANGE needs .. */
          &&
          ( ISCHAR( 2 ) )                    /* .. string as 2nd .. */
          &&
          ( ISCHAR( 3 ) )                    /* .. and 3rd param */
         )
       )
       )
   {

      unsigned char *   pcString;
      size_t            sStrLen;
      unsigned char *   puc, ucChar1 = ' ', ucChar2 = ' ';
      int               iMode;
      size_t            sIgnore;
      int               iParamShift = 0;

      if( iSwitch == DO_POS1_POSRANGE )
      {

         if( hb_parclen( 1 ) == 0 )
         {
            hb_retnl( 0 );
            return;
         }
         else
         {
            ucChar1 = *( hb_parc( 1 ) );
         }

         if( hb_parclen( 2 ) == 0 )
         {
            hb_retnl( 0 );
            return;
         }
         else
         {
            ucChar2 = *( hb_parc( 2 ) );
         }

         iParamShift += 2;
      }

      pcString = ( unsigned char * ) hb_parc( iParamShift + 1 );
      sStrLen  = ( size_t ) hb_parclen( iParamShift + 1 );

      if( ISLOG( iParamShift + 2 ) )
         iMode = hb_parl( iParamShift + 2 );
      else
         iMode = 0;

      if( ISNUM( iParamShift + 3 ) )
         sIgnore = ( size_t ) hb_parnl( iParamShift + 3 );
      else
         sIgnore = 0;

      for( puc = pcString + sIgnore; puc < pcString + sStrLen; puc++ )
      {
         int iDoRet = 0;
         switch( iSwitch )
         {
            case DO_POS1_POSALPHA:
            {
               iDoRet = ISALPHA( *puc );
            }; break;

            case DO_POS1_POSLOWER:
            {
               iDoRet = ISLOWER( *puc );
            }; break;

            case DO_POS1_POSRANGE:
            {
               iDoRet = ( ( ucChar1 <= *puc ) && ( ucChar2 >= *puc ) );
            }; break;

            case DO_POS1_POSUPPER:
            {
               iDoRet = ISUPPER( *puc );
            }; break;
         }

         if( ( iMode && ! iDoRet ) || ( ! iMode && iDoRet ) )
         {
            hb_retns( puc - pcString + 1 );
            return;
         }
      }

      hb_retnl( 0 );

   }
   else /* ISCHAR (1) etc. */
   {
      PHB_ITEM pSubst         = NULL;
      int      iArgErrorMode  = ct_getargerrormode();
      if( iArgErrorMode != CT_ARGERR_IGNORE )
      {
         switch( iSwitch )
         {
            case DO_POS1_POSALPHA:
            {
               pSubst = ct_error_subst( ( USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_POSALPHA,
                                        NULL, "POSALPHA", 0, EF_CANSUBSTITUTE, 3,
                                        hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) );
            }; break;

            case DO_POS1_POSLOWER:
            {
               pSubst = ct_error_subst( ( USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_POSLOWER,
                                        NULL, "POSLOWER", 0, EF_CANSUBSTITUTE, 3,
                                        hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) );
            }; break;

            case DO_POS1_POSRANGE:
            {
               pSubst = ct_error_subst( ( USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_POSRANGE,
                                        NULL, "POSRANGE", 0, EF_CANSUBSTITUTE, 5,
                                        hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ),
                                        hb_paramError( 4 ), hb_paramError( 5 ) );
            }; break;

            case DO_POS1_POSUPPER:
            {
               pSubst = ct_error_subst( ( USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_POSUPPER,
                                        NULL, "POSUPPER", 0, EF_CANSUBSTITUTE, 3,
                                        hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) );
            }; break;
         }
      }

      if( pSubst != NULL )
      {
         hb_itemRelease( hb_itemReturnForward( pSubst ) );
      }
      else
      {
         hb_retnl( 0 );
      }
   }
}
예제 #11
0
/* helper function for the pad functions */
static void do_pad (int iSwitch)
{

  if (ISCHAR (1) && ISNUM (2))
  {

    char *pcString = (char *)hb_parc (1);
    size_t sStrLen = (size_t)hb_parclen (1);
    char *pcRet, *pc;
    LONG lRetLen;
    size_t sRetLen;
    char cFill;

    lRetLen = hb_parnl (2);
    if (lRetLen <= 0)
    {
      int iArgErrorMode = ct_getargerrormode();
      if (iArgErrorMode != CT_ARGERR_IGNORE)
      {
        ct_error ((USHORT)iArgErrorMode, EG_ARG,
                  (iSwitch == DO_PAD_PADLEFT ? CT_ERROR_PADLEFT : CT_ERROR_PADRIGHT),
                  NULL,
                  (iSwitch == DO_PAD_PADLEFT ? "PADLEFT" : "ROR_PADRIGHT"),
                  0, EF_CANDEFAULT, 3,
                  hb_paramError (1), hb_paramError (2),
                  hb_paramError (3));
      }
      hb_retc ("");
      return;
    }
    sRetLen = (size_t)lRetLen;

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

    pcRet = ( char * )hb_xgrab (sRetLen);

    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 (pcRet, sRetLen);
    hb_xfree (pcRet);

  }
  else /* ISCHAR (1) && ISNUM (2) */
  {
    PHB_ITEM pSubst = NULL;
    int iArgErrorMode = ct_getargerrormode();
    if (iArgErrorMode != CT_ARGERR_IGNORE)
    {
      pSubst = ct_error_subst ((USHORT)iArgErrorMode, EG_ARG,
                               (iSwitch == DO_PAD_PADLEFT ? CT_ERROR_PADLEFT : CT_ERROR_PADRIGHT),
                               NULL,
                               (iSwitch == DO_PAD_PADLEFT ? "PADLEFT" : "ROR_PADRIGHT"),
                               0, EF_CANSUBSTITUTE, 3,
                               hb_paramError (1), hb_paramError (2),
                               hb_paramError (3));
    }

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

  return;

}
예제 #12
0
파일: hbi18n1.c 프로젝트: JamesLinus/core
PHB_ITEM hb_i18n_ngettext( PHB_ITEM pNum, PHB_ITEM pMsgID, PHB_ITEM pContext )
{
   PHB_I18N_TRANS pI18N = hb_i18n_table();
   PHB_CODEPAGE cdpage = NULL;
   PHB_ITEM pMsgDst = pMsgID;
   PHB_ITEM pBlock = NULL;
   int iPluralForm = 0;

   if( pI18N )
   {
      PHB_ITEM pTable = pContext && pI18N->context_table ?
                        hb_hashGetItemPtr( pI18N->context_table, pContext, 0 ) :
                        pI18N->default_context;

      cdpage = pI18N->base_cdpage;
      pBlock = pI18N->base_plural_block;
      iPluralForm = pI18N->base_plural_form;

      if( pTable )
      {
         PHB_ITEM pMsg = HB_IS_ARRAY( pMsgID ) ?
                         hb_arrayGetItemPtr( pMsgID, 1 ) : pMsgID;
         pTable = pMsg && HB_IS_STRING( pMsg ) ?
                  hb_hashGetItemPtr( pTable, pMsg, 0 ) : NULL;
         if( pTable )
         {
            if( HB_IS_STRING( pTable ) ||
                ( HB_IS_ARRAY( pTable ) &&
                  ( hb_arrayGetType( pTable, 1 ) & HB_IT_STRING ) != 0 ) )
            {
               pMsgID = pTable;
               cdpage = pI18N->cdpage;
               pBlock = pI18N->plural_block;
               iPluralForm = pI18N->plural_form;
            }
         }
      }
   }

   if( pMsgID && HB_IS_ARRAY( pMsgID ) )
   {
      long lIndex;

      if( ! pNum )
         lIndex = 1;
      else if( pBlock )
      {
         hb_evalBlock1( pBlock, pNum );
         lIndex = hb_parnl( -1 );
      }
      else
         lIndex = hb_i18n_pluralindex( iPluralForm, pNum );

      if( lIndex < 1 || ( lIndex != 1 &&
            ( hb_arrayGetType( pMsgID, lIndex ) & HB_IT_STRING ) == 0 ) )
         lIndex = 1;

      pMsgID = hb_arrayGetItemPtr( pMsgID, lIndex );
   }

   if( pMsgID )
   {
      if( HB_IS_STRING( pMsgID ) )
      {
         if( cdpage )
         {
            PHB_CODEPAGE cdp = hb_vmCDP();
            if( cdp && cdp != cdpage )
            {
               if( pMsgDst != pMsgID )
               {
                  hb_itemCopy( pMsgDst, pMsgID );
                  pMsgID = pMsgDst;
               }
               hb_i18n_transitm( pMsgID, cdpage, cdp );
            }
         }
      }
      else
         pMsgID = NULL;
   }

   return pMsgID;
}
예제 #13
0
파일: remove.c 프로젝트: xharbour/core
/* helper function for the remxxx functions */
static void do_remove( int iSwitch )
{
   /* param check */
   if( ISCHAR( 1 ) )
   {
      char *   pcString = ( char * ) hb_parc( 1 );
      size_t   sStrLen  = ( size_t ) hb_parclen( 1 );
      char *   pcRet, * pc;
      size_t   sRetLen;
      char     cSearch;

      if( hb_parclen( 2 ) > 0 )
         cSearch = *( hb_parc( 2 ) );
      else if( 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( "" );
      else
         hb_retclen( pcRet, sRetLen );

   }
   else /* if (ISCHAR (1)) */
   {
      PHB_ITEM pSubst         = NULL;
      int      iArgErrorMode  = ct_getargerrormode();
      if( iArgErrorMode != CT_ARGERR_IGNORE )
      {
         pSubst = ct_error_subst( ( USHORT ) iArgErrorMode, EG_ARG, sulErrorSubcodes[ iSwitch ],
                                  NULL, ( char * ) spcErrorOperation[ iSwitch ], 0, EF_CANSUBSTITUTE, 2,
                                  hb_paramError( 1 ), hb_paramError( 2 ) );
      }

      if( pSubst != NULL )
      {
         hb_itemRelease( hb_itemReturnForward( pSubst ) );
      }
      else
      {
         hb_retc( "" );
      }
   }
}
예제 #14
0
파일: ctpad.c 프로젝트: JamesLinus/core
/* 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();
   }
}
예제 #15
0
파일: justify.c 프로젝트: xharbour/core
/* 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();
   }
}
예제 #16
0
파일: atnum.c 프로젝트: xharbour/core
/* 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;
      }
   }
}
예제 #17
0
파일: count.c 프로젝트: xharbour/core
/* helper function for the countxxx functions */
static void do_count( int iSwitch )
{
   /* param check */
   if( ISCHAR( 1 ) )
   {
      const char *   pcString = hb_parc( 1 );
      size_t         sStrLen  = ( size_t ) hb_parclen( 1 );
      size_t         sRetVal;
      const char *   pc;
      char           cSearch;

      if( hb_parclen( 2 ) > 0 )
         cSearch = *( hb_parc( 2 ) );
      else if( 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 /* if (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_COUNT_COUNTLEFT ? CT_ERROR_COUNTLEFT : CT_ERROR_COUNTRIGHT ),
                                  NULL,
                                  ( iSwitch == DO_COUNT_COUNTLEFT ? "COUNTLEFT" : "COUNTRIGHT" ),
                                  0, EF_CANSUBSTITUTE, 2,
                                  hb_paramError( 1 ), hb_paramError( 2 ) );
      }

      if( pSubst != NULL )
      {
         hb_itemRelease( hb_itemReturnForward( pSubst ) );
      }
      else
      {
         hb_retnl( 0 );
      }
   }
}