version 1.23, 2002/09/15 14:08:57 |
version 1.24, 2003/11/09 00:23:01 |
|
|
#define TCSASOFT 0 |
#define TCSASOFT 0 |
#endif |
#endif |
|
|
|
int ttstarted; |
char obuf[NOBUF]; /* Output buffer. */ |
char obuf[NOBUF]; /* Output buffer. */ |
int nobuf; /* Buffer count. */ |
int nobuf; /* Buffer count. */ |
struct termios oldtty; /* POSIX tty settings. */ |
struct termios oldtty; /* POSIX tty settings. */ |
|
|
void |
void |
ttopen(void) |
ttopen(void) |
{ |
{ |
|
|
if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) |
if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) |
panic("standard input and output must be a terminal"); |
panic("standard input and output must be a terminal"); |
|
|
|
|
int |
int |
ttraw(void) |
ttraw(void) |
{ |
{ |
|
|
if (tcgetattr(0, &oldtty) < 0) { |
if (tcgetattr(0, &oldtty) < 0) { |
ewprintf("ttopen can't get terminal attributes"); |
ewprintf("ttopen can't get terminal attributes"); |
return (FALSE); |
return (FALSE); |
|
|
ewprintf("ttopen can't tcsetattr"); |
ewprintf("ttopen can't tcsetattr"); |
return (FALSE); |
return (FALSE); |
} |
} |
|
ttstarted = 1; |
|
|
return (TRUE); |
return (TRUE); |
} |
} |
|
|
|
|
void |
void |
ttclose(void) |
ttclose(void) |
{ |
{ |
if (ttcooked() == FALSE) |
if (ttstarted) { |
panic(""); /* ttcooked() already printf'd */ |
if (ttcooked() == FALSE) |
|
panic(""); /* ttcooked() already printf'd */ |
|
ttstarted = 0; |
|
} |
} |
} |
|
|
/* |
/* |
|
|
void |
void |
panic(char *s) |
panic(char *s) |
{ |
{ |
|
ttclose(); |
(void) fputs("panic: ", stderr); |
(void) fputs("panic: ", stderr); |
(void) fputs(s, stderr); |
(void) fputs(s, stderr); |
(void) fputc('\n', stderr); |
(void) fputc('\n', stderr); |