lib/scripts/run-polyml
author wenzelm
Tue Apr 22 11:37:12 1997 +0200 (1997-04-22)
changeset 3007 e5efa177ee0c
parent 2936 bd33e7aae062
child 3055 5da4afa207ad
permissions -rwxr-xr-x
removed -norc;
     1 #!/bin/bash
     2 #
     3 # $Id$
     4 #
     5 # Poly/ML startup script.
     6 #
     7 # Global vars: INFILE OUTFILE COPYDB MLTEXT TERMINATE,
     8 # and from settings
     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 
    20 ## Poly/ML programs
    21 
    22 POLY=$ML_HOME/poly
    23 DISCGARB=$ML_HOME/discgarb
    24 
    25 case "$ML_SYSTEM" in
    26   polyml-3.*)
    27     DISCGARB="$DISCGARB -c"
    28     ;;
    29 esac
    30 
    31 
    32 ## prepare databases
    33 
    34 MLINIT=""
    35 
    36 if [ -z "$INFILE" ]; then
    37   INFILE="$ML_HOME/ML_dbase"
    38   MLINIT="val use = PolyML.use; val exit = PolyML.exit; fun init_database () = ();"
    39 fi
    40 
    41 if [ -z "$OUTFILE" ]; then
    42   DB="$INFILE"
    43   ML_OPTIONS="-r $ML_OPTIONS"  
    44 elif [ "$INFILE" -ef "$OUTFILE" ]; then
    45   DB="$INFILE"
    46 elif [ -n "$COPYDB" ]; then
    47   [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
    48   cp "$INFILE" "$OUTFILE" || fail_out
    49   chmod +w "$OUTFILE" || fail_out
    50   DB="$OUTFILE"
    51 else
    52   [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
    53   echo "PolyML.make_database \"$OUTFILE\"; PolyML.quit();" | $POLY -r "$INFILE"
    54   [ -f "$OUTFILE" ] || fail_out
    55   DB="$OUTFILE"
    56   MLINIT="$MLINIT init_database ();"
    57 fi
    58 
    59 
    60 ## run it!
    61 
    62 START_POLY="$POLY $ML_OPTIONS $DB"
    63 DB_INFO=$(ls -l "$DB")
    64 
    65 [ -n "$MLINIT" ] && MLTEXT="$MLINIT $MLTEXT"
    66 
    67 if [ -n "$TERMINATE" ]; then
    68   echo "$MLTEXT" | $START_POLY
    69   RC=$?
    70 elif [ -z "$MLTEXT" ]; then
    71   sh -c "$ISABELLE_HOME/lib/Tools/symbolinput | $START_POLY"
    72   RC=$?
    73 else
    74   sh -c "{ echo '$MLTEXT'; $ISABELLE_HOME/lib/Tools/symbolinput; } | $START_POLY"
    75   RC=$?
    76 fi
    77 
    78 NEW_DB_INFO=$(ls -l "$DB")
    79 [ -n "$OUTFILE" -a "$DB_INFO" != "$NEW_DB_INFO" ] && $DISCGARB "$OUTFILE"
    80 
    81 exit $RC