]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/TianoTools/String/PrintLibInternal.c
2 Print Library worker functions.
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
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.
13 Module Name: PrintLibInternal.c
17 #include <Common/UefiBaseTypes.h>
18 #include <Library/PrintLib.h>
20 #include "CommonLib.h"
21 #include "PrintLibInternal.h"
23 static CONST CHAR8 mHexStr
[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
26 BasePrintLibFillBuffer (
35 for (Index
= 0; Index
< Length
; Index
++) {
36 *Buffer
= (CHAR8
) Character
;
37 *(Buffer
+ 1) = (CHAR8
) (Character
>> 8);
44 Print worker function that prints a Value as a decimal number in Buffer.
46 @param Buffer Location to place the Unicode or ASCII string of Value.
48 @param Value Value to convert to a Decimal or Hexidecimal string in Buffer.
50 @param Flags Flags to use in printing string, see file header for details.
52 @param Precision Minimum number of digits to return in the ASCII string
54 @return Number of characters printed.
59 BasePrintLibValueToString (
69 // Loop to convert one digit at a time in reverse order
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
];
84 BasePrintLibConvertValueToString (
92 CHAR8
*OriginalBuffer
;
93 CHAR8 ValueBuffer
[MAXIMUM_VALUE_CHARACTERS
];
98 OriginalBuffer
= Buffer
;
100 if (Width
== 0 || (Flags
& COMMA_TYPE
) != 0) {
101 Flags
&= (~PREFIX_ZERO
);
104 if (Width
== 0 || Width
> (MAXIMUM_VALUE_CHARACTERS
- 1)) {
105 Width
= MAXIMUM_VALUE_CHARACTERS
- 1;
110 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, '-', Increment
);
113 Count
= BasePrintLibValueToString (ValueBuffer
, Value
, 10);
115 if ((Flags
& PREFIX_ZERO
) != 0) {
116 Buffer
= BasePrintLibFillBuffer (Buffer
, Width
- Count
, '0', Increment
);
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) {
126 if ((Index
+ 1) < Count
) {
127 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, ',', Increment
);
133 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, 0, Increment
);
135 return ((Buffer
- OriginalBuffer
) / Increment
);