From d742eb23e788564876482a577d932eef22fa3184 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Mon, 13 Nov 2023 08:31:47 -0800 Subject: [PATCH] Add 1998/bas2/try.sh + format/typo check README.md The try.sh allows one to pass in args: if a readable regular file it will be fed to the program and otherwise it'll act as if it's a string. It also has some additional commands that I thought might be fun to show the entry. Format/typo check README.md file. --- 1998/bas2/README.md | 18 +++++++++++++++--- 1998/bas2/try.sh | 38 ++++++++++++++++++++++++++++++++++++++ thanks-for-fixes.md | 7 +++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100755 1998/bas2/try.sh diff --git a/1998/bas2/README.md b/1998/bas2/README.md index 91f0ccf0b..f960fca5a 100644 --- a/1998/bas2/README.md +++ b/1998/bas2/README.md @@ -8,12 +8,23 @@ make all ## To use: ```sh -./bas2 < bas2.c +./bas2 < file +echo text | ./bas2 +``` + + +## Try: + +```sh +./try.sh + +./try.sh "foo bar" "baz" "IOCCC 1998/bas2" README.md ``` ## Judges' remarks: + ### Questions to ponder: Can you determine the relationship between the input and the resulting numeric @@ -22,6 +33,7 @@ output? The program was not designed to process files with a certain octet value, what value is that? + ### Hint and Extra Credit: This entry points out a minor flaw in the IOCCC rules that has @@ -40,10 +52,10 @@ done by matching the bit patterns. Minor obfuscations are: - Useless variable names. -- Recursive main() instead of 2 loops (over input characters and over bits in +- Recursive `main()` instead of 2 loops (over input characters and over bits in the character). -- `?` and `||` instead of if statements. +- `?:` and `||` instead of if statements. ## Copyright and CC BY-SA 4.0 License: diff --git a/1998/bas2/try.sh b/1998/bas2/try.sh new file mode 100755 index 000000000..08a76ae35 --- /dev/null +++ b/1998/bas2/try.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate 1998/bas2 +# +# If any args are specified it checks if it's a readable file and if it is it +# feeds it to the program. If not it assumes it's a string and feeds that to the +# program. +# + +make all || exit 1 + +echo "$ ./bas2 < bas2.c" 1>&2 +./bas2 < bas2.c + +echo "$ ./bas2 < README.md" 1>&2 +./bas2 < README.md + +echo "$ ./bas2 < Makefile" 1>&2 +./bas2 < Makefile + +echo "$ echo foo bar baz | ./bas2" 1>&2 +echo foo bar baz | ./bas2 + +echo "$ cat README.md Makefile bas2.c | ./bas2" 1>&2 +cat README.md Makefile bas2.c | ./bas2 + +# while we have an arg check if it's a file. If it is a regular file that is +# readable feed it to the program; otherwise act as if it's a string. +while [[ "$#" -gt 0 ]]; do + if [[ -f "$1" && -r "$1" ]]; then + echo "$ ./bas2 < $1" 1>&2 + ./bas2 < "$1" + else + echo "$ echo $1 | ./bas2" 1>&2 + echo "$1" | ./bas2 + fi + shift 1 +done diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index d48f0025b..ca6e039e4 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -2042,6 +2042,12 @@ they do have page up and page down but this gives a default for those who don't have them like with Macs. +## [1998/bas2](1998/bas2/bas2.c) ([README.md](1998/bas2/README.md])) + +Cody added the [try.sh](1998/bas2/try.sh) script which runs some default actions +as well as allowing one to pass in different file names or strings. + + ## [1998/chaos](1998/chaos/chaos.c) ([README.md](1998/chaos/README.md])) Cody added a call to `endwin()` to restore terminal sanity (echo etc.) when @@ -2059,6 +2065,7 @@ by changing the typedef `lint` (to `int` - see the code for why this has to be done in modern systems) to be `_int`. +## [1998/dlowe](1998/dlowe/dlowe.c) ([README.md](1998/dlowe/README.md])) ## [1998/dlowe](1998/dlowe/dlowe.c) ([README.md](1998/dlowe/README.md])) Cody made the program more portable by changing the void return type of `main()`