X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FUefiLib%2FConsole.c;h=c37e3d0f58108fdeee5e4852fdf71d1e7fa11a3f;hb=2f88bd3a1296c522317f1c21377876de63de5be7;hp=41a9f3db97ee7eea6b4e8b6d4bee879a58499961;hpb=33026ccf33d8295ea6475f79f34415243a7a2513;p=mirror_edk2.git diff --git a/MdePkg/Library/UefiLib/Console.c b/MdePkg/Library/UefiLib/Console.c index 41a9f3db97..c37e3d0f58 100644 --- a/MdePkg/Library/UefiLib/Console.c +++ b/MdePkg/Library/UefiLib/Console.c @@ -1,37 +1,29 @@ /** @file This module provide help function for displaying unicode string. - Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php. - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent **/ - - - #include "UefiLibInternal.h" typedef struct { - CHAR16 WChar; - UINT32 Width; + CHAR16 WChar; + UINT32 Width; } UNICODE_WIDTH_ENTRY; -#define NARROW_CHAR 0xFFF0 -#define WIDE_CHAR 0xFFF1 +#define NARROW_CHAR 0xFFF0 +#define WIDE_CHAR 0xFFF1 -GLOBAL_REMOVE_IF_UNREFERENCED CONST UNICODE_WIDTH_ENTRY mUnicodeWidthTable[] = { +GLOBAL_REMOVE_IF_UNREFERENCED CONST UNICODE_WIDTH_ENTRY mUnicodeWidthTable[] = { // // General script area // - {(CHAR16)0x1FFF, 1}, + { (CHAR16)0x1FFF, 1 }, + /* - * Merge the blocks and replace them with the above entry as they fall to + * Merge the blocks and replace them with the above entry as they fall to * the same category and they are all narrow glyph. This will reduce search * time and table size. The merge will omit the reserved code. * @@ -76,9 +68,10 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UNICODE_WIDTH_ENTRY mUnicodeWidthTable[] = { // // Symbol area // - {(CHAR16)0x2FFF, 1}, + { (CHAR16)0x2FFF, 1 }, + /* - * Merge the blocks and replace them with the above entry as they fall to + * Merge the blocks and replace them with the above entry as they fall to * the same category and they are all narrow glyph. This will reduce search * time and table size. The merge will omit the reserved code. * @@ -108,9 +101,10 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UNICODE_WIDTH_ENTRY mUnicodeWidthTable[] = { // // CJK phonetics and symbol area // - {(CHAR16)0x33FF, 2}, + { (CHAR16)0x33FF, 2 }, + /* - * Merge the blocks and replace them with the above entry as they fall to + * Merge the blocks and replace them with the above entry as they fall to * the same category and they are all wide glyph. This will reduce search * time and table size. The merge will omit the reserved code. * @@ -131,15 +125,16 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UNICODE_WIDTH_ENTRY mUnicodeWidthTable[] = { // // CJK ideograph area // - {(CHAR16)0x9FFF, 2}, + { (CHAR16)0x9FFF, 2 }, + /* - * Merge the blocks and replace them with the above entry as they fall to + * Merge the blocks and replace them with the above entry as they fall to * the same category and they are all wide glyph. This will reduce search * time and table size. The merge will omit the reserved code. * * Remove the above item if below is un-commented. * - {(CHAR16)0x4DFF, 0}, // Reserved. 0x3400-0x4DBF as CJK unified ideographs + {(CHAR16)0x4DFF, 0}, // Reserved. 0x3400-0x4DBF as CJK unified ideographs // extension A in ver3.0. 0x3400-0x4DFF {(CHAR16)0x9FFF, 2}, // CJK unified ideographs. 0x4E00-0x9FFF * @@ -148,14 +143,15 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UNICODE_WIDTH_ENTRY mUnicodeWidthTable[] = { // // Reserved // - {(CHAR16)0xABFF, 0}, // Reserved. 0xA000-0xA490 as Yi syllables. 0xA490-0xA4D0 + { (CHAR16)0xABFF, 0 }, // Reserved. 0xA000-0xA490 as Yi syllables. 0xA490-0xA4D0 // as Yi radicals in ver3.0. 0xA000-0xABFF // // Hangul syllables // - {(CHAR16)0xD7FF, 2}, + { (CHAR16)0xD7FF, 2 }, + /* - * Merge the blocks and replace them with the above entry as they fall to + * Merge the blocks and replace them with the above entry as they fall to * the same category and they are all wide glyph. This will reduce search * time and table size. The merge will omit the reserved code. * @@ -169,26 +165,26 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UNICODE_WIDTH_ENTRY mUnicodeWidthTable[] = { // // Surrogates area // - {(CHAR16)0xDFFF, 0}, // Surrogates, not used now. 0xD800-0xDFFF + { (CHAR16)0xDFFF, 0 }, // Surrogates, not used now. 0xD800-0xDFFF // // Private use area // - {(CHAR16)0xF8FF, 0}, // Private use area. 0xE000-0xF8FF + { (CHAR16)0xF8FF, 0 }, // Private use area. 0xE000-0xF8FF // // Compatibility area and specials // - {(CHAR16)0xFAFF, 2}, // CJK compatibility ideographs. 0xF900-0xFAFF - {(CHAR16)0xFB4F, 1}, // Alphabetic presentation forms. 0xFB00-0xFB4F - {(CHAR16)0xFDFF, 1}, // Arabic presentation forms-A. 0xFB50-0xFDFF - {(CHAR16)0xFE1F, 0}, // Reserved. As variation selectors in ver3.0. 0xFE00-0xFE1F - {(CHAR16)0xFE2F, 1}, // Combining half marks. 0xFE20-0xFE2F - {(CHAR16)0xFE4F, 2}, // CJK compatibility forms. 0xFE30-0xFE4F - {(CHAR16)0xFE6F, 1}, // Small Form Variants. 0xFE50-0xFE6F - {(CHAR16)0xFEFF, 1}, // Arabic presentation forms-B. 0xFE70-0xFEFF - {(CHAR16)0xFFEF, 1}, // Half width and full width forms. 0xFF00-0xFFEF - {(CHAR16)0xFFFF, 0}, // Speicials. 0xFFF0-0xFFFF + { (CHAR16)0xFAFF, 2 }, // CJK compatibility ideographs. 0xF900-0xFAFF + { (CHAR16)0xFB4F, 1 }, // Alphabetic presentation forms. 0xFB00-0xFB4F + { (CHAR16)0xFDFF, 1 }, // Arabic presentation forms-A. 0xFB50-0xFDFF + { (CHAR16)0xFE1F, 0 }, // Reserved. As variation selectors in ver3.0. 0xFE00-0xFE1F + { (CHAR16)0xFE2F, 1 }, // Combining half marks. 0xFE20-0xFE2F + { (CHAR16)0xFE4F, 2 }, // CJK compatibility forms. 0xFE30-0xFE4F + { (CHAR16)0xFE6F, 1 }, // Small Form Variants. 0xFE50-0xFE6F + { (CHAR16)0xFEFF, 1 }, // Arabic presentation forms-B. 0xFE70-0xFEFF + { (CHAR16)0xFFEF, 1 }, // Half width and full width forms. 0xFF00-0xFFEF + { (CHAR16)0xFFFF, 0 }, // Speicials. 0xFFF0-0xFFFF }; /** @@ -210,14 +206,14 @@ GetGlyphWidth ( IN CHAR16 UnicodeChar ) { - UINTN Index; - UINTN Low; - UINTN High; - CONST UNICODE_WIDTH_ENTRY *Item; - - Item = NULL; - Low = 0; - High = (sizeof (mUnicodeWidthTable)) / (sizeof (UNICODE_WIDTH_ENTRY)) - 1; + UINTN Index; + UINTN Low; + UINTN High; + CONST UNICODE_WIDTH_ENTRY *Item; + + Item = NULL; + Low = 0; + High = (sizeof (mUnicodeWidthTable)) / (sizeof (UNICODE_WIDTH_ENTRY)) - 1; while (Low <= High) { Index = (Low + High) >> 1; Item = &(mUnicodeWidthTable[Index]); @@ -251,18 +247,18 @@ GetGlyphWidth ( /** Computes the display length of a Null-terminated Unicode String. - This function computes and returns the display length of the Null-terminated - Unicode string specified by String. If String is NULL then 0 is returned. If - any of the widths of the Unicode characters in String can not be determined, - then 0 is returned. The display width of String can be computed by summing the - display widths of each Unicode character in String. Unicode characters that - are narrow glyphs have a width of 1, and Unicode characters that are width glyphs + This function computes and returns the display length of the Null-terminated + Unicode string specified by String. If String is NULL then 0 is returned. If + any of the widths of the Unicode characters in String can not be determined, + then 0 is returned. The display width of String can be computed by summing the + display widths of each Unicode character in String. Unicode characters that + are narrow glyphs have a width of 1, and Unicode characters that are width glyphs have a width of 2. If String is not aligned on a 16-bit boundary, then ASSERT(). @param String A pointer to a Null-terminated Unicode string. @return The display length of the Null-terminated Unicode string specified by String. - + **/ UINTN EFIAPI @@ -270,8 +266,8 @@ UnicodeStringDisplayLength ( IN CONST CHAR16 *String ) { - UINTN Length; - UINTN Width; + UINTN Length; + UINTN Width; if (String == NULL) { return 0; @@ -292,7 +288,7 @@ UnicodeStringDisplayLength ( } /** - Count the storage space of a Unicode string. + Count the storage space of a Unicode string. This function handles the Unicode string with NARROW_CHAR and WIDE_CHAR control characters. NARROW_HCAR and WIDE_CHAR @@ -303,38 +299,39 @@ UnicodeStringDisplayLength ( @param String The input string to be counted. @param LimitLen Whether need to limit the string length. @param MaxWidth The max length this function supported. - @param Offset The max index of the string can be show out. + @param Offset The max index of the string can be show out. @return Storage space for the input string. **/ UINTN UefiLibGetStringWidth ( - IN CHAR16 *String, - IN BOOLEAN LimitLen, - IN UINTN MaxWidth, - OUT UINTN *Offset + IN CHAR16 *String, + IN BOOLEAN LimitLen, + IN UINTN MaxWidth, + OUT UINTN *Offset ) { - UINTN Index; - UINTN Count; - UINTN IncrementValue; + UINTN Index; + UINTN Count; + UINTN IncrementValue; if (String == NULL) { return 0; } - Index = 0; - Count = 0; - IncrementValue = 1; + Index = 0; + Count = 0; + IncrementValue = 1; do { // // Advance to the null-terminator or to the first width directive // - for (;(String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0); - Index++, Count = Count + IncrementValue) { - if (LimitLen && Count > MaxWidth) { + for ( ; (String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0); Index++) { + Count = Count + IncrementValue; + + if (LimitLen && (Count > MaxWidth)) { break; } } @@ -346,8 +343,8 @@ UefiLibGetStringWidth ( break; } - if (LimitLen && Count > MaxWidth) { - *Offset = Index - 1; + if (LimitLen && (Count > MaxWidth)) { + *Offset = Index; break; } @@ -370,42 +367,36 @@ UefiLibGetStringWidth ( } } while (String[Index] != 0); - // - // Increment by one to include the null-terminator in the size - // - if (!LimitLen) { - Count++; - } - return Count * sizeof (CHAR16); } /** - Draws a dialog box to the console output device specified by + Draws a dialog box to the console output device specified by ConOut defined in the EFI_SYSTEM_TABLE and waits for a keystroke - from the console input device specified by ConIn defined in the + from the console input device specified by ConIn defined in the EFI_SYSTEM_TABLE. If there are no strings in the variable argument list, then ASSERT(). If all the strings in the variable argument list are empty, then ASSERT(). @param[in] Attribute Specifies the foreground and background color of the popup. - @param[out] Key A pointer to the EFI_KEY value of the key that was + @param[out] Key A pointer to the EFI_KEY value of the key that was pressed. This is an optional parameter that may be NULL. If it is NULL then no wait for a keypress will be performed. @param[in] ... The variable argument list that contains pointers to Null- - terminated Unicode strings to display in the dialog box. + terminated Unicode strings to display in the dialog box. The variable argument list is terminated by a NULL. **/ VOID EFIAPI CreatePopUp ( - IN UINTN Attribute, - OUT EFI_INPUT_KEY *Key, OPTIONAL + IN UINTN Attribute, + OUT EFI_INPUT_KEY *Key OPTIONAL, ... ) { + EFI_STATUS Status; VA_LIST Args; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut; EFI_SIMPLE_TEXT_OUTPUT_MODE SavedConsoleMode; @@ -419,18 +410,20 @@ CreatePopUp ( UINTN Length; CHAR16 *Line; UINTN EventIndex; + CHAR16 *TmpString; // - // Determine the length of the longest line in the popup and the the total + // Determine the length of the longest line in the popup and the the total // number of lines in the popup // VA_START (Args, Key); - MaxLength = 0; + MaxLength = 0; NumberOfLines = 0; while ((String = VA_ARG (Args, CHAR16 *)) != NULL) { MaxLength = MAX (MaxLength, UefiLibGetStringWidth (String, FALSE, 0, NULL) / 2); NumberOfLines++; } + VA_END (Args); // @@ -447,7 +440,7 @@ CreatePopUp ( // Cache a pointer to the Simple Text Output Protocol in the EFI System Table // ConOut = gST->ConOut; - + // // Save the current console cursor position and attributes // @@ -487,7 +480,7 @@ CreatePopUp ( ASSERT (Line != NULL); // - // Draw top of popup box + // Draw top of popup box // SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL); Line[0] = BOXDRAW_DOWN_RIGHT; @@ -519,13 +512,19 @@ CreatePopUp ( // Length > MaxLength // UefiLibGetStringWidth (String, TRUE, MaxLength, &Length); - String[Length] = L'\0'; + TmpString = AllocateZeroPool ((Length + 1) * sizeof (CHAR16)); + ASSERT (TmpString != NULL); + StrnCpyS (TmpString, Length + 1, String, Length - 3); + StrCatS (TmpString, Length + 1, L"..."); ConOut->SetCursorPosition (ConOut, Column + 1, Row++); - ConOut->OutputString (ConOut, String); + ConOut->OutputString (ConOut, TmpString); + FreePool (TmpString); } + NumberOfLines--; } + VA_END (Args); // @@ -546,15 +545,28 @@ CreatePopUp ( // // Restore the cursor visibility, position, and attributes // - ConOut->EnableCursor (ConOut, SavedConsoleMode.CursorVisible); + ConOut->EnableCursor (ConOut, SavedConsoleMode.CursorVisible); ConOut->SetCursorPosition (ConOut, SavedConsoleMode.CursorColumn, SavedConsoleMode.CursorRow); - ConOut->SetAttribute (ConOut, SavedConsoleMode.Attribute); + ConOut->SetAttribute (ConOut, SavedConsoleMode.Attribute); // // Wait for a keystroke // if (Key != NULL) { - gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); - gST->ConIn->ReadKeyStroke (gST->ConIn, Key); + while (TRUE) { + Status = gST->ConIn->ReadKeyStroke (gST->ConIn, Key); + if (!EFI_ERROR (Status)) { + break; + } + + // + // If we encounter error, continue to read another key in. + // + if (Status != EFI_NOT_READY) { + continue; + } + + gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); + } } }