]>
Commit | Line | Data |
---|---|---|
30fdf114 | 1 | /** @file\r |
97fa0ee9 | 2 | EFI tools utility functions to display warning, error, and informational messages\r |
30fdf114 | 3 | \r |
2ff3293d | 4 | Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r |
40d841f6 | 5 | This program and the accompanying materials\r |
30fdf114 LG |
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 | |
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 | |
27 | STATIC STATUS mStatus = STATUS_SUCCESS;\r | |
28 | STATIC CHAR8 mUtilityName[50] = { 0 };\r | |
fd171542 | 29 | STATIC UINT64 mPrintLogLevel = INFO_LOG_LEVEL;\r |
30fdf114 LG |
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 | |
30fdf114 LG |
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 | |
30fdf114 LG |
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 | |
30fdf114 LG |
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 | |
fd171542 | 326 | UINT64 MsgLevel,\r |
30fdf114 LG |
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 | |
30fdf114 LG |
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 | |
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 | |
529 | STATIC\r | |
530 | VOID\r | |
531 | PrintSimpleMessage (\r | |
532 | CHAR8 *MsgFmt,\r | |
533 | va_list List\r | |
534 | )\r | |
535 | /*++\r | |
536 | Routine Description:\r | |
537 | Print message into stdout.\r | |
538 | \r | |
539 | Arguments:\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 | |
544 | Returns:\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 | |
558 | VOID\r | |
559 | ParserSetPosition (\r | |
560 | CHAR8 *SourceFileName,\r | |
561 | UINT32 LineNum\r | |
562 | )\r | |
563 | /*++\r | |
564 | \r | |
565 | Routine 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 | |
569 | Arguments:\r | |
570 | SourceFileName - name of the source file being parsed\r | |
571 | LineNum - line number of the source file being parsed\r | |
572 | \r | |
573 | Returns:\r | |
574 | NA\r | |
575 | \r | |
576 | --*/\r | |
577 | {\r | |
578 | mSourceFileName = SourceFileName;\r | |
579 | mSourceFileLineNum = LineNum;\r | |
580 | }\r | |
581 | \r | |
582 | VOID\r | |
583 | SetUtilityName (\r | |
584 | CHAR8 *UtilityName\r | |
585 | )\r | |
586 | /*++\r | |
587 | \r | |
588 | Routine 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 | |
595 | Arguments:\r | |
596 | UtilityName - name of the utility, which will be printed with all\r | |
597 | error/warning/debug messags.\r | |
598 | \r | |
599 | Returns:\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 | |
611 | strncpy (mUtilityName, UtilityName, sizeof (mUtilityName) - 1);\r | |
612 | mUtilityName[sizeof (mUtilityName) - 1] = 0;\r | |
613 | return ;\r | |
614 | } else {\r | |
615 | strcpy (mUtilityName, UtilityName);\r | |
616 | }\r | |
617 | } else {\r | |
618 | Error (NULL, 0, 0, "application error", "SetUtilityName() called with NULL utility name");\r | |
619 | }\r | |
620 | }\r | |
621 | \r | |
622 | STATUS\r | |
623 | GetUtilityStatus (\r | |
624 | VOID\r | |
625 | )\r | |
626 | /*++\r | |
627 | \r | |
628 | Routine Description:\r | |
629 | When you call Error() or Warning(), this module keeps track of it and\r | |
630 | sets a local mStatus to STATUS_ERROR or STATUS_WARNING. When the utility\r | |
631 | exits, it can call this function to get the status and use it as a return\r | |
632 | value.\r | |
633 | \r | |
634 | Arguments:\r | |
635 | None.\r | |
636 | \r | |
637 | Returns:\r | |
638 | Worst-case status reported, as defined by which print function was called.\r | |
639 | \r | |
640 | --*/\r | |
641 | {\r | |
642 | return mStatus;\r | |
643 | }\r | |
644 | \r | |
645 | VOID\r | |
646 | SetPrintLevel (\r | |
fd171542 | 647 | UINT64 LogLevel\r |
30fdf114 LG |
648 | )\r |
649 | /*++\r | |
650 | \r | |
651 | Routine Description:\r | |
652 | Set the printing message Level. This is used by the PrintMsg() function\r | |
653 | to determine when/if a message should be printed.\r | |
654 | \r | |
655 | Arguments:\r | |
656 | LogLevel - 0~50 to specify the different level message.\r | |
657 | \r | |
658 | Returns:\r | |
659 | NA\r | |
660 | \r | |
661 | --*/\r | |
662 | {\r | |
663 | mPrintLogLevel = LogLevel;\r | |
664 | }\r | |
665 | \r | |
666 | VOID\r | |
667 | VerboseMsg (\r | |
668 | CHAR8 *MsgFmt,\r | |
669 | ...\r | |
670 | )\r | |
671 | /*++\r | |
672 | \r | |
673 | Routine Description:\r | |
674 | Print a verbose level message.\r | |
675 | \r | |
676 | Arguments:\r | |
677 | MsgFmt - the format string for the message. Can contain formatting\r | |
678 | controls for use with varargs.\r | |
679 | List - the variable list.\r | |
680 | \r | |
681 | Returns:\r | |
682 | NA\r | |
683 | \r | |
684 | --*/\r | |
685 | {\r | |
686 | va_list List;\r | |
687 | //\r | |
688 | // If the debug level is less than current print level, then do nothing.\r | |
689 | //\r | |
690 | if (VERBOSE_LOG_LEVEL < mPrintLogLevel) {\r | |
691 | return ;\r | |
692 | }\r | |
693 | \r | |
694 | va_start (List, MsgFmt);\r | |
695 | PrintSimpleMessage (MsgFmt, List);\r | |
696 | va_end (List);\r | |
697 | }\r | |
698 | \r | |
699 | VOID\r | |
700 | NormalMsg (\r | |
701 | CHAR8 *MsgFmt,\r | |
702 | ...\r | |
703 | )\r | |
704 | /*++\r | |
705 | \r | |
706 | Routine Description:\r | |
707 | Print a default level message.\r | |
708 | \r | |
709 | Arguments:\r | |
710 | MsgFmt - the format string for the message. Can contain formatting\r | |
711 | controls for use with varargs.\r | |
712 | List - the variable list.\r | |
713 | \r | |
714 | Returns:\r | |
715 | NA\r | |
716 | \r | |
717 | --*/\r | |
718 | {\r | |
719 | va_list List;\r | |
720 | //\r | |
721 | // If the debug level is less than current print level, then do nothing.\r | |
722 | //\r | |
723 | if (INFO_LOG_LEVEL < mPrintLogLevel) {\r | |
724 | return ;\r | |
725 | }\r | |
726 | \r | |
727 | va_start (List, MsgFmt);\r | |
728 | PrintSimpleMessage (MsgFmt, List);\r | |
729 | va_end (List);\r | |
730 | }\r | |
731 | \r | |
732 | VOID\r | |
733 | KeyMsg (\r | |
734 | CHAR8 *MsgFmt,\r | |
735 | ...\r | |
736 | )\r | |
737 | /*++\r | |
738 | \r | |
739 | Routine Description:\r | |
740 | Print a key level message.\r | |
741 | \r | |
742 | Arguments:\r | |
743 | MsgFmt - the format string for the message. Can contain formatting\r | |
744 | controls for use with varargs.\r | |
745 | List - the variable list.\r | |
746 | \r | |
747 | Returns:\r | |
748 | NA\r | |
749 | \r | |
750 | --*/\r | |
751 | {\r | |
752 | va_list List;\r | |
753 | //\r | |
754 | // If the debug level is less than current print level, then do nothing.\r | |
755 | //\r | |
756 | if (KEY_LOG_LEVEL < mPrintLogLevel) {\r | |
757 | return ;\r | |
758 | }\r | |
759 | \r | |
760 | va_start (List, MsgFmt);\r | |
761 | PrintSimpleMessage (MsgFmt, List);\r | |
762 | va_end (List);\r | |
763 | }\r | |
764 | \r | |
765 | VOID\r | |
766 | SetPrintLimits (\r | |
767 | UINT32 MaxErrors,\r | |
768 | UINT32 MaxWarnings,\r | |
769 | UINT32 MaxWarningsPlusErrors\r | |
770 | )\r | |
771 | /*++\r | |
772 | \r | |
773 | Routine Description:\r | |
774 | Set the limits of how many errors, warnings, and errors+warnings\r | |
775 | we will print.\r | |
776 | \r | |
777 | Arguments:\r | |
778 | MaxErrors - maximum number of error messages to print\r | |
779 | MaxWarnings - maximum number of warning messages to print\r | |
780 | MaxWarningsPlusErrors\r | |
781 | - maximum number of errors+warnings to print\r | |
782 | \r | |
783 | Returns:\r | |
784 | NA\r | |
785 | \r | |
786 | --*/\r | |
787 | {\r | |
788 | mMaxErrors = MaxErrors;\r | |
789 | mMaxWarnings = MaxWarnings;\r | |
790 | mMaxWarningsPlusErrors = MaxWarningsPlusErrors;\r | |
791 | mPrintLimitsSet = 1;\r | |
792 | }\r | |
793 | \r | |
794 | STATIC\r | |
795 | VOID\r | |
796 | PrintLimitExceeded (\r | |
797 | VOID\r | |
798 | )\r | |
799 | {\r | |
800 | STATIC INT8 mPrintLimitExceeded = 0;\r | |
801 | //\r | |
802 | // If we've already printed the message, do nothing. Otherwise\r | |
803 | // temporarily increase our print limits so we can pass one\r | |
804 | // more message through.\r | |
805 | //\r | |
806 | if (mPrintLimitExceeded == 0) {\r | |
807 | mPrintLimitExceeded++;\r | |
808 | mMaxErrors++;\r | |
809 | mMaxWarnings++;\r | |
810 | mMaxWarningsPlusErrors++;\r | |
811 | Error (NULL, 0, 0, "error/warning print limit exceeded", NULL);\r | |
812 | mMaxErrors--;\r | |
813 | mMaxWarnings--;\r | |
814 | mMaxWarningsPlusErrors--;\r | |
815 | }\r | |
816 | }\r | |
817 | \r | |
818 | #if 0\r | |
819 | VOID\r | |
820 | TestUtilityMessages (\r | |
821 | VOID\r | |
822 | )\r | |
823 | {\r | |
824 | CHAR8 *ArgStr = "ArgString";\r | |
fd171542 | 825 | int ArgInt;\r |
30fdf114 LG |
826 | \r |
827 | ArgInt = 0x12345678;\r | |
828 | //\r | |
829 | // Test without setting utility name\r | |
830 | //\r | |
831 | fprintf (stdout, "* Testing without setting utility name\n");\r | |
832 | fprintf (stdout, "** Test debug message not printed\n");\r | |
833 | DebugMsg (NULL, 0, 0x00000001, NULL, NULL);\r | |
834 | fprintf (stdout, "** Test warning with two strings and two args\n");\r | |
835 | Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
836 | fprintf (stdout, "** Test error with two strings and two args\n");\r | |
837 | Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
838 | fprintf (stdout, "** Test parser warning with nothing\n");\r | |
839 | ParserWarning (0, NULL, NULL);\r | |
840 | fprintf (stdout, "** Test parser error with nothing\n");\r | |
841 | ParserError (0, NULL, NULL);\r | |
842 | //\r | |
843 | // Test with utility name set now\r | |
844 | //\r | |
845 | fprintf (stdout, "** Testingin with utility name set\n");\r | |
846 | SetUtilityName ("MyUtilityName");\r | |
847 | //\r | |
848 | // Test debug prints\r | |
849 | //\r | |
850 | SetDebugMsgMask (2);\r | |
851 | fprintf (stdout, "** Test debug message with one string\n");\r | |
852 | DebugMsg (NULL, 0, 0x00000002, "Text1", NULL);\r | |
853 | fprintf (stdout, "** Test debug message with one string\n");\r | |
854 | DebugMsg (NULL, 0, 0x00000002, NULL, "Text2");\r | |
855 | fprintf (stdout, "** Test debug message with two strings\n");\r | |
856 | DebugMsg (NULL, 0, 0x00000002, "Text1", "Text2");\r | |
857 | fprintf (stdout, "** Test debug message with two strings and two args\n");\r | |
858 | DebugMsg (NULL, 0, 0x00000002, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
859 | //\r | |
860 | // Test warning prints\r | |
861 | //\r | |
862 | fprintf (stdout, "** Test warning with no strings\n");\r | |
863 | Warning (NULL, 0, 1234, NULL, NULL);\r | |
864 | fprintf (stdout, "** Test warning with one string\n");\r | |
865 | Warning (NULL, 0, 1234, "Text1", NULL);\r | |
866 | fprintf (stdout, "** Test warning with one string\n");\r | |
867 | Warning (NULL, 0, 1234, NULL, "Text2");\r | |
868 | fprintf (stdout, "** Test warning with two strings and two args\n");\r | |
869 | Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
870 | //\r | |
871 | // Test error prints\r | |
872 | //\r | |
873 | fprintf (stdout, "** Test error with no strings\n");\r | |
874 | Error (NULL, 0, 1234, NULL, NULL);\r | |
875 | fprintf (stdout, "** Test error with one string\n");\r | |
876 | Error (NULL, 0, 1234, "Text1", NULL);\r | |
877 | fprintf (stdout, "** Test error with one string\n");\r | |
878 | Error (NULL, 0, 1234, NULL, "Text2");\r | |
879 | fprintf (stdout, "** Test error with two strings and two args\n");\r | |
880 | Error (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
881 | //\r | |
882 | // Test parser prints\r | |
883 | //\r | |
884 | fprintf (stdout, "** Test parser errors\n");\r | |
885 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
886 | ParserError (1234, NULL, NULL);\r | |
887 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
888 | ParserError (1234, "Text1", NULL);\r | |
889 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
890 | ParserError (1234, NULL, "Text2");\r | |
891 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
892 | ParserError (1234, "Text1", "Text2");\r | |
893 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
894 | ParserError (1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
895 | \r | |
896 | fprintf (stdout, "** Test parser warnings\n");\r | |
897 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
898 | ParserWarning (4321, NULL, NULL);\r | |
899 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
900 | ParserWarning (4321, "Text1", NULL);\r | |
901 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
902 | ParserWarning (4321, NULL, "Text2");\r | |
903 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
904 | ParserWarning (4321, "Text1", "Text2");\r | |
905 | ParserSetPosition (__FILE__, __LINE__ + 1);\r | |
906 | ParserWarning (4321, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r | |
907 | }\r | |
908 | #endif\r |