Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
2.7 KiB

  1. /*****************************************************************************
  2. *
  3. * assert.c
  4. *
  5. *****************************************************************************/
  6. #include "m4.h"
  7. /*****************************************************************************
  8. *
  9. * PrintPtszPtszVa
  10. *
  11. * Perform printf-style formatting, but much more restricted.
  12. *
  13. * %s - null-terminated string
  14. * %P - snapped TOKEN structure
  15. * %d - decimal number
  16. *
  17. *****************************************************************************/
  18. UINT STDCALL
  19. PrintPtszPtszVa(PTSTR ptszBuf, PCTSTR ptszFormat, va_list ap)
  20. {
  21. PTSTR ptsz = ptszBuf;
  22. PTOK ptok;
  23. for (;;) {
  24. if (*ptszFormat != '%') {
  25. *ptsz++ = *ptszFormat;
  26. if (*ptszFormat == TEXT('\0'))
  27. return (UINT)(ptsz - ptszBuf - 1);
  28. ptszFormat++;
  29. continue;
  30. }
  31. /*
  32. * Found a formatting character.
  33. */
  34. ptszFormat++;
  35. switch (*ptszFormat) {
  36. /*
  37. * %s - null-terminated string
  38. */
  39. case 's':
  40. ptsz += PrintPtchPtchV(ptsz, TEXT("%s"), va_arg(ap, PCTSTR));
  41. break;
  42. /*
  43. * %d - decimal integer
  44. */
  45. case 'd':
  46. ptsz += PrintPtchPtchV(ptsz, TEXT("%d"), va_arg(ap, int));
  47. break;
  48. /*
  49. * %P - snapped token
  50. */
  51. case 'P':
  52. ptok = va_arg(ap, PTOK);
  53. AssertSPtok(ptok);
  54. Assert(fClosedPtok(ptok));
  55. CopyPtchPtchCtch(ptsz, ptok->u.ptch, ptok->ctch);
  56. ptsz += ptok->ctch;
  57. break;
  58. case '%':
  59. *ptsz++ = TEXT('%');
  60. break;
  61. default:
  62. Assert(0); break;
  63. }
  64. ptszFormat++;
  65. }
  66. }
  67. /*****************************************************************************
  68. *
  69. * Die
  70. *
  71. * Squirt a message and die.
  72. *
  73. *****************************************************************************/
  74. NORETURN void CDECL
  75. Die(PCTSTR ptszFormat, ...)
  76. {
  77. TCHAR tszBuf[1024];
  78. va_list ap;
  79. CTCH ctch;
  80. va_start(ap, ptszFormat);
  81. ctch = PrintPtszPtszVa(tszBuf, ptszFormat, ap);
  82. va_end(ap);
  83. cbWriteHfPvCb(hfErr, tszBuf, cbCtch(ctch));
  84. exit(1);
  85. }
  86. #ifdef DEBUG
  87. /*****************************************************************************
  88. *
  89. * AssertPszPszLn
  90. *
  91. * An assertion just failed. pszExpr is the expression, pszFile is the
  92. * filename, and iLine is the line number.
  93. *
  94. *****************************************************************************/
  95. NORETURN int STDCALL
  96. AssertPszPszLn(PCSTR pszExpr, PCSTR pszFile, int iLine)
  97. {
  98. Die(TEXT("Assertion failed: `%s' at %s(%d)") EOL, pszExpr, pszFile, iLine);
  99. return 0;
  100. }
  101. #endif