Add 2012/vik/try.sh + format/typo checks

The try.sh script includes the brainfuck feature that the author
implemented.
This commit is contained in:
Cody Boone Ferguson committed 2023-11-29 14:23:08 -08:00
1 parent d7e73b4f38
commit 4750077034
4 files changed
+85 -23

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
mmm-chocolate.png
chocolate-in-ioccc.png
encodedimg.png
ioccc-in-chocolate.png
+19 -23
View File
@@ -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
+63
View File
@@ -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
+2
View File
@@ -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]))