X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellDebug1CommandsLib%2FUefiShellDebug1CommandsLib.c;h=c3682eeae476145f00f21f04239d9d2a1a9f877b;hb=HEAD;hp=226dd903971a794e43309e80ddfeb352ddd1b68f;hpb=3737ac2bc3c2e6589d88be97345d641ea2006933;p=mirror_edk2.git
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
index 226dd90397..c3682eeae4 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
@@ -1,25 +1,16 @@
/** @file
Main file for NULL named library for debug1 profile shell command functions.
- Copyright (c) 2010 - 2011, 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) 2010 - 2018, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "UefiShellDebug1CommandsLib.h"
+#include
-STATIC CONST CHAR16 mFileName[] = L"Debug1Commands";
-EFI_HANDLE gShellDebug1HiiHandle = NULL;
-CONST EFI_GUID gShellDebug1HiiGuid = \
- { \
- 0x25f200aa, 0xd3cb, 0x470a, { 0xbf, 0x51, 0xe7, 0xd1, 0x62, 0xd2, 0x2e, 0x6f } \
- };
+STATIC CONST CHAR16 mFileName[] = L"Debug1Commands";
+EFI_HII_HANDLE gShellDebug1HiiHandle = NULL;
/**
Gets the debug file name. This will be used if HII is not working.
@@ -27,7 +18,7 @@ CONST EFI_GUID gShellDebug1HiiGuid = \
@retval NULL No file is available.
@return The NULL-terminated filename to get help from.
**/
-CONST CHAR16*
+CONST CHAR16 *
EFIAPI
ShellCommandGetManFileNameDebug1 (
VOID
@@ -55,8 +46,8 @@ UefiShellDebug1CommandsLibConstructor (
//
// check our bit of the profiles mask
//
- if ((PcdGet8(PcdShellProfileMask) & BIT1) == 0) {
- return (EFI_UNSUPPORTED);
+ if ((PcdGet8 (PcdShellProfileMask) & BIT1) == 0) {
+ return (EFI_SUCCESS);
}
//
@@ -70,35 +61,27 @@ UefiShellDebug1CommandsLibConstructor (
//
// install our shell command handlers that are always installed
//
- ShellCommandRegisterCommandName(L"setsize", ShellCommandRunSetSize , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SETSIZE) );
- ShellCommandRegisterCommandName(L"comp", ShellCommandRunComp , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_COMP) );
- ShellCommandRegisterCommandName(L"mode", ShellCommandRunMode , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_MODE) );
- ShellCommandRegisterCommandName(L"memmap", ShellCommandRunMemMap , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_MEMMAP) );
- ShellCommandRegisterCommandName(L"eficompress", ShellCommandRunEfiCompress , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EFICOMPRESS) );
- ShellCommandRegisterCommandName(L"efidecompress", ShellCommandRunEfiDecompress , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EFIDCOMPRESS) );
- ShellCommandRegisterCommandName(L"dmem", ShellCommandRunDmem , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_DMEM) );
- ShellCommandRegisterCommandName(L"loadpcirom", ShellCommandRunLoadPciRom , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_LOAD_PCI_ROM) );
- ShellCommandRegisterCommandName(L"mm", ShellCommandRunMm , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_MM) );
- ShellCommandRegisterCommandName(L"setvar", ShellCommandRunSetVar , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SETVAR) );
- ShellCommandRegisterCommandName(L"sermode", ShellCommandRunSerMode , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SERMODE) );
- ShellCommandRegisterCommandName(L"pci", ShellCommandRunPci , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_PCI) );
- ShellCommandRegisterCommandName(L"smbiosview", ShellCommandRunSmbiosView , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SMBIOSVIEW) );
- ShellCommandRegisterCommandName(L"dmpstore", ShellCommandRunDmpStore , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_DMPSTORE) );
- ShellCommandRegisterCommandName(L"dblk", ShellCommandRunDblk , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_DBLK) );
- ShellCommandRegisterCommandName(L"edit", ShellCommandRunEdit , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EDIT) );
- ShellCommandRegisterCommandName(L"hexedit", ShellCommandRunHexEdit , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_HEXEDIT) );
-
- //
- // check install profile bit of the profiles mask is set
- //
- if ((PcdGet8(PcdShellProfileMask) & BIT2) == 0) {
- ShellCommandRegisterCommandName(L"bcfg", ShellCommandRunBcfg , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_BCFG) );
- }
-
-
-
-
- ShellCommandRegisterAlias(L"dmem", L"mem");
+ ShellCommandRegisterCommandName (L"setsize", ShellCommandRunSetSize, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_SETSIZE));
+ ShellCommandRegisterCommandName (L"comp", ShellCommandRunComp, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_COMP));
+ ShellCommandRegisterCommandName (L"mode", ShellCommandRunMode, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_MODE));
+ ShellCommandRegisterCommandName (L"memmap", ShellCommandRunMemMap, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_MEMMAP));
+ ShellCommandRegisterCommandName (L"eficompress", ShellCommandRunEfiCompress, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_EFICOMPRESS));
+ ShellCommandRegisterCommandName (L"efidecompress", ShellCommandRunEfiDecompress, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_EFIDCOMPRESS));
+ ShellCommandRegisterCommandName (L"dmem", ShellCommandRunDmem, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_DMEM));
+ ShellCommandRegisterCommandName (L"loadpcirom", ShellCommandRunLoadPciRom, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_LOAD_PCI_ROM));
+ ShellCommandRegisterCommandName (L"mm", ShellCommandRunMm, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_MM));
+ ShellCommandRegisterCommandName (L"setvar", ShellCommandRunSetVar, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_SETVAR));
+ ShellCommandRegisterCommandName (L"sermode", ShellCommandRunSerMode, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_SERMODE));
+ ShellCommandRegisterCommandName (L"pci", ShellCommandRunPci, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_PCI));
+ ShellCommandRegisterCommandName (L"smbiosview", ShellCommandRunSmbiosView, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_SMBIOSVIEW));
+ ShellCommandRegisterCommandName (L"dmpstore", ShellCommandRunDmpStore, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_DMPSTORE));
+ ShellCommandRegisterCommandName (L"dblk", ShellCommandRunDblk, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_DBLK));
+ ShellCommandRegisterCommandName (L"edit", ShellCommandRunEdit, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_EDIT));
+ ShellCommandRegisterCommandName (L"hexedit", ShellCommandRunHexEdit, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_HEXEDIT));
+
+ ShellCommandRegisterAlias (L"dmem", L"mem");
+
+ BcfgLibraryRegisterBcfgCommand (ImageHandle, SystemTable, L"Debug1");
return (EFI_SUCCESS);
}
@@ -117,130 +100,31 @@ UefiShellDebug1CommandsLibDestructor (
)
{
if (gShellDebug1HiiHandle != NULL) {
- HiiRemovePackages(gShellDebug1HiiHandle);
+ HiiRemovePackages (gShellDebug1HiiHandle);
}
- return (EFI_SUCCESS);
-}
-
-STATIC CONST CHAR8 Hex[] = {
- '0',
- '1',
- '2',
- '3',
- '4',
- '5',
- '6',
- '7',
- '8',
- '9',
- 'A',
- 'B',
- 'C',
- 'D',
- 'E',
- 'F'
-};
-
-/**
- Dump some hexadecimal data to the screen.
-
- @param[in] Indent How many spaces to indent the output.
- @param[in] Offset The offset of the printing.
- @param[in] DataSize The size in bytes of UserData.
- @param[in] UserData The data to print out.
-**/
-VOID
-EFIAPI
-DumpHex (
- IN UINTN Indent,
- IN UINTN Offset,
- IN UINTN DataSize,
- IN VOID *UserData
- )
-{
- UINT8 *Data;
-
- CHAR8 Val[50];
-
- CHAR8 Str[20];
-
- UINT8 TempByte;
- UINTN Size;
- UINTN Index;
-
- Data = UserData;
- while (DataSize != 0) {
- Size = 16;
- if (Size > DataSize) {
- Size = DataSize;
- }
-
- for (Index = 0; Index < Size; Index += 1) {
- TempByte = Data[Index];
- Val[Index * 3 + 0] = Hex[TempByte >> 4];
- Val[Index * 3 + 1] = Hex[TempByte & 0xF];
- Val[Index * 3 + 2] = (CHAR8) ((Index == 7) ? '-' : ' ');
- Str[Index] = (CHAR8) ((TempByte < ' ' || TempByte > 'z') ? '.' : TempByte);
- }
-
- Val[Index * 3] = 0;
- Str[Index] = 0;
- ShellPrintEx(-1, -1, L"%*a%02X: %-.48a *%a*\r\n", Indent, "", Offset, Val, Str);
- Data += Size;
- Offset += Size;
- DataSize -= Size;
- }
-}
-
-/**
- Convert a Unicode character to upper case only if
- it maps to a valid small-case ASCII character.
-
- This internal function only deal with Unicode character
- which maps to a valid small-case ASCII character, i.e.
- L'a' to L'z'. For other Unicode character, the input character
- is returned directly.
-
- @param Char The character to convert.
-
- @retval LowerCharacter If the Char is with range L'a' to L'z'.
- @retval Unchanged Otherwise.
-
-
- //Stolen from MdePkg Baselib
-**/
-CHAR16
-EFIAPI
-CharToUpper (
- IN CHAR16 Char
- )
-{
- if (Char >= L'a' && Char <= L'z') {
- return (CHAR16) (Char - (L'a' - L'A'));
- }
-
- return Char;
+ BcfgLibraryUnregisterBcfgCommand (ImageHandle, SystemTable);
+ return (EFI_SUCCESS);
}
/**
Function returns a system configuration table that is stored in the
EFI System Table based on the provided GUID.
- @param[in] TableGuid A pointer to the table's GUID type.
- @param[in,out] Table On exit, a pointer to a system configuration table.
+ @param[in] TableGuid A pointer to the table's GUID type.
+ @param[in, out] Table On exit, a pointer to a system configuration table.
@retval EFI_SUCCESS A configuration table matching TableGuid was found.
@retval EFI_NOT_FOUND A configuration table matching TableGuid was not found.
**/
EFI_STATUS
-EFIAPI
GetSystemConfigurationTable (
- IN EFI_GUID *TableGuid,
- IN OUT VOID **Table
+ IN EFI_GUID *TableGuid,
+ IN OUT VOID **Table
)
{
- UINTN Index;
+ UINTN Index;
+
ASSERT (Table != NULL);
for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {
@@ -253,178 +137,22 @@ GetSystemConfigurationTable (
return EFI_NOT_FOUND;
}
-/**
- Convert a Unicode character to numerical value.
-
- This internal function only deal with Unicode character
- which maps to a valid hexadecimal ASII character, i.e.
- L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other
- Unicode character, the value returned does not make sense.
-
- @param Char The character to convert.
-
- @return The numerical value converted.
-
-**/
-UINTN
-EFIAPI
-HexCharToUintn (
- IN CHAR16 Char
- )
-{
- if (Char >= L'0' && Char <= L'9') {
- return Char - L'0';
- }
-
- return (UINTN) (10 + CharToUpper (Char) - L'A');
-}
-
-/**
- Convert a string representation of a guid to a Guid value.
-
- @param[in] StringGuid The pointer to the string of a guid.
- @param[in,out] Guid The pointer to the GUID structure to populate.
-
- @retval EFI_INVALID_PARAMETER A parameter was invalid.
- @retval EFI_SUCCESS The conversion was successful.
-**/
-EFI_STATUS
-EFIAPI
-ConvertStringToGuid (
- IN CONST CHAR16 *StringGuid,
- IN OUT EFI_GUID *Guid
- )
-{
- CHAR16 *TempCopy;
- CHAR16 *TempSpot;
- CHAR16 *Walker;
- UINT64 TempVal;
- EFI_STATUS Status;
-
- if (StringGuid == NULL) {
- return (EFI_INVALID_PARAMETER);
- } else if (StrLen(StringGuid) != 36) {
- return (EFI_INVALID_PARAMETER);
- }
- TempCopy = NULL;
- TempCopy = StrnCatGrow(&TempCopy, NULL, StringGuid, 0);
- Walker = TempCopy;
- TempSpot = StrStr(Walker, L"-");
- *TempSpot = CHAR_NULL;
- Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);
- if (EFI_ERROR(Status)) {
- FreePool(TempCopy);
- return (Status);
- }
- Guid->Data1 = (UINT32)TempVal;
- Walker += 9;
- TempSpot = StrStr(Walker, L"-");
- *TempSpot = CHAR_NULL;
- Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);
- if (EFI_ERROR(Status)) {
- FreePool(TempCopy);
- return (Status);
- }
- Guid->Data2 = (UINT16)TempVal;
- Walker += 5;
- TempSpot = StrStr(Walker, L"-");
- *TempSpot = CHAR_NULL;
- Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);
- if (EFI_ERROR(Status)) {
- FreePool(TempCopy);
- return (Status);
- }
- Guid->Data3 = (UINT16)TempVal;
- Walker += 5;
- Guid->Data4[0] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
- Guid->Data4[0] = (UINT8)(Guid->Data4[0]+ (UINT8)HexCharToUintn(Walker[1]));
- Walker += 2;
- Guid->Data4[1] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
- Guid->Data4[1] = (UINT8)(Guid->Data4[1] + (UINT8)HexCharToUintn(Walker[1]));
- Walker += 3;
- Guid->Data4[2] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
- Guid->Data4[2] = (UINT8)(Guid->Data4[2] + (UINT8)HexCharToUintn(Walker[1]));
- Walker += 2;
- Guid->Data4[3] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
- Guid->Data4[3] = (UINT8)(Guid->Data4[3] + (UINT8)HexCharToUintn(Walker[1]));
- Walker += 2;
- Guid->Data4[4] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
- Guid->Data4[4] = (UINT8)(Guid->Data4[4] + (UINT8)HexCharToUintn(Walker[1]));
- Walker += 2;
- Guid->Data4[5] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
- Guid->Data4[5] = (UINT8)(Guid->Data4[5] + (UINT8)HexCharToUintn(Walker[1]));
- Walker += 2;
- Guid->Data4[6] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
- Guid->Data4[6] = (UINT8)(Guid->Data4[6] + (UINT8)HexCharToUintn(Walker[1]));
- Walker += 2;
- Guid->Data4[7] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
- Guid->Data4[7] = (UINT8)(Guid->Data4[7] + (UINT8)HexCharToUintn(Walker[1]));
- FreePool(TempCopy);
- return (EFI_SUCCESS);
-}
-
-CHAR16 TempBufferCatSPrint[1000];
-/**
- Appends a formatted Unicode string to a Null-terminated Unicode string
-
- This function appends a formatted Unicode string to the Null-terminated
- Unicode string specified by String. String is optional and may be NULL.
- Storage for the formatted Unicode string returned is allocated using
- AllocateZeroPool(). The pointer to the appended string is returned. The caller
- is responsible for freeing the returned string.
-
- If String is not NULL and not aligned on a 16-bit boundary, then ASSERT().
- If Format is NULL, then ASSERT().
- If Format is not aligned on a 16-bit boundary, then ASSERT().
-
- @param String A null-terminated Unicode string.
- @param FormatString A null-terminated Unicode format string.
- @param ... The variable argument list whose contents are accessed based
- on the format string specified by Format.
-
- @retval NULL There was not enough available memory.
- @return Null terminated Unicode string is that is the formatted
- string appended to String.
- @sa CatVSPrint
-**/
-CHAR16*
-EFIAPI
-CatSPrint (
- IN CONST CHAR16 *String OPTIONAL,
- IN CONST CHAR16 *FormatString,
- ...
- )
-{
- VA_LIST Marker;
- UINTN StringLength;
- if (String != NULL) {
- StrCpy(TempBufferCatSPrint, String);
- } else {
- *TempBufferCatSPrint = CHAR_NULL;
- }
- VA_START (Marker, FormatString);
- StringLength = StrLen(TempBufferCatSPrint);
-
- UnicodeVSPrint(TempBufferCatSPrint+StrLen(TempBufferCatSPrint), 1000-StringLength, FormatString, Marker);
- return (AllocateCopyPool(StrSize(TempBufferCatSPrint), TempBufferCatSPrint));
-}
-
/**
Clear the line at the specified Row.
-
+
@param[in] Row The row number to be cleared ( start from 1 )
@param[in] LastCol The last printable column.
@param[in] LastRow The last printable row.
**/
VOID
-EFIAPI
EditorClearLine (
- IN UINTN Row,
- IN UINTN LastCol,
- IN UINTN LastRow
+ IN UINTN Row,
+ IN UINTN LastCol,
+ IN UINTN LastRow
)
{
- CHAR16 Line[200];
+ UINTN Col;
+ CHAR16 Line[200];
if (Row == 0) {
Row = 1;
@@ -432,22 +160,28 @@ EditorClearLine (
//
// prepare a blank line
+ // If max column is larger, split to multiple prints.
//
- SetMem16(Line, LastCol*sizeof(CHAR16), L' ');
+ SetMem16 (Line, sizeof (Line), L' ');
+ Line[ARRAY_SIZE (Line) - 1] = CHAR_NULL;
+
+ for (Col = 1; Col <= LastCol; Col += ARRAY_SIZE (Line) - 1) {
+ if (Col + ARRAY_SIZE (Line) - 1 > LastCol) {
+ if (Row == LastRow) {
+ //
+ // if CHAR_NULL is still at position LastCol, it will cause first line error
+ //
+ Line[(LastCol - 1) % (ARRAY_SIZE (Line) - 1)] = CHAR_NULL;
+ } else {
+ Line[LastCol % (ARRAY_SIZE (Line) - 1)] = CHAR_NULL;
+ }
+ }
- if (Row == LastRow) {
//
- // if CHAR_NULL is still at position 80, it will cause first line error
+ // print out the blank line
//
- Line[LastCol - 1] = CHAR_NULL;
- } else {
- Line[LastCol] = CHAR_NULL;
+ ShellPrintEx ((INT32)Col - 1, (INT32)Row - 1, Line);
}
-
- //
- // print out the blank line
- //
- ShellPrintEx (0, ((INT32)Row) - 1, Line);
}
/**
@@ -459,15 +193,14 @@ EditorClearLine (
@retval FALSE The character is not valid.
**/
BOOLEAN
-EFIAPI
IsValidFileNameChar (
- IN CONST CHAR16 Ch
+ IN CONST CHAR16 Ch
)
{
//
// See if there are any illegal characters within the name
//
- if (Ch < 0x20 || Ch == L'\"' || Ch == L'*' || Ch == L'/' || Ch == L'<' || Ch == L'>' || Ch == L'?' || Ch == L'|' || Ch == L' ') {
+ if ((Ch < 0x20) || (Ch == L'\"') || (Ch == L'*') || (Ch == L'/') || (Ch == L'<') || (Ch == L'>') || (Ch == L'?') || (Ch == L'|')) {
return FALSE;
}
@@ -476,34 +209,33 @@ IsValidFileNameChar (
/**
Check if file name has illegal characters.
-
+
@param Name The filename to check.
@retval TRUE The filename is ok.
@retval FALSE The filename is not ok.
**/
BOOLEAN
-EFIAPI
IsValidFileName (
- IN CONST CHAR16 *Name
+ IN CONST CHAR16 *Name
)
{
-
- UINTN Index;
- UINTN Len;
+ UINTN Index;
+ UINTN Len;
//
// check the length of Name
//
for (Len = 0, Index = StrLen (Name) - 1; Index + 1 != 0; Index--, Len++) {
- if (Name[Index] == '\\' || Name[Index] == ':') {
+ if ((Name[Index] == '\\') || (Name[Index] == ':')) {
break;
}
}
- if (Len == 0 || Len > 255) {
+ if ((Len == 0) || (Len > 255)) {
return FALSE;
}
+
//
// check whether any char in Name not appears in valid file name char
//
@@ -525,18 +257,15 @@ IsValidFileName (
@return the valid filename.
**/
CHAR16 *
-EFIAPI
EditGetDefaultFileName (
- IN CONST CHAR16 *Extension
+ IN CONST CHAR16 *Extension
)
{
- EFI_STATUS Status;
- UINTN Suffix;
- BOOLEAN FoundNewFile;
- CHAR16 *FileNameTmp;
+ EFI_STATUS Status;
+ UINTN Suffix;
+ CHAR16 *FileNameTmp;
- Suffix = 0;
- FoundNewFile = FALSE;
+ Suffix = 0;
do {
FileNameTmp = CatSPrint (NULL, L"NewFile%d.%s", Suffix, Extension);
@@ -560,18 +289,18 @@ EditGetDefaultFileName (
}
/**
- Read a file into an allocated buffer. The buffer is the responsibility
+ Read a file into an allocated buffer. The buffer is the responsibility
of the caller to free.
@param[in] FileName The filename of the file to open.
- @param[out] Buffer Upon successful return, the pointer to the
- address of the allocated buffer.
+ @param[out] Buffer Upon successful return, the pointer to the
+ address of the allocated buffer.
@param[out] BufferSize If not NULL, then the pointer to the size
of the allocated buffer.
@param[out] ReadOnly Upon successful return TRUE if the file is
read only. FALSE otherwise.
- @retval EFI_NOT_FOUND The filename did not represent a file in the
+ @retval EFI_NOT_FOUND The filename did not represent a file in the
file system.
@retval EFI_SUCCESS The file was read into the buffer.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
@@ -581,29 +310,28 @@ EditGetDefaultFileName (
@retval EFI_INVALID_PARAMETER FileName was a directory.
**/
EFI_STATUS
-EFIAPI
ReadFileIntoBuffer (
- IN CONST CHAR16 *FileName,
- OUT VOID **Buffer,
- OUT UINTN *BufferSize OPTIONAL,
- OUT BOOLEAN *ReadOnly
+ IN CONST CHAR16 *FileName,
+ OUT VOID **Buffer,
+ OUT UINTN *BufferSize OPTIONAL,
+ OUT BOOLEAN *ReadOnly
)
{
- VOID *InternalBuffer;
- UINTN FileSize;
- SHELL_FILE_HANDLE FileHandle;
- BOOLEAN CreateFile;
- EFI_STATUS Status;
- EFI_FILE_INFO *Info;
-
- InternalBuffer = NULL;
- FileSize = 0;
- FileHandle = NULL;
- CreateFile = FALSE;
- Status = EFI_SUCCESS;
- Info = NULL;
-
- if (FileName == NULL || Buffer == NULL || ReadOnly == NULL) {
+ VOID *InternalBuffer;
+ UINTN FileSize;
+ SHELL_FILE_HANDLE FileHandle;
+ BOOLEAN CreateFile;
+ EFI_STATUS Status;
+ EFI_FILE_INFO *Info;
+
+ InternalBuffer = NULL;
+ FileSize = 0;
+ FileHandle = NULL;
+ CreateFile = FALSE;
+ Status = EFI_SUCCESS;
+ Info = NULL;
+
+ if ((FileName == NULL) || (Buffer == NULL) || (ReadOnly == NULL)) {
return (EFI_INVALID_PARAMETER);
}
@@ -612,14 +340,14 @@ ReadFileIntoBuffer (
//
Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ, 0);
- if (!EFI_ERROR(Status)) {
- ASSERT(CreateFile == FALSE);
+ if (!EFI_ERROR (Status)) {
+ ASSERT (CreateFile == FALSE);
if (FileHandle == NULL) {
return EFI_LOAD_ERROR;
}
- Info = ShellGetFileInfo(FileHandle);
-
+ Info = ShellGetFileInfo (FileHandle);
+
if (Info->Attribute & EFI_FILE_DIRECTORY) {
FreePool (Info);
return EFI_INVALID_PARAMETER;
@@ -630,10 +358,11 @@ ReadFileIntoBuffer (
} else {
*ReadOnly = FALSE;
}
+
//
// get file size
//
- FileSize = (UINTN) Info->FileSize;
+ FileSize = (UINTN)Info->FileSize;
FreePool (Info);
} else if (Status == EFI_NOT_FOUND) {
@@ -651,10 +380,12 @@ ReadFileIntoBuffer (
if (Status == EFI_WARN_DELETE_FAILURE) {
Status = EFI_ACCESS_DENIED;
}
+
if (EFI_ERROR (Status)) {
return Status;
}
}
+
//
// file doesn't exist, so set CreateFile to TRUE and can't be read-only
//
@@ -673,21 +404,23 @@ ReadFileIntoBuffer (
if (InternalBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
+
//
// read file into InternalBuffer
//
Status = ShellReadFile (FileHandle, &FileSize, InternalBuffer);
- ShellCloseFile(&FileHandle);
+ ShellCloseFile (&FileHandle);
FileHandle = NULL;
if (EFI_ERROR (Status)) {
SHELL_FREE_NON_NULL (InternalBuffer);
return EFI_LOAD_ERROR;
}
}
+
*Buffer = InternalBuffer;
if (BufferSize != NULL) {
*BufferSize = FileSize;
}
- return (EFI_SUCCESS);
+ return (EFI_SUCCESS);
}