fix bash compatibility and remove non-standard echo
This commit is contained in:
parent
093b490ce0
commit
075173185d
24
cscript
24
cscript
@ -18,13 +18,13 @@ at_args=""
|
|||||||
args=""
|
args=""
|
||||||
arg() {
|
arg() {
|
||||||
if [ -z "$shebang_mode" ] && [ -n "$at_args" ]; then
|
if [ -z "$shebang_mode" ] && [ -n "$at_args" ]; then
|
||||||
args="$args\n$1"
|
args="$(printf "%s\n%s" "$args" "$1")"
|
||||||
elif [ "$shebang_mode" = "next_is_file" ]; then
|
elif [ "$shebang_mode" = "next_is_file" ]; then
|
||||||
basedir="$(dirname "$1")"
|
basedir="$(dirname "$1")"
|
||||||
files="$files\n$(basename "$1")"
|
files="$(printf "%s\n%s" "$files" "$(basename "$1")")"
|
||||||
shebang_mode=1
|
shebang_mode=1
|
||||||
elif [ -n "$shebang_mode" ]; then
|
elif [ -n "$shebang_mode" ]; then
|
||||||
args="$args\n$1"
|
args="$(printf "%s\n%s" "$args" "$1")"
|
||||||
else
|
else
|
||||||
case "$1" in
|
case "$1" in
|
||||||
# Pass through following args
|
# Pass through following args
|
||||||
@ -41,11 +41,11 @@ arg() {
|
|||||||
;;
|
;;
|
||||||
# Add option
|
# Add option
|
||||||
-*)
|
-*)
|
||||||
opts="$opts\n$1"
|
opts="$(printf "%s\n%s" "$opts" "$1")"
|
||||||
;;
|
;;
|
||||||
# Add source file
|
# Add source file
|
||||||
*)
|
*)
|
||||||
files="$files\n$1"
|
files="$(printf "%s\n%s" "$files" "$1")"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
@ -54,9 +54,9 @@ for a in "$@"; do
|
|||||||
arg "$a"
|
arg "$a"
|
||||||
done
|
done
|
||||||
# Remove empty lines
|
# Remove empty lines
|
||||||
files="$(echo -n "$files" | grep '.')"
|
files="$(printf "%s" "$files" | grep '.')"
|
||||||
opts="$(echo -n "$opts" | grep '.')"
|
opts="$(printf "%s" "$opts" | grep '.')"
|
||||||
args="$(echo -n "$args" | grep '.')"
|
args="$(printf "%s" "$args" | grep '.')"
|
||||||
|
|
||||||
cd "$basedir"
|
cd "$basedir"
|
||||||
|
|
||||||
@ -72,16 +72,16 @@ EOF
|
|||||||
|
|
||||||
# Compile and run C program
|
# Compile and run C program
|
||||||
cleanup() {
|
cleanup() {
|
||||||
echo -n "$files" | xargs -d'\n' sed "s@^//#!@#!@g" -i
|
printf "%s" "$files" | xargs -d'\n' sed "s@^//#!@#!@g" -i
|
||||||
rm -f "$tmpfile"
|
rm -f "$tmpfile"
|
||||||
}
|
}
|
||||||
tmpfile="$(mktemp -t "cscript.XXXXXXXXXX")"
|
tmpfile="$(mktemp -t "cscript.XXXXXXXXXX")"
|
||||||
echo -n "$files" | xargs -d'\n' sed "s@^#!@//#!@g" -i
|
printf "%s" "$files" | xargs -d'\n' sed "s@^#!@//#!@g" -i
|
||||||
trap 'cleanup; exit 130' INT
|
trap 'cleanup; exit 130' INT
|
||||||
if ! echo -n "$files\n$opts" | xargs -d'\n' cc -Wall -pedantic -o "$tmpfile"; then
|
if ! printf "%s\n%s" "$files" "$opts" | xargs -d'\n' cc -Wall -pedantic -o "$tmpfile"; then
|
||||||
cleanup
|
cleanup
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo -n "$args" | xargs -d'\n' "$tmpfile"
|
printf "%s" "$args" | xargs -d'\n' "$tmpfile"
|
||||||
trap - INT
|
trap - INT
|
||||||
cleanup
|
cleanup
|
||||||
|
Loading…
Reference in New Issue
Block a user