From f954d8d4a5370b96c4d812685926508e04827913 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Tue, 14 Nov 2023 04:50:29 -0800 Subject: [PATCH 1/2] Make 2013/birken restore sanity after exit As long as the program (alt code and otherwise) runs to completion the program will return instead of 0: system("reset"); so that the terminal becomes sane again (otherwise cursor is invisible). One could also use 'tput cvvis' but this is longer and I wanted to make the column as close to the original ending as possible. --- 2013/birken/Makefile | 2 +- 2013/birken/README.md | 17 ++++++++++++----- 2013/birken/birken.alt.c | 2 +- 2013/birken/birken.c | 2 +- 2013/birken/try.sh | 2 +- thanks-for-fixes.md | 16 ++++++++++------ 6 files changed, 26 insertions(+), 15 deletions(-) diff --git a/2013/birken/Makefile b/2013/birken/Makefile index 07415fe6f..a9d285c37 100644 --- a/2013/birken/Makefile +++ b/2013/birken/Makefile @@ -61,7 +61,7 @@ CDEFINE= -DZ=15000 # Include files that are needed to compile # -CINCLUDE= +CINCLUDE= -include stdlib.h # Optimization # diff --git a/2013/birken/README.md b/2013/birken/README.md index 09a56ef5f..d55ad8a9a 100644 --- a/2013/birken/README.md +++ b/2013/birken/README.md @@ -42,9 +42,16 @@ perl -e 'map{map{print int(rand()*8);}(0..16);print chr(10);}(0..30);' | tr '[0- ./try.sh ``` -If you wish to speed it up 200% you can use instead `-DZ=3750`. Doing this -you might find the right value to your liking; use ctrl-c to terminate the -program early. +If you wish to speed that up 200% you can use instead `-DZ=3750`. Doing this you +might find the right value to your liking; use ctrl-c to terminate the program +early but note that the terminal is likely to be messed up. Try: + + +```sh +reset +``` + +to make it sane again (running to completion will do that for you). ## Original code: @@ -69,8 +76,8 @@ PLEASE be careful if you are sensitive to flashing colours! ## Judges' remarks: -This program also wins the "Most amusing abuse of the iocccsize tool" award; although not the -absolute best: it is possible to achieve 0 by writing: +This program also wins the "Most amusing abuse of the iocccsize tool" award; +although not the absolute best: it is possible to achieve 0 by writing: ```c /* *\ diff --git a/2013/birken/birken.alt.c b/2013/birken/birken.alt.c index e9f9e21bb..2ff1dd4dd 100644 --- a/2013/birken/birken.alt.c +++ b/2013/birken/birken.alt.c @@ -47,4 +47,4 @@ g[2][g[i][T]]=T; n(R+i)o(e,m )if(G[T][e]+i) G[T][e]=g[2][G[T][e]]; ; else if(G[R][T]+i) s++; if(s) { if(V>4){ V=9-V; D++; } V+=29; n(20) q(c[V][T][0],c [V][T][i],D); } } n(19) if((L=G[R][T])+i) { O=T-L; e=O>9; t=e?18-O :O; o(K,((t&3)-3? 16:37)){ if(K){ L=c[t+19][K-i][0]; O=c[t+19][K-i][i] ; } q(L,O,K && e); } } if(s) q( -c[V][20][0], c[V][20][i], D); R--; } printf("\33[47;1f\33[?25h\33[40m"); return 0; } +c[V][20][0], c[V][20][i], D); R--; } printf("\33[47;1f\33[?25h\33[40m"); return system("reset"); } diff --git a/2013/birken/birken.c b/2013/birken/birken.c index b47199672..c7d8de63f 100644 --- a/2013/birken/birken.c +++ b/2013/birken/birken.c @@ -46,4 +46,4 @@ g[2][g[i][T]]=T; n(R+i)o(e,m )if(G[T][e]+i) G[T][e]=g[2][G[T][e]]; ; else if(G[R][T]+i) s++; if(s) { if(V>4){ V=9-V; D++; } V+=29; n(20) q(c[V][T][0],c [V][T][i],D); } } n(19) if((L=G[R][T])+i) { O=T-L; e=O>9; t=e?18-O :O; o(K,((t&3)-3? 16:37)){ if(K){ L=c[t+19][K-i][0]; O=c[t+19][K-i][i] ; } q(L,O,K && e); } } if(s) q( -c[V][20][0], c[V][20][i], D); R--; } printf("\33[47;1f\33[?25h\33[40m"); return 0; } \ No newline at end of file +c[V][20][0], c[V][20][i], D); R--; } printf("\33[47;1f\33[?25h\33[40m"); return system("reset");} diff --git a/2013/birken/try.sh b/2013/birken/try.sh index faaa5a513..609a82935 100755 --- a/2013/birken/try.sh +++ b/2013/birken/try.sh @@ -18,7 +18,7 @@ if [[ -z "$BIRKEN" ]]; then BIRKEN="birken.alt" fi -trap "clear; exit" SIGINT +trap 'reset; exit' 0 1 2 3 15 for i in *.txt; do NAME="$(echo "$i" | awk '{ print toupper(substr($1,1,1)) substr($1,2)}'|sed -e 's/\.txt//g' \ diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 7d55111b8..8fc0751f8 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -3040,13 +3040,17 @@ sure if he wants to be thanked either :-) but we appreciate it nonetheless. ## [2013/birken](2013/birken/birken.c) ([README.md](2013/birken/README.md])) -Along with the [try.sh](2013/birken/try.sh) that he added, Cody also added an -alternate version which allows one to control how fast the painting is done, +Cody changed the `return 0;` at the end of the program to be `return +system("reset");` so that as long as it runs to completion the terminal will be +sane and the cursor will be visible. + +Cody also added the [try.sh](2013/birken/try.sh) script and the +alternate version (that has the above fix) which allows one to control how fast the painting is done, based on the author's recommendations, except that Cody made it configurable at -compile time just like he did with other entries (in all but one it was -alternate code) that use `usleep()`. The alternate version and the original -version were swapped in the `To build`, `To run` and `Try` sections, with what -is normally `Alternate code` being `Original code`. +compile time just like he did with other entries that use `usleep(3)`. The +alternate version and the original version were swapped in the `To build`, `To +run` and `Try` sections, with what is normally `Alternate code` being `Original +code`. ## [2013/cable3](2013/cable3/cable3.c) ([README.md](2013/cable3/README.md])) From c7c103049472e168e188efe030b336f7f1810537 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Tue, 14 Nov 2023 04:54:09 -0800 Subject: [PATCH 2/2] Restore cursor visibility in 2013/birken at end If the program (alt and original) runs to completion the program will use (via redefined exit(3)): return system("reset"); so that the terminal becomes sane. One could use tput cvvis as well but this was not done as it's longer. --- 2013/birken/birken.alt.c | 3 ++- 2013/birken/birken.c | 3 ++- thanks-for-fixes.md | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/2013/birken/birken.alt.c b/2013/birken/birken.alt.c index 2ff1dd4dd..6833faef0 100644 --- a/2013/birken/birken.alt.c +++ b/2013/birken/birken.alt.c @@ -4,6 +4,7 @@ char*_ = "'""/*"; #define m 21 #define o(l, k) for(l=0; l4){ V=9-V; D++; } V+=29; n(20) q(c[V][T][0],c [V][T][i],D); } } n(19) if((L=G[R][T])+i) { O=T-L; e=O>9; t=e?18-O :O; o(K,((t&3)-3? 16:37)){ if(K){ L=c[t+19][K-i][0]; O=c[t+19][K-i][i] ; } q(L,O,K && e); } } if(s) q( -c[V][20][0], c[V][20][i], D); R--; } printf("\33[47;1f\33[?25h\33[40m"); return system("reset"); } +c[V][20][0], c[V][20][i], D); R--; } printf("\33[47;1f\33[?25h\33[40m"); exit(0); } diff --git a/2013/birken/birken.c b/2013/birken/birken.c index c7d8de63f..c204fdc62 100644 --- a/2013/birken/birken.c +++ b/2013/birken/birken.c @@ -3,6 +3,7 @@ char*_ = "'""/*"; #define m 21 #define o(l, k) for(l=0; l4){ V=9-V; D++; } V+=29; n(20) q(c[V][T][0],c [V][T][i],D); } } n(19) if((L=G[R][T])+i) { O=T-L; e=O>9; t=e?18-O :O; o(K,((t&3)-3? 16:37)){ if(K){ L=c[t+19][K-i][0]; O=c[t+19][K-i][i] ; } q(L,O,K && e); } } if(s) q( -c[V][20][0], c[V][20][i], D); R--; } printf("\33[47;1f\33[?25h\33[40m"); return system("reset");} +c[V][20][0], c[V][20][i], D); R--; } printf("\33[47;1f\33[?25h\33[40m"); exit(0); } diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 8fc0751f8..b8962fa09 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -3041,8 +3041,10 @@ sure if he wants to be thanked either :-) but we appreciate it nonetheless. ## [2013/birken](2013/birken/birken.c) ([README.md](2013/birken/README.md])) Cody changed the `return 0;` at the end of the program to be `return -system("reset");` so that as long as it runs to completion the terminal will be -sane and the cursor will be visible. +system("reset");` (via redefining `exit(3)` so that the column ending would be +the same) so that as long as it runs to completion the terminal will be sane and +the cursor will be visible. Using `atexit(3)` will not work if the program is +killed and signals are ugly so this was not done. Cody also added the [try.sh](2013/birken/try.sh) script and the alternate version (that has the above fix) which allows one to control how fast the painting is done,