Add 2005/boutines/try.sh
This commit is contained in:
1 parent
d5dd94d85a
commit
4f089535b6
3 files changed
+84
-12
No files matched your search
+13
-12
@@ -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.
|
||||
|
||||
Executable
+69
@@ -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
|
||||
Reference in new issue
Block a user