EfiUtilityMsgs.c 23 KB

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