Beispiel #1
0
static HB_ISIZ hb_vmWithObjectCount( void )
{
   HB_ISIZ nOffset = hb_stackWithObjectOffset(), nCount = 0;

   while( nOffset )
   {
      HB_ISIZ * pnOffset = ( HB_ISIZ * ) hb_itemGetPtr( hb_stackItem( nOffset + 1 ) );
      if( ! pnOffset )
         break;
      ++nCount;
      nOffset = *pnOffset;
   }

   return nCount;
}
Beispiel #2
0
static PHB_ITEM hb_vmWithObjectItem( HB_ISIZ nLevel )
{
   HB_ISIZ nOffset = hb_stackWithObjectOffset();

   while( nOffset && nLevel > 0 )
   {
      HB_ISIZ * pnOffset = ( HB_ISIZ * ) hb_itemGetPtr( hb_stackItem( nOffset + 1 ) );
      if( ! pnOffset )
         break;
      --nLevel;
      nOffset = *pnOffset;
   }

   return ( nOffset && ! nLevel ) ? hb_stackItem( nOffset ) : NULL;
}
Beispiel #3
0
// 26/07/2008 - 11:32:47
static
void printf_add_conv( PPrintInfo pInfo, PHB_ITEM pItem )
{
    char flag = 0;
    int width = 0;
    int precision = 0;
    char specifier = '\0';
    char m = '\0';
    char c;
    char mask[20];
    const char *t1;
    const char *t2;

    char * cValue;
    double dValue;
    ULONG  Length;

    /*
     * Procura por uma string de conversao com o formato:
     *        0       1        2         3      4
     *     %[flags][width][.precision][length]specifier
     *
     */
    t1 = pInfo->Mask;
    mask[0] = '\0';

    pInfo->Mask ++;
    pInfo->msk_len--;

    /*
     * 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->msk_len &&
            // pInfo->Mask[0] != '%' &&
            !pItem)
    {
        pInfo->error =  FAILURE;
        return;
    }

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

        // setou o flag?
        if (strchr( "-+ #0", c ))
        {
            flag = c;
            c = 'A';
        }

        // setar o width?
        if (strchr( "1234567890", c ))
        {
            char *t = (char *) hb_xgrab(15);
            char *s = t;

            do
            {
                *t = c;
                t++;
                pInfo->Mask ++;
                pInfo->msk_len--;
                c = pInfo->Mask[0];

            } while (pInfo->msk_len && strchr( "1234567890", c ));

            *t = '\0';
            width = atoi( s );
            hb_xfree(s);
        }

        // setar precision?
        if (c == '.')
        {
            char *t = (char *) hb_xgrab(15);
            char *s = t;

            pInfo->Mask ++;
            pInfo->msk_len--;
            c = pInfo->Mask[0];

            while (pInfo->msk_len && strchr( "1234567890", c ))
            {
                *t = c;
                t++;
                pInfo->Mask ++;
                pInfo->msk_len--;
                c = pInfo->Mask[0];
            }

            *t = '\0';
            precision = atoi( s );
            hb_xfree(s);

            c = pInfo->Mask[0];
        }

        if (c == 'l' && strchr( "idouxX", pInfo->Mask[1] ))
            m = c;
        if (c == 'h' && strchr( "idouxX", pInfo->Mask[1] ))
            m = c;
        if (c == 'L' && strchr( "eEfgG", pInfo->Mask[1] ))
            m = c;

        // Chegou no tipo?
        if (strchr( "cdieEfgGosuxXpn%", c ))
        {
            specifier = c;
            pInfo->Mask ++;
            pInfo->msk_len--;

            t2 = pInfo->Mask;

            switch( specifier )
            {
            case '%':
            {
                printf_add_str( pInfo, "%", 1L );
                break;
            }
            case 'c':
                //  O argumento é tratado como um inteiro, e mostrado como o caractere ASCII correspondente.
            {
                char s[2];
                memset( s, 0, 2 );

                if (HB_IS_STRING( pItem ))
                {
                    const char *t = hb_itemGetCPtr( pItem );
                    s[0] = ((t) ? t[0] : 0);
                } else if( HB_IS_NUMERIC( pItem ) )
                {
                    s[0] = (char) hb_itemGetNI( pItem );
                }

                printf_add_str( pInfo, s, 1L );
                break;
            }
            case 's':
            {
                Length = t2-t1;
                width  = max( hb_itemGetCLen( pItem ), (ULONG) width );
                cValue = (char *) hb_xgrab( width + 1 );

                memmove( mask, t1, Length );
                mask[Length] = '\0';

                cValue[0] = '\0';
                Length = sprintf( cValue, mask, hb_itemGetCPtr( pItem ) );
                printf_add_str( pInfo, cValue, Length );
                hb_xfree( cValue );
                break;
            }
            case 'p':
            {
                char s[9];
                s[0] = '\0';
                sprintf( s, "%p", hb_itemGetPtr( pItem ) );
                printf_add_str( pInfo, s, 8);
                break;
            }

            /*
             * Separamos aqui as operações sobre inteiros
             */
            case 'i':
            case 'd':
            // O argumento é tratado como um INTEIRO, e mostrado como um número decimal com sinal.
            case 'o':
            // O argumento é tratado com um INTEIRO, e mostrado como un número octal.
            case 'u':
            // O argumento é tratado com um INTEIRO, e mostrado como um número decimal sem sinal.
            case 'x':
            // O argumento é tratado como um INTEIRO, e mostrado como um número hexadecimal (com as letras minúsculas).
            case 'X':
                // O argumento é tratado como um INTEIRO, e mostrado como um número hexadecimal (com as letras maiúsculas).
            {
                Length = t2-t1;
                width  = ((width) ? width : 32 );
                cValue = (char *) hb_xgrab( width + 1 );

                memmove( mask, t1, Length );
                mask[Length] = '\0';
                cValue[0] = '\0';

                if (m == '\0')
                    Length = sprintf( cValue, mask, (int) hb_itemGetNI( pItem ));
                if (m == 'l')
                    Length = sprintf( cValue, mask, (LONG) hb_itemGetNL( pItem )); // como LONG ???
                if (m == 'h')
                    Length = sprintf( cValue, mask, (LONG) hb_itemGetNL( pItem )); // como LONG ???

                printf_add_str( pInfo, cValue, Length );
                hb_xfree( cValue );
                break;
            }

            /*
             * Separamos aqui as operações com numeros flutuantes
             */
            case 'e' :
            // O argumento é tratado como notação científica (e.g. 1.2e+2).
            case 'E' :
            // O argumento é tratado como notação científica (e.g. 1.2e+2).
            case 'f' :
            // O argumento é tratado como um float, e mostrado como um número de ponto flutuante.
            case 'F' :
                // O argumento é tratado como um float, e mostrado como um número de ponto flutuante.
            {
                Length = t2-t1;
                width  = ((width) ? width : 64 );
                dValue = (double) hb_itemGetND( pItem );     // converting double --> float ???
                cValue = (char *) hb_xgrab( width + 1 );

                memmove( mask, t1, Length );
                mask[Length] = '\0';

                sprintf( cValue, mask, dValue );
                printf_add_str( pInfo, cValue, strlen( cValue ) );
                hb_xfree( cValue );
                break;
            }

            default:
                break;
            }
            break;
        } else {
            pInfo->Mask ++;
            pInfo->msk_len--;
        }
    }
}
Beispiel #4
0
static HB_UINT SCItm( char * cBuffer, HB_UINT ulMaxBuf, char * cParFrm, int iCOut, int IsIndW,
                      int iIndWidth, int IsIndP, int iIndPrec,
                      PHB_ITEM pItmPar )
{
   HB_UINT s;

   if( IsIndW && IsIndP )
   {
      switch( iCOut )
      {
         case 'p':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iIndWidth, iIndPrec, hb_itemGetPtr( pItmPar ) );
            break;
         case 's': case 'S':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iIndWidth, iIndPrec, hb_itemGetCPtr( pItmPar ) );
            break;
         case 'e': case 'E': case 'f': case 'g': case 'G': case 'a': case 'A':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iIndWidth, iIndPrec, hb_itemGetND( pItmPar ) );
            break;
         /* case 'c': case 'C': case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': */
         default:
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iIndWidth, iIndPrec,
                             HB_IS_LONG( pItmPar ) ? hb_itemGetNL( pItmPar ) : hb_itemGetNI( pItmPar ) );
      }
   }
   else if( IsIndW || IsIndP )
   {
      int iInd = ( IsIndW ? iIndWidth : iIndPrec );

      switch( iCOut )
      {
         case 'p':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iInd, hb_itemGetPtr( pItmPar ) );
            break;
         case 's': case 'S':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iInd, hb_itemGetCPtr( pItmPar ) );
            break;
         case 'e': case 'E': case 'f': case 'g': case 'G': case 'a': case 'A':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iInd, hb_itemGetND( pItmPar ) );
            break;
         /* case 'c': case 'C': case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': */
         default:
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, iInd,
                             HB_IS_LONG( pItmPar ) ? hb_itemGetNL( pItmPar ) : hb_itemGetNI( pItmPar ) );
      }
   }
   else
   {
      switch( iCOut )
      {
         case 'p':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, hb_itemGetPtr( pItmPar ) );
            break;
         case 's': case 'S':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, hb_itemGetCPtr( pItmPar ) );
            break;
         case 'e': case 'E': case 'f': case 'g': case 'G': case 'a': case 'A':
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm, hb_itemGetND( pItmPar ) );
            break;
         /* case 'c': case 'C': case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': */
         default:
            s = hb_snprintf( cBuffer, ulMaxBuf, cParFrm,
                             HB_IS_LONG( pItmPar ) ? hb_itemGetNL( pItmPar ) : hb_itemGetNI( pItmPar ) );
      }
   }
   return s;
}
Beispiel #5
0
BOOL hb_execFromArray( PHB_ITEM pFirst )
{
   register ULONG i;
   HB_SIZE        ulLen;
   ULONG          ulStart  = 1;
   PHB_ITEM       pArgs;
   PHB_ITEM       pString;
   PHB_ITEM       pSelf    = NULL;
   PHB_DYNS       pExecSym = NULL;
   PHB_SYMB       pSymbol  = NULL;

   if( pFirst == NULL || pFirst->type != HB_IT_ARRAY )
      return FALSE;

   pString  = hb_arrayGetItemPtr( pFirst, 1 );
   pArgs    = pFirst;

   if( HB_IS_OBJECT( pString ) && hb_arrayLen( pFirst ) >= 2 )
   {
      pSelf    = pString;
      pString  = hb_arrayGetItemPtr( pFirst, 2 );

      if( pString->type == HB_IT_STRING )
         pExecSym = hb_dynsymFindName( pString->item.asString.value );
      else if( pString->type == HB_IT_POINTER )
         pSymbol = ( PHB_SYMB ) hb_itemGetPtr( pString );

      ulStart = 3;
   }
   else if( pString->type == HB_IT_STRING )
   {
      pExecSym = hb_dynsymFindName( pString->item.asString.value );
      ulStart  = 2;
   }
   else if( pString->type == HB_IT_POINTER )
   {
      pSymbol  = ( PHB_SYMB ) hb_itemGetPtr( pString );
      ulStart  = 2;
   }
   else if( HB_IS_BLOCK( pString ) )
   {
      pSymbol  = &hb_symEval;
      ulStart  = 2;
   }

   if( pExecSym )
      pSymbol = pExecSym->pSymbol;

   if( pSymbol == NULL )
      return FALSE;

   hb_vmPushSymbol( pSymbol );

   if( pSelf )
      hb_vmPush( pSelf );
   else
      hb_vmPushNil();

   ulLen = hb_arrayLen( pArgs );

   /* pushing the contents of the array
    */
   for( i = ulStart; i <= ulLen; i++ )
      hb_vmPush( hb_arrayGetItemPtr( pArgs, i ) );

   if( pSelf )
      hb_vmSend( ( USHORT ) ( ulLen - ulStart + 1 ) );
   else
      hb_vmDo( ( USHORT ) ( ulLen - ulStart + 1 ) );

   return TRUE;
}