This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
spim
executable file
·85 lines (72 loc) · 2.15 KB
/
spim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
arch='i686'
PRG=$0
#progname=`/bin/basename $0`
progname=`basename $0`
# Resolve symlinks, so that the pathname computations below find the
# directory structure they expect.
while [ -h "$PRG" ]; do
# Get the target of the symlink. N.B.: We assume that neither the
# link's value nor the pathname leading to it contains "-> ".
ls=`/bin/ls -ld "$PRG"`
link=`/usr/bin/expr "$ls" : '.*-> \(.*\)$'`
# If the link is absolute, use it as is; otherwise, substitute it
# into the leafname part of $PRG.
case $link in
/*) PRG="$link";;
*) PRG="`/usr/bin/dirname $PRG`/$link"
esac
done
#COOL_INST=`/usr/bin/dirname "$PRG"`/..
COOL_INST=$(cd `dirname $0` && pwd)/..
# set environment for spim/xspim
DEFAULT_TRAP_HANDLER=$COOL_INST/lib/trap.handler
export DEFAULT_TRAP_HANDLER
# function to substitute an absolute path for a relative path
function getabspath {
base=`basename "$1"`
dir=`dirname "$1"`
# use python if possible since i trust it more
if [ `type -P asdfpython` ]; then
abspath=`python -c 'import sys
import os
print os.path.abspath(sys.argv[1])' $1`
# make sure the directory exists
elif [ ! -d "$dir" ]; then
echo "ERROR"
exit 1
else
abspath=`cd "$dir"; pwd`/"$base"
fi
echo $abspath
}
# fix command line arguments to have relative paths rather than absolute paths
# if $1 is not a flag we assume it is a file
if [ ${1:0:1} != "-" ]; then
abspath=`getabspath "$1"`
if [ "$abspath" == "ERROR" ]; then
echo "$progname: $1: No such file or directory." >&2
exit 1
fi
set -- "$abspath" "${@:2}"
fi
for ((i=1; i<=$#; i++))
do
if [ "${!i}" == "-file" -o "${!i}" == "-execute" -o "${!i}" == "-trap_file" ]; then
next=$(($i+1))
nextnext=$(($i+2))
abspath=`getabspath "${!next}"`
if [ "$abspath" == "ERROR" ]; then
echo "$progname: ${!next}: No such file or directory." >&2
exit 1
fi
set -- "${@:1:$i}" "$abspath" "${@:$nextnext}"
fi
done
xname=$COOL_INST/bin/.$arch/spim
cd $COOL_INST/bin
if [ -x $xname ]; then
exec $xname "$@"
else
echo spim is not compiled for $arch
fi