From 7f4204bed874b8374bb0ce261798d9d99530a2b4 Mon Sep 17 00:00:00 2001
From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com>
Date: Thu, 14 Dec 2023 10:17:59 -0800
Subject: [PATCH] Add 2018/anderson/try.sh + format/typo checks
---
2018/anderson/README.md | 33 +++++++++++++++++++--------------
2018/anderson/try.sh | 35 +++++++++++++++++++++++++++++++++++
thanks-for-help.md | 5 +++++
3 files changed, 59 insertions(+), 14 deletions(-)
create mode 100755 2018/anderson/try.sh
diff --git a/2018/anderson/README.md b/2018/anderson/README.md
index 1da341724..eeb3a9ee1 100644
--- a/2018/anderson/README.md
+++ b/2018/anderson/README.md
@@ -4,6 +4,9 @@
make
```
+There is an alternate version of this entry. See [Alternate
+code](#alternate-code) below for more details.
+
## To use:
@@ -15,32 +18,33 @@ make
### Try:
```sh
-./prog < prog.c
-./prog < prog.alt.c
-./prog < README.md
+./try.sh
```
## Alternate code:
-An alternate version of this entry, [prog.alt.c](prog.alt.c), is provided.
-
Compare [prog.c](prog.c) and [prog.alt.c](prog.alt.c) and find out why we had to
modify the entry, and what confused the author (see the author's remarks). No,
it was not the shape of the Roman V that we, or the compiler, didn't like.
-To compile this alternate version:
+
+### Alternate build:
```sh
make alt
```
+
+### Alternate use:
+
Use `prog.alt` as you would `prog` above.
## Judges' remarks:
-With this entry, you won't need to turn your monitor [upside down](http://en.wikipedia.org/wiki/River_%28typography%29)!
+With this entry, you won't need to turn your monitor [upside
+down](http://en.wikipedia.org/wiki/River_%28typography%29)!
## Author's remarks:
@@ -52,12 +56,13 @@ cc -Wall -Wextra -Wpedantic -O3 -std=c11 prog.c -o prog
```
Also works with a standard of C99, but C90/C89 will not compile due to
-for loop initial declarations, along with additional warnings about
-variable length arrays and lack of a return statement.
+`for` loop initial declarations, along with additional warnings about
+variable length arrays and lack of a `return` statement.
+
### Additional info:
-This small program, when given text on stdin, will produce a pattern of
+This small program, when given text on `stdin`, will produce a pattern of
squiggly lines. This pattern is deterministic, and it shouldn't be too
difficult to determine from whence they come. There is even a comment
that describes the highlighted phenomena in the source, for those that
@@ -74,14 +79,14 @@ such as proper handling of tabs are left as an exercise to the reader.
In developing this program, the author found a potentially interesting
bug. If the expression `(j=k,j)` (near the middle of the source) is
changed to `(j=k,k)`, the program produces different output. The author
-used compiler gcc 5.4.0, compiled for x86_64-linux-gnu. Enabling or
+used gcc 5.4.0, compiled for `x86_64-linux-gnu`. Enabling or
disabling optimization produces the same results. The author is not
sure who is the culprit, but instead shrugged and moved on with life.
Of course, YMMV with your own environment.
-The structure of this program, as you may have deduced, is two for
-loops, one nested in the other. There is also a bunch of direct
-variable assignment, such as `j=k`. There is some filler fluff, such as
+The structure of this program, as you may have deduced, is two `for`
+loops, one nested in the other. There are also a bunch of direct
+variable assignments, such as `j=k`. There is some filler fluff, such as
`0-0+0`, but all that sort should be rather easy to spot. It was mostly
added for the purpose of making certain things line up right, and only
secondarily to obfuscate.
diff --git a/2018/anderson/try.sh b/2018/anderson/try.sh
new file mode 100755
index 000000000..18cdfae8a
--- /dev/null
+++ b/2018/anderson/try.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+#
+# try.sh - demonstrate IOCCC winner 2018/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: ./prog < prog.c: "
+echo 1>&2
+./prog < prog.c
+echo 1>&2
+
+read -r -n 1 -p "Press any key to run: ./prog < prog.alt.c: "
+echo 1>&2
+./prog < prog.alt.c
+echo 1>&2
+
+read -r -n 1 -p "Press any key to run: ./prog < README.md (space = next page, q = quit): "
+echo 1>&2
+./prog < README.md | less -EXF
+echo 1>&2
+
+read -r -n 1 -p "Press any key to run: ./prog < Makefile (space = next page, q = quit): "
+echo 1>&2
+./prog < Makefile | less -EXF
diff --git a/thanks-for-help.md b/thanks-for-help.md
index 62ccb2b28..e6d587549 100644
--- a/thanks-for-help.md
+++ b/thanks-for-help.md
@@ -3952,6 +3952,11 @@ He also added the [try.sh](/2015/yang/try.sh) script.
# 2018
+## [2018/anderson](/2018/anderson/prog.c) ([README.md](/2018/anderson/README.md))
+
+[Cody](#cody) added the [try.sh](/2018/anderson/try.sh) script.
+
+
## [2018/algmyr](/2018/algmyr/prog.c) ([README.md](/2018/algmyr/README.md))