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