Add 2014/wiedijk/try.sh + formatting/typo checks
The try.sh allows one to override the default indent(1) and sed(1) tools and also verifies that they are executable. This means one can use, for example, bcpp, instead of indent, or if one wants to specify a different path to sed(1) they can. The README.md file explains this more. README.md file format/typo checked. This should complete the review of this entry.
This commit is contained in:
1 parent
bccf3b4cdb
commit
025191d8af
3 files changed
+86
-18
No files matched your search
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.sh - demonstrate IOCCC winner 2014/wiedijk
|
||||
#
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
# Make sure that indent(1) and sed(1) are installed but let user override them
|
||||
# as well say for using a different beautifier. We assume less(1) is installed.
|
||||
|
||||
if [[ -z "$INDENT" ]]; then
|
||||
INDENT="$(type -P indent)"
|
||||
else
|
||||
INDENT="$(type -P "$INDENT")"
|
||||
fi
|
||||
if [[ ! -x "$INDENT" ]]; then
|
||||
echo "$0: cannot find indent, sorry." 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$SED" ]]; then
|
||||
SED="$(type -P sed)"
|
||||
else
|
||||
SED="$(type -P "$SED")"
|
||||
fi
|
||||
if [[ ! -x "$SED" ]]; then
|
||||
echo "$0: cannot find sed, sorry." 1>&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
echo "$ cc -E prog.c | "$INDENT" |
|
||||
"$SED" '1,/5.*prog/d' | less -EXF"
|
||||
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
|
||||
echo 1>&2
|
||||
cc -E prog.c | "$INDENT" | "$SED" '1,/5.*prog/d' | less -EXF
|
||||
Reference in new issue
Block a user