]>
Commit | Line | Data |
---|---|---|
30fdf114 | 1 | /** @file\r |
97fa0ee9 | 2 | EFI tools utility functions to display warning, error, and informational messages\r |
30fdf114 | 3 | \r |
938cf4b9 | 4 | Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r |
2e351cbe | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
30fdf114 | 6 | \r |
30fdf114 LG |
7 | --*/\r |
8 | \r | |
9 | #include <stdio.h>\r | |
10 | #include <string.h>\r | |
11 | #include <ctype.h>\r | |
12 | #include <stdarg.h>\r | |
13 | #include <time.h>\r | |
14 | \r | |
15 | #include "EfiUtilityMsgs.h"\r | |
16 | \r | |
17 | //\r | |
fb0b35e0 | 18 | // Declare module globals for keeping track of the utility's\r |
30fdf114 LG |
19 | // name and other settings.\r |
20 | //\r | |
21 | STATIC STATUS mStatus = STATUS_SUCCESS;\r | |
22 | STATIC CHAR8 mUtilityName[50] = { 0 };\r | |
fd171542 | 23 | STATIC UINT64 mPrintLogLevel = INFO_LOG_LEVEL;\r |
30fdf114 LG |
24 | STATIC CHAR8 *mSourceFileName = NULL;\r |
25 | STATIC UINT32 mSourceFileLineNum = 0;\r | |
26 | STATIC UINT32 mErrorCount = 0;\r | |
27 | STATIC UINT32 mWarningCount = 0;\r | |
28 | STATIC UINT32 mMaxErrors = 0;\r | |
29 | STATIC UINT32 mMaxWarnings = 0;\r | |
30 | STATIC UINT32 mMaxWarningsPlusErrors = 0;\r | |
31 | STATIC INT8 mPrintLimitsSet = 0;\r | |
32 | \r | |
30fdf114 LG |
33 | STATIC\r |
34 | VOID\r | |
35 | PrintLimitExceeded (\r | |
36 | VOID\r | |
37 | );\r | |
38 | \r | |
39 | VOID\r | |
40 | Error (\r | |
41 | CHAR8 *FileName,\r | |
42 | UINT32 LineNumber,\r | |
43 | UINT32 MessageCode,\r | |
44 | CHAR8 *Text,\r | |
45 | CHAR8 *MsgFmt,\r | |
46 | ...\r | |
47 | )\r | |
48 | /*++\r | |
49 | \r | |
50 | Routine Description:\r | |
51 | Prints an error message.\r | |
52 | \r | |
53 | Arguments:\r | |
54 | All arguments are optional, though the printed message may be useless if\r | |
55 | at least something valid is not specified.\r | |
56 | \r | |
57 | FileName - name of the file or application. If not specified, then the\r | |
fb0b35e0 | 58 | utility name (as set by the utility calling SetUtilityName()\r |
30fdf114 LG |
59 | earlier) is used. Otherwise "Unknown utility" is used.\r |
60 | \r | |
61 | LineNumber - the line number of error, typically used by parsers. If the\r | |
62 | utility is not a parser, then 0 should be specified. Otherwise\r | |
63 | the FileName and LineNumber info can be used to cause\r | |
64 | MS Visual Studio to jump to the error.\r | |
65 | \r | |
66 | MessageCode - an application-specific error code that can be referenced in\r | |
67 | other documentation.\r | |
68 | \r | |
69 | Text - the text in question, typically used by parsers.\r | |
70 | \r | |
71 | MsgFmt - the format string for the error message. Can contain formatting\r | |
72 | controls for use with the varargs.\r | |
73 | \r | |
74 | Returns:\r | |
75 | None.\r | |
76 | \r | |
77 | Notes:\r | |
78 | We print the following (similar to the Warn() and Debug()\r | |
79 | W\r | |
80 | Typical error/warning message format:\r | |
81 | \r | |
82 | bin\VfrCompile.cpp(330) : error C2660: 'AddVfrDataStructField' : function does not take 2 parameters\r | |
83 | \r | |
84 | BUGBUG -- these three utility functions are almost identical, and\r | |
85 | should be modified to share code.\r | |
86 | \r | |
87 | Visual Studio does not find error messages with:\r | |
88 | \r | |
89 | " error :"\r | |
90 | " error 1:"\r | |
91 | " error c1:"\r | |
92 | " error 1000:"\r | |
93 | " error c100:"\r | |
94 | \r | |
95 | It does find:\r | |
96 | " error c1000:"\r | |
97 | --*/\r | |
98 | {\r | |
99 | va_list List;\r | |
100 | //\r | |
101 | // If limits have been set, then check that we have not exceeded them\r | |
102 | //\r | |
103 | if (mPrintLimitsSet) {\r | |
104 | //\r | |
105 | // See if we've exceeded our total count\r | |
106 | //\r | |
107 | if (mMaxWarningsPlusErrors != 0) {\r | |
108 | if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {\r | |
109 | PrintLimitExceeded ();\r | |
110 | return ;\r | |
111 | }\r | |
112 | }\r | |
113 | //\r | |
114 | // See if we've exceeded our error count\r | |
115 | //\r | |
116 | if (mMaxErrors != 0) {\r | |
117 | if (mErrorCount > mMaxErrors) {\r | |
118 | PrintLimitExceeded ();\r | |
119 | return ;\r | |
120 | }\r | |
121 | }\r | |
122 | }\r | |
123 | \r | |
124 | mErrorCount++;\r | |
125 | va_start (List, MsgFmt);\r | |
126 | PrintMessage ("ERROR", FileName, LineNumber, MessageCode, Text, MsgFmt, List);\r | |
127 | va_end (List);\r | |
30fdf114 LG |
128 | }\r |
129 | \r | |
130 | VOID\r | |
131 | ParserError (\r | |
132 | UINT32 MessageCode,\r | |
133 | CHAR8 *Text,\r | |
134 | CHAR8 *MsgFmt,\r | |
135 | ...\r | |
136 | )\r | |
137 | /*++\r | |
138 | \r | |
139 | Routine Description:\r | |
140 | Print a parser error, using the source file name and line number\r | |
141 | set by a previous call to SetParserPosition().\r | |
142 | \r | |
143 | Arguments:\r | |
144 | MessageCode - application-specific error code\r | |
145 | Text - text to print in the error message\r | |
146 | MsgFmt - format string to print at the end of the error message\r | |
147 | \r | |
148 | Returns:\r | |
149 | NA\r | |
150 | \r | |
151 | --*/\r | |
152 | {\r | |
153 | va_list List;\r | |
154 | //\r | |
155 | // If limits have been set, then check them\r | |
156 | //\r | |
157 | if (mPrintLimitsSet) {\r | |
158 | //\r | |
159 | // See if we've exceeded our total count\r | |
160 | //\r | |
161 | if (mMaxWarningsPlusErrors != 0) {\r | |
162 | if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {\r | |
163 | PrintLimitExceeded ();\r | |
164 | return ;\r | |
165 | }\r | |
166 | }\r | |
167 | //\r | |
168 | // See if we've exceeded our error count\r | |
169 | //\r | |
170 | if (mMaxErrors != 0) {\r | |
171 | if (mErrorCount > mMaxErrors) {\r | |
172 | PrintLimitExceeded ();\r | |
173 | return ;\r | |
174 | }\r | |
175 | }\r | |
176 | }\r | |
177 | \r | |
178 | mErrorCount++;\r | |
179 | va_start (List, MsgFmt);\r | |
180 | PrintMessage ("ERROR", mSourceFileName, mSourceFileLineNum, MessageCode, Text, MsgFmt, List);\r | |
181 | va_end (List);\r | |
30fdf114 LG |
182 | }\r |
183 | \r | |
184 | VOID\r | |
185 | ParserWarning (\r | |
186 | UINT32 ErrorCode,\r | |
187 | CHAR8 *OffendingText,\r | |
188 | CHAR8 *MsgFmt,\r | |
189 | ...\r | |
190 | )\r | |
191 | /*++\r | |
192 | \r | |
193 | Routine Description:\r | |
194 | Print a parser warning, using the source file name and line number\r | |
195 | set by a previous call to SetParserPosition().\r | |
196 | \r | |
197 | Arguments:\r | |
198 | ErrorCode - application-specific error code\r | |
199 | OffendingText - text to print in the warning message\r | |
200 | MsgFmt - format string to print at the end of the warning message\r | |
201 | \r | |
202 | Returns:\r | |
203 | NA\r | |
204 | \r | |
205 | --*/\r | |
206 | {\r | |
207 | va_list List;\r | |
208 | //\r | |
209 | // If limits have been set, then check them\r | |
210 | //\r | |
211 | if (mPrintLimitsSet) {\r | |
212 | //\r | |
213 | // See if we've exceeded our total count\r | |
214 | //\r | |
215 | if (mMaxWarningsPlusErrors != 0) {\r | |
216 | if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {\r | |
217 | PrintLimitExceeded ();\r | |
218 | return ;\r | |
219 | }\r | |
220 | }\r | |
221 | //\r | |
222 | // See if we've exceeded our warning count\r | |
223 | //\r | |
224 | if (mMaxWarnings != 0) {\r | |
225 | if (mWarningCount > mMaxWarnings) {\r | |
226 | PrintLimitExceeded ();\r | |
227 | return ;\r | |
228 | }\r | |
229 | }\r | |
230 | }\r | |
231 | \r | |
232 | mWarningCount++;\r | |
233 | va_start (List, MsgFmt);\r | |
234 | PrintMessage ("WARNING", mSourceFileName, mSourceFileLineNum, ErrorCode, OffendingText, MsgFmt, List);\r | |
235 | va_end (List);\r | |
236 | //\r | |
237 | // Don't set warning status accordingly\r | |
238 | //\r | |
239 | // if (mStatus < STATUS_WARNING) {\r | |
240 | // mStatus = STATUS_WARNING;\r | |
241 | // }\r | |
242 | }\r | |
243 | \r | |
244 | VOID\r | |
245 | Warning (\r | |
246 | CHAR8 *FileName,\r | |
247 | UINT32 LineNumber,\r | |
248 | UINT32 MessageCode,\r | |
249 | CHAR8 *Text,\r | |
250 | CHAR8 *MsgFmt,\r | |
251 | ...\r | |
252 | )\r | |
253 | /*++\r | |
254 | \r | |
255 | Routine Description:\r | |
256 | Print a warning message.\r | |
257 | \r | |
258 | Arguments:\r | |
259 | FileName - name of the file where the warning was detected, or the name\r | |
260 | of the application that detected the warning\r | |
261 | \r | |
262 | LineNumber - the line number where the warning was detected (parsers).\r | |
263 | 0 should be specified if the utility is not a parser.\r | |
264 | \r | |
265 | MessageCode - an application-specific warning code that can be referenced in\r | |
266 | other documentation.\r | |
267 | \r | |
268 | Text - the text in question (parsers)\r | |
269 | \r | |
270 | MsgFmt - the format string for the warning message. Can contain formatting\r | |
271 | controls for use with varargs.\r | |
272 | \r | |
273 | Returns:\r | |
274 | None.\r | |
275 | \r | |
276 | --*/\r | |
277 | {\r | |
278 | va_list List;\r | |
279 | \r | |
280 | //\r | |
281 | // Current Print Level not output warning information.\r | |
282 | //\r | |
283 | if (WARNING_LOG_LEVEL < mPrintLogLevel) {\r | |
284 | return;\r | |
285 | }\r | |
286 | //\r | |
287 | // If limits have been set, then check them\r | |
288 | //\r | |
289 | if (mPrintLimitsSet) {\r | |
290 | //\r | |
291 | // See if we've exceeded our total count\r | |
292 | //\r | |
293 | if (mMaxWarningsPlusErrors != 0) {\r | |
294 | if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {\r | |
295 | PrintLimitExceeded ();\r | |
296 | return ;\r | |
297 | }\r | |
298 | }\r | |
299 | //\r | |
300 | // See if we've exceeded our warning count\r | |
301 | //\r | |
302 | if (mMaxWarnings != 0) {\r | |
303 | if (mWarningCount > mMaxWarnings) {\r | |
304 | PrintLimitExceeded ();\r | |
305 | return ;\r | |
306 | }\r | |
307 | }\r | |
308 | }\r | |
309 | \r | |
310 | mWarningCount++;\r | |
311 | va_start (List, MsgFmt);\r | |
312 | PrintMessage ("WARNING", FileName, LineNumber, MessageCode, Text, MsgFmt, List);\r | |
313 | va_end (List);\r | |
314 | }\r | |
315 | \r | |
316 | VOID\r | |
317 | DebugMsg (\r | |
318 | CHAR8 *FileName,\r | |
319 | UINT32 LineNumber,\r | |
fd171542 | 320 | UINT64 MsgLevel,\r |
30fdf114 LG |
321 | CHAR8 *Text,\r |
322 | CHAR8 *MsgFmt,\r | |
323 | ...\r | |
324 | )\r | |
325 | /*++\r | |
326 | \r | |
327 | Routine Description:\r | |
328 | Print a Debug message.\r | |
329 | \r | |
330 | Arguments:\r | |
331 | FileName - typically the name of the utility printing the debug message, but\r | |
332 | can be the name of a file being parsed.\r | |
333 | \r | |
334 | LineNumber - the line number in FileName (parsers)\r | |
335 | \r | |
336 | MsgLevel - Debug message print level (0~9)\r | |
337 | \r | |
338 | Text - the text in question (parsers)\r | |
339 | \r | |
340 | MsgFmt - the format string for the debug message. Can contain formatting\r | |
341 | controls for use with varargs.\r | |
342 | \r | |
343 | Returns:\r | |
344 | None.\r | |
345 | \r | |
346 | --*/\r | |
347 | {\r | |
348 | va_list List;\r | |
349 | //\r | |
350 | // If the debug level is less than current print level, then do nothing.\r | |
351 | //\r | |
352 | if (MsgLevel < mPrintLogLevel) {\r | |
353 | return ;\r | |
354 | }\r | |
355 | \r | |
356 | va_start (List, MsgFmt);\r | |
357 | PrintMessage ("DEBUG", FileName, LineNumber, 0, Text, MsgFmt, List);\r | |
358 | va_end (List);\r | |
359 | }\r | |
360 | \r | |
30fdf114 LG |
361 | VOID\r |
362 | PrintMessage (\r | |
363 | CHAR8 *Type,\r | |
364 | CHAR8 *FileName,\r | |
365 | UINT32 LineNumber,\r | |
366 | UINT32 MessageCode,\r | |
367 | CHAR8 *Text,\r | |
368 | CHAR8 *MsgFmt,\r | |
369 | va_list List\r | |
370 | )\r | |
371 | /*++\r | |
372 | \r | |
373 | Routine Description:\r | |
374 | Worker routine for all the utility printing services. Prints the message in\r | |
375 | a format that Visual Studio will find when scanning build outputs for\r | |
376 | errors or warnings.\r | |
377 | \r | |
378 | Arguments:\r | |
379 | Type - "warning" or "error" string to insert into the message to be\r | |
380 | printed. The first character of this string (converted to uppercase)\r | |
fb0b35e0 | 381 | is used to precede the MessageCode value in the output string.\r |
30fdf114 LG |
382 | \r |
383 | FileName - name of the file where the warning was detected, or the name\r | |
384 | of the application that detected the warning\r | |
385 | \r | |
386 | LineNumber - the line number where the warning was detected (parsers).\r | |
387 | 0 should be specified if the utility is not a parser.\r | |
388 | \r | |
389 | MessageCode - an application-specific warning code that can be referenced in\r | |
390 | other documentation.\r | |
391 | \r | |
392 | Text - part of the message to print\r | |
393 | \r | |
394 | MsgFmt - the format string for the message. Can contain formatting\r | |
395 | controls for use with varargs.\r | |
396 | List - the variable list.\r | |
397 | \r | |
398 | Returns:\r | |
399 | None.\r | |
400 | \r | |
401 | Notes:\r | |
402 | If FileName == NULL then this utility will use the string passed into SetUtilityName().\r | |
403 | \r | |
404 | LineNumber is only used if the caller is a parser, in which case FileName refers to the\r | |
405 | file being parsed.\r | |
406 | \r | |
407 | Text and MsgFmt are both optional, though it would be of little use calling this function with\r | |
408 | them both NULL.\r | |
409 | \r | |
410 | Output will typically be of the form:\r | |
411 | <FileName>(<LineNumber>) : <Type> <Type[0]><MessageCode>: <Text> : <MsgFmt>\r | |
412 | \r | |
413 | Parser (LineNumber != 0)\r | |
414 | VfrCompile.cpp(330) : error E2660: AddVfrDataStructField : function does not take 2 parameters\r | |
415 | Generic utility (LineNumber == 0)\r | |
416 | UtilityName : error E1234 : Text string : MsgFmt string and args\r | |
417 | \r | |
418 | --*/\r | |
419 | {\r | |
420 | CHAR8 Line[MAX_LINE_LEN];\r | |
421 | CHAR8 Line2[MAX_LINE_LEN];\r | |
422 | CHAR8 *Cptr;\r | |
423 | struct tm *NewTime;\r | |
424 | time_t CurrentTime;\r | |
425 | \r | |
426 | //\r | |
427 | // init local variable\r | |
428 | //\r | |
429 | Line[0] = '\0';\r | |
430 | Line2[0] = '\0';\r | |
431 | \r | |
432 | //\r | |
433 | // If given a filename, then add it (and the line number) to the string.\r | |
434 | // If there's no filename, then use the program name if provided.\r | |
435 | //\r | |
436 | if (FileName != NULL) {\r | |
437 | Cptr = FileName;\r | |
438 | } else {\r | |
439 | Cptr = NULL;\r | |
440 | }\r | |
441 | \r | |
442 | if (strcmp (Type, "DEBUG") == 0) {\r | |
443 | //\r | |
444 | // Debug Message requires current time.\r | |
445 | //\r | |
446 | time (&CurrentTime);\r | |
447 | NewTime = localtime (&CurrentTime);\r | |
2ff3293d HW |
448 | if (NewTime != NULL) {\r |
449 | fprintf (stdout, "%04d-%02d-%02d %02d:%02d:%02d",\r | |
450 | NewTime->tm_year + 1900,\r | |
451 | NewTime->tm_mon + 1,\r | |
452 | NewTime->tm_mday,\r | |
453 | NewTime->tm_hour,\r | |
454 | NewTime->tm_min,\r | |
455 | NewTime->tm_sec\r | |
456 | );\r | |
457 | }\r | |
30fdf114 | 458 | if (Cptr != NULL) {\r |
3e149733 HW |
459 | strcpy (Line, ": ");\r |
460 | strncat (Line, Cptr, MAX_LINE_LEN - strlen (Line) - 1);\r | |
30fdf114 | 461 | if (LineNumber != 0) {\r |
fd171542 | 462 | sprintf (Line2, "(%u)", (unsigned) LineNumber);\r |
3e149733 | 463 | strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1);\r |
30fdf114 LG |
464 | }\r |
465 | }\r | |
466 | } else {\r | |
467 | //\r | |
468 | // Error and Warning Information.\r | |
469 | //\r | |
470 | if (Cptr != NULL) {\r | |
471 | if (mUtilityName[0] != '\0') {\r | |
472 | fprintf (stdout, "%s...\n", mUtilityName);\r | |
473 | }\r | |
3e149733 HW |
474 | strncpy (Line, Cptr, MAX_LINE_LEN - 1);\r |
475 | Line[MAX_LINE_LEN - 1] = 0;\r | |
30fdf114 | 476 | if (LineNumber != 0) {\r |
fd171542 | 477 | sprintf (Line2, "(%u)", (unsigned) LineNumber);\r |
3e149733 | 478 | strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1);\r |
30fdf114 LG |
479 | }\r |
480 | } else {\r | |
481 | if (mUtilityName[0] != '\0') {\r | |
3e149733 HW |
482 | strncpy (Line, mUtilityName, MAX_LINE_LEN - 1);\r |
483 | Line[MAX_LINE_LEN - 1] = 0;\r | |
30fdf114 LG |
484 | }\r |
485 | }\r | |
52302d4d LG |
486 | \r |
487 | if (strcmp (Type, "ERROR") == 0) {\r | |
488 | //\r | |
489 | // Set status accordingly for ERROR information.\r | |
490 | //\r | |
491 | if (mStatus < STATUS_ERROR) {\r | |
492 | mStatus = STATUS_ERROR;\r | |
493 | }\r | |
494 | }\r | |
30fdf114 LG |
495 | }\r |
496 | \r | |
497 | //\r | |
498 | // Have to print an error code or Visual Studio won't find the\r | |
499 | // message for you. It has to be decimal digits too.\r | |
500 | //\r | |
3e149733 HW |
501 | strncat (Line, ": ", MAX_LINE_LEN - strlen (Line) - 1);\r |
502 | strncat (Line, Type, MAX_LINE_LEN - strlen (Line) - 1);\r | |
30fdf114 | 503 | if (MessageCode != 0) {\r |
3e149733 HW |
504 | sprintf (Line2, " %04u", (unsigned) MessageCode);\r |
505 | strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1);\r | |
30fdf114 | 506 | }\r |
30fdf114 LG |
507 | fprintf (stdout, "%s", Line);\r |
508 | //\r | |
509 | // If offending text was provided, then print it\r | |
510 | //\r | |
511 | if (Text != NULL) {\r | |
512 | fprintf (stdout, ": %s", Text);\r | |
513 | }\r | |
514 | fprintf (stdout, "\n");\r | |
515 | \r | |
516 | //\r | |
517 | // Print formatted message if provided\r | |
518 | //\r | |
519 | if (MsgFmt != NULL) {\r | |
520 | vsprintf (Line2, MsgFmt, List);\r | |
521 | fprintf (stdout, " %s\n", Line2);\r | |
522 | }\r | |
52302d4d | 523 | \r |
30fdf114 LG |
524 | }\r |
525 | \r | |
526 | STATIC\r | |
527 | VOID\r | |
528 | PrintSimpleMessage (\r | |
529 | CHAR8 *MsgFmt,\r | |
530 | va_list List\r | |
531 | )\r | |
532 | /*++\r | |
533 | Routine Description:\r | |
534 | Print message into stdout.\r | |
535 | \r | |
536 | Arguments:\r | |
537 | MsgFmt - the format string for the message. Can contain formatting\r | |
538 | controls for use with varargs.\r | |
539 | List - the variable list.\r | |
540 | \r | |
541 | Returns:\r | |
542 | None.\r | |
543 | --*/\r | |
544 | {\r | |
545 | CHAR8 Line[MAX_LINE_LEN];\r | |
546 | //\r | |
547 | // Print formatted message if provided\r | |
548 | //\r | |
549 | if (MsgFmt != NULL) {\r | |
550 | vsprintf (Line, MsgFmt, List);\r | |
551 | fprintf (stdout, "%s\n", Line);\r | |
552 | }\r | |
553 | }\r | |
554 | \r | |
555 | VOID\r | |
556 | ParserSetPosition (\r | |
557 | CHAR8 *SourceFileName,\r | |
558 | UINT32 LineNum\r | |
559 | )\r | |
560 | /*++\r | |
561 | \r | |
562 | Routine Description:\r | |
563 | Set the position in a file being parsed. This can be used to\r | |
564 | print error messages deeper down in a parser.\r | |
565 | \r | |
566 | Arguments:\r | |
567 | SourceFileName - name of the source file being parsed\r | |
568 | LineNum - line number of the source file being parsed\r | |
569 | \r | |
570 | Returns:\r | |
571 | NA\r | |
572 | \r | |
573 | --*/\r | |
574 | {\r | |
575 | mSourceFileName = SourceFileName;\r | |
576 | mSourceFileLineNum = LineNum;\r | |
577 | }\r | |
578 | \r | |
579 | VOID\r | |
580 | SetUtilityName (\r | |
581 | CHAR8 *UtilityName\r | |
582 | )\r | |
583 | /*++\r | |
584 | \r | |
585 | Routine Description:\r | |
586 | All printed error/warning/debug messages follow the same format, and\r | |
587 | typically will print a filename or utility name followed by the error\r | |
588 | text. However if a filename is not passed to the print routines, then\r | |
589 | they'll print the utility name if you call this function early in your\r | |
590 | app to set the utility name.\r | |
591 | \r | |
592 | Arguments:\r | |
593 | UtilityName - name of the utility, which will be printed with all\r | |
fb0b35e0 | 594 | error/warning/debug messages.\r |
30fdf114 LG |
595 | \r |
596 | Returns:\r | |
597 | NA\r | |
598 | \r | |
599 | --*/\r | |
600 | {\r | |
601 | //\r | |
602 | // Save the name of the utility in our local variable. Make sure its\r | |
603 | // length does not exceed our buffer.\r | |
604 | //\r | |
605 | if (UtilityName != NULL) {\r | |
606 | if (strlen (UtilityName) >= sizeof (mUtilityName)) {\r | |
607 | Error (UtilityName, 0, 0, "application error", "utility name length exceeds internal buffer size");\r | |
30fdf114 | 608 | }\r |
938cf4b9 HW |
609 | strncpy (mUtilityName, UtilityName, sizeof (mUtilityName) - 1);\r |
610 | mUtilityName[sizeof (mUtilityName) - 1] = 0;\r | |
30fdf114 LG |
611 | } else {\r |
612 | Error (NULL, 0, 0, "application error", "SetUtilityName() called with NULL utility name");\r | |
613 | }\r | |
614 | }\r | |
615 | \r | |
616 | STATUS\r | |
617 | GetUtilityStatus (\r | |
618 | VOID\r | |
619 | )\r | |
620 | /*++\r | |
621 | \r | |
622 | Routine Description:\r | |
623 | When you call Error() or Warning(), this module keeps track of it and\r | |
624 | sets a local mStatus to STATUS_ERROR or STATUS_WARNING. When the utility\r | |
625 | exits, it can call this function to get the status and use it as a return\r | |
626 | value.\r | |
627 | \r | |
628 | Arguments:\r | |
629 | None.\r | |
630 | \r | |
631 | Returns:\r | |
632 | Worst-case status reported, as defined by which print function was called.\r | |
633 | \r | |
634 | --*/\r | |
635 | {\r | |
636 | return mStatus;\r | |
637 | }\r | |
638 | \r | |
639 | VOID\r | |
640 | SetPrintLevel (\r | |
fd171542 | 641 | UINT64 LogLevel\r |
30fdf114 LG |
642 | )\r |
643 | /*++\r | |
644 | \r | |
645 | Routine Description:\r | |
646 | Set the printing message Level. This is used by the PrintMsg() function\r | |
647 | to determine when/if a message should be printed.\r | |
648 | \r | |
649 | Arguments:\r | |
650 | LogLevel - 0~50 to specify the different level message.\r | |
651 | \r | |
652 | Returns:\r | |
653 | NA\r | |
654 | \r | |
655 | --*/\r | |
656 | {\r | |
657 | mPrintLogLevel = LogLevel;\r | |
658 | }\r | |
659 | \r | |
660 | VOID\r | |
661 | VerboseMsg (\r | |
662 | CHAR8 *MsgFmt,\r | |
663 | ...\r | |
664 | )\r | |
665 | /*++\r | |
666 | \r | |
667 | Routine Description:\r | |
668 | Print a verbose level message.\r | |
669 | \r | |
670 | Arguments:\r | |
671 | MsgFmt - the format string for the message. Can contain formatting\r | |
672 | controls for use with varargs.\r | |
673 | List - the variable list.\r | |
674 | \r | |
675 | Returns:\r | |
676 | NA\r | |
677 | \r | |
678 | --*/\r | |
679 | {\r | |
680 | va_list List;\r | |
681 | //\r | |
682 | // If the debug level is less than current print level, then do nothing.\r | |
683 | //\r | |
684 | if (VERBOSE_LOG_LEVEL < mPrintLogLevel) {\r | |
685 | return ;\r | |
686 | }\r | |
687 | \r | |
688 | va_start (List, MsgFmt);\r | |
689 | PrintSimpleMessage (MsgFmt, List);\r | |
690 | va_end (List);\r | |
691 | }\r | |
692 | \r | |
693 | VOID\r | |
694 | NormalMsg (\r | |
695 | CHAR8 *MsgFmt,\r | |
696 | ...\r | |
697 | )\r | |
698 | /*++\r | |
699 | \r | |
700 | Routine Description:\r | |
701 | Print a default level message.\r | |
702 | \r | |
703 | Arguments:\r | |
704 | MsgFmt - the format string for the message. Can contain formatting\r | |
705 | controls for use with varargs.\r | |
706 | List - the variable list.\r | |
707 | \r | |
708 | Returns:\r | |
709 | NA\r | |
710 | \r | |
711 | --*/\r | |
712 | {\r | |
713 | va_list List;\r | |
714 | //\r | |
715 | // If the debug level is less than current print level, then do nothing.\r | |
716 | //\r | |
717 | if (INFO_LOG_LEVEL < mPrintLogLevel) {\r | |
718 | return ;\r | |
719 | }\r | |
720 | \r | |
721 | va_start (List, MsgFmt);\r | |
722 | PrintSimpleMessage (MsgFmt, List);\r | |
723 | va_end (List);\r | |
724 | }\r | |
725 | \r | |
726 | VOID\r | |
727 | KeyMsg (\r | |
728 | CHAR8 *MsgFmt,\r | |
729 | ...\r | |
730 | )\r | |
731 | /*++\r | |
732 | \r | |
733 | Routine Description:\r | |
734 | Print a key level message.\r | |
735 | \r | |
736 | Arguments:\r | |
737 | MsgFmt - the format string for the message. Can contain formatting\r | |
738 | controls for use with varargs.\r | |
739 | List - the variable list.\r | |
740 | \r | |
741 | Returns:\r | |
742 | NA\r | |
743 | \r | |
744 | --*/\r | |
745 | {\r | |
746 | va_list List;\r | |
747 | //\r | |
748 | // If the debug level is less than current print level, then do nothing.\r | |
749 | //\r | |
750 | if (KEY_LOG_LEVEL < mPrintLogLevel) {\r | |
751 | return ;\r | |
752 | }\r | |
753 | \r | |
754 | va_start (List, MsgFmt);\r | |
755 | PrintSimpleMessage (MsgFmt, List);\r | |
756 | va_end (List);\r | |
757 | }\r | |
758 | \r | |
759 | VOID\r | |
760 | SetPrintLimits (\r | |
761 | UINT32 MaxErrors,\r | |
762 | UINT32 MaxWarnings,\r | |
763 | UINT32 MaxWarningsPlusErrors\r | |
764 | )\r | |
765 | /*++\r | |
766 | \r | |
767 | Routine Description:\r | |
768 | Set the limits of how many errors, warnings, and errors+warnings\r | |
769 | we will print.\r | |
770 | \r | |
771 | Arguments:\r | |
772 | MaxErrors - maximum number of error messages to print\r | |
773 | MaxWarnings - maximum number of warning messages to print\r | |
774 | MaxWarningsPlusErrors\r | |
775 | - maximum number of errors+warnings to print\r | |
776 | \r | |
777 | Returns:\r | |
778 | NA\r | |
779 | \r | |
780 | --*/\r | |
781 | {\r | |
782 | mMaxErrors = MaxErrors;\r | |
783 | mMaxWarnings = MaxWarnings;\r | |
784 | mMaxWarningsPlusErrors = MaxWarningsPlusErrors;\r | |
785 | mPrintLimitsSet = 1;\r | |
786 | }\r | |
787 | \r | |
788 | STATIC\r | |
789 | VOID\r | |
790 | PrintLimitExceeded (\r | |
791 | VOID\r | |
792 | )\r | |
793 | {\r | |
794 | STATIC INT8 mPrintLimitExceeded = 0;\r | |
795 | //\r | |
796 | // If we've already printed the message, do nothing. Otherwise\r | |
797 | // temporarily increase our print limits so we can pass one\r | |
798 | // more message through.\r | |
799 | //\r | |
800 | if (mPrintLimitExceeded == 0) {\r | |
801 | mPrintLimitExceeded++;\r | |
802 | mMaxErrors++;\r | |
803 | mMaxWarnings++;\r | |
804 | mMaxWarningsPlusErrors++;\r | |
805 | Error (NULL, 0, 0, "error/warning print limit exceeded", NULL);\r | |
806 | mMaxErrors--;\r | |
807 | mMaxWarnings--;\r | |
808 | mMaxWarningsPlusErrors--;\r | |
809 | }\r | |
810 | }\r | |
811 | \r | |
812 | #if 0\r | |
813 | VOID\r | |
814 | TestUtilityMessages (\r | |
815 | VOID\r | |
816 | )\r | |
817 | {\r | |
818 | CHAR8 *ArgStr = "ArgString";\r | |
fd171542 | 819 | int ArgInt;\r |
30fdf114 LG |
820 | \r |
821 | ArgInt = 0x12345678;\r | |
822 | //\r | |
823 | // Test without setting utility name\r | |
824 | //\r | |
825 | fprintf (stdout, "* Testing without setting utility name\n");\r | |
826 | fprintf (stdout, "** Test debug message not printed\n");\r | |
827 | DebugMsg (NULL, 0, 0x00000001, NULL, NULL);\r | |
828 | fprintf (stdout, "** Test warning with two strings and two args\n");\r | |
829 | Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
830 | fprintf (stdout, "** Test error with two strings and two args\n");\r | |
831 | Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
832 | fprintf (stdout, "** Test parser warning with nothing\n");\r | |
833 | ParserWarning (0, NULL, NULL);\r | |
834 | fprintf (stdout, "** Test parser error with nothing\n");\r | |
835 | ParserError (0, NULL, NULL);\r | |
836 | //\r | |
837 | // Test with utility name set now\r | |
838 | //\r | |
839 | fprintf (stdout, "** Testingin with utility name set\n");\r | |
840 | SetUtilityName ("MyUtilityName");\r | |
841 | //\r | |
842 | // Test debug prints\r | |
843 | //\r | |
844 | SetDebugMsgMask (2);\r | |
845 | fprintf (stdout, "** Test debug message with one string\n");\r | |
846 | DebugMsg (NULL, 0, 0x00000002, "Text1", NULL);\r | |
847 | fprintf (stdout, "** Test debug message with one string\n");\r | |
848 | DebugMsg (NULL, 0, 0x00000002, NULL, "Text2");\r | |
849 | fprintf (stdout, "** Test debug message with two strings\n");\r | |
850 | DebugMsg (NULL, 0, 0x00000002, "Text1", "Text2");\r | |
851 | fprintf (stdout, "** Test debug message with two strings and two args\n");\r | |
852 | DebugMsg (NULL, 0, 0x00000002, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
853 | //\r | |
854 | // Test warning prints\r | |
855 | //\r | |
856 | fprintf (stdout, "** Test warning with no strings\n");\r | |
857 | Warning (NULL, 0, 1234, NULL, NULL);\r | |
858 | fprintf (stdout, "** Test warning with one string\n");\r | |
859 | Warning (NULL, 0, 1234, "Text1", NULL);\r | |
860 | fprintf (stdout, "** Test warning with one string\n");\r | |
861 | Warning (NULL, 0, 1234, NULL, "Text2");\r | |
862 | fprintf (stdout, "** Test warning with two strings and two args\n");\r | |
863 | Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
864 | //\r | |
865 | // Test error prints\r | |
866 | //\r | |
867 | fprintf (stdout, "** Test error with no strings\n");\r | |
868 | Error (NULL, 0, 1234, NULL, NULL);\r | |
869 | fprintf (stdout, "** Test error with one string\n");\r | |
870 | Error (NULL, 0, 1234, "Text1", NULL);\r | |
871 | fprintf (stdout, "** Test error with one string\n");\r | |
872 | Error (NULL, 0, 1234, NULL, "Text2");\r | |
873 | fprintf (stdout, "** Test error with two strings and two args\n");\r | |
874 | Error (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
875 | //\r | |
876 | // Test parser prints\r | |
877 | //\r | |
878 | fprintf (stdout, "** Test parser errors\n");\r | |
879 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
880 | ParserError (1234, NULL, NULL);\r | |
881 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
882 | ParserError (1234, "Text1", NULL);\r | |
883 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
884 | ParserError (1234, NULL, "Text2");\r | |
885 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
886 | ParserError (1234, "Text1", "Text2");\r | |
887 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
888 | ParserError (1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
889 | \r | |
890 | fprintf (stdout, "** Test parser warnings\n");\r | |
891 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
892 | ParserWarning (4321, NULL, NULL);\r | |
893 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
894 | ParserWarning (4321, "Text1", NULL);\r | |
895 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
896 | ParserWarning (4321, NULL, "Text2");\r | |
897 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
898 | ParserWarning (4321, "Text1", "Text2");\r | |
899 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
900 | ParserWarning (4321, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
901 | }\r | |
902 | #endif\r |