From e055834526a2d6c4f98d268f4f04724ba8b38161 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 4 Sep 2022 13:15:33 +0200 Subject: [PATCH] Minor refactor to simplify signal handler Signed-off-by: Joachim Wiberg --- tetris.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tetris.c b/tetris.c index a064d59..d63f4e4 100644 --- a/tetris.c +++ b/tetris.c @@ -69,6 +69,8 @@ #define HIGH_SCORE_FILE "/var/games/tetris.scores" #define TEMP_SCORE_FILE "/tmp/tetris-tmp.scores" +static volatile sig_atomic_t running = 1; + static struct termios savemodes; static int havemodes = 0; @@ -309,10 +311,7 @@ static void alarm_handler(int signo) static void exit_handler(int signo) { (void)signo; - - clrscr(); - tty_exit(); - exit(0); + running = 0; } static void sig_init(void) @@ -349,7 +348,7 @@ int main(void) show_online_help(); shape = next_shape(); - while (1) { + while (running) { if (c < 0) { if (fits_in(shape, pos + B_COLS)) { pos += B_COLS; @@ -427,6 +426,7 @@ int main(void) place(shape, pos, 0); } + clrscr(); if (tty_exit() == -1) return 1; -- 2.11.4.GIT