EfiUtilityMsgs.c 22 KB

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