| 
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
  | 
| 
 | 
    91  | 
  if [ -z "$NOWRITE" ]; then
  | 
| 
 | 
    92  | 
    COMMIT="fun commit () = if System.make {image =\"$OUTFILE\", lock = false, share = false, banner = false, init = false} then System.restart() else true;"
 | 
| 
 | 
    93  | 
  else
  | 
| 
 | 
    94  | 
    COMMIT="fun commit () = if System.make {image =\"$OUTFILE\", lock = true, share = true, banner = false, init = false} then System.restart() else true;"
 | 
| 
 | 
    95  | 
  fi
  | 
| 
17794
 | 
    96  | 
  [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
 | 
| 
17759
 | 
    97  | 
fi
  | 
| 
 | 
    98  | 
  | 
| 
 | 
    99  | 
  | 
| 
 | 
   100  | 
## run it!
  | 
| 
 | 
   101  | 
  | 
| 
 | 
   102  | 
POPLOG="$ML_HOME/poplog"
  | 
| 
 | 
   103  | 
check_mlhome_file "$POPLOG"
  | 
| 
 | 
   104  | 
  | 
| 
17794
 | 
   105  | 
MLTEXT="$EXIT $USE $COMMIT $MLTEXT"
  | 
| 
17759
 | 
   106  | 
MLEXIT="commit();"
  | 
| 
 | 
   107  | 
  | 
| 
 | 
   108  | 
if [ -z "$TERMINATE" ]; then
  | 
| 
 | 
   109  | 
  FEEDER_OPTS=""
  | 
| 
 | 
   110  | 
else
  | 
| 
 | 
   111  | 
  FEEDER_OPTS="-q"
  | 
| 
 | 
   112  | 
fi
  | 
| 
 | 
   113  | 
  | 
| 
 | 
   114  | 
"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
  | 
| 
 | 
   115  | 
  { read FPID; "$POPLOG" pml "$DB" $ML_OPTIONS; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
 | 
| 
 | 
   116  | 
RC="$?"
  | 
| 
 | 
   117  | 
  | 
| 
 | 
   118  | 
  | 
| 
17794
 | 
   119  | 
## check heap
  | 
| 
17759
 | 
   120  | 
  | 
| 
17794
 | 
   121  | 
[ -n "$OUTFILE" ] && check_heap_file "$OUTFILE" && \
  | 
| 
 | 
   122  | 
  [ -n "$NOWRITE" ] && chmod -w "$OUTFILE"
  | 
| 
17759
 | 
   123  | 
  | 
| 
 | 
   124  | 
exit "$RC"
  |