From 51790b6a9461d0acbb54f3fdc669ff5c21c0e751 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:03:02 -0800 Subject: [PATCH 1/3] Make 1989/fubar more like original There's no need to have the 'cc' macro have 'int ' before main. Instead have CSILENCE include '-Wno-implicit-int'. --- 1989/fubar/Makefile | 2 +- 1989/fubar/fubar.c | 2 +- thanks-for-help.md | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/1989/fubar/Makefile b/1989/fubar/Makefile index 122352226..cd1421ae7 100644 --- a/1989/fubar/Makefile +++ b/1989/fubar/Makefile @@ -38,7 +38,7 @@ include ../../var.mk # Common C compiler warnings to silence # -CSILENCE= -Wno-implicit-function-declaration -Wno-incompatible-library-redeclaration +CSILENCE= -Wno-implicit-function-declaration -Wno-incompatible-library-redeclaration -Wno-implicit-int # Common C compiler warning flags # diff --git a/1989/fubar/fubar.c b/1989/fubar/fubar.c index 136dbb394..894ad85d7 100644 --- a/1989/fubar/fubar.c +++ b/1989/fubar/fubar.c @@ -3,7 +3,7 @@ #include #define QQ 1 #define TT 1 -#define cc int main(c,v) int c; char **v;{char tt[12],qq[7]; int q=0,o=1,l=1,m=1;struct {int c;} f; +#define cc main(c,v) int c; char **v;{char tt[12],qq[7]; int q=0,o=1,l=1,m=1;struct {int c;} f; #define ouroboros qq[6]='\0';tt[11]='\0';if(QQ==atoi(v[1])+1){(void)fprintf(stderr,"%s factorial = %d\n",v[1], TT);exit(1);}o=c+f #define x ;while(EOF!=(o=getchar())){if(l && q=='Q' && o=='Q'){l=0;(void)getchar();(void)fread(qq,6,1,stdin);(void)printf("Q %6d",atoi(qq)+1);}else if(m && q=='T' && o=='T'){m=0;(void)fread(tt,11,1,stdin);(void)printf("T %9d\n",atoi(tt)*QQ);}else {q=o;(void)putchar(o);}}exit(0);} diff --git a/thanks-for-help.md b/thanks-for-help.md index e62960e14..d76d466b4 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -755,7 +755,8 @@ not strictly necessary but nonetheless more correct, even if not warned against. [Cody](#cody) got this to work with modern systems. The main issues were that an `#include` had to be added along with fixing the path (due to `.` not being in -`$PATH`) to files referred to in the code. +`$PATH`) to files referred to in the code. The path problem was also fixed in +[fubar.sh](/1989/fubar/fubar.sh). ## [1989/jar.1](/1989/jar.1/jar.1.c) ([README.md](/1989/jar.1/README.md])) From 92a66822165a8f46b15ae19c8beac99990260df4 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:10:10 -0800 Subject: [PATCH 2/3] Make 1989/fubar/fubar.sh use bash Fixed for ShellCheck as well. The if [ .. ] was changed to if [[ .. ]] and this was done in the C code as well. --- 1989/fubar/fubar.c | 2 +- 1989/fubar/fubar.sh | 6 +++--- thanks-for-help.md | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/1989/fubar/fubar.c b/1989/fubar/fubar.c index 894ad85d7..34ac78bdf 100644 --- a/1989/fubar/fubar.c +++ b/1989/fubar/fubar.c @@ -10,7 +10,7 @@ if(m && q=='T' && o=='T'){m=0;(void)fread(tt,11,1,stdin);(void)printf("T %9d\n", cc ouroboros.c -o x #define zxc ;{/* cat ./ouroboros.c | ./x $1 > x1 -if [ $? -ne 0 ]; then +if [[ $? -ne 0 ]]; then exit fi mv x1 ./ouroboros.c diff --git a/1989/fubar/fubar.sh b/1989/fubar/fubar.sh index abb4b0ae5..816a1147d 100755 --- a/1989/fubar/fubar.sh +++ b/1989/fubar/fubar.sh @@ -1,8 +1,8 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash # to run fubar in the 'proper' way # parse args -if [ $# -ne 1 ]; then +if [[ $# -ne 1 ]]; then echo "usage: $0 number" 1>&2 exit 1 fi @@ -15,5 +15,5 @@ r fubar.c w ouroboros.c EOF chmod +x ouroboros.c -./ouroboros.c $1 +./ouroboros.c "$1" #rm -f ouroboros.c x1 x diff --git a/thanks-for-help.md b/thanks-for-help.md index d76d466b4..9d6a7058b 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -758,6 +758,9 @@ not strictly necessary but nonetheless more correct, even if not warned against. `$PATH`) to files referred to in the code. The path problem was also fixed in [fubar.sh](/1989/fubar/fubar.sh). +Cody also 'modernised' the script to use `bash` and fixed for ShellCheck. The +`if [ .. ]` was changed in the C code as well as the script. + ## [1989/jar.1](/1989/jar.1/jar.1.c) ([README.md](/1989/jar.1/README.md])) From 231530d8900e158695e85d248ef307cc4d4a3955 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:41:43 -0800 Subject: [PATCH 3/3] Add try.sh to 1989/fubar --- 1989/fubar/Makefile | 3 ++- 1989/fubar/README.md | 7 +++++-- 1989/fubar/try.sh | 30 ++++++++++++++++++++++++++++++ thanks-for-help.md | 2 ++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100755 1989/fubar/try.sh diff --git a/1989/fubar/Makefile b/1989/fubar/Makefile index cd1421ae7..c372d36d6 100644 --- a/1989/fubar/Makefile +++ b/1989/fubar/Makefile @@ -38,7 +38,8 @@ include ../../var.mk # Common C compiler warnings to silence # -CSILENCE= -Wno-implicit-function-declaration -Wno-incompatible-library-redeclaration -Wno-implicit-int +CSILENCE= -Wno-implicit-function-declaration -Wno-incompatible-library-redeclaration -Wno-implicit-int \ + -Wno-deprecated-non-prototype # Common C compiler warning flags # diff --git a/1989/fubar/README.md b/1989/fubar/README.md index 57133ad06..3488ee573 100644 --- a/1989/fubar/README.md +++ b/1989/fubar/README.md @@ -26,14 +26,17 @@ For more detailed information see [1989 fubar in bugs.md](/bugs.md#1989-fubar). ### Try: ```sh -./fubar 2 +./try.sh # run on 1 - 7 + +./fubar.sh 2 # run via script +./fubar 2 # run directly ``` ## Judges' remarks: Run this with a single digit argument (or wait a long time and risk an infinite -loop as described above). +loop as described in the [bugs.md](/bugs.md#1989-fubar) file). The blank line at the beginning of the source is mandatory. Do you know why? diff --git a/1989/fubar/try.sh b/1989/fubar/try.sh new file mode 100755 index 000000000..86445b6ac --- /dev/null +++ b/1989/fubar/try.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 1989/fubar +# + +# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it +# this way allows us to have the user specify a different compiler in an easy +# way. +if [[ -z "$CC" ]]; then + CC="cc" +fi + +make CC="$CC" all >/dev/null || exit 1 + +# clear screen after compilation so that only the entry is shown +clear + +fubar() +{ + if [[ "$#" -ne 1 ]]; then + echo "$0: expected 1 arg, got: $#" 1>&2 + else + read -r -n 1 -p "Press any key to run: ./fubar.sh $1: " + echo 1>&2 + ./fubar.sh "$1" + fi + +} + +for i in $(seq 1 7); do fubar "$i" ; done diff --git a/thanks-for-help.md b/thanks-for-help.md index 9d6a7058b..76169a5bd 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -761,6 +761,8 @@ not strictly necessary but nonetheless more correct, even if not warned against. Cody also 'modernised' the script to use `bash` and fixed for ShellCheck. The `if [ .. ]` was changed in the C code as well as the script. +Cody also added the [try.sh](/1989/fubar/try.sh) script. + ## [1989/jar.1](/1989/jar.1/jar.1.c) ([README.md](/1989/jar.1/README.md]))