]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Sample/Tools/Source/UefiVfrCompile/VfrError.cpp
1) Sync EdkCompatibilityPkg with EDK 1.04. The changes includes:
[mirror_edk2.git] / EdkCompatibilityPkg / Sample / Tools / Source / UefiVfrCompile / VfrError.cpp
diff --git a/EdkCompatibilityPkg/Sample/Tools/Source/UefiVfrCompile/VfrError.cpp b/EdkCompatibilityPkg/Sample/Tools/Source/UefiVfrCompile/VfrError.cpp
new file mode 100644 (file)
index 0000000..e157577
--- /dev/null
@@ -0,0 +1,197 @@
+#include "stdio.h"\r
+#include "string.h"\r
+#include "stdlib.h"\r
+#include "VfrError.h"\r
+\r
+static SVFR_ERROR_HANDLE VFR_ERROR_HANDLE_TABLE [] = {\r
+  { VFR_RETURN_SUCCESS, NULL },\r
+  { VFR_RETURN_ERROR_SKIPED, NULL },\r
+  { VFR_RETURN_FATAL_ERROR, "fatal error!!" },\r
+\r
+  { VFR_RETURN_MISMATCHED, "unexpected token" },\r
+  { VFR_RETURN_INVALID_PARAMETER, "Invalid parameter" },\r
+  { VFR_RETURN_OUT_FOR_RESOURCES, "system out of memory" },\r
+  { VFR_RETURN_UNSUPPORTED, "unsupported" },\r
+  { VFR_RETURN_REDEFINED, "already defined" },\r
+  { VFR_RETURN_FORMID_REDEFINED, "form id already defined" },\r
+  { VFR_RETURN_QUESTIONID_REDEFINED, "question id already defined" },\r
+  { VFR_RETURN_VARSTOREID_REDEFINED, "varstore id already defined" },\r
+  { VFR_RETURN_UNDEFINED, "undefined" },\r
+  { VFR_RETURN_VAR_NOTDEFINED_BY_QUESTION, "some variable has not defined by a question"},\r
+  { VFR_RETURN_GET_EFIVARSTORE_ERROR, "get efi varstore error"},\r
+  { VFR_RETURN_EFIVARSTORE_USE_ERROR, "can not use the efi varstore like this" },\r
+  { VFR_RETURN_EFIVARSTORE_SIZE_ERROR, "unsupport efi varstore size should be <= 8 bytes" },\r
+  { VFR_RETURN_GET_NVVARSTORE_ERROR, "get name value varstore error" },\r
+  { VFR_RETURN_QVAR_REUSE, "variable reused by more than one question" }, \r
+  { VFR_RETURN_FLAGS_UNSUPPORTED, "flags unsupported" }, \r
+  { VFR_RETURN_ERROR_ARRARY_NUM, "array number error" },\r
+  { VFR_RETURN_DATA_STRING_ERROR, "data field string error or not support"},\r
+  { VFR_RETURN_CODEUNDEFINED, "Undefined Error Code" }\r
+};\r
+\r
+CVfrErrorHandle::CVfrErrorHandle (\r
+  VOID\r
+  )\r
+{\r
+  mScopeRecordListHead = NULL;\r
+  mScopeRecordListTail = NULL;\r
+  mVfrErrorHandleTable = VFR_ERROR_HANDLE_TABLE;\r
+}\r
+\r
+CVfrErrorHandle::~CVfrErrorHandle (\r
+  VOID\r
+  )\r
+{\r
+  SVfrFileScopeRecord *pNode = NULL;\r
+\r
+  while (mScopeRecordListHead != NULL) {\r
+    pNode = mScopeRecordListHead;\r
+    mScopeRecordListHead = mScopeRecordListHead->mNext;\r
+    delete pNode;\r
+  }\r
+\r
+  mScopeRecordListHead = NULL;\r
+  mScopeRecordListTail = NULL;\r
+  mVfrErrorHandleTable = NULL;\r
+}\r
+\r
+SVfrFileScopeRecord::SVfrFileScopeRecord (\r
+  IN INT8     *Record, \r
+  IN UINT32   LineNum\r
+  )\r
+{\r
+  UINT32      Index;\r
+  INT8        *FileName = NULL;\r
+  INT8        *Str      = NULL;\r
+\r
+  mWholeScopeLine      = LineNum;\r
+  mNext                = NULL;\r
+\r
+  Str = strchr (Record, ' ');\r
+  mScopeLineStart = atoi (++Str);\r
+\r
+  Str = strchr (Str, '\"');\r
+  FileName = ++Str;\r
+\r
+  while((Str = strstr (FileName, "\\\\")) != NULL) {\r
+    FileName = Str + 2;\r
+  }\r
+  if ((mFileName = new INT8[strlen(FileName)]) != NULL) {\r
+    for (Index = 0; FileName[Index] != '\"'; Index++) {\r
+      mFileName[Index] = FileName[Index];\r
+    }\r
+    mFileName[Index] = '\0';\r
+  }\r
+\r
+  return;\r
+}\r
+\r
+SVfrFileScopeRecord::~SVfrFileScopeRecord (\r
+  VOID\r
+  )\r
+{\r
+  if (mFileName != NULL) {\r
+    delete mFileName;\r
+  }\r
+}\r
+\r
+VOID\r
+CVfrErrorHandle::ParseFileScopeRecord (\r
+  IN INT8      *Record, \r
+  IN UINT32    WholeScopeLine\r
+  )\r
+{\r
+  INT8                *FullPathName = NULL;\r
+  SVfrFileScopeRecord *pNode        = NULL;\r
+\r
+  if (Record == NULL) {\r
+    return;\r
+  }\r
+\r
+  if ((pNode = new SVfrFileScopeRecord(Record, WholeScopeLine)) == NULL) {\r
+    return;\r
+  }\r
+\r
+  if (mScopeRecordListHead == NULL) {\r
+    mScopeRecordListTail = mScopeRecordListHead = pNode;\r
+  } else {\r
+    mScopeRecordListTail->mNext = pNode;\r
+    mScopeRecordListTail        = pNode;\r
+  }\r
+}\r
+\r
+VOID\r
+CVfrErrorHandle::GetFileNameLineNum (\r
+  IN  UINT32 LineNum,\r
+  OUT INT8   **FileName,\r
+  OUT UINT32 *FileLine\r
+  )\r
+{\r
+  SVfrFileScopeRecord *pNode    = NULL;\r
+\r
+  if ((FileName == NULL) || (FileLine == NULL)) {\r
+    return;\r
+  }\r
+\r
+  *FileName = NULL;\r
+  *FileLine = 0xFFFFFFFF;\r
+\r
+  for (pNode = mScopeRecordListHead; pNode->mNext != NULL; pNode = pNode->mNext) {\r
+    if ((LineNum > pNode->mWholeScopeLine) && (pNode->mNext->mWholeScopeLine > LineNum)) {\r
+      *FileName = pNode->mFileName;\r
+      *FileLine = LineNum - pNode->mWholeScopeLine + pNode->mScopeLineStart - 1;\r
+      return ;\r
+    }\r
+  }\r
+\r
+  *FileName = pNode->mFileName;\r
+  *FileLine = LineNum - pNode->mWholeScopeLine + pNode->mScopeLineStart - 1;\r
+}\r
+\r
+VOID\r
+CVfrErrorHandle::PrintError (\r
+  IN UINT32               LineNum,\r
+  IN INT8                 *TokName,\r
+  IN INT8                 *ErrorMsg\r
+  )\r
+{\r
+  INT8                   *FileName = NULL;\r
+  UINT32                 FileLine;\r
+\r
+  GetFileNameLineNum (LineNum, &FileName, &FileLine);\r
+  printf ("%s line %d: error %s %s\n", FileName, FileLine, TokName, ErrorMsg);\r
+}\r
+\r
+UINT8\r
+CVfrErrorHandle::HandleError (\r
+  IN EFI_VFR_RETURN_CODE  ErrorCode,\r
+  IN UINT32               LineNum,\r
+  IN INT8                 *TokName\r
+  )\r
+{\r
+  UINT32                 Index;\r
+  INT8                   *FileName = NULL;\r
+  UINT32                 FileLine;\r
+  INT8                   *ErrorMsg = NULL;\r
+\r
+  if (mVfrErrorHandleTable == NULL) {\r
+    return 1;\r
+  }\r
+\r
+  for (Index = 0; mVfrErrorHandleTable[Index].mErrorCode != VFR_RETURN_CODEUNDEFINED; Index++) {\r
+    if (ErrorCode == mVfrErrorHandleTable[Index].mErrorCode) {\r
+      ErrorMsg = mVfrErrorHandleTable[Index].mErrorMsg;\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (ErrorMsg != NULL) {\r
+    GetFileNameLineNum (LineNum, &FileName, &FileLine);\r
+    printf ("%s line %d: error %s %s\n", FileName, FileLine, TokName, ErrorMsg);\r
+    return 1;\r
+  } else {\r
+    return 0;\r
+  }\r
+}\r
+\r
+CVfrErrorHandle gCVfrErrorHandle;\r