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.

130 lines
3.0 KiB

  1. #include "common.hpp"
  2. #ifndef NO_LTRACE
  3. int __CLTraceScope::s_depth = 0;
  4. static const int g_LTRACEBUFLEN = 2048;
  5. static TCHAR g_buf[g_LTRACEBUFLEN];
  6. static TCHAR g_buf2[g_LTRACEBUFLEN];
  7. void __trace(LPCTSTR format, ...)
  8. {
  9. va_list args;
  10. va_start(args, format);
  11. #ifdef WIN95
  12. {
  13. char *psz = NULL;
  14. char szDfs[1024]={0};
  15. strcpy(szDfs,Format); // make a local copy of format string
  16. while (psz = strstr(szDfs,"%p")) // find each %p
  17. *(psz+1) = 'x'; // replace each %p with %x
  18. _vstprintf(g_buf2, szDfs, args); // use the local format string
  19. }
  20. #else
  21. {
  22. _vstprintf(g_buf2, format, args);
  23. }
  24. #endif
  25. va_end(args);
  26. OutputDebugString((LPCTSTR)g_buf2);
  27. }
  28. __CLTraceScope::__CLTraceScope(LPCTSTR scope, LPCTSTR file, int line) :
  29. m_scope(NULL), m_file(file), m_line(line), m_depth(s_depth++)
  30. {
  31. __trace(_T("{LTF}\t%s{ %s\n"), spacing(), scope);
  32. }
  33. __CLTraceScope::__CLTraceScope(LPCTSTR file, int line) :
  34. m_scope(NULL), m_file(file), m_line(line), m_depth(s_depth++)
  35. {
  36. }
  37. __CLTraceScope::~__CLTraceScope()
  38. {
  39. s_depth--;
  40. __trace(_T("{LTF}\t%s}\n"), spacing());
  41. }
  42. void __CLTraceScope::ltrace(LPCTSTR format, ...)
  43. {
  44. va_list args;
  45. va_start(args, format);
  46. #ifdef WIN95
  47. {
  48. char *psz = NULL;
  49. char szDfs[1024]={0};
  50. strcpy(szDfs,format); // make a local copy of format string
  51. while (psz = strstr(szDfs,"%p")) // find each %p
  52. *(psz+1) = 'x'; // replace each %p with %x
  53. _vstprintf(g_buf, szDfs, args); // use the local format string
  54. }
  55. #else
  56. {
  57. _vstprintf(g_buf, format, args);
  58. }
  59. #endif
  60. va_end(args);
  61. __trace(_T("{LTF}\t%s|- %s\n"), spacing(), g_buf);
  62. }
  63. void __CLTraceScope::scope(LPCTSTR format, ...)
  64. {
  65. va_list args;
  66. va_start(args, format);
  67. #ifdef WIN95
  68. {
  69. char *psz = NULL;
  70. char szDfs[1024]={0};
  71. strcpy(szDfs,format); // make a local copy of format string
  72. while (psz = strstr(szDfs,"%p")) // find each %p
  73. *(psz+1) = 'x'; // replace each %p with %x
  74. _vstprintf(g_buf, szDfs, args); // use the local format string
  75. }
  76. #else
  77. {
  78. _vstprintf(g_buf, format, args);
  79. }
  80. #endif
  81. va_end(args);
  82. __trace(_T("{LTF}\t%s{ %s\n"), spacing(), g_buf);
  83. }
  84. LPCTSTR __CLTraceScope::spacing()
  85. {
  86. const int SPACINGCHAR = _T(' ');
  87. const int SPACERSPERDEPTH = 3;
  88. const int DEPTHCHAR = _T('|');
  89. const int MINSPACING = 1;
  90. const int MAXSPACING = 128;
  91. static TCHAR space[MAXSPACING + 1], backup[MAXSPACING + 1];
  92. static bool sinit = false;
  93. if (!sinit)
  94. {
  95. for (int i = 0; i < MAXSPACING;)
  96. {
  97. for (int s = 0; s < SPACERSPERDEPTH && i < MAXSPACING; s++)
  98. space[i++] = SPACINGCHAR;
  99. if (i >= MAXSPACING)
  100. break;
  101. space[i++] = DEPTHCHAR;
  102. }
  103. space[MAXSPACING] = 0;
  104. strcpy(backup, space);
  105. sinit = true;
  106. }
  107. else
  108. strcpy(space, backup); // todo: this can be greatly optimized :)
  109. int zat = (MINSPACING + m_depth) * (SPACERSPERDEPTH + 1) - 1;
  110. if (zat > MAXSPACING)
  111. zat = MAXSPACING;
  112. space[zat] = 0;
  113. return space;
  114. }
  115. #endif