1 /*---------------------------------------------------------------------
2 * Borrowed from chin.c v1.1, written by Davor Slamnig, 6/94 *
3 * Modified by Michael Harvey 8/94 *
5 * Single character keyboard input on UNIX in three modes: *
7 * wait - getchar() blocks until a character is read. *
8 * nowait - getchar() returns immediately, -1 is returned *
9 * if there are no characters in queue. *
10 * timeout - getchar() blocks until a character is read, *
11 * or a specified time limit is exceeded. *
13 * vidsetup(1, 0); /* wait * / *
14 * vidsetup(0, 0); /* nowait * / *
15 * vidsetup(0, V_TIMEOUT); /* timeout * / *
17 * vidsave(); /* save terminal * / *
18 * vidreset(); /* restore normal settings * / *
20 * kb_init(); /* init kb mode * / *
21 * kb_done(); /* reset kb mode * / *
22 * kb_shell(); /* shell mode * / *
24 * kb_wait(); /* wait mode * / *
25 * kb_nowait(); /* nowait mode * / *
26 * kb_timeout(); /* timeout mode * / *
29 ---------------------------------------------------------------------*/
35 #define V_TIMEOUT 10 /* 1 second */
37 struct termio Savevid
;
39 void vid_save(vmin
, vtime
)
41 if(ioctl(0, TCGETA
, &Savevid
) == -1)
43 perror("vidsave failed");
48 void vid_setup(vmin
, vtime
)
51 static struct termio newvid
; /* must be static or global */
53 if(ioctl(0, TCGETA
, &newvid
) == -1)
55 perror("TCGETA failed");
59 newvid
.c_lflag
= (newvid
.c_lflag
& ~ICANON
& ~ECHO
);
60 newvid
.c_cc
[VMIN
] = vmin
;
61 newvid
.c_cc
[VTIME
] = vtime
;
63 if(ioctl(0, TCSETA
, &newvid
) == -1)
65 perror("vidsetup failed");
72 if(ioctl(0, TCSETA
, &Savevid
) == -1)
74 perror("vidreset failed");
81 /* wait mode - getchar() blocks until a character is read. */
88 /* nowait mode - getchar() returns immediately, -1 is returned. */
89 /* if there are no characters in queue. */
96 /* timeout mode - getchar() blocks until a character is read, */
97 /* or a specified time limit is exceeded. */
99 vid_setup(0, V_TIMEOUT
);
102 void kb_init() { vid_save(0,0); }
103 void kb_done() { vid_reset(); }
104 void kb_shell() { vid_reset(); }
105 void kb_wait() { vid_wait(); }
106 void kb_nowait() { vid_nowait(); }
107 void kb_timeout() { vid_timeout(); }