]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/TianoTools/GenFfsFile/SimpleFileParsing.c
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Source / TianoTools / GenFfsFile / SimpleFileParsing.c
diff --git a/Tools/Source/TianoTools/GenFfsFile/SimpleFileParsing.c b/Tools/Source/TianoTools/GenFfsFile/SimpleFileParsing.c
deleted file mode 100644 (file)
index 5fa5a22..0000000
+++ /dev/null
@@ -1,969 +0,0 @@
-/*++\r
-\r
-Copyright (c) 2004, 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
-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
-\r
-Module Name:\r
-\r
-  SimpleFileParsing.c  \r
-\r
-Abstract:\r
-\r
-  Generic but simple file parsing routines.\r
-\r
---*/\r
-\r
-#include <stdio.h>\r
-#include <string.h>\r
-#include <stdlib.h>\r
-#include <ctype.h>\r
-\r
-#include <Common/UefiBaseTypes.h>\r
-\r
-#include "EfiUtilityMsgs.h"\r
-#include "SimpleFileParsing.h"\r
-\r
-#define MAX_PATH                    255\r
-#define MAX_NEST_DEPTH              20  // just in case we get in an endless loop.\r
-#define MAX_STRING_IDENTIFIER_NAME  100 // number of wchars\r
-#define MAX_LINE_LEN                400\r
-\r
-#define T_CHAR_SPACE                ' '\r
-#define T_CHAR_NULL                 0\r
-#define T_CHAR_CR                   '\r'\r
-#define T_CHAR_TAB                  '\t'\r
-#define T_CHAR_LF                   '\n'\r
-#define T_CHAR_SLASH                '/'\r
-#define T_CHAR_BACKSLASH            '\\'\r
-#define T_CHAR_DOUBLE_QUOTE         '"'\r
-#define T_CHAR_LC_X                 'x'\r
-#define T_CHAR_0                    '0'\r
-\r
-//\r
-// We keep a linked list of these for the source files we process\r
-//\r
-typedef struct _SOURCE_FILE {\r
-  FILE                *Fptr;\r
-  T_CHAR              *FileBuffer;\r
-  T_CHAR              *FileBufferPtr;\r
-  UINT32              FileSize;\r
-  INT8                FileName[MAX_PATH];\r
-  UINT32              LineNum;\r
-  BOOLEAN             EndOfFile;\r
-  BOOLEAN             SkipToHash;\r
-  struct _SOURCE_FILE *Previous;\r
-  struct _SOURCE_FILE *Next;\r
-  T_CHAR              ControlCharacter;\r
-} SOURCE_FILE;\r
-\r
-//\r
-// Here's all our module globals.\r
-//\r
-static struct {\r
-  SOURCE_FILE SourceFile;\r
-  BOOLEAN     Verbose;\r
-} mGlobals;\r
-\r
-static\r
-UINT32\r
-t_strcmp (\r
-  T_CHAR *Buffer,\r
-  T_CHAR *Str\r
-  );\r
-\r
-static\r
-UINT32\r
-t_strncmp (\r
-  T_CHAR *Str1,\r
-  T_CHAR *Str2,\r
-  UINT32 Len\r
-  );\r
-\r
-static\r
-UINT32\r
-t_strlen (\r
-  T_CHAR *Str\r
-  );\r
-\r
-static\r
-void\r
-RewindFile (\r
-  SOURCE_FILE *SourceFile\r
-  );\r
-\r
-static\r
-BOOLEAN\r
-SkipTo (\r
-  SOURCE_FILE *SourceFile,\r
-  T_CHAR      TChar,\r
-  BOOLEAN     StopAfterNewline\r
-  );\r
-\r
-static\r
-BOOLEAN\r
-IsWhiteSpace (\r
-  SOURCE_FILE *SourceFile\r
-  );\r
-\r
-static\r
-UINT32\r
-SkipWhiteSpace (\r
-  SOURCE_FILE *SourceFile\r
-  );\r
-\r
-static\r
-BOOLEAN\r
-EndOfFile (\r
-  SOURCE_FILE *SourceFile\r
-  );\r
-\r
-static\r
-void\r
-PreprocessFile (\r
-  SOURCE_FILE *SourceFile\r
-  );\r
-\r
-//\r
-// static\r
-// T_CHAR *\r
-// GetQuotedString (\r
-//  SOURCE_FILE *SourceFile,\r
-//  BOOLEAN     Optional\r
-//  );\r
-//\r
-static\r
-T_CHAR  *\r
-t_strcpy (\r
-  T_CHAR *Dest,\r
-  T_CHAR *Src\r
-  );\r
-\r
-static\r
-STATUS\r
-ProcessIncludeFile (\r
-  SOURCE_FILE *SourceFile,\r
-  SOURCE_FILE *ParentSourceFile\r
-  );\r
-\r
-static\r
-STATUS\r
-ParseFile (\r
-  SOURCE_FILE *SourceFile\r
-  );\r
-\r
-static\r
-FILE    *\r
-FindFile (\r
-  IN INT8     *FileName,\r
-  OUT INT8    *FoundFileName,\r
-  IN UINT32   FoundFileNameLen\r
-  );\r
-\r
-static\r
-STATUS\r
-ProcessFile (\r
-  SOURCE_FILE *SourceFile\r
-  );\r
-\r
-STATUS\r
-SFPInit (\r
-  VOID\r
-  )\r
-{\r
-  memset ((void *) &mGlobals, 0, sizeof (mGlobals));\r
-  return STATUS_SUCCESS;\r
-}\r
-\r
-UINT32\r
-SFPGetLineNumber (\r
-  VOID\r
-  )\r
-{\r
-  return mGlobals.SourceFile.LineNum;\r
-}\r
-\r
-/*++\r
-\r
-Routine Description:\r
-  Return the line number of the file we're parsing. Used\r
-  for error reporting purposes.\r
-\r
-Arguments:\r
-  None.\r
-\r
-Returns:\r
-  The line number, or 0 if no file is being processed\r
-\r
---*/\r
-T_CHAR *\r
-SFPGetFileName (\r
-  VOID\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  Return the name of the file we're parsing. Used\r
-  for error reporting purposes.\r
-\r
-Arguments:\r
-  None.\r
-\r
-Returns:\r
-  A pointer to the file name. Null if no file is being\r
-  processed.\r
-\r
---*/\r
-{\r
-  if (mGlobals.SourceFile.FileName[0]) {\r
-    return mGlobals.SourceFile.FileName;\r
-  }\r
-\r
-  return NULL;\r
-}\r
-\r
-STATUS\r
-SFPOpenFile (\r
-  IN INT8   *FileName\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  Open a file for parsing.\r
-\r
-Arguments:\r
-  FileName  - name of the file to parse\r
-\r
-Returns:\r
-  \r
-\r
---*/\r
-{\r
-  STATUS  Status;\r
-  t_strcpy (mGlobals.SourceFile.FileName, FileName);\r
-  Status = ProcessIncludeFile (&mGlobals.SourceFile, NULL);\r
-  return Status;\r
-}\r
-\r
-BOOLEAN\r
-SFPIsToken (\r
-  T_CHAR *Str\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  Check to see if the specified token is found at\r
-  the current position in the input file.\r
-\r
-Arguments:\r
-  Str - the token to look for\r
-\r
-Returns:\r
-  TRUE - the token is next\r
-  FALSE - the token is not next\r
-\r
-Notes:\r
-  We do a simple string comparison on this function. It is\r
-  the responsibility of the caller to ensure that the token\r
-  is not a subset of some other token.\r
-\r
-  The file pointer is advanced past the token in the input file.\r
-\r
---*/\r
-{\r
-  UINT32  Len;\r
-  SkipWhiteSpace (&mGlobals.SourceFile);\r
-\r
-  if ((Len = t_strcmp (mGlobals.SourceFile.FileBufferPtr, Str)) > 0) {\r
-    mGlobals.SourceFile.FileBufferPtr += Len;\r
-    return TRUE;\r
-  }\r
-\r
-  return FALSE;\r
-\r
-}\r
-\r
-BOOLEAN\r
-SFPGetNextToken (\r
-  T_CHAR *Str,\r
-  UINT32 Len\r
-  )\r
-{\r
-  UINT32  Index;\r
-  SkipWhiteSpace (&mGlobals.SourceFile);\r
-  Index = 0;\r
-  while (!EndOfFile (&mGlobals.SourceFile) && (Index < Len)) {\r
-    if (IsWhiteSpace (&mGlobals.SourceFile)) {\r
-      if (Index > 0) {\r
-        Str[Index] = 0;\r
-        return TRUE;\r
-      }\r
-\r
-      return FALSE;\r
-    } else {\r
-      Str[Index] = mGlobals.SourceFile.FileBufferPtr[0];\r
-      mGlobals.SourceFile.FileBufferPtr++;\r
-      Index++;\r
-    }\r
-  }\r
-\r
-  return FALSE;\r
-}\r
-\r
-BOOLEAN\r
-SFPSkipToToken (\r
-  T_CHAR *Str\r
-  )\r
-{\r
-  UINT32  Len;\r
-  T_CHAR  *SavePos;\r
-  Len     = t_strlen (Str);\r
-  SavePos = mGlobals.SourceFile.FileBufferPtr;\r
-  SkipWhiteSpace (&mGlobals.SourceFile);\r
-  while (!EndOfFile (&mGlobals.SourceFile)) {\r
-    if (t_strncmp (Str, mGlobals.SourceFile.FileBufferPtr, Len) == 0) {\r
-      mGlobals.SourceFile.FileBufferPtr += Len;\r
-      return TRUE;\r
-    }\r
-\r
-    mGlobals.SourceFile.FileBufferPtr++;\r
-    SkipWhiteSpace (&mGlobals.SourceFile);\r
-  }\r
-\r
-  mGlobals.SourceFile.FileBufferPtr = SavePos;\r
-  return FALSE;\r
-}\r
-\r
-BOOLEAN\r
-SFPGetNumber (\r
-  UINT32   *Value\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  Check the token at the current file position for a numeric value.\r
-  May be either decimal or hex.\r
-\r
-Arguments:\r
-  Value  - pointer where to store the value\r
-\r
-Returns:\r
-  FALSE    - current token is not a number\r
-  TRUE     - current token is a number\r
-\r
---*/\r
-{\r
-  //\r
-  //  UINT32 Len;\r
-  //\r
-  SkipWhiteSpace (&mGlobals.SourceFile);\r
-  if (EndOfFile (&mGlobals.SourceFile)) {\r
-    return FALSE;\r
-  }\r
-\r
-  if (isdigit (mGlobals.SourceFile.FileBufferPtr[0])) {\r
-    //\r
-    // Check for hex value\r
-    //\r
-    if ((mGlobals.SourceFile.FileBufferPtr[0] == T_CHAR_0) && (mGlobals.SourceFile.FileBufferPtr[1] == T_CHAR_LC_X)) {\r
-      if (!isxdigit (mGlobals.SourceFile.FileBufferPtr[2])) {\r
-        return FALSE;\r
-      }\r
-\r
-      mGlobals.SourceFile.FileBufferPtr += 2;\r
-      sscanf (mGlobals.SourceFile.FileBufferPtr, "%x", Value);\r
-      while (isxdigit (mGlobals.SourceFile.FileBufferPtr[0])) {\r
-        mGlobals.SourceFile.FileBufferPtr++;\r
-      }\r
-\r
-      return TRUE;\r
-    } else {\r
-      *Value = atoi (mGlobals.SourceFile.FileBufferPtr);\r
-      while (isdigit (mGlobals.SourceFile.FileBufferPtr[0])) {\r
-        mGlobals.SourceFile.FileBufferPtr++;\r
-      }\r
-\r
-      return TRUE;\r
-    }\r
-  } else {\r
-    return FALSE;\r
-  }\r
-}\r
-\r
-STATUS\r
-SFPCloseFile (\r
-  VOID\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  Close the file being parsed.\r
-\r
-Arguments:\r
-  None.\r
-\r
-Returns:\r
-  STATUS_SUCCESS - the file was closed \r
-  STATUS_ERROR   - no file is currently open\r
-\r
---*/\r
-{\r
-  if (mGlobals.SourceFile.FileBuffer != NULL) {\r
-    free (mGlobals.SourceFile.FileBuffer);\r
-    memset (&mGlobals.SourceFile, 0, sizeof (mGlobals.SourceFile));\r
-    return STATUS_SUCCESS;\r
-  }\r
-\r
-  return STATUS_ERROR;\r
-}\r
-\r
-static\r
-STATUS\r
-ProcessIncludeFile (\r
-  SOURCE_FILE *SourceFile,\r
-  SOURCE_FILE *ParentSourceFile\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Given a source file, open the file and parse it\r
-  \r
-Arguments:\r
-\r
-  SourceFile        - name of file to parse\r
-  ParentSourceFile  - for error reporting purposes, the file that #included SourceFile.\r
-\r
-Returns:\r
-\r
-  Standard status.\r
-  \r
---*/\r
-{\r
-  static UINT32 NestDepth = 0;\r
-  INT8          FoundFileName[MAX_PATH];\r
-  STATUS        Status;\r
-\r
-  Status = STATUS_SUCCESS;\r
-  NestDepth++;\r
-  //\r
-  // Print the file being processed. Indent so you can tell the include nesting\r
-  // depth.\r
-  //\r
-  if (mGlobals.Verbose) {\r
-    fprintf (stdout, "%*cProcessing file '%s'\n", NestDepth * 2, ' ', SourceFile->FileName);\r
-  }\r
-\r
-  //\r
-  // Make sure we didn't exceed our maximum nesting depth\r
-  //\r
-  if (NestDepth > MAX_NEST_DEPTH) {\r
-    Error (NULL, 0, 0, SourceFile->FileName, "max nesting depth (%d) exceeded", NestDepth);\r
-    Status = STATUS_ERROR;\r
-    goto Finish;\r
-  }\r
-  //\r
-  // Try to open the file locally, and if that fails try along our include paths.\r
-  //\r
-  strcpy (FoundFileName, SourceFile->FileName);\r
-  if ((SourceFile->Fptr = fopen (FoundFileName, "r")) == NULL) {\r
-    //\r
-    // Try to find it among the paths if it has a parent (that is, it is included\r
-    // by someone else).\r
-    //\r
-    Error (NULL, 0, 0, SourceFile->FileName, "file not found");\r
-    return STATUS_ERROR;\r
-  }\r
-  //\r
-  // Process the file found\r
-  //\r
-  ProcessFile (SourceFile);\r
-Finish:\r
-  //\r
-  // Close open files and return status\r
-  //\r
-  if (SourceFile->Fptr != NULL) {\r
-    fclose (SourceFile->Fptr);\r
-    SourceFile->Fptr = NULL;\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
-static\r
-STATUS\r
-ProcessFile (\r
-  SOURCE_FILE *SourceFile\r
-  )\r
-{\r
-  //\r
-  // Get the file size, and then read the entire thing into memory.\r
-  // Allocate space for a terminator character.\r
-  //\r
-  fseek (SourceFile->Fptr, 0, SEEK_END);\r
-  SourceFile->FileSize = ftell (SourceFile->Fptr);\r
-  fseek (SourceFile->Fptr, 0, SEEK_SET);\r
-  SourceFile->FileBuffer = (T_CHAR *) malloc (SourceFile->FileSize + sizeof (T_CHAR));\r
-  if (SourceFile->FileBuffer == NULL) {\r
-    Error (NULL, 0, 0, "memory allocation failure", NULL);\r
-    return STATUS_ERROR;\r
-  }\r
-\r
-  fread ((VOID *) SourceFile->FileBuffer, SourceFile->FileSize, 1, SourceFile->Fptr);\r
-  SourceFile->FileBuffer[(SourceFile->FileSize / sizeof (T_CHAR))] = T_CHAR_NULL;\r
-  //\r
-  // Pre-process the file to replace comments with spaces\r
-  //\r
-  PreprocessFile (SourceFile);\r
-  SourceFile->LineNum = 1;\r
-  return STATUS_SUCCESS;\r
-}\r
-\r
-static\r
-void\r
-PreprocessFile (\r
-  SOURCE_FILE *SourceFile\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  Preprocess a file to replace all carriage returns with NULLs so\r
-  we can print lines from the file to the screen.\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
-  BOOLEAN InComment;\r
-\r
-  RewindFile (SourceFile);\r
-  InComment = FALSE;\r
-  while (!EndOfFile (SourceFile)) {\r
-    //\r
-    // If a line-feed, then no longer in a comment\r
-    //\r
-    if (SourceFile->FileBufferPtr[0] == T_CHAR_LF) {\r
-      SourceFile->FileBufferPtr++;\r
-      SourceFile->LineNum++;\r
-      InComment = 0;\r
-    } else if (SourceFile->FileBufferPtr[0] == T_CHAR_CR) {\r
-      //\r
-      // Replace all carriage returns with a NULL so we can print stuff\r
-      //\r
-      SourceFile->FileBufferPtr[0] = 0;\r
-      SourceFile->FileBufferPtr++;\r
-    } else if (InComment) {\r
-      SourceFile->FileBufferPtr[0] = T_CHAR_SPACE;\r
-      SourceFile->FileBufferPtr++;\r
-    } else if ((SourceFile->FileBufferPtr[0] == T_CHAR_SLASH) && (SourceFile->FileBufferPtr[1] == T_CHAR_SLASH)) {\r
-      SourceFile->FileBufferPtr += 2;\r
-      InComment = TRUE;\r
-    } else {\r
-      SourceFile->FileBufferPtr++;\r
-    }\r
-  }\r
-  //\r
-  // Could check for end-of-file and still in a comment, but\r
-  // should not be necessary. So just restore the file pointers.\r
-  //\r
-  RewindFile (SourceFile);\r
-}\r
-\r
-#if 0\r
-static\r
-T_CHAR *\r
-GetQuotedString (\r
-  SOURCE_FILE *SourceFile,\r
-  BOOLEAN     Optional\r
-  )\r
-{\r
-  T_CHAR  *String;\r
-  T_CHAR  *Start;\r
-  T_CHAR  *Ptr;\r
-  UINT32  Len;\r
-  BOOLEAN PreviousBackslash;\r
-\r
-  if (SourceFile->FileBufferPtr[0] != T_CHAR_DOUBLE_QUOTE) {\r
-    if (!Optional) {\r
-      Error (SourceFile->FileName, SourceFile->LineNum, 0, "expected quoted string", "%S", SourceFile->FileBufferPtr);\r
-    }\r
-\r
-    return NULL;\r
-  }\r
-\r
-  Len = 0;\r
-  SourceFile->FileBufferPtr++;\r
-  Start             = Ptr = SourceFile->FileBufferPtr;\r
-  PreviousBackslash = FALSE;\r
-  while (!EndOfFile (SourceFile)) {\r
-    if ((SourceFile->FileBufferPtr[0] == T_CHAR_DOUBLE_QUOTE) && (!PreviousBackslash)) {\r
-      break;\r
-    } else if (SourceFile->FileBufferPtr[0] == T_CHAR_CR) {\r
-      Warning (SourceFile->FileName, SourceFile->LineNum, 0, "carriage return found in quoted string", "%S", Start);\r
-      PreviousBackslash = FALSE;\r
-    } else if (SourceFile->FileBufferPtr[0] == T_CHAR_BACKSLASH) {\r
-      PreviousBackslash = TRUE;\r
-    } else {\r
-      PreviousBackslash = FALSE;\r
-    }\r
-\r
-    SourceFile->FileBufferPtr++;\r
-    Len++;\r
-  }\r
-\r
-  if (SourceFile->FileBufferPtr[0] != T_CHAR_DOUBLE_QUOTE) {\r
-    Warning (SourceFile->FileName, SourceFile->LineNum, 0, "missing closing quote on string", "%S", Start);\r
-  } else {\r
-    SourceFile->FileBufferPtr++;\r
-  }\r
-  //\r
-  // Now allocate memory for the string and save it off\r
-  //\r
-  String = (T_CHAR *) malloc ((Len + 1) * sizeof (T_CHAR));\r
-  if (String == NULL) {\r
-    Error (NULL, 0, 0, "memory allocation failed", NULL);\r
-    return NULL;\r
-  }\r
-  //\r
-  // Copy the string from the file buffer to the local copy.\r
-  // We do no reformatting of it whatsoever at this point.\r
-  //\r
-  Ptr = String;\r
-  while (Len > 0) {\r
-    *Ptr = *Start;\r
-    Start++;\r
-    Ptr++;\r
-    Len--;\r
-  }\r
-\r
-  *Ptr = 0;\r
-  return String;\r
-}\r
-#endif\r
-static\r
-BOOLEAN\r
-EndOfFile (\r
-  SOURCE_FILE *SourceFile\r
-  )\r
-{\r
-  //\r
-  // The file buffer pointer will typically get updated before the End-of-file flag in the\r
-  // source file structure, so check it first.\r
-  //\r
-  if (SourceFile->FileBufferPtr >= SourceFile->FileBuffer + SourceFile->FileSize / sizeof (T_CHAR)) {\r
-    SourceFile->EndOfFile = TRUE;\r
-    return TRUE;\r
-  }\r
-\r
-  if (SourceFile->EndOfFile) {\r
-    return TRUE;\r
-  }\r
-\r
-  return FALSE;\r
-}\r
-\r
-#if 0\r
-static\r
-void\r
-ProcessTokenInclude (\r
-  SOURCE_FILE *SourceFile\r
-  )\r
-{\r
-  INT8        IncludeFileName[MAX_PATH];\r
-  INT8        *To;\r
-  UINT32      Len;\r
-  BOOLEAN     ReportedError;\r
-  SOURCE_FILE IncludedSourceFile;\r
-\r
-  ReportedError = FALSE;\r
-  if (SkipWhiteSpace (SourceFile) == 0) {\r
-    Warning (SourceFile->FileName, SourceFile->LineNum, 0, "expected whitespace following #include keyword", NULL);\r
-  }\r
-  //\r
-  // Should be quoted file name\r
-  //\r
-  if (SourceFile->FileBufferPtr[0] != T_CHAR_DOUBLE_QUOTE) {\r
-    Error (SourceFile->FileName, SourceFile->LineNum, 0, "expected quoted include file name", NULL);\r
-    goto FailDone;\r
-  }\r
-\r
-  SourceFile->FileBufferPtr++;\r
-  //\r
-  // Copy the filename as ascii to our local string\r
-  //\r
-  To  = IncludeFileName;\r
-  Len = 0;\r
-  while (!EndOfFile (SourceFile)) {\r
-    if ((SourceFile->FileBufferPtr[0] == T_CHAR_CR) || (SourceFile->FileBufferPtr[0] == T_CHAR_LF)) {\r
-      Error (SourceFile->FileName, SourceFile->LineNum, 0, "end-of-line found in quoted include file name", NULL);\r
-      goto FailDone;\r
-    }\r
-\r
-    if (SourceFile->FileBufferPtr[0] == T_CHAR_DOUBLE_QUOTE) {\r
-      SourceFile->FileBufferPtr++;\r
-      break;\r
-    }\r
-    //\r
-    // If too long, then report the error once and process until the closing quote\r
-    //\r
-    Len++;\r
-    if (!ReportedError && (Len >= sizeof (IncludeFileName))) {\r
-      Error (SourceFile->FileName, SourceFile->LineNum, 0, "length of include file name exceeds limit", NULL);\r
-      ReportedError = TRUE;\r
-    }\r
-\r
-    if (!ReportedError) {\r
-      //\r
-      // *To = UNICODE_TO_ASCII(SourceFile->FileBufferPtr[0]);\r
-      //\r
-      *To = (T_CHAR) SourceFile->FileBufferPtr[0];\r
-      To++;\r
-    }\r
-\r
-    SourceFile->FileBufferPtr++;\r
-  }\r
-\r
-  if (!ReportedError) {\r
-    *To = 0;\r
-    memset ((char *) &IncludedSourceFile, 0, sizeof (SOURCE_FILE));\r
-    strcpy (IncludedSourceFile.FileName, IncludeFileName);\r
-    //\r
-    // IncludedSourceFile.ControlCharacter = DEFAULT_CONTROL_CHARACTER;\r
-    //\r
-    ProcessIncludeFile (&IncludedSourceFile, SourceFile);\r
-    //\r
-    // printf ("including file '%s'\n", IncludeFileName);\r
-    //\r
-  }\r
-\r
-  return ;\r
-FailDone:\r
-  //\r
-  // Error recovery -- skip to next #\r
-  //\r
-  SourceFile->SkipToHash = TRUE;\r
-}\r
-#endif\r
-static\r
-BOOLEAN\r
-IsWhiteSpace (\r
-  SOURCE_FILE *SourceFile\r
-  )\r
-{\r
-  switch (*SourceFile->FileBufferPtr) {\r
-  case T_CHAR_NULL:\r
-  case T_CHAR_CR:\r
-  case T_CHAR_SPACE:\r
-  case T_CHAR_TAB:\r
-  case T_CHAR_LF:\r
-    return TRUE;\r
-\r
-  default:\r
-    return FALSE;\r
-  }\r
-}\r
-\r
-UINT32\r
-SkipWhiteSpace (\r
-  SOURCE_FILE *SourceFile\r
-  )\r
-{\r
-  UINT32  Count;\r
-\r
-  Count = 0;\r
-  while (!EndOfFile (SourceFile)) {\r
-    Count++;\r
-    switch (*SourceFile->FileBufferPtr) {\r
-    case T_CHAR_NULL:\r
-    case T_CHAR_CR:\r
-    case T_CHAR_SPACE:\r
-    case T_CHAR_TAB:\r
-      SourceFile->FileBufferPtr++;\r
-      break;\r
-\r
-    case T_CHAR_LF:\r
-      SourceFile->FileBufferPtr++;\r
-      SourceFile->LineNum++;\r
-      if (mGlobals.Verbose) {\r
-        printf ("%d: %S\n", SourceFile->LineNum, SourceFile->FileBufferPtr);\r
-      }\r
-      break;\r
-\r
-    default:\r
-      return Count - 1;\r
-    }\r
-  }\r
-  //\r
-  // Some tokens require trailing whitespace. If we're at the end of the\r
-  // file, then we count that as well.\r
-  //\r
-  if ((Count == 0) && (EndOfFile (SourceFile))) {\r
-    Count++;\r
-  }\r
-\r
-  return Count;\r
-}\r
-\r
-static\r
-UINT32\r
-t_strcmp (\r
-  T_CHAR *Buffer,\r
-  T_CHAR *Str\r
-  )\r
-{\r
-  UINT32  Len;\r
-\r
-  Len = 0;\r
-  while (*Str == *Buffer) {\r
-    Buffer++;\r
-    Str++;\r
-    Len++;\r
-  }\r
-\r
-  if (*Str) {\r
-    return 0;\r
-  }\r
-\r
-  return Len;\r
-}\r
-\r
-static\r
-UINT32\r
-t_strlen (\r
-  T_CHAR *Str\r
-  )\r
-{\r
-  UINT32  Len;\r
-  Len = 0;\r
-  while (*Str) {\r
-    Len++;\r
-    Str++;\r
-  }\r
-\r
-  return Len;\r
-}\r
-\r
-static\r
-UINT32\r
-t_strncmp (\r
-  T_CHAR *Str1,\r
-  T_CHAR *Str2,\r
-  UINT32 Len\r
-  )\r
-{\r
-  while (Len > 0) {\r
-    if (*Str1 != *Str2) {\r
-      return Len;\r
-    }\r
-\r
-    Len--;\r
-    Str1++;\r
-    Str2++;\r
-  }\r
-\r
-  return 0;\r
-}\r
-\r
-static\r
-T_CHAR *\r
-t_strcpy (\r
-  T_CHAR *Dest,\r
-  T_CHAR *Src\r
-  )\r
-{\r
-  T_CHAR  *SaveDest;\r
-  SaveDest = Dest;\r
-  while (*Src) {\r
-    *Dest = *Src;\r
-    Dest++;\r
-    Src++;\r
-  }\r
-\r
-  *Dest = 0;\r
-  return SaveDest;\r
-}\r
-\r
-#if 0\r
-static\r
-BOOLEAN\r
-IsValidIdentifierChar (\r
-  INT8      Char,\r
-  BOOLEAN   FirstChar\r
-  )\r
-{\r
-  //\r
-  // If it's the first character of an identifier, then\r
-  // it must be one of [A-Za-z_].\r
-  //\r
-  if (FirstChar) {\r
-    if (isalpha (Char) || (Char == '_')) {\r
-      return TRUE;\r
-    }\r
-  } else {\r
-    //\r
-    // If it's not the first character, then it can\r
-    // be one of [A-Za-z_0-9]\r
-    //\r
-    if (isalnum (Char) || (Char == '_')) {\r
-      return TRUE;\r
-    }\r
-  }\r
-\r
-  return FALSE;\r
-}\r
-#endif\r
-static\r
-void\r
-RewindFile (\r
-  SOURCE_FILE *SourceFile\r
-  )\r
-{\r
-  SourceFile->LineNum       = 1;\r
-  SourceFile->FileBufferPtr = SourceFile->FileBuffer;\r
-  SourceFile->EndOfFile     = 0;\r
-}\r
-\r
-#if 0\r
-static\r
-BOOLEAN\r
-SkipTo (\r
-  SOURCE_FILE  *SourceFile,\r
-  T_CHAR       TChar,\r
-  BOOLEAN      StopAfterNewline\r
-  )\r
-{\r
-  while (!EndOfFile (SourceFile)) {\r
-    //\r
-    // Check for the character of interest\r
-    //\r
-    if (SourceFile->FileBufferPtr[0] == TChar) {\r
-      return TRUE;\r
-    } else {\r
-      if (SourceFile->FileBufferPtr[0] == T_CHAR_LF) {\r
-        SourceFile->LineNum++;\r
-        if (StopAfterNewline) {\r
-          SourceFile->FileBufferPtr++;\r
-          if (SourceFile->FileBufferPtr[0] == 0) {\r
-            SourceFile->FileBufferPtr++;\r
-          }\r
-\r
-          return FALSE;\r
-        }\r
-      }\r
-\r
-      SourceFile->FileBufferPtr++;\r
-    }\r
-  }\r
-\r
-  return FALSE;\r
-}\r
-#endif\r