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