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.

86 lines
1.9 KiB

  1. #define WIN32_ONLY
  2. #include <posix/sys/types.h>
  3. #include <posix/termios.h>
  4. #include "psxses.h"
  5. #include <io.h>
  6. #include <stdio.h>
  7. #include <memory.h>
  8. #include <string.h>
  9. DWORD InputModeFlags;
  10. DWORD OutputModeFlags; /* Console Output Mode */
  11. unsigned char AnsiNewMode;
  12. struct termios SavedTermios;
  13. BOOL
  14. ServeTcRequest(
  15. PSCTCREQUEST PReq,
  16. PVOID PStatus
  17. )
  18. {
  19. DWORD Rc = 0;
  20. // BUGBUG! error code and returned Status are wrong
  21. switch ( PReq->Request ) {
  22. case TcGetAttr:
  23. memcpy(&PReq->Termios, &SavedTermios, sizeof(struct termios));
  24. break;
  25. case TcSetAttr:
  26. // Don't play this game if the tricky input stuff hasn't been
  27. // enabled.
  28. if (!DoTrickyIO)
  29. return 0;
  30. AnsiNewMode = TRUE;
  31. memcpy(&SavedTermios, &PReq->Termios, sizeof(struct termios));
  32. InputModeFlags = 0;
  33. if (PReq->Termios.c_lflag & ICANON) {
  34. InputModeFlags |= ENABLE_LINE_INPUT;
  35. } else {
  36. InputModeFlags &= ~ENABLE_LINE_INPUT;
  37. }
  38. if (PReq->Termios.c_lflag & ECHO) {
  39. // If you want ECHO_INPUT, you need LINE_INPUT, too.
  40. InputModeFlags |= (ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
  41. } else {
  42. InputModeFlags &= ~ENABLE_ECHO_INPUT;
  43. }
  44. if (PReq->Termios.c_lflag & ISIG)
  45. InputModeFlags |= ENABLE_PROCESSED_INPUT;
  46. else
  47. InputModeFlags &= ~ENABLE_PROCESSED_INPUT;
  48. if (!SetConsoleMode(hConsoleInput, InputModeFlags)) {
  49. KdPrint(("PSXSES: SetConsoleMode: %d\n", GetLastError()));
  50. *(PDWORD)PStatus = (DWORD)-1L;
  51. return 1;
  52. }
  53. break;
  54. default:
  55. *(PDWORD)PStatus = (DWORD)-1L; //STATUS_INVALID_PARAMETER;
  56. Rc = 1;
  57. break;
  58. }
  59. #if 1
  60. *(PDWORD) PStatus = (Rc) ? GetLastError() : 0;
  61. #else
  62. if ( !Rc ) {
  63. *(PDWORD) PStatus = 0;
  64. } else {
  65. *(PDWORD) PStatus = GetLastError();
  66. }
  67. #endif
  68. return(TRUE);
  69. }