diff options
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 { |