From be64048e3d125eb0bf1e1e0c378868bf46fd7912 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Thu, 16 Nov 2023 09:09:41 -0800 Subject: [PATCH] Add 2001/schweikh/try.sh + format/typo checks --- 2001/schweikh/README.md | 16 +++++++--------- 2001/schweikh/try.sh | 25 +++++++++++++++++++++++++ thanks-for-fixes.md | 2 ++ 3 files changed, 34 insertions(+), 9 deletions(-) create mode 100755 2001/schweikh/try.sh diff --git a/2001/schweikh/README.md b/2001/schweikh/README.md index c1ded11e7..46eb53afe 100644 --- a/2001/schweikh/README.md +++ b/2001/schweikh/README.md @@ -41,9 +41,7 @@ That's not a bug, that's a feature. ### Try: ```sh -./schweikh foo 'f??'; echo $? -./schweikh 'best short program' '??st*o**p?*'; echo $? -./schweikh bar 'f??'; echo $? +./try.sh ``` @@ -64,7 +62,7 @@ the whole string, so you may want to use `*` at the beginning and end of the pattern if you are looking for something in the middle. You can use it for your shell scripting needs similar to a silent grep -(and without stdout redirected to `/dev/null`): +(and without `stdout` redirected to `/dev/null`): ```sh if prog "${VARIABLE}" ''; then @@ -83,15 +81,15 @@ All obfuscation is obviously in the recursive `m()` function, an 86 character glob pattern evaluator, returning nonzero for a match: * Just a single complex return expression. -* Nested ternary operator `?:` to save on if/else verbosity. -* Short circuiting `&&` and `||` to save even more on if/else verbosity. +* Nested ternary operator `?:` to save on `if`/`else` verbosity. +* Short circuiting `&&` and `||` to save even more on `if`/`else` verbosity. * Subtraction instead of an equality operator in `*t - 42`. * ASCII codes for `*` and `?`. * Careful use of blanks even though this year's rules have extended that resource limit. * The source is a complete preprocessed C program. Because it communicates - with the world out there by means of argv and the exit status, there - is no need for stdio bloat. An asm guru could surely squeeze this + with the world out there by means of `argv` and the exit status, there + is no need for `stdio.h` bloat. An asm guru could surely squeeze this program in less than a screenful. * `indent(1)` is probably not too helpful. @@ -101,7 +99,7 @@ backtracking. I could tell you how it works but then I would have to inputs, it will be quite helpful and instructive. Handling of `?` is straightforward; for `*` start out with `*foo` and `foo*` against `foo`. How does it deal with sequences of adjacent `*`? How could this be -improved? If all else fails, recode the `?:` operators with if/else and +improved? If all else fails, recode the `?:` operators with `if`/`else` and try again. For extra credit implement character classes like `[a-z]`. diff --git a/2001/schweikh/try.sh b/2001/schweikh/try.sh new file mode 100755 index 000000000..31366963e --- /dev/null +++ b/2001/schweikh/try.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2001/schweikh +# + +# 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 + +# clear screen after compilation so that only the entry is shown +clear + +echo "$ ./schweikh foo 'f??'; echo \$?" 1>&2 +./schweikh foo 'f??'; echo $? + +echo "$ ./schweikh 'best short program' '??st*o**p?*'; echo \$?" 1>&2 +./schweikh 'best short program' '??st*o**p?*'; echo $? + +echo "$ ./schweikh bar 'f??'; echo \$?" 1>&2 +./schweikh bar 'f??'; echo $? diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 0072ae680..6fd3ef875 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -2587,6 +2587,8 @@ Cody fixed this to not crash if not enough args as this was not documented by the author. The other problems are documented so were not fixed. See README.md for details. +Cody also added the [try.sh](2001/schweikh/try.sh) script. + ## [2001/westley](2001/westley/westley.c) ([README.md](2001/westley/README.md]))