Add 2019/burton/try.sh and other fixes/updates
The try.sh runs prog and wc side by side but in a way that is formatted (including alignment) so it's easier to see what line is from which program and it also runs make test. The script cow was renamed cow.sh to help browsers with whether or not to display or download. The script check was renamed check.sh to help browsers with whether or not to display or download. The script check.sh was fixed in case the 'x' (passed in to the script as an environmental variable) is not executable (it resets it back to ./prog) and also made to satisfy ShellCheck. The script cow.sh was fixed for ShellCheck moo (or was it too? :-) ).
This commit is contained in:
1 parent
ae420f7b32
commit
00b9181b11
12 files changed
+136
-55
No files matched your search
@@ -50,7 +50,7 @@
|
||||
"winners_text" : "original source"
|
||||
},
|
||||
{
|
||||
"file_path" : "check",
|
||||
"file_path" : "check.sh",
|
||||
"winners_rank" : 100,
|
||||
"created_by" : null,
|
||||
"prog" : null,
|
||||
@@ -60,7 +60,7 @@
|
||||
"winners_text" : "test suite"
|
||||
},
|
||||
{
|
||||
"file_path" : "cow",
|
||||
"file_path" : "cow.sh",
|
||||
"winners_rank" : 100,
|
||||
"created_by" : null,
|
||||
"prog" : null,
|
||||
|
||||
@@ -139,12 +139,12 @@ remarks: README.md
|
||||
${RM} -f $@
|
||||
${CP} $? $@
|
||||
|
||||
correct: newlines remarks 256 check
|
||||
env out=${CAT} ${SHELL} ./check ${WC} > $@
|
||||
correct: newlines remarks 256 check.sh
|
||||
env out=${CAT} ${SHELL} ./check.sh ${WC} > $@
|
||||
|
||||
test: ${PROG} ${PROG}.clean correct check
|
||||
-${SHELL} ./check ./${PROG}
|
||||
-${SHELL} ./check ./${PROG}.clean
|
||||
test: ${PROG} ${PROG}.clean correct check.sh
|
||||
-${SHELL} ./check.sh ./${PROG}
|
||||
-${SHELL} ./check.sh ./${PROG}.clean
|
||||
|
||||
# alternative executable
|
||||
#
|
||||
|
||||
+25
-8
@@ -5,17 +5,30 @@ make
|
||||
```
|
||||
|
||||
|
||||
### Bugs and (Mis)features:
|
||||
|
||||
The current status of this entry is:
|
||||
|
||||
```
|
||||
STATUS: INABIAF - please **DO NOT** fix
|
||||
```
|
||||
|
||||
For more detailed information see [2019 burton in bugs.md](/bugs.md#2019-burton).
|
||||
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
./prog < prog.c
|
||||
./prog < file
|
||||
|
||||
./cow file
|
||||
```
|
||||
|
||||
|
||||
### Try:
|
||||
|
||||
```sh
|
||||
echo "Do or do not. There is no try."
|
||||
./try.sh
|
||||
```
|
||||
|
||||
|
||||
@@ -30,7 +43,7 @@ unix utilities available as winning entries.
|
||||
|
||||
### Synopsis:
|
||||
|
||||
Feed it anything on stdin.
|
||||
Feed it anything on `stdin`.
|
||||
The output should look familiar.
|
||||
|
||||
Compiles cleanly with:
|
||||
@@ -44,11 +57,11 @@ cc -Wall -Wextra -Weverything -pedantic $WARN -include stdio.h -o prog prog.c
|
||||
|
||||
Included is a test script, useful for the corner cases. As in all good Unix
|
||||
programs, it is silent upon success; any output demonstrates an error. Instead
|
||||
of checking correctness, the check script can simply output the results: (The
|
||||
Makefile contains the spoiler):
|
||||
of checking correctness, the [check.sh](check.sh) script can simply output the
|
||||
results: (The Makefile contains the spoiler):
|
||||
|
||||
```sh
|
||||
out=cat ./check ./prog
|
||||
out=cat ./check.sh ./prog
|
||||
```
|
||||
|
||||
Interestingly, and a spoiler here: macOS and FreeBSD implement the common
|
||||
@@ -60,20 +73,24 @@ on these systems omit these characters from the description.
|
||||
|
||||
This program follows FreeBSD and macOS, the arbiters of correct for these purposes.
|
||||
|
||||
|
||||
### Limits:
|
||||
|
||||
Requires the C locale and ASCII character set.
|
||||
Input should be less than ten million octets "toavoidthisproblem".
|
||||
|
||||
|
||||
### See Also:
|
||||
|
||||
You can enjoy this code from beginning to end.
|
||||
No whitespace was harmed in the creation of this program.
|
||||
All your base belong to us, but the constants seem a bit ... off?
|
||||
|
||||
|
||||
### Bonus
|
||||
|
||||
The script `cow` provides a closer analog, and perhaps a more useful interface.
|
||||
The script [cow.sh](cow.sh) provides a closer analog, and perhaps a more useful
|
||||
interface.
|
||||
|
||||
Included is a version without compilation warnings:
|
||||
|
||||
@@ -83,7 +100,7 @@ cc -Wall -Wextra -Weverything -pedantic -include stdio.h -o prog.clean prog.clea
|
||||
|
||||
### Bugs
|
||||
|
||||
The flags are not supported. Although they could easily be added into `cow`.
|
||||
The flags are not supported. Although they could easily be added into `cow.sh`.
|
||||
This exercise left to the reader.
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
x=$1
|
||||
: ${x:=./prog}
|
||||
|
||||
: ${out:="diff - correct"}
|
||||
|
||||
(
|
||||
/bin/echo -n | $x
|
||||
$x < /dev/null
|
||||
echo | $x
|
||||
/bin/echo -n a | $x
|
||||
echo a | $x
|
||||
$x < newlines
|
||||
$x < 256
|
||||
$x < remarks
|
||||
) | $out
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
x=$1
|
||||
: "${x:=./prog}"
|
||||
|
||||
if [[ ! -x "$x" ]]; then
|
||||
x="./prog"
|
||||
fi
|
||||
|
||||
: "${out:="diff - correct"}"
|
||||
|
||||
(
|
||||
/bin/echo -n | $x
|
||||
$x < /dev/null
|
||||
echo | $x
|
||||
/bin/echo -n a | $x
|
||||
echo a | $x
|
||||
$x < newlines
|
||||
# ^---^ SC2210 (warning): This is a file redirection. Was it supposed to be a comparison or fd operation?
|
||||
# Answer: 256 is a file so it is supposed to be file redirection.
|
||||
# shellcheck disable=SC2210
|
||||
$x < 256
|
||||
$x < remarks
|
||||
) | $out
|
||||
@@ -1,19 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if test $# -eq 0; then
|
||||
./prog
|
||||
exit 0
|
||||
fi
|
||||
|
||||
args=$*
|
||||
for name in $args
|
||||
do if test -r $name; then
|
||||
s=$(./prog < $name)
|
||||
echo "$s" $name
|
||||
set -- $s
|
||||
((a += $1))
|
||||
((b += $2))
|
||||
((c += $3))
|
||||
((d += 1))
|
||||
fi; done
|
||||
((d > 1)) && printf "%8d%8d%8d total\n" $a $b $c
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if test $# -eq 0; then
|
||||
./prog
|
||||
exit 0
|
||||
fi
|
||||
|
||||
args=$*
|
||||
for name in $args
|
||||
do if test -r "$name"; then
|
||||
s=$(./prog < "$name")
|
||||
echo "$s" "$name"
|
||||
# We have to disable this warning to prevent ShellCheck from being a cow.sh
|
||||
# (or, to use Bart Simpson's advice, make it 'not have a cow.sh'), as we
|
||||
# actually need this to happen:
|
||||
#
|
||||
# ^-- SC2086 (info): Double quote to prevent globbing and word splitting.
|
||||
#
|
||||
# shellcheck disable=SC2086
|
||||
set -- $s
|
||||
((a += $1))
|
||||
((b += $2))
|
||||
((c += $3))
|
||||
((d += 1))
|
||||
fi; done
|
||||
((d > 1)) && printf "%8d%8d%8d total\n" "$a" "$b" "$c"
|
||||
@@ -25,7 +25,7 @@
|
||||
<hr style="width:50%;text-align:left;margin-left:0">
|
||||
|
||||
<!-- Start Nu Html Checker -->
|
||||
<p><a href="https://validator.w3.org/nu/?doc=https%3A%2F%2Fioccc-src.github.io%2Ftemp-test-ioccc%2F2019%2Fburton%2Findex.html">Nu Html check https://ioccc-src.github.io/temp-test-ioccc/2019/burton/index.html</a></p>
|
||||
<p><a href="https://validator.w3.org/nu/?doc=https%3A%2F%2Fioccc-src.github.io%2Ftemp-test-ioccc%2F2019%2Fburton%2Findex.html">Nu Html check.sh https://ioccc-src.github.io/temp-test-ioccc/2019/burton/index.html</a></p>
|
||||
<!-- End Nu Html Checker -->
|
||||
|
||||
</body>
|
||||
|
||||
@@ -219,13 +219,13 @@ href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2019/burton/prog.
|
||||
<tr class="odd">
|
||||
<td style="text-align: left;">test suite</td>
|
||||
<td style="text-align: left;"><a
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2019/burton/check">check</a></td>
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2019/burton/check.sh">check.sh</a></td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td style="text-align: left;">an alternate implementation with a useful
|
||||
interface</td>
|
||||
<td style="text-align: left;"><a
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2019/burton/cow">cow</a></td>
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2019/burton/cow.sh">cow.sh</a></td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td style="text-align: left;">on writing an IOCCC one-liner</td>
|
||||
@@ -276,7 +276,7 @@ href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2019/burton/newli
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h4 id="nu-html-check">Nu HTML check</h4>
|
||||
<h4 id="nu-html-check.sh">Nu HTML check.sh</h4>
|
||||
<p>For web site admin: <a
|
||||
href="https://validator.w3.org/nu/?doc=https%3A%2F%2Fioccc-src.github.io%2Ftemp-test-ioccc%2F2019%2Fburton%2Finventory.html">Check
|
||||
HTML</a></p>
|
||||
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.sh - demonstrate IOCCC winner 2019/burton
|
||||
#
|
||||
|
||||
# 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 "$ cat prog.c" 1>&2
|
||||
cat prog.c
|
||||
echo 1>&2
|
||||
|
||||
for i in prog.c Makefile README.md; do
|
||||
echo "$ ./prog < $i && wc < $i" 1>&2
|
||||
printf "prog: %s\n%4s: %s\n\n" "$(./prog < "$i"|tr -s ' ')" "wc" "$(wc "$i" | tr -s ' ')"
|
||||
done
|
||||
echo 1>&2
|
||||
|
||||
echo "$ make test" 1>&2
|
||||
make test
|
||||
@@ -3267,6 +3267,16 @@ Certain input can crash this program. The file
|
||||
[crash.unl](/2019/adamovsky/crash.unl) is an example file.
|
||||
|
||||
|
||||
## 2019 burton
|
||||
|
||||
### STATUS: INABIAF - please **DO NOT** fix
|
||||
### Source code: [2019/burton/prog.c](2019/burton/prog.c)
|
||||
### Information: [2019/burton/README.md](2019/burton/README.md)
|
||||
|
||||
The author pointed out that some implementations of `wc(1)` show different
|
||||
values but his implementation matches that of macOS and FreeBSD.
|
||||
|
||||
|
||||
## 2019 duble
|
||||
|
||||
### STATUS: INABIAF - please **DO NOT** fix
|
||||
|
||||
@@ -4106,6 +4106,17 @@ to what can crash it - but it's not a bug, it's a feature.
|
||||
[Cody](#cody) fixed the Makefile which had a bad character, a '%' instead of a '$' which
|
||||
caused a rule to fail.
|
||||
|
||||
Cody also added the [try.sh](/2019/burton/try.sh) script which shows a
|
||||
side-by-side comparison on several files of the entry and `wc(1)` as well as
|
||||
running `make test`.
|
||||
|
||||
Cody also fixed the script [check.sh](/2019/burton/check.sh) (renamed from
|
||||
`check`) in case `x` is specified and is not executable and also made it satisfy
|
||||
ShellCheck. He also made ShellCheck not be a cow and/or (to use Bart Simpson's
|
||||
advice :-) ) 'not have a cow' about certain things (including one thing it was
|
||||
wrong about) in [cow.sh](/2019/burton/cow.sh) (which was renamed from `cow`)
|
||||
<strike>moo</strike>too.
|
||||
|
||||
|
||||
## <a name="2019_ciura"></a>[2019/ciura](/2019/ciura/prog.c) ([README.md](/2019/ciura/README.md]))
|
||||
|
||||
|
||||
Reference in new issue
Block a user