From a438eb468f9847ab98017ce5a5ab2e8bd21423de Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Tue, 16 Jan 2024 05:57:13 -0800 Subject: [PATCH] Add 1994/imc/try.sh + inclusion of unistd.h The inclusion of unistd.h is for getpid(2). While not strictly necessary (at least not observed) this type of thing can be a problem and in some other entries a missing or incorrect prototype caused the entry to fail (sometimes only some systems namely macOS). This was just noticed by chance and I did it on a whim. --- 1994/imc/Makefile | 3 +-- 1994/imc/README.md | 7 +------ 1994/imc/imc.c | 1 + 1994/imc/try.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ thanks-for-help.md | 10 ++++++++++ 5 files changed, 55 insertions(+), 8 deletions(-) create mode 100755 1994/imc/try.sh diff --git a/1994/imc/Makefile b/1994/imc/Makefile index 38c4d76a5..8e31f7f7f 100644 --- a/1994/imc/Makefile +++ b/1994/imc/Makefile @@ -38,8 +38,7 @@ include ../../var.mk # Common C compiler warnings to silence # -CSILENCE= -Wno-error -Wno-implicit-function-declaration \ - -Wno-deprecated-non-prototype -Wno-strict-prototypes +CSILENCE= -Wno-error -Wno-deprecated-non-prototype -Wno-strict-prototypes # Common C compiler warning flags # diff --git a/1994/imc/README.md b/1994/imc/README.md index 7d3192474..cfa4090f8 100644 --- a/1994/imc/README.md +++ b/1994/imc/README.md @@ -17,12 +17,7 @@ where `[NUMBER]` is an optional number. Default is 5. ## Try: ```sh -./imc 3 -./imc 3 -./imc 4 -./imc 4 -./imc 6 -./imc 13 +./try.sh ``` diff --git a/1994/imc/imc.c b/1994/imc/imc.c index 8cde6fe74..6323cf426 100644 --- a/1994/imc/imc.c +++ b/1994/imc/imc.c @@ -1,5 +1,6 @@ #include #include +#include #define f (sizeof(int)) int i,j,k,l,m,*t,*u,*v; diff --git a/1994/imc/try.sh b/1994/imc/try.sh new file mode 100755 index 000000000..1a0780745 --- /dev/null +++ b/1994/imc/try.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 1994/imc +# + +# 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 + +imc() +{ + if [[ "$#" != 1 ]]; then + echo "$0: imc() expects 1, arg got: $#" 1>&2 + return + fi + + read -r -n 1 -p "Press any key to run: ./imc $1: " + echo 1>&2 + ./imc "$1" + echo 1>&2 + + # Notice how we run the program with the same arg as above. This is because it + # will not show the same output as it is randomised. + read -r -n 1 -p "Press any key to run: ./imc $1: " + echo 1>&2 + ./imc "$1" + echo 1>&2 +} + +# clear screen after compilation so that only the entry is shown +clear + +imc 3 +imc 4 +imc 6 +imc 13 +imc 15 diff --git a/thanks-for-help.md b/thanks-for-help.md index 3b4a03104..3b97574ae 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -1890,6 +1890,16 @@ newsletter was found on the Internet Wayback Machine and the article was extracted as a PDF in the macOS `Preview.app` (`File -> Print` feature). +## [1994/imc](/1994/imc/imc.c) ([README.md](/1994/imc/README.md])) + +[Cody](#cody) added the [try.sh](/1994/imc/try.sh) script. + +Cody also added inclusion of `unistd.h` for `getpid(2)`. While strictly speaking +this was not necessary (in multiple systems) it can sometimes be a problem and +as it was noticed it was changed (the only case this was done except in the +entries that actually did not work because of missing or incorrect prototypes). + + ## [1994/ldb](/1994/ldb/ldb.c) ([README.md](/1994/ldb/README.md])) [Cody](#cody) fixed this so it would compile and work with modern compilers. The problem