diff --git a/2011/goren/MagrittePipe.jpg b/2011/goren/MagrittePipe.jpg new file mode 100644 index 000000000..71bb3ab51 Binary files /dev/null and b/2011/goren/MagrittePipe.jpg differ diff --git a/2011/goren/README.md b/2011/goren/README.md index fa088969c..e61bac7b5 100644 --- a/2011/goren/README.md +++ b/2011/goren/README.md @@ -15,7 +15,7 @@ echo "some text" | ./goren ### Try: ```sh -echo "Hello, world!" | ./goren +./try.sh ``` @@ -23,7 +23,7 @@ echo "Hello, world!" | ./goren In the words of [René François Ghislain Magritte Magritte](http://en.wikipedia.org/wiki/Rene_Magritte): -![This is not a pipe](http://upload.wikimedia.org/wikipedia/en/b/b9/MagrittePipe.jpg "Ceci n'est pas une pipe") +![This is not a pipe](MagrittePipe.jpg "Ceci n'est pas une pipe") One may ask the surrealist question: @@ -65,31 +65,31 @@ stuffing data. One thing I tried to achieve is condition free programming. Many have noted that conditions make the code harder to read and understand. -A good example would be: - -[Brent Burley's 2004 IOCCC winner](/2004/burley/burley.c). +A good example would be: [Brent Burley's 2004 IOCCC +winner](/2004/burley/README.md). That entry omits conditional statements such as `if` and `while`. His achievement in improving clarity by omitting conditions is impressive, but I think it can be taken further, in two ways. -First, conditional operators, such as `?:`, `&&` and `||`, can be thrown -away. Second, using `setjmp` and `longjmp`, which are unfortunately -not in common use, might make it difficult for a novice programmer -to understand the code without referring to the man page. +First, conditional operators, such as `?:`, `&&` and `||`, can be thrown away. +Second, using `setjmp(3)` and `longjmp(3)`, which are unfortunately not in +common use, might make it difficult for a novice programmer to understand the +code without referring to the man page. By removing these, the code is 100% condition free, and every function runs its instructions in perfect order. Naturally, this -makes the program flow trivial to understand. This can be verified +makes the program flow trivial to understand. This can be verified by disassembling the compiled code and looking for conditional jumps (when compiled with gcc on x86, there are none). + ### Compatibility: The program should compile with any C compiler, but was tested mostly with gcc on Linux. -It doesn't support 64 bits (due to integer-pointer casts, and a >>31). +It doesn't support 64 bits (due to integer-pointer casts, and `a >>31`). It does work on 64-bit Linux, because all functions are below 4GB. diff --git a/2011/goren/try.sh b/2011/goren/try.sh new file mode 100755 index 000000000..4d9195141 --- /dev/null +++ b/2011/goren/try.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2011/goren +# + +# 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 + + +read -r -n 1 -p "Press any key to run: echo 'Hello, world!' | ./goren: " +echo "Hello, world!" | ./goren +echo 1>&2 + +read -r -n 1 -p "Press any key to run: echo '|' | ./goren: " +echo '|' | ./goren +echo 1>&2 + +read -r -n 1 -p "Press any key to run: echo '|!|!|' | ./goren: " +echo '|' | ./goren +echo 1>&2 + +read -r -n 1 -p "Press any key to run: echo 'This is a pipe!' | ./goren: " +echo 'This is a pipe!' | ./goren +echo 1>&2 + +read -r -n 1 -p "Press any key to run: echo '| is a pipe!' | ./goren: " +echo '| is a pipe!' | ./goren +echo 1>&2 + diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 47714e507..f31ced6f5 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -3224,7 +3224,9 @@ for 64-bit so it was then tested as a 32-bit binary (linux) and 64-bit binary (linux, macOS) and both work. It was fixed by changing some `int`s to `long`s and now it does work with 64-bit systems as well as 32-bit systems. -Cody added the following words of wisdom: 'this is not a pipe'. +Cody also added the [try.sh](2011/goren/try.sh) script. + +Cody added the following words of wisdom: '"this" is not a pipe but "!" is'. ## [2011/hou](2011/hou/hou.c) ([README.md](2011/hou/README.md]))