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.

178 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. resources.c
  5. Abstract:
  6. This module implements all access to
  7. the resources.
  8. Author:
  9. Wesley Witt (wesw) 21-Oct-1998
  10. Revision History:
  11. --*/
  12. #include "cmdcons.h"
  13. #pragma hdrstop
  14. LPCWSTR _DateTimeFormat;
  15. VOID
  16. vRcMessageOut(
  17. IN ULONG MessageId,
  18. IN va_list *arglist
  19. )
  20. {
  21. WCHAR *p;
  22. NTSTATUS Status;
  23. //
  24. // Load the message
  25. //
  26. p = SpRetreiveMessageText(ImageBase,MessageId,NULL,0);
  27. if(!p) {
  28. return;
  29. }
  30. Status = SpRtlFormatMessage(
  31. p,
  32. 0,
  33. FALSE,
  34. FALSE,
  35. FALSE,
  36. arglist,
  37. _CmdConsBlock->TemporaryBuffer,
  38. _CmdConsBlock->TemporaryBufferSize,
  39. NULL
  40. );
  41. SpMemFree(p);
  42. if(NT_SUCCESS(Status)) {
  43. RcTextOut(_CmdConsBlock->TemporaryBuffer);
  44. }
  45. }
  46. VOID
  47. RcMessageOut(
  48. IN ULONG MessageId,
  49. ...
  50. )
  51. {
  52. va_list arglist;
  53. va_start(arglist,MessageId);
  54. vRcMessageOut(MessageId,&arglist);
  55. va_end(arglist);
  56. }
  57. ULONG
  58. RcFormatDateTime(
  59. IN PLARGE_INTEGER Time,
  60. OUT LPWSTR Output
  61. )
  62. {
  63. TIME_FIELDS TimeFields;
  64. WCHAR *p,*AmPmSpec;
  65. LPCWSTR q;
  66. int i;
  67. //
  68. // Load the system date and time format string if not loaded already.
  69. //
  70. if(!_DateTimeFormat) {
  71. _DateTimeFormat = SpRetreiveMessageText(ImageBase,MSG_DATE_TIME_FORMAT,NULL,0);
  72. if(!_DateTimeFormat) {
  73. _DateTimeFormat = L"m/d/y h:na*";
  74. }
  75. }
  76. //
  77. // Translate the last write time to time fields.
  78. //
  79. RtlTimeToTimeFields(Time,&TimeFields);
  80. //
  81. // Format the date and time.
  82. //
  83. p = Output;
  84. q = _DateTimeFormat;
  85. AmPmSpec = NULL;
  86. while(*q != L'*') {
  87. switch(*q) {
  88. case L'm':
  89. i = TimeFields.Month;
  90. break;
  91. case L'd':
  92. i = TimeFields.Day;
  93. break;
  94. case L'y':
  95. i = TimeFields.Year;
  96. break;
  97. case L'h':
  98. i = TimeFields.Hour % 12;
  99. if(i == 0) {
  100. i = 12;
  101. }
  102. break;
  103. case L'H':
  104. i = TimeFields.Hour;
  105. break;
  106. case L'n':
  107. i = TimeFields.Minute;
  108. break;
  109. case L'a':
  110. i = -1;
  111. AmPmSpec = p++;
  112. break;
  113. default:
  114. i = -1;
  115. *p++ = *q;
  116. break;
  117. }
  118. if(i != -1) {
  119. i = i % 100;
  120. *p++ = (i / 10) + L'0';
  121. *p++ = (i % 10) + L'0';
  122. }
  123. q++;
  124. }
  125. if(AmPmSpec) {
  126. q++; // q points at am specifier
  127. if(TimeFields.Hour >= 12) {
  128. q++; // q points at pm specifier
  129. }
  130. *AmPmSpec = *q;
  131. }
  132. *p = 0;
  133. return (ULONG)(p - Output);
  134. }