/** @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
FileName - name of the file to parse\r
\r
Returns:\r
- \r
+\r
\r
--*/\r
{\r
/*++\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
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
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
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
Returns:\r
\r
Standard status.\r
- \r
+\r
--*/\r
{\r
STATIC UINTN NestDepth = 0;\r
// 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
\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
Returns:\r
\r
Standard status.\r
- \r
+\r
--*/\r
{\r
//\r
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
/*++\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
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
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
{\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
//\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