3 Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 static SVFR_ERROR_HANDLE VFR_ERROR_HANDLE_TABLE
[] = {
26 { VFR_RETURN_SUCCESS
, NULL
},
27 { VFR_RETURN_ERROR_SKIPED
, NULL
},
28 { VFR_RETURN_FATAL_ERROR
, ": fatal error!!" },
30 { VFR_RETURN_MISMATCHED
, ": unexpected token" },
31 { VFR_RETURN_INVALID_PARAMETER
, ": invalid parameter" },
32 { VFR_RETURN_OUT_FOR_RESOURCES
, ": system out of memory" },
33 { VFR_RETURN_UNSUPPORTED
, ": unsupported" },
34 { VFR_RETURN_REDEFINED
, ": already defined" },
35 { VFR_RETURN_FORMID_REDEFINED
, ": form id already defined" },
36 { VFR_RETURN_QUESTIONID_REDEFINED
, ": question id already defined" },
37 { VFR_RETURN_VARSTOREID_REDEFINED
, ": varstore id already defined" },
38 { VFR_RETURN_UNDEFINED
, ": undefined" },
39 { VFR_RETURN_VAR_NOTDEFINED_BY_QUESTION
, ": some variable has not defined by a question"},
40 { VFR_RETURN_GET_EFIVARSTORE_ERROR
, ": get efi varstore error"},
41 { VFR_RETURN_EFIVARSTORE_USE_ERROR
, ": can not use the efi varstore like this" },
42 { VFR_RETURN_EFIVARSTORE_SIZE_ERROR
, ": unsupport efi varstore size should be <= 8 bytes" },
43 { VFR_RETURN_GET_NVVARSTORE_ERROR
, ": get name value varstore error" },
44 { VFR_RETURN_QVAR_REUSE
, ": variable reused by more than one question" },
45 { VFR_RETURN_FLAGS_UNSUPPORTED
, ": flags unsupported" },
46 { VFR_RETURN_ERROR_ARRARY_NUM
, ": array number error" },
47 { VFR_RETURN_DATA_STRING_ERROR
, ": data field string error or not support"},
48 { VFR_RETURN_DEFAULT_VALUE_REDEFINED
, ": default value re-defined with different value"},
49 { VFR_RETURN_CONSTANT_ONLY
, ": only constant is allowed in the expression"},
50 { VFR_RETURN_CODEUNDEFINED
, ": undefined Error Code" }
53 CVfrErrorHandle::CVfrErrorHandle (
57 mInputFileName
= NULL
;
58 mScopeRecordListHead
= NULL
;
59 mScopeRecordListTail
= NULL
;
60 mVfrErrorHandleTable
= VFR_ERROR_HANDLE_TABLE
;
63 CVfrErrorHandle::~CVfrErrorHandle (
67 SVfrFileScopeRecord
*pNode
= NULL
;
69 if (mInputFileName
!= NULL
) {
70 delete mInputFileName
;
73 while (mScopeRecordListHead
!= NULL
) {
74 pNode
= mScopeRecordListHead
;
75 mScopeRecordListHead
= mScopeRecordListHead
->mNext
;
79 mScopeRecordListHead
= NULL
;
80 mScopeRecordListTail
= NULL
;
81 mVfrErrorHandleTable
= NULL
;
85 CVfrErrorHandle::SetInputFile (
89 if (InputFile
!= NULL
) {
90 mInputFileName
= new INT8
[strlen(InputFile
) + 1];
91 strcpy (mInputFileName
, InputFile
);
95 SVfrFileScopeRecord::SVfrFileScopeRecord (
101 INT8
*FileName
= NULL
;
104 mWholeScopeLine
= LineNum
;
107 Str
= strchr (Record
, ' ');
108 mScopeLineStart
= atoi (++Str
);
110 Str
= strchr (Str
, '\"');
113 while((Str
= strstr (FileName
, "\\\\")) != NULL
) {
116 if ((mFileName
= new INT8
[strlen(FileName
)]) != NULL
) {
117 for (Index
= 0; FileName
[Index
] != '\"'; Index
++) {
118 mFileName
[Index
] = FileName
[Index
];
120 mFileName
[Index
] = '\0';
126 SVfrFileScopeRecord::~SVfrFileScopeRecord (
130 if (mFileName
!= NULL
) {
136 CVfrErrorHandle::ParseFileScopeRecord (
138 IN UINT32 WholeScopeLine
141 INT8
*FullPathName
= NULL
;
142 SVfrFileScopeRecord
*pNode
= NULL
;
144 if (Record
== NULL
) {
148 if ((pNode
= new SVfrFileScopeRecord(Record
, WholeScopeLine
)) == NULL
) {
152 if (mScopeRecordListHead
== NULL
) {
153 mScopeRecordListTail
= mScopeRecordListHead
= pNode
;
155 mScopeRecordListTail
->mNext
= pNode
;
156 mScopeRecordListTail
= pNode
;
161 CVfrErrorHandle::GetFileNameLineNum (
167 SVfrFileScopeRecord
*pNode
= NULL
;
169 if ((FileName
== NULL
) || (FileLine
== NULL
)) {
174 *FileLine
= 0xFFFFFFFF;
177 // Some errors occur before scope record list been built.
179 if (mScopeRecordListHead
== NULL
) {
181 *FileName
= mInputFileName
;
185 for (pNode
= mScopeRecordListHead
; pNode
->mNext
!= NULL
; pNode
= pNode
->mNext
) {
186 if ((LineNum
> pNode
->mWholeScopeLine
) && (pNode
->mNext
->mWholeScopeLine
> LineNum
)) {
187 *FileName
= pNode
->mFileName
;
188 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
193 *FileName
= pNode
->mFileName
;
194 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
198 CVfrErrorHandle::PrintMsg (
205 INT8
*FileName
= NULL
;
208 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
209 printf ("%s line %d: %s %s %s\n", FileName
, FileLine
, MsgType
, TokName
, ErrorMsg
);
213 CVfrErrorHandle::HandleError (
214 IN EFI_VFR_RETURN_CODE ErrorCode
,
220 INT8
*FileName
= NULL
;
222 INT8
*ErrorMsg
= NULL
;
224 if (mVfrErrorHandleTable
== NULL
) {
228 for (Index
= 0; mVfrErrorHandleTable
[Index
].mErrorCode
!= VFR_RETURN_CODEUNDEFINED
; Index
++) {
229 if (ErrorCode
== mVfrErrorHandleTable
[Index
].mErrorCode
) {
230 ErrorMsg
= mVfrErrorHandleTable
[Index
].mErrorMsg
;
235 if (ErrorMsg
!= NULL
) {
236 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
237 printf ("%s line %d: error %s %s\n", FileName
, FileLine
, TokName
, ErrorMsg
);
244 CVfrErrorHandle gCVfrErrorHandle
;