return to toplevel from a long running query after receiving Ctrl-C

This commit is contained in:
Mark Thom
2019-09-30 13:27:22 -06:00
parent ecb2cc3518
commit b26c5c213e
4 changed files with 35 additions and 1 deletions

View File

@@ -2,20 +2,38 @@
extern crate downcast;
extern crate indexmap;
#[macro_use]
extern crate lazy_static;
extern crate libc;
extern crate nix;
#[macro_use]
extern crate prolog_parser;
#[macro_use]
extern crate ref_thread_local;
extern crate termion;
use nix::sys::signal;
mod prolog;
use prolog::machine::*;
use prolog::read::*;
use std::sync::atomic::Ordering;
#[cfg(test)]
mod tests;
extern fn handle_sigint(signal: libc::c_int) {
let signal = signal::Signal::from_c_int(signal).unwrap();
if signal == signal::Signal::SIGINT {
INTERRUPT.store(true, Ordering::Relaxed);
}
}
fn main() {
let mut wam = Machine::new(readline::input_stream());
let handler = signal::SigHandler::Handler(handle_sigint);
unsafe { signal::signal(signal::Signal::SIGINT, handler) }.unwrap();
let mut wam = Machine::new(readline::input_stream());
wam.run_top_level();
}