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

This commit is contained in:
Cody Boone Ferguson committed 2023-12-14 10:17:59 -08:00
1 parent 0cbd1db764
commit 7f4204bed8
3 files changed
+59 -14

No files matched your search

+19 -14
View File
@@ -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.
+35
View File
@@ -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
+5
View File
@@ -3952,6 +3952,11 @@ He also added the [try.sh](/2015/yang/try.sh) script.
# <a name="2018"></a>2018
## <a name="2018_anderson"></a>[2018/anderson](/2018/anderson/prog.c) ([README.md](/2018/anderson/README.md))
[Cody](#cody) added the [try.sh](/2018/anderson/try.sh) script.
## <a name="2018_algmyr"></a>[2018/algmyr](/2018/algmyr/prog.c) ([README.md](/2018/algmyr/README.md))