コード例 #1
0
CLIPPER chgattr()
{
    if (! (PCOUNT==3 || ISCHAR(1) || ISNUM(2) || ISNUM(3)))
        _retni(0);
    else
        _retni(_chmod(_parc(1),_parni(3),_parni(2)));
}
コード例 #2
0
void CGrannyListView::OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
	
	UINT iData = GetSelectedItemData();
	CGrannyViewerDoc *pDoc = GetDocument();
	if (!pDoc) return;

	if (ISSET(iData))
	{
		if (ISANIM(iData)) 
		{
			pDoc->SetCurAnimId(GETDATA(iData));
		} 
		else if (ISCHAR(iData)) 
		{
			UINT id = GETDATA(iData);
		/*	if (GETASSIGN(id)) 
				pDoc->SetCurEquipId(id);
			else */
			
			pDoc->SetCurModelId(id);
		}
	}
	//else
	//{
	//	pDoc->SetCurModelId(INVALID_GRN_ID);
	//}

	*pResult = 0;
}
コード例 #3
0
ファイル: C_FWRITE.C プロジェクト: ibarrar/clipper
CLIPPER c_fwrite (void)
{
   int  file_handle;
   char *line;
   USHORT  line_size;
   
   if (PCOUNT == 3 && ISNUM(FILE_HANDLE) && ISCHAR(WRITE_LINE)
                   && ISNUM(LINE_SIZE) && ISBYREF(LINE_SIZE))
   {
      /* convert clipper parameters into C types... */
      file_handle = _parni(FILE_HANDLE);
      line_size = _parni(LINE_SIZE);
      line = _parc(WRITE_LINE);
      
      /* call C write function... */
      if ( _fsWrite(file_handle, line, line_size) < line_size ) 
      {
        _storni (0, LINE_SIZE);
        _ret();
        return;
      }
      
      /* flush the data to file without closing it... */
      if (asm_commit(file_handle))  
        _storni (0, LINE_SIZE);
   }
   else
      /* update line_size to zero... */
      _storni (0, LINE_SIZE);                   

   _ret();  /* returns NIL */
}
コード例 #4
0
ファイル: FILEOPEN.C プロジェクト: ibarrar/clipper
CLIPPER FILEOPEN()
{
   BYTEP fpFileName;
   FHANDLE hFile = FS_ERROR;
   USHORT uiFlags = FO_READWRITE;
   ERRORP pError;

   if ( ISCHAR( 1 ) )
   {
      fpFileName = _parc( 1 );

      uiFlags |= ( ISLOG( 2 ) && _parl( 2 ) ) ? FO_SHARED : FO_EXCLUSIVE;

      pError = _errNew();
      _errPutSubCode( pError, 1111 );     // subCode determined by caller

      hFile = FileOpener( fpFileName, uiFlags, pError );

      if ( ISBYREF( 1 ) )
         _storc( fpFileName, 1 );
   }

   _retni( hFile );

}
コード例 #5
0
ファイル: VERIFONE.C プロジェクト: ibarrar/clipper
CLIPPER veri_recv()
{
  unsigned char buffer[100];
  int data=0,i;
  long far *timer_ticks = (long far *) 0x0040006CL;
  long timein = *timer_ticks+1080L;
  char far * str_txt;

  
  if ( PCOUNT == 2 && ISBYREF(BYTES_READ) && ISNUM(BYTES_READ)
                    && ISBYREF(STR_TXT)  && ISCHAR(STR_TXT) )
  {
     str_txt = _parc(STR_TXT);
     
     i = 0;
     while ( ((data & 0x00ff) != 0x03)  &&  ( timein > *timer_ticks ))
     {
       if (pfl_com_sts(port_no) & DATA_READY)
       {
	 data = pfl_com_drecv();
	 buffer[i++] = (unsigned char) (data & 0x00ff);            
       }    
     }  
     
     _storni(i,BYTES_READ);
     _storclen(buffer,i,STR_TXT);
     _retni(NORMAL);
  }
  else
     _retni(INVP);
      
}
コード例 #6
0
CLIPPER mkdirct()
{
    char *utl_pth = _parc(1);
    if (! (PCOUNT==1 || ISCHAR(1)))
        _retl(0);
    else
        _retl(mkdir(utl_pth)+1);
}
コード例 #7
0
void CGrannyListView::OnModelRegistermodel()
{
	CGrannyViewerDoc *pDoc = GetDocument();
	UINT iData = GetSelectedItemData();
	if (!pDoc || !ISCHAR(iData)) return;

	UINT id = GETDATA(iData);
	pDoc->RegisterModel(id);
}
コード例 #8
0
void CGrannyListView::OnModelUnregistermodel()
{
	UINT iData = GetSelectedItemData();
	CGrannyViewerDoc *pDoc = GetDocument();
	if (!pDoc) return;

	if (ISCHAR(iData))
	{	
		UINT id = GETDATA(iData);
		pDoc->UnregisterModel(id);
	}
}
コード例 #9
0
ファイル: READLIB.C プロジェクト: fabioandrec/fivedos
 CLIPPER  LLIBOPEN( void ){
    WORD i;
    if (PCOUNT() >= 1 && ISCHAR(1) && wLib == 0xffff){
       if ((wLib=_topen(_parc(1),0))!=0xffff){
          if (ScanLibOffsets()){
             _retl(TRUE);
             return;
          }
       }
    }
    _retl(FALSE);
    return;
 }
コード例 #10
0
static void
setup(int *string, char *arg, STR *str, int cflag, int Cflag)
{
	int cnt, *p;

	str->str = arg;
	bzero(string, NCHARS * sizeof(int));
	while (next(str))
		string[str->lastch] = 1;
	if (cflag)
		for (p = string, cnt = NCHARS; cnt--; ++p)
			*p = !*p;
	else if (Cflag)
		for (cnt = 0; cnt < NCHARS; cnt++)
			string[cnt] = !string[cnt] && ISCHAR(cnt);
}
コード例 #11
0
ファイル: VERIFONE.C プロジェクト: ibarrar/clipper
CLIPPER veri_send()
{
 char far * text;
 int status = INVP;
 int textlen;
 
  if (PCOUNT == 1 && ISCHAR(TXT))
  {      
      text = _parc(TXT);
      textlen = _parclen(TXT);
      status = pfl_com_nsend( text, textlen );
  }
  
  _retni(status);         
    
}
コード例 #12
0
ファイル: CPROC.C プロジェクト: Jimboeri/SMIC
CLIPPER JW_SCRAM(void)
{
    char *temp;
    char *str;
    unsigned int len;
    int i;
    char c;

    if ( PCOUNT == 2 && ISCHAR(1) && ISNUM(2))
	{
	/* get pointer to param */
	str = _parc(1);

	/* get strings length */
	len = _parclen(1);

	/* allocate temp buffer */
	temp = _xgrab(len+1);

	/* put null byte */
	temp[len] = '\0';

	/* get encrypting value */
	i = _parni(2);

	/* convert to char */
	c = (char)i;

	/* copy input string to buffer XORing and 2's complementing as we go */
	for (i = 0; i < len; i++)
	    {
	    temp[i] = ~(str[i] ^ c);
	    }
	/* post modified value as CLIPPER return */
	_retclen(temp, len);

	/* free buffer */
	_xfree(temp);
	}
    else
    {
	     /* bad param */
	     _ret();
    }
}
コード例 #13
0
ファイル: Winsock.c プロジェクト: azulae/Gestool
   CLIPPER GETHOSTBYA( PARAMS ) // DDRESS( cIPAddress )
#endif
{
   LONG lAddr;
   struct hostent * pHostent;

   if( ISCHAR( 1 ) )
   {
      lAddr = inet_addr( _parc( 1 ) );
      pHostent = gethostbyaddr( ( LPSTR ) &lAddr, 4, PF_INET );
   }
   else
   {
      lAddr = _parnl( 1 );
      pHostent = gethostbyaddr( ( char * ) &lAddr, 4, PF_INET );
   }

   // if( ( int ) pHostent != INADDR_NONE )      // GPF's with some servers with no associated host name
   if( pHostent )                                // Changed by Jorge Mason, www.htcsoft.cl, Sept.2002
      _retc( pHostent->h_name );
   else
      _retc( "Unknown" );                        // changed from "" to "unknown" by LKM
}
コード例 #14
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 );
      }
   }
}
コード例 #15
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 );
      }
   }
}
コード例 #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
ファイル: 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();
   }
}
コード例 #18
0
ファイル: RJSFACE1.C プロジェクト: ibarrar/clipper
CLIPPER a_rjs_prnt(void)
{
  static unsigned char printer_type;  /* bit assignments for print station */
  static unsigned int text_len;  /* data length */
  static char *data;  /* data pointer */
  static int line_feed;  /* line feed flag */  
  static int next_buff_in;  /* next buffer input index */

  /* validate parameters */
  if (PCOUNT == 5 && ISNUM(RCPT) && ISNUM(JRNAL) && 
                     ISNUM(SLIP) && ISCHAR(TXT) && ISNUM(LINE_FLAG))
  {                     
    if (!async_printing)  /* not in asynchronous printing mode */
    {
      _retni(INVP);  
      return;
    }
      
    data = _parc(TXT);  /* get data to be printed */

    /* check data length */
    text_len = _parclen(TXT);
    
    if (NOT_IN_RANGE(text_len, 1, 80))
    {
      _retni(INVP);
      return;
    }    

    /* determine printer station */
    printer_type = 0x00;  
    if (_parni(JRNAL))
      printer_type |= 0x01;  /* print on journal */

    if (_parni(RCPT))
      printer_type |= 0x02;  /* print on receipt */

    if (_parni(SLIP))
      printer_type |= 0x04;  /* print on slip/document */

    if (printer_type == 0x04)  /* slip validation not supported */
    {
      _retni(INVP);
      return;
    }

    if (printer_type == 0)   /* no printer assignment */
      printer_type = 0x02;   /* default to receipt */

    /* only one printer station at a time */
    if (((printer_type & 0x02) && (printer_type & 0x04)) ||
        ((printer_type & 0x01) && (printer_type & 0x04)))
    {
      _retni(INVP);
      return;
    }

    /* get line feed flag */
    line_feed = _parni(LINE_FLAG);
    
    /* verify initial status */
    if (chk_init_flag(POS_PRINTER) == 0)
    {
      _retni(DEV_NOT_EXIST);   /* device not yet initialized */
      return;
    }    

    /* buffer the print job */
    next_buff_in = buff_in1;  /* get current buffer input index */
    ++next_buff_in;           

    if (next_buff_in == PRINT_JOBS)  /* past the end of buffer ? */
      next_buff_in = 0;  /* reset to start of buffer */

    if (next_buff_in == buff_out1)  /* is the buffer full ? */
    {
      _retni(MEM_OUT);
      return;
    }

    prnt_data1[buff_in1].func_type = 0;  /* A_RJS_PRNT() */
    prnt_data1[buff_in1].printer_type = printer_type;
    prnt_data1[buff_in1].line_flag = line_feed;
    prnt_data1[buff_in1].text_len = text_len;
    _bcopy(prnt_data1[buff_in1].txt_msg, data,text_len);

    buff_in1 = next_buff_in;  /* update buffer input index */
    buffer_empty = 0;  /* buffer is not empty */

    _retni(NORMAL);
  }
  else
    _retni(INVP);
}
コード例 #19
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( "" );
      }
   }
}
コード例 #20
0
ファイル: putscj.c プロジェクト: MoochMcGee/pcc-optimized
/*
 * Convert a f77 tree statement to something that looks like a
 * pcc expression tree.
 */
NODE *
putx(bigptr q)
{
	struct bigblock *x1;
	NODE *p = NULL; /* XXX */
	int opc;
	int type, k;

#ifdef PCC_DEBUG
	if (tflag) {
		printf("putx %p\n", q);
		fprint(q, 0);
	}
#endif

	switch(q->tag) {
	case TERROR:
		ckfree(q);
		break;

	case TCONST:
		switch(type = q->vtype) {
			case TYLOGICAL:
				type = tyint;
			case TYLONG:
			case TYSHORT:
				p = mklnode(ICON, q->b_const.fconst.ci,
				    0, types2[type]);
				ckfree(q);
				break;

			case TYADDR:
				p = mklnode(ICON, 0, 0, types2[type]);
				p->n_name = copys(memname(STGCONST,
				    (int)q->b_const.fconst.ci));
				ckfree(q);
				break;

			default:
				p = putx(putconst(q));
				break;
			}
		break;

	case TEXPR:
		switch(opc = q->b_expr.opcode) {
			case OPCALL:
			case OPCCALL:
				if( ISCOMPLEX(q->vtype) )
					p = putcxop(q);
				else {
					putcall(q);
					p = callval;
				}
				break;

			case OPMIN:
			case OPMAX:
				p = putmnmx(q);
				break;

			case OPASSIGN:
				if (ISCOMPLEX(q->b_expr.leftp->vtype) ||
				    ISCOMPLEX(q->b_expr.rightp->vtype)) {
					frexpr(putcxeq(q));
				} else if (ISCHAR(q))
					p = putcheq(q);
				else
					goto putopp;
				break;

			case OPEQ:
			case OPNE:
				if (ISCOMPLEX(q->b_expr.leftp->vtype) ||
				    ISCOMPLEX(q->b_expr.rightp->vtype) ) {
					p = putcxcmp(q);
					break;
				}
			case OPLT:
			case OPLE:
			case OPGT:
			case OPGE:
				if(ISCHAR(q->b_expr.leftp))
					p = putchcmp(q);
				else
					goto putopp;
				break;

			case OPPOWER:
				p = putpower(q);
				break;

			case OPSTAR:
				/*   m * (2**k) -> m<<k   */
				if (XINT(q->b_expr.leftp->vtype) &&
				    ISICON(q->b_expr.rightp) &&
				    ((k = flog2(q->b_expr.rightp->b_const.fconst.ci))>0) ) {
					q->b_expr.opcode = OPLSHIFT;
					frexpr(q->b_expr.rightp);
					q->b_expr.rightp = MKICON(k);
					goto putopp;
				}

			case OPMOD:
				goto putopp;
			case OPPLUS:
			case OPMINUS:
			case OPSLASH:
			case OPNEG:
				if( ISCOMPLEX(q->vtype) )
					p = putcxop(q);
				else	
					goto putopp;
				break;

			case OPCONV:
				if( ISCOMPLEX(q->vtype) )
					p = putcxop(q);
				else if (ISCOMPLEX(q->b_expr.leftp->vtype)) {
					p = putx(mkconv(q->vtype,
					    realpart(putcx1(q->b_expr.leftp))));
					ckfree(q);
				} else
					goto putopp;
				break;

			case OPAND:
				/* Create logical AND */
				x1 = fmktemp(TYLOGICAL, NULL);
				putexpr(mkexpr(OPASSIGN, cpexpr(x1),
				    mklogcon(0)));
				k = newlabel();
				putif(q->b_expr.leftp, k);
				putif(q->b_expr.rightp, k);
				putexpr(mkexpr(OPASSIGN, cpexpr(x1),
				    mklogcon(1)));
				putlabel(k);
				p = putx(x1);
				break;

			case OPNOT: /* Logical NOT */
				x1 = fmktemp(TYLOGICAL, NULL);
				putexpr(mkexpr(OPASSIGN, cpexpr(x1),
				    mklogcon(1)));
				k = newlabel();
				putif(q->b_expr.leftp, k);
				putexpr(mkexpr(OPASSIGN, cpexpr(x1),
				    mklogcon(0)));
				putlabel(k);
				p = putx(x1);
				break;

			case OPOR: /* Create logical OR */
				x1 = fmktemp(TYLOGICAL, NULL);
				putexpr(mkexpr(OPASSIGN, cpexpr(x1),
				    mklogcon(1)));
				k = newlabel();
				putif(mkexpr(OPEQ, q->b_expr.leftp,
				    mklogcon(0)), k);
				putif(mkexpr(OPEQ, q->b_expr.rightp,
				    mklogcon(0)), k);
				putexpr(mkexpr(OPASSIGN, cpexpr(x1),
				    mklogcon(0)));
				putlabel(k);
				p = putx(x1);
				break;

			case OPCOMMA:
				for (x1 = q; x1->b_expr.opcode == OPCOMMA; 
				    x1 = x1->b_expr.leftp)
					putexpr(x1->b_expr.rightp);
				p = putx(x1);
				break;

			case OPEQV:
			case OPNEQV:
			case OPADDR:
			case OPBITOR:
			case OPBITAND:
			case OPBITXOR:
			case OPBITNOT:
			case OPLSHIFT:
			case OPRSHIFT:
		putopp:
				p = putop(q);
				break;

			default:
				fatal1("putx: invalid opcode %d", opc);
			}
		break;

	case TADDR:
		p = putaddr(q, YES);
		break;

	default:
		fatal1("putx: impossible tag %d", q->tag);
	}
	return p;
}
コード例 #21
0
ファイル: wxPrintf.c プロジェクト: josefilhopi/wxweb
/*
 * Implementação de printf() para Harbour/xHarbour.
 *
 * TODO: Creio que uma ótima melhoria seria somar o tamanho de todos os argumentos
 * e criar um buffer já pre-determinado com um tamanho +/- necessário para evitar
 * tantas realocações de memoria como ocorre nestes casos.
 * 26/07/2008 - 08:17:42
 */
static
char *wx_printf( ULONG *Length )
{
    PPrintInfo pInfo;
    char c;
    char *result;
    ULONG request_len;

    *Length = 0L;

    // o primeiro argumento tem que ser uma string!
    if ( !ISCHAR(1) )
        return NULL;

    /* Iniciamos a memoria */
    pInfo = (PPrintInfo) hb_xgrab( sizeof(TPrintInfo) );
    memset( pInfo, 0, sizeof(TPrintInfo) );

    pInfo->Mask   = hb_parcx(1);
    pInfo->msk_len= hb_parclen(1);

    pInfo->Result = (char *) hb_xgrab( pInfo->msk_len+1 );
    pInfo->Buffer = pInfo->Result;
    pInfo->cap_len= pInfo->msk_len;

    pInfo->argp ++;

    /* processamos a string como um todo */
    while (pInfo->error == NONE   &&
            pInfo->msk_len         &&
            pInfo->Mask[0] )
    {
        c = pInfo->Mask[0];

        switch (c)
        {
        case '%':
        {
            /*
             * Se nao tem nenhum item de argumento, e o proximo caracter de escape nao for
             * o "%", entao temos que abortar a rotina... indicando erro de argumento!
             */
            if (pInfo->Mask[1] == '%')
            {
                printf_add_str( pInfo, "%", 1L );
                pInfo->Mask    += 2;
                pInfo->msk_len -= 2;
                continue;
            }

            pInfo->argp ++;
            printf_add_conv( pInfo, hb_param( pInfo->argp, HB_IT_ANY ));
            continue;
        }

        default:
        {
            // Precisa realocar memoria?
            request_len = 1L;

            if (pInfo->out_len+request_len > pInfo->cap_len)
            {
                pInfo->cap_len += request_len;
                pInfo->Result   = (char *) hb_xrealloc( pInfo->Result, pInfo->cap_len+1 );
                pInfo->Buffer   = pInfo->Result + (pInfo->out_len);
                pInfo->out_len += request_len;
            } else {
                pInfo->out_len += request_len;
            }

            /*
             * É um caracter simples ou é uma sequencia de escape a ser add?
             * Links relacionados:
             *    http://docs.sun.com/app/docs/doc/816-0220/6m6nkorp8?a=view
             *    http://docs.sun.com/app/docs/doc/816-0213/6m6ne387j?a=view
             */
            if (c == '\\')
            {
                pInfo->Mask ++;
                pInfo->msk_len--;

                if (!pInfo->msk_len)
                    continue;

                c = pInfo->Mask[0];

                switch(c)
                {
                case '\\':
                    c = '\\';
                    break;
                case '\0':
                    c = '\0';
                    break;
                case 'a':
                    c = '\a';
                    break;
                case 'b':
                    c = '\b';
                    break;
                case 'f':
                    c = '\f';
                    break;
                case 'n':
                    c = '\n';
                    break;
                case 'r':
                    c = '\r';
                    break;
                case 't':
                    c = '\t';
                    break;
                case 'v':
                    c = '\v';
                    break;
                }
            }

            pInfo->Buffer[0] = c;
            pInfo->Buffer ++;

            pInfo->Mask ++;
            pInfo->msk_len--;
            break;
        }
        }
    }
    pInfo->Result[pInfo->out_len] = '\0';

    result  = pInfo->Result;
    *Length = pInfo->out_len;

    /* Liberamos a memoria alocada */
    hb_xfree( pInfo );
    return result;
}
コード例 #22
0
ファイル: justify.c プロジェクト: philippe78/TrioGesmag
/* 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;

}
コード例 #23
0
ファイル: charone.c プロジェクト: philippe78/TrioGesmag
/* helper function for the *one functions */
static void do_charone( int iSwitch )
{
   char *pcString;
   size_t sStrLen;
   char *pcDeleteSet;
   size_t sDeleteSetLen;

   /* param check */
   if ( ISCHAR( 1 ) )
   {
      if ( ISCHAR( 2 ) )
      {
         pcString = hb_parc( 2 );
         sStrLen = (size_t)hb_parclen( 2 );
         pcDeleteSet = hb_parc( 1 );
         sDeleteSetLen = (size_t)hb_parclen( 1 );
      }
      else
      {
         pcString = hb_parc( 1 );
         sStrLen = (size_t)hb_parclen( 1 );
         pcDeleteSet = NULL;
         sDeleteSetLen = 0;
      }

      switch ( iSwitch )
      {
         case DO_CHARONE_CHARONE:
         {
            if (sStrLen > 1)
            {
               char *pcSub;
               char *pcRet;
               size_t 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  /* if (sStrLen > 1) */
            {
               /* algorithm does nothing to 1-char-strings */
               hb_retclen( pcString, sStrLen );
            }
         }
	 break;

         case DO_CHARONE_WORDONE:
         {
            if ( sStrLen > 3 && sDeleteSetLen >= 2 )
            {
               char *pcSub;
               char *pcRet;
               size_t 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 )
		  {
		     char *pc = NULL;
		     char *pStart = pcDeleteSet;
		     size_t 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 % 2 == 1 )
               {
                  pcRet[ sRetStrLen++ ] = pcString[ sStrLen - 1 ];
               }
               hb_retclen( pcRet, sRetStrLen );
               hb_xfree( pcRet );
            }
            else  /* if (sStrLen > 3) */
            {
               /* algorithm does nothing to 3-char-strings */
               hb_retclen( pcString, sStrLen );
            }
         }
	 break;
      } /* switch (iSwitch) */
   }
   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_CHARONE_CHARONE ? CT_ERROR_CHARONE : CT_ERROR_WORDONE ),
                                  NULL,
                                  ( iSwitch == DO_CHARONE_CHARONE ? "CHARONE" : "WORDONE" ),
                                  0, EF_CANSUBSTITUTE, 2,
                                  hb_paramError( 1 ), hb_paramError( 2 ) );
      }
     
      if ( pSubst != NULL )
      {
         hb_itemRelease( hb_itemReturnForward( pSubst ) );
      }
      else
      {
         hb_retc( "" );
      }
   }
}
コード例 #24
0
ファイル: RID_SCAN.C プロジェクト: ibarrar/clipper
CLIPPER read_scan(void)
{
  int barcode_sts;  /* scanner input status */
  int barcode_len;  /* holds the no. of bytes actually read */
  int check_flag = 0;  
  int label_chkdigit,chkdigit;
    
  if ((PCOUNT >= 2) && ISBYREF(BYTES_READ) && ISNUM(BYTES_READ) &&
                     ISBYREF(STR_BUFF) && ISCHAR(STR_BUFF))
  {
     /* verify initial status */
     if (chk_init_flag(POS_SCAN) == 0)
     {
        _retni(DEV_NOT_EXIST);   
        return;
     } /* device not yet initialized */

    /* not in asynchronous scanning mode */
    if (!async_scan)
    {
      _retni(INVP);
      return;
    }
    
    /* read scanner input */
    if ((barcode_sts = pfl_get_label(label_buff)) == -1)
      barcode_sts = READ_ERR;  /* no available data to be fetched */
    else
    {
      barcode_len = barcode_sts & 0x00ff;              /* get label length */
      barcode_sts >>= 8;                               /* label status     */

      barcode_sts = (barcode_sts == 0)? NORMAL: SCAN_ERR;  /* status      */
      
      if ( PCOUNT == 3 )
      {
        int check_flag = _parl(CHECK_FLAG);      
        if (check_flag)
        {  
           barcode_len--;                
                    
           label_chkdigit = (int) label_buff[barcode_len] - 48 ;
           
           chkdigit = checkdgt(label_buff,barcode_len);           

           if ( label_chkdigit !=  chkdigit )
             barcode_sts = SCAN_ERR;
                                       
        }   
        
      }     

      _storni(barcode_len, BYTES_READ);                /* length */
        
      *(label_buff+barcode_len+1) = '\0';              /* insert a NULL character */
      _storclen(label_buff, barcode_len+2, STR_BUFF);  /* bar code data */        
                          
    }
    
    _retni(barcode_sts);
  }
  else
コード例 #25
0
int
main(int argc, char **argv)
{
	int ch, cnt, lastch, *p;
	int Cflag, cflag, dflag, sflag, isstring2;

	(void)setlocale(LC_ALL, "");

	Cflag = cflag = dflag = sflag = 0;
	while ((ch = getopt(argc, argv, "Ccdsu")) != -1)
		switch((char)ch) {
		case 'C':
			Cflag = 1;
			cflag = 0;
			break;
		case 'c':
			cflag = 1;
			Cflag = 0;
			break;
		case 'd':
			dflag = 1;
			break;
		case 's':
			sflag = 1;
			break;
		case 'u':
			setbuf(stdout, NULL);
			break;
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	switch(argc) {
	case 0:
	default:
		usage();
		/* NOTREACHED */
	case 1:
		isstring2 = 0;
		break;
	case 2:
		isstring2 = 1;
		break;
	}

	/*
	 * tr -ds [-Cc] string1 string2
	 * Delete all characters (or complemented characters) in string1.
	 * Squeeze all characters in string2.
	 */
	if (dflag && sflag) {
		if (!isstring2)
			usage();

		setup(string1, argv[0], &s1, cflag, Cflag);
		setup(string2, argv[1], &s2, 0, 0);

		for (lastch = OOBCH; (ch = getchar()) != EOF;)
			if (!string1[ch] && (!string2[ch] || lastch != ch)) {
				lastch = ch;
				(void)putchar(ch);
			}
		exit(0);
	}

	/*
	 * tr -d [-Cc] string1
	 * Delete all characters (or complemented characters) in string1.
	 */
	if (dflag) {
		if (isstring2)
			usage();

		setup(string1, argv[0], &s1, cflag, Cflag);

		while ((ch = getchar()) != EOF)
			if (!string1[ch])
				(void)putchar(ch);
		exit(0);
	}

	/*
	 * tr -s [-Cc] string1
	 * Squeeze all characters (or complemented characters) in string1.
	 */
	if (sflag && !isstring2) {
		setup(string1, argv[0], &s1, cflag, Cflag);

		for (lastch = OOBCH; (ch = getchar()) != EOF;)
			if (!string1[ch] || lastch != ch) {
				lastch = ch;
				(void)putchar(ch);
			}
		exit(0);
	}

	/*
	 * tr [-Ccs] string1 string2
	 * Replace all characters (or complemented characters) in string1 with
	 * the character in the same position in string2.  If the -s option is
	 * specified, squeeze all the characters in string2.
	 */
	if (!isstring2)
		usage();

	s1.str = argv[0];
	s2.str = argv[1];

	if (cflag || Cflag)
		for (cnt = NCHARS, p = string1; cnt--;)
			*p++ = OOBCH;

	if (!next(&s2))
		errx(1, "empty string2");

	ch = s2.lastch;
	/* If string2 runs out of characters, use the last one specified. */
	if (sflag)
		while (next(&s1)) {
			string1[s1.lastch] = ch = s2.lastch;
			string2[ch] = 1;
			(void)next(&s2);
		}
	else
		while (next(&s1)) {
			string1[s1.lastch] = ch = s2.lastch;
			(void)next(&s2);
		}

	if (cflag)
		for (cnt = 0, p = string1; cnt < NCHARS; ++p, ++cnt)
			*p = *p == OOBCH ? ch : cnt;
	else if (Cflag)
		for (cnt = 0, p = string1; cnt < NCHARS; ++p, ++cnt)
			*p = *p == OOBCH && ISCHAR(cnt) ? ch : cnt;

	if (sflag)
		for (lastch = OOBCH; (ch = getchar()) != EOF;) {
			ch = string1[ch];
			if (!string2[ch] || lastch != ch) {
				lastch = ch;
				(void)putchar(ch);
			}
		}
	else
		while ((ch = getchar()) != EOF)
			(void)putchar(string1[ch]);
	exit (0);
}
コード例 #26
0
ファイル: ctpad.c プロジェクト: philippe78/TrioGesmag
/* 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;

}
コード例 #27
0
ファイル: rt_miscc.c プロジェクト: CsBela/core
CLIPPER HB_STOD( void )
{
   /* The length check is a fix to avoid buggy behaviour of _retds() */
   _retds( ( ISCHAR( 1 ) && _parclen( 1 ) == 8 ) ? _parc( 1 ) : "        " );
}