diff options
author | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-08-02 23:33:06 +0000 |
---|---|---|
committer | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-08-02 23:33:06 +0000 |
commit | f405c0674aef0fb8bff34acb0011c47f7cd38ea6 (patch) | |
tree | ce09868cf38489b3570ae33e90a9385c2e92b95e /MdePkg/Library | |
parent | 274402de4642937735918e6c756777c40524957d (diff) | |
download | edk2-f405c0674aef0fb8bff34acb0011c47f7cd38ea6.zip edk2-f405c0674aef0fb8bff34acb0011c47f7cd38ea6.tar.gz edk2-f405c0674aef0fb8bff34acb0011c47f7cd38ea6.tar.bz2 |
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
Diffstat (limited to 'MdePkg/Library')
-rw-r--r-- | MdePkg/Library/BasePrintLib/PrintLib.c | 50 | ||||
-rw-r--r-- | MdePkg/Library/BasePrintLib/PrintLibInternal.c | 106 | ||||
-rw-r--r-- | MdePkg/Library/BasePrintLib/PrintLibInternal.h | 45 | ||||
-rw-r--r-- | MdePkg/Library/UefiLib/UefiLibPrint.c | 96 |
4 files changed, 255 insertions, 42 deletions
diff --git a/MdePkg/Library/BasePrintLib/PrintLib.c b/MdePkg/Library/BasePrintLib/PrintLib.c index 6add9cb..daeb8d4 100644 --- a/MdePkg/Library/BasePrintLib/PrintLib.c +++ b/MdePkg/Library/BasePrintLib/PrintLib.c @@ -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);
+}
diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Library/BasePrintLib/PrintLibInternal.c index 2be6ad5..dbab58d 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.c +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.c @@ -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
//
diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.h b/MdePkg/Library/BasePrintLib/PrintLibInternal.h index a68a57f..32a2126 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.h +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.h @@ -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
diff --git a/MdePkg/Library/UefiLib/UefiLibPrint.c b/MdePkg/Library/UefiLib/UefiLibPrint.c index 5ce73b0..8ecb58d 100644 --- a/MdePkg/Library/UefiLib/UefiLibPrint.c +++ b/MdePkg/Library/UefiLib/UefiLibPrint.c @@ -2,7 +2,7 @@ Mde UEFI library API implementation.
Print to StdErr or ConOut defined in EFI_SYSTEM_TABLE
- Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2007 - 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
@@ -706,3 +706,97 @@ AsciiPrintXY ( return ReturnNum;
}
+/**
+ Appends a formatted Unicode string to a Null-terminated Unicode string
+
+ This function appends a formatted Unicode string to the Null-terminated
+ Unicode string specified by String. String is optional and may be NULL.
+ Storage for the formatted Unicode string returned is allocated using
+ AllocatePool(). The pointer to the appended string is returned. The caller
+ is responsible for freeing the returned string.
+
+ If String is not NULL and not aligned on a 16-bit boundary, then ASSERT().
+ If FormatString is NULL, then ASSERT().
+ If FormatString is not aligned on a 16-bit boundary, then ASSERT().
+
+ @param[in] String A Null-terminated Unicode string.
+ @param[in] FormatString A Null-terminated Unicode format string.
+ @param[in] Marker VA_LIST marker for the variable argument list.
+
+ @retval NULL There was not enough available memory.
+ @return Null-terminated Unicode string is that is the formatted
+ string appended to String.
+**/
+CHAR16*
+EFIAPI
+CatVSPrint (
+ IN CHAR16 *String, OPTIONAL
+ IN CONST CHAR16 *FormatString,
+ IN VA_LIST Marker
+ )
+{
+ UINTN CharactersRequired;
+ UINTN SizeRequired;
+ CHAR16 *BufferToReturn;
+
+ CharactersRequired = SPrintLength(FormatString, Marker);
+
+ if (String != NULL) {
+ SizeRequired = StrSize(String) + (CharactersRequired * sizeof(CHAR16));
+ } else {
+ SizeRequired = sizeof(CHAR16) + (CharactersRequired * sizeof(CHAR16));
+ }
+
+ BufferToReturn = AllocateZeroPool(SizeRequired);
+
+ if (BufferToReturn == NULL) {
+ return NULL;
+ }
+
+ if (String != NULL) {
+ StrCpy(BufferToReturn, String);
+ }
+
+ UnicodeVSPrint(BufferToReturn + StrLen(BufferToReturn), (CharactersRequired+1) * sizeof(CHAR16), FormatString, Marker);
+
+ ASSERT(StrSize(BufferToReturn)==SizeRequired);
+
+ return (BufferToReturn);
+}
+
+/**
+ Appends a formatted Unicode string to a Null-terminated Unicode string
+
+ This function appends a formatted Unicode string to the Null-terminated
+ Unicode string specified by String. String is optional and may be NULL.
+ Storage for the formatted Unicode string returned is allocated using
+ AllocatePool(). The pointer to the appended string is returned. The caller
+ is responsible for freeing the returned string.
+
+ If String is not NULL and not aligned on a 16-bit boundary, then ASSERT().
+ If FormatString is NULL, then ASSERT().
+ If FormatString is not aligned on a 16-bit boundary, then ASSERT().
+
+ @param[in] String A Null-terminated Unicode string.
+ @param[in] FormatString A Null-terminated Unicode format string.
+ @param[in] ... The variable argument list whose contents are
+ accessed based on the format string specified by
+ FormatString.
+
+ @retval NULL There was not enough available memory.
+ @return Null-terminated Unicode string is that is the formatted
+ string appended to String.
+**/
+CHAR16 *
+EFIAPI
+CatSPrint (
+ IN CHAR16 *String, OPTIONAL
+ IN CONST CHAR16 *FormatString,
+ ...
+ )
+{
+ VA_LIST Marker;
+ VA_START (Marker, FormatString);
+ return (CatVSPrint(String, FormatString, Marker));
+}
+
|