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.
This commit is contained in:
Cody Boone Ferguson committed 2023-11-13 08:33:08 -08:00
1 parent aa1427f18e
commit d742eb23e7
3 files changed
+60 -3

No files matched your search

+15 -3
View File
@@ -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:
+38
View File
@@ -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