3007
|
1 |
#!/bin/bash
|
2302
|
2 |
#
|
2313
|
3 |
# $Id$
|
9789
|
4 |
# Author: Markus Wenzel, TU Muenchen
|
|
5 |
# License: GPL (GNU GENERAL PUBLIC LICENSE)
|
2313
|
6 |
#
|
5708
|
7 |
# SML/NJ startup script (for 110 or later).
|
2302
|
8 |
#
|
4333
|
9 |
# Global vars: INFILE OUTFILE MLTEXT TERMINATE NOWRITE ISABELLE_TMP,
|
2302
|
10 |
# and from settings
|
|
11 |
|
|
12 |
|
|
13 |
## diagnostics
|
|
14 |
|
2349
|
15 |
function fail_out()
|
2302
|
16 |
{
|
2349
|
17 |
echo "Unable to create output heap file: \"$OUTFILE\"" >&2
|
2302
|
18 |
exit 2
|
|
19 |
}
|
|
20 |
|
5063
|
21 |
function check_mlhome_file()
|
|
22 |
{
|
|
23 |
if [ ! -f "$1" ]; then
|
|
24 |
echo "Unable to locate $1" >&2
|
|
25 |
echo "Please check your ML_HOME setting!" >&2
|
|
26 |
exit 2
|
|
27 |
fi
|
|
28 |
}
|
|
29 |
|
6078
|
30 |
function check_heap_file()
|
|
31 |
{
|
|
32 |
if [ ! -f "$1" ]; then
|
|
33 |
echo "Expected to find ML heap file $1" >&2
|
|
34 |
return 1
|
|
35 |
else
|
|
36 |
return 0
|
|
37 |
fi
|
|
38 |
}
|
|
39 |
|
|
40 |
|
5063
|
41 |
|
|
42 |
## compiler binaries
|
|
43 |
|
|
44 |
SML="$ML_HOME/sml"
|
|
45 |
ARCH_N_OPSYS="$ML_HOME/.arch-n-opsys"
|
|
46 |
|
|
47 |
check_mlhome_file "$SML"
|
|
48 |
check_mlhome_file "$ARCH_N_OPSYS"
|
|
49 |
|
|
50 |
|
2302
|
51 |
|
3046
|
52 |
## prepare databases
|
|
53 |
|
4505
|
54 |
if [ -z "$INFILE" ]; then
|
|
55 |
EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;"
|
|
56 |
DB=""
|
|
57 |
else
|
|
58 |
EXIT=""
|
3046
|
59 |
DB="@SMLload=$INFILE"
|
2349
|
60 |
fi
|
|
61 |
|
4505
|
62 |
if [ -z "$OUTFILE" ]; then
|
|
63 |
COMMIT='fun commit () = (TextIO.output (TextIO.stdErr, "Error - Database is not opened for writing.\n"); false);'
|
|
64 |
else
|
|
65 |
COMMIT="fun commit () = not (SMLofNJ.exportML\"$OUTFILE\");"
|
|
66 |
[ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
|
|
67 |
fi
|
2302
|
68 |
|
|
69 |
|
|
70 |
## run it!
|
|
71 |
|
4505
|
72 |
MLTEXT="$EXIT $COMMIT $MLTEXT"
|
|
73 |
MLEXIT="commit();"
|
2302
|
74 |
|
4505
|
75 |
if [ -z "$TERMINATE" ]; then
|
|
76 |
FEEDER_OPTS=""
|
2302
|
77 |
else
|
4505
|
78 |
FEEDER_OPTS="-q"
|
2302
|
79 |
fi
|
|
80 |
|
9789
|
81 |
"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
|
|
82 |
{ read FPID; "$SML" $ML_OPTIONS "$DB"; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
|
|
83 |
RC="$?"
|
4505
|
84 |
|
|
85 |
|
|
86 |
## fix heap file name and permissions
|
3046
|
87 |
|
4505
|
88 |
if [ -n "$OUTFILE" ]; then
|
9789
|
89 |
eval $("$ARCH_N_OPSYS")
|
6078
|
90 |
[ -z "$HEAP_SUFFIX" ] && HEAP_SUFFIX="$ARCH-$OPSYS"
|
|
91 |
HEAP="$OUTFILE.$HEAP_SUFFIX"
|
|
92 |
check_heap_file "$HEAP" && mv "$HEAP" "$OUTFILE" && \
|
4505
|
93 |
[ -n "$NOWRITE" ] && chmod -w "$OUTFILE"
|
|
94 |
fi
|
3503
|
95 |
|
9789
|
96 |
exit "$RC"
|