Fix bug of missing Pcd information in FPD ModuleSA.
[mirror_edk2.git] / Tools / Source / TianoTools / String / PrintLibInternal.c
CommitLineData
d2ec0d9e 1/** @file\r
2 Print Library worker functions.\r
3\r
4 Copyright (c) 2006, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13 Module Name: PrintLibInternal.c\r
14\r
15**/\r
16\r
ce53a8c3 17#include <Common/UefiBaseTypes.h>\r
18#include <Library/PrintLib.h>\r
19\r
20#include "CommonLib.h"\r
d2ec0d9e 21#include "PrintLibInternal.h"\r
22\r
23static CONST CHAR8 mHexStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};\r
24\r
25CHAR8 *\r
26BasePrintLibFillBuffer (\r
27 CHAR8 *Buffer,\r
28 INTN Length,\r
29 UINTN Character,\r
30 INTN Increment\r
31 )\r
32{\r
33 INTN Index;\r
34\r
35 for (Index = 0; Index < Length; Index++) {\r
36 *Buffer = (CHAR8) Character;\r
37 *(Buffer + 1) = (CHAR8) (Character >> 8);\r
38 Buffer += Increment;\r
39 }\r
40 return Buffer;\r
41}\r
42\r
43/**\r
44 Print worker function that prints a Value as a decimal number in Buffer.\r
45\r
46 @param Buffer Location to place the Unicode or ASCII string of Value.\r
47 \r
48 @param Value Value to convert to a Decimal or Hexidecimal string in Buffer.\r
49 \r
50 @param Flags Flags to use in printing string, see file header for details.\r
51 \r
52 @param Precision Minimum number of digits to return in the ASCII string\r
53\r
54 @return Number of characters printed.\r
55\r
56**/\r
57UINTN\r
58EFIAPI\r
59BasePrintLibValueToString (\r
60 IN OUT CHAR8 *Buffer,\r
61 IN INT64 Value,\r
62 IN UINTN Radix\r
63 )\r
64{\r
65 UINTN Digits;\r
66 UINT32 Remainder;\r
67\r
68 //\r
69 // Loop to convert one digit at a time in reverse order\r
70 //\r
71 *(Buffer++) = 0;\r
72 Digits = 0;\r
73 do {\r
74 // Value = (INT64)DivU64x32Remainder ((UINT64)Value, (UINT32)Radix, &Remainder);\r
75 Remainder = (UINT64)Value % (UINT32)Radix;\r
76 Value = (UINT64)Value / (UINT32)Radix;\r
77 *(Buffer++) = mHexStr[Remainder];\r
78 Digits++;\r
79 } while (Value != 0);\r
80 return Digits;\r
81}\r
82\r
83UINTN\r
84BasePrintLibConvertValueToString (\r
85 IN OUT CHAR8 *Buffer,\r
86 IN UINTN Flags,\r
87 IN INT64 Value,\r
88 IN UINTN Width,\r
89 IN UINTN Increment\r
90 )\r
91{\r
92 CHAR8 *OriginalBuffer;\r
93 CHAR8 ValueBuffer[MAXIMUM_VALUE_CHARACTERS];\r
94 UINTN Count;\r
95 UINTN Digits;\r
96 UINTN Index;\r
97\r
98 OriginalBuffer = Buffer;\r
99\r
100 if (Width == 0 || (Flags & COMMA_TYPE) != 0) {\r
101 Flags &= (~PREFIX_ZERO);\r
102 }\r
103\r
104 if (Width == 0 || Width > (MAXIMUM_VALUE_CHARACTERS - 1)) {\r
105 Width = MAXIMUM_VALUE_CHARACTERS - 1;\r
106 }\r
107\r
108 if (Value < 0) {\r
109 Value = -Value;\r
110 Buffer = BasePrintLibFillBuffer (Buffer, 1, '-', Increment);\r
111 }\r
112\r
113 Count = BasePrintLibValueToString (ValueBuffer, Value, 10);\r
114\r
115 if ((Flags & PREFIX_ZERO) != 0) {\r
116 Buffer = BasePrintLibFillBuffer (Buffer, Width - Count, '0', Increment);\r
117 }\r
118\r
119 Digits = 3 - (Count % 3);\r
120 for (Index = 0; Index < Count; Index++) {\r
121 Buffer = BasePrintLibFillBuffer (Buffer, 1, ValueBuffer[Count - Index], Increment);\r
122 if ((Flags & COMMA_TYPE) != 0) {\r
123 Digits++;\r
124 if (Digits == 3) {\r
125 Digits = 0;\r
126 if ((Index + 1) < Count) {\r
127 Buffer = BasePrintLibFillBuffer (Buffer, 1, ',', Increment);\r
128 }\r
129 }\r
130 }\r
131 }\r
132\r
133 Buffer = BasePrintLibFillBuffer (Buffer, 1, 0, Increment);\r
134\r
135 return ((Buffer - OriginalBuffer) / Increment);\r
136}\r