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.

83 lines
2.5 KiB

  1. #include "stdinc.h"
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4. #include "debmacro.h"
  5. #include "fusionbuffer.h"
  6. #include "util.h"
  7. BOOL
  8. FusionpFormatFlags(
  9. DWORD dwFlagsToFormat,
  10. bool fUseLongNames,
  11. SIZE_T cMapEntries,
  12. PCFUSION_FLAG_FORMAT_MAP_ENTRY prgMapEntries,
  13. CBaseStringBuffer &rbuff
  14. )
  15. {
  16. FN_PROLOG_WIN32;
  17. CSmallStringBuffer buffTemp;
  18. SIZE_T i;
  19. rbuff.Clear();
  20. for (i=0; i<cMapEntries; i++)
  21. {
  22. // What the heck does a flag mask of 0 mean?
  23. INTERNAL_ERROR_CHECK(prgMapEntries[i].m_dwFlagMask != 0);
  24. if ((prgMapEntries[i].m_dwFlagMask != 0) &&
  25. ((dwFlagsToFormat & prgMapEntries[i].m_dwFlagMask) == prgMapEntries[i].m_dwFlagMask))
  26. {
  27. // we have a winner...
  28. if (buffTemp.Cch() != 0)
  29. {
  30. if (fUseLongNames)
  31. IFW32FALSE_EXIT(buffTemp.Win32Append(L" | ", 3));
  32. else
  33. IFW32FALSE_EXIT(buffTemp.Win32Append(L", ", 2));
  34. }
  35. if (fUseLongNames)
  36. IFW32FALSE_EXIT(buffTemp.Win32Append(prgMapEntries[i].m_pszString, prgMapEntries[i].m_cchString));
  37. else
  38. IFW32FALSE_EXIT(buffTemp.Win32Append(prgMapEntries[i].m_pszShortString, prgMapEntries[i].m_cchShortString));
  39. if (prgMapEntries[i].m_dwFlagsToTurnOff != 0)
  40. dwFlagsToFormat &= ~(prgMapEntries[i].m_dwFlagsToTurnOff);
  41. else
  42. dwFlagsToFormat &= ~(prgMapEntries[i].m_dwFlagMask);
  43. }
  44. }
  45. if (dwFlagsToFormat != 0)
  46. {
  47. const static WCHAR comma[] = L", ";
  48. WCHAR rgwchHexBuffer[16];
  49. int nCharsWritten = ::_snwprintf(rgwchHexBuffer, NUMBER_OF(rgwchHexBuffer), L"0x%08lx", dwFlagsToFormat);
  50. rgwchHexBuffer[NUMBER_OF(rgwchHexBuffer) - 1] = L'\0';
  51. if (nCharsWritten < 0)
  52. nCharsWritten = 0;
  53. rgwchHexBuffer[nCharsWritten] = L'\0';
  54. if (buffTemp.Cch() != 0)
  55. IFW32FALSE_EXIT(buffTemp.Win32Append(comma, NUMBER_OF(comma) - 1));
  56. IFW32FALSE_EXIT(buffTemp.Win32Append(rgwchHexBuffer, nCharsWritten));
  57. }
  58. // if we didn't write anything; at least say that.
  59. if (buffTemp.Cch() == 0)
  60. {
  61. const static WCHAR none[] = L"<none>";
  62. IFW32FALSE_EXIT(rbuff.Win32Assign(none, NUMBER_OF(none) - 1));
  63. }
  64. else
  65. IFW32FALSE_EXIT(rbuff.Win32Assign(buffTemp));
  66. FN_EPILOG;
  67. }