Merge pull request #1917 from xexyl/esde95-try
Improve 1995/esde/try.sh
This commit is contained in:
12 files changed
+198
-31
No files matched your search
@@ -31,7 +31,7 @@ For more detailed information see [1994 dodsond2 in bugs.md](/bugs.md#1994-dodso
|
|||||||
## Alternate code:
|
## Alternate code:
|
||||||
|
|
||||||
This version allows you to choose how many arrows to start with, instead of the
|
This version allows you to choose how many arrows to start with, instead of the
|
||||||
default 0. If one tried specifying a value < 0 it will set it to 0.
|
default 0. If one tries specifying a value < 0 it will set it to 0.
|
||||||
|
|
||||||
Fun fact: this version helped uncover and fix a bug that prevented the entry
|
Fun fact: this version helped uncover and fix a bug that prevented the entry
|
||||||
from working in some cases.
|
from working in some cases.
|
||||||
|
|||||||
+1
-5
@@ -28,11 +28,7 @@ some_command | ./ldb
|
|||||||
## Try:
|
## Try:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./ldb < /etc/passwd
|
./try.sh
|
||||||
|
|
||||||
printf "The International Obfuscated C Code Contest\n
|
|
||||||
Best One-liner\n
|
|
||||||
by Laurion Burchall" | ./ldb
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Executable
+41
@@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# try.sh - demonstrate IOCCC winner 1994/ldb
|
||||||
|
#
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
ldb_file()
|
||||||
|
{
|
||||||
|
if [[ "$#" != 1 ]]; then
|
||||||
|
echo "$0: ldb_file() expects 1 arg, got $#" 1>&2
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
read -r -n 1 -p "Press any key to run: ./ldb < $1: "
|
||||||
|
echo 1>&2
|
||||||
|
./ldb < "$1" | sed '/^$/d'
|
||||||
|
echo 1>&2
|
||||||
|
}
|
||||||
|
|
||||||
|
ldb_ioccc()
|
||||||
|
{
|
||||||
|
echo "$ printf \"The International Obfuscated C Code Contest\\nBest One-liner\\nby Laurion Burchall\" | ./ldb"
|
||||||
|
read -r -n 1 -p "Press any key to continue: "
|
||||||
|
echo 1>&2
|
||||||
|
printf "The International Obfuscated C Code Contest\nBest One-liner\nby Laurion Burchall" | ./ldb | sed '/^$/d'
|
||||||
|
echo 1>&2
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in $(seq 1 5); do
|
||||||
|
ldb_file /etc/passwd
|
||||||
|
ldb_ioccc
|
||||||
|
ldb_file ldb.c
|
||||||
|
ldb_file README.md
|
||||||
|
done
|
||||||
@@ -8,6 +8,11 @@ prog.orig
|
|||||||
schnitzi
|
schnitzi
|
||||||
schnitzi2
|
schnitzi2
|
||||||
schnitzi2.c
|
schnitzi2.c
|
||||||
|
schnitzi3
|
||||||
|
schnitzi3.c
|
||||||
schnitzi.alt
|
schnitzi.alt
|
||||||
schnitzi.alt2
|
schnitzi.alt2
|
||||||
schnitzi.orig
|
schnitzi.orig
|
||||||
|
try1.txt
|
||||||
|
try2.txt
|
||||||
|
try3.txt
|
||||||
@@ -39,7 +39,7 @@ include ../../var.mk
|
|||||||
# Common C compiler warnings to silence
|
# Common C compiler warnings to silence
|
||||||
#
|
#
|
||||||
CSILENCE= -Wno-deprecated-declarations -Wno-error -Wno-implicit-function-declaration \
|
CSILENCE= -Wno-deprecated-declarations -Wno-error -Wno-implicit-function-declaration \
|
||||||
-Wno-strict-prototypes
|
-Wno-strict-prototypes -Wno-implicit-int
|
||||||
|
|
||||||
# Common C compiler warning flags
|
# Common C compiler warning flags
|
||||||
#
|
#
|
||||||
|
|||||||
+13
-8
@@ -31,12 +31,7 @@ For more detailed information see [1994 schnitzi in bugs.md](/bugs.md#1994-schni
|
|||||||
## Try:
|
## Try:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./schnitzi < /etc/motd 2>/dev/null
|
./try.sh
|
||||||
./schnitzi < /etc/passwd 2>/dev/null
|
|
||||||
|
|
||||||
./schnitzi < schnitzi.c > schnitzi2.c 2>/dev/null
|
|
||||||
make schnitzi2
|
|
||||||
./schnitzi2 < README.md
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -65,6 +60,13 @@ Use `schnitzi.alt` and `schnitzi.alt2` as you would `schnitzi` above except that
|
|||||||
feeding the source code to it will not work right.
|
feeding the source code to it will not work right.
|
||||||
|
|
||||||
|
|
||||||
|
### Alternate try:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./try.alt.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Judges' remarks:
|
## Judges' remarks:
|
||||||
|
|
||||||
Try:
|
Try:
|
||||||
@@ -77,6 +79,9 @@ Compare the output of the program with its source. Sure the output
|
|||||||
is different, but there is more than meets the `diff`'s eye. Can you
|
is different, but there is more than meets the `diff`'s eye. Can you
|
||||||
find out why?
|
find out why?
|
||||||
|
|
||||||
|
You might also wish to redirect the output to another file,
|
||||||
|
compile it and compare how it works to the original code.
|
||||||
|
|
||||||
|
|
||||||
## Author's remarks:
|
## Author's remarks:
|
||||||
|
|
||||||
@@ -92,14 +97,14 @@ line; for instance, for the file 'info', the program
|
|||||||
would be run as follows:
|
would be run as follows:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
schnitzi < info
|
./schnitzi < info
|
||||||
```
|
```
|
||||||
|
|
||||||
The program generates interesting results when its source file is
|
The program generates interesting results when its source file is
|
||||||
used as input:
|
used as input:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
schnitzi < schnitzi.c
|
./schnitzi < schnitzi.c
|
||||||
```
|
```
|
||||||
|
|
||||||
The result of this command is a program which does the exact same
|
The result of this command is a program which does the exact same
|
||||||
|
|||||||
Executable
+30
@@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# try.alt.sh - demonstrate IOCCC winner 1994/schnitzi alt code
|
||||||
|
#
|
||||||
|
|
||||||
|
# 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" alt >/dev/null || exit 1
|
||||||
|
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: ./schnitzi.alt < README.md (space = next page, q = quit): "
|
||||||
|
echo 1>&2
|
||||||
|
./schnitzi.alt < README.md | less -rEXF
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
echo "$ ./schnitzi.alt2 < schnitzi.alt2.c | diff - schnitzi.c" 1>&2
|
||||||
|
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
|
||||||
|
echo 1>&2
|
||||||
|
./schnitzi.alt2 < schnitzi.alt2.c | diff - schnitzi.c
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: ./schnitzi.alt2 < README.md (space = next page, q = quit): "
|
||||||
|
echo 1>&2
|
||||||
|
./schnitzi.alt2 < README.md
|
||||||
|
echo 1>&2
|
||||||
Executable
+66
@@ -0,0 +1,66 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# try.sh - demonstrate IOCCC winner 1994/schnitzi
|
||||||
|
#
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: ./schnitzi < schnitzi.c > schnitzi2.c: "
|
||||||
|
echo 1>&2
|
||||||
|
./schnitzi < schnitzi.c > schnitzi2.c 2>/dev/null
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: make schnitzi2: "
|
||||||
|
echo 1>&2
|
||||||
|
make schnitzi2
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: ./schnitzi2 < schnitzi2.c > schnitzi3.c: "
|
||||||
|
echo 1>&2
|
||||||
|
./schnitzi2 < schnitzi2.c > schnitzi3.c 2>/dev/null
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: make schnitzi3: "
|
||||||
|
echo 1>&2
|
||||||
|
make schnitzi3
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: diff3 schnitzi.c schnitzi2.c schnitzi3.c (space = next page, q = quit): "
|
||||||
|
echo 1>&2
|
||||||
|
diff3 schnitzi.c schnitzi2.c schnitzi3.c | less -rEXF
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to show try.txt: "
|
||||||
|
echo 1>&2
|
||||||
|
cat try.txt
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
rm -f try1.txt try2.txt try3.txt
|
||||||
|
read -r -n 1 -p "Press any key to run: ./schnitzi < try.txt | tee try1.txt (space = next page, q = quit): "
|
||||||
|
echo 1>&2
|
||||||
|
./schnitzi < try.txt 2>/dev/null | tee try1.txt
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: ./schnitzi2 < try.txt | tee try2.txt (space = next page, q = quit): "
|
||||||
|
echo 1>&2
|
||||||
|
./schnitzi2 < try.txt 2>/dev/null | tee try2.txt
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: ./schnitzi3 < try.txt | tee try3.txt (space = next page, q = quit): "
|
||||||
|
echo 1>&2
|
||||||
|
./schnitzi3 < try.txt 2>/dev/null | tee try3.txt
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: diff3 try1.txt try2.txt try3.txt: "
|
||||||
|
echo 1>&2
|
||||||
|
diff3 try1.txt try2.txt try3.txt && echo "All three files are the same!"
|
||||||
|
echo 1>&2
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
1994/schnitzi IOCCC winner test file.
|
||||||
@@ -17,8 +17,12 @@ make CC="$CC" all >/dev/null || exit 1
|
|||||||
# clear screen after compilation so that only the entry is shown
|
# clear screen after compilation so that only the entry is shown
|
||||||
clear
|
clear
|
||||||
|
|
||||||
echo "$ cat try.this.txt"
|
read -r -n 1 -p "Press any key to show try.this.txt: "
|
||||||
|
echo 1>&2
|
||||||
cat try.this.txt
|
cat try.this.txt
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
echo "$ ./dodsond1 < try.this.txt"
|
read -r -n 1 -p "Press any key to run: ./dodsond1 < try.this.txt: "
|
||||||
|
echo 1>&2
|
||||||
./dodsond1 < try.this.txt
|
./dodsond1 < try.this.txt
|
||||||
|
echo 1>&2
|
||||||
+19
-5
@@ -15,13 +15,27 @@ make CC="$CC" all >/dev/null || exit 1
|
|||||||
# clear screen after compilation so that only the entry is shown
|
# clear screen after compilation so that only the entry is shown
|
||||||
clear
|
clear
|
||||||
|
|
||||||
echo "$ ./esde esde.data Johanson"
|
read -r -n 1 -p "Press any key to show esde.data: "
|
||||||
|
echo 1>&2
|
||||||
|
cat esde.data
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: ./esde esde.data Johanson: "
|
||||||
|
echo 1>&2
|
||||||
./esde esde.data Johanson
|
./esde esde.data Johanson
|
||||||
echo
|
echo 1>&2
|
||||||
|
|
||||||
echo "$ ./esde esde.data2 read"
|
read -r -n 1 -p "Press any key to show esde.data2: "
|
||||||
|
echo 1>&2
|
||||||
|
cat esde.data2
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: ./esde esde.data2 read: "
|
||||||
|
echo 1>&2
|
||||||
./esde esde.data2 read
|
./esde esde.data2 read
|
||||||
echo
|
echo 1>&2
|
||||||
|
|
||||||
echo "$ ./esde README.md date"
|
read -r -n 1 -p "Press any key to run: ./esde README.md date: "
|
||||||
|
echo 1>&2
|
||||||
./esde README.md date
|
./esde README.md date
|
||||||
|
echo 1>&2
|
||||||
+14
-9
@@ -1903,7 +1903,7 @@ entries that actually did not work because of missing or incorrect prototypes).
|
|||||||
## <a name="1994_ldb"></a>[1994/ldb](/1994/ldb/ldb.c) ([README.md](/1994/ldb/README.md]))
|
## <a name="1994_ldb"></a>[1994/ldb](/1994/ldb/ldb.c) ([README.md](/1994/ldb/README.md]))
|
||||||
|
|
||||||
[Cody](#cody) fixed this so it would compile and work with modern compilers. The problem
|
[Cody](#cody) fixed this so it would compile and work with modern compilers. The problem
|
||||||
was that `srand()` returns void but it was used in a `||` expression. Thus the
|
was that `srand()` returns `void` but it was used in a `||` expression. Thus the
|
||||||
comma operator was needed.
|
comma operator was needed.
|
||||||
|
|
||||||
Cody also fixed it for clang under Linux which objected to incompatible pointer
|
Cody also fixed it for clang under Linux which objected to incompatible pointer
|
||||||
@@ -1913,14 +1913,15 @@ but what was being passed to it is an `int`).
|
|||||||
Cody also changed the entry to use `fgets(3)` instead of `gets(3)`. This one has
|
Cody also changed the entry to use `fgets(3)` instead of `gets(3)`. This one has
|
||||||
a minor annoyance in that it now prints a newline after the output but this
|
a minor annoyance in that it now prints a newline after the output but this
|
||||||
seems like a worthy compromise for preventing the interspersed output in macOS
|
seems like a worthy compromise for preventing the interspersed output in macOS
|
||||||
and at the same time it's safer (fixing it to not have the extra newline is more
|
and at the same time it's safer and allows for parsing file with longer lines.
|
||||||
problematic than it's worth and in macOS another line of output would be shown
|
Fixing it it to not have the extra newline is more problematic than it's worth,
|
||||||
without the change anyway and the difference is that now it's just a blank line
|
in macOS another line of output would be shown without the change anyway -
|
||||||
rather than an annoying warning).
|
unless `2>/dev/null` - and the difference is that now it's just a blank line
|
||||||
|
rather than an annoying warning. A subtlety about this fix: if a line is greater
|
||||||
|
than 231 in length if the program chooses that line it might print the first 231
|
||||||
|
characters or it might print (up to) the next 231 characters and so on.
|
||||||
|
|
||||||
A subtlety about this fix: if a line is greater than 231 in length if the
|
Cody also added the [try.sh](/1994/ldb/try.sh) script.
|
||||||
program chooses that line it might print the first 231 characters or it might
|
|
||||||
print (up to) the next 231 characters and so on.
|
|
||||||
|
|
||||||
|
|
||||||
## <a name="1994_schnitzi"></a>[1994/schnitzi](/1994/schnitzi/schnitzi.c) ([README.md](/1994/schnitzi/README.md]))
|
## <a name="1994_schnitzi"></a>[1994/schnitzi](/1994/schnitzi/schnitzi.c) ([README.md](/1994/schnitzi/README.md]))
|
||||||
@@ -1935,11 +1936,15 @@ bugs.md](/bugs.md#1994-schnitzi).
|
|||||||
|
|
||||||
The purpose for these versions it both demonstrate how the magic works behind it
|
The purpose for these versions it both demonstrate how the magic works behind it
|
||||||
and to help others, should they wish, get the code to work with `fgets(3)`, with
|
and to help others, should they wish, get the code to work with `fgets(3)`, with
|
||||||
or without an increase in buffer size. See [1994/schnitzi in
|
or without an increase in buffer size. Note that without this feeding longer
|
||||||
|
files, say the README.md file, will crash the program. See [1994/schnitzi in
|
||||||
bugs.md](/bugs.md#1994-schnitzi) where Cody also explains the magic for more
|
bugs.md](/bugs.md#1994-schnitzi) where Cody also explains the magic for more
|
||||||
details. Later on, if nobody takes up the task, Cody might resume it, but for
|
details. Later on, if nobody takes up the task, Cody might resume it, but for
|
||||||
now there is more important work to do so that the next contest can run.
|
now there is more important work to do so that the next contest can run.
|
||||||
|
|
||||||
|
Cody also added the [try.sh](/1994/schnitzi/try.sh) and
|
||||||
|
[try.alt.sh](/1994/schnitzi/try.alt.sh) scripts.
|
||||||
|
|
||||||
|
|
||||||
## <a name="1994_shapiro"></a>[1994/shapiro](/1994/shapiro/shapiro.c) ([README.md](/1994/shapiro/README.md]))
|
## <a name="1994_shapiro"></a>[1994/shapiro](/1994/shapiro/shapiro.c) ([README.md](/1994/shapiro/README.md]))
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user