From: Nir Lichtman Subject: Add a way to exit ddb Hangman game To: tech@openbsd.org Date: Sun, 22 Sep 2024 05:44:24 +0000 Problem: Currently the only way to safely exit the DDB hangman game is to win (which is hard) Solution: Add a way to safely exit using CTRL+C (which is expected to help exit a program anyway) =================================================================== diff --git sys/ddb/db_hangman.c sys/ddb/db_hangman.c index e73bd032f..5b13d1d68 100644 --- sys/ddb/db_hangman.c +++ sys/ddb/db_hangman.c @@ -48,6 +48,7 @@ struct _abc { #define TOLOWER(c) ((c)|0x20) #define ISLOWALPHA(c) ('a'<=(c) && (c)<='z') #define ISALPHA(c) ISLOWALPHA(TOLOWER(c)) +#define CTRL(c) ((c) & 0x1f) void db_hang(int, char *, struct _abc *); @@ -176,6 +177,10 @@ db_hangman(db_expr_t addr, int haddr, db_expr_t count, char *modif) } db_hang(tries, word, sabc); c = cngetc(); + + if (c == CTRL('c')) + break; + c = TOLOWER(c); if (ISLOWALPHA(c) && ABC_ISCLR(c)) {