Team Fortress 2 Source Code as on 22/4/2020
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.

125 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=======================================================================================//
  4. #include "spew.h"
  5. #include "dbg.h"
  6. #include "strtools.h"
  7. // memdbgon must be the last include file in a .cpp file!!!
  8. #include "tier0/memdbgon.h"
  9. //----------------------------------------------------------------------------------------
  10. class CBlockSpewer : public ISpewer
  11. {
  12. virtual void PrintBlockStart() const
  13. {
  14. Log( "\n********************************************************************************\n*\n" );
  15. }
  16. virtual void PrintBlockEnd() const
  17. {
  18. Log( "*\n********************************************************************************\n\n" );
  19. }
  20. virtual void PrintEmptyLine() const
  21. {
  22. Log( "*\n" );
  23. }
  24. virtual void PrintEventStartMsg( const char *pMsg ) const
  25. {
  26. char pDots[] = { "............................................." };
  27. const int nNumDots = MAX( 3, V_strlen( pDots ) - V_strlen( pMsg ) );
  28. pDots[ nNumDots ] = '\0';
  29. Log( "* %s%s", pMsg, pDots );
  30. }
  31. virtual void PrintEventResult( bool bSuccess ) const
  32. {
  33. Log( "%s\n", bSuccess ? "OK" : "FAILED" );
  34. }
  35. virtual void PrintEventError( const char *pError ) const
  36. {
  37. Log( "*\n*\n* ** ERROR: %s\n*\n", pError );
  38. }
  39. virtual void PrintTestHeader( const char *pHeader ) const
  40. {
  41. Log( "*\n*\n* %s...\n*\n", pHeader );
  42. }
  43. virtual void PrintValue( const char *pWhat, const char *pValue ) const
  44. {
  45. char pSpaces[] = { " " };
  46. const int nNumSpaces = MAX( 3, V_strlen( pSpaces ) - V_strlen( pWhat ) );
  47. pSpaces[ nNumSpaces ] = '\0';
  48. Log( "* %s: %s%s\n", pWhat, pSpaces, pValue );
  49. }
  50. virtual void PrintMsg( const char *pMsg ) const
  51. {
  52. Log( "* %s\n", pMsg );
  53. }
  54. };
  55. //----------------------------------------------------------------------------------------
  56. static CBlockSpewer s_BlockSpewer;
  57. ISpewer *g_pBlockSpewer = &s_BlockSpewer;
  58. //----------------------------------------------------------------------------------------
  59. class CNullSpewer : public ISpewer
  60. {
  61. public:
  62. virtual void PrintBlockStart() const {}
  63. virtual void PrintBlockEnd() const {}
  64. virtual void PrintEmptyLine() const {}
  65. virtual void PrintEventStartMsg( const char *pMsg ) const {}
  66. virtual void PrintEventResult( bool bSuccess ) const {}
  67. virtual void PrintTestHeader( const char *pHeader ) const {}
  68. virtual void PrintMsg( const char *pMsg ) const {}
  69. virtual void PrintValue( const char *pWhat, const char *pValue ) const {}
  70. virtual void PrintEventError( const char *pError ) const
  71. {
  72. Log( "\n\nERROR: %s\n\n", pError );
  73. }
  74. };
  75. //----------------------------------------------------------------------------------------
  76. static CNullSpewer s_NullSpewer;
  77. ISpewer *g_pNullSpewer = &s_NullSpewer;
  78. //----------------------------------------------------------------------------------------
  79. class CSimpleSpewer : public CNullSpewer
  80. {
  81. public:
  82. virtual void PrintMsg( const char *pMsg ) const
  83. {
  84. Log( "%s", pMsg );
  85. }
  86. };
  87. //----------------------------------------------------------------------------------------
  88. static CSimpleSpewer s_SimpleSpewer;
  89. ISpewer *g_pSimpleSpewer = &s_SimpleSpewer;
  90. //----------------------------------------------------------------------------------------
  91. ISpewer *g_pDefaultSpewer = g_pNullSpewer;
  92. //----------------------------------------------------------------------------------------
  93. CBaseSpewer::CBaseSpewer( ISpewer *pSpewer/*=g_pDefaultSpewer*/ )
  94. : m_pSpewer( pSpewer )
  95. {
  96. }
  97. //----------------------------------------------------------------------------------------