]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Sample/Tools/Source/UefiVfrCompile/VfrError.cpp
Add the missing BDS license header.
[mirror_edk2.git] / EdkCompatibilityPkg / Sample / Tools / Source / UefiVfrCompile / VfrError.cpp
1 /*++
2
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
8
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.
11
12 Module Name:
13
14 VfrError.cpp
15
16 Abstract:
17
18 --*/
19
20 #include "stdio.h"
21 #include "string.h"
22 #include "stdlib.h"
23 #include "VfrError.h"
24
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!!" },
29
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" }
49 };
50
51 CVfrErrorHandle::CVfrErrorHandle (
52 VOID
53 )
54 {
55 mScopeRecordListHead = NULL;
56 mScopeRecordListTail = NULL;
57 mVfrErrorHandleTable = VFR_ERROR_HANDLE_TABLE;
58 }
59
60 CVfrErrorHandle::~CVfrErrorHandle (
61 VOID
62 )
63 {
64 SVfrFileScopeRecord *pNode = NULL;
65
66 while (mScopeRecordListHead != NULL) {
67 pNode = mScopeRecordListHead;
68 mScopeRecordListHead = mScopeRecordListHead->mNext;
69 delete pNode;
70 }
71
72 mScopeRecordListHead = NULL;
73 mScopeRecordListTail = NULL;
74 mVfrErrorHandleTable = NULL;
75 }
76
77 SVfrFileScopeRecord::SVfrFileScopeRecord (
78 IN INT8 *Record,
79 IN UINT32 LineNum
80 )
81 {
82 UINT32 Index;
83 INT8 *FileName = NULL;
84 INT8 *Str = NULL;
85
86 mWholeScopeLine = LineNum;
87 mNext = NULL;
88
89 Str = strchr (Record, ' ');
90 mScopeLineStart = atoi (++Str);
91
92 Str = strchr (Str, '\"');
93 FileName = ++Str;
94
95 while((Str = strstr (FileName, "\\\\")) != NULL) {
96 FileName = Str + 2;
97 }
98 if ((mFileName = new INT8[strlen(FileName)]) != NULL) {
99 for (Index = 0; FileName[Index] != '\"'; Index++) {
100 mFileName[Index] = FileName[Index];
101 }
102 mFileName[Index] = '\0';
103 }
104
105 return;
106 }
107
108 SVfrFileScopeRecord::~SVfrFileScopeRecord (
109 VOID
110 )
111 {
112 if (mFileName != NULL) {
113 delete mFileName;
114 }
115 }
116
117 VOID
118 CVfrErrorHandle::ParseFileScopeRecord (
119 IN INT8 *Record,
120 IN UINT32 WholeScopeLine
121 )
122 {
123 INT8 *FullPathName = NULL;
124 SVfrFileScopeRecord *pNode = NULL;
125
126 if (Record == NULL) {
127 return;
128 }
129
130 if ((pNode = new SVfrFileScopeRecord(Record, WholeScopeLine)) == NULL) {
131 return;
132 }
133
134 if (mScopeRecordListHead == NULL) {
135 mScopeRecordListTail = mScopeRecordListHead = pNode;
136 } else {
137 mScopeRecordListTail->mNext = pNode;
138 mScopeRecordListTail = pNode;
139 }
140 }
141
142 VOID
143 CVfrErrorHandle::GetFileNameLineNum (
144 IN UINT32 LineNum,
145 OUT INT8 **FileName,
146 OUT UINT32 *FileLine
147 )
148 {
149 SVfrFileScopeRecord *pNode = NULL;
150
151 if ((FileName == NULL) || (FileLine == NULL)) {
152 return;
153 }
154
155 *FileName = NULL;
156 *FileLine = 0xFFFFFFFF;
157
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;
162 return ;
163 }
164 }
165
166 *FileName = pNode->mFileName;
167 *FileLine = LineNum - pNode->mWholeScopeLine + pNode->mScopeLineStart - 1;
168 }
169
170 VOID
171 CVfrErrorHandle::PrintError (
172 IN UINT32 LineNum,
173 IN INT8 *TokName,
174 IN INT8 *ErrorMsg
175 )
176 {
177 INT8 *FileName = NULL;
178 UINT32 FileLine;
179
180 GetFileNameLineNum (LineNum, &FileName, &FileLine);
181 printf ("%s line %d: error %s %s\n", FileName, FileLine, TokName, ErrorMsg);
182 }
183
184 UINT8
185 CVfrErrorHandle::HandleError (
186 IN EFI_VFR_RETURN_CODE ErrorCode,
187 IN UINT32 LineNum,
188 IN INT8 *TokName
189 )
190 {
191 UINT32 Index;
192 INT8 *FileName = NULL;
193 UINT32 FileLine;
194 INT8 *ErrorMsg = NULL;
195
196 if (mVfrErrorHandleTable == NULL) {
197 return 1;
198 }
199
200 for (Index = 0; mVfrErrorHandleTable[Index].mErrorCode != VFR_RETURN_CODEUNDEFINED; Index++) {
201 if (ErrorCode == mVfrErrorHandleTable[Index].mErrorCode) {
202 ErrorMsg = mVfrErrorHandleTable[Index].mErrorMsg;
203 break;
204 }
205 }
206
207 if (ErrorMsg != NULL) {
208 GetFileNameLineNum (LineNum, &FileName, &FileLine);
209 printf ("%s line %d: error %s %s\n", FileName, FileLine, TokName, ErrorMsg);
210 return 1;
211 } else {
212 return 0;
213 }
214 }
215
216 CVfrErrorHandle gCVfrErrorHandle;