]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Add a simple case to test shell parameter parsing logic
authorRuiyu Ni <ruiyu.ni@intel.com>
Tue, 29 Sep 2015 06:35:33 +0000 (06:35 +0000)
committerniruiyu <niruiyu@Edk2>
Tue, 29 Sep 2015 06:35:33 +0000 (06:35 +0000)
TestArgv.nsh is a very simple shell script to test how the interpreter parses
the parameters. It uses ShellCTestApp.efi to dump the parameters passed from the
interpreter.

TestArgv.log is the desired output created using "TestArgv.nsh > TestArgv.log".

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18558 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Application/ShellCTestApp/README.txt [new file with mode: 0644]
ShellPkg/Application/ShellCTestApp/ShellCTestApp.c
ShellPkg/Application/ShellCTestApp/TestArgv.log [new file with mode: 0644]
ShellPkg/Application/ShellCTestApp/TestArgv.nsh [new file with mode: 0644]

diff --git a/ShellPkg/Application/ShellCTestApp/README.txt b/ShellPkg/Application/ShellCTestApp/README.txt
new file mode 100644 (file)
index 0000000..7814bb8
--- /dev/null
@@ -0,0 +1,5 @@
+TestArgv.nsh is a very simple shell script to test how the interpreter parses\r
+the parameters. It uses ShellCTestApp.efi to dump the parameters passed from the\r
+intepreter.\r
+\r
+TestArgv.log is the desired output created using "TestArgv.nsh > TestArgv.log".
\ No newline at end of file
index 8d3fa4c6621a76ac99cd5f03449b6bb5f6fb7a0f..08c830cfb79a07e0f97b9142f41b146b343be59d 100644 (file)
@@ -2,7 +2,7 @@
   This is a test application that demonstrates how to use the C-style entry point\r
   for a shell application.\r
 \r
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2015, 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
@@ -40,10 +40,11 @@ ShellAppMain (
   )\r
 {\r
   UINTN  Index;\r
-\r
-  Print(L"ShellCTestApp.c:ShellAppMain called with %d parameters\n", Argc);\r
-  for (Index = 0; Index < Argc; Index++) {\r
-    Print(L"Argv[%d]: %s\n", Index, Argv[Index]);\r
+  if (Argc == 1) {\r
+    Print (L"Argv[1] = NULL\n");\r
+  }\r
+  for (Index = 1; Index < Argc; Index++) {\r
+    Print(L"Argv[%d]: \"%s\"\n", Index, Argv[Index]);\r
   }\r
 \r
   return 0;\r
diff --git a/ShellPkg/Application/ShellCTestApp/TestArgv.log b/ShellPkg/Application/ShellCTestApp/TestArgv.log
new file mode 100644 (file)
index 0000000..e76781e
Binary files /dev/null and b/ShellPkg/Application/ShellCTestApp/TestArgv.log differ
diff --git a/ShellPkg/Application/ShellCTestApp/TestArgv.nsh b/ShellPkg/Application/ShellCTestApp/TestArgv.nsh
new file mode 100644 (file)
index 0000000..013ac12
--- /dev/null
@@ -0,0 +1,64 @@
+#/** @file\r
+#  This is a very simple shell script to test how the interpreter parses the parameters.\r
+#\r
+#  Copyright (c) 2015, 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
+echo -on\r
+set Var_EFCF356F_228C_47C2_AD0C_3B5DAC9A8CFA      ValueOfGuid\r
+set Sharp_E8528E46_A008_4221_8DE0_D5AB42A9C580    ^#\r
+set Quote_E95DEE8B_E3AA_4155_9ED5_6916394104FC    ^"\r
+set Var_ShellCTestApp_EE6E8BC6_71A6_44A5_BED3_D8F901105CDE ShellCTestApp_EE6E8BC6_71A6_44A5_BED3_D8F901105CDE\r
+alias ShellCTestApp_EE6E8BC6_71A6_44A5_BED3_D8F901105CDE   ShellCTestApp\r
+\r
+#\r
+# '^' should escape all special characters (including space)\r
+#     but has no impact to non-special characters\r
+#\r
+ShellCTestApp ^^\r
+ShellCTestApp ^#\r
+ShellCTestApp ^%Var_EFCF356F_228C_47C2_AD0C_3B5DAC9A8CFA%\r
+ShellCTestApp ^"\r
+ShellCTestApp ^ 1\r
+ShellCTestApp ^ \r
+ShellCTestApp ^1\r
+ShellCTestApp ^^^"\r
+ShellCTestApp ^^^\r
+\r
+#\r
+# '#' should be processed before %% replacement, and inside '"'\r
+#\r
+ShellCTestApp #%Var_EFCF356F_228C_47C2_AD0C_3B5DAC9A8CFA%\r
+#ShellCTestApp "#"\r
+ShellCTestApp %Sharp_E8528E46_A008_4221_8DE0_D5AB42A9C580%\r
+\r
+#\r
+# '%' should be processed before grouping parameters\r
+#\r
+ShellCTestApp "%Var_EFCF356F_228C_47C2_AD0C_3B5DAC9A8CFA% 2%Quote_E95DEE8B_E3AA_4155_9ED5_6916394104FC%\r
+\r
+#\r
+# alias should be processed after %% replacement\r
+#\r
+%Var_ShellCTestApp_EE6E8BC6_71A6_44A5_BED3_D8F901105CDE%\r
+\r
+#\r
+# '"' should be stripped, space inside '"' should be kept, \r
+#\r
+ShellCTestApp "p   1"\r
+ShellCTestApp "p"1\r
+ShellCTestApp "p   1"e"x"""\r
+\r
+set -d Var_EFCF356F_228C_47C2_AD0C_3B5DAC9A8CFA\r
+set -d Sharp_E8528E46_A008_4221_8DE0_D5AB42A9C580\r
+set -d Quote_E95DEE8B_E3AA_4155_9ED5_6916394104FC\r
+set -d Var_ShellCTestApp_EE6E8BC6_71A6_44A5_BED3_D8F901105CDE\r
+alias -d ShellCTestApp_EE6E8BC6_71A6_44A5_BED3_D8F901105CDE\r
+echo -off
\ No newline at end of file