]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel3CommandsLib/Echo.c
udk2010.up2.shell initial release.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel3CommandsLib / Echo.c
diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/Echo.c b/ShellPkg/Library/UefiShellLevel3CommandsLib/Echo.c
new file mode 100644 (file)
index 0000000..dc6bca0
--- /dev/null
@@ -0,0 +1,116 @@
+/** @file\r
+  Main file for Echo shell level 3 function.\r
+\r
+  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "UefiShellLevel3CommandsLib.h"\r
+\r
+#include <Library/ShellLib.h>\r
+\r
+STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
+  {L"-on", TypeFlag},\r
+  {L"-off", TypeFlag},\r
+  {NULL, TypeMax}\r
+  };\r
+\r
+/**\r
+  Function for 'echo' command.\r
+\r
+  @param[in] ImageHandle  Handle to the Image (NULL if Internal).\r
+  @param[in] SystemTable  Pointer to the System Table (NULL if Internal).\r
+**/\r
+SHELL_STATUS\r
+EFIAPI\r
+ShellCommandRunEcho (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  LIST_ENTRY          *Package;\r
+//  CHAR16              *ProblemParam;\r
+  SHELL_STATUS        ShellStatus;\r
+  UINTN               ParamCount;\r
+\r
+//  ProblemParam        = NULL;\r
+  ShellStatus         = SHELL_SUCCESS;\r
+\r
+  //\r
+  // initialize the shell lib (we must be in non-auto-init...)\r
+  //\r
+  Status = ShellInitialize();\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  //\r
+  // parse the command line\r
+  //\r
+  Status = ShellCommandLineParseEx (ParamList, &Package, NULL, TRUE, TRUE);\r
+//  if (EFI_ERROR(Status)) {\r
+//    if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
+//      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);\r
+//      FreePool(ProblemParam);\r
+//      ShellStatus = SHELL_INVALID_PARAMETER;\r
+//    } else {\r
+//      ASSERT(FALSE);\r
+//    }\r
+//  } else {\r
+    //\r
+    // check for "-?"\r
+    //\r
+    if (ShellCommandLineGetFlag(Package, L"-?")) {\r
+      ASSERT(FALSE);\r
+    }\r
+    if (ShellCommandLineGetFlag(Package, L"-on")) {\r
+      //\r
+      // Turn it on\r
+      //\r
+      ShellCommandSetEchoState(TRUE);\r
+    } else if (ShellCommandLineGetFlag(Package, L"-off")) {\r
+      //\r
+      // turn it off\r
+      //\r
+      ShellCommandSetEchoState(FALSE);\r
+    } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {\r
+      //\r
+      // output its current state\r
+      //\r
+      if (ShellCommandGetEchoState()) {\r
+        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_ON), gShellLevel3HiiHandle);\r
+      } else {\r
+        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_OFF), gShellLevel3HiiHandle);\r
+      }\r
+    } else {\r
+      //\r
+      // print the line\r
+      //\r
+      for ( ParamCount = 1\r
+          ; ShellCommandLineGetRawValue(Package, ParamCount) != NULL\r
+          ; ParamCount++\r
+         ) {\r
+        if (ShellCommandLineGetRawValue(Package, ParamCount+1) != NULL) {\r
+          ShellPrintEx(-1, -1, L"%s ", ShellCommandLineGetRawValue(Package, ParamCount));\r
+        } else {\r
+          ShellPrintEx(-1, -1, L"%s", ShellCommandLineGetRawValue(Package, ParamCount));\r
+        }\r
+      }\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel3HiiHandle);\r
+    }\r
+\r
+    //\r
+    // free the command line package\r
+    //\r
+    ShellCommandLineFreeVarList (Package);\r
+//  }\r
+\r
+  return (ShellStatus);\r
+}\r
+\r