From b127660a5c6adf834a654ddd571e53fa7dd2089a Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Thu, 16 Nov 2023 09:35:30 -0800 Subject: [PATCH] Bug fix 2001/ctk and alt code added Fixed bug where if one does not hit 'q' it would mess up the terminal on exit. I think (but I'm also distracted) this happened if you crashed as well. Now if you kill the game (ctrl-c for instance), you crash or you quit with 'q' it should still be a sane terminal. The alt code adds (it does not replace) vi(m) movement keys: h for left, l for right and k for straight. Format/typo check README.md file. --- 2001/ctk/Makefile | 7 +++++-- 2001/ctk/README.md | 48 ++++++++++++++++++++++++++++----------------- 2001/ctk/ctk.c | 2 +- thanks-for-fixes.md | 9 ++++++++- 4 files changed, 44 insertions(+), 22 deletions(-) diff --git a/2001/ctk/Makefile b/2001/ctk/Makefile index 83928a90a..e626182db 100644 --- a/2001/ctk/Makefile +++ b/2001/ctk/Makefile @@ -114,8 +114,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= ${PROG}.alt ################# @@ -138,6 +138,9 @@ ${PROG}: ${PROG}.c alt: data ${ALT_TARGET} @${TRUE} +${PROG}.alt: ${PROG}.alt.c + ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} + # data files # data: ${DATA} diff --git a/2001/ctk/README.md b/2001/ctk/README.md index ba30c4fb3..5a762e2f6 100644 --- a/2001/ctk/README.md +++ b/2001/ctk/README.md @@ -4,6 +4,9 @@ make ``` +There is an alternate version with vi(m) key movements. See [alternate +code](#alternate code) below. + ## To use: @@ -12,14 +15,24 @@ make ``` -### Try: +## Alternate code: + +This alternate version adds to the movement keys `l` for right, `h` for left and +`k` for straight. + + +### Alternate build: + ```sh -echo "Do or do not. There is no try." +make alt ``` -Make sure to hit `q` to exit or else your terminal will be messed up (to restore -it you can try `stty sane` or `reset`). +### Alternate use: + +```sh +./ctk.alt +``` ## Judges' remarks: @@ -32,20 +45,19 @@ This is, of course, another of the retro games. ## Author's remarks: -This is a game based on an Apple ][ Print Shop Companion [Easter -egg][1] named 'DRIVER', in which the goal is to drive as fast as -you can down a long twisty highway without running off the -road. Use `,./`, `[ ]`, or `bnm` to go left, straight, and -right respectively. Use `1234` to switch gears. `q` quits. The -faster you go and the thinner the road is, the more points you -get. Most of the obfuscation is in the nonsensical if statements -among other things. It works best on the Linux console: you -get engine sound (!) and the * Lock keyboard lights tell you -what gear you're in (none lit=4th). The `q` argument (no -leading `-`) will silence the sound. It won't work on a terminal -smaller than 80x24, but it works fine with more (try it in an -XTerm with the "Unreadable" font and the window maximized -vertically!). +This is a game based on an [Apple +II](https://en.wikipedia.org/wiki/Apple_II_series) [Print Shop +Companion](https://en.wikipedia.org/wiki/The_Print_Shop) [Easter egg][1] named +'DRIVER', in which the goal is to drive as fast as you can down a long twisty +highway without running off the road. Use `,./`, `[ ]`, or `bnm` to go left, +straight, and right respectively. Use `1234` to switch gears. `q` quits. The +faster you go and the thinner the road is, the more points you get. Most of the +obfuscation is in the nonsensical if statements among other things. It works +best on the Linux console: you get engine sound (!) and the * Lock keyboard +lights tell you what gear you're in (none lit=4th). The `q` argument (no +leading `-`) will silence the sound. It won't work on a terminal smaller than +80x24, but it works fine with more (try it in an XTerm with the "Unreadable" +font and the window maximized vertically!). [1]: https://en.wikipedia.org/wiki/Easter_egg_(media)#In_computing diff --git a/2001/ctk/ctk.c b/2001/ctk/ctk.c index 6aba6497c..597610be4 100644 --- a/2001/ctk/ctk.c +++ b/2001/ctk/ctk.c @@ -22,4 +22,4 @@ SIG_IGN);printf("\e[0q\ecScore: %u\n",s);system("stty echo -cbreak");}int main int)0x756E696C||C==(int)0x6C696E75);srand(getpid());system("stty -echo cbreak" );h(0);u(14);for(;;)switch(getchar()){case 113:return 0;case 91:case 98:c(44,k =-1);case 32:case 110:c(46,k=0);case 93:case 109:c(47,k=1);c(49,h(0));c(50,h(1 -));c(51,h(2));c(52,h(3));}} +));c(51,h(2));c(52,h(3));}e();} diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 6fd3ef875..0a5040bfc 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -2517,7 +2517,14 @@ sound devices in macOS). ## [2001/ctk](2001/ctk/ctk.c) ([README.md](2001/ctk/README.md])) The ANSI escape codes were no longer valid but Yusuke provided a patch to fix -the ANSI escape codes. Cody tested this for macOS and it works fine. +the ANSI escape codes. This works with both linux and macOS. + +Cody fixed this so that it should always restore terminal sanity (echo enabled +etc.) after exiting even if you don't press 'q', if you crash or if you kill the +program prematurely. + +Cody also added the [alt code](2001/ctk/README.md#alternate-code) that adds +vi(m) movement keys. ## [2001/dgbeards](2001/dgbeards/dgbeards.c) ([README.md](2001/dgbeards/README.md]))