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