]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/Shell.c
Refine comments and two code style.
[mirror_edk2.git] / ShellPkg / Application / Shell / Shell.c
index 17943531dbb08b13aa00d5a2e13a85c8d0a04776..3a5899f342ee989f9683e731e96f11a931078ea9 100644 (file)
@@ -55,7 +55,8 @@ SHELL_INFO ShellInfoObject = {
   NULL,\r
   NULL,\r
   NULL,\r
-  NULL\r
+  NULL,\r
+  FALSE\r
 };\r
 \r
 STATIC CONST CHAR16 mScriptExtension[]      = L".NSH";\r
@@ -155,17 +156,11 @@ UefiMain (
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  CHAR16      *TempString;\r
-  UINTN       Size;\r
-//    EFI_INPUT_KEY                 Key;\r
-\r
-//  gST->ConOut->OutputString(gST->ConOut, L"ReadKeyStroke Calling\r\n");\r
-//\r
-//  Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-//\r
-//  gST->ConOut->OutputString(gST->ConOut, L"ReadKeyStroke Done\r\n");\r
-//  gBS->Stall (1000000);\r
+  EFI_STATUS                      Status;\r
+  CHAR16                          *TempString;\r
+  UINTN                           Size;\r
+  EFI_HANDLE                      ConInHandle;\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *OldConIn;\r
 \r
   if (PcdGet8(PcdShellSupportLevel) > 3) {\r
     return (EFI_UNSUPPORTED);\r
@@ -361,6 +356,18 @@ UefiMain (
         Status = InternalEfiShellStartCtrlSMonitor();\r
       }\r
 \r
+      if (!EFI_ERROR(Status) && ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r
+        //\r
+        // close off the gST->ConIn\r
+        //\r
+        OldConIn      = gST->ConIn;\r
+        ConInHandle   = gST->ConsoleInHandle;\r
+        gST->ConIn = CreateSimpleTextInOnFile((SHELL_FILE_HANDLE)&FileInterfaceNulFile, &gST->ConsoleInHandle);\r
+      } else {\r
+        OldConIn      = NULL;\r
+        ConInHandle   = NULL;\r
+      }\r
+\r
       if (!EFI_ERROR(Status) && PcdGet8(PcdShellSupportLevel) >= 1) {\r
         //\r
         // process the startup script or launch the called app.\r
@@ -399,6 +406,11 @@ UefiMain (
           Status = DoShellPrompt();\r
         } while (!ShellCommandGetExit());\r
       }\r
+      if (OldConIn != NULL && ConInHandle != NULL) {\r
+        CloseSimpleTextInOnFile (gST->ConIn);\r
+        gST->ConIn            = OldConIn;\r
+        gST->ConsoleInHandle  = ConInHandle;\r
+      }\r
     }\r
   }\r
 \r
@@ -548,16 +560,14 @@ IsScriptOnlyCommand(
   return (FALSE);\r
 }\r
 \r
-\r
-\r
 /**\r
   This function will populate the 2 device path protocol parameters based on the\r
   global gImageHandle.  The DevPath will point to the device path for the handle that has\r
   loaded image protocol installed on it.  The FilePath will point to the device path\r
   for the file that was loaded.\r
 \r
-  @param[in,out] DevPath       On a sucessful return the device path to the loaded image.\r
-  @param[in,out] FilePath      On a sucessful return the device path to the file.\r
+  @param[in, out] DevPath       On a sucessful return the device path to the loaded image.\r
+  @param[in, out] FilePath      On a sucessful return the device path to the file.\r
 \r
   @retval EFI_SUCCESS           The 2 device paths were sucessfully returned.\r
   @retval other                 A error from gBS->HandleProtocol.\r
@@ -598,6 +608,11 @@ GetDevicePathsForImageAndFile (
     if (!EFI_ERROR (Status)) {\r
       *DevPath  = DuplicateDevicePath (ImageDevicePath);\r
       *FilePath = DuplicateDevicePath (LoadedImage->FilePath);\r
+      gBS->CloseProtocol(\r
+                  LoadedImage->DeviceHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  gImageHandle,\r
+                  NULL);\r
     }\r
     gBS->CloseProtocol(\r
                 gImageHandle,\r
@@ -620,6 +635,7 @@ STATIC CONST SHELL_PARAM_ITEM mShellParamList[] = {
   {L"-delay",         TypeValue},\r
   {NULL, TypeMax}\r
   };\r
+\r
 /**\r
   Process all Uefi Shell 2.0 command line options.\r
 \r
@@ -731,7 +747,7 @@ ProcessCommandLine(
     ShellInfoObject.ShellInitSettings.Delay = 0;\r
   } else if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay) {\r
     TempConst = ShellCommandLineGetValue(Package, L"-delay");\r
-    if (*TempConst == L':') {\r
+    if (TempConst != NULL && *TempConst == L':') {\r
       TempConst++;\r
     }\r
     if (TempConst != NULL && !EFI_ERROR(ShellConvertStringToUint64(TempConst, &Intermediate, FALSE, FALSE))) {\r
@@ -843,7 +859,7 @@ DoStartupScript(
       *TempSpot = CHAR_NULL;\r
     }\r
     FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, ((FILEPATH_DEVICE_PATH*)FilePath)->PathName, 0);\r
-    ChopLastSlash(FileStringPath);\r
+    PathRemoveLastItem(FileStringPath);\r
     FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, mStartupScript, 0);\r
     Status = ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ);\r
     FreePool(FileStringPath);\r
@@ -1000,10 +1016,10 @@ AddLineToCommandHistory(
   Checks if a string is an alias for another command.  If yes, then it replaces the alias name\r
   with the correct command name.\r
 \r
-  @param[in,out] CommandString    Upon entry the potential alias.  Upon return the\r
-                                  command name if it was an alias.  If it was not\r
-                                  an alias it will be unchanged.  This function may\r
-                                  change the buffer to fit the command name.\r
+  @param[in, out] CommandString    Upon entry the potential alias.  Upon return the\r
+                                   command name if it was an alias.  If it was not\r
+                                   an alias it will be unchanged.  This function may\r
+                                   change the buffer to fit the command name.\r
 \r
   @retval EFI_SUCCESS             The name was changed.\r
   @retval EFI_SUCCESS             The name was not an alias.\r
@@ -1427,21 +1443,6 @@ RunCommand(
         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle);\r
       }\r
     } else {\r
-      //\r
-      // remove the < and/or > from the command line now\r
-      //\r
-      for (TempLocation3 = PostVariableCmdLine ; TempLocation3 != NULL && *TempLocation3 != CHAR_NULL ; TempLocation3++) {\r
-        if (*TempLocation3 == L'^') {\r
-          if (*(TempLocation3+1) == L'<' || *(TempLocation3+1) == L'>') {\r
-            CopyMem(TempLocation3, TempLocation3+1, StrSize(TempLocation3) - sizeof(TempLocation3[0]));\r
-          }\r
-        } else if (*TempLocation3 == L'>') {\r
-          *TempLocation3 = CHAR_NULL;\r
-        } else if ((*TempLocation3 == L'1' || *TempLocation3 == L'2')&&(*(TempLocation3+1) == L'>')) {\r
-          *TempLocation3 = CHAR_NULL;\r
-        }\r
-      }\r
-\r
       while (PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] == L' ') {\r
         PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] = CHAR_NULL;\r
       }\r
@@ -1618,6 +1619,7 @@ RunScriptFileHandle (
   SCRIPT_COMMAND_LIST *LastCommand;\r
   BOOLEAN             Ascii;\r
   BOOLEAN             PreScriptEchoState;\r
+  BOOLEAN             PreCommandEchoState;\r
   CONST CHAR16        *CurDir;\r
   UINTN               LineCount;\r
 \r
@@ -1805,7 +1807,22 @@ RunScriptFileHandle (
             }\r
             ShellPrintEx(-1, -1, L"%s\r\n", CommandLine2);\r
           }\r
-          Status = RunCommand(CommandLine3);\r
+          if (CommandLine3[0] == L'@') {\r
+            //\r
+            // We need to save the current echo state\r
+            // and disable echo for just this command.\r
+            //\r
+            PreCommandEchoState = ShellCommandGetEchoState();\r
+            ShellCommandSetEchoState(FALSE);\r
+            Status = RunCommand(CommandLine3+1);\r
+\r
+            //\r
+            // Now restore the pre-'@' echo state.\r
+            //\r
+            ShellCommandSetEchoState(PreCommandEchoState);\r
+          } else {\r
+            Status = RunCommand(CommandLine3);\r
+          }\r
         }\r
 \r
         if (ShellCommandGetScriptExit()) {\r