From edbbfedacd963450085a47a1df75aea45e0f1db4 Mon Sep 17 00:00:00 2001
From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com>
Date: Tue, 16 Jan 2024 09:09:19 -0800
Subject: [PATCH] Add 1994/ldb/try.sh
---
1994/ldb/README.md | 6 +-----
1994/ldb/try.sh | 41 +++++++++++++++++++++++++++++++++++++++++
thanks-for-help.md | 17 +++++++++--------
3 files changed, 51 insertions(+), 13 deletions(-)
create mode 100755 1994/ldb/try.sh
diff --git a/1994/ldb/README.md b/1994/ldb/README.md
index 56d903f1b..c1dc4d873 100644
--- a/1994/ldb/README.md
+++ b/1994/ldb/README.md
@@ -28,11 +28,7 @@ some_command | ./ldb
## Try:
```sh
-./ldb < /etc/passwd
-
-printf "The International Obfuscated C Code Contest\n
- Best One-liner\n
- by Laurion Burchall" | ./ldb
+./try.sh
```
diff --git a/1994/ldb/try.sh b/1994/ldb/try.sh
new file mode 100755
index 000000000..e0471b94f
--- /dev/null
+++ b/1994/ldb/try.sh
@@ -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
diff --git a/thanks-for-help.md b/thanks-for-help.md
index 282c8d7a0..b665eea4e 100644
--- a/thanks-for-help.md
+++ b/thanks-for-help.md
@@ -1903,7 +1903,7 @@ entries that actually did not work because of missing or incorrect prototypes).
## [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
-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.
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
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
-and at the same time it's safer (fixing it to not have the extra newline is more
-problematic than it's worth and in macOS another line of output would be shown
-without the change anyway and the difference is that now it's just a blank line
-rather than an annoying warning).
+and at the same time it's safer and allows for parsing file with longer lines.
+Fixing it it to not have the extra newline is more problematic than it's worth,
+in macOS another line of output would be shown without the change anyway -
+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
-program chooses that line it might print the first 231 characters or it might
-print (up to) the next 231 characters and so on.
+Cody also added the [try.sh](/1994/ldb/try.sh) script.
## [1994/schnitzi](/1994/schnitzi/schnitzi.c) ([README.md](/1994/schnitzi/README.md]))