diff options
author | oliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-09-09 10:49:54 +0000 |
---|---|---|
committer | oliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-09-09 10:49:54 +0000 |
commit | 74b961324c1cc3ae3f97523e085fb169ec63b608 (patch) | |
tree | 80aeaf152679289f0fa3cc5ceabfdc164c1e11cb /ArmPlatformPkg/Bds/BdsHelper.c | |
parent | c3cd46d421cef32077ae6caf860b50d00ba2aa7f (diff) | |
download | edk2-platforms-74b961324c1cc3ae3f97523e085fb169ec63b608.tar.xz |
ArmPlatformPkg/Bds: Get User inputs in Unicode
The user input was getting in Ascii and converted later to Unicode
when required.
In this change, the user inputs are caught in Unicode and converted
to Ascii only when needed.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12310 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ArmPlatformPkg/Bds/BdsHelper.c')
-rw-r--r-- | ArmPlatformPkg/Bds/BdsHelper.c | 90 |
1 files changed, 64 insertions, 26 deletions
diff --git a/ArmPlatformPkg/Bds/BdsHelper.c b/ArmPlatformPkg/Bds/BdsHelper.c index 2f0cb31d39..0a6961183a 100644 --- a/ArmPlatformPkg/Bds/BdsHelper.c +++ b/ArmPlatformPkg/Bds/BdsHelper.c @@ -68,8 +68,8 @@ GetEnvironmentVariable ( } EFI_STATUS -EditHIInputAscii ( - IN OUT CHAR8 *CmdLine, +EditHIInputStr ( + IN OUT CHAR16 *CmdLine, IN UINTN MaxCmdLine ) { @@ -79,9 +79,9 @@ EditHIInputAscii ( EFI_INPUT_KEY Key; EFI_STATUS Status; - AsciiPrint (CmdLine); + Print (CmdLine); - for (CmdLineIndex = AsciiStrLen(CmdLine); CmdLineIndex < MaxCmdLine; ) { + for (CmdLineIndex = StrLen (CmdLine); CmdLineIndex < MaxCmdLine; ) { Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &WaitIndex); ASSERT_EFI_ERROR (Status); @@ -98,19 +98,19 @@ EditHIInputAscii ( if ((Char == CHAR_LINEFEED) || (Char == CHAR_CARRIAGE_RETURN) || (Char == 0x7f)) { CmdLine[CmdLineIndex] = '\0'; - AsciiPrint ("\n\r"); + Print (L"\n\r"); return EFI_SUCCESS; - } else if ((Char == '\b') || (Key.ScanCode == SCAN_LEFT) || (Key.ScanCode == SCAN_DELETE)){ + } else if ((Key.UnicodeChar == L'\b') || (Key.ScanCode == SCAN_LEFT) || (Key.ScanCode == SCAN_DELETE)){ if (CmdLineIndex != 0) { CmdLineIndex--; - AsciiPrint ("\b \b"); + Print (L"\b \b"); } } else if ((Key.ScanCode == SCAN_ESC) || (Char == 0x1B) || (Char == 0x0)) { return EFI_INVALID_PARAMETER; } else { - CmdLine[CmdLineIndex++] = Char; - AsciiPrint ("%c", Char); + CmdLine[CmdLineIndex++] = Key.UnicodeChar; + Print (L"%c", Key.UnicodeChar); } } @@ -118,6 +118,44 @@ EditHIInputAscii ( } EFI_STATUS +GetHIInputStr ( + IN OUT CHAR16 *CmdLine, + IN UINTN MaxCmdLine + ) +{ + EFI_STATUS Status; + + // For a new input just passed an empty string + CmdLine[0] = L'\0'; + + Status = EditHIInputStr (CmdLine, MaxCmdLine); + + return Status; +} + +EFI_STATUS +EditHIInputAscii ( + IN OUT CHAR8 *CmdLine, + IN UINTN MaxCmdLine + ) +{ + CHAR16* Str; + EFI_STATUS Status; + + Str = (CHAR16*)AllocatePool (MaxCmdLine * sizeof(CHAR16)); + AsciiStrToUnicodeStr (CmdLine, Str); + + Status = EditHIInputStr (Str, MaxCmdLine); + + if (!EFI_ERROR(Status)) { + UnicodeStrToAsciiStr (Str, CmdLine); + } + FreePool (Str); + + return Status; +} + +EFI_STATUS GetHIInputAscii ( IN OUT CHAR8 *CmdLine, IN UINTN MaxCmdLine @@ -134,13 +172,13 @@ GetHIInputInteger ( OUT UINTN *Integer ) { - CHAR8 CmdLine[255]; + CHAR16 CmdLine[255]; EFI_STATUS Status; CmdLine[0] = '\0'; - Status = EditHIInputAscii (CmdLine,255); + Status = EditHIInputStr (CmdLine, 255); if (!EFI_ERROR(Status)) { - *Integer = AsciiStrDecimalToUintn (CmdLine); + *Integer = StrDecimalToUintn (CmdLine); } return Status; @@ -151,36 +189,36 @@ GetHIInputIP ( OUT EFI_IP_ADDRESS *Ip ) { - CHAR8 CmdLine[255]; - CHAR8 *Str; + CHAR16 CmdLine[255]; + CHAR16 *Str; EFI_STATUS Status; CmdLine[0] = '\0'; - Status = EditHIInputAscii (CmdLine,255); + Status = EditHIInputStr (CmdLine,255); if (!EFI_ERROR(Status)) { Str = CmdLine; - Ip->v4.Addr[0] = (UINT8)AsciiStrDecimalToUintn (Str); + Ip->v4.Addr[0] = (UINT8)StrDecimalToUintn (Str); - Str = AsciiStrStr (Str, "."); + Str = StrStr (Str, L"."); if (Str == NULL) { return EFI_INVALID_PARAMETER; } - Ip->v4.Addr[1] = (UINT8)AsciiStrDecimalToUintn (++Str); + Ip->v4.Addr[1] = (UINT8)StrDecimalToUintn (++Str); - Str = AsciiStrStr (Str, "."); + Str = StrStr (Str, L"."); if (Str == NULL) { return EFI_INVALID_PARAMETER; } - Ip->v4.Addr[2] = (UINT8)AsciiStrDecimalToUintn (++Str); + Ip->v4.Addr[2] = (UINT8)StrDecimalToUintn (++Str); - Str = AsciiStrStr (Str, "."); + Str = StrStr (Str, L"."); if (Str == NULL) { return EFI_INVALID_PARAMETER; } - Ip->v4.Addr[3] = (UINT8)AsciiStrDecimalToUintn (++Str); + Ip->v4.Addr[3] = (UINT8)StrDecimalToUintn (++Str); } return Status; @@ -191,18 +229,18 @@ GetHIInputBoolean ( OUT BOOLEAN *Value ) { - CHAR8 CmdBoolean[2]; + CHAR16 CmdBoolean[2]; EFI_STATUS Status; while(1) { Print (L"[y/n] "); - Status = GetHIInputAscii (CmdBoolean,2); + Status = GetHIInputStr (CmdBoolean,2); if (EFI_ERROR(Status)) { return Status; - } else if ((CmdBoolean[0] == 'y') || (CmdBoolean[0] == 'Y')) { + } else if ((CmdBoolean[0] == L'y') || (CmdBoolean[0] == L'Y')) { if (Value) *Value = TRUE; return EFI_SUCCESS; - } else if ((CmdBoolean[0] == 'n') || (CmdBoolean[0] == 'N')) { + } else if ((CmdBoolean[0] == L'n') || (CmdBoolean[0] == L'N')) { if (Value) *Value = FALSE; return EFI_SUCCESS; } |