kbdtest.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*+-----------------------------------------------------------------------
  2. kbdtest.c -- hack to test keyboard function key sequences
  3. wht@wht.net
  4. compile with cc -o kbdtest kbdtest.c
  5. or just cc kbdtest.c;a.out
  6. ------------------------------------------------------------------------*/
  7. /*+:EDITS:*/
  8. /*:04-26-2000-11:16-wht@bob-RELEASE 4.42 */
  9. /*:01-24-1997-02:37-wht@yuriatin-SOURCE RELEASE 4.00 */
  10. /*:09-11-1996-20:00-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
  11. /*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
  12. /*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
  13. /*:10-21-1995-12:54-wht@wwtp1-wild edit broke this HOW long ago? */
  14. /*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
  15. /*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  16. /*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  17. /*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
  18. /*:12-21-1990-23:47-wht@n4hgf-liven up for release with ECU 3 */
  19. /*:04-07-1990-01:36-wht@tridom-bring out of the daaaaark ages a bit */
  20. /*:04-18-1988-13:44-wht-first edits -- oollldd program */
  21. #include <stdio.h>
  22. #include <signal.h>
  23. #include <ctype.h>
  24. #include <fcntl.h>
  25. #include <termio.h>
  26. #include "ecu_types.h"
  27. #include <sys/errno.h>
  28. #include "ecu_stat.h"
  29. #include <string.h>
  30. #define TTYIN 0
  31. #define TTYOUT 1
  32. #define TTYERR 2
  33. struct termio tv0; /* for saving, changing TTY atributes */
  34. struct termio tv; /* for saving, changing TTY atributes */
  35. /*+-----------------------------------------------------------------------
  36. ttymode(arg) -- control user console (kbd/screen)
  37. Where arg ==
  38. 0 restore attributes saved at start of execution
  39. 1 raw mode
  40. ------------------------------------------------------------------------*/
  41. void
  42. ttymode(arg)
  43. int arg;
  44. {
  45. char *mode_type;
  46. switch (arg)
  47. {
  48. case 0:
  49. mode_type = "console to cooked mode\r\n";
  50. break;
  51. default:
  52. mode_type = "console to raw mode\r\n";
  53. break;
  54. }
  55. (void)fprintf(stderr, mode_type);
  56. if (arg)
  57. {
  58. (void)ioctl(TTYIN, TCGETA, &tv);
  59. tv.c_cflag &= ~(CS8 | PARENB | PARODD);
  60. tv.c_cflag |= CS8;
  61. tv.c_iflag &= ~(INLCR | ICRNL | IGNCR | IXOFF | IUCLC | ISTRIP);
  62. tv.c_oflag |= OPOST;
  63. tv.c_oflag &= ~(OLCUC | ONLCR | OCRNL | ONOCR | ONLRET);
  64. tv.c_lflag &= ~(ICANON | ISIG | ECHO);
  65. tv.c_cc[VEOF] = '\01';
  66. tv.c_cc[VEOL] = '\0';
  67. tv.c_cc[VMIN] = 1;
  68. tv.c_cc[VTIME] = 1;
  69. (void)ioctl(TTYIN, TCSETAW, &tv);
  70. }
  71. else
  72. (void)ioctl(TTYIN, TCSETAW, &tv0);
  73. }
  74. /*+-----------------------------------------------------------------------
  75. main()
  76. ------------------------------------------------------------------------*/
  77. main(argc, argv)
  78. int argc;
  79. char **argv;
  80. {
  81. unsigned char inchar;
  82. setbuf(stdout, NULL);
  83. setbuf(stderr, NULL);
  84. ioctl(TTYIN, TCGETA, &tv0); /* get original status */
  85. ttymode(2);
  86. fprintf(stderr, "press ^D (0x04) to terminate program\r\n");
  87. while (read(TTYIN, &inchar, 1) == 1)
  88. {
  89. printf("%02x %c\r\n", inchar,
  90. ((inchar >= 0x20) && (inchar < 0x7F)) ? inchar : '.');
  91. if ((inchar & 0x7F) == 4)
  92. {
  93. ttymode(0);
  94. exit(0);
  95. }
  96. }
  97. ttymode(0);
  98. exit(1);
  99. }
  100. /* vi: set tabstop=4 shiftwidth=4: */
  101. /* end of kbdtest.c */