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.

406 lines
10 KiB

  1. /*++
  2. Copyright (c) 1985 - 1999, Microsoft Corporation
  3. Module Name:
  4. cmdline.h
  5. Abstract:
  6. This file contains the internal structures and definitions used
  7. by command line input and editing.
  8. Author:
  9. Therese Stowell (thereses) 15-Nov-1991
  10. Revision History:
  11. --*/
  12. typedef struct _COMMAND {
  13. USHORT CommandLength;
  14. WCHAR Command[0];
  15. } COMMAND, *PCOMMAND;
  16. typedef
  17. NTSTATUS
  18. (*PCLE_POPUP_INPUT_ROUTINE)(
  19. IN PVOID CookedReadData,
  20. IN PCSR_API_MSG WaitReplyMessage,
  21. IN PCSR_THREAD WaitingThread,
  22. IN BOOLEAN WaitRoutine
  23. );
  24. /*
  25. * CLE_POPUP Flags
  26. */
  27. #define CLEPF_FALSE_UNICODE 0x0001
  28. typedef struct _CLE_POPUP {
  29. LIST_ENTRY ListLink; // pointer to next popup
  30. SMALL_RECT Region; // region popup occupies
  31. WORD Attributes; // text attributes
  32. WORD Flags; // CLEPF_ flags
  33. PCHAR_INFO OldContents; // contains data under popup
  34. SHORT BottomIndex; // number of command displayed on last line of popup
  35. SHORT CurrentCommand;
  36. WCHAR NumberBuffer[6];
  37. SHORT NumberRead;
  38. PCLE_POPUP_INPUT_ROUTINE PopupInputRoutine; // routine to call when input is received
  39. #if defined(FE_SB)
  40. COORD OldScreenSize;
  41. #endif
  42. } CLE_POPUP, *PCLE_POPUP;
  43. #define POPUP_SIZE_X(POPUP) (SHORT)(((POPUP)->Region.Right - (POPUP)->Region.Left - 1))
  44. #define POPUP_SIZE_Y(POPUP) (SHORT)(((POPUP)->Region.Bottom - (POPUP)->Region.Top - 1))
  45. #define COMMAND_NUMBER_SIZE 8 // size of command number buffer
  46. /*
  47. * COMMAND_HISTORY Flags
  48. */
  49. #define CLE_ALLOCATED 0x00000001
  50. #define CLE_RESET 0x00000002
  51. typedef struct _COMMAND_HISTORY {
  52. DWORD Flags;
  53. LIST_ENTRY ListLink;
  54. PWCHAR AppName;
  55. SHORT NumberOfCommands;
  56. SHORT LastAdded;
  57. SHORT LastDisplayed;
  58. SHORT FirstCommand; // circular buffer
  59. SHORT MaximumNumberOfCommands;
  60. HANDLE ProcessHandle;
  61. LIST_ENTRY PopupList; // pointer to top-level popup
  62. PCOMMAND Commands[0];
  63. } COMMAND_HISTORY, *PCOMMAND_HISTORY;
  64. #define DEFAULT_NUMBER_OF_COMMANDS 25
  65. #define DEFAULT_NUMBER_OF_BUFFERS 4
  66. typedef struct _COOKED_READ_DATA {
  67. PINPUT_INFORMATION InputInfo;
  68. PSCREEN_INFORMATION ScreenInfo;
  69. PCONSOLE_INFORMATION Console;
  70. HANDLE_DATA TempHandle;
  71. ULONG UserBufferSize; // doubled size in ansi case
  72. PWCHAR UserBuffer;
  73. ULONG BufferSize;
  74. ULONG BytesRead;
  75. ULONG CurrentPosition; // char position, not byte position
  76. PWCHAR BufPtr;
  77. PWCHAR BackupLimit;
  78. COORD OriginalCursorPosition;
  79. DWORD NumberOfVisibleChars;
  80. PCOMMAND_HISTORY CommandHistory;
  81. BOOLEAN Echo;
  82. BOOLEAN Processed;
  83. BOOLEAN Line;
  84. BOOLEAN InsertMode;
  85. PCONSOLE_PER_PROCESS_DATA ProcessData;
  86. HANDLE HandleIndex;
  87. PWCHAR ExeName;
  88. USHORT ExeNameLength; // in bytes
  89. ULONG CtrlWakeupMask;
  90. ULONG ControlKeyState;
  91. } COOKED_READ_DATA, *PCOOKED_READ_DATA;
  92. #define COMMAND_NUM_TO_INDEX(NUM,CMDHIST) (SHORT)(((NUM+(CMDHIST)->FirstCommand)%((CMDHIST)->MaximumNumberOfCommands)))
  93. #define COMMAND_INDEX_TO_NUM(INDEX,CMDHIST) (SHORT)(((INDEX+((CMDHIST)->MaximumNumberOfCommands)-(CMDHIST)->FirstCommand)%((CMDHIST)->MaximumNumberOfCommands)))
  94. /*
  95. * COMMAND_IND_NEXT and COMMAND_IND_PREV go to the next and prev command
  96. * COMMAND_IND_INC and COMMAND_IND_DEC go to the next and prev slots
  97. *
  98. * Don't get the two confused - it matters when the cmd history is not full!
  99. */
  100. #define COMMAND_IND_PREV(IND,CMDHIST) \
  101. { \
  102. if (IND <= 0) { \
  103. IND = (CMDHIST)->NumberOfCommands; \
  104. } \
  105. IND--; \
  106. }
  107. #define COMMAND_IND_NEXT(IND,CMDHIST) \
  108. { \
  109. ++IND; \
  110. if (IND >= (CMDHIST)->NumberOfCommands) { \
  111. IND = 0; \
  112. } \
  113. }
  114. #define COMMAND_IND_DEC(IND,CMDHIST) \
  115. { \
  116. if (IND <= 0) { \
  117. IND = (CMDHIST)->MaximumNumberOfCommands; \
  118. } \
  119. IND--; \
  120. }
  121. #define COMMAND_IND_INC(IND,CMDHIST) \
  122. { \
  123. ++IND; \
  124. if (IND >= (CMDHIST)->MaximumNumberOfCommands) { \
  125. IND = 0; \
  126. } \
  127. }
  128. #define CLE_NO_POPUPS(COMMAND_HISTORY) (&(COMMAND_HISTORY)->PopupList == (COMMAND_HISTORY)->PopupList.Blink)
  129. //
  130. // aliases are grouped per console, per exe.
  131. //
  132. typedef struct _ALIAS {
  133. LIST_ENTRY ListLink;
  134. USHORT SourceLength; // in bytes
  135. USHORT TargetLength; // in bytes
  136. PWCHAR Source;
  137. PWCHAR Target;
  138. } ALIAS, *PALIAS;
  139. typedef struct _EXE_ALIAS_LIST {
  140. LIST_ENTRY ListLink;
  141. USHORT ExeLength; // in bytes
  142. PWCHAR ExeName;
  143. LIST_ENTRY AliasList;
  144. } EXE_ALIAS_LIST, *PEXE_ALIAS_LIST;
  145. NTSTATUS
  146. ProcessCommandLine(
  147. IN PCOOKED_READ_DATA CookedReadData,
  148. IN WCHAR Char,
  149. IN DWORD KeyState,
  150. IN PCSR_API_MSG WaitReplyMessage,
  151. IN PCSR_THREAD WaitingThread,
  152. IN BOOLEAN WaitRoutine
  153. );
  154. VOID
  155. DeleteCommandLine(
  156. IN OUT PCOOKED_READ_DATA CookedReadData,
  157. IN BOOL UpdateFields
  158. );
  159. VOID
  160. RedrawCommandLine(
  161. IN PCOOKED_READ_DATA CookedReadData
  162. );
  163. VOID
  164. EmptyCommandHistory(
  165. IN PCOMMAND_HISTORY CommandHistory
  166. );
  167. PCOMMAND_HISTORY
  168. ReallocCommandHistory(
  169. IN PCONSOLE_INFORMATION Console,
  170. IN PCOMMAND_HISTORY CurrentCommandHistory,
  171. IN DWORD NumCommands
  172. );
  173. PCOMMAND_HISTORY
  174. FindExeCommandHistory(
  175. IN PCONSOLE_INFORMATION Console,
  176. IN PVOID AppName,
  177. IN DWORD AppNameLength,
  178. IN BOOLEAN UnicodeExe
  179. );
  180. PCOMMAND_HISTORY
  181. FindCommandHistory(
  182. IN PCONSOLE_INFORMATION Console,
  183. IN HANDLE ProcessHandle
  184. );
  185. ULONG
  186. RetrieveNumberOfSpaces(
  187. IN SHORT OriginalCursorPositionX,
  188. IN PWCHAR Buffer,
  189. IN ULONG CurrentPosition
  190. #if defined(FE_SB)
  191. ,
  192. IN PCONSOLE_INFORMATION Console,
  193. IN DWORD CodePage
  194. #endif
  195. );
  196. ULONG
  197. RetrieveTotalNumberOfSpaces(
  198. IN SHORT OriginalCursorPositionX,
  199. IN PWCHAR Buffer,
  200. IN ULONG CurrentPosition
  201. #if defined(FE_SB)
  202. ,
  203. IN PCONSOLE_INFORMATION Console
  204. #endif
  205. );
  206. NTSTATUS
  207. GetChar(
  208. IN PINPUT_INFORMATION InputInfo,
  209. OUT PWCHAR Char,
  210. IN BOOLEAN Wait,
  211. IN PCONSOLE_INFORMATION Console,
  212. IN PHANDLE_DATA HandleData,
  213. IN PCSR_API_MSG Message OPTIONAL,
  214. IN CSR_WAIT_ROUTINE WaitRoutine OPTIONAL,
  215. IN PVOID WaitParameter OPTIONAL,
  216. IN ULONG WaitParameterLength OPTIONAL,
  217. IN BOOLEAN WaitBlockExists OPTIONAL,
  218. OUT PBOOLEAN CommandLineEditingKeys OPTIONAL,
  219. OUT PBOOLEAN CommandLinePopupKeys OPTIONAL,
  220. OUT PBOOLEAN EnableScrollMode OPTIONAL,
  221. OUT PDWORD KeyState OPTIONAL
  222. );
  223. BOOL
  224. IsCommandLinePopupKey(
  225. IN OUT PKEY_EVENT_RECORD KeyEvent
  226. );
  227. BOOL
  228. IsCommandLineEditingKey(
  229. IN OUT PKEY_EVENT_RECORD KeyEvent
  230. );
  231. VOID
  232. CleanUpPopups(
  233. IN PCOOKED_READ_DATA CookedReadData
  234. );
  235. BOOL
  236. ProcessCookedReadInput(
  237. IN PCOOKED_READ_DATA CookedReadData,
  238. IN WCHAR Char,
  239. IN DWORD KeyState,
  240. OUT PNTSTATUS Status
  241. );
  242. VOID
  243. DrawCommandListBorder(
  244. IN PCLE_POPUP Popup,
  245. IN PSCREEN_INFORMATION ScreenInfo
  246. );
  247. PCOMMAND
  248. GetLastCommand(
  249. IN PCOMMAND_HISTORY CommandHistory
  250. );
  251. SHORT
  252. FindMatchingCommand(
  253. IN PCOMMAND_HISTORY CommandHistory,
  254. IN PWCHAR CurrentCommand,
  255. IN ULONG CurrentCommandLength,
  256. IN SHORT CurrentIndex,
  257. IN DWORD Flags
  258. );
  259. #define FMCFL_EXACT_MATCH 1
  260. #define FMCFL_JUST_LOOKING 2
  261. NTSTATUS
  262. CommandNumberPopup(
  263. IN PCOOKED_READ_DATA CookedReadData,
  264. IN PCSR_API_MSG WaitReplyMessage,
  265. IN PCSR_THREAD WaitingThread,
  266. IN BOOLEAN WaitRoutine
  267. );
  268. BOOLEAN
  269. CookedReadWaitRoutine(
  270. IN PLIST_ENTRY WaitQueue,
  271. IN PCSR_THREAD WaitingThread,
  272. IN PCSR_API_MSG WaitReplyMessage,
  273. IN PVOID WaitParameter,
  274. IN PVOID SatisfyParameter1,
  275. IN PVOID SatisfyParameter2,
  276. IN ULONG WaitFlags
  277. );
  278. VOID
  279. ReadRectFromScreenBuffer(
  280. IN PSCREEN_INFORMATION ScreenInfo,
  281. IN COORD SourcePoint,
  282. IN PCHAR_INFO Target,
  283. IN COORD TargetSize,
  284. IN PSMALL_RECT TargetRect
  285. );
  286. NTSTATUS
  287. WriteCharsFromInput(
  288. IN PSCREEN_INFORMATION ScreenInfo,
  289. IN PWCHAR lpBufferBackupLimit,
  290. IN PWCHAR lpBuffer,
  291. IN PWCHAR lpString,
  292. IN OUT PDWORD NumBytes,
  293. OUT PLONG NumSpaces OPTIONAL,
  294. IN SHORT OriginalXPosition,
  295. IN DWORD dwFlags,
  296. OUT PSHORT ScrollY OPTIONAL
  297. );
  298. //
  299. // Values for WriteChars(),WriteCharsFromInput() dwFlags
  300. //
  301. #define WC_DESTRUCTIVE_BACKSPACE 0x01
  302. #define WC_KEEP_CURSOR_VISIBLE 0x02
  303. #define WC_ECHO 0x04
  304. #define WC_FALSIFY_UNICODE 0x08
  305. #define WC_LIMIT_BACKSPACE 0x10
  306. VOID
  307. DrawCommandListPopup(
  308. IN PCLE_POPUP Popup,
  309. IN SHORT CurrentCommand,
  310. IN PCOMMAND_HISTORY CommandHistory,
  311. IN PSCREEN_INFORMATION ScreenInfo
  312. );
  313. VOID
  314. UpdateCommandListPopup(
  315. IN SHORT Delta,
  316. IN OUT PSHORT CurrentCommand,
  317. IN PCOMMAND_HISTORY CommandHistory,
  318. IN PCLE_POPUP Popup,
  319. IN PSCREEN_INFORMATION ScreenInfo,
  320. IN DWORD Flags
  321. );
  322. #define UCLP_WRAP 1
  323. //
  324. // InitExtendedEditKey
  325. // If lpwstr is NULL, the default value will be used.
  326. //
  327. VOID InitExtendedEditKeys(CONST ExtKeyDefBuf* lpbuf);
  328. //
  329. // IsPauseKey
  330. // returns TRUE if pKeyEvent is pause.
  331. // The default key is Ctrl-S if extended edit keys are not specified.
  332. //
  333. BOOL IsPauseKey(IN PKEY_EVENT_RECORD pKeyEvent);
  334. //
  335. // Word delimiters
  336. //
  337. #define IS_WORD_DELIM(wch) ((wch) == L' ' || (gaWordDelimChars[0] && IsWordDelim(wch)))
  338. extern WCHAR gaWordDelimChars[];
  339. extern CONST WCHAR gaWordDelimCharsDefault[];
  340. extern BOOL IsWordDelim(WCHAR);
  341. #define WORD_DELIM_MAX 32