/******************************************************************************
*
* Module Name: utprint - Formatted printing routines
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2016, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
#include "acpi.h"
#include "accommon.h"
ACPI_MODULE_NAME ("utprint")
/* Local prototypes */
static ACPI_SIZE
const char *String,
static char *
char *String,
const char *End,
char c);
static char *
char *String,
char *End,
static char *
char *String,
/*******************************************************************************
*
* FUNCTION: AcpiUtBoundStringLength
*
* PARAMETERS: String - String with boundary
* Count - Boundary of the string
*
* RETURN: Length of the string. Less than or equal to Count.
*
* DESCRIPTION: Calculate the length of a string with boundary.
*
******************************************************************************/
static ACPI_SIZE
const char *String,
{
{
Length++;
String++;
Count--;
}
return (Length);
}
/*******************************************************************************
*
* FUNCTION: AcpiUtBoundStringOutput
*
* PARAMETERS: String - String with boundary
* End - Boundary of the string
* c - Character to be output to the string
*
* RETURN: Updated position for next valid character
*
* DESCRIPTION: Output a character into a string with boundary check.
*
******************************************************************************/
static char *
char *String,
const char *End,
char c)
{
{
*String = c;
}
++String;
return (String);
}
/*******************************************************************************
*
* FUNCTION: AcpiUtPutNumber
*
* PARAMETERS: String - Buffer to hold reverse-ordered string
* Number - Integer to be converted
* Base - Base of the integer
* Upper - Whether or not using upper cased digits
*
* RETURN: Updated position for next valid character
*
* DESCRIPTION: Convert an integer into a string, note that, the string holds a
* reversed ordered number without the trailing zero.
*
******************************************************************************/
static char *
char *String,
{
const char *Digits;
char *Pos;
if (Number == 0)
{
*(Pos++) = '0';
}
else
{
while (Number)
{
}
}
/* *(Pos++) = '0'; */
return (Pos);
}
/*******************************************************************************
*
* FUNCTION: AcpiUtScanNumber
*
* PARAMETERS: String - String buffer
* NumberPtr - Where the number is returned
*
* RETURN: Updated position for next valid character
*
* DESCRIPTION: Scan a string for a decimal integer.
*
******************************************************************************/
const char *
const char *String,
{
{
Number *= 10;
}
return (String);
}
/*******************************************************************************
*
* FUNCTION: AcpiUtPrintNumber
*
* PARAMETERS: String - String buffer
* Number - The number to be converted
*
* RETURN: Updated position for next valid character
*
* DESCRIPTION: Print a decimal integer into a string.
*
******************************************************************************/
const char *
char *String,
{
const char *Pos1;
char *Pos2;
while (Pos1 != AsciiString)
{
}
*Pos2 = 0;
return (String);
}
/*******************************************************************************
*
* FUNCTION: AcpiUtFormatNumber
*
* PARAMETERS: String - String buffer with boundary
* End - Boundary of the string
* Number - The number to be converted
* Base - Base of the integer
* Width - Field width
* Precision - Precision of the integer
* Type - Special printing flags
*
* RETURN: Updated position for next valid character
*
* DESCRIPTION: Print an integer into a string with any base and any precision.
*
******************************************************************************/
static char *
char *String,
char *End,
{
char *Pos;
char Sign;
char Zero;
INT32 i;
/* Parameter validation */
{
return (NULL);
}
if (Type & ACPI_FORMAT_LEFT)
{
Type &= ~ACPI_FORMAT_ZERO;
}
/* Calculate size according to sign and prefix */
Sign = '\0';
if (Type & ACPI_FORMAT_SIGN)
{
{
Sign = '-';
Width--;
}
else if (Type & ACPI_FORMAT_SIGN_PLUS)
{
Sign = '+';
Width--;
}
else if (Type & ACPI_FORMAT_SIGN_PLUS_SPACE)
{
Sign = ' ';
Width--;
}
}
if (NeedPrefix)
{
Width--;
if (Base == 16)
{
Width--;
}
}
/* Generate full string in reverse order */
/* Printing 100 using %2d gives "100", not "00" */
if (i > Precision)
{
Precision = i;
}
/* Output the string */
{
while (--Width >= 0)
{
}
}
if (Sign)
{
}
if (NeedPrefix)
{
if (Base == 16)
{
}
}
if (!(Type & ACPI_FORMAT_LEFT))
{
while (--Width >= 0)
{
}
}
while (i <= --Precision)
{
}
while (--i >= 0)
{
ReversedString[i]);
}
while (--Width >= 0)
{
}
return (String);
}
/*******************************************************************************
*
* FUNCTION: AcpiUtVsnprintf
*
* PARAMETERS: String - String with boundary
* Size - Boundary of the string
* Format - Standard printf format
* Args - Argument list
*
* RETURN: Number of bytes actually written.
*
* DESCRIPTION: Formatted output to a string using argument list pointer.
*
******************************************************************************/
int
char *String,
const char *Format,
{
char Qualifier;
char *Pos;
char *End;
char c;
const char *s;
const void *p;
int i;
{
if (*Format != '%')
{
continue;
}
Type = 0;
Base = 10;
/* Process sign */
do
{
++Format;
if (*Format == '#')
{
}
else if (*Format == '0')
{
Type |= ACPI_FORMAT_ZERO;
}
else if (*Format == '+')
{
}
else if (*Format == ' ')
{
}
else if (*Format == '-')
{
Type |= ACPI_FORMAT_LEFT;
}
else
{
break;
}
} while (1);
/* Process width */
Width = -1;
{
}
else if (*Format == '*')
{
++Format;
if (Width < 0)
{
Type |= ACPI_FORMAT_LEFT;
}
}
/* Process precision */
Precision = -1;
if (*Format == '.')
{
++Format;
{
}
else if (*Format == '*')
{
++Format;
}
if (Precision < 0)
{
Precision = 0;
}
}
/* Process qualifier */
Qualifier = -1;
{
++Format;
{
Qualifier = 'L';
++Format;
}
}
switch (*Format)
{
case '%':
continue;
case 'c':
if (!(Type & ACPI_FORMAT_LEFT))
{
while (--Width > 0)
{
}
}
while (--Width > 0)
{
}
continue;
case 's':
if (!s)
{
s = "<NULL>";
}
if (!(Type & ACPI_FORMAT_LEFT))
{
{
}
}
for (i = 0; i < Length; ++i)
{
++s;
}
{
}
continue;
case 'o':
Base = 8;
break;
case 'X':
case 'x':
Base = 16;
break;
case 'd':
case 'i':
Type |= ACPI_FORMAT_SIGN;
case 'u':
break;
case 'p':
if (Width == -1)
{
Width = 2 * sizeof (void *);
Type |= ACPI_FORMAT_ZERO;
}
continue;
default:
if (*Format)
{
}
else
{
--Format;
}
continue;
}
if (Qualifier == 'L')
{
if (Type & ACPI_FORMAT_SIGN)
{
}
}
else if (Qualifier == 'l')
{
if (Type & ACPI_FORMAT_SIGN)
{
}
}
else if (Qualifier == 'h')
{
if (Type & ACPI_FORMAT_SIGN)
{
}
}
else
{
if (Type & ACPI_FORMAT_SIGN)
{
}
}
}
if (Size > 0)
{
{
*Pos = '\0';
}
else
{
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiUtSnprintf
*
* PARAMETERS: String - String with boundary
* Size - Boundary of the string
* Format, ... - Standard printf format
*
* RETURN: Number of bytes actually written.
*
* DESCRIPTION: Formatted output to a string.
*
******************************************************************************/
int
char *String,
const char *Format,
...)
{
int Length;
return (Length);
}
#ifdef ACPI_APPLICATION
/*******************************************************************************
*
* FUNCTION: AcpiUtFileVprintf
*
* PARAMETERS: File - File descriptor
* Format - Standard printf format
* Args - Argument list
*
* RETURN: Number of bytes actually written.
*
* DESCRIPTION: Formatted output to a file using argument list pointer.
*
******************************************************************************/
int
const char *Format,
{
int Length;
return (Length);
}
/*******************************************************************************
*
* FUNCTION: AcpiUtFilePrintf
*
* PARAMETERS: File - File descriptor
* Format, ... - Standard printf format
*
* RETURN: Number of bytes actually written.
*
* DESCRIPTION: Formatted output to a file.
*
******************************************************************************/
int
const char *Format,
...)
{
int Length;
return (Length);
}
#endif