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.

386 lines
11 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. vtutf8scraper.h
  5. Abstract:
  6. Define VT-UTF8 compatible screen scraper.
  7. Author:
  8. Brian Guarraci (briangu), 2001
  9. Revision History:
  10. (remotely based on scraper.cpp from telnet code)
  11. --*/
  12. #ifndef __VTUTF8_SCRAPER__H__
  13. #define __VTUTF8_SCRAPER__H__
  14. #include <iohandler.h>
  15. #include <scraper.h>
  16. #define VT_ESC 0x1B
  17. #define CTRLC 0x03
  18. #define CTRLA 0x01
  19. #define CTRLQ 0x11
  20. #define CTRLS 0x13
  21. #define CTRLU 0x15
  22. #define ESC '\033'
  23. #define VS_ESCAPE 1
  24. #define VS_O 24
  25. #define VS_LEFT_BRACKET 26
  26. #define VS_CONTROL 29
  27. #define VS_SHIFT 54
  28. #define VS_MENU 56
  29. #define VS_F1 59
  30. #define VS_F2 60
  31. #define VS_F3 61
  32. #define VS_F4 62
  33. #define VS_F5 63
  34. #define VS_F6 64
  35. #define VS_F7 65
  36. #define VS_F8 66
  37. #define VS_F9 67
  38. #define VS_F10 68
  39. #define VS_PAUSE 70
  40. #define VS_HOME 71
  41. #define VS_UP 72
  42. #define VS_PRIOR 73
  43. #define VS_LEFT 75
  44. #define VS_RIGHT 77
  45. #define VS_END 79
  46. #define VS_DOWN 80
  47. #define VS_NEXT 81
  48. #define VS_INSERT 82
  49. #define VS_DELETE 83
  50. #define VS_F11 87
  51. #define VS_F12 88
  52. //
  53. // Length & size of buffer used to read from the channel
  54. //
  55. #define READ_BUFFER_LENGTH 2048
  56. #define READ_BUFFER_SIZE (READ_BUFFER_LENGTH*sizeof(WCHAR))
  57. //
  58. // Define the Process Enhanced Key parser states
  59. //
  60. enum {
  61. IP_INIT,
  62. IP_ESC_RCVD,
  63. IP_ESC_BRACKET_RCVD,
  64. IP_ESC_CTRL_A_RCVD,
  65. IP_ESC_CTRL_A_ESC_RCVD,
  66. IP_ESC_CTRL_C_RCVD,
  67. IP_ESC_CTRL_S_RCVD
  68. };
  69. class CVTUTF8Scraper : public CScraper {
  70. protected:
  71. CONSOLE_SCREEN_BUFFER_INFO CSBI;
  72. CONSOLE_SCREEN_BUFFER_INFO LastCSBI;
  73. PCHAR_INFO pLastSeen;
  74. PCHAR_INFO pCurrent;
  75. DWORD m_dwInputSequenceState;
  76. DWORD m_dwDigitInTheSeq;
  77. PWCHAR m_readBuffer;
  78. inline BOOL
  79. CursorEOL(
  80. VOID
  81. )
  82. {
  83. return SendString(L"\033[K");
  84. }
  85. LPWSTR
  86. CursorMove(
  87. OUT LPWSTR lpszCmsResult,
  88. IN WORD wHorPos,
  89. IN WORD wVertPos
  90. );
  91. inline PWCHAR
  92. FastIToA_10(
  93. IN ULONG x,
  94. IN PWCHAR Buffer
  95. )
  96. /*++
  97. Routine Description:
  98. This is equivalent to _itoa( x, Buffer, 10 );
  99. where 0 <= x <= 99
  100. Arguments:
  101. x - the integer to translate
  102. Buffer - the destination buffer
  103. Return Value:
  104. The address of the buffer immediately after the last character
  105. produce as a result of this ItoA operation
  106. --*/
  107. {
  108. PWCHAR AfterP;
  109. AfterP = Buffer + 2;
  110. switch (x) {
  111. case 0: Buffer[0] = L'0'; AfterP = Buffer + 1; break;
  112. case 1: Buffer[0] = L'1'; AfterP = Buffer + 1; break;
  113. case 2: Buffer[0] = L'2'; AfterP = Buffer + 1; break;
  114. case 3: Buffer[0] = L'3'; AfterP = Buffer + 1; break;
  115. case 4: Buffer[0] = L'4'; AfterP = Buffer + 1; break;
  116. case 5: Buffer[0] = L'5'; AfterP = Buffer + 1; break;
  117. case 6: Buffer[0] = L'6'; AfterP = Buffer + 1; break;
  118. case 7: Buffer[0] = L'7'; AfterP = Buffer + 1; break;
  119. case 8: Buffer[0] = L'8'; AfterP = Buffer + 1; break;
  120. case 9: Buffer[0] = L'9'; AfterP = Buffer + 1; break;
  121. case 10: Buffer[1] = L'0'; Buffer[0] = L'1'; break;
  122. case 11: Buffer[1] = L'1'; Buffer[0] = L'1'; break;
  123. case 12: Buffer[1] = L'2'; Buffer[0] = L'1'; break;
  124. case 13: Buffer[1] = L'3'; Buffer[0] = L'1'; break;
  125. case 14: Buffer[1] = L'4'; Buffer[0] = L'1'; break;
  126. case 15: Buffer[1] = L'5'; Buffer[0] = L'1'; break;
  127. case 16: Buffer[1] = L'6'; Buffer[0] = L'1'; break;
  128. case 17: Buffer[1] = L'7'; Buffer[0] = L'1'; break;
  129. case 18: Buffer[1] = L'8'; Buffer[0] = L'1'; break;
  130. case 19: Buffer[1] = L'9'; Buffer[0] = L'1'; break;
  131. case 20: Buffer[1] = L'0'; Buffer[0] = L'2'; break;
  132. case 21: Buffer[1] = L'1'; Buffer[0] = L'2'; break;
  133. case 22: Buffer[1] = L'2'; Buffer[0] = L'2'; break;
  134. case 23: Buffer[1] = L'3'; Buffer[0] = L'2'; break;
  135. case 24: Buffer[1] = L'4'; Buffer[0] = L'2'; break;
  136. case 25: Buffer[1] = L'5'; Buffer[0] = L'2'; break;
  137. case 26: Buffer[1] = L'6'; Buffer[0] = L'2'; break;
  138. case 27: Buffer[1] = L'7'; Buffer[0] = L'2'; break;
  139. case 28: Buffer[1] = L'8'; Buffer[0] = L'2'; break;
  140. case 29: Buffer[1] = L'9'; Buffer[0] = L'2'; break;
  141. case 30: Buffer[1] = L'0'; Buffer[0] = L'3'; break;
  142. case 31: Buffer[1] = L'1'; Buffer[0] = L'3'; break;
  143. case 32: Buffer[1] = L'2'; Buffer[0] = L'3'; break;
  144. case 33: Buffer[1] = L'3'; Buffer[0] = L'3'; break;
  145. case 34: Buffer[1] = L'4'; Buffer[0] = L'3'; break;
  146. case 35: Buffer[1] = L'5'; Buffer[0] = L'3'; break;
  147. case 36: Buffer[1] = L'6'; Buffer[0] = L'3'; break;
  148. case 37: Buffer[1] = L'7'; Buffer[0] = L'3'; break;
  149. case 38: Buffer[1] = L'8'; Buffer[0] = L'3'; break;
  150. case 39: Buffer[1] = L'9'; Buffer[0] = L'3'; break;
  151. case 40: Buffer[1] = L'0'; Buffer[0] = L'4'; break;
  152. case 41: Buffer[1] = L'1'; Buffer[0] = L'4'; break;
  153. case 42: Buffer[1] = L'2'; Buffer[0] = L'4'; break;
  154. case 43: Buffer[1] = L'3'; Buffer[0] = L'4'; break;
  155. case 44: Buffer[1] = L'4'; Buffer[0] = L'4'; break;
  156. case 45: Buffer[1] = L'5'; Buffer[0] = L'4'; break;
  157. case 46: Buffer[1] = L'6'; Buffer[0] = L'4'; break;
  158. case 47: Buffer[1] = L'7'; Buffer[0] = L'4'; break;
  159. case 48: Buffer[1] = L'8'; Buffer[0] = L'4'; break;
  160. case 49: Buffer[1] = L'9'; Buffer[0] = L'4'; break;
  161. case 50: Buffer[1] = L'0'; Buffer[0] = L'5'; break;
  162. case 51: Buffer[1] = L'1'; Buffer[0] = L'5'; break;
  163. case 52: Buffer[1] = L'2'; Buffer[0] = L'5'; break;
  164. case 53: Buffer[1] = L'3'; Buffer[0] = L'5'; break;
  165. case 54: Buffer[1] = L'4'; Buffer[0] = L'5'; break;
  166. case 55: Buffer[1] = L'5'; Buffer[0] = L'5'; break;
  167. case 56: Buffer[1] = L'6'; Buffer[0] = L'5'; break;
  168. case 57: Buffer[1] = L'7'; Buffer[0] = L'5'; break;
  169. case 58: Buffer[1] = L'8'; Buffer[0] = L'5'; break;
  170. case 59: Buffer[1] = L'9'; Buffer[0] = L'5'; break;
  171. case 60: Buffer[1] = L'0'; Buffer[0] = L'6'; break;
  172. case 61: Buffer[1] = L'1'; Buffer[0] = L'6'; break;
  173. case 62: Buffer[1] = L'2'; Buffer[0] = L'6'; break;
  174. case 63: Buffer[1] = L'3'; Buffer[0] = L'6'; break;
  175. case 64: Buffer[1] = L'4'; Buffer[0] = L'6'; break;
  176. case 65: Buffer[1] = L'5'; Buffer[0] = L'6'; break;
  177. case 66: Buffer[1] = L'6'; Buffer[0] = L'6'; break;
  178. case 67: Buffer[1] = L'7'; Buffer[0] = L'6'; break;
  179. case 68: Buffer[1] = L'8'; Buffer[0] = L'6'; break;
  180. case 69: Buffer[1] = L'9'; Buffer[0] = L'6'; break;
  181. case 70: Buffer[1] = L'0'; Buffer[0] = L'7'; break;
  182. case 71: Buffer[1] = L'1'; Buffer[0] = L'7'; break;
  183. case 72: Buffer[1] = L'2'; Buffer[0] = L'7'; break;
  184. case 73: Buffer[1] = L'3'; Buffer[0] = L'7'; break;
  185. case 74: Buffer[1] = L'4'; Buffer[0] = L'7'; break;
  186. case 75: Buffer[1] = L'5'; Buffer[0] = L'7'; break;
  187. case 76: Buffer[1] = L'6'; Buffer[0] = L'7'; break;
  188. case 77: Buffer[1] = L'7'; Buffer[0] = L'7'; break;
  189. case 78: Buffer[1] = L'8'; Buffer[0] = L'7'; break;
  190. case 79: Buffer[1] = L'9'; Buffer[0] = L'7'; break;
  191. case 80: Buffer[1] = L'0'; Buffer[0] = L'8'; break;
  192. case 81: Buffer[1] = L'1'; Buffer[0] = L'8'; break;
  193. case 82: Buffer[1] = L'2'; Buffer[0] = L'8'; break;
  194. case 83: Buffer[1] = L'3'; Buffer[0] = L'8'; break;
  195. case 84: Buffer[1] = L'4'; Buffer[0] = L'8'; break;
  196. case 85: Buffer[1] = L'5'; Buffer[0] = L'8'; break;
  197. case 86: Buffer[1] = L'6'; Buffer[0] = L'8'; break;
  198. case 87: Buffer[1] = L'7'; Buffer[0] = L'8'; break;
  199. case 88: Buffer[1] = L'8'; Buffer[0] = L'8'; break;
  200. case 89: Buffer[1] = L'9'; Buffer[0] = L'8'; break;
  201. case 90: Buffer[1] = L'0'; Buffer[0] = L'9'; break;
  202. case 91: Buffer[1] = L'1'; Buffer[0] = L'9'; break;
  203. case 92: Buffer[1] = L'2'; Buffer[0] = L'9'; break;
  204. case 93: Buffer[1] = L'3'; Buffer[0] = L'9'; break;
  205. case 94: Buffer[1] = L'4'; Buffer[0] = L'9'; break;
  206. case 95: Buffer[1] = L'5'; Buffer[0] = L'9'; break;
  207. case 96: Buffer[1] = L'6'; Buffer[0] = L'9'; break;
  208. case 97: Buffer[1] = L'7'; Buffer[0] = L'9'; break;
  209. case 98: Buffer[1] = L'8'; Buffer[0] = L'9'; break;
  210. case 99: Buffer[1] = L'9'; Buffer[0] = L'9'; break;
  211. default:
  212. ASSERT(0);
  213. //
  214. // put the cursor at some safe location
  215. //
  216. Buffer[0] = L'0';
  217. Buffer[1] = L'0';
  218. break;
  219. }
  220. return AfterP;
  221. }
  222. BOOL InitScraper( VOID );
  223. void ResetLastScreen(VOID);
  224. BOOL CreateIOHandles(VOID);
  225. BOOL CreateConsoleOutHandle(VOID);
  226. BOOL CreateConsoleInHandle(VOID);
  227. BOOL
  228. CreateIOHandle(
  229. IN PWCHAR HandleName,
  230. OUT PHANDLE pHandle
  231. );
  232. inline BOOL
  233. SendChar(
  234. IN WCHAR ch
  235. )
  236. {
  237. return SendBytes( ( PUCHAR )&ch, sizeof(WCHAR) );
  238. }
  239. BOOL
  240. SendString(
  241. PWCHAR
  242. );
  243. BOOL
  244. SendBytes(
  245. PUCHAR,
  246. DWORD
  247. );
  248. BOOL
  249. SendColorInfo(
  250. WORD
  251. );
  252. BOOL
  253. SetWindowInfo(
  254. VOID
  255. );
  256. BOOL
  257. SetScreenBufferInfo(
  258. VOID
  259. );
  260. BOOL
  261. ProcessEnhancedKeys(
  262. IN WCHAR
  263. );
  264. BOOL
  265. IsValidControlSequence(
  266. VOID
  267. );
  268. DWORD
  269. WriteAKeyToCMD(
  270. WCHAR
  271. );
  272. DWORD
  273. WriteAKeyToCMD(
  274. WORD,
  275. WORD,
  276. WCHAR,
  277. DWORD
  278. );
  279. DWORD
  280. WriteAKeyToCMD(
  281. BOOL bKeyDown,
  282. WORD wVKCode,
  283. WORD wVSCode,
  284. WCHAR Char,
  285. DWORD dwCKState
  286. );
  287. BOOL
  288. CompareAndUpdate(
  289. WORD,
  290. WORD,
  291. PCHAR_INFO,
  292. PCHAR_INFO,
  293. PCONSOLE_SCREEN_BUFFER_INFO,
  294. PCONSOLE_SCREEN_BUFFER_INFO
  295. );
  296. private:
  297. //
  298. // Don't let this construct be called directly
  299. //
  300. CVTUTF8Scraper();
  301. public:
  302. BOOL Start( VOID );
  303. BOOL Write( VOID );
  304. BOOL Read( VOID );
  305. BOOL DisplayFullScreen(VOID);
  306. CVTUTF8Scraper(
  307. CIoHandler *IoHandler,
  308. WORD wCols,
  309. WORD wRows
  310. );
  311. virtual ~CVTUTF8Scraper();
  312. };
  313. #endif __VTUTF8_SCRAPER__H__