]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/TianoTools/String/PrintLibInternal.c
60e8bba0df15c34a98cd0cce566a10f2a875146c
2 Print Library worker functions.
5 Copyright (c) 2004-2006 Intel Corporation. All rights reserved
6 This software and associated documentation (if any) is furnished
7 under a license and may only be used or copied in accordance
8 with the terms of the license. Except as permitted by such
9 license, no part of this software or documentation may be
10 reproduced, stored in a retrieval system, or transmitted in any
11 form or by any means without the express written consent of
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 Module Name: PrintLibInternal.c
21 #include <Common/UefiBaseTypes.h>
22 #include <Library/PrintLib.h>
24 #include "CommonLib.h"
25 #include "PrintLibInternal.h"
27 static CONST CHAR8 mHexStr
[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
30 BasePrintLibFillBuffer (
39 for (Index
= 0; Index
< Length
; Index
++) {
40 *Buffer
= (CHAR8
) Character
;
41 *(Buffer
+ 1) = (CHAR8
) (Character
>> 8);
48 Print worker function that prints a Value as a decimal number in Buffer.
50 @param Buffer Location to place the Unicode or ASCII string of Value.
52 @param Value Value to convert to a Decimal or Hexidecimal string in Buffer.
54 @param Flags Flags to use in printing string, see file header for details.
56 @param Precision Minimum number of digits to return in the ASCII string
58 @return Number of characters printed.
63 BasePrintLibValueToString (
73 // Loop to convert one digit at a time in reverse order
78 // Value = (INT64)DivU64x32Remainder ((UINT64)Value, (UINT32)Radix, &Remainder);
79 Remainder
= (UINT64
)Value
% (UINT32
)Radix
;
80 Value
= (UINT64
)Value
/ (UINT32
)Radix
;
81 *(Buffer
++) = mHexStr
[Remainder
];
88 BasePrintLibConvertValueToString (
96 CHAR8
*OriginalBuffer
;
97 CHAR8 ValueBuffer
[MAXIMUM_VALUE_CHARACTERS
];
102 OriginalBuffer
= Buffer
;
104 if (Width
== 0 || (Flags
& COMMA_TYPE
) != 0) {
105 Flags
&= (~PREFIX_ZERO
);
108 if (Width
== 0 || Width
> (MAXIMUM_VALUE_CHARACTERS
- 1)) {
109 Width
= MAXIMUM_VALUE_CHARACTERS
- 1;
114 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, '-', Increment
);
117 Count
= BasePrintLibValueToString (ValueBuffer
, Value
, 10);
119 if ((Flags
& PREFIX_ZERO
) != 0) {
120 Buffer
= BasePrintLibFillBuffer (Buffer
, Width
- Count
, '0', Increment
);
123 Digits
= 3 - (Count
% 3);
124 for (Index
= 0; Index
< Count
; Index
++) {
125 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, ValueBuffer
[Count
- Index
], Increment
);
126 if ((Flags
& COMMA_TYPE
) != 0) {
130 if ((Index
+ 1) < Count
) {
131 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, ',', Increment
);
137 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, 0, Increment
);
139 return ((Buffer
- OriginalBuffer
) / Increment
);