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.

181 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1999-2003 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 <stdarg.h>
  17. #include <stdio.h>
  18. /*++
  19. Title:
  20. vsntprintf
  21. Routine Description:
  22. Formats a string and returns a heap allocated string with the
  23. formated data. This routine can be used to for extremely
  24. long format strings. Note: If a valid pointer is returned
  25. the callng functions must release the data with a call to delete.
  26. Arguments:
  27. psFmt - format string
  28. pArgs - pointer to a argument list.
  29. Return Value:
  30. Pointer to formated string. NULL if error.
  31. --*/
  32. LPSTR
  33. vsntprintf(
  34. IN LPCSTR szFmt,
  35. IN va_list pArgs
  36. )
  37. {
  38. LPSTR pszBuff;
  39. UINT uSize = 256;
  40. for( ; ; )
  41. {
  42. pszBuff = AllocSplMem(sizeof(char) * uSize);
  43. if (!pszBuff)
  44. {
  45. break;
  46. }
  47. //
  48. // Attempt to format the string. If format succeeds, get out
  49. // of the loop. If it fails, increase buffer size and continue.
  50. // (assuming failure is due to less buffer size).
  51. //
  52. if (SUCCEEDED ( StringCchVPrintfA(pszBuff, uSize, szFmt, pArgs) ) )
  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