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.

181 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. local.c
  6. // @@BEGIN_DDKSPLIT
  7. Abstract:
  8. Implementation of debug functions
  9. Environment:
  10. User Mode -Win32
  11. Revision History:
  12. // @@END_DDKSPLIT
  13. --*/
  14. #if DBG
  15. #include "local.h"
  16. #include <tchar.h>
  17. #include <stdarg.h>
  18. #include <stdio.h>
  19. /*++
  20. Title:
  21. vsntprintf
  22. Routine Description:
  23. Formats a string and returns a heap allocated string with the
  24. formated data. This routine can be used to for extremely
  25. long format strings. Note: If a valid pointer is returned
  26. the callng functions must release the data with a call to delete.
  27. Arguments:
  28. psFmt - format string
  29. pArgs - pointer to a argument list.
  30. Return Value:
  31. Pointer to formated string. NULL if error.
  32. --*/
  33. LPSTR
  34. vsntprintf(
  35. IN LPCSTR szFmt,
  36. IN va_list pArgs
  37. )
  38. {
  39. LPSTR pszBuff;
  40. UINT uSize = 256;
  41. for( ; ; )
  42. {
  43. pszBuff = AllocSplMem(sizeof(char) * uSize);
  44. if (!pszBuff)
  45. {
  46. break;
  47. }
  48. //
  49. // Attempt to format the string. snprintf fails with a
  50. // negative number when the buffer is too small.
  51. //
  52. if (_vsnprintf(pszBuff, uSize, szFmt, pArgs) >= 0)
  53. {
  54. break;
  55. }
  56. FreeSplMem(pszBuff);
  57. pszBuff = NULL;
  58. //
  59. // Double the buffer size after each failure.
  60. //
  61. uSize *= 2;
  62. //
  63. // If the size is greater than 100k exit without formatting a string.
  64. //
  65. if (uSize > 100*1024)
  66. {
  67. break;
  68. }
  69. }
  70. return pszBuff;
  71. }
  72. /*++
  73. Title:
  74. DbgPrint
  75. Routine Description:
  76. Format the string similar to sprintf and output it in the debugger.
  77. Arguments:
  78. pszFmt pointer format string.
  79. .. variable number of arguments similar to sprintf.
  80. Return Value:
  81. 0
  82. --*/
  83. BOOL
  84. DebugPrint(
  85. PCH pszFmt,
  86. ...
  87. )
  88. {
  89. LPSTR pszString = NULL;
  90. BOOL bReturn;
  91. va_list pArgs;
  92. va_start( pArgs, pszFmt );
  93. pszString = vsntprintf( pszFmt, pArgs );
  94. bReturn = !!pszString;
  95. va_end( pArgs );
  96. if (pszString)
  97. {
  98. OutputDebugStringA(pszString);
  99. FreeSplMem(pszString);
  100. }
  101. return bReturn;
  102. }
  103. // @@BEGIN_DDKSPLIT
  104. #ifdef NEVER
  105. VOID
  106. vTest(
  107. IN LPTSTR pPrinterName,
  108. IN LPTSTR pDocName
  109. )
  110. {
  111. WCHAR buf[250];
  112. UINT i;
  113. ODS(("Printer %ws\nDocument %ws\n\n", pPrinterName, pDocName));
  114. ODS(("Some numbers: %u %u %u %u %u %u %u \n\n", 1, 2, 3, 4, 5, 6 ,7));
  115. for (i=0;i<250;i++)
  116. {
  117. buf[i] = i%40 + 40 ;
  118. }
  119. ODS(("The string %ws \n\n", buf));
  120. }
  121. #endif //NEVER
  122. // @@END_DDKSPLIT
  123. #endif // DBG