Abstract CCSP setup into a function, and set up terminal properly.
If stdin is in use, it'll now be put into non-canonical mode. This is almost the same as libkrocif's behaviour, except I've set VTIME to 0, since I don't think there's a good reason to have a terminal read complete if no characters are available. This also sets CCSP's branding to "Tock", so error messages now start "Tock: ".
This commit is contained in:
parent
ac532be667
commit
88af6a29d2
|
@ -186,14 +186,14 @@ cgenTopLevel s
|
||||||
sequence_ [tell [" ", func, "_kill (wptr, &", kc, ");\n"]
|
sequence_ [tell [" ", func, "_kill (wptr, &", kc, ");\n"]
|
||||||
| (func, kc) <- zip funcs killChans]
|
| (func, kc) <- zip funcs killChans]
|
||||||
|
|
||||||
|
let uses_stdin = if TLPIn `elem` (map snd tlpChans) then "true" else "false"
|
||||||
tell [" LightProcBarrierWait (wptr, &bar);\n\
|
tell [" LightProcBarrierWait (wptr, &bar);\n\
|
||||||
\\n\
|
\\n\
|
||||||
\ Shutdown (wptr);\n\
|
\ Shutdown (wptr);\n\
|
||||||
\}\n\
|
\}\n\
|
||||||
\\n\
|
\\n\
|
||||||
\int main (int argc, char *argv[]) {\n\
|
\int main (int argc, char *argv[]) {\n\
|
||||||
\ if (!ccsp_init ())\n\
|
\ tock_init_ccsp (", uses_stdin, ");\n\
|
||||||
\ return 1;\n\
|
|
||||||
\\n\
|
\\n\
|
||||||
\ Workspace p = ProcAllocInitial (0, "]
|
\ Workspace p = ProcAllocInitial (0, "]
|
||||||
genName tlpName
|
genName tlpName
|
||||||
|
|
|
@ -21,6 +21,10 @@
|
||||||
|
|
||||||
#include <cif.h>
|
#include <cif.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
//{{{ occam_stop
|
//{{{ occam_stop
|
||||||
#define occam_stop(pos, nargs, format, args...) \
|
#define occam_stop(pos, nargs, format, args...) \
|
||||||
|
@ -109,4 +113,60 @@ static void tock_tlp_output_kill (Workspace wptr, Channel *kill) {
|
||||||
}
|
}
|
||||||
//}}}
|
//}}}
|
||||||
|
|
||||||
|
//{{{ 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) {
|
||||||
|
//{{{ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tock_init_ccsp (bool uses_stdin) occam_unused;
|
||||||
|
static void tock_init_ccsp (bool uses_stdin) {
|
||||||
|
ccsp_set_branding ("Tock");
|
||||||
|
|
||||||
|
//{{{ 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//}}}
|
||||||
|
|
||||||
|
if (!ccsp_init ())
|
||||||
|
exit (1);
|
||||||
|
|
||||||
|
ccsp_set_exit_handler (tock_exit_handler);
|
||||||
|
}
|
||||||
|
//}}}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user