1 /* $Id: tty.c,v 1.7 2020-10-18 01:18:05 phil Exp $ */
2
3 /*
4 * tty mode, echo
5 * borland version
6 */
7
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif /* HAVE_CONFIG_H defined */
11
12 #include <stdio.h>
13 #include <conio.h>
14
15 #include "h.h"
16 #include "snotypes.h"
17 #include "lib.h"
18
19 int
fisatty(FILE * f)20 fisatty(FILE *f) {
21 /*
22 * XXX we can only do tty_read() on keyboard so this better not
23 * return true for opens on COM: devices. If so replace "isatty"
24 * with check for fd 0, 1 or 2?
25 */
26 return isatty(fileno(f));
27 }
28
29 void
tty_save(void)30 tty_save(void) {
31 }
32
33 void
tty_restore(void)34 tty_restore(void) {
35 }
36
37 void
tty_mode(FILE * fp,int cbreak,int noecho,int recl)38 tty_mode(FILE *fp, int cbreak, int noecho, int recl) {
39 }
40
41 /* advisory notice */
42 void
tty_close(FILE * f)43 tty_close(FILE *f) {
44 /* should not be called (fisatty returns FALSE) */
45 }
46
47 /* called for raw tty reads if TTY_READ_RAW defined */
48 int
tty_read(FILE * f,char * buf,int len,int raw,int noecho,int keepeol,const char * fname)49 tty_read(FILE *f, char *buf, int len,
50 int raw, int noecho, int keepeol, const char *fname) {
51 int cc;
52
53 if (!raw) /* paranoia */
54 return -1;
55
56 for (cc = 0; cc < len; cc++) {
57 while (!kbhit())
58 ;
59 *buf++ = noecho ? getch() : getche();
60 }
61 return cc;
62 } /* tty_read */
63