]>
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
18 #include <UefiBaseTypes.h>
21 #include <CommonLib.h>
22 #include "PrintLibInternal.h"
24 static CONST CHAR8 mHexStr
[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
27 BasePrintLibFillBuffer (
36 for (Index
= 0; Index
< Length
; Index
++) {
37 *Buffer
= (CHAR8
) Character
;
38 *(Buffer
+ 1) = (CHAR8
) (Character
>> 8);
45 Print worker function that prints a Value as a decimal number in Buffer.
47 @param Buffer Location to place the Unicode or ASCII string of Value.
49 @param Value Value to convert to a Decimal or Hexidecimal string in Buffer.
51 @param Flags Flags to use in printing string, see file header for details.
53 @param Precision Minimum number of digits to return in the ASCII string
55 @return Number of characters printed.
60 BasePrintLibValueToString (
70 // Loop to convert one digit at a time in reverse order
75 // Value = (INT64)DivU64x32Remainder ((UINT64)Value, (UINT32)Radix, &Remainder);
76 Remainder
= (UINT64
)Value
% (UINT32
)Radix
;
77 Value
= (UINT64
)Value
/ (UINT32
)Radix
;
78 *(Buffer
++) = mHexStr
[Remainder
];
85 BasePrintLibConvertValueToString (
93 CHAR8
*OriginalBuffer
;
94 CHAR8 ValueBuffer
[MAXIMUM_VALUE_CHARACTERS
];
99 OriginalBuffer
= Buffer
;
101 if (Width
== 0 || (Flags
& COMMA_TYPE
) != 0) {
102 Flags
&= (~PREFIX_ZERO
);
105 if (Width
== 0 || Width
> (MAXIMUM_VALUE_CHARACTERS
- 1)) {
106 Width
= MAXIMUM_VALUE_CHARACTERS
- 1;
111 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, '-', Increment
);
114 Count
= BasePrintLibValueToString (ValueBuffer
, Value
, 10);
116 if ((Flags
& PREFIX_ZERO
) != 0) {
117 Buffer
= BasePrintLibFillBuffer (Buffer
, Width
- Count
, '0', Increment
);
120 Digits
= 3 - (Count
% 3);
121 for (Index
= 0; Index
< Count
; Index
++) {
122 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, ValueBuffer
[Count
- Index
], Increment
);
123 if ((Flags
& COMMA_TYPE
) != 0) {
127 if ((Index
+ 1) < Count
) {
128 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, ',', Increment
);
134 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, 0, Increment
);
136 return ((Buffer
- OriginalBuffer
) / Increment
);