]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
ShellPkg: "For Run" fix for spaces between numerals
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel1CommandsLib / For.c
index 7d91d2348f73e94cc16175583d2f4ab308a18c73..f0c4a23b245932851c8550697847ceac96b67e8d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for endfor and for shell level 1 functions.\r
 \r
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2012, 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
@@ -253,6 +253,29 @@ InternalRemoveAliasFromList(
   return (FALSE);\r
 }\r
 \r
+/**\r
+  Function to determine whether a string is decimal or hex representation of a number\r
+  and return the number converted from the string.\r
+\r
+  @param[in] String   String representation of a number\r
+\r
+  @return             the number\r
+  @retval (UINTN)(-1) An error ocurred.\r
+**/\r
+UINTN\r
+EFIAPI\r
+ReturnUintn(\r
+  IN CONST CHAR16 *String\r
+  )\r
+{\r
+  UINT64        RetVal;\r
+\r
+  if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, FALSE, FALSE))) {\r
+    return ((UINTN)RetVal);\r
+  }\r
+  return ((UINTN)(-1));\r
+}\r
+\r
 /**\r
   Function for 'for' command.\r
 \r
@@ -425,6 +448,7 @@ ShellCommandRunFor (
         //\r
         Info = AllocateZeroPool(sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]));\r
         ASSERT(Info != NULL);\r
+        Info->Signature = SHELL_FOR_INFO_SIGNATURE;\r
         CopyMem(Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize(gEfiShellParametersProtocol->Argv[1]));\r
         Info->ReplacementName = Info->Set;\r
         Info->CurrentValue    = NULL;\r
@@ -485,9 +509,9 @@ ShellCommandRunFor (
               ShellStatus = SHELL_INVALID_PARAMETER;\r
             } else {\r
               if (ArgSetWalker[0] == L'-') {\r
-                Info->Current = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);\r
+                Info->Current = 0 - (INTN)ReturnUintn(ArgSetWalker+1);\r
               } else {\r
-                Info->Current = (INTN)ShellStrToUintn(ArgSetWalker);\r
+                Info->Current = (INTN)ReturnUintn(ArgSetWalker);\r
               }\r
               ArgSetWalker  = StrStr(ArgSetWalker, L" ");\r
               while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {\r
@@ -507,9 +531,9 @@ ShellCommandRunFor (
                 ShellStatus = SHELL_INVALID_PARAMETER;\r
               } else {\r
                 if (ArgSetWalker[0] == L'-') {\r
-                  Info->End = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);\r
+                  Info->End = 0 - (INTN)ReturnUintn(ArgSetWalker+1);\r
                 } else {\r
-                  Info->End = (INTN)ShellStrToUintn(ArgSetWalker);\r
+                  Info->End = (INTN)ReturnUintn(ArgSetWalker);\r
                 }\r
                 if (Info->Current < Info->End) {\r
                   Info->Step            = 1;\r
@@ -539,9 +563,9 @@ ShellCommandRunFor (
                       ASSERT(Info->Step == 1 || Info->Step == -1);\r
                     } else {\r
                       if (ArgSetWalker[0] == L'-') {\r
-                        Info->Step = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);\r
+                        Info->Step = 0 - (INTN)ReturnUintn(ArgSetWalker+1);\r
                       } else {\r
-                        Info->Step = (INTN)ShellStrToUintn(ArgSetWalker);\r
+                        Info->Step = (INTN)ReturnUintn(ArgSetWalker);\r
                       }\r
 \r
                       if (StrStr(ArgSetWalker, L" ") != NULL) {\r
@@ -659,12 +683,9 @@ ShellCommandRunFor (
       //\r
       ASSERT(Info->Set != NULL);\r
       if (Info->CurrentValue != NULL && *Info->CurrentValue != CHAR_NULL) {\r
-        if (Info->CurrentValue[0] == L'\"') {\r
+        if (Info->CurrentValue[0] == L' ') {\r
           Info->CurrentValue++;\r
         }\r
-//        while (Info->CurrentValue[0] == L' ') {\r
-//          Info->CurrentValue++;\r
-//        }\r
         if (Info->CurrentValue[0] == L'\"') {\r
           Info->CurrentValue++;\r
         }\r