Moved the code for setting up the terminal into tock_support.h so that C++CSP can use it too
This commit is contained in:
parent
c37e183879
commit
e8adfb51fa
|
@ -26,6 +26,10 @@
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
//{{{ mostneg/mostpos
|
//{{{ mostneg/mostpos
|
||||||
#define occam_mostneg_bool false
|
#define occam_mostneg_bool false
|
||||||
|
@ -355,4 +359,53 @@ static inline double occam_DSQRT (double v, const char *pos) {
|
||||||
}
|
}
|
||||||
//}}}
|
//}}}
|
||||||
|
|
||||||
|
//{{{ Terminal handling
|
||||||
|
static bool tock_uses_tty;
|
||||||
|
static struct termios tock_saved_termios;
|
||||||
|
|
||||||
|
static void tock_restore_terminal() occam_unused;
|
||||||
|
static void tock_restore_terminal()
|
||||||
|
{
|
||||||
|
//{{{ restore terminal
|
||||||
|
if (tock_uses_tty) {
|
||||||
|
if (tcsetattr (0, TCSAFLUSH, &tock_saved_termios) != 0) {
|
||||||
|
fprintf (stderr, "Tock: tcsetattr failed\n");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
tock_uses_tty = false;
|
||||||
|
}
|
||||||
|
//}}}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tock_configure_terminal(bool) occam_unused;
|
||||||
|
static void tock_configure_terminal(bool uses_stdin)
|
||||||
|
{
|
||||||
|
//{{{ configure terminal
|
||||||
|
tock_uses_tty = uses_stdin && isatty (0);
|
||||||
|
if (tock_uses_tty) {
|
||||||
|
struct termios term;
|
||||||
|
|
||||||
|
if (tcgetattr (0, &term) != 0) {
|
||||||
|
fprintf (stderr, "Tock: tcgetattr failed\n");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
tock_saved_termios = term;
|
||||||
|
|
||||||
|
// Disable canonicalised input and echoing.
|
||||||
|
term.c_lflag &= ~(ICANON | ECHO);
|
||||||
|
// Satisfy a read request when one character is available.
|
||||||
|
term.c_cc[VMIN] = 1;
|
||||||
|
// Block read requests until VMIN characters are available.
|
||||||
|
term.c_cc[VTIME] = 0;
|
||||||
|
|
||||||
|
if (tcsetattr (0, TCSANOW, &term) != 0) {
|
||||||
|
fprintf (stderr, "Tock: tcsetattr failed\n");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//}}}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -121,22 +121,9 @@ static void tock_tlp_output_kill (Workspace wptr, Channel *kill) {
|
||||||
//}}}
|
//}}}
|
||||||
|
|
||||||
//{{{ CCSP startup and terminal handling
|
//{{{ CCSP startup and terminal handling
|
||||||
static bool tock_uses_tty;
|
|
||||||
static struct termios tock_saved_termios;
|
|
||||||
|
|
||||||
static void tock_exit_handler (int status, word core) occam_unused;
|
static void tock_exit_handler (int status, word core) occam_unused;
|
||||||
static void tock_exit_handler (int status, word core) {
|
static void tock_exit_handler (int status, word core) {
|
||||||
//{{{ restore terminal
|
tock_restore_terminal();
|
||||||
if (tock_uses_tty) {
|
|
||||||
if (tcsetattr (0, TCSAFLUSH, &tock_saved_termios) != 0) {
|
|
||||||
fprintf (stderr, "Tock: tcsetattr failed\n");
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
tock_uses_tty = false;
|
|
||||||
}
|
|
||||||
//}}}
|
|
||||||
|
|
||||||
ccsp_default_exit_handler (status, core);
|
ccsp_default_exit_handler (status, core);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,30 +131,7 @@ static void tock_init_ccsp (bool uses_stdin) occam_unused;
|
||||||
static void tock_init_ccsp (bool uses_stdin) {
|
static void tock_init_ccsp (bool uses_stdin) {
|
||||||
ccsp_set_branding ("Tock");
|
ccsp_set_branding ("Tock");
|
||||||
|
|
||||||
//{{{ configure terminal
|
tock_configure_terminal(uses_stdin);
|
||||||
tock_uses_tty = uses_stdin && isatty (0);
|
|
||||||
if (tock_uses_tty) {
|
|
||||||
struct termios term;
|
|
||||||
|
|
||||||
if (tcgetattr (0, &term) != 0) {
|
|
||||||
fprintf (stderr, "Tock: tcgetattr failed\n");
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
tock_saved_termios = term;
|
|
||||||
|
|
||||||
// Disable canonicalised input and echoing.
|
|
||||||
term.c_lflag &= ~(ICANON | ECHO);
|
|
||||||
// Satisfy a read request when one character is available.
|
|
||||||
term.c_cc[VMIN] = 1;
|
|
||||||
// Block read requests until VMIN characters are available.
|
|
||||||
term.c_cc[VTIME] = 0;
|
|
||||||
|
|
||||||
if (tcsetattr (0, TCSANOW, &term) != 0) {
|
|
||||||
fprintf (stderr, "Tock: tcsetattr failed\n");
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//}}}
|
|
||||||
|
|
||||||
if (!ccsp_init ())
|
if (!ccsp_init ())
|
||||||
exit (1);
|
exit (1);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user