]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/Common/ParseInf.c
Sync EDKII BaseTools to BaseTools project r1903.
[mirror_edk2.git] / BaseTools / Source / C / Common / ParseInf.c
index b39c5bde4022527333b78ce2914b0e1952cb8452..2ce25be86f365e95d8ce056cb8dfb81360ad16b9 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation                                                         \r
+Copyright (c) 2004 - 2010, Intel Corporation                                                         \r
 All rights reserved. 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
@@ -484,13 +484,14 @@ Returns:
 --*/\r
 {\r
   UINT8   Index;\r
-  UINT64  HexNumber;\r
+  UINT64  Value;\r
   CHAR8   CurrentChar;\r
   \r
   //\r
   // Initialize the result\r
   //\r
-  HexNumber = 0;\r
+  Value = 0;\r
+  Index = 0;\r
   \r
   //\r
   // Check input paramter\r
@@ -498,50 +499,65 @@ Returns:
   if (AsciiString == NULL || ReturnValue == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
+  while (AsciiString[Index] == ' ') {\r
+    Index ++;\r
+  }\r
+  \r
   //\r
   // Add each character to the result\r
   //\r
-  if (IsHex || (AsciiString[0] == '0' && (AsciiString[1] == 'x' || AsciiString[1] == 'X'))) {\r
-    //\r
-    // Verify string is a hex number\r
-    //\r
-    for (Index = 2; Index < strlen (AsciiString); Index++) {\r
-      if (isxdigit (AsciiString[Index]) == 0) {\r
-        return EFI_ABORTED;\r
-      }\r
-    }\r
+  if (IsHex || (AsciiString[Index] == '0' && (AsciiString[Index + 1] == 'x' || AsciiString[Index + 1] == 'X'))) {\r
     //\r
     // Convert the hex string.\r
     //\r
-    for (Index = 2; AsciiString[Index] != '\0'; Index++) {\r
+    for (Index = Index + 2; AsciiString[Index] != '\0'; Index++) {\r
       CurrentChar = AsciiString[Index];\r
-      HexNumber *= 16;\r
+      if (CurrentChar == ' ') {\r
+        break;\r
+      }\r
+      //\r
+      // Verify Hex string\r
+      //\r
+      if (isxdigit ((int)CurrentChar) == 0) {\r
+        return EFI_ABORTED;\r
+      }\r
+      //\r
+      // Add hex value\r
+      //\r
+      Value *= 16;\r
       if (CurrentChar >= '0' && CurrentChar <= '9') {\r
-        HexNumber += CurrentChar - '0';\r
+        Value += CurrentChar - '0';\r
       } else if (CurrentChar >= 'a' && CurrentChar <= 'f') {\r
-        HexNumber += CurrentChar - 'a' + 10;\r
+        Value += CurrentChar - 'a' + 10;\r
       } else if (CurrentChar >= 'A' && CurrentChar <= 'F') {\r
-        HexNumber += CurrentChar - 'A' + 10;\r
-      } else {\r
-        //\r
-        // Unrecognized character\r
-        //\r
-        return EFI_ABORTED;\r
+        Value += CurrentChar - 'A' + 10;\r
       }\r
     }\r
 \r
-    *ReturnValue = HexNumber;\r
+    *ReturnValue = Value;\r
   } else {\r
     //\r
-    // Verify string is a number\r
+    // Convert dec string is a number\r
     //\r
-    for (Index = 0; Index < strlen (AsciiString); Index++) {\r
-      if (isdigit (AsciiString[Index]) == 0) {\r
+    for (; Index < strlen (AsciiString); Index++) {\r
+      CurrentChar = AsciiString[Index];\r
+      if (CurrentChar == ' ') {\r
+        break;\r
+      }\r
+      //\r
+      // Verify Dec string\r
+      //\r
+      if (isdigit ((int)CurrentChar) == 0) {\r
         return EFI_ABORTED;\r
       }\r
+      //\r
+      // Add dec value\r
+      //\r
+      Value = Value * 10;\r
+      Value += CurrentChar - '0';\r
     }\r
 \r
-    *ReturnValue = atol (AsciiString);\r
+    *ReturnValue = Value;\r
   }\r
 \r
   return EFI_SUCCESS;\r