Revision: 15103
          http://sourceforge.net/p/edk2/code/15103
Author:   niruiyu
Date:     2014-01-13 07:30:08 +0000 (Mon, 13 Jan 2014)
Log Message:
-----------
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 <[email protected]>
Reviewed-by: Ruiyu Ni <[email protected]>

Modified Paths:
--------------
    trunk/edk2/ShellPkg/Application/Shell/Shell.c
    trunk/edk2/ShellPkg/Application/Shell/Shell.h

Modified: trunk/edk2/ShellPkg/Application/Shell/Shell.c
===================================================================
--- trunk/edk2/ShellPkg/Application/Shell/Shell.c       2014-01-13 07:28:01 UTC 
(rev 15102)
+++ trunk/edk2/ShellPkg/Application/Shell/Shell.c       2014-01-13 07:30:08 UTC 
(rev 15103)
@@ -990,7 +990,7 @@
   // 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 @@
       Status = EFI_SUCCESS;
       ASSERT(FileHandle == NULL);
     } else {
-      Status = RunScriptFile(FileStringPath);
+      Status = RunScriptFile(FileStringPath, NULL, L"", 
ShellInfoObject.NewShellParametersProtocol);
       FreePool(FileStringPath);
     }
   }
@@ -2048,7 +2048,7 @@
       }
       switch (Type) {
         case   Script_File_Name:
-          Status = RunScriptFile (CommandWithPath);
+          Status = RunScriptFile (CommandWithPath, NULL, CmdLine, 
ParamProtocol);
           break;
         case   Efi_Application:
           //
@@ -2578,30 +2578,62 @@
   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)) {
+
+    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);
+
+        //
+        // now close the file
+        //
+        ShellCloseFile(&FileHandle);
+      }
+    } else {
+      Status = RunScriptFileHandle(Handle, ScriptPath);
+    }
   }
 
-  Status = RunScriptFileHandle(FileHandle, 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);
 
-  ShellCloseFile(&FileHandle);
-
   return (Status);
 }

Modified: trunk/edk2/ShellPkg/Application/Shell/Shell.h
===================================================================
--- trunk/edk2/ShellPkg/Application/Shell/Shell.h       2014-01-13 07:28:01 UTC 
(rev 15102)
+++ trunk/edk2/ShellPkg/Application/Shell/Shell.h       2014-01-13 07:30:08 UTC 
(rev 15103)
@@ -1,7 +1,7 @@
 /** @file
   function definitions for internal to shell functions.
 
-  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2014, 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
@@ -327,13 +327,19 @@
   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
   );
 
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to