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.

133 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. misc.c
  5. Abstract:
  6. This is the console fullscreen driver for the VGA card.
  7. Environment:
  8. kernel mode only
  9. Notes:
  10. Revision History:
  11. --*/
  12. #include "fsvga.h"
  13. int
  14. ConvertOutputToOem(
  15. IN LPWSTR Source,
  16. IN int SourceLength, // in chars
  17. OUT LPSTR Target,
  18. IN int TargetLength // in chars
  19. )
  20. /*
  21. Converts SourceLength Unicode characters from Source into
  22. not more than TargetLength Codepage characters at Target.
  23. Returns the number characters put in Target. (0 if failure)
  24. [ntcon\server\misc.c]
  25. */
  26. {
  27. NTSTATUS Status;
  28. int Length;
  29. UNICODE_STRING SourceUni;
  30. ANSI_STRING TargetAns;
  31. CHAR AnsBuf[256];
  32. SourceUni.MaximumLength =
  33. SourceUni.Length = SourceLength * sizeof(WCHAR);
  34. SourceUni.Buffer = Source;
  35. TargetAns.Length = 0;
  36. TargetAns.MaximumLength = sizeof(AnsBuf);
  37. TargetAns.Buffer = AnsBuf;
  38. // Can do this in place
  39. Status = RtlUnicodeStringToAnsiString(&TargetAns,
  40. &SourceUni,
  41. FALSE);
  42. if (NT_SUCCESS(Status)) {
  43. Length = strlen(AnsBuf);
  44. if (Length <= TargetLength) {
  45. RtlMoveMemory(Target, AnsBuf, Length);
  46. return Length;
  47. }
  48. else {
  49. return 0;
  50. }
  51. } else {
  52. return 0;
  53. }
  54. }
  55. /***************************************************************************\
  56. * TranslateOutputToOem
  57. *
  58. * routine to translate console PCHAR_INFO to the ASCII from Unicode
  59. *
  60. * [ntcon\server\fe\direct2.c]
  61. \***************************************************************************/
  62. NTSTATUS
  63. TranslateOutputToOem(
  64. OUT PCHAR_IMAGE_INFO OutputBuffer,
  65. IN PCHAR_IMAGE_INFO InputBuffer,
  66. IN ULONG Length
  67. )
  68. {
  69. CHAR AsciiDbcs[2];
  70. ULONG NumBytes;
  71. while (Length--)
  72. {
  73. if (InputBuffer->CharInfo.Attributes & COMMON_LVB_LEADING_BYTE)
  74. {
  75. if (Length >= 2) // Safe DBCS in buffer ?
  76. {
  77. Length--;
  78. NumBytes = sizeof(AsciiDbcs);
  79. NumBytes = ConvertOutputToOem(&InputBuffer->CharInfo.Char.UnicodeChar,
  80. 1,
  81. &AsciiDbcs[0],
  82. NumBytes);
  83. OutputBuffer->CharInfo.Char.AsciiChar = AsciiDbcs[0];
  84. OutputBuffer->CharInfo.Attributes = InputBuffer->CharInfo.Attributes;
  85. OutputBuffer++;
  86. InputBuffer++;
  87. OutputBuffer->CharInfo.Char.AsciiChar = AsciiDbcs[1];
  88. OutputBuffer->CharInfo.Attributes = InputBuffer->CharInfo.Attributes;
  89. OutputBuffer++;
  90. InputBuffer++;
  91. }
  92. else
  93. {
  94. OutputBuffer->CharInfo.Char.AsciiChar = ' ';
  95. OutputBuffer->CharInfo.Attributes = InputBuffer->CharInfo.Attributes & ~COMMON_LVB_SBCSDBCS;
  96. OutputBuffer++;
  97. InputBuffer++;
  98. }
  99. }
  100. else if (! (InputBuffer->CharInfo.Attributes & COMMON_LVB_SBCSDBCS))
  101. {
  102. ConvertOutputToOem(&InputBuffer->CharInfo.Char.UnicodeChar,
  103. 1,
  104. &OutputBuffer->CharInfo.Char.AsciiChar,
  105. 1);
  106. OutputBuffer->CharInfo.Attributes = InputBuffer->CharInfo.Attributes;
  107. OutputBuffer++;
  108. InputBuffer++;
  109. }
  110. }
  111. return STATUS_SUCCESS;
  112. }