2349
|
1 |
#!/bin/bash -norc
|
2301
|
2 |
#
|
2314
|
3 |
# $Id$
|
|
4 |
#
|
2301
|
5 |
# Poly/ML startup script.
|
|
6 |
#
|
2349
|
7 |
# Global vars: INFILE OUTFILE COPYDB MLTEXT TERMINATE,
|
2301
|
8 |
# and from settings
|
|
9 |
|
|
10 |
|
|
11 |
## diagnostics
|
|
12 |
|
2349
|
13 |
function fail_out()
|
2301
|
14 |
{
|
2349
|
15 |
echo "Unable to create output heap file: \"$OUTFILE\"" >&2
|
2301
|
16 |
exit 2
|
|
17 |
}
|
|
18 |
|
|
19 |
|
2400
|
20 |
## Poly/ML programs
|
2301
|
21 |
|
|
22 |
POLY=$ML_HOME/poly
|
|
23 |
DISCGARB=$ML_HOME/discgarb
|
|
24 |
|
|
25 |
case "$ML_SYSTEM" in
|
2349
|
26 |
polyml-3.*)
|
2314
|
27 |
DISCGARB="$DISCGARB -c"
|
2301
|
28 |
;;
|
|
29 |
esac
|
|
30 |
|
|
31 |
|
|
32 |
## prepare databases
|
|
33 |
|
2349
|
34 |
MLINIT=""
|
|
35 |
|
2301
|
36 |
if [ -z "$INFILE" ]; then
|
2400
|
37 |
INFILE="$ML_HOME/ML_dbase"
|
2349
|
38 |
MLINIT="val use = PolyML.use; val exit = PolyML.exit; fun init_database () = ();"
|
2301
|
39 |
fi
|
|
40 |
|
|
41 |
if [ -z "$OUTFILE" ]; then
|
|
42 |
DB="$INFILE"
|
2349
|
43 |
ML_OPTIONS="-r $ML_OPTIONS"
|
|
44 |
elif [ "$INFILE" -ef "$OUTFILE" ]; then
|
2301
|
45 |
DB="$INFILE"
|
|
46 |
elif [ -n "$COPYDB" ]; then
|
2548
|
47 |
[ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out }
|
|
48 |
cp "$INFILE" "$OUTFILE" || fail_out
|
2349
|
49 |
chmod +w "$OUTFILE" || fail_out
|
2301
|
50 |
DB="$OUTFILE"
|
|
51 |
else
|
2389
|
52 |
[ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out }
|
2349
|
53 |
echo "PolyML.make_database \"$OUTFILE\"; PolyML.quit();" | $POLY -r "$INFILE"
|
2301
|
54 |
[ -f "$OUTFILE" ] || fail_out
|
|
55 |
DB="$OUTFILE"
|
2349
|
56 |
MLINIT="$MLINIT init_database ();"
|
2301
|
57 |
fi
|
|
58 |
|
|
59 |
|
|
60 |
## run it!
|
|
61 |
|
2349
|
62 |
START_POLY="$POLY $ML_OPTIONS $DB"
|
2400
|
63 |
DB_INFO=$(ls -l "$DB")
|
2349
|
64 |
|
|
65 |
[ -n "$MLINIT" ] && MLTEXT="$MLINIT $MLTEXT"
|
2301
|
66 |
|
|
67 |
if [ -n "$TERMINATE" ]; then
|
2349
|
68 |
echo "$MLTEXT" | $START_POLY
|
2301
|
69 |
RC=$?
|
|
70 |
else
|
2400
|
71 |
{ echo "$MLTEXT"; $ISABELLE_HOME/lib/Tools/symbolinput } | $START_POLY
|
2301
|
72 |
RC=$?
|
|
73 |
fi
|
|
74 |
|
2400
|
75 |
NEW_DB_INFO=$(ls -l "$DB")
|
2389
|
76 |
[ $RC -eq 0 -a -n "$OUTFILE" -a "$DB_INFO" != "$NEW_DB_INFO" ] && $DISCGARB "$OUTFILE"
|
2301
|
77 |
|
|
78 |
exit $RC
|