]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | EFI tools utility functions to display warning, error, and informational messages\r | |
3 | \r | |
4 | Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
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 | |
27 | STATIC STATUS mStatus = STATUS_SUCCESS;\r | |
28 | STATIC CHAR8 mUtilityName[50] = { 0 };\r | |
29 | STATIC UINT64 mPrintLogLevel = INFO_LOG_LEVEL;\r | |
30 | STATIC CHAR8 *mSourceFileName = NULL;\r | |
31 | STATIC UINT32 mSourceFileLineNum = 0;\r | |
32 | STATIC UINT32 mErrorCount = 0;\r | |
33 | STATIC UINT32 mWarningCount = 0;\r | |
34 | STATIC UINT32 mMaxErrors = 0;\r | |
35 | STATIC UINT32 mMaxWarnings = 0;\r | |
36 | STATIC UINT32 mMaxWarningsPlusErrors = 0;\r | |
37 | STATIC INT8 mPrintLimitsSet = 0;\r | |
38 | \r | |
39 | STATIC\r | |
40 | VOID\r | |
41 | PrintLimitExceeded (\r | |
42 | VOID\r | |
43 | );\r | |
44 | \r | |
45 | VOID\r | |
46 | Error (\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 | |
56 | Routine Description:\r | |
57 | Prints an error message.\r | |
58 | \r | |
59 | Arguments:\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 | |
80 | Returns:\r | |
81 | None.\r | |
82 | \r | |
83 | Notes:\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 | |
134 | }\r | |
135 | \r | |
136 | VOID\r | |
137 | ParserError (\r | |
138 | UINT32 MessageCode,\r | |
139 | CHAR8 *Text,\r | |
140 | CHAR8 *MsgFmt,\r | |
141 | ...\r | |
142 | )\r | |
143 | /*++\r | |
144 | \r | |
145 | Routine 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 | |
149 | Arguments:\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 | |
154 | Returns:\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 | |
188 | }\r | |
189 | \r | |
190 | VOID\r | |
191 | ParserWarning (\r | |
192 | UINT32 ErrorCode,\r | |
193 | CHAR8 *OffendingText,\r | |
194 | CHAR8 *MsgFmt,\r | |
195 | ...\r | |
196 | )\r | |
197 | /*++\r | |
198 | \r | |
199 | Routine 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 | |
203 | Arguments:\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 | |
208 | Returns:\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 | |
250 | VOID\r | |
251 | Warning (\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 | |
261 | Routine Description:\r | |
262 | Print a warning message.\r | |
263 | \r | |
264 | Arguments:\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 | |
279 | Returns:\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 | |
322 | VOID\r | |
323 | DebugMsg (\r | |
324 | CHAR8 *FileName,\r | |
325 | UINT32 LineNumber,\r | |
326 | UINT64 MsgLevel,\r | |
327 | CHAR8 *Text,\r | |
328 | CHAR8 *MsgFmt,\r | |
329 | ...\r | |
330 | )\r | |
331 | /*++\r | |
332 | \r | |
333 | Routine Description:\r | |
334 | Print a Debug message.\r | |
335 | \r | |
336 | Arguments:\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 | |
349 | Returns:\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 | |
367 | VOID\r | |
368 | PrintMessage (\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 | |
379 | Routine 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 | |
384 | Arguments:\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 | |
404 | Returns:\r | |
405 | None.\r | |
406 | \r | |
407 | Notes:\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 | |
454 | fprintf (stdout, "%04d-%02d-%02d %02d:%02d:%02d",\r | |
455 | NewTime->tm_year + 1900,\r | |
456 | NewTime->tm_mon + 1,\r | |
457 | NewTime->tm_mday,\r | |
458 | NewTime->tm_hour,\r | |
459 | NewTime->tm_min,\r | |
460 | NewTime->tm_sec\r | |
461 | );\r | |
462 | if (Cptr != NULL) {\r | |
463 | sprintf (Line, ": %s", Cptr);\r | |
464 | if (LineNumber != 0) {\r | |
465 | sprintf (Line2, "(%u)", (unsigned) LineNumber);\r | |
466 | strcat (Line, Line2);\r | |
467 | }\r | |
468 | }\r | |
469 | } else {\r | |
470 | //\r | |
471 | // Error and Warning Information.\r | |
472 | //\r | |
473 | if (Cptr != NULL) {\r | |
474 | if (mUtilityName[0] != '\0') {\r | |
475 | fprintf (stdout, "%s...\n", mUtilityName);\r | |
476 | }\r | |
477 | sprintf (Line, "%s", Cptr);\r | |
478 | if (LineNumber != 0) {\r | |
479 | sprintf (Line2, "(%u)", (unsigned) LineNumber);\r | |
480 | strcat (Line, Line2);\r | |
481 | }\r | |
482 | } else {\r | |
483 | if (mUtilityName[0] != '\0') {\r | |
484 | sprintf (Line, "%s", mUtilityName);\r | |
485 | }\r | |
486 | }\r | |
487 | \r | |
488 | if (strcmp (Type, "ERROR") == 0) {\r | |
489 | //\r | |
490 | // Set status accordingly for ERROR information.\r | |
491 | //\r | |
492 | if (mStatus < STATUS_ERROR) {\r | |
493 | mStatus = STATUS_ERROR;\r | |
494 | }\r | |
495 | }\r | |
496 | }\r | |
497 | \r | |
498 | //\r | |
499 | // Have to print an error code or Visual Studio won't find the\r | |
500 | // message for you. It has to be decimal digits too.\r | |
501 | //\r | |
502 | if (MessageCode != 0) {\r | |
503 | sprintf (Line2, ": %s %04u", Type, (unsigned) MessageCode);\r | |
504 | } else {\r | |
505 | sprintf (Line2, ": %s", Type);\r | |
506 | }\r | |
507 | strcat (Line, Line2);\r | |
508 | fprintf (stdout, "%s", Line);\r | |
509 | //\r | |
510 | // If offending text was provided, then print it\r | |
511 | //\r | |
512 | if (Text != NULL) {\r | |
513 | fprintf (stdout, ": %s", Text);\r | |
514 | }\r | |
515 | fprintf (stdout, "\n");\r | |
516 | \r | |
517 | //\r | |
518 | // Print formatted message if provided\r | |
519 | //\r | |
520 | if (MsgFmt != NULL) {\r | |
521 | vsprintf (Line2, MsgFmt, List);\r | |
522 | fprintf (stdout, " %s\n", Line2);\r | |
523 | }\r | |
524 | \r | |
525 | }\r | |
526 | \r | |
527 | STATIC\r | |
528 | VOID\r | |
529 | PrintSimpleMessage (\r | |
530 | CHAR8 *MsgFmt,\r | |
531 | va_list List\r | |
532 | )\r | |
533 | /*++\r | |
534 | Routine Description:\r | |
535 | Print message into stdout.\r | |
536 | \r | |
537 | Arguments:\r | |
538 | MsgFmt - the format string for the message. Can contain formatting\r | |
539 | controls for use with varargs.\r | |
540 | List - the variable list.\r | |
541 | \r | |
542 | Returns:\r | |
543 | None.\r | |
544 | --*/\r | |
545 | {\r | |
546 | CHAR8 Line[MAX_LINE_LEN];\r | |
547 | //\r | |
548 | // Print formatted message if provided\r | |
549 | //\r | |
550 | if (MsgFmt != NULL) {\r | |
551 | vsprintf (Line, MsgFmt, List);\r | |
552 | fprintf (stdout, "%s\n", Line);\r | |
553 | }\r | |
554 | }\r | |
555 | \r | |
556 | VOID\r | |
557 | ParserSetPosition (\r | |
558 | CHAR8 *SourceFileName,\r | |
559 | UINT32 LineNum\r | |
560 | )\r | |
561 | /*++\r | |
562 | \r | |
563 | Routine Description:\r | |
564 | Set the position in a file being parsed. This can be used to\r | |
565 | print error messages deeper down in a parser.\r | |
566 | \r | |
567 | Arguments:\r | |
568 | SourceFileName - name of the source file being parsed\r | |
569 | LineNum - line number of the source file being parsed\r | |
570 | \r | |
571 | Returns:\r | |
572 | NA\r | |
573 | \r | |
574 | --*/\r | |
575 | {\r | |
576 | mSourceFileName = SourceFileName;\r | |
577 | mSourceFileLineNum = LineNum;\r | |
578 | }\r | |
579 | \r | |
580 | VOID\r | |
581 | SetUtilityName (\r | |
582 | CHAR8 *UtilityName\r | |
583 | )\r | |
584 | /*++\r | |
585 | \r | |
586 | Routine Description:\r | |
587 | All printed error/warning/debug messages follow the same format, and\r | |
588 | typically will print a filename or utility name followed by the error\r | |
589 | text. However if a filename is not passed to the print routines, then\r | |
590 | they'll print the utility name if you call this function early in your\r | |
591 | app to set the utility name.\r | |
592 | \r | |
593 | Arguments:\r | |
594 | UtilityName - name of the utility, which will be printed with all\r | |
595 | error/warning/debug messags.\r | |
596 | \r | |
597 | Returns:\r | |
598 | NA\r | |
599 | \r | |
600 | --*/\r | |
601 | {\r | |
602 | //\r | |
603 | // Save the name of the utility in our local variable. Make sure its\r | |
604 | // length does not exceed our buffer.\r | |
605 | //\r | |
606 | if (UtilityName != NULL) {\r | |
607 | if (strlen (UtilityName) >= sizeof (mUtilityName)) {\r | |
608 | Error (UtilityName, 0, 0, "application error", "utility name length exceeds internal buffer size");\r | |
609 | strncpy (mUtilityName, UtilityName, sizeof (mUtilityName) - 1);\r | |
610 | mUtilityName[sizeof (mUtilityName) - 1] = 0;\r | |
611 | return ;\r | |
612 | } else {\r | |
613 | strcpy (mUtilityName, UtilityName);\r | |
614 | }\r | |
615 | } else {\r | |
616 | Error (NULL, 0, 0, "application error", "SetUtilityName() called with NULL utility name");\r | |
617 | }\r | |
618 | }\r | |
619 | \r | |
620 | STATUS\r | |
621 | GetUtilityStatus (\r | |
622 | VOID\r | |
623 | )\r | |
624 | /*++\r | |
625 | \r | |
626 | Routine Description:\r | |
627 | When you call Error() or Warning(), this module keeps track of it and\r | |
628 | sets a local mStatus to STATUS_ERROR or STATUS_WARNING. When the utility\r | |
629 | exits, it can call this function to get the status and use it as a return\r | |
630 | value.\r | |
631 | \r | |
632 | Arguments:\r | |
633 | None.\r | |
634 | \r | |
635 | Returns:\r | |
636 | Worst-case status reported, as defined by which print function was called.\r | |
637 | \r | |
638 | --*/\r | |
639 | {\r | |
640 | return mStatus;\r | |
641 | }\r | |
642 | \r | |
643 | VOID\r | |
644 | SetPrintLevel (\r | |
645 | UINT64 LogLevel\r | |
646 | )\r | |
647 | /*++\r | |
648 | \r | |
649 | Routine Description:\r | |
650 | Set the printing message Level. This is used by the PrintMsg() function\r | |
651 | to determine when/if a message should be printed.\r | |
652 | \r | |
653 | Arguments:\r | |
654 | LogLevel - 0~50 to specify the different level message.\r | |
655 | \r | |
656 | Returns:\r | |
657 | NA\r | |
658 | \r | |
659 | --*/\r | |
660 | {\r | |
661 | mPrintLogLevel = LogLevel;\r | |
662 | }\r | |
663 | \r | |
664 | VOID\r | |
665 | VerboseMsg (\r | |
666 | CHAR8 *MsgFmt,\r | |
667 | ...\r | |
668 | )\r | |
669 | /*++\r | |
670 | \r | |
671 | Routine Description:\r | |
672 | Print a verbose level message.\r | |
673 | \r | |
674 | Arguments:\r | |
675 | MsgFmt - the format string for the message. Can contain formatting\r | |
676 | controls for use with varargs.\r | |
677 | List - the variable list.\r | |
678 | \r | |
679 | Returns:\r | |
680 | NA\r | |
681 | \r | |
682 | --*/\r | |
683 | {\r | |
684 | va_list List;\r | |
685 | //\r | |
686 | // If the debug level is less than current print level, then do nothing.\r | |
687 | //\r | |
688 | if (VERBOSE_LOG_LEVEL < mPrintLogLevel) {\r | |
689 | return ;\r | |
690 | }\r | |
691 | \r | |
692 | va_start (List, MsgFmt);\r | |
693 | PrintSimpleMessage (MsgFmt, List);\r | |
694 | va_end (List);\r | |
695 | }\r | |
696 | \r | |
697 | VOID\r | |
698 | NormalMsg (\r | |
699 | CHAR8 *MsgFmt,\r | |
700 | ...\r | |
701 | )\r | |
702 | /*++\r | |
703 | \r | |
704 | Routine Description:\r | |
705 | Print a default level message.\r | |
706 | \r | |
707 | Arguments:\r | |
708 | MsgFmt - the format string for the message. Can contain formatting\r | |
709 | controls for use with varargs.\r | |
710 | List - the variable list.\r | |
711 | \r | |
712 | Returns:\r | |
713 | NA\r | |
714 | \r | |
715 | --*/\r | |
716 | {\r | |
717 | va_list List;\r | |
718 | //\r | |
719 | // If the debug level is less than current print level, then do nothing.\r | |
720 | //\r | |
721 | if (INFO_LOG_LEVEL < mPrintLogLevel) {\r | |
722 | return ;\r | |
723 | }\r | |
724 | \r | |
725 | va_start (List, MsgFmt);\r | |
726 | PrintSimpleMessage (MsgFmt, List);\r | |
727 | va_end (List);\r | |
728 | }\r | |
729 | \r | |
730 | VOID\r | |
731 | KeyMsg (\r | |
732 | CHAR8 *MsgFmt,\r | |
733 | ...\r | |
734 | )\r | |
735 | /*++\r | |
736 | \r | |
737 | Routine Description:\r | |
738 | Print a key level message.\r | |
739 | \r | |
740 | Arguments:\r | |
741 | MsgFmt - the format string for the message. Can contain formatting\r | |
742 | controls for use with varargs.\r | |
743 | List - the variable list.\r | |
744 | \r | |
745 | Returns:\r | |
746 | NA\r | |
747 | \r | |
748 | --*/\r | |
749 | {\r | |
750 | va_list List;\r | |
751 | //\r | |
752 | // If the debug level is less than current print level, then do nothing.\r | |
753 | //\r | |
754 | if (KEY_LOG_LEVEL < mPrintLogLevel) {\r | |
755 | return ;\r | |
756 | }\r | |
757 | \r | |
758 | va_start (List, MsgFmt);\r | |
759 | PrintSimpleMessage (MsgFmt, List);\r | |
760 | va_end (List);\r | |
761 | }\r | |
762 | \r | |
763 | VOID\r | |
764 | SetPrintLimits (\r | |
765 | UINT32 MaxErrors,\r | |
766 | UINT32 MaxWarnings,\r | |
767 | UINT32 MaxWarningsPlusErrors\r | |
768 | )\r | |
769 | /*++\r | |
770 | \r | |
771 | Routine Description:\r | |
772 | Set the limits of how many errors, warnings, and errors+warnings\r | |
773 | we will print.\r | |
774 | \r | |
775 | Arguments:\r | |
776 | MaxErrors - maximum number of error messages to print\r | |
777 | MaxWarnings - maximum number of warning messages to print\r | |
778 | MaxWarningsPlusErrors\r | |
779 | - maximum number of errors+warnings to print\r | |
780 | \r | |
781 | Returns:\r | |
782 | NA\r | |
783 | \r | |
784 | --*/\r | |
785 | {\r | |
786 | mMaxErrors = MaxErrors;\r | |
787 | mMaxWarnings = MaxWarnings;\r | |
788 | mMaxWarningsPlusErrors = MaxWarningsPlusErrors;\r | |
789 | mPrintLimitsSet = 1;\r | |
790 | }\r | |
791 | \r | |
792 | STATIC\r | |
793 | VOID\r | |
794 | PrintLimitExceeded (\r | |
795 | VOID\r | |
796 | )\r | |
797 | {\r | |
798 | STATIC INT8 mPrintLimitExceeded = 0;\r | |
799 | //\r | |
800 | // If we've already printed the message, do nothing. Otherwise\r | |
801 | // temporarily increase our print limits so we can pass one\r | |
802 | // more message through.\r | |
803 | //\r | |
804 | if (mPrintLimitExceeded == 0) {\r | |
805 | mPrintLimitExceeded++;\r | |
806 | mMaxErrors++;\r | |
807 | mMaxWarnings++;\r | |
808 | mMaxWarningsPlusErrors++;\r | |
809 | Error (NULL, 0, 0, "error/warning print limit exceeded", NULL);\r | |
810 | mMaxErrors--;\r | |
811 | mMaxWarnings--;\r | |
812 | mMaxWarningsPlusErrors--;\r | |
813 | }\r | |
814 | }\r | |
815 | \r | |
816 | #if 0\r | |
817 | VOID\r | |
818 | TestUtilityMessages (\r | |
819 | VOID\r | |
820 | )\r | |
821 | {\r | |
822 | CHAR8 *ArgStr = "ArgString";\r | |
823 | int ArgInt;\r | |
824 | \r | |
825 | ArgInt = 0x12345678;\r | |
826 | //\r | |
827 | // Test without setting utility name\r | |
828 | //\r | |
829 | fprintf (stdout, "* Testing without setting utility name\n");\r | |
830 | fprintf (stdout, "** Test debug message not printed\n");\r | |
831 | DebugMsg (NULL, 0, 0x00000001, NULL, NULL);\r | |
832 | fprintf (stdout, "** Test warning with two strings and two args\n");\r | |
833 | Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
834 | fprintf (stdout, "** Test error 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 parser warning with nothing\n");\r | |
837 | ParserWarning (0, NULL, NULL);\r | |
838 | fprintf (stdout, "** Test parser error with nothing\n");\r | |
839 | ParserError (0, NULL, NULL);\r | |
840 | //\r | |
841 | // Test with utility name set now\r | |
842 | //\r | |
843 | fprintf (stdout, "** Testingin with utility name set\n");\r | |
844 | SetUtilityName ("MyUtilityName");\r | |
845 | //\r | |
846 | // Test debug prints\r | |
847 | //\r | |
848 | SetDebugMsgMask (2);\r | |
849 | fprintf (stdout, "** Test debug message with one string\n");\r | |
850 | DebugMsg (NULL, 0, 0x00000002, "Text1", NULL);\r | |
851 | fprintf (stdout, "** Test debug message with one string\n");\r | |
852 | DebugMsg (NULL, 0, 0x00000002, NULL, "Text2");\r | |
853 | fprintf (stdout, "** Test debug message with two strings\n");\r | |
854 | DebugMsg (NULL, 0, 0x00000002, "Text1", "Text2");\r | |
855 | fprintf (stdout, "** Test debug message with two strings and two args\n");\r | |
856 | DebugMsg (NULL, 0, 0x00000002, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
857 | //\r | |
858 | // Test warning prints\r | |
859 | //\r | |
860 | fprintf (stdout, "** Test warning with no strings\n");\r | |
861 | Warning (NULL, 0, 1234, NULL, NULL);\r | |
862 | fprintf (stdout, "** Test warning with one string\n");\r | |
863 | Warning (NULL, 0, 1234, "Text1", NULL);\r | |
864 | fprintf (stdout, "** Test warning with one string\n");\r | |
865 | Warning (NULL, 0, 1234, NULL, "Text2");\r | |
866 | fprintf (stdout, "** Test warning with two strings and two args\n");\r | |
867 | Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
868 | //\r | |
869 | // Test error prints\r | |
870 | //\r | |
871 | fprintf (stdout, "** Test error with no strings\n");\r | |
872 | Error (NULL, 0, 1234, NULL, NULL);\r | |
873 | fprintf (stdout, "** Test error with one string\n");\r | |
874 | Error (NULL, 0, 1234, "Text1", NULL);\r | |
875 | fprintf (stdout, "** Test error with one string\n");\r | |
876 | Error (NULL, 0, 1234, NULL, "Text2");\r | |
877 | fprintf (stdout, "** Test error with two strings and two args\n");\r | |
878 | Error (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
879 | //\r | |
880 | // Test parser prints\r | |
881 | //\r | |
882 | fprintf (stdout, "** Test parser errors\n");\r | |
883 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
884 | ParserError (1234, NULL, NULL);\r | |
885 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
886 | ParserError (1234, "Text1", NULL);\r | |
887 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
888 | ParserError (1234, NULL, "Text2");\r | |
889 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
890 | ParserError (1234, "Text1", "Text2");\r | |
891 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
892 | ParserError (1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
893 | \r | |
894 | fprintf (stdout, "** Test parser warnings\n");\r | |
895 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
896 | ParserWarning (4321, NULL, NULL);\r | |
897 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
898 | ParserWarning (4321, "Text1", NULL);\r | |
899 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
900 | ParserWarning (4321, NULL, "Text2");\r | |
901 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
902 | ParserWarning (4321, "Text1", "Text2");\r | |
903 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
904 | ParserWarning (4321, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
905 | }\r | |
906 | #endif\r |