Windows NT 4.0 source code leak
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.

129 lines
3.3 KiB

4 years ago
  1. /***
  2. *initnum.c - contains _init_numeric
  3. *
  4. * Copyright (c) 1991-1993, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Contains the locale-category initialization function: _init_numeric().
  8. *
  9. * Each initialization function sets up locale-specific information
  10. * for their category, for use by functions which are affected by
  11. * their locale category.
  12. *
  13. * *** For internal use by setlocale() only ***
  14. *
  15. *Revision History:
  16. * 12-08-91 ETC Created.
  17. * 12-20-91 ETC Updated to use new NLSAPI GetLocaleInfo.
  18. * 12-18-92 CFW Ported to Cuda tree, changed _CALLTYPE4 to _CRTAPI3.
  19. * 12-29-92 CFW Updated to use new _getlocaleinfo wrapper function.
  20. * 01-25-93 KRS Change interface to _getlocaleinfo again.
  21. * 02-08-93 CFW Added _lconv_static_*.
  22. * 02-17-93 CFW Removed debugging print statement.
  23. * 03-17-93 CFW C locale thousands sep is "", not ",".
  24. * 05-20-93 GJF Include windows.h, not individual win*.h files
  25. * 06-11-93 CFW Now inithelp takes void *.
  26. *
  27. *******************************************************************************/
  28. #ifdef _INTL
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <windows.h>
  32. #include <locale.h>
  33. #include <setlocal.h>
  34. #include <malloc.h>
  35. #include <assert.h>
  36. #include <nlsint.h>
  37. /* Pointer to current lconv */
  38. extern struct lconv *_lconv;
  39. /***
  40. *int _init_numeric() - initialization for LC_NUMERIC locale category.
  41. *
  42. *Purpose:
  43. *
  44. *Entry:
  45. * None.
  46. *
  47. *Exit:
  48. * 0 success
  49. * 1 fail
  50. *
  51. *Exceptions:
  52. *
  53. *******************************************************************************/
  54. int _CRTAPI3 _init_numeric (
  55. void
  56. )
  57. {
  58. static char *decimal_point = NULL;
  59. static char *thousands_sep = NULL;
  60. static char *grouping = NULL;
  61. int ret = 0;
  62. /* Numeric data is country--not language--dependent. NT work-around. */
  63. LCID ctryid = MAKELCID(_lc_id[LC_NUMERIC].wCountry, SORT_DEFAULT);
  64. if (_lc_handle[LC_NUMERIC] != _CLOCALEHANDLE)
  65. {
  66. ret |= _getlocaleinfo(LC_STR_TYPE, ctryid, LOCALE_SDECIMAL, (void *)&decimal_point);
  67. ret |= _getlocaleinfo(LC_STR_TYPE, ctryid, LOCALE_STHOUSAND, (void *)&thousands_sep);
  68. ret |= _getlocaleinfo(LC_STR_TYPE, ctryid, LOCALE_SGROUPING, (void *)&grouping);
  69. if (ret == -1)
  70. {
  71. free (decimal_point);
  72. free (thousands_sep);
  73. free (grouping);
  74. decimal_point = NULL;
  75. thousands_sep = NULL;
  76. grouping = NULL;
  77. return -1;
  78. }
  79. if (_lconv->decimal_point != _lconv_static_decimal)
  80. {
  81. free(_lconv->decimal_point);
  82. free(_lconv->thousands_sep);
  83. free(_lconv->grouping);
  84. }
  85. _lconv->decimal_point = decimal_point;
  86. _lconv->thousands_sep = thousands_sep;
  87. _lconv->grouping = grouping;
  88. #ifdef _DEBUG
  89. assert (strlen(_lconv->decimal_point) == 1);
  90. #endif
  91. /* set global decimal point character */
  92. *_decimal_point = *_lconv->decimal_point;
  93. _decimal_point_length = 1;
  94. return 0;
  95. } else {
  96. free (decimal_point);
  97. free (thousands_sep);
  98. free (grouping);
  99. decimal_point = NULL;
  100. thousands_sep = NULL;
  101. grouping = NULL;
  102. // strdup them so we can free them
  103. _lconv->decimal_point = _strdup(".");
  104. _lconv->thousands_sep = _strdup("");
  105. _lconv->grouping = strdup("");
  106. /* set global decimal point character */
  107. *_decimal_point = *_lconv->decimal_point;
  108. _decimal_point_length = 1;
  109. return 0;
  110. }
  111. }
  112. #endif /* _INTL */