2013-03-03 11:19:50 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
if [ $# -lt 1 ]; then
|
2013-06-25 22:56:10 +02:00
|
|
|
cat<<EOF
|
2013-10-23 10:37:55 +02:00
|
|
|
Usage: ${0##*/} FILE [FLAGS]
|
2013-06-25 22:56:10 +02:00
|
|
|
|
|
|
|
Simulate a C interpreter by compiling, executing and removing file in one run.
|
|
|
|
EOF
|
2013-03-03 11:19:50 +01:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2013-10-23 10:37:55 +02:00
|
|
|
[ -z "$CC" ] && CC=gcc
|
|
|
|
FLAGS="-Wall -Wextra -Wshadow -pthread -lm -g3 -O0"
|
2013-03-03 11:19:50 +01:00
|
|
|
INPUT="$1"
|
|
|
|
|
|
|
|
shift
|
2013-10-23 10:37:55 +02:00
|
|
|
[ $# -ne 0 ] && FLAGS="$@"
|
2013-03-03 11:19:50 +01:00
|
|
|
|
2013-05-31 19:01:32 +02:00
|
|
|
FILE="$(mktemp)"
|
2013-10-23 10:37:55 +02:00
|
|
|
echo "==> $CC \"$INPUT\" -o \"$FILE\" $FLAGS"
|
2013-03-03 11:19:50 +01:00
|
|
|
|
2013-10-23 10:37:55 +02:00
|
|
|
## Zsh compatibility. We need it otherwise word splitting of parameter will not
|
|
|
|
## work.
|
2014-01-04 10:37:47 +01:00
|
|
|
STATUS="$(set -o | awk '/shwordsplit / {print $2}')"
|
2013-03-03 11:19:50 +01:00
|
|
|
[ "$STATUS" = "off" ] && set -o shwordsplit
|
|
|
|
|
2013-10-23 10:37:55 +02:00
|
|
|
$CC "$INPUT" -o "$FILE" $FLAGS
|
2013-03-03 11:19:50 +01:00
|
|
|
|
|
|
|
## Restore Zsh previous options. This will not turn off shwordsplit if it
|
|
|
|
## was on before calling the function.
|
|
|
|
[ "$STATUS" = "off" ] && set +o shwordsplit
|
|
|
|
|
|
|
|
echo "==> $FILE"
|
|
|
|
"$FILE"
|
|
|
|
rm "$FILE"
|