printlib.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 1,062 行 · 第 1/3 页
C
1,062 行
ArgumentString = (CHAR8 *)VA_ARG (Marker, CHAR8 *);
if (ArgumentString == NULL) {
Flags &= (~ARGUMENT_UNICODE);
ArgumentString = "<null string>";
}
break;
case 'c':
Character = VA_ARG (Marker, UINTN) & 0xffff;
ArgumentString = (CHAR8 *)&Character;
Flags |= ARGUMENT_UNICODE;
break;
case 'g':
TmpGuid = VA_ARG (Marker, GUID *);
if (TmpGuid == NULL) {
ArgumentString = "<null guid>";
} else {
BasePrintLibSPrint (
ValueBuffer,
MAXIMUM_VALUE_CHARACTERS,
0,
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
TmpGuid->Data1,
TmpGuid->Data2,
TmpGuid->Data3,
TmpGuid->Data4[0],
TmpGuid->Data4[1],
TmpGuid->Data4[2],
TmpGuid->Data4[3],
TmpGuid->Data4[4],
TmpGuid->Data4[5],
TmpGuid->Data4[6],
TmpGuid->Data4[7]
);
ArgumentString = ValueBuffer;
}
break;
case 't':
TmpTime = VA_ARG (Marker, TIME *);
if (TmpTime == NULL) {
ArgumentString = "<null time>";
} else {
BasePrintLibSPrint (
ValueBuffer,
MAXIMUM_VALUE_CHARACTERS,
0,
"%02d/%02d/%04d %02d:%02d",
TmpTime->Month,
TmpTime->Day,
TmpTime->Year,
TmpTime->Hour,
TmpTime->Minute
);
ArgumentString = ValueBuffer;
}
break;
case 'r':
Status = VA_ARG (Marker, RETURN_STATUS);
ArgumentString = ValueBuffer;
if (RETURN_ERROR (Status)) {
//
// Clear error bit
//
Index = Status & ~MAX_BIT;
if (Index > 0 && Index <= ERROR_STATUS_NUMBER) {
ArgumentString = StatusString [Index + WARNING_STATUS_NUMBER];
}
} else {
Index = Status;
if (Index <= WARNING_STATUS_NUMBER) {
ArgumentString = StatusString [Index];
}
}
if (ArgumentString == ValueBuffer) {
BasePrintLibSPrint ((CHAR8 *) ValueBuffer, MAXIMUM_VALUE_CHARACTERS, 0, "%08X", Status);
}
break;
case '\n':
ArgumentString = "\n\r";
break;
case '%':
default:
//
// if the type is '%' or unknown, then print it to the screen
//
ArgumentString = (CHAR8 *)&FormatCharacter;
Flags |= ARGUMENT_UNICODE;
break;
}
break;
case '\n':
ArgumentString = "\n\r";
break;
default:
ArgumentString = (CHAR8 *)&FormatCharacter;
Flags |= ARGUMENT_UNICODE;
break;
}
//
// Retrieve the ArgumentString attriubutes
//
if ((Flags & ARGUMENT_UNICODE) != 0) {
ArgumentMask = 0xffff;
BytesPerArgumentCharacter = 2;
} else {
ArgumentMask = 0xff;
BytesPerArgumentCharacter = 1;
}
if ((Flags & ARGUMENT_REVERSED) != 0) {
BytesPerArgumentCharacter = -BytesPerArgumentCharacter;
} else {
//
// Compute the number of characters in ArgumentString and store it in Count
// ArgumentString is either null-terminated, or it contains Precision characters
//
for (Count = 0; Count < Precision || ((Flags & PRECISION) == 0); Count++) {
ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;
if (ArgumentCharacter == 0) {
break;
}
}
}
if (Precision < Count) {
Precision = Count;
}
//
// Pad before the string
//
if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);
}
if (ZeroPad) {
if (Prefix != 0) {
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);
}
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, '0', BytesPerOutputCharacter);
} else {
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter);
if (Prefix != 0) {
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);
}
}
//
// Output the Prefix character if it is present
//
Index = 0;
if (Prefix != 0) {
Index++;
}
//
// Copy the string into the output buffer performing the required type conversions
//
while (Index < Count) {
ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask;
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter);
ArgumentString += BytesPerArgumentCharacter;
Index++;
if (Comma) {
Digits++;
if (Digits == 3) {
Digits = 0;
Index++;
if (Index < Count) {
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter);
}
}
}
}
//
// Pad after the string
//
if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) {
Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);
}
//
// Get the next character from the format string
//
Format += BytesPerFormatCharacter;
//
// Get the next character from the format string
//
FormatCharacter = (*Format | (*(Format + 1) << 8)) & FormatMask;
}
//
// Null terminate the Unicode or ASCII string
//
BasePrintLibFillBuffer (Buffer, EndBuffer + BytesPerOutputCharacter, 1, 0, BytesPerOutputCharacter);
//
// Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength
// Unicode characters if PcdMaximumUnicodeStringLength is not zero.
//
ASSERT ((((Flags & OUTPUT_UNICODE) == 0)) || (StrSize ((CHAR16 *) OriginalBuffer) != 0));
//
// Make sure output buffer cannot contain more than PcdMaximumAsciiStringLength
// ASCII characters if PcdMaximumAsciiStringLength is not zero.
//
ASSERT ((((Flags & OUTPUT_UNICODE) != 0)) || (AsciiStrSize (OriginalBuffer) != 0));
return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter);
}
/**
Worker function that produces a Null-terminated string in an output buffer
based on a Null-terminated format string and variable argument list.
VSPrint function to process format and place the results in Buffer. Since a
VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
this is the main print working routine.
@param Buffer Character buffer to print the results of the parsing
of Format into.
@param BufferSize Maximum number of characters to put into buffer.
Zero means no limit.
@param Flags Intial flags value.
Can only have FORMAT_UNICODE and OUTPUT_UNICODE set
@param FormatString Null-terminated format string.
@return Number of characters printed not including the Null-terminator.
**/
UINTN
BasePrintLibSPrint (
OUT CHAR8 *StartOfBuffer,
IN UINTN BufferSize,
IN UINTN Flags,
IN CONST CHAR8 *FormatString,
...
)
{
VA_LIST Marker;
VA_START (Marker, FormatString);
return BasePrintLibVSPrint (StartOfBuffer, BufferSize, Flags, FormatString, Marker);
}
/**
Produces a Null-terminated Unicode string in an output buffer based on
a Null-terminated Unicode format string and a VA_LIST argument list
Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
and BufferSize.
The Unicode string is produced by parsing the format string specified by FormatString.
Arguments are pulled from the variable argument list specified by Marker based on the
contents of the format string.
The number of Unicode characters in the produced output buffer is returned not including
the Null-terminator.
If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
If BufferSize > 1 and FormatString is NULL, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
Null-terminator, then ASSERT().
@param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
Unicode string.
@param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
@param FormatString Null-terminated Unicode format string.
@param Marker VA_LIST marker for the variable argument list.
@return The number of Unicode characters in the produced output buffer not including the
Null-terminator.
**/
UINTN
EFIAPI
UnicodeVSPrint (
OUT CHAR16 *StartOfBuffer,
IN UINTN BufferSize,
IN CONST CHAR16 *FormatString,
IN VA_LIST Marker
)
{
return BasePrintLibVSPrint ((CHAR8 *)StartOfBuffer, BufferSize >> 1, FORMAT_UNICODE | OUTPUT_UNICODE, (CHAR8 *)FormatString, Marker);
}
/**
Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
Unicode format string and variable argument list.
Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
and BufferSize.
The Unicode string is produced by parsing the format string specified by FormatString.
Arguments are pulled from the variable argument list based on the contents of the format string.
The number of Unicode characters in the produced output buffer is returned not including
the Null-terminator.
If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
If BufferSize > 1 and FormatString is NULL, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
Null-terminator, then ASSERT().
@param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
Unicode string.
@param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
@param FormatString Null-terminated Unicode format string.
@return The number of Unicode characters in the produced output buffer not including the
Null-terminator.
**/
UINTN
EFIAPI
UnicodeSPrint (
OUT CHAR16 *StartOfBuffer,
IN UINTN BufferSize,
IN CONST CHAR16 *FormatString,
...
)
{
VA_LIST Marker;
VA_START (Marker, FormatString);
return UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
}
/**
Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
ASCII format string and a VA_LIST argument list
Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
and BufferSize.
The Unicode string is produced by parsing the format string specified by FormatString.
Arguments are pulled from the variable argument list specified by Marker based on the
contents of the format string.
The number of Unicode characters in the produced output buffer is returned not including
the Null-terminator.
If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?