From 4f089535b6431e21c940e4b702f8496f66b85789 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 21 Jan 2024 09:30:53 -0800 Subject: [PATCH] Add 2005/boutines/try.sh --- 2005/boutines/README.md | 25 ++++++++------- 2005/boutines/try.sh | 69 +++++++++++++++++++++++++++++++++++++++++ thanks-for-help.md | 2 ++ 3 files changed, 84 insertions(+), 12 deletions(-) create mode 100755 2005/boutines/try.sh diff --git a/2005/boutines/README.md b/2005/boutines/README.md index 617a11435..d013543a6 100644 --- a/2005/boutines/README.md +++ b/2005/boutines/README.md @@ -7,37 +7,38 @@ make ## To use: -You will need an [SVG](https://www.w3.org/TR/SVG11/expanded-toc.html) viewer. +You will need an [SVG](https://www.w3.org/TR/SVG11/expanded-toc.html) viewer or +a converter like [ImageMagick](https://imagemagick.org/index.php)'s `convert`. + Look here to find some [SVG Viewer Implementations](https://www.w3.org/Graphics/SVG/WG/wiki/Implementations). -The following will create an `SVG` file: - ```sh -ruby -e '20.times{puts "#{rand} #{rand}"}' | ./boutines > test.svg +./boutines < input > output.svg ``` ## Try: ```sh -./boutines < input.txt > result.svg +./try.sh ``` -After running the above commands, use [ImageMagick](https://imagemagick.org/index.php)'s -`convert` tool to convert the images to a png file: +If `ruby` is installed [try.sh](try.sh) will generate an SVG file by: ```sh -convert test.svg test.png - -convert result.svg result.png +ruby -e '20.times{puts "#{rand} #{rand}"}' | ./boutines > test.svg ``` -and then open it with your preferred graphics viewer or editor. +It will also create an SVG file with the file [input.txt](input.txt). + +The script will check if `convert` is available and if so it will try converting +the SVG file(s) to PNG file(s) which you should be able to view in most any +graphics viewer, editor or web browser. If you have a program that opens [SVG](https://www.w3.org/TR/SVG11/expanded-toc.html) files then you could open -the `test.svg` file directly. An example program is +the `test.svg` and `result.svg` files directly. An example program is [Inkscape](https://inkscape.org). See the [list](https://www.w3.org/Graphics/SVG/WG/wiki/Implementations) cited above for others. diff --git a/2005/boutines/try.sh b/2005/boutines/try.sh new file mode 100755 index 000000000..aae39ffbf --- /dev/null +++ b/2005/boutines/try.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2005/boutines +# + +# 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 + +# see if the user has ruby installed +# +RUBY="$(type -P ruby)" + +# see if convert(1) is available (hopefully from ImageMagick :-) ) +# +CONVERT="$(type -P convert)" + +if [[ -n "$RUBY" ]]; then + echo "$ $RUBY -e '20.times{puts \"\#{rand} \#{rand}\"}' | ./boutines > test.svg" 1>&2 + read -r -n 1 -p "Press any key to continue: " + echo 1>&2 + "$RUBY" -e '20.times{puts "#{rand} #{rand}"}' | ./boutines > test.svg +else + echo "ruby not installed, skipping generation of an SVG file via ruby." 1>&2 +fi + +read -r -n 1 -p "Press any key to run: ./boutines < input.txt > result.svg: " +echo 1>&2 +./boutines < input.txt > result.svg +echo 1>&2 + +if [[ ! -f result.svg && ! -f test.svg ]]; then + echo "failed to create any SVG file, exiting." 1>&2 + exit 1 +fi + +if [[ -n "$CONVERT" ]]; then + + read -r -n 1 -p "Press any key to run: convert test.svg test.png: " + echo 1>&2 + if ! convert test.svg test.png; then + echo "Failed to convert test.svg to test.png, try a graphics viewer that" 1>&2 + echo "can view SVG files." 1>&2 + else + echo "Now try viewing test.png with your favourite graphics viewer." 1>&2 + fi + + echo 1>&2 + read -r -n 1 -p "Press any key to run: convert result.svg result.png: " + echo 1>&2 + if ! convert result.svg result.png; then + echo "Failed to convert result.svg to result.png, try a graphics viewer that" 1>&2 + echo "can view SVG files." 1>&2 + else + echo "Now try viewing result.png with your favourite graphics viewer." 1>&2 + fi +else + echo 1>&2 + echo "convert not found (ImageMagick not installed?)" 1>&2 + echo "Try viewing *.svg with a graphics viewer that can view SVG files." 1>&2 +fi diff --git a/thanks-for-help.md b/thanks-for-help.md index b3ef61296..1a3a499f3 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -3196,6 +3196,8 @@ movements. [Cody](#cody) added the [input.txt](/2005/boutines/input.txt) data file based on suggested input from the author, adapting it to a command to try out. +Cody also added the [try.sh](/2005/boutines/try.sh) script. + ## [2005/giljade](/2005/giljade/giljade.c) ([README.md](/2005/giljade/README.md]))