]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel1CommandsLib/If.c
ShellPkg: Skip leading tabs when processing command line and scripts
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel1CommandsLib / If.c
index 62c713e58973b473cd2465bdb5cdf5519d40ca43..791b1aed8faa06bd8352ad69a4a2f191a4b5581f 100644 (file)
@@ -1,6 +1,7 @@
 /** @file\r
   Main file for If and else shell level 1 function.\r
 \r
+  Copyright (c) 2013, Hewlett-Packard Development Company, L.P.\r
   Copyright (c) 2009 - 2011, 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
@@ -14,6 +15,7 @@
 \r
 #include "UefiShellLevel1CommandsLib.h"\r
 #include <Library/PrintLib.h>\r
+#include <Library/PathLib.h>\r
 \r
 typedef enum {\r
   EndTagOr,\r
@@ -39,8 +41,8 @@ typedef enum {
 /**\r
   Extract the next fragment, if there is one.\r
 \r
-  @param[in,out] Statement    The current remaining statement.\r
-  @param[in] Fragment         The current fragment.\r
+  @param[in, out] Statement    The current remaining statement.\r
+  @param[in] Fragment          The current fragment.\r
 \r
   @retval FALSE   There is not another fragment.\r
   @retval TRUE    There is another fragment.\r
@@ -95,10 +97,7 @@ IsValidProfile (
   CONST CHAR16  *TempLocation;\r
 \r
   ProfilesString = ShellGetEnvironmentVariable(L"profiles");\r
-  //\r
-  // According to the Shell spec this is a required environment variable.\r
-  //\r
-  ASSERT(ProfileString != NULL);\r
+  ASSERT(ProfilesString != NULL);\r
   TempLocation = StrStr(ProfilesString, String);\r
   if ((TempLocation != NULL) && (*(TempLocation-1) == L';') && (*(TempLocation+StrLen(String)) == L';')) {\r
     return (TRUE);\r
@@ -168,7 +167,6 @@ TestOperation (
       }\r
     }\r
     return (FALSE);\r
-    break;\r
   case OperatorUnsignedLessThan:\r
   case OperatorLessThan:\r
     if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {\r
@@ -204,7 +202,6 @@ TestOperation (
 \r
     }\r
     return (FALSE);\r
-    break;\r
   case OperatorEqual:\r
     if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {\r
       //\r
@@ -232,7 +229,6 @@ TestOperation (
       }\r
     }\r
     return (FALSE);\r
-    break;\r
   case OperatorNotEqual:\r
     if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {\r
       //\r
@@ -260,7 +256,6 @@ TestOperation (
       }\r
     }\r
     return (FALSE);\r
-    break;\r
   case OperatorUnsignedGreaterOrEqual:\r
   case OperatorGreatorOrEqual:\r
     if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {\r
@@ -295,7 +290,6 @@ TestOperation (
       }\r
     }\r
     return (FALSE);\r
-    break;\r
   case OperatorLessOrEqual:\r
   case OperatorUnsignedLessOrEqual:\r
     if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {\r
@@ -330,7 +324,6 @@ TestOperation (
       }\r
     }\r
     return (FALSE);\r
-    break;\r
   default:\r
     ASSERT(FALSE);\r
     return (FALSE);\r
@@ -340,15 +333,15 @@ TestOperation (
 /**\r
   Process an if statement and determine if its is valid or not.\r
 \r
-  @param[in,out] PassingState     Opon entry, the current state.  Upon exit, \r
-                                  the new state.\r
-  @param[in] StartParameterNumber The number of the first parameter of\r
-                                  this statement.\r
-  @param[in] EndParameterNumber   The number of the final parameter of\r
-                                  this statement.\r
-  @param[in] OperatorToUse        The type of termination operator.\r
-  @param[in] CaseInsensitive      TRUE for case insensitive, FALSE otherwise.\r
-  @param[in] ForceStringCompare   TRUE for all string based, FALSE otherwise.\r
+  @param[in, out] PassingState     Opon entry, the current state.  Upon exit, \r
+                                   the new state.\r
+  @param[in] StartParameterNumber  The number of the first parameter of\r
+                                   this statement.\r
+  @param[in] EndParameterNumber    The number of the final parameter of\r
+                                   this statement.\r
+  @param[in] OperatorToUse         The type of termination operator.\r
+  @param[in] CaseInsensitive       TRUE for case insensitive, FALSE otherwise.\r
+  @param[in] ForceStringCompare    TRUE for all string based, FALSE otherwise.\r
 \r
   @retval EFI_INVALID_PARAMETER   A parameter was invalid.\r
   @retval EFI_SUCCESS             The operation was successful.                                  \r
@@ -664,12 +657,9 @@ BuildNextStatement (
   OUT END_TAG_TYPE  *EndTag\r
   )\r
 {\r
-  CHAR16    *Buffer;\r
-  UINTN     BufferSize;\r
-\r
   *EndTag = EndTagMax;\r
 \r
-  for(Buffer = NULL, BufferSize = 0\r
+  for(\r
     ; ParameterNumber < gEfiShellParametersProtocol->Argc\r
     ; ParameterNumber++\r
    ) {\r
@@ -741,8 +731,15 @@ MoveToTagSpecial (
     //\r
     CommandName   = NULL;\r
     CommandName   = StrnCatGrow(&CommandName, NULL, CommandNode->Cl, 0);\r
+    if (CommandName == NULL) {\r
+      continue;\r
+    }\r
     CommandWalker = CommandName;\r
-    while (CommandWalker[0] == L' ') {\r
+\r
+    //\r
+    // Skip leading spaces and tabs.\r
+    //\r
+    while ((CommandWalker[0] == L' ') || (CommandWalker[0] == L'\t')) {\r
       CommandWalker++;\r
     }\r
     TempLocation  = StrStr(CommandWalker, L" ");\r
@@ -855,7 +852,7 @@ ShellCommandRunIf (
       NULL, \r
       STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r
       gShellLevel1HiiHandle, \r
-      L"EnfIf", \r
+      L"EndIf", \r
       L"If", \r
       CurrentScriptFile!=NULL \r
         && CurrentScriptFile->CurrentCommand!=NULL\r