2301
|
1 |
#!/bin/bash
|
|
2 |
#
|
2314
|
3 |
# $Id$
|
|
4 |
#
|
2301
|
5 |
# Poly/ML startup script.
|
|
6 |
#
|
|
7 |
# Global vars: INFILE OUTFILE COPYDB MLTEXT OPTIONS TERMINATE,
|
|
8 |
# and from settings
|
|
9 |
|
|
10 |
|
|
11 |
## diagnostics
|
|
12 |
|
|
13 |
function fail()
|
|
14 |
{
|
|
15 |
echo "$1"
|
|
16 |
exit 2
|
|
17 |
}
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
## locations and settings
|
|
22 |
|
|
23 |
ML_QUIT=";PolyML.quit();"
|
|
24 |
ML_DBASE=$ML_HOME/ML_dbase
|
|
25 |
POLY=$ML_HOME/poly
|
|
26 |
DISCGARB=$ML_HOME/discgarb
|
|
27 |
|
|
28 |
case "$ML_SYSTEM" in
|
|
29 |
polyml-3.1)
|
2314
|
30 |
DISCGARB="$DISCGARB -c"
|
2301
|
31 |
export LM_LICENSE_FILE=$ML_HOME/license.dat
|
|
32 |
;;
|
|
33 |
esac
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
## prepare databases
|
|
38 |
|
|
39 |
if [ -z "$INFILE" ]; then
|
|
40 |
INFILE="$ML_DBASE"
|
|
41 |
MLTEXT="val use = PolyML.use; val exit = PolyML.exit; $MLTEXT"
|
|
42 |
fi
|
|
43 |
|
|
44 |
function fail_out()
|
|
45 |
{
|
|
46 |
fail "Unable to create output heap file: \"$OUTFILE\""
|
|
47 |
}
|
|
48 |
|
|
49 |
if [ -z "$OUTFILE" ]; then
|
|
50 |
DB="$INFILE"
|
|
51 |
OPTS="-r"
|
|
52 |
elif [ "$INFILE" = "$OUTFILE" ]; then # FIXME -ef !?
|
|
53 |
DB="$INFILE"
|
|
54 |
OPTS=""
|
|
55 |
elif [ -n "$COPYDB" ]; then
|
|
56 |
cp "$INFILE" "$OUTFILE" || fail_out
|
|
57 |
chmod +w "$OUTFILE"
|
|
58 |
DB="$OUTFILE"
|
|
59 |
OPTS=""
|
|
60 |
else
|
|
61 |
[ -f "$OUTFILE" ] && { rm "$OUTFILE" || fail_out }
|
|
62 |
echo "PolyML.make_database \"$OUTFILE\"; $ML_QUIT" | $POLY -r "$INFILE"
|
|
63 |
[ -f "$OUTFILE" ] || fail_out
|
|
64 |
DB="$OUTFILE"
|
|
65 |
OPTS=""
|
|
66 |
fi
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
## run it!
|
|
71 |
|
|
72 |
START_POLY="$POLY $OPTS $ML_OPTIONS $OPTIONS $DB"
|
|
73 |
|
|
74 |
if [ -n "$TERMINATE" ]; then
|
|
75 |
echo "$MLTEXT" "$ML_QUIT" | $START_POLY
|
|
76 |
RC=$?
|
|
77 |
elif [ -z "$MLTEXT" ]; then
|
|
78 |
$START_POLY
|
|
79 |
RC=$?
|
|
80 |
else
|
|
81 |
TMP_FILE=/tmp/mltext-$$
|
|
82 |
echo "$MLTEXT" >$TMP_FILE
|
2314
|
83 |
$ISABELLE_HOME/lib/scripts/ucat $TMP_FILE - | $START_POLY
|
2301
|
84 |
RC=$?
|
|
85 |
rm $TMP_FILE
|
|
86 |
fi
|
|
87 |
|
2314
|
88 |
[ $RC -eq 0 -a -n "$OUTFILE" ] && $DISCGARB "$OUTFILE"
|
2301
|
89 |
|
|
90 |
exit $RC
|