Source code of Windows XP (NT5)
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.

222 lines
4.8 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 PUCHAR 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", sizeof("\r\n"), &Count);
  52. ArcWrite(BlConsoleOutDeviceId, TERMINAL_PROMPT, sizeof(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, "\\", sizeof("\\"), &Count);
  64. BlPositionCursor(1, ScreenHeight);
  65. ArcWrite(BlConsoleOutDeviceId, "\r\n", sizeof("\r\n"), &Count);
  66. ArcWrite(BlConsoleOutDeviceId, TERMINAL_PROMPT, sizeof(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, " ", sizeof(" "), &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. ArcWrite(BlConsoleOutDeviceId, "\007", sizeof("\007"), &Count);
  81. return FALSE;
  82. }
  83. if (Key == ENTER_KEY) {
  84. TerminalLine[LinePosition] = '\0';
  85. ArcWrite(BlConsoleOutDeviceId, "\r\n", sizeof("\r\n"), &Count);
  86. if (LinePosition != 0) {
  87. Reboot = BlpDoCommand(TerminalLine);
  88. } else {
  89. Reboot = FALSE;
  90. }
  91. if (!Reboot) {
  92. BlPositionCursor(1, ScreenHeight);
  93. ArcWrite(BlConsoleOutDeviceId, "\r\n", sizeof("\r\n"), &Count);
  94. ArcWrite(BlConsoleOutDeviceId, TERMINAL_PROMPT, sizeof(TERMINAL_PROMPT), &Count);
  95. LinePosition = 0;
  96. }
  97. return Reboot;
  98. }
  99. //
  100. // Ignore all other non-ASCII keys
  101. //
  102. if (Key != (ULONG)(Key & 0x7F)) {
  103. return FALSE;
  104. }
  105. //
  106. // All other keys get recorded.
  107. //
  108. TerminalLine[LinePosition] = (UCHAR)Key;
  109. if (LinePosition < TERMINAL_LINE_LENGTH - 1) {
  110. LinePosition++;
  111. } else {
  112. BlPositionCursor(LinePosition + sizeof(TERMINAL_PROMPT) - 1, ScreenHeight);
  113. }
  114. //
  115. // Echo back to the console the character.
  116. //
  117. ArcWrite(BlConsoleOutDeviceId, &((UCHAR)Key), sizeof(UCHAR), &Count);
  118. }
  119. return FALSE;
  120. }
  121. BOOLEAN
  122. BlpDoCommand(
  123. IN PUCHAR InputLine
  124. )
  125. /*++
  126. Routine Description:
  127. Process an input line.
  128. Arguments:
  129. InputLine - The command from the user.
  130. Return Value:
  131. TRUE - When the user wants a reboot, else FALSE.
  132. --*/
  133. {
  134. ULONG Count;
  135. if ((_stricmp(InputLine, "?") == 0) ||
  136. (_stricmp(InputLine, "help") == 0)) {
  137. ArcWrite(BlConsoleOutDeviceId,
  138. "? Display this message.\r\n",
  139. sizeof("? Display this message.\r\n"),
  140. &Count
  141. );
  142. ArcWrite(BlConsoleOutDeviceId,
  143. "restart Restart the system immediately.\r\n",
  144. sizeof("restart Restart the system immediately.\r\n"),
  145. &Count
  146. );
  147. return FALSE;
  148. }
  149. if (_stricmp(InputLine, "restart") == 0) {
  150. return TRUE;
  151. }
  152. ArcWrite(BlConsoleOutDeviceId,
  153. "Invalid Command, use '?' for help.\r\n",
  154. sizeof("Invalid Command, use '?' for help.\r\n"),
  155. &Count
  156. );
  157. return FALSE;
  158. }