]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/Common/EfiUtilityMsgs.c
BaseTools/C/Common: Add/refine boundary checks for strcpy/strcat calls
[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
LG
464 if (Cptr != NULL) {\r
465 sprintf (Line, ": %s", Cptr);\r
466 if (LineNumber != 0) {\r
fd171542 467 sprintf (Line2, "(%u)", (unsigned) LineNumber);\r
30fdf114
LG
468 strcat (Line, Line2);\r
469 }\r
470 }\r
471 } else {\r
472 //\r
473 // Error and Warning Information.\r
474 //\r
475 if (Cptr != NULL) {\r
476 if (mUtilityName[0] != '\0') {\r
477 fprintf (stdout, "%s...\n", mUtilityName);\r
478 }\r
479 sprintf (Line, "%s", Cptr);\r
480 if (LineNumber != 0) {\r
fd171542 481 sprintf (Line2, "(%u)", (unsigned) LineNumber);\r
30fdf114
LG
482 strcat (Line, Line2);\r
483 }\r
484 } else {\r
485 if (mUtilityName[0] != '\0') {\r
486 sprintf (Line, "%s", mUtilityName);\r
487 }\r
488 }\r
52302d4d
LG
489\r
490 if (strcmp (Type, "ERROR") == 0) {\r
491 //\r
492 // Set status accordingly for ERROR information.\r
493 //\r
494 if (mStatus < STATUS_ERROR) {\r
495 mStatus = STATUS_ERROR;\r
496 }\r
497 }\r
30fdf114
LG
498 }\r
499\r
500 //\r
501 // Have to print an error code or Visual Studio won't find the\r
502 // message for you. It has to be decimal digits too.\r
503 //\r
504 if (MessageCode != 0) {\r
fd171542 505 sprintf (Line2, ": %s %04u", Type, (unsigned) MessageCode);\r
30fdf114
LG
506 } else {\r
507 sprintf (Line2, ": %s", Type);\r
508 }\r
509 strcat (Line, Line2);\r
510 fprintf (stdout, "%s", Line);\r
511 //\r
512 // If offending text was provided, then print it\r
513 //\r
514 if (Text != NULL) {\r
515 fprintf (stdout, ": %s", Text);\r
516 }\r
517 fprintf (stdout, "\n");\r
518\r
519 //\r
520 // Print formatted message if provided\r
521 //\r
522 if (MsgFmt != NULL) {\r
523 vsprintf (Line2, MsgFmt, List);\r
524 fprintf (stdout, " %s\n", Line2);\r
525 }\r
52302d4d 526\r
30fdf114
LG
527}\r
528\r
529STATIC\r
530VOID\r
531PrintSimpleMessage (\r
532 CHAR8 *MsgFmt,\r
533 va_list List\r
534 )\r
535/*++\r
536Routine Description:\r
537 Print message into stdout.\r
538\r
539Arguments:\r
540 MsgFmt - the format string for the message. Can contain formatting\r
541 controls for use with varargs.\r
542 List - the variable list.\r
543\r
544Returns:\r
545 None.\r
546--*/\r
547{\r
548 CHAR8 Line[MAX_LINE_LEN];\r
549 //\r
550 // Print formatted message if provided\r
551 //\r
552 if (MsgFmt != NULL) {\r
553 vsprintf (Line, MsgFmt, List);\r
554 fprintf (stdout, "%s\n", Line);\r
555 }\r
556}\r
557\r
558VOID\r
559ParserSetPosition (\r
560 CHAR8 *SourceFileName,\r
561 UINT32 LineNum\r
562 )\r
563/*++\r
564\r
565Routine Description:\r
566 Set the position in a file being parsed. This can be used to\r
567 print error messages deeper down in a parser.\r
568\r
569Arguments:\r
570 SourceFileName - name of the source file being parsed\r
571 LineNum - line number of the source file being parsed\r
572\r
573Returns:\r
574 NA\r
575\r
576--*/\r
577{\r
578 mSourceFileName = SourceFileName;\r
579 mSourceFileLineNum = LineNum;\r
580}\r
581\r
582VOID\r
583SetUtilityName (\r
584 CHAR8 *UtilityName\r
585 )\r
586/*++\r
587\r
588Routine Description:\r
589 All printed error/warning/debug messages follow the same format, and\r
590 typically will print a filename or utility name followed by the error\r
591 text. However if a filename is not passed to the print routines, then\r
592 they'll print the utility name if you call this function early in your\r
593 app to set the utility name.\r
594\r
595Arguments:\r
596 UtilityName - name of the utility, which will be printed with all\r
597 error/warning/debug messags.\r
598\r
599Returns:\r
600 NA\r
601\r
602--*/\r
603{\r
604 //\r
605 // Save the name of the utility in our local variable. Make sure its\r
606 // length does not exceed our buffer.\r
607 //\r
608 if (UtilityName != NULL) {\r
609 if (strlen (UtilityName) >= sizeof (mUtilityName)) {\r
610 Error (UtilityName, 0, 0, "application error", "utility name length exceeds internal buffer size");\r
30fdf114 611 }\r
938cf4b9
HW
612 strncpy (mUtilityName, UtilityName, sizeof (mUtilityName) - 1);\r
613 mUtilityName[sizeof (mUtilityName) - 1] = 0;\r
30fdf114
LG
614 } else {\r
615 Error (NULL, 0, 0, "application error", "SetUtilityName() called with NULL utility name");\r
616 }\r
617}\r
618\r
619STATUS\r
620GetUtilityStatus (\r
621 VOID\r
622 )\r
623/*++\r
624\r
625Routine Description:\r
626 When you call Error() or Warning(), this module keeps track of it and\r
627 sets a local mStatus to STATUS_ERROR or STATUS_WARNING. When the utility\r
628 exits, it can call this function to get the status and use it as a return\r
629 value.\r
630\r
631Arguments:\r
632 None.\r
633\r
634Returns:\r
635 Worst-case status reported, as defined by which print function was called.\r
636\r
637--*/\r
638{\r
639 return mStatus;\r
640}\r
641\r
642VOID\r
643SetPrintLevel (\r
fd171542 644 UINT64 LogLevel\r
30fdf114
LG
645 )\r
646/*++\r
647\r
648Routine Description:\r
649 Set the printing message Level. This is used by the PrintMsg() function\r
650 to determine when/if a message should be printed.\r
651\r
652Arguments:\r
653 LogLevel - 0~50 to specify the different level message.\r
654\r
655Returns:\r
656 NA\r
657\r
658--*/\r
659{\r
660 mPrintLogLevel = LogLevel;\r
661}\r
662\r
663VOID\r
664VerboseMsg (\r
665 CHAR8 *MsgFmt,\r
666 ...\r
667 )\r
668/*++\r
669\r
670Routine Description:\r
671 Print a verbose level message.\r
672\r
673Arguments:\r
674 MsgFmt - the format string for the message. Can contain formatting\r
675 controls for use with varargs.\r
676 List - the variable list.\r
677\r
678Returns:\r
679 NA\r
680\r
681--*/\r
682{\r
683 va_list List;\r
684 //\r
685 // If the debug level is less than current print level, then do nothing.\r
686 //\r
687 if (VERBOSE_LOG_LEVEL < mPrintLogLevel) {\r
688 return ;\r
689 }\r
690\r
691 va_start (List, MsgFmt);\r
692 PrintSimpleMessage (MsgFmt, List);\r
693 va_end (List);\r
694}\r
695\r
696VOID\r
697NormalMsg (\r
698 CHAR8 *MsgFmt,\r
699 ...\r
700 )\r
701/*++\r
702\r
703Routine Description:\r
704 Print a default level message.\r
705\r
706Arguments:\r
707 MsgFmt - the format string for the message. Can contain formatting\r
708 controls for use with varargs.\r
709 List - the variable list.\r
710\r
711Returns:\r
712 NA\r
713\r
714--*/\r
715{\r
716 va_list List;\r
717 //\r
718 // If the debug level is less than current print level, then do nothing.\r
719 //\r
720 if (INFO_LOG_LEVEL < mPrintLogLevel) {\r
721 return ;\r
722 }\r
723\r
724 va_start (List, MsgFmt);\r
725 PrintSimpleMessage (MsgFmt, List);\r
726 va_end (List);\r
727}\r
728\r
729VOID\r
730KeyMsg (\r
731 CHAR8 *MsgFmt,\r
732 ...\r
733 )\r
734/*++\r
735\r
736Routine Description:\r
737 Print a key level message.\r
738\r
739Arguments:\r
740 MsgFmt - the format string for the message. Can contain formatting\r
741 controls for use with varargs.\r
742 List - the variable list.\r
743\r
744Returns:\r
745 NA\r
746\r
747--*/\r
748{\r
749 va_list List;\r
750 //\r
751 // If the debug level is less than current print level, then do nothing.\r
752 //\r
753 if (KEY_LOG_LEVEL < mPrintLogLevel) {\r
754 return ;\r
755 }\r
756\r
757 va_start (List, MsgFmt);\r
758 PrintSimpleMessage (MsgFmt, List);\r
759 va_end (List);\r
760}\r
761\r
762VOID\r
763SetPrintLimits (\r
764 UINT32 MaxErrors,\r
765 UINT32 MaxWarnings,\r
766 UINT32 MaxWarningsPlusErrors\r
767 )\r
768/*++\r
769\r
770Routine Description:\r
771 Set the limits of how many errors, warnings, and errors+warnings\r
772 we will print.\r
773\r
774Arguments:\r
775 MaxErrors - maximum number of error messages to print\r
776 MaxWarnings - maximum number of warning messages to print\r
777 MaxWarningsPlusErrors\r
778 - maximum number of errors+warnings to print\r
779\r
780Returns:\r
781 NA\r
782\r
783--*/\r
784{\r
785 mMaxErrors = MaxErrors;\r
786 mMaxWarnings = MaxWarnings;\r
787 mMaxWarningsPlusErrors = MaxWarningsPlusErrors;\r
788 mPrintLimitsSet = 1;\r
789}\r
790\r
791STATIC\r
792VOID\r
793PrintLimitExceeded (\r
794 VOID\r
795 )\r
796{\r
797 STATIC INT8 mPrintLimitExceeded = 0;\r
798 //\r
799 // If we've already printed the message, do nothing. Otherwise\r
800 // temporarily increase our print limits so we can pass one\r
801 // more message through.\r
802 //\r
803 if (mPrintLimitExceeded == 0) {\r
804 mPrintLimitExceeded++;\r
805 mMaxErrors++;\r
806 mMaxWarnings++;\r
807 mMaxWarningsPlusErrors++;\r
808 Error (NULL, 0, 0, "error/warning print limit exceeded", NULL);\r
809 mMaxErrors--;\r
810 mMaxWarnings--;\r
811 mMaxWarningsPlusErrors--;\r
812 }\r
813}\r
814\r
815#if 0\r
816VOID\r
817TestUtilityMessages (\r
818 VOID\r
819 )\r
820{\r
821 CHAR8 *ArgStr = "ArgString";\r
fd171542 822 int ArgInt;\r
30fdf114
LG
823\r
824 ArgInt = 0x12345678;\r
825 //\r
826 // Test without setting utility name\r
827 //\r
828 fprintf (stdout, "* Testing without setting utility name\n");\r
829 fprintf (stdout, "** Test debug message not printed\n");\r
830 DebugMsg (NULL, 0, 0x00000001, NULL, NULL);\r
831 fprintf (stdout, "** Test warning with two strings and two args\n");\r
832 Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r
833 fprintf (stdout, "** Test error with two strings and two args\n");\r
834 Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r
835 fprintf (stdout, "** Test parser warning with nothing\n");\r
836 ParserWarning (0, NULL, NULL);\r
837 fprintf (stdout, "** Test parser error with nothing\n");\r
838 ParserError (0, NULL, NULL);\r
839 //\r
840 // Test with utility name set now\r
841 //\r
842 fprintf (stdout, "** Testingin with utility name set\n");\r
843 SetUtilityName ("MyUtilityName");\r
844 //\r
845 // Test debug prints\r
846 //\r
847 SetDebugMsgMask (2);\r
848 fprintf (stdout, "** Test debug message with one string\n");\r
849 DebugMsg (NULL, 0, 0x00000002, "Text1", NULL);\r
850 fprintf (stdout, "** Test debug message with one string\n");\r
851 DebugMsg (NULL, 0, 0x00000002, NULL, "Text2");\r
852 fprintf (stdout, "** Test debug message with two strings\n");\r
853 DebugMsg (NULL, 0, 0x00000002, "Text1", "Text2");\r
854 fprintf (stdout, "** Test debug message with two strings and two args\n");\r
855 DebugMsg (NULL, 0, 0x00000002, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r
856 //\r
857 // Test warning prints\r
858 //\r
859 fprintf (stdout, "** Test warning with no strings\n");\r
860 Warning (NULL, 0, 1234, NULL, NULL);\r
861 fprintf (stdout, "** Test warning with one string\n");\r
862 Warning (NULL, 0, 1234, "Text1", NULL);\r
863 fprintf (stdout, "** Test warning with one string\n");\r
864 Warning (NULL, 0, 1234, NULL, "Text2");\r
865 fprintf (stdout, "** Test warning with two strings and two args\n");\r
866 Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r
867 //\r
868 // Test error prints\r
869 //\r
870 fprintf (stdout, "** Test error with no strings\n");\r
871 Error (NULL, 0, 1234, NULL, NULL);\r
872 fprintf (stdout, "** Test error with one string\n");\r
873 Error (NULL, 0, 1234, "Text1", NULL);\r
874 fprintf (stdout, "** Test error with one string\n");\r
875 Error (NULL, 0, 1234, NULL, "Text2");\r
876 fprintf (stdout, "** Test error with two strings and two args\n");\r
877 Error (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r
878 //\r
879 // Test parser prints\r
880 //\r
881 fprintf (stdout, "** Test parser errors\n");\r
882 ParserSetPosition (__FILE__, __LINE__ + 1);\r
883 ParserError (1234, NULL, NULL);\r
884 ParserSetPosition (__FILE__, __LINE__ + 1);\r
885 ParserError (1234, "Text1", NULL);\r
886 ParserSetPosition (__FILE__, __LINE__ + 1);\r
887 ParserError (1234, NULL, "Text2");\r
888 ParserSetPosition (__FILE__, __LINE__ + 1);\r
889 ParserError (1234, "Text1", "Text2");\r
890 ParserSetPosition (__FILE__, __LINE__ + 1);\r
891 ParserError (1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r
892\r
893 fprintf (stdout, "** Test parser warnings\n");\r
894 ParserSetPosition (__FILE__, __LINE__ + 1);\r
895 ParserWarning (4321, NULL, NULL);\r
896 ParserSetPosition (__FILE__, __LINE__ + 1);\r
897 ParserWarning (4321, "Text1", NULL);\r
898 ParserSetPosition (__FILE__, __LINE__ + 1);\r
899 ParserWarning (4321, NULL, "Text2");\r
900 ParserSetPosition (__FILE__, __LINE__ + 1);\r
901 ParserWarning (4321, "Text1", "Text2");\r
902 ParserSetPosition (__FILE__, __LINE__ + 1);\r
903 ParserWarning (4321, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r
904}\r
905#endif\r