3 Copyright (c) 2004 - 2010, Intel Corporation
4 All rights reserved. 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_CODEUNDEFINED
, "Undefined Error Code" }
51 CVfrErrorHandle::CVfrErrorHandle (
55 mScopeRecordListHead
= NULL
;
56 mScopeRecordListTail
= NULL
;
57 mVfrErrorHandleTable
= VFR_ERROR_HANDLE_TABLE
;
60 CVfrErrorHandle::~CVfrErrorHandle (
64 SVfrFileScopeRecord
*pNode
= NULL
;
66 while (mScopeRecordListHead
!= NULL
) {
67 pNode
= mScopeRecordListHead
;
68 mScopeRecordListHead
= mScopeRecordListHead
->mNext
;
72 mScopeRecordListHead
= NULL
;
73 mScopeRecordListTail
= NULL
;
74 mVfrErrorHandleTable
= NULL
;
77 SVfrFileScopeRecord::SVfrFileScopeRecord (
83 INT8
*FileName
= NULL
;
86 mWholeScopeLine
= LineNum
;
89 Str
= strchr (Record
, ' ');
90 mScopeLineStart
= atoi (++Str
);
92 Str
= strchr (Str
, '\"');
95 while((Str
= strstr (FileName
, "\\\\")) != NULL
) {
98 if ((mFileName
= new INT8
[strlen(FileName
)]) != NULL
) {
99 for (Index
= 0; FileName
[Index
] != '\"'; Index
++) {
100 mFileName
[Index
] = FileName
[Index
];
102 mFileName
[Index
] = '\0';
108 SVfrFileScopeRecord::~SVfrFileScopeRecord (
112 if (mFileName
!= NULL
) {
118 CVfrErrorHandle::ParseFileScopeRecord (
120 IN UINT32 WholeScopeLine
123 INT8
*FullPathName
= NULL
;
124 SVfrFileScopeRecord
*pNode
= NULL
;
126 if (Record
== NULL
) {
130 if ((pNode
= new SVfrFileScopeRecord(Record
, WholeScopeLine
)) == NULL
) {
134 if (mScopeRecordListHead
== NULL
) {
135 mScopeRecordListTail
= mScopeRecordListHead
= pNode
;
137 mScopeRecordListTail
->mNext
= pNode
;
138 mScopeRecordListTail
= pNode
;
143 CVfrErrorHandle::GetFileNameLineNum (
149 SVfrFileScopeRecord
*pNode
= NULL
;
151 if ((FileName
== NULL
) || (FileLine
== NULL
)) {
156 *FileLine
= 0xFFFFFFFF;
158 for (pNode
= mScopeRecordListHead
; pNode
->mNext
!= NULL
; pNode
= pNode
->mNext
) {
159 if ((LineNum
> pNode
->mWholeScopeLine
) && (pNode
->mNext
->mWholeScopeLine
> LineNum
)) {
160 *FileName
= pNode
->mFileName
;
161 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
166 *FileName
= pNode
->mFileName
;
167 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
171 CVfrErrorHandle::PrintError (
177 INT8
*FileName
= NULL
;
180 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
181 printf ("%s line %d: error %s %s\n", FileName
, FileLine
, TokName
, ErrorMsg
);
185 CVfrErrorHandle::HandleError (
186 IN EFI_VFR_RETURN_CODE ErrorCode
,
192 INT8
*FileName
= NULL
;
194 INT8
*ErrorMsg
= NULL
;
196 if (mVfrErrorHandleTable
== NULL
) {
200 for (Index
= 0; mVfrErrorHandleTable
[Index
].mErrorCode
!= VFR_RETURN_CODEUNDEFINED
; Index
++) {
201 if (ErrorCode
== mVfrErrorHandleTable
[Index
].mErrorCode
) {
202 ErrorMsg
= mVfrErrorHandleTable
[Index
].mErrorMsg
;
207 if (ErrorMsg
!= NULL
) {
208 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
209 printf ("%s line %d: error %s %s\n", FileName
, FileLine
, TokName
, ErrorMsg
);
216 CVfrErrorHandle gCVfrErrorHandle
;