MdeModulePkg: TerminalDxe driver code clean up

Roll back the EOL change wrongly made by last patch.
Adjust the space to align to the EDKII coding style.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12513 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
niruiyu 2011-10-08 02:44:59 +00:00
parent 02b7bcf9ce
commit 4bc6ad3935
3 changed files with 1980 additions and 1978 deletions

View File

@ -1,79 +1,79 @@
/** @file /** @file
Implementation of translation upon PC ANSI. Implementation of translation upon PC ANSI.
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR> Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License 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 which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#include "Terminal.h" #include "Terminal.h"
/** /**
Translate all raw data in the Raw FIFO into unicode, and insert Translate all raw data in the Raw FIFO into unicode, and insert
them into Unicode FIFO. them into Unicode FIFO.
@param TerminalDevice The terminal device. @param TerminalDevice The terminal device.
**/ **/
VOID VOID
AnsiRawDataToUnicode ( AnsiRawDataToUnicode (
IN TERMINAL_DEV *TerminalDevice IN TERMINAL_DEV *TerminalDevice
) )
{ {
UINT8 RawData; UINT8 RawData;
// //
// pop the raw data out from the raw fifo, // pop the raw data out from the raw fifo,
// and translate it into unicode, then push // and translate it into unicode, then push
// the unicode into unicode fifo, until the raw fifo is empty. // the unicode into unicode fifo, until the raw fifo is empty.
// //
while (!IsRawFiFoEmpty (TerminalDevice) && !IsUnicodeFiFoFull(TerminalDevice) ) { while (!IsRawFiFoEmpty (TerminalDevice) && !IsUnicodeFiFoFull (TerminalDevice)) {
RawFiFoRemoveOneKey (TerminalDevice, &RawData); RawFiFoRemoveOneKey (TerminalDevice, &RawData);
UnicodeFiFoInsertOneKey (TerminalDevice, (UINT16) RawData); UnicodeFiFoInsertOneKey (TerminalDevice, (UINT16) RawData);
} }
} }
/** /**
Check if input string is valid Ascii string, valid EFI control characters Check if input string is valid Ascii string, valid EFI control characters
or valid text graphics. or valid text graphics.
@param TerminalDevice The terminal device. @param TerminalDevice The terminal device.
@param WString The input string. @param WString The input string.
@retval EFI_UNSUPPORTED If not all input characters are valid. @retval EFI_UNSUPPORTED If not all input characters are valid.
@retval EFI_SUCCESS If all input characters are valid. @retval EFI_SUCCESS If all input characters are valid.
**/ **/
EFI_STATUS EFI_STATUS
AnsiTestString ( AnsiTestString (
IN TERMINAL_DEV *TerminalDevice, IN TERMINAL_DEV *TerminalDevice,
IN CHAR16 *WString IN CHAR16 *WString
) )
{ {
CHAR8 GraphicChar; CHAR8 GraphicChar;
// //
// support three kind of character: // support three kind of character:
// valid ascii, valid efi control char, valid text graphics. // valid ascii, valid efi control char, valid text graphics.
// //
for (; *WString != CHAR_NULL; WString++) { for (; *WString != CHAR_NULL; WString++) {
if ( !(TerminalIsValidAscii (*WString) || if ( !(TerminalIsValidAscii (*WString) ||
TerminalIsValidEfiCntlChar (*WString) || TerminalIsValidEfiCntlChar (*WString) ||
TerminalIsValidTextGraphics (*WString, &GraphicChar, NULL) )) { TerminalIsValidTextGraphics (*WString, &GraphicChar, NULL) )) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,328 +1,328 @@
/** @file /** @file
Implementation of translation upon VT-UTF8. Implementation of translation upon VT-UTF8.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License 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 which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#include "Terminal.h" #include "Terminal.h"
/** /**
Translate all VT-UTF8 characters in the Raw FIFI into unicode characters, Translate all VT-UTF8 characters in the Raw FIFI into unicode characters,
and insert them into Unicode FIFO. and insert them into Unicode FIFO.
@param TerminalDevice The terminal device. @param TerminalDevice The terminal device.
**/ **/
VOID VOID
VTUTF8RawDataToUnicode ( VTUTF8RawDataToUnicode (
IN TERMINAL_DEV *TerminalDevice IN TERMINAL_DEV *TerminalDevice
) )
{ {
UTF8_CHAR Utf8Char; UTF8_CHAR Utf8Char;
UINT8 ValidBytes; UINT8 ValidBytes;
UINT16 UnicodeChar; UINT16 UnicodeChar;
ValidBytes = 0; ValidBytes = 0;
// //
// pop the raw data out from the raw fifo, // pop the raw data out from the raw fifo,
// and translate it into unicode, then push // and translate it into unicode, then push
// the unicode into unicode fifo, until the raw fifo is empty. // the unicode into unicode fifo, until the raw fifo is empty.
// //
while (!IsRawFiFoEmpty (TerminalDevice) && !IsUnicodeFiFoFull(TerminalDevice) ) { while (!IsRawFiFoEmpty (TerminalDevice) && !IsUnicodeFiFoFull (TerminalDevice)) {
GetOneValidUtf8Char (TerminalDevice, &Utf8Char, &ValidBytes); GetOneValidUtf8Char (TerminalDevice, &Utf8Char, &ValidBytes);
if (ValidBytes < 1 || ValidBytes > 3) { if (ValidBytes < 1 || ValidBytes > 3) {
continue; continue;
} }
Utf8ToUnicode (Utf8Char, ValidBytes, (CHAR16 *) &UnicodeChar); Utf8ToUnicode (Utf8Char, ValidBytes, (CHAR16 *) &UnicodeChar);
UnicodeFiFoInsertOneKey (TerminalDevice, UnicodeChar); UnicodeFiFoInsertOneKey (TerminalDevice, UnicodeChar);
} }
} }
/** /**
Get one valid VT-UTF8 characters set from Raw Data FIFO. Get one valid VT-UTF8 characters set from Raw Data FIFO.
@param Utf8Device The terminal device. @param Utf8Device The terminal device.
@param Utf8Char Returned valid VT-UTF8 characters set. @param Utf8Char Returned valid VT-UTF8 characters set.
@param ValidBytes The count of returned VT-VTF8 characters. @param ValidBytes The count of returned VT-VTF8 characters.
If ValidBytes is zero, no valid VT-UTF8 returned. If ValidBytes is zero, no valid VT-UTF8 returned.
**/ **/
VOID VOID
GetOneValidUtf8Char ( GetOneValidUtf8Char (
IN TERMINAL_DEV *Utf8Device, IN TERMINAL_DEV *Utf8Device,
OUT UTF8_CHAR *Utf8Char, OUT UTF8_CHAR *Utf8Char,
OUT UINT8 *ValidBytes OUT UINT8 *ValidBytes
) )
{ {
UINT8 Temp; UINT8 Temp;
UINT8 Index; UINT8 Index;
BOOLEAN FetchFlag; BOOLEAN FetchFlag;
Temp = 0; Temp = 0;
Index = 0; Index = 0;
FetchFlag = TRUE; FetchFlag = TRUE;
// //
// if no valid Utf8 char is found in the RawFiFo, // if no valid Utf8 char is found in the RawFiFo,
// then *ValidBytes will be zero. // then *ValidBytes will be zero.
// //
*ValidBytes = 0; *ValidBytes = 0;
while (!IsRawFiFoEmpty (Utf8Device)) { while (!IsRawFiFoEmpty (Utf8Device)) {
RawFiFoRemoveOneKey (Utf8Device, &Temp); RawFiFoRemoveOneKey (Utf8Device, &Temp);
switch (*ValidBytes) { switch (*ValidBytes) {
case 0: case 0:
if ((Temp & 0x80) == 0) { if ((Temp & 0x80) == 0) {
// //
// one-byte utf8 char // one-byte utf8 char
// //
*ValidBytes = 1; *ValidBytes = 1;
Utf8Char->Utf8_1 = Temp; Utf8Char->Utf8_1 = Temp;
FetchFlag = FALSE; FetchFlag = FALSE;
} else if ((Temp & 0xe0) == 0xc0) { } else if ((Temp & 0xe0) == 0xc0) {
// //
// two-byte utf8 char // two-byte utf8 char
// //
*ValidBytes = 2; *ValidBytes = 2;
Utf8Char->Utf8_2[1] = Temp; Utf8Char->Utf8_2[1] = Temp;
} else if ((Temp & 0xf0) == 0xe0) { } else if ((Temp & 0xf0) == 0xe0) {
// //
// three-byte utf8 char // three-byte utf8 char
// //
*ValidBytes = 3; *ValidBytes = 3;
Utf8Char->Utf8_3[2] = Temp; Utf8Char->Utf8_3[2] = Temp;
Index++; Index++;
} else { } else {
// //
// reset *ValidBytes to zero, let valid utf8 char search restart // reset *ValidBytes to zero, let valid utf8 char search restart
// //
*ValidBytes = 0; *ValidBytes = 0;
} }
break; break;
case 2: case 2:
// //
// two-byte utf8 char go on // two-byte utf8 char go on
// //
if ((Temp & 0xc0) == 0x80) { if ((Temp & 0xc0) == 0x80) {
Utf8Char->Utf8_2[0] = Temp; Utf8Char->Utf8_2[0] = Temp;
FetchFlag = FALSE; FetchFlag = FALSE;
} else { } else {
*ValidBytes = 0; *ValidBytes = 0;
} }
break; break;
case 3: case 3:
// //
// three-byte utf8 char go on // three-byte utf8 char go on
// //
if ((Temp & 0xc0) == 0x80) { if ((Temp & 0xc0) == 0x80) {
if (Index == 1) { if (Index == 1) {
Utf8Char->Utf8_3[1] = Temp; Utf8Char->Utf8_3[1] = Temp;
Index++; Index++;
} else { } else {
Utf8Char->Utf8_3[0] = Temp; Utf8Char->Utf8_3[0] = Temp;
FetchFlag = FALSE; FetchFlag = FALSE;
} }
} else { } else {
// //
// reset *ValidBytes and Index to zero, let valid utf8 char search restart // reset *ValidBytes and Index to zero, let valid utf8 char search restart
// //
*ValidBytes = 0; *ValidBytes = 0;
Index = 0; Index = 0;
} }
break; break;
default: default:
break; break;
} }
if (!FetchFlag) { if (!FetchFlag) {
break; break;
} }
} }
return ; return ;
} }
/** /**
Translate VT-UTF8 characters into one Unicode character. Translate VT-UTF8 characters into one Unicode character.
UTF8 Encoding Table UTF8 Encoding Table
Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
@param Utf8Char VT-UTF8 character set needs translating. @param Utf8Char VT-UTF8 character set needs translating.
@param ValidBytes The count of valid VT-UTF8 characters. @param ValidBytes The count of valid VT-UTF8 characters.
@param UnicodeChar Returned unicode character. @param UnicodeChar Returned unicode character.
**/ **/
VOID VOID
Utf8ToUnicode ( Utf8ToUnicode (
IN UTF8_CHAR Utf8Char, IN UTF8_CHAR Utf8Char,
IN UINT8 ValidBytes, IN UINT8 ValidBytes,
OUT CHAR16 *UnicodeChar OUT CHAR16 *UnicodeChar
) )
{ {
UINT8 UnicodeByte0; UINT8 UnicodeByte0;
UINT8 UnicodeByte1; UINT8 UnicodeByte1;
UINT8 Byte0; UINT8 Byte0;
UINT8 Byte1; UINT8 Byte1;
UINT8 Byte2; UINT8 Byte2;
*UnicodeChar = 0; *UnicodeChar = 0;
// //
// translate utf8 code to unicode, in terminal standard, // translate utf8 code to unicode, in terminal standard,
// up to 3 bytes utf8 code is supported. // up to 3 bytes utf8 code is supported.
// //
switch (ValidBytes) { switch (ValidBytes) {
case 1: case 1:
// //
// one-byte utf8 code // one-byte utf8 code
// //
*UnicodeChar = (UINT16) Utf8Char.Utf8_1; *UnicodeChar = (UINT16) Utf8Char.Utf8_1;
break; break;
case 2: case 2:
// //
// two-byte utf8 code // two-byte utf8 code
// //
Byte0 = Utf8Char.Utf8_2[0]; Byte0 = Utf8Char.Utf8_2[0];
Byte1 = Utf8Char.Utf8_2[1]; Byte1 = Utf8Char.Utf8_2[1];
UnicodeByte0 = (UINT8) ((Byte1 << 6) | (Byte0 & 0x3f)); UnicodeByte0 = (UINT8) ((Byte1 << 6) | (Byte0 & 0x3f));
UnicodeByte1 = (UINT8) ((Byte1 >> 2) & 0x07); UnicodeByte1 = (UINT8) ((Byte1 >> 2) & 0x07);
*UnicodeChar = (UINT16) (UnicodeByte0 | (UnicodeByte1 << 8)); *UnicodeChar = (UINT16) (UnicodeByte0 | (UnicodeByte1 << 8));
break; break;
case 3: case 3:
// //
// three-byte utf8 code // three-byte utf8 code
// //
Byte0 = Utf8Char.Utf8_3[0]; Byte0 = Utf8Char.Utf8_3[0];
Byte1 = Utf8Char.Utf8_3[1]; Byte1 = Utf8Char.Utf8_3[1];
Byte2 = Utf8Char.Utf8_3[2]; Byte2 = Utf8Char.Utf8_3[2];
UnicodeByte0 = (UINT8) ((Byte1 << 6) | (Byte0 & 0x3f)); UnicodeByte0 = (UINT8) ((Byte1 << 6) | (Byte0 & 0x3f));
UnicodeByte1 = (UINT8) ((Byte2 << 4) | ((Byte1 >> 2) & 0x0f)); UnicodeByte1 = (UINT8) ((Byte2 << 4) | ((Byte1 >> 2) & 0x0f));
*UnicodeChar = (UINT16) (UnicodeByte0 | (UnicodeByte1 << 8)); *UnicodeChar = (UINT16) (UnicodeByte0 | (UnicodeByte1 << 8));
default: default:
break; break;
} }
return ; return ;
} }
/** /**
Translate one Unicode character into VT-UTF8 characters. Translate one Unicode character into VT-UTF8 characters.
UTF8 Encoding Table UTF8 Encoding Table
Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
@param Unicode Unicode character need translating. @param Unicode Unicode character need translating.
@param Utf8Char Return VT-UTF8 character set. @param Utf8Char Return VT-UTF8 character set.
@param ValidBytes The count of valid VT-UTF8 characters. If @param ValidBytes The count of valid VT-UTF8 characters. If
ValidBytes is zero, no valid VT-UTF8 returned. ValidBytes is zero, no valid VT-UTF8 returned.
**/ **/
VOID VOID
UnicodeToUtf8 ( UnicodeToUtf8 (
IN CHAR16 Unicode, IN CHAR16 Unicode,
OUT UTF8_CHAR *Utf8Char, OUT UTF8_CHAR *Utf8Char,
OUT UINT8 *ValidBytes OUT UINT8 *ValidBytes
) )
{ {
UINT8 UnicodeByte0; UINT8 UnicodeByte0;
UINT8 UnicodeByte1; UINT8 UnicodeByte1;
// //
// translate unicode to utf8 code // translate unicode to utf8 code
// //
UnicodeByte0 = (UINT8) Unicode; UnicodeByte0 = (UINT8) Unicode;
UnicodeByte1 = (UINT8) (Unicode >> 8); UnicodeByte1 = (UINT8) (Unicode >> 8);
if (Unicode < 0x0080) { if (Unicode < 0x0080) {
Utf8Char->Utf8_1 = (UINT8) (UnicodeByte0 & 0x7f); Utf8Char->Utf8_1 = (UINT8) (UnicodeByte0 & 0x7f);
*ValidBytes = 1; *ValidBytes = 1;
} else if (Unicode < 0x0800) { } else if (Unicode < 0x0800) {
// //
// byte sequence: high -> low // byte sequence: high -> low
// Utf8_2[0], Utf8_2[1] // Utf8_2[0], Utf8_2[1]
// //
Utf8Char->Utf8_2[1] = (UINT8) ((UnicodeByte0 & 0x3f) + 0x80); Utf8Char->Utf8_2[1] = (UINT8) ((UnicodeByte0 & 0x3f) + 0x80);
Utf8Char->Utf8_2[0] = (UINT8) ((((UnicodeByte1 << 2) + (UnicodeByte0 >> 6)) & 0x1f) + 0xc0); Utf8Char->Utf8_2[0] = (UINT8) ((((UnicodeByte1 << 2) + (UnicodeByte0 >> 6)) & 0x1f) + 0xc0);
*ValidBytes = 2; *ValidBytes = 2;
} else { } else {
// //
// byte sequence: high -> low // byte sequence: high -> low
// Utf8_3[0], Utf8_3[1], Utf8_3[2] // Utf8_3[0], Utf8_3[1], Utf8_3[2]
// //
Utf8Char->Utf8_3[2] = (UINT8) ((UnicodeByte0 & 0x3f) + 0x80); Utf8Char->Utf8_3[2] = (UINT8) ((UnicodeByte0 & 0x3f) + 0x80);
Utf8Char->Utf8_3[1] = (UINT8) ((((UnicodeByte1 << 2) + (UnicodeByte0 >> 6)) & 0x3f) + 0x80); Utf8Char->Utf8_3[1] = (UINT8) ((((UnicodeByte1 << 2) + (UnicodeByte0 >> 6)) & 0x3f) + 0x80);
Utf8Char->Utf8_3[0] = (UINT8) (((UnicodeByte1 >> 4) & 0x0f) + 0xe0); Utf8Char->Utf8_3[0] = (UINT8) (((UnicodeByte1 >> 4) & 0x0f) + 0xe0);
*ValidBytes = 3; *ValidBytes = 3;
} }
} }
/** /**
Check if input string is valid VT-UTF8 string. Check if input string is valid VT-UTF8 string.
@param TerminalDevice The terminal device. @param TerminalDevice The terminal device.
@param WString The input string. @param WString The input string.
@retval EFI_SUCCESS If all input characters are valid. @retval EFI_SUCCESS If all input characters are valid.
**/ **/
EFI_STATUS EFI_STATUS
VTUTF8TestString ( VTUTF8TestString (
IN TERMINAL_DEV *TerminalDevice, IN TERMINAL_DEV *TerminalDevice,
IN CHAR16 *WString IN CHAR16 *WString
) )
{ {
// //
// to utf8, all kind of characters are supported. // to utf8, all kind of characters are supported.
// //
return EFI_SUCCESS; return EFI_SUCCESS;
} }