summaryrefslogtreecommitdiff
path: root/ShellPkg/Application
diff options
context:
space:
mode:
Diffstat (limited to 'ShellPkg/Application')
-rw-r--r--ShellPkg/Application/Shell/ConsoleLogger.c5
-rw-r--r--ShellPkg/Application/Shell/ConsoleWrappers.c34
-rw-r--r--ShellPkg/Application/Shell/ConsoleWrappers.h11
-rw-r--r--ShellPkg/Application/Shell/FileHandleWrappers.c43
-rw-r--r--ShellPkg/Application/Shell/Shell.c42
-rw-r--r--ShellPkg/Application/Shell/ShellManParser.c16
-rw-r--r--ShellPkg/Application/Shell/ShellParametersProtocol.c44
7 files changed, 160 insertions, 35 deletions
diff --git a/ShellPkg/Application/Shell/ConsoleLogger.c b/ShellPkg/Application/Shell/ConsoleLogger.c
index 0a2b1fa5e..c3729f16c 100644
--- a/ShellPkg/Application/Shell/ConsoleLogger.c
+++ b/ShellPkg/Application/Shell/ConsoleLogger.c
@@ -1,6 +1,7 @@
/** @file
Provides interface to shell console logger.
+ Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -640,6 +641,10 @@ ConsoleLoggerDoPageBreak(
} else if (*Resp == ShellPromptResponseQuit) {
FreePool(Resp);
ShellInfoObject.ConsoleInfo->Enabled = FALSE;
+ //
+ // When user wants to quit, the shell should stop running the command.
+ //
+ gBS->SignalEvent (ShellInfoObject.NewEfiShellProtocol->ExecutionBreak);
return (EFI_DEVICE_ERROR);
} else {
ASSERT(FALSE);
diff --git a/ShellPkg/Application/Shell/ConsoleWrappers.c b/ShellPkg/Application/Shell/ConsoleWrappers.c
index d85d1acf4..38491216f 100644
--- a/ShellPkg/Application/Shell/ConsoleWrappers.c
+++ b/ShellPkg/Application/Shell/ConsoleWrappers.c
@@ -1,6 +1,7 @@
/** @file
Function definitions for shell simple text in and out on top of file handles.
+ Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -24,6 +25,7 @@ typedef struct {
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOut;
SHELL_FILE_HANDLE FileHandle;
EFI_HANDLE TheHandle;
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalSimpleTextOut;
} SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;
/**
@@ -253,7 +255,14 @@ FileBasedSimpleTextOutQueryMode (
OUT UINTN *Rows
)
{
- return (EFI_UNSUPPORTED);
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *PassThruProtocol = ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)This)->OriginalSimpleTextOut;
+
+ // Pass the QueryMode call thru to the original SimpleTextOutProtocol
+ return (PassThruProtocol->QueryMode(
+ PassThruProtocol,
+ ModeNumber,
+ Columns,
+ Rows));
}
/**
@@ -386,8 +395,9 @@ FileBasedSimpleTextOutOutputString (
Function to create a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
SHELL_FILE_HANDLE to support redirecting output from a file.
- @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
- @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
+ @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
+ @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
+ @param[in] OriginalProtocol The pointer to the original output protocol for pass thru of functions.
@retval NULL There was insufficient memory available.
@return A pointer to the allocated protocol structure;
@@ -395,8 +405,9 @@ FileBasedSimpleTextOutOutputString (
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*
EFIAPI
CreateSimpleTextOutOnFile(
- IN SHELL_FILE_HANDLE FileHandleToUse,
- IN EFI_HANDLE *HandleLocation
+ IN SHELL_FILE_HANDLE FileHandleToUse,
+ IN EFI_HANDLE *HandleLocation,
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalProtocol
)
{
SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ProtocolToReturn;
@@ -411,6 +422,7 @@ CreateSimpleTextOutOnFile(
return (NULL);
}
ProtocolToReturn->FileHandle = FileHandleToUse;
+ ProtocolToReturn->OriginalSimpleTextOut = OriginalProtocol;
ProtocolToReturn->SimpleTextOut.Reset = FileBasedSimpleTextOutReset;
ProtocolToReturn->SimpleTextOut.TestString = FileBasedSimpleTextOutTestString;
ProtocolToReturn->SimpleTextOut.QueryMode = FileBasedSimpleTextOutQueryMode;
@@ -425,12 +437,12 @@ CreateSimpleTextOutOnFile(
FreePool(ProtocolToReturn);
return (NULL);
}
- ProtocolToReturn->SimpleTextOut.Mode->MaxMode = 0;
- ProtocolToReturn->SimpleTextOut.Mode->Mode = 0;
- ProtocolToReturn->SimpleTextOut.Mode->Attribute = 0;
- ProtocolToReturn->SimpleTextOut.Mode->CursorColumn = 0;
- ProtocolToReturn->SimpleTextOut.Mode->CursorRow = 0;
- ProtocolToReturn->SimpleTextOut.Mode->CursorVisible = FALSE;
+ ProtocolToReturn->SimpleTextOut.Mode->MaxMode = OriginalProtocol->Mode->MaxMode;
+ ProtocolToReturn->SimpleTextOut.Mode->Mode = OriginalProtocol->Mode->Mode;
+ ProtocolToReturn->SimpleTextOut.Mode->Attribute = OriginalProtocol->Mode->Attribute;
+ ProtocolToReturn->SimpleTextOut.Mode->CursorColumn = OriginalProtocol->Mode->CursorColumn;
+ ProtocolToReturn->SimpleTextOut.Mode->CursorRow = OriginalProtocol->Mode->CursorRow;
+ ProtocolToReturn->SimpleTextOut.Mode->CursorVisible = OriginalProtocol->Mode->CursorVisible;
Status = gBS->InstallProtocolInterface(
&(ProtocolToReturn->TheHandle),
diff --git a/ShellPkg/Application/Shell/ConsoleWrappers.h b/ShellPkg/Application/Shell/ConsoleWrappers.h
index 572113d39..13d12e8f4 100644
--- a/ShellPkg/Application/Shell/ConsoleWrappers.h
+++ b/ShellPkg/Application/Shell/ConsoleWrappers.h
@@ -1,6 +1,7 @@
/** @file
Function definitions for shell simple text in and out on top of file handles.
+ Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -50,8 +51,9 @@ CloseSimpleTextInOnFile(
Function to create a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
SHELL_FILE_HANDLE to support redirecting output from a file.
- @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
- @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
+ @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
+ @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
+ @param[in] OriginalProtocol The pointer to the original output protocol for pass thru of functions.
@retval NULL There was insufficient memory available.
@return A pointer to the allocated protocol structure;
@@ -59,8 +61,9 @@ CloseSimpleTextInOnFile(
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*
EFIAPI
CreateSimpleTextOutOnFile(
- IN SHELL_FILE_HANDLE FileHandleToUse,
- IN EFI_HANDLE *HandleLocation
+ IN SHELL_FILE_HANDLE FileHandleToUse,
+ IN EFI_HANDLE *HandleLocation,
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalProtocol
);
/**
diff --git a/ShellPkg/Application/Shell/FileHandleWrappers.c b/ShellPkg/Application/Shell/FileHandleWrappers.c
index 2ca13cb3f..ef8293c1d 100644
--- a/ShellPkg/Application/Shell/FileHandleWrappers.c
+++ b/ShellPkg/Application/Shell/FileHandleWrappers.c
@@ -3,6 +3,7 @@
StdIn, StdOut, StdErr, etc...).
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2013, Hewlett-Packard Development Company, L.P.
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
@@ -950,8 +951,48 @@ FileInterfaceEnvClose(
IN EFI_FILE_PROTOCOL *This
)
{
+ VOID* NewBuffer;
+ UINTN NewSize;
+ EFI_STATUS Status;
+
+ //
+ // Most if not all UEFI commands will have an '\r\n' at the end of any output.
+ // Since the output was redirected to a variable, it does not make sense to
+ // keep this. So, before closing, strip the trailing '\r\n' from the variable
+ // if it exists.
+ //
+ NewBuffer = NULL;
+ NewSize = 0;
+
+ Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer);
+ if (Status == EFI_BUFFER_TOO_SMALL) {
+ NewBuffer = AllocateZeroPool(NewSize + sizeof(CHAR16));
+ if (NewBuffer == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer);
+ }
+
+ if (!EFI_ERROR(Status)) {
+
+ if (StrSize(NewBuffer) > 6)
+ {
+ if ((((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 2] == CHAR_LINEFEED)
+ && (((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 3] == CHAR_CARRIAGE_RETURN)) {
+ ((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 3] = CHAR_NULL;
+ }
+
+ if (IsVolatileEnv(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name)) {
+ Status = SHELL_SET_ENVIRONMENT_VARIABLE_V(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, StrSize(NewBuffer), NewBuffer);
+ } else {
+ Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, StrSize(NewBuffer), NewBuffer);
+ }
+ }
+ }
+
+ SHELL_FREE_NON_NULL(NewBuffer);
FreePool((EFI_FILE_PROTOCOL_ENVIRONMENT*)This);
- return (EFI_SUCCESS);
+ return (Status);
}
/**
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c
index e5a648833..1b52692ec 100644
--- a/ShellPkg/Application/Shell/Shell.c
+++ b/ShellPkg/Application/Shell/Shell.c
@@ -1415,9 +1415,9 @@ RunCommand(
}
//
- // Remove any spaces at the beginning of the string.
+ // Remove any spaces and tabs at the beginning of the string.
//
- while (CleanOriginal[0] == L' ') {
+ while ((CleanOriginal[0] == L' ') || (CleanOriginal[0] == L'\t')) {
CopyMem(CleanOriginal, CleanOriginal+1, StrSize(CleanOriginal) - sizeof(CleanOriginal[0]));
}
@@ -1593,10 +1593,15 @@ RunCommand(
if (!EFI_ERROR(Status)) {
Status = ShellCommandRunCommandHandler(ShellInfoObject.NewShellParametersProtocol->Argv[0], &ShellStatus, &LastError);
ASSERT_EFI_ERROR(Status);
- UnicodeSPrint(LeString, sizeof(LeString), L"0x%08Lx", ShellStatus);
- DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE););
+
+ if (sizeof(EFI_STATUS) == sizeof(UINT64)) {
+ UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellStatus);
+ } else {
+ UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", ShellStatus);
+ }
+ DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););
if (LastError) {
- InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE);
+ InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);
}
//
// Pass thru the exitcode from the app.
@@ -1622,6 +1627,14 @@ RunCommand(
}
if (CommandWithPath == NULL || ShellIsDirectory(CommandWithPath) == EFI_SUCCESS) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, ShellInfoObject.NewShellParametersProtocol->Argv[0]);
+
+ if (sizeof(EFI_STATUS) == sizeof(UINT64)) {
+ UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", EFI_NOT_FOUND);
+ } else {
+ UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", EFI_NOT_FOUND);
+ }
+ DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););
+ InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);
} else {
//
// Check if it's a NSH (script) file.
@@ -1642,11 +1655,15 @@ RunCommand(
);
//
- // Updatet last error status.
+ // Update last error status.
//
- UnicodeSPrint(LeString, sizeof(LeString), L"0x%08Lx", StatusCode);
- DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE););
- InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE);
+ if (sizeof(EFI_STATUS) == sizeof(UINT64)) {
+ UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", StatusCode);
+ } else {
+ UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", StatusCode);
+ }
+ DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););
+ InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);
}
}
}
@@ -1952,9 +1969,12 @@ RunScriptFileHandle (
}
if (ShellCommandGetScriptExit()) {
+ //
+ // ShellCommandGetExitCode() always returns a UINT64
+ //
UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellCommandGetExitCode());
- DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE););
- InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE);
+ DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););
+ InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);
ShellCommandRegisterExit(FALSE, 0);
Status = EFI_SUCCESS;
diff --git a/ShellPkg/Application/Shell/ShellManParser.c b/ShellPkg/Application/Shell/ShellManParser.c
index 470f51a8e..8196a6ac9 100644
--- a/ShellPkg/Application/Shell/ShellManParser.c
+++ b/ShellPkg/Application/Shell/ShellManParser.c
@@ -1,7 +1,7 @@
/** @file
Provides interface to shell MAN file parser.
- Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
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
@@ -491,6 +491,20 @@ ManFileFindTitleSection(
}
StrCpy(TitleString, L".TH ");
StrCat(TitleString, Command);
+
+ //
+ // If the "name" ends with .efi we can safely chop that off since "help foo.efi" and "help foo"
+ // should produce the same results.
+ //
+ if ((StrLen(Command)> 4)
+ && (TitleString[StrLen(TitleString)-1] == L'i' || TitleString[StrLen(TitleString)-1] == L'I')
+ && (TitleString[StrLen(TitleString)-2] == L'f' || TitleString[StrLen(TitleString)-2] == L'F')
+ && (TitleString[StrLen(TitleString)-3] == L'e' || TitleString[StrLen(TitleString)-2] == L'E')
+ && (TitleString[StrLen(TitleString)-4] == L'.')
+ ) {
+ TitleString[StrLen(TitleString)-4] = CHAR_NULL;
+ }
+
TitleLen = StrLen(TitleString);
for (;!ShellFileHandleEof(Handle);Size = 1024) {
Status = ShellFileHandleReadLine(Handle, ReadLine, &Size, TRUE, Ascii);
diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c
index 2f8c626b0..b6598c0cf 100644
--- a/ShellPkg/Application/Shell/ShellParametersProtocol.c
+++ b/ShellPkg/Application/Shell/ShellParametersProtocol.c
@@ -2,6 +2,7 @@
Member functions of EFI_SHELL_PARAMETERS_PROTOCOL and functions for creation,
manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.
+ Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -538,6 +539,35 @@ FixFileName (
}
/**
+ Fix a string to only have the environment variable name, removing starting at the first space of whatever is quoted and removing the leading and trailing %.
+
+ @param[in] FileName The filename to start with.
+
+ @retval NULL FileName was invalid.
+ @return The modified FileName.
+**/
+CHAR16*
+EFIAPI
+FixVarName (
+ IN CHAR16 *FileName
+ )
+{
+ CHAR16 *Copy;
+ CHAR16 *TempLocation;
+
+ Copy = FileName;
+
+ if (FileName[0] == L'%') {
+ Copy = FileName+1;
+ if ((TempLocation = StrStr(Copy , L"%")) != NULL) {
+ TempLocation[0] = CHAR_NULL;
+ }
+ }
+
+ return (FixFileName(Copy));
+}
+
+/**
Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
structure by parsing NewCommandLine. The current values are returned to the
user.
@@ -913,17 +943,17 @@ UpdateStdInStdOutStdErr(
}
}
if (StdErrVarName != NULL) {
- if ((StdErrVarName = FixFileName(StdErrVarName)) == NULL) {
+ if ((StdErrVarName = FixVarName(StdErrVarName)) == NULL) {
Status = EFI_INVALID_PARAMETER;
}
}
if (StdOutVarName != NULL) {
- if ((StdOutVarName = FixFileName(StdOutVarName)) == NULL) {
+ if ((StdOutVarName = FixVarName(StdOutVarName)) == NULL) {
Status = EFI_INVALID_PARAMETER;
}
}
if (StdInVarName != NULL) {
- if ((StdInVarName = FixFileName(StdInVarName)) == NULL) {
+ if ((StdInVarName = FixVarName(StdInVarName)) == NULL) {
Status = EFI_INVALID_PARAMETER;
}
}
@@ -1008,7 +1038,7 @@ UpdateStdInStdOutStdErr(
}
if (!EFI_ERROR(Status)) {
ShellParameters->StdErr = TempHandle;
- gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle);
+ gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle, gST->StdErr);
}
}
@@ -1051,7 +1081,7 @@ UpdateStdInStdOutStdErr(
}
if (!EFI_ERROR(Status)) {
ShellParameters->StdOut = TempHandle;
- gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle);
+ gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle, gST->ConOut);
}
}
}
@@ -1069,7 +1099,7 @@ UpdateStdInStdOutStdErr(
TempHandle = CreateFileInterfaceEnv(StdOutVarName);
ASSERT(TempHandle != NULL);
ShellParameters->StdOut = TempHandle;
- gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle);
+ gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle, gST->ConOut);
}
//
@@ -1085,7 +1115,7 @@ UpdateStdInStdOutStdErr(
TempHandle = CreateFileInterfaceEnv(StdErrVarName);
ASSERT(TempHandle != NULL);
ShellParameters->StdErr = TempHandle;
- gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle);
+ gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle, gST->StdErr);
}
//