Leaked source code of windows server 2003
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.

106 lines
3.1 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) Microsoft Corporation, 2000.
  3. //
  4. // errlog.cpp
  5. //
  6. // Direct3D Reference Device - Error log for shader validation.
  7. //
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #include "pch.cpp"
  10. #pragma hdrstop
  11. //-----------------------------------------------------------------------------
  12. // CErrorLog::CErrorLog
  13. //-----------------------------------------------------------------------------
  14. CErrorLog::CErrorLog( BOOL bRememberAllSpew )
  15. {
  16. m_TotalStringLength = 0;
  17. m_pHead = NULL;
  18. m_pTail = NULL;
  19. m_bRememberAllSpew = bRememberAllSpew;
  20. }
  21. //-----------------------------------------------------------------------------
  22. // CErrorLog::~CErrorLog
  23. //-----------------------------------------------------------------------------
  24. CErrorLog::~CErrorLog()
  25. {
  26. ErrorLogNode* pCurr = m_pHead;
  27. while( pCurr )
  28. {
  29. ErrorLogNode* pDeleteMe = pCurr;
  30. pCurr = pCurr->pNext;
  31. delete pDeleteMe;
  32. }
  33. m_pHead = NULL;
  34. m_pTail = NULL;
  35. }
  36. //-----------------------------------------------------------------------------
  37. // CErrorLog::AppendText
  38. //-----------------------------------------------------------------------------
  39. void CErrorLog::AppendText( const char* pszFormat, ... )
  40. {
  41. #if DBG
  42. OutputDebugString("D3D Shader Validator: ");
  43. #endif
  44. ErrorLogNode* pNewString = new ErrorLogNode;
  45. if( NULL == pNewString )
  46. {
  47. OutputDebugString("Out of memory.\n");
  48. return;
  49. }
  50. _snprintf( pNewString->String, ERRORLOG_STRINGSIZE-1, "");
  51. va_list marker;
  52. va_start(marker, pszFormat);
  53. _vsnprintf(pNewString->String+lstrlen(pNewString->String), ERRORLOG_STRINGSIZE - lstrlen(pNewString->String) - 2, pszFormat, marker);
  54. _snprintf( pNewString->String, ERRORLOG_STRINGSIZE - 2, "%s", pNewString->String );
  55. strcat( pNewString->String, "\n" ); // force trailing \n
  56. pNewString->String[ERRORLOG_STRINGSIZE-1] = '\0'; // force trailing \0.
  57. #if DBG
  58. OutputDebugString(pNewString->String);
  59. #endif
  60. if( m_bRememberAllSpew )
  61. {
  62. // append node
  63. if( NULL == m_pHead )
  64. m_pHead = pNewString;
  65. if( NULL != m_pTail )
  66. m_pTail->pNext = pNewString;
  67. m_pTail = pNewString;
  68. pNewString->pNext = NULL;
  69. m_TotalStringLength += strlen(pNewString->String);
  70. }
  71. else
  72. {
  73. delete pNewString;
  74. }
  75. }
  76. //-----------------------------------------------------------------------------
  77. // CErrorLog::WriteLogToBuffer()
  78. //
  79. // Call GetLogBufferSizeRequired() first to figure out how big to make pBuffer
  80. //-----------------------------------------------------------------------------
  81. void CErrorLog::WriteLogToBuffer( char* pBuffer )
  82. {
  83. if( NULL == pBuffer )
  84. return;
  85. pBuffer[0] = '\0';
  86. if( NULL != m_pHead )
  87. {
  88. ErrorLogNode* pCurr = m_pHead;
  89. while( pCurr )
  90. {
  91. strcat(pBuffer,pCurr->String);
  92. pCurr = pCurr->pNext;
  93. }
  94. }
  95. }