diff options
| author | Franklin Wei <git@fwei.tk> | 2015-05-22 21:20:44 -0400 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2015-05-22 21:20:44 -0400 |
| commit | 9e53ccfefd2433452fdfa2bbe2ece903c0afb790 (patch) | |
| tree | f0e9c0c5a3f152e1d05c5fd8da0b76b21d3bedd9 /src | |
| parent | 06d3b96728f44c32a918eac21c6ec2995bf62a94 (diff) | |
| download | market-sim-9e53ccfefd2433452fdfa2bbe2ece903c0afb790.zip market-sim-9e53ccfefd2433452fdfa2bbe2ece903c0afb790.tar.gz market-sim-9e53ccfefd2433452fdfa2bbe2ece903c0afb790.tar.bz2 market-sim-9e53ccfefd2433452fdfa2bbe2ece903c0afb790.tar.xz | |
support ctrl-c
Diffstat (limited to 'src')
| -rw-r--r-- | src/globals.h | 2 | ||||
| -rw-r--r-- | src/main.c | 10 | ||||
| -rw-r--r-- | src/util.c | 7 |
3 files changed, 16 insertions, 3 deletions
diff --git a/src/globals.h b/src/globals.h index b85ecc0..ee6790f 100644 --- a/src/globals.h +++ b/src/globals.h @@ -3,6 +3,7 @@ #include <assert.h> #include <ctype.h> +#include <signal.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> @@ -110,6 +111,7 @@ void load_portfolio(struct player_t*, const char*); void print_history(struct stock_t*); void print_usage(int argc, char *argv[]); void print_version(void); +void sig_handler(int); int output(const char*, ...); void buy_handler(struct player_t*); @@ -13,15 +13,19 @@ int main(int argc, char *argv[]) curl_global_init(CURL_GLOBAL_DEFAULT); - atexit(cleanup); - initscr(); echo(); nocbreak(); nl(); scrollok(stdscr, true); - atexit(endwin); + atexit(cleanup); + + const struct sigaction handler = { + .sa_handler = sig_handler + }; + + sigaction(SIGINT, &handler, NULL); struct player_t *player = malloc(sizeof(struct player_t)); memset(player, 0, sizeof(struct player_t)); @@ -6,6 +6,13 @@ void cleanup(void) { curl_global_cleanup(); + endwin(); +} + +void sig_handler(int sig) +{ + cleanup(); + exit(EXIT_FAILURE); } struct data_buffer_t { |