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