2349
|
1 |
#!/bin/bash -norc
|
2302
|
2 |
#
|
2313
|
3 |
# $Id$
|
|
4 |
#
|
2302
|
5 |
# SML/NJ startup script (for 1.06 or later).
|
|
6 |
#
|
2349
|
7 |
# Global vars: INFILE OUTFILE COPYDB MLTEXT TERMINATE,
|
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 |
|
|
19 |
|
|
20 |
## prepare databases
|
|
21 |
|
2349
|
22 |
EXIT=""
|
|
23 |
if [ -z "$INFILE" ]; then
|
|
24 |
case "$ML_SYSTEM" in
|
|
25 |
smlnj-1.0[678])
|
|
26 |
EXIT="val exit = System.Unix.exit;"
|
|
27 |
;;
|
|
28 |
smlnj-1.09*)
|
|
29 |
EXIT="fun exit 0 = OS.Process.exit OS.Process.success | exit _ = OS.Process.exit OS.Process.failure;"
|
|
30 |
;;
|
|
31 |
esac
|
|
32 |
fi
|
|
33 |
|
|
34 |
DB="$INFILE"
|
|
35 |
[ -n "$DB" ] && DB="@SMLload=$INFILE"
|
|
36 |
|
|
37 |
COMMIT="fun commit () = not (exportML\"$OUTFILE\");"
|
2302
|
38 |
|
|
39 |
if [ -z "$OUTFILE" ]; then
|
2349
|
40 |
COMMIT='fun commit () = (output (std_err, "Error - Database is not opened for writing.\n"); false);'
|
|
41 |
elif [ -n "$INFILE" -a ! "$INFILE" -ef "$OUTFILE" ]; then
|
2302
|
42 |
[ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out }
|
|
43 |
cp "$INFILE" "$OUTFILE" || fail_out
|
|
44 |
fi
|
|
45 |
|
2429
|
46 |
[ -n "$OUTFILE" -a -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out }
|
2396
|
47 |
|
2349
|
48 |
MLTEXT="$EXIT $COMMIT $MLTEXT"
|
|
49 |
MLEXIT="commit();"
|
2302
|
50 |
|
|
51 |
|
|
52 |
## run it!
|
|
53 |
|
2429
|
54 |
START_SML="$ML_HOME/sml $ML_OPTIONS $DB"
|
2302
|
55 |
|
|
56 |
if [ -n "$TERMINATE" ]; then
|
2349
|
57 |
{ echo "$MLTEXT"; echo "$MLEXIT" } | $START_SML
|
2302
|
58 |
RC=$?
|
|
59 |
else
|
2349
|
60 |
{ echo "$MLTEXT"; $ISABELLE_HOME/lib/scripts/ucat; echo "$MLEXIT" } | $START_SML
|
2302
|
61 |
RC=$?
|
|
62 |
fi
|
|
63 |
|
|
64 |
exit $RC
|