summaryrefslogtreecommitdiff
path: root/ShellPkg/Application/Shell/Shell.c
diff options
context:
space:
mode:
authorJaben Carsey <jaben.carsey@intel.com>2014-01-13 07:30:08 +0000
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>2014-01-13 07:30:08 +0000
commite958b94662d2a5cd838d59b463dcb38a1ccfb56b (patch)
tree69a80382310d802b678f0c6508a1a8326a989e3a /ShellPkg/Application/Shell/Shell.c
parent483b86b918fad5bfe8ecf3d4e2b6655a26e07d2d (diff)
downloadedk2-platforms-e958b94662d2a5cd838d59b463dcb38a1ccfb56b.tar.xz
ShellPkg: Fix command line parsing for script files (%1, %1, etc...)
This change makes sure that all script files get their command lines properly parsed for use in the script file. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15103 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg/Application/Shell/Shell.c')
-rw-r--r--ShellPkg/Application/Shell/Shell.c52
1 files changed, 42 insertions, 10 deletions
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c
index 81982f1354..134ec587d5 100644
--- a/ShellPkg/Application/Shell/Shell.c
+++ b/ShellPkg/Application/Shell/Shell.c
@@ -990,7 +990,7 @@ DoStartupScript(
// If we got a file, run it
//
if (!EFI_ERROR(Status) && FileHandle != NULL) {
- Status = RunScriptFileHandle (FileHandle, mStartupScript);
+ Status = RunScriptFile (mStartupScript, FileHandle, L"", ShellInfoObject.NewShellParametersProtocol);
ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);
} else {
FileStringPath = ShellFindFilePath(mStartupScript);
@@ -1001,7 +1001,7 @@ DoStartupScript(
Status = EFI_SUCCESS;
ASSERT(FileHandle == NULL);
} else {
- Status = RunScriptFile(FileStringPath);
+ Status = RunScriptFile(FileStringPath, NULL, L"", ShellInfoObject.NewShellParametersProtocol);
FreePool(FileStringPath);
}
}
@@ -2048,7 +2048,7 @@ RunCommandOrFile(
}
switch (Type) {
case Script_File_Name:
- Status = RunScriptFile (CommandWithPath);
+ Status = RunScriptFile (CommandWithPath, NULL, CmdLine, ParamProtocol);
break;
case Efi_Application:
//
@@ -2578,30 +2578,62 @@ RunScriptFileHandle (
Function to process a NSH script file.
@param[in] ScriptPath Pointer to the script file name (including file system path).
+ @param[in] Handle the handle of the script file already opened.
+ @param[in] CmdLine the command line to run.
+ @param[in] ParamProtocol the shell parameters protocol pointer
@retval EFI_SUCCESS the script completed sucessfully
**/
EFI_STATUS
EFIAPI
RunScriptFile (
- IN CONST CHAR16 *ScriptPath
+ IN CONST CHAR16 *ScriptPath,
+ IN SHELL_FILE_HANDLE Handle OPTIONAL,
+ IN CONST CHAR16 *CmdLine,
+ IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol
)
{
EFI_STATUS Status;
SHELL_FILE_HANDLE FileHandle;
+ UINTN Argc;
+ CHAR16 **Argv;
if (ShellIsFile(ScriptPath) != EFI_SUCCESS) {
return (EFI_INVALID_PARAMETER);
}
- Status = ShellOpenFileByName(ScriptPath, &FileHandle, EFI_FILE_MODE_READ, 0);
- if (EFI_ERROR(Status)) {
- return (Status);
- }
+ //
+ // get the argc and argv updated for scripts
+ //
+ Status = UpdateArgcArgv(ParamProtocol, CmdLine, &Argv, &Argc);
+ if (!EFI_ERROR(Status)) {
- Status = RunScriptFileHandle(FileHandle, ScriptPath);
+ if (Handle == NULL) {
+ //
+ // open the file
+ //
+ Status = ShellOpenFileByName(ScriptPath, &FileHandle, EFI_FILE_MODE_READ, 0);
+ if (!EFI_ERROR(Status)) {
+ //
+ // run it
+ //
+ Status = RunScriptFileHandle(FileHandle, ScriptPath);
- ShellCloseFile(&FileHandle);
+ //
+ // now close the file
+ //
+ ShellCloseFile(&FileHandle);
+ }
+ } else {
+ Status = RunScriptFileHandle(Handle, ScriptPath);
+ }
+ }
+
+ //
+ // This is guarenteed to be called after UpdateArgcArgv no matter what else happened.
+ // This is safe even if the update API failed. In this case, it may be a no-op.
+ //
+ RestoreArgcArgv(ParamProtocol, &Argv, &Argc);
return (Status);
}