From 6e482a5a44989cb7e94b9b29b149144d8c6efa06 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Wed, 15 Nov 2023 07:44:53 -0800 Subject: [PATCH] Add 2000/anderson/try.sh + format/typo checks --- 2000/anderson/README.md | 15 ++++++++++++--- 2000/anderson/try.sh | 31 +++++++++++++++++++++++++++++++ thanks-for-fixes.md | 2 ++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100755 2000/anderson/try.sh diff --git a/2000/anderson/README.md b/2000/anderson/README.md index 16bb8aad9..0ef16c714 100644 --- a/2000/anderson/README.md +++ b/2000/anderson/README.md @@ -15,7 +15,7 @@ echo something | ./anderson ### Try: ```sh -echo Obfuscate | ./anderson +./try.sh ``` @@ -30,6 +30,15 @@ very cleverly obscured without the use of a single `#define`! Reformatting this program by hand :-) is the easiest way to understand what is going on. +### Note about `#define`s not being used: + +In 2023 due to annoying warnings triggered at different times, sometimes +interspersed with the output of the program (this happens in macOS), many +entries were changed to use `fgets(3)` instead. However to make the entries more +like the original we redefined `gets` to use `fgets`. Unfortunately it's not +possible to do it through `-Dfoo` compiler options so there is a `#define` in +the code now. + ## Author's remarks: @@ -59,7 +68,7 @@ input "Hello, world!", the output will be: The program is obfuscated without the use of the preprocessor or any special compilation parameters. In fact, the program doesn't even -bother using any keywords, save the single 'char' at the beginning. +bother using any keywords, save the single `char` at the beginning. This program was crafted using only operator precedence rules, short-circuit evaluation and recursion. Each function contains a single, non-empty statement. (I did have to add a couple of empty @@ -75,7 +84,7 @@ An ANSI C compiler will generate several warnings when it compiles this program, as none of the functions declare their return type, nor do they return anything. This was necessary to keep the program free of keywords. It's valid in K&R C, and compiles in ANSI C. There are also -warnings about conversion from 'int' to 'char' and the resulting loss of +warnings about conversion from `int` to `char` and the resulting loss of data. Again, if it's OK with K&R, it's OK with me. This program is a great teaching tool for learning the semaphore code; diff --git a/2000/anderson/try.sh b/2000/anderson/try.sh new file mode 100755 index 000000000..0028f7986 --- /dev/null +++ b/2000/anderson/try.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2000/anderson +# + +# 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 + +read -r -n 1 -p "Press any key to run: echo Obfuscate | ./anderson: " +echo Obfuscate | ./anderson + +read -r -n 1 -p "Press any key to run: echo 'Hello, world!' | ./anderson: " +echo 'Hello, world!' | ./anderson + +read -r -n 1 -p "Press any key to run: ./anderson < anderson.c: " +./anderson < anderson.c + +read -r -n 1 -p "Press any key to run: ./anderson < README.md: " +./anderson < README.md + +read -r -n 1 -p "Press any key to run: cat README.md anderson.c | ./anderson: " +cat README.md anderson.c | ./anderson diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 8564b8167..f97af52c9 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -2258,6 +2258,8 @@ changing the `K` arg to `gets(3)` to `&K` in `fgets(3)`. Cody later improved the fix to use `gets()` by redefining `gets()` so that the code looks like before. +Cody also added the [try.sh](2000/anderson/try.sh) script. + ## [2000/briddlebane](2000/briddlebane/briddlebane.c) ([README.md](2000/briddlebane/README.md]))