Add 2 functions to UefiLib library class: CatSPrint and CatVSPrint.
Implement these functions in the UefiLib instance. Add 2 functions to PrintLib library class: SPrintLengthAsciiFormat and SPrintLength. Implement these functions in the BasePrintLib instance and the DxePrintLib2Protocol instance. Signed-off-by: jcarsey Reviewed-by: jljusten Reviewed-by: geekboy15a git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12081 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
Base Print Library instance implementation.
|
||||
|
||||
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||
Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
@@ -694,3 +694,51 @@ AsciiValueToString (
|
||||
{
|
||||
return BasePrintLibConvertValueToString (Buffer, Flags, Value, Width, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the number of characters that would be produced by if the formatted
|
||||
output were produced not including the Null-terminator.
|
||||
|
||||
If FormatString is NULL, then ASSERT().
|
||||
If FormatString is not aligned on a 16-bit boundary, then ASSERT().
|
||||
|
||||
@param[in] FormatString A Null-terminated Unicode format string.
|
||||
@param[in] Marker VA_LIST marker for the variable argument list.
|
||||
|
||||
@return The number of characters that would be produced, not including the
|
||||
Null-terminator.
|
||||
**/
|
||||
UINTN
|
||||
EFIAPI
|
||||
SPrintLength (
|
||||
IN CONST CHAR16 *FormatString,
|
||||
IN VA_LIST Marker
|
||||
)
|
||||
{
|
||||
ASSERT(FormatString != NULL);
|
||||
ASSERT_UNICODE_BUFFER (FormatString);
|
||||
return BasePrintLibSPrintMarker (NULL, 0, FORMAT_UNICODE | OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the number of characters that would be produced by if the formatted
|
||||
output were produced not including the Null-terminator.
|
||||
|
||||
If FormatString is NULL, then ASSERT().
|
||||
|
||||
@param[in] FormatString A Null-terminated ASCII format string.
|
||||
@param[in] Marker VA_LIST marker for the variable argument list.
|
||||
|
||||
@return The number of characters that would be produced, not including the
|
||||
Null-terminator.
|
||||
**/
|
||||
UINTN
|
||||
EFIAPI
|
||||
SPrintLengthAsciiFormat (
|
||||
IN CONST CHAR8 *FormatString,
|
||||
IN VA_LIST Marker
|
||||
)
|
||||
{
|
||||
ASSERT(FormatString != NULL);
|
||||
return BasePrintLibSPrintMarker (NULL, 0, OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);
|
||||
}
|
||||
|
@@ -275,16 +275,24 @@ BasePrintLibConvertValueToString (
|
||||
VA_LIST is used this routine allows the nesting of Vararg routines. Thus
|
||||
this is the main print working routine.
|
||||
|
||||
@param Buffer The character buffer to print the results of the parsing
|
||||
of Format into.
|
||||
@param BufferSize The maximum number of characters to put into buffer.
|
||||
@param Flags Initial flags value.
|
||||
Can only have FORMAT_UNICODE and OUTPUT_UNICODE set.
|
||||
@param Format A Null-terminated format string.
|
||||
@param VaListMarker VA_LIST style variable argument list consumed by processing Format.
|
||||
@param BaseListMarker BASE_LIST style variable argument list consumed by processing Format.
|
||||
If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.
|
||||
|
||||
@param[out] Buffer The character buffer to print the results of the
|
||||
parsing of Format into.
|
||||
@param[in] BufferSize The maximum number of characters to put into
|
||||
buffer.
|
||||
@param[in] Flags Initial flags value.
|
||||
Can only have FORMAT_UNICODE, OUTPUT_UNICODE,
|
||||
and COUNT_ONLY_NO_PRINT set.
|
||||
@param[in] Format A Null-terminated format string.
|
||||
@param[in] VaListMarker VA_LIST style variable argument list consumed by
|
||||
processing Format.
|
||||
@param[in] BaseListMarker BASE_LIST style variable argument list consumed
|
||||
by processing Format.
|
||||
|
||||
@return The number of characters printed not including the Null-terminator.
|
||||
If COUNT_ONLY_NO_PRINT was set returns the same, but without any
|
||||
modification to Buffer.
|
||||
|
||||
**/
|
||||
UINTN
|
||||
@@ -300,7 +308,7 @@ BasePrintLibSPrintMarker (
|
||||
CHAR8 *OriginalBuffer;
|
||||
CHAR8 *EndBuffer;
|
||||
CHAR8 ValueBuffer[MAXIMUM_VALUE_CHARACTERS];
|
||||
UINTN BytesPerOutputCharacter;
|
||||
UINT32 BytesPerOutputCharacter;
|
||||
UINTN BytesPerFormatCharacter;
|
||||
UINTN FormatMask;
|
||||
UINTN FormatCharacter;
|
||||
@@ -326,18 +334,36 @@ BasePrintLibSPrintMarker (
|
||||
UINT32 GuidData1;
|
||||
UINT16 GuidData2;
|
||||
UINT16 GuidData3;
|
||||
UINT32 LengthToReturn;
|
||||
|
||||
if (BufferSize == 0) {
|
||||
return 0;
|
||||
//
|
||||
// If you change this code be sure to match the 2 versions of this function.
|
||||
// Nearly identical logic is found in the BasePrintLib and
|
||||
// DxePrintLibPrint2Protocol (both PrintLib instances).
|
||||
//
|
||||
|
||||
if (Flags & COUNT_ONLY_NO_PRINT) {
|
||||
if (BufferSize == 0) {
|
||||
Buffer = NULL;
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// We can run without a Buffer for counting only.
|
||||
//
|
||||
if (BufferSize == 0) {
|
||||
return 0;
|
||||
}
|
||||
ASSERT (Buffer != NULL);
|
||||
}
|
||||
ASSERT (Buffer != NULL);
|
||||
|
||||
if ((Flags & OUTPUT_UNICODE) != 0) {
|
||||
if (Flags & OUTPUT_UNICODE) {
|
||||
BytesPerOutputCharacter = 2;
|
||||
} else {
|
||||
BytesPerOutputCharacter = 1;
|
||||
}
|
||||
|
||||
LengthToReturn = 0;
|
||||
|
||||
//
|
||||
// Reserve space for the Null terminator.
|
||||
//
|
||||
@@ -379,7 +405,7 @@ BasePrintLibSPrintMarker (
|
||||
//
|
||||
// Clear all the flag bits except those that may have been passed in
|
||||
//
|
||||
Flags &= (OUTPUT_UNICODE | FORMAT_UNICODE);
|
||||
Flags &= (OUTPUT_UNICODE | FORMAT_UNICODE | COUNT_ONLY_NO_PRINT);
|
||||
|
||||
//
|
||||
// Set the default width to zero, and the default precision to 1
|
||||
@@ -816,18 +842,38 @@ BasePrintLibSPrintMarker (
|
||||
// Pad before the string
|
||||
//
|
||||
if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);
|
||||
if (Flags & COUNT_ONLY_NO_PRINT) {
|
||||
LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);
|
||||
} else {
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);
|
||||
}
|
||||
}
|
||||
|
||||
if (ZeroPad) {
|
||||
if (Prefix != 0) {
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);
|
||||
if (Flags & COUNT_ONLY_NO_PRINT) {
|
||||
LengthToReturn += (1 * BytesPerOutputCharacter);
|
||||
} else {
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);
|
||||
}
|
||||
}
|
||||
if (Flags & COUNT_ONLY_NO_PRINT) {
|
||||
LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);
|
||||
} else {
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, '0', BytesPerOutputCharacter);
|
||||
}
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, '0', BytesPerOutputCharacter);
|
||||
} else {
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter);
|
||||
if (Flags & COUNT_ONLY_NO_PRINT) {
|
||||
LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);
|
||||
} else {
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter);
|
||||
}
|
||||
if (Prefix != 0) {
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);
|
||||
if (Flags & COUNT_ONLY_NO_PRINT) {
|
||||
LengthToReturn += (1 * BytesPerOutputCharacter);
|
||||
} else {
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -845,7 +891,11 @@ BasePrintLibSPrintMarker (
|
||||
while (Index < Count) {
|
||||
ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask;
|
||||
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter);
|
||||
if (Flags & COUNT_ONLY_NO_PRINT) {
|
||||
LengthToReturn += (1 * BytesPerOutputCharacter);
|
||||
} else {
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter);
|
||||
}
|
||||
ArgumentString += BytesPerArgumentCharacter;
|
||||
Index++;
|
||||
if (Comma) {
|
||||
@@ -854,7 +904,11 @@ BasePrintLibSPrintMarker (
|
||||
Digits = 0;
|
||||
Index++;
|
||||
if (Index < Count) {
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter);
|
||||
if (Flags & COUNT_ONLY_NO_PRINT) {
|
||||
LengthToReturn += (1 * BytesPerOutputCharacter);
|
||||
} else {
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -864,7 +918,11 @@ BasePrintLibSPrintMarker (
|
||||
// Pad after the string
|
||||
//
|
||||
if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) {
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);
|
||||
if (Flags & COUNT_ONLY_NO_PRINT) {
|
||||
LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);
|
||||
} else {
|
||||
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -878,6 +936,10 @@ BasePrintLibSPrintMarker (
|
||||
FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
|
||||
}
|
||||
|
||||
if (Flags & COUNT_ONLY_NO_PRINT) {
|
||||
return (LengthToReturn / BytesPerOutputCharacter);
|
||||
}
|
||||
|
||||
//
|
||||
// Null terminate the Unicode or ASCII string
|
||||
//
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
Base Print Library instance Internal Functions definition.
|
||||
|
||||
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
@@ -24,15 +24,16 @@
|
||||
//
|
||||
// Print primitives
|
||||
//
|
||||
#define PREFIX_SIGN 0x02
|
||||
#define PREFIX_BLANK 0x04
|
||||
#define LONG_TYPE 0x10
|
||||
#define OUTPUT_UNICODE 0x40
|
||||
#define FORMAT_UNICODE 0x100
|
||||
#define PAD_TO_WIDTH 0x200
|
||||
#define ARGUMENT_UNICODE 0x400
|
||||
#define PRECISION 0x800
|
||||
#define ARGUMENT_REVERSED 0x1000
|
||||
#define PREFIX_SIGN BIT1
|
||||
#define PREFIX_BLANK BIT2
|
||||
#define LONG_TYPE BIT4
|
||||
#define OUTPUT_UNICODE BIT6
|
||||
#define FORMAT_UNICODE BIT8
|
||||
#define PAD_TO_WIDTH BIT9
|
||||
#define ARGUMENT_UNICODE BIT10
|
||||
#define PRECISION BIT11
|
||||
#define ARGUMENT_REVERSED BIT12
|
||||
#define COUNT_ONLY_NO_PRINT BIT13
|
||||
|
||||
//
|
||||
// Record date and time information
|
||||
@@ -59,16 +60,24 @@ typedef struct {
|
||||
VA_LIST is used this routine allows the nesting of Vararg routines. Thus
|
||||
this is the main print working routine.
|
||||
|
||||
@param Buffer The character buffer to print the results of the parsing
|
||||
of Format into.
|
||||
@param BufferSize The maximum number of characters to put into buffer.
|
||||
@param Flags Initial flags value.
|
||||
Can only have FORMAT_UNICODE and OUTPUT_UNICODE set.
|
||||
@param Format A Null-terminated format string.
|
||||
@param VaListMarker VA_LIST style variable argument list consumed by processing Format.
|
||||
@param BaseListMarker BASE_LIST style variable argument list consumed by processing Format.
|
||||
If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.
|
||||
|
||||
@param[out] Buffer The character buffer to print the results of the
|
||||
parsing of Format into.
|
||||
@param[in] BufferSize The maximum number of characters to put into
|
||||
buffer.
|
||||
@param[in] Flags Initial flags value.
|
||||
Can only have FORMAT_UNICODE, OUTPUT_UNICODE,
|
||||
and COUNT_ONLY_NO_PRINT set.
|
||||
@param[in] Format A Null-terminated format string.
|
||||
@param[in] VaListMarker VA_LIST style variable argument list consumed by
|
||||
processing Format.
|
||||
@param[in] BaseListMarker BASE_LIST style variable argument list consumed
|
||||
by processing Format.
|
||||
|
||||
@return The number of characters printed not including the Null-terminator.
|
||||
If COUNT_ONLY_NO_PRINT was set returns the same, but without any
|
||||
modification to Buffer.
|
||||
|
||||
**/
|
||||
UINTN
|
||||
|
Reference in New Issue
Block a user