From 47500770345a7bbe927522d49f5707d1553a82d0 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Wed, 29 Nov 2023 14:22:09 -0800 Subject: [PATCH] Add 2012/vik/try.sh + format/typo checks The try.sh script includes the brainfuck feature that the author implemented. --- 2012/vik/.gitignore | 1 + 2012/vik/README.md | 42 ++++++++++++++---------------- 2012/vik/try.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++ thanks-for-fixes.md | 2 ++ 4 files changed, 85 insertions(+), 23 deletions(-) create mode 100755 2012/vik/try.sh diff --git a/2012/vik/.gitignore b/2012/vik/.gitignore index ab94f510a..94929532f 100644 --- a/2012/vik/.gitignore +++ b/2012/vik/.gitignore @@ -1,3 +1,4 @@ +mmm-chocolate.png chocolate-in-ioccc.png encodedimg.png ioccc-in-chocolate.png diff --git a/2012/vik/README.md b/2012/vik/README.md index e2e3ec7a6..feaae0aad 100644 --- a/2012/vik/README.md +++ b/2012/vik/README.md @@ -6,6 +6,9 @@ make This entry requires [Zlib](https://www.zlib.net). +There is an alternate version which might work for Windows. See [Alternate +code](#alternate-code) section below. + ### Bugs and (Mis)features: @@ -50,40 +53,28 @@ To extract the embedded PNG: ./vik d encodedimg.png > restored.png ``` -There is an alternate version which might work for Windows. See Alternate code -section below. - -The author stated that the program will crash if no argument is passed to the -program or if invalid arguments or images of mismatching sizes or unsupported -pixel formats though we note that your computer might also [halt and catch -fire](https://en.wikipedia.org/wiki/Halt_and_Catch_Fire_(computing)) :-) - -This is supposed to happen. As is written in the -[The Jargon File](http://catb.org/jargon/html/F/feature.html): - -``` -That's not a bug, that's a feature. -``` - ### Try: ```sh -./vik e ioccc.png chocolate.png > chocolate-in-ioccc.png -./vik e chocolate.png ioccc.png > ioccc-in-chocolate.png -./vik d chocolate-in-ioccc.png > restored-chocolate.png -./vik d ioccc-in-chocolate.png > restored-ioccc.png +./try.sh ``` ## Alternate code: -For those few who might use Windows, To compile: +For those few who might use Windows this alternate code might work. + + +### Alternate build: ```sh make alt ``` + +### Alternate use: + Use `vik.alt` as you would `vik` above. @@ -114,6 +105,7 @@ one image into another, the width and height needs to be the same. The program only updates the `IDAT` and `IHDR` chunks of the source image. Any additional chunks are copied into the resulting image. + ### Bonus Extractor: For some reason the chocolate image seems to have some special properties. @@ -146,15 +138,16 @@ or helper methods that can be confusing, I placed all functionality in the gives the benefit that all invocations of the function have the same parameters, `argv` and `argc`. This really helps readability, as a programmer doesn't need to remember several variable or function names. I also tried to reduce the -number of keywords, and the program only has four for-loops followed by a single -return statement. There is a little bit of use of the ternary (`?:`) operator, +number of keywords, and the program only has four `for` loops followed by a single +`return` statement. There is a little bit of use of the ternary (`?:`) operator, but this is really there to keep the program as simple as possible. + ### Portability The program is portable to most platforms that have [zlib](https://www.zlib.net) available. The only system dependency is that the program relies on writing -binary data to stdout. +binary data to `stdout`. By default, Microsoft compilers adds carriage returns to new lines, and to compile the program on this platform, the following line can be added after @@ -165,6 +158,9 @@ correctly: _setmode(_fileno(stdout), 0x8000); ``` +NOTE: this is what the [Alternate code](#alternate-code) does. + + ### Limitations The program doesn't have many error checks so passing in invalid arguments diff --git a/2012/vik/try.sh b/2012/vik/try.sh new file mode 100755 index 000000000..deb29e9fb --- /dev/null +++ b/2012/vik/try.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2012/vik +# + +# 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 embed chocolate in chocolate-in-ioccc.png: " +echo 1>&2 +echo "$ ./vik e chocolate-in-ioccc.png \"Mmm... chocolate.\" > mmm-chocolate.png" 1>&2 +./vik e chocolate-in-ioccc.png "Mmm... chocolate." > mmm-chocolate.png +echo 1>&2 + +read -r -n 1 -p "Press any key to extract chocolate from mmm-chocolate.png: " +echo 1>&2 +echo "$ ./vik d mmm-chocolate.png" 1>&2 +./vik d mmm-chocolate.png +echo 1>&2 + +read -r -n 1 -p "Press any key to embed chocolate.png in ioccc.png: " +echo 1>&2 +echo "$ ./vik e ioccc.png chocolate.png > chocolate-in-ioccc.png" 1>&2 +./vik e ioccc.png chocolate.png > chocolate-in-ioccc.png +echo 1>&2 + +read -r -n 1 -p "Press any key to embed ioccc.png in chocolate.png: " +echo 1>&2 +echo "$ ./vik e chocolate.png ioccc.png > ioccc-in-chocolate.png" +./vik e chocolate.png ioccc.png > ioccc-in-chocolate.png +echo 1>&2 + +read -r -n 1 -p "Press any key to embed a brainfuck program as a text file and decode it: " +echo 1>&2 +echo "$ ./vik e ioccc.png .+[.+] > encodedimg.png" 1>&2 +./vik e ioccc.png .+[.+] > encodedimg.png +echo "$ ./vik b encodedimg.png" 1>&2 +./vik b encodedimg.png +echo 1>&2 + +read -r -n 1 -p "Press any key to extract chocolate from chocolate-in-ioccc.png: " +echo 1>&2 +echo "$ ./vik d chocolate-in-ioccc.png > restored-chocolate.png" 1>&2 +./vik d chocolate-in-ioccc.png > restored-chocolate.png +echo 1>&2 +echo "Make sure to open restored-chocolate.png in your graphics viewer of choice!" 1>&2 + +read -r -n 1 -p "Press any key to extract ioccc from ioccc-in-chocolate.png: " +echo 1>&2 +echo "$ ./vik d ioccc-in-chocolate.png > restored-ioccc.png" 1>&2 +./vik d ioccc-in-chocolate.png > restored-ioccc.png +echo "Now make sure to open restored-ioccc.png in your graphics viewer of choice!" 1>&2 + +exit 0 diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 14b319b57..7d29d9b85 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -3386,6 +3386,8 @@ this for the few who might use Windows. We're not sure whether we want to thank Cody or not for this :-) and he's not sure if he wants to be thanked either :-) but we appreciate it nonetheless. +Cody also added the [try.sh](2012/vik/try.sh) script. + ## [2012/zeitak](2012/zeitak/zeitak.c) ([README.md](2012/zeitak/README.md]))