Add 2000/anderson/try.sh + format/typo checks

This commit is contained in:
Cody Boone Ferguson committed 2023-11-15 07:44:53 -08:00
1 parent b11061198a
commit 6e482a5a44
3 files changed
+45 -3

No files matched your search

+12 -3
View File
@@ -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;
+31
View File
@@ -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
+2
View File
@@ -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]))