]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/Common/SimpleFileParsing.c
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / C / Common / SimpleFileParsing.c
index 868c6b794b99fa240a31e884131671b0e1b16f33..eb6abea1bec78daefbf04859b938a5786f466506 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
 Generic but simple file parsing routines.\r
 \r
-Copyright (c) 2004 - 2016, 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
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 --*/\r
 \r
@@ -238,7 +232,7 @@ Arguments:
   FileName  - name of the file to parse\r
 \r
 Returns:\r
-  \r
+\r
 \r
 --*/\r
 {\r
@@ -345,7 +339,7 @@ SFPGetNextToken (
 /*++\r
 \r
 Routine Description:\r
-  Get the next token from the input stream. \r
+  Get the next token from the input stream.\r
 \r
 Arguments:\r
   Str - pointer to a copy of the next token\r
@@ -356,7 +350,7 @@ Returns:
   FALSE - otherwise\r
 \r
 Notes:\r
-  Preceeding white space is ignored. \r
+  Preceding white space is ignored.\r
   The parser's buffer pointer is advanced past the end of the\r
   token.\r
 \r
@@ -580,7 +574,7 @@ Arguments:
   None.\r
 \r
 Returns:\r
-  STATUS_SUCCESS - the file was closed \r
+  STATUS_SUCCESS - the file was closed\r
   STATUS_ERROR   - no file is currently open\r
 \r
 --*/\r
@@ -605,7 +599,7 @@ ProcessIncludeFile (
 Routine Description:\r
 \r
   Given a source file, open the file and parse it\r
-  \r
+\r
 Arguments:\r
 \r
   SourceFile        - name of file to parse\r
@@ -614,7 +608,7 @@ Arguments:
 Returns:\r
 \r
   Standard status.\r
-  \r
+\r
 --*/\r
 {\r
   STATIC UINTN NestDepth = 0;\r
@@ -636,7 +630,7 @@ Returns:
   // Make sure we didn't exceed our maximum nesting depth\r
   //\r
   if (NestDepth > MAX_NEST_DEPTH) {\r
-    Error (NULL, 0, 3001, "Not Supported", "%s exceeeds max nesting depth (%u)", SourceFile->FileName, (unsigned) NestDepth);\r
+    Error (NULL, 0, 3001, "Not Supported", "%s exceeds max nesting depth (%u)", SourceFile->FileName, (unsigned) NestDepth);\r
     Status = STATUS_ERROR;\r
     goto Finish;\r
   }\r
@@ -674,7 +668,7 @@ Routine Description:
 \r
   Given a source file that's been opened, read the contents into an internal\r
   buffer and pre-process it to remove comments.\r
-  \r
+\r
 Arguments:\r
 \r
   SourceFile        - structure containing info on the file to process\r
@@ -682,7 +676,7 @@ Arguments:
 Returns:\r
 \r
   Standard status.\r
-  \r
+\r
 --*/\r
 {\r
   //\r
@@ -722,13 +716,13 @@ PreprocessFile (
 Routine Description:\r
   Preprocess a file to replace all carriage returns with NULLs so\r
   we can print lines (as part of error messages) from the file to the screen.\r
-  \r
+\r
 Arguments:\r
   SourceFile - structure that we use to keep track of an input file.\r
 \r
 Returns:\r
   Nothing.\r
-  \r
+\r
 --*/\r
 {\r
   BOOLEAN InComment;\r
@@ -826,8 +820,8 @@ SFPGetQuotedString (
 /*++\r
 \r
 Routine Description:\r
-  Retrieve a quoted-string from the input file. \r
-  \r
+  Retrieve a quoted-string from the input file.\r
+\r
 Arguments:\r
   Str    - pointer to a copy of the quoted string parsed\r
   Length - size of buffer pointed to by Str\r
@@ -836,7 +830,7 @@ Returns:
   TRUE    - next token in input stream was a quoted string, and\r
             the string value was returned in Str\r
   FALSE   - otherwise\r
-  \r
+\r
 --*/\r
 {\r
   SkipWhiteSpace (&mGlobals.SourceFile);\r
@@ -881,14 +875,14 @@ SFPIsEOF (
 Routine Description:\r
   Return TRUE of FALSE to indicate whether or not we've reached the end of the\r
   file we're parsing.\r
-  \r
+\r
 Arguments:\r
   NA\r
 \r
 Returns:\r
   TRUE    - EOF reached\r
   FALSE   - otherwise\r
-  \r
+\r
 --*/\r
 {\r
   SkipWhiteSpace (&mGlobals.SourceFile);\r
@@ -1232,12 +1226,10 @@ GetHexChars (
 {\r
   UINT32  Len;\r
   Len = 0;\r
-  while (!EndOfFile (&mGlobals.SourceFile) && (BufferLen > 0)) {\r
+  while (!EndOfFile (&mGlobals.SourceFile) && (Len < BufferLen)) {\r
     if (isxdigit ((int)mGlobals.SourceFile.FileBufferPtr[0])) {\r
-      *Buffer = mGlobals.SourceFile.FileBufferPtr[0];\r
-      Buffer++;\r
+      Buffer[Len] = mGlobals.SourceFile.FileBufferPtr[0];\r
       Len++;\r
-      BufferLen--;\r
       mGlobals.SourceFile.FileBufferPtr++;\r
     } else {\r
       break;\r
@@ -1246,8 +1238,8 @@ GetHexChars (
   //\r
   // Null terminate if we can\r
   //\r
-  if ((Len > 0) && (BufferLen > 0)) {\r
-    *Buffer = 0;\r
+  if ((Len > 0) && (Len < BufferLen)) {\r
+    Buffer[Len] = 0;\r
   }\r
 \r
   return Len;\r