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.

223 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. hdlsterm.c
  5. Abstract:
  6. This modules implements stuff that is specific for headless terminal support.
  7. Author:
  8. Sean Selitrennikoff (v-seans) 1-13-00
  9. Revision History:
  10. --*/
  11. #include "bldr.h"
  12. #include "string.h"
  13. #include "stdlib.h"
  14. #include "stdio.h"
  15. #include "ntverp.h"
  16. #include "bldrx86.h"
  17. #define TERMINAL_LINE_LENGTH 70
  18. BOOLEAN FirstEntry = TRUE;
  19. UCHAR TerminalLine[TERMINAL_LINE_LENGTH];
  20. ULONG LinePosition = 0;
  21. #define TERMINAL_PROMPT "!SAC>"
  22. BOOLEAN
  23. BlpDoCommand(
  24. IN PCHAR InputLine
  25. );
  26. BOOLEAN
  27. BlTerminalHandleLoaderFailure(
  28. VOID
  29. )
  30. /*++
  31. Routine Description:
  32. Gives a mini-SAC to the user, return TRUE when the user wants a reboot.
  33. Arguments:
  34. None.
  35. Return Value:
  36. TRUE - When the user wants a reboot, else FALSE.
  37. --*/
  38. {
  39. ULONG Count;
  40. BOOLEAN Reboot;
  41. ULONG Key;
  42. if (!BlIsTerminalConnected()) {
  43. return TRUE;
  44. }
  45. //
  46. // Position the cursor to the bottom of the screen and write the prompt
  47. //
  48. if (FirstEntry) {
  49. FirstEntry = FALSE;
  50. BlPositionCursor(1, ScreenHeight);
  51. ArcWrite(BlConsoleOutDeviceId, "\r\n", (ULONG)strlen("\r\n"), &Count);
  52. ArcWrite(BlConsoleOutDeviceId, TERMINAL_PROMPT, (ULONG)strlen(TERMINAL_PROMPT), &Count);
  53. }
  54. //
  55. // Check for input.
  56. //
  57. if (ArcGetReadStatus(BlConsoleInDeviceId) == ESUCCESS) {
  58. Key = BlGetKey();
  59. if (Key == ESCAPE_KEY) {
  60. //
  61. // Clear this line
  62. //
  63. ArcWrite(BlConsoleOutDeviceId, "\\", (ULONG)strlen("\\"), &Count);
  64. BlPositionCursor(1, ScreenHeight);
  65. ArcWrite(BlConsoleOutDeviceId, "\r\n", (ULONG)strlen("\r\n"), &Count);
  66. ArcWrite(BlConsoleOutDeviceId, TERMINAL_PROMPT, (ULONG)strlen(TERMINAL_PROMPT), &Count);
  67. return FALSE;
  68. }
  69. if (Key == BKSP_KEY) {
  70. if (LinePosition != 0) {
  71. BlPositionCursor(LinePosition + sizeof(TERMINAL_PROMPT) - 1, ScreenHeight);
  72. ArcWrite(BlConsoleOutDeviceId, " ", (ULONG)strlen(" "), &Count);
  73. BlPositionCursor(LinePosition + sizeof(TERMINAL_PROMPT) - 1, ScreenHeight);
  74. LinePosition--;
  75. TerminalLine[LinePosition] = '\0';
  76. }
  77. return FALSE;
  78. }
  79. if (Key == TAB_KEY) {
  80. //
  81. // don't support this key
  82. //
  83. return FALSE;
  84. }
  85. if (Key == ENTER_KEY) {
  86. TerminalLine[LinePosition] = '\0';
  87. ArcWrite(BlConsoleOutDeviceId, "\r\n", (ULONG)strlen("\r\n"), &Count);
  88. if (LinePosition != 0) {
  89. Reboot = BlpDoCommand((PCHAR)TerminalLine);
  90. } else {
  91. Reboot = FALSE;
  92. }
  93. if (!Reboot) {
  94. BlPositionCursor(1, ScreenHeight);
  95. ArcWrite(BlConsoleOutDeviceId, "\r\n", (ULONG)strlen("\r\n"), &Count);
  96. ArcWrite(BlConsoleOutDeviceId, TERMINAL_PROMPT, (ULONG)strlen(TERMINAL_PROMPT), &Count);
  97. LinePosition = 0;
  98. }
  99. return Reboot;
  100. }
  101. //
  102. // Ignore all other non-ASCII keys
  103. //
  104. if (Key != (ULONG)(Key & 0x7F)) {
  105. return FALSE;
  106. }
  107. //
  108. // All other keys get recorded.
  109. //
  110. TerminalLine[LinePosition] = (UCHAR)Key;
  111. if (LinePosition < TERMINAL_LINE_LENGTH - 1) {
  112. LinePosition++;
  113. } else {
  114. BlPositionCursor(LinePosition + sizeof(TERMINAL_PROMPT) - 1, ScreenHeight);
  115. }
  116. //
  117. // Echo back to the console the character.
  118. //
  119. ArcWrite(BlConsoleOutDeviceId, &((UCHAR)Key), sizeof(UCHAR), &Count);
  120. }
  121. return FALSE;
  122. }
  123. BOOLEAN
  124. BlpDoCommand(
  125. IN PCHAR InputLine
  126. )
  127. /*++
  128. Routine Description:
  129. Process an input line.
  130. Arguments:
  131. InputLine - The command from the user.
  132. Return Value:
  133. TRUE - When the user wants a reboot, else FALSE.
  134. --*/
  135. {
  136. ULONG Count;
  137. if ((_stricmp(InputLine, "?") == 0) ||
  138. (_stricmp(InputLine, "help") == 0)) {
  139. ArcWrite(BlConsoleOutDeviceId,
  140. "? Display this message.\r\n",
  141. sizeof("? Display this message.\r\n"),
  142. &Count
  143. );
  144. ArcWrite(BlConsoleOutDeviceId,
  145. "restart Restart the system immediately.\r\n",
  146. sizeof("restart Restart the system immediately.\r\n"),
  147. &Count
  148. );
  149. return FALSE;
  150. }
  151. if (_stricmp(InputLine, "restart") == 0) {
  152. return TRUE;
  153. }
  154. ArcWrite(BlConsoleOutDeviceId,
  155. "Invalid Command, use '?' for help.\r\n",
  156. sizeof("Invalid Command, use '?' for help.\r\n"),
  157. &Count
  158. );
  159. return FALSE;
  160. }