- use just the basename for program name
- quote variables - use mktemp to create directories (from jtc) - exit on errors
This commit is contained in:
parent
8a78d908fb
commit
5eb5e1c36d
@ -1,5 +1,5 @@
|
|||||||
#!/bin/sh -
|
#!/bin/sh -
|
||||||
# $NetBSD: genassym.sh,v 1.7 2011/07/05 05:19:02 matt Exp $
|
# $NetBSD: genassym.sh,v 1.8 2014/01/06 22:43:15 christos Exp $
|
||||||
#
|
#
|
||||||
# Copyright (c) 1997 Matthias Pfaller.
|
# Copyright (c) 1997 Matthias Pfaller.
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
@ -25,7 +25,7 @@
|
|||||||
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#
|
#
|
||||||
|
|
||||||
progname=${0}
|
progname="$(basename "${0}")"
|
||||||
: ${AWK:=awk}
|
: ${AWK:=awk}
|
||||||
|
|
||||||
ccode=0 # generate temporary C file, compile it, execute result
|
ccode=0 # generate temporary C file, compile it, execute result
|
||||||
@ -37,6 +37,8 @@ usage()
|
|||||||
echo "usage: ${progname} [-c | -f] -- compiler command" >&2
|
echo "usage: ${progname} [-c | -f] -- compiler command" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
while getopts cf i
|
while getopts cf i
|
||||||
do
|
do
|
||||||
case "$i" in
|
case "$i" in
|
||||||
@ -48,7 +50,7 @@ do
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
shift $(($OPTIND - 1))
|
shift "$(($OPTIND - 1))"
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
@ -56,7 +58,7 @@ fi
|
|||||||
|
|
||||||
# Deal with any leading environment settings..
|
# Deal with any leading environment settings..
|
||||||
|
|
||||||
while [ "$1" ]
|
while [ -n "$1" ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
*=*)
|
*=*)
|
||||||
@ -69,9 +71,10 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
genassym_temp=/tmp/genassym.$$
|
genassym_temp="$(mktemp -d "${TMPDIR-/tmp}/genassym.XXXXXX")"
|
||||||
|
|
||||||
if ! mkdir $genassym_temp; then
|
|
||||||
|
if [ ! -d $genassym_temp ]; then
|
||||||
echo "${progname}: unable to create temporary directory" >&2
|
echo "${progname}: unable to create temporary directory" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -191,21 +194,21 @@ END {
|
|||||||
printf("return(0); }\n");
|
printf("return(0); }\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
' ccode=$ccode fcode=$fcode > ${genassym_temp}/assym.c || exit 1
|
' ccode="$ccode" fcode="$fcode" > "${genassym_temp}/assym.c" || exit 1
|
||||||
|
|
||||||
if [ $ccode = 1 ] ; then
|
if [ "$ccode" = 1 ]; then
|
||||||
"$@" ${genassym_temp}/assym.c -o ${genassym_temp}/genassym && \
|
"$@" "${genassym_temp}/assym.c" -o "${genassym_temp}/genassym" && \
|
||||||
${genassym_temp}/genassym
|
"${genassym_temp}/genassym"
|
||||||
elif [ $fcode = 1 ]; then
|
elif [ "$fcode" = 1 ]; then
|
||||||
# Kill all of the "#" and "$" modifiers; locore.s already
|
# Kill all of the "#" and "$" modifiers; locore.s already
|
||||||
# prepends the correct "constant" modifier.
|
# prepends the correct "constant" modifier.
|
||||||
"$@" -S ${genassym_temp}/assym.c -o - | sed -e 's/\$//g' | \
|
"$@" -S "${genassym_temp}/assym.c" -o - | sed -e 's/\$//g' | \
|
||||||
sed -n 's/.*XYZZY//gp'
|
sed -n 's/.*XYZZY//gp'
|
||||||
else
|
else
|
||||||
# Kill all of the "#" and "$" modifiers; locore.s already
|
# Kill all of the "#" and "$" modifiers; locore.s already
|
||||||
# prepends the correct "constant" modifier.
|
# prepends the correct "constant" modifier.
|
||||||
"$@" -S ${genassym_temp}/assym.c -o - > \
|
"$@" -S "${genassym_temp}/assym.c" -o - > \
|
||||||
${genassym_temp}/genassym.out && \
|
"${genassym_temp}/genassym.out" && \
|
||||||
sed -e 's/#//g' -e 's/\$//g' < ${genassym_temp}/genassym.out | \
|
sed -e 's/#//g' -e 's/\$//g' < "${genassym_temp}/genassym.out" | \
|
||||||
sed -n 's/.*XYZZY/#define/gp'
|
sed -n 's/.*XYZZY/#define/gp'
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user