From 6bae492fb4573b414661ee9f850e14073ccf1ad9 Mon Sep 17 00:00:00 2001 From: jcarsey Date: Mon, 8 Aug 2011 20:50:31 +0000 Subject: [PATCH] clarify the logic of the print length counting functions in both PrintLib library instances. signed-off-by: jcarsey reviewed-by: geekboy15a git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12102 6f19259b-4bc3-4df7-8a09-765794883524 --- .../DxePrintLibPrint2Protocol/PrintLib.c | 48 ++++--------------- .../Library/BasePrintLib/PrintLibInternal.c | 42 +++++++--------- 2 files changed, 25 insertions(+), 65 deletions(-) diff --git a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c index a239dee2cc..45aab49176 100644 --- a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c +++ b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c @@ -1660,38 +1660,18 @@ InternalPrintLibSPrintMarker ( // Pad before the string // if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) { - if (Flags & COUNT_ONLY_NO_PRINT) { - LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter); - } else { -// Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter); - } + LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter); } if (ZeroPad) { if (Prefix != 0) { - 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); + LengthToReturn += (1 * BytesPerOutputCharacter); } + LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter); } else { - if (Flags & COUNT_ONLY_NO_PRINT) { - LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter); - } else { -// Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter); - } + LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter); if (Prefix != 0) { - if (Flags & COUNT_ONLY_NO_PRINT) { - LengthToReturn += (1 * BytesPerOutputCharacter); - } else { -// Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter); - } + LengthToReturn += (1 * BytesPerOutputCharacter); } } @@ -1709,11 +1689,7 @@ InternalPrintLibSPrintMarker ( while (Index < Count) { ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask; - if (Flags & COUNT_ONLY_NO_PRINT) { - LengthToReturn += (1 * BytesPerOutputCharacter); - } else { -// Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter); - } + LengthToReturn += (1 * BytesPerOutputCharacter); ArgumentString += BytesPerArgumentCharacter; Index++; if (Comma) { @@ -1722,11 +1698,7 @@ InternalPrintLibSPrintMarker ( Digits = 0; Index++; if (Index < Count) { - if (Flags & COUNT_ONLY_NO_PRINT) { - LengthToReturn += (1 * BytesPerOutputCharacter); - } else { -// Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter); - } + LengthToReturn += (1 * BytesPerOutputCharacter); } } } @@ -1736,11 +1708,7 @@ InternalPrintLibSPrintMarker ( // Pad after the string // if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) { - if (Flags & COUNT_ONLY_NO_PRINT) { - LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter); - } else { -// Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter); - } + LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter); } // diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Library/BasePrintLib/PrintLibInternal.c index 205b54aa09..de1b25fa7a 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.c +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.c @@ -334,7 +334,7 @@ BasePrintLibSPrintMarker ( UINT32 GuidData1; UINT16 GuidData2; UINT16 GuidData3; - UINTN LengthToReturn; + UINT32 LengthToReturn; // // If you change this code be sure to match the 2 versions of this function. @@ -842,36 +842,31 @@ BasePrintLibSPrintMarker ( // Pad before the string // if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) { - if (Flags & COUNT_ONLY_NO_PRINT) { - LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter); - } else { + LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter); + if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter); } } if (ZeroPad) { if (Prefix != 0) { - if (Flags & COUNT_ONLY_NO_PRINT) { - LengthToReturn += (1 * BytesPerOutputCharacter); - } else { + LengthToReturn += (1 * BytesPerOutputCharacter); + if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter); } } - if (Flags & COUNT_ONLY_NO_PRINT) { - LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter); - } else { + LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter); + if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, '0', BytesPerOutputCharacter); } } else { - if (Flags & COUNT_ONLY_NO_PRINT) { - LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter); - } else { + LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter); + if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter); } if (Prefix != 0) { - if (Flags & COUNT_ONLY_NO_PRINT) { - LengthToReturn += (1 * BytesPerOutputCharacter); - } else { + LengthToReturn += (1 * BytesPerOutputCharacter); + if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter); } } @@ -891,9 +886,8 @@ BasePrintLibSPrintMarker ( while (Index < Count) { ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask; - if (Flags & COUNT_ONLY_NO_PRINT) { - LengthToReturn += (1 * BytesPerOutputCharacter); - } else { + LengthToReturn += (1 * BytesPerOutputCharacter); + if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter); } ArgumentString += BytesPerArgumentCharacter; @@ -904,9 +898,8 @@ BasePrintLibSPrintMarker ( Digits = 0; Index++; if (Index < Count) { - if (Flags & COUNT_ONLY_NO_PRINT) { - LengthToReturn += (1 * BytesPerOutputCharacter); - } else { + LengthToReturn += (1 * BytesPerOutputCharacter); + if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter); } } @@ -918,9 +911,8 @@ BasePrintLibSPrintMarker ( // Pad after the string // if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) { - if (Flags & COUNT_ONLY_NO_PRINT) { - LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter); - } else { + LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter); + if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter); } } -- 2.39.2