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.0 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: utility.cpp
  4. //
  5. // Module: CMMON32.EXE
  6. //
  7. // Synopsis: Utility functions for cmmon32.exe.
  8. //
  9. // Copyright (c) 1998-1999 Microsoft Corporation
  10. //
  11. // Author: quintinb Created Header 08/16/99
  12. //
  13. //+----------------------------------------------------------------------------
  14. #include "cmmaster.h"
  15. #include "cm_misc.h"
  16. #include <stdio.h>
  17. #include "resource.h"
  18. #include <stdlib.h>
  19. //+----------------------------------------------------------------------------
  20. //
  21. // Function: FmtNum
  22. //
  23. // Synopsis: Formats a number according to current locale
  24. //
  25. // Arguments: DWORD dwNum - Number to be formatted
  26. // LPTSTR pszNum - Buffer to receive formatted output
  27. // DWORD dwNumSize - Size of buffer
  28. //
  29. // Returns: Nothing
  30. //
  31. // History: nickball Created Header 3/30/98
  32. //
  33. //+----------------------------------------------------------------------------
  34. void FmtNum(DWORD dwNum, LPSTR pszNum, DWORD dwNumSize)
  35. {
  36. static BOOL bLocaleInit = FALSE;
  37. static UINT nDecimalDigits;
  38. DWORD dwNumLen;
  39. CHAR szRawNum[MAX_PATH];
  40. if (!bLocaleInit)
  41. {
  42. int iRes;
  43. bLocaleInit = TRUE;
  44. iRes = GetLocaleInfoA(LOCALE_USER_DEFAULT,
  45. LOCALE_IDIGITS,
  46. szRawNum,
  47. (sizeof(szRawNum) / sizeof(CHAR)) - 1);
  48. #ifdef DEBUG
  49. if (!iRes)
  50. {
  51. CMTRACE1(TEXT("FmtNum() GetLocaleInfo() failed, GLE=%u."), GetLastError());
  52. }
  53. #endif
  54. nDecimalDigits = (UINT)CmAtolA(szRawNum);
  55. }
  56. wsprintfA(szRawNum, "%u", dwNum);
  57. GetNumberFormatA(LOCALE_USER_DEFAULT,
  58. 0,
  59. szRawNum,
  60. NULL,
  61. pszNum,
  62. (dwNumSize / sizeof(CHAR)) - 1);
  63. dwNumLen = lstrlenA(pszNum);
  64. if (nDecimalDigits && (dwNumLen > nDecimalDigits) && !CmIsDigitA(pszNum+dwNumLen - nDecimalDigits - 1))
  65. {
  66. pszNum[dwNumLen - nDecimalDigits - 1] = 0;
  67. }
  68. else
  69. {
  70. CMTRACE(TEXT("FmtNum() unexpected decimal output."));
  71. bLocaleInit = FALSE;
  72. }
  73. }