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