17759
|
1 |
#!/usr/bin/env bash
|
|
2 |
#
|
|
3 |
# $Id$
|
|
4 |
# Author: Makarius
|
|
5 |
#
|
|
6 |
# Poplog/PML startup script (version 15.6/2.1).
|
|
7 |
|
|
8 |
export -n INFILE OUTFILE COPYDB COMPRESS MLTEXT TERMINATE NOWRITE
|
|
9 |
|
|
10 |
|
|
11 |
## diagnostics
|
|
12 |
|
|
13 |
function fail_out()
|
|
14 |
{
|
|
15 |
echo "Unable to create output heap file: \"$OUTFILE\"" >&2
|
|
16 |
exit 2
|
|
17 |
}
|
|
18 |
|
|
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 |
|
|
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 |
|
|
39 |
## prepare databases
|
|
40 |
|
|
41 |
if [ -z "$INFILE" ]; then
|
|
42 |
EXIT="fun exit (i: int) = OS.execve \"/bin/sh\" [\"sh\", \"-c\", \"exit \" ^ makestring i] (OS.envlist());"
|
17794
|
43 |
USE='pop11
|
|
44 |
section $-ml;
|
|
45 |
|
|
46 |
ml_exception Use of string;
|
|
47 |
|
|
48 |
ml_val use : string -> unit =
|
|
49 |
procedure(name) with_props use;
|
|
50 |
lvars name, path;
|
|
51 |
lconstant UseExn = exception("Use");
|
|
52 |
|
|
53 |
define dlocal pop_exception_handler(n, msg, idstring, severity);
|
|
54 |
returnunless(severity == `E` or severity == `R`)(false);
|
|
55 |
erasenum(n);
|
|
56 |
raise(UseExn(name));
|
|
57 |
enddefine;
|
|
58 |
|
|
59 |
unless sourcefile(name) ->> path then raise(UseExn(name)) endunless;
|
|
60 |
ml_load(path);
|
|
61 |
ml_unit;
|
|
62 |
endprocedure;
|
|
63 |
|
|
64 |
ml_val use_string : string -> unit =
|
|
65 |
procedure(str) with_props use_string;
|
|
66 |
lvars str;
|
|
67 |
lconstant UseExn = exception("Use");
|
|
68 |
|
|
69 |
define dlocal pop_exception_handler(n, msg, idstring, severity);
|
|
70 |
returnunless(severity == `E` or severity == `R`)(false);
|
|
71 |
erasenum(n);
|
|
72 |
raise(UseExn(str));
|
|
73 |
enddefine;
|
|
74 |
|
|
75 |
ml_compile(stringin(str));
|
|
76 |
ml_unit;
|
|
77 |
endprocedure;
|
|
78 |
|
|
79 |
endsection;
|
|
80 |
ml'
|
17759
|
81 |
DB=""
|
|
82 |
else
|
|
83 |
EXIT=""
|
17794
|
84 |
USE=""
|
17759
|
85 |
DB="+$INFILE"
|
|
86 |
fi
|
|
87 |
|
|
88 |
if [ -z "$OUTFILE" ]; then
|
|
89 |
COMMIT='fun commit () = (StdIO.output (StdIO.std_err, "Error - Database is not opened for writing.\n"); false);'
|
|
90 |
else
|
17805
|
91 |
ML_OPTIONS="$ML_OPTIONS -nort"
|
17759
|
92 |
if [ -z "$NOWRITE" ]; then
|
|
93 |
COMMIT="fun commit () = if System.make {image =\"$OUTFILE\", lock = false, share = false, banner = false, init = false} then System.restart() else true;"
|
|
94 |
else
|
|
95 |
COMMIT="fun commit () = if System.make {image =\"$OUTFILE\", lock = true, share = true, banner = false, init = false} then System.restart() else true;"
|
|
96 |
fi
|
17794
|
97 |
[ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
|
17759
|
98 |
fi
|
|
99 |
|
|
100 |
|
|
101 |
## run it!
|
|
102 |
|
|
103 |
POPLOG="$ML_HOME/poplog"
|
|
104 |
check_mlhome_file "$POPLOG"
|
|
105 |
|
17794
|
106 |
MLTEXT="$EXIT $USE $COMMIT $MLTEXT"
|
17759
|
107 |
MLEXIT="commit();"
|
|
108 |
|
|
109 |
if [ -z "$TERMINATE" ]; then
|
|
110 |
FEEDER_OPTS=""
|
|
111 |
else
|
|
112 |
FEEDER_OPTS="-q"
|
|
113 |
fi
|
|
114 |
|
|
115 |
"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
|
|
116 |
{ read FPID; "$POPLOG" pml "$DB" $ML_OPTIONS; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
|
|
117 |
RC="$?"
|
|
118 |
|
|
119 |
|
17794
|
120 |
## check heap
|
17759
|
121 |
|
17794
|
122 |
[ -n "$OUTFILE" ] && check_heap_file "$OUTFILE" && \
|
|
123 |
[ -n "$NOWRITE" ] && chmod -w "$OUTFILE"
|
17759
|
124 |
|
|
125 |
exit "$RC"
|