Add 1987/heckbert/try.sh
The script runs a variety of commands to show how it can fold files (mostly itself) into different column lengths but it also shows how that folded code can recreate the original (uses diff -s). It also asks a question that was in the try section as well.
This commit is contained in:
1 parent
df22315198
commit
9223a14012
3 files changed
+63
-9
No files matched your search
@@ -20,15 +20,7 @@ where col is the number of columns to fold at and file is the file to fold.
|
|||||||
### Try:
|
### Try:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./heckbert 40 < heckbert.c > ph.c; make ph
|
./try.sh
|
||||||
./ph 21 < heckbert.c > bar.c; make bar
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
Ask yourself what happens to `foo.md` if you try:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
./ph 40 < README.md > foo.md
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Executable
+59
@@ -0,0 +1,59 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# try.sh - demonstrate IOCCC winner 1987/heckbert
|
||||||
|
#
|
||||||
|
|
||||||
|
# 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 show heckbert.c (space = next page, q = quit): "
|
||||||
|
echo 1>&2
|
||||||
|
less -rEXF heckbert.c
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: ./heckbert 40 < heckbert.c: "
|
||||||
|
echo 1>&2
|
||||||
|
./heckbert 40 < heckbert.c
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: ./heckbert 40 < heckbert.c > ph.c; make ph: "
|
||||||
|
./heckbert 40 < heckbert.c > ph.c; make ph
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to show ph.c (space = next page, q = quit): "
|
||||||
|
echo 1>&2
|
||||||
|
less -rEXF ph.c
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: ./ph 21 < heckbert.c > bar.c; make bar: "
|
||||||
|
echo 1>&2
|
||||||
|
./ph 21 < heckbert.c > bar.c; make bar
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to show bar.c (space = next page, q = quit): "
|
||||||
|
echo 1>&2
|
||||||
|
less -rEXF bar.c
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: ./bar 79 < bar.c > foo.c: "
|
||||||
|
echo 1>&2
|
||||||
|
./bar 79 < bar.c > foo.c
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to show difference between foo.c and heckbert.c: "
|
||||||
|
echo 1>&2
|
||||||
|
diff -s heckbert.c foo.c
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: ./ph 40 < README.md > foo.md: "
|
||||||
|
./ph 40 < README.md > foo.md
|
||||||
|
echo 1>&2
|
||||||
|
echo "Now what happened to foo.md?"
|
||||||
@@ -510,6 +510,9 @@ There might have been other changes as well.
|
|||||||
[Cody](#cody) made this look more like the original entry by restoring the `#define` of
|
[Cody](#cody) made this look more like the original entry by restoring the `#define` of
|
||||||
`define`. It's not used but it now looks closer to the original.
|
`define`. It's not used but it now looks closer to the original.
|
||||||
|
|
||||||
|
Cody also added the [try.sh](1987/heckbert/try.sh) script which shows how the
|
||||||
|
program works but also how the folded code can recreate the original.
|
||||||
|
|
||||||
Also because `index(3)` is deprecated and in some systems requires the inclusion
|
Also because `index(3)` is deprecated and in some systems requires the inclusion
|
||||||
of `strings.h` and because it's identical in use to `strchr(3)` (and we noted
|
of `strings.h` and because it's identical in use to `strchr(3)` (and we noted
|
||||||
that for System V we had to do this) Cody added to the Makefile
|
that for System V we had to do this) Cody added to the Makefile
|
||||||
|
|||||||
Reference in new issue
Block a user