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.

80 lines
2.3 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. #define PRINTABLE(_ch) (isprint((_ch)) ? (_ch) : '.')
  8. #if defined(FUSION_WIN) || defined(FUSION_WIN2000)
  9. #define wnsprintfW _snwprintf
  10. #define wnsprintfA _snprintf
  11. #endif
  12. BOOL
  13. FusionpFormatFlags(
  14. DWORD dwFlagsToFormat,
  15. bool fUseLongNames,
  16. SIZE_T cMapEntries,
  17. PCFUSION_FLAG_FORMAT_MAP_ENTRY prgMapEntries,
  18. CBaseStringBuffer &rbuff
  19. )
  20. {
  21. BOOL fSuccess = FALSE;
  22. FN_TRACE_WIN32(fSuccess);
  23. CSmallStringBuffer buffTemp;
  24. SIZE_T i;
  25. for (i=0; i<cMapEntries; i++)
  26. {
  27. // What the heck does a flag mask of 0 mean?
  28. INTERNAL_ERROR_CHECK(prgMapEntries[i].m_dwFlagMask != 0);
  29. if ((prgMapEntries[i].m_dwFlagMask != 0) &&
  30. ((dwFlagsToFormat & prgMapEntries[i].m_dwFlagMask) == prgMapEntries[i].m_dwFlagMask))
  31. {
  32. // we have a winner...
  33. if (buffTemp.Cch() != 0)
  34. {
  35. if (fUseLongNames)
  36. IFW32FALSE_EXIT(buffTemp.Win32Append(L" | ", 3));
  37. else
  38. IFW32FALSE_EXIT(buffTemp.Win32Append(L", ", 2));
  39. }
  40. if (fUseLongNames)
  41. IFW32FALSE_EXIT(buffTemp.Win32Append(prgMapEntries[i].m_pszString, prgMapEntries[i].m_cchString));
  42. else
  43. IFW32FALSE_EXIT(buffTemp.Win32Append(prgMapEntries[i].m_pszShortString, prgMapEntries[i].m_cchShortString));
  44. if (prgMapEntries[i].m_dwFlagsToTurnOff != 0)
  45. dwFlagsToFormat &= ~(prgMapEntries[i].m_dwFlagsToTurnOff);
  46. else
  47. dwFlagsToFormat &= ~(prgMapEntries[i].m_dwFlagMask);
  48. }
  49. }
  50. if (dwFlagsToFormat != 0)
  51. {
  52. WCHAR rgwchHexBuffer[16];
  53. SIZE_T nCharsWritten = wnsprintfW(rgwchHexBuffer, NUMBER_OF(rgwchHexBuffer), L"0x%08lx", dwFlagsToFormat);
  54. if (buffTemp.Cch() != 0)
  55. IFW32FALSE_EXIT(buffTemp.Win32Append(L", ", 2));
  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. IFW32FALSE_EXIT(buffTemp.Win32Assign(L"<none>", 6));
  61. IFW32FALSE_EXIT(rbuff.Win32Assign(buffTemp));
  62. fSuccess = TRUE;
  63. Exit:
  64. return fSuccess;
  65. }