FreeBSD/sys/contrib/dev/acpica/components/executer/exconvrt.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiExConvertToString
 *
 * PARAMETERS:  ObjDesc         - Object to be converted. Must be an
 *                                Integer, Buffer, or String
 *              ResultDesc      - Where the string object is returned
 *              Type            - String flags (base and conversion type)
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Convert an ACPI Object to a string
 *
 ******************************************************************************/
AcpiExConvertToString
PARAMETERS:  ObjDesc         - Object to be converted. Must be an
Integer, Buffer, or String
ResultDesc      - Where the string object is returned
Type            - String flags (base and conversion type)

Status

Convert an ACPI Object to a string
AcpiExConvertToString PARAMETERS : ObjDesc - Object to be converted . Must be an Integer Buffer or String ResultDesc - Where the string object is returned Type - String flags ( base and conversion type ) Status Convert an ACPI Object to a string
ACPI_STATUS
AcpiExConvertToString (
    ACPI_OPERAND_OBJECT     *ObjDesc,
    ACPI_OPERAND_OBJECT     **ResultDesc,
    UINT32                  Type)
{
    ACPI_OPERAND_OBJECT     *ReturnDesc;
    UINT8                   *NewBuf;
    UINT32                  i;
    UINT32                  StringLength = 0;
    UINT16                  Base = 16;
    UINT8                   Separator = ',';
    ACPI_FUNCTION_TRACE_PTR (ExConvertToString, ObjDesc);
    switch (ObjDesc->Common.Type)
    {
    case ACPI_TYPE_STRING:
        *ResultDesc = ObjDesc;
        return_ACPI_STATUS (AE_OK);
    case ACPI_TYPE_INTEGER:
        switch (Type)
        {
        case ACPI_EXPLICIT_CONVERT_DECIMAL:
            StringLength = ACPI_MAX_DECIMAL_DIGITS;
            Base = 10;
            break;
        default:
            StringLength = ACPI_MUL_2 (AcpiGbl_IntegerByteWidth);
            break;
        }
        ReturnDesc = AcpiUtCreateStringObject ((ACPI_SIZE) StringLength);
        if (!ReturnDesc)
        {
            return_ACPI_STATUS (AE_NO_MEMORY);
        }
        NewBuf = ReturnDesc->Buffer.Pointer;
        StringLength = AcpiExConvertToAscii (
            ObjDesc->Integer.Value, Base, NewBuf, AcpiGbl_IntegerByteWidth);
        ReturnDesc->String.Length = StringLength;
        NewBuf [StringLength] = 0;
        break;
    case ACPI_TYPE_BUFFER:
        switch (Type)
        {
        case ACPI_EXPLICIT_CONVERT_DECIMAL: 
            Base = 10;
            for (i = 0; i < ObjDesc->Buffer.Length; i++)
            {
                if (ObjDesc->Buffer.Pointer[i] >= 100)
                {
                    StringLength += 4;
                }
                else if (ObjDesc->Buffer.Pointer[i] >= 10)
                {
                    StringLength += 3;
                }
                else
                {
                    StringLength += 2;
                }
            }
            break;
        case ACPI_IMPLICIT_CONVERT_HEX:
            Separator = ' ';
            StringLength = (ObjDesc->Buffer.Length * 3);
            break;
        case ACPI_EXPLICIT_CONVERT_HEX:     
            StringLength = (ObjDesc->Buffer.Length * 3);
            break;
        default:
            return_ACPI_STATUS (AE_BAD_PARAMETER);
        }
        if (StringLength)
        {
            StringLength--;
        }
        ReturnDesc = AcpiUtCreateStringObject ((ACPI_SIZE) StringLength);
        if (!ReturnDesc)
        {
            return_ACPI_STATUS (AE_NO_MEMORY);
        }
        NewBuf = ReturnDesc->Buffer.Pointer;
        for (i = 0; i < ObjDesc->Buffer.Length; i++)
        {
            NewBuf += AcpiExConvertToAscii (
                (UINT64) ObjDesc->Buffer.Pointer[i], Base, NewBuf, 1);
            *NewBuf++ = Separator; 
        }
        if (ObjDesc->Buffer.Length)
        {
            NewBuf--;
        }
        *NewBuf = 0;
        break;
    default:
        return_ACPI_STATUS (AE_TYPE);
    }
    *ResultDesc = ReturnDesc;
    return_ACPI_STATUS (AE_OK);
}
ACPI_STATUS AcpiExConvertToString ( ACPI_OPERAND_OBJECT * ObjDesc , ACPI_OPERAND_OBJECT * * ResultDesc , UINT32 Type ) { ACPI_OPERAND_OBJECT * ReturnDesc ; UINT8 * NewBuf ; UINT32 i ; UINT32 StringLength = 0 ; UINT16 Base = 16 ; UINT8 Separator = ' ' ; ACPI_FUNCTION_TRACE_PTR ( ExConvertToString , ObjDesc ) ; switch ( ObjDesc -> Common . Type ) { case ACPI_TYPE_STRING : * ResultDesc = ObjDesc ; return_ACPI_STATUS ( AE_OK ) ; case ACPI_TYPE_INTEGER : switch ( Type ) { case ACPI_EXPLICIT_CONVERT_DECIMAL : StringLength = ACPI_MAX_DECIMAL_DIGITS ; Base = 10 ; break ; default : StringLength = ACPI_MUL_2 ( AcpiGbl_IntegerByteWidth ) ; break ; } ReturnDesc = AcpiUtCreateStringObject ( ( ACPI_SIZE ) StringLength ) ; if ( ! ReturnDesc ) { return_ACPI_STATUS ( AE_NO_MEMORY ) ; } NewBuf = ReturnDesc -> Buffer . Pointer ; StringLength = AcpiExConvertToAscii ( ObjDesc -> Integer . Value , Base , NewBuf , AcpiGbl_IntegerByteWidth ) ; ReturnDesc -> String . Length = StringLength ; NewBuf [ StringLength ] = 0 ; break ; case ACPI_TYPE_BUFFER : switch ( Type ) { case ACPI_EXPLICIT_CONVERT_DECIMAL : Base = 10 ; for ( i = 0 ; i < ObjDesc -> Buffer . Length ; i ++ ) { if ( ObjDesc -> Buffer . Pointer [ i ] >= 100 ) { StringLength += 4 ; } else if ( ObjDesc -> Buffer . Pointer [ i ] >= 10 ) { StringLength += 3 ; } else { StringLength += 2 ; } } break ; case ACPI_IMPLICIT_CONVERT_HEX : Separator = ' ' ; StringLength = ( ObjDesc -> Buffer . Length * 3 ) ; break ; case ACPI_EXPLICIT_CONVERT_HEX : StringLength = ( ObjDesc -> Buffer . Length * 3 ) ; break ; default : return_ACPI_STATUS ( AE_BAD_PARAMETER ) ; } if ( StringLength ) { StringLength -- ; } ReturnDesc = AcpiUtCreateStringObject ( ( ACPI_SIZE ) StringLength ) ; if ( ! ReturnDesc ) { return_ACPI_STATUS ( AE_NO_MEMORY ) ; } NewBuf = ReturnDesc -> Buffer . Pointer ; for ( i = 0 ; i < ObjDesc -> Buffer . Length ; i ++ ) { NewBuf += AcpiExConvertToAscii ( ( UINT64 ) ObjDesc -> Buffer . Pointer [ i ] , Base , NewBuf , 1 ) ; * NewBuf ++ = Separator ; } if ( ObjDesc -> Buffer . Length ) { NewBuf -- ; } * NewBuf = 0 ; break ; default : return_ACPI_STATUS ( AE_TYPE ) ; } * ResultDesc = ReturnDesc ; return_ACPI_STATUS ( AE_OK ) ; }
FUNCTION:    AcpiExConvertToString
 PARAMETERS:  ObjDesc         - Object to be converted.
FUNCTION : AcpiExConvertToString PARAMETERS : ObjDesc - Object to be converted .
/* No conversion necessary */ /* Make room for maximum decimal number */ /* Two hex string characters for each integer byte */ /*
         * Create a new String
         * Need enough space for one ASCII integer (plus null terminator)
         */ /* Convert integer to string */ /* Null terminate at the correct place */ /* Setup string length, base, and separator */ /* Used by ToDecimalString */ /*
             * From ACPI: "If Data is a buffer, it is converted to a string of
             * decimal values separated by commas."
             */ /*
             * Calculate the final string length. Individual string values
             * are variable length (include separator for each)
             */ /*
             * From the ACPI spec:
             *"The entire contents of the buffer are converted to a string of
             * two-character hexadecimal numbers, each separated by a space."
             */ /* Used by ToHexString */ /*
             * From ACPI: "If Data is a buffer, it is converted to a string of
             * hexadecimal values separated by commas."
             */ /*
         * Create a new string object and string buffer
         * (-1 because of extra separator included in StringLength from above)
         * Allow creation of zero-length strings from zero-length buffers.
         */ /*
         * Convert buffer bytes to hex or decimal values
         * (separated by commas or spaces)
         */ /* each separated by a comma or space */ /*
         * Null terminate the string
         * (overwrites final comma/space from above)
         */