Add 1992/adrian/try.sh
This script shows the entry itself as well as some of the other tools that the entry generates. The adwc / wc one uses a pipeline to show the output (with leading spaces and filename removed along with squeezing spaces) and also writes each to a text file to use diff on, to show how they have the same output. Not all the tools are in the script. The adbasename might have a bug (in any case it doesn't appear to function exactly like basename(1) in that it requires two args, not one) so it is not used and adgrep is not used either. For the latter one the author's remarks might provide some clues as to why I did not include it.
This commit is contained in:
1 parent
85a9066b02
commit
094a4da91a
4 files changed
+76
-11
No files matched your search
@@ -13,8 +13,10 @@ adsleep
|
||||
adsleep.c
|
||||
adwc
|
||||
adwc.c
|
||||
adwc.adwc.txt
|
||||
*.dSYM
|
||||
indent
|
||||
indent.c
|
||||
indent.o
|
||||
prog.orig
|
||||
wc.adwc.txt
|
||||
+7
-10
@@ -20,7 +20,7 @@ For more detailed information see [1992 adrian in bugs.md](/bugs.md#1992-adrian)
|
||||
### Try:
|
||||
|
||||
```sh
|
||||
./adrian adrian.grep.try < README.md
|
||||
./try.sh
|
||||
```
|
||||
|
||||
For the slow minded, try:
|
||||
@@ -29,9 +29,6 @@ For the slow minded, try:
|
||||
./adsleep 32767
|
||||
```
|
||||
|
||||
NOTE: if you do not specify an arg some of the programs such as `adsleep` it
|
||||
will very likely segfault do something funny. This is supposed to happen.
|
||||
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
@@ -160,11 +157,11 @@ Running:
|
||||
|
||||
will perform a function similar to that of the unix `from` command.
|
||||
|
||||
If no filename is specified on the command line, then `__FILE__` is used
|
||||
as the specification for the automaton. (Originally `"adgrep.c"` the file was renamed
|
||||
to `adrian.c` by the judges but for more portability the arg was changed to
|
||||
`__FILE__`.) In this case, the program will search for
|
||||
matches to the regular expression:
|
||||
If no filename is specified on the command line, then `__FILE__` is used as the
|
||||
specification for the automaton. (Originally this was `"adgrep.c"` but the file
|
||||
was renamed to `adrian.c` by the judges and for more portability the arg was
|
||||
changed to `__FILE__`.) In this case, the program will search for matches to
|
||||
the regular expression:
|
||||
|
||||
```
|
||||
^.[^|C][^w[Q]*(Q|[w[]c).*|^.[C|]$
|
||||
@@ -219,7 +216,7 @@ you can search for matches to
|
||||
|
||||
By some freak happenstance, lines of `adrian.c` which match this regular
|
||||
expression form a unix `head(1)` command. It prints the first ten lines of
|
||||
the file specified on the command line or adrian.c if no file is
|
||||
the file specified on the command line or `adrian.c` if no file is
|
||||
specified (again this was changed to `__FILE__`).
|
||||
|
||||
By setting the first line to
|
||||
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.sh - demonstrate IOCCC winner 1992/adrian
|
||||
#
|
||||
|
||||
# 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
|
||||
|
||||
# don't redirect output to /dev/null so that they can see how it's done,
|
||||
# assuming it's not already built
|
||||
make CC="$CC" everything || exit 1
|
||||
# DON'T clear the screen so they can see how the files are generated!
|
||||
|
||||
echo 1>&2
|
||||
read -r -n 1 -p "Press any key to show: adrian.grep.try: "
|
||||
echo 1>&2
|
||||
cat adrian.grep.try
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./adrian adrian.grep.try < README.md: "
|
||||
echo 1>&2
|
||||
./adrian adrian.grep.try < README.md
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./adhead try.sh: "
|
||||
echo 1>&2
|
||||
./adhead try.sh
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./adecho 1992 IOCCC adrian: "
|
||||
echo 1>&2
|
||||
./adecho 1992 IOCCC adrian
|
||||
echo 1>&2
|
||||
|
||||
rm -f wc.adwc.txt adwc.adwc.txt
|
||||
echo "$ wc adwc.c | sed -e 's/^[[:space:]]//g' | tr -s '[:space:]' | cut -d' ' -f1-3 | tee wc.adwc.txt" 1>&2
|
||||
read -r -n 1 -p "Press any key to continue: "
|
||||
echo 1>&2
|
||||
wc adwc.c | sed -e 's/^[[:space:]]//g' | tr -s '[:space:]' | cut -d' ' -f1-3 | tee wc.adwc.txt
|
||||
echo 1>&2
|
||||
|
||||
echo "$ ./adwc adwc.c|tr -s ' '|sed -e 's/^[[:space:]]//g' | tee adwc.adwc.txt" 1>&2
|
||||
read -r -n 1 -p "Press any key to continue: "
|
||||
echo 1>&2
|
||||
./adwc adwc.c|tr -s ' '|sed -e 's/^[[:space:]]//g' | tee adwc.adwc.txt
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to show diff between wc.adwc.txt and adwc.adwc.txt: "
|
||||
echo 1>&2
|
||||
diff -s wc.adwc.txt adwc.adwc.txt
|
||||
echo 1>&2
|
||||
rm -f wc.adwc.txt adwc.adwc.txt
|
||||
|
||||
echo "$ ./adsleep 10" 1>&2
|
||||
read -r -n 1 -p "Press any key to take a 10 second nap: "
|
||||
echo 1>&2
|
||||
./adsleep 10
|
||||
+6
-1
@@ -1427,7 +1427,7 @@ from (`__FILE__`), not `adgrep.c`, as the latter does not exist: `adgrep` is
|
||||
simply a link to `adrian` as `adgrep` is what the program was submitted as but
|
||||
the winner is `adrian.c`.
|
||||
|
||||
Not fixing the above problem would have also cause the program to crash if no
|
||||
Not fixing the above problem would have also caused the program to crash if no
|
||||
arg was specified as the file doesn't exist. In making the above fix, at first
|
||||
the change to check for a `NULL` file was added. Then it was noticed that the
|
||||
problem is that `adgrep.c` was an incorrect reference that never existed and it
|
||||
@@ -1489,6 +1489,11 @@ one must keep the `Y[strlen(Y)-1]='\0';` part and keep it there.
|
||||
These fixes are complex changes due to the way the program and Makefile generate
|
||||
the additional tools.
|
||||
|
||||
Cody finally added the [try.sh](/1992/adrian/try.sh) script that shows the entry
|
||||
and some of the tools this entry generates. Unlike other scripts, it does not
|
||||
clear the screen after compilation so that one can see how the other files are
|
||||
generated.
|
||||
|
||||
|
||||
## <a name="1992_albert"></a>[1992/albert](/1992/albert/albert.c) ([README.md](/1992/albert/README.md]))
|
||||
|
||||
|
||||
Reference in new issue
Block a user