Add 1994/ldb/try.sh
This commit is contained in:
1 parent
3e2287f5ec
commit
edbbfedacd
3 files changed
+51
-13
No files matched your search
+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
|
||||||
+9
-8
@@ -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]))
|
||||||
|
|||||||
Reference in new issue
Block a user