lib/scripts/run-smlnj
changeset 3051 30490aa41356
parent 3046 6b7935317538
child 3055 5da4afa207ad
equal deleted inserted replaced
3050:7eacab79b8e1 3051:30490aa41356
    19 
    19 
    20 ## version specific stuff
    20 ## version specific stuff
    21 
    21 
    22 EXIT=""
    22 EXIT=""
    23 COMMIT=""
    23 COMMIT=""
    24 FIXNAME=""
    24 SUFFIX=""
    25 
    25 
    26 case "$ML_SYSTEM" in
    26 case "$ML_SYSTEM" in
    27   smlnj-1.0[678]*)
    27   smlnj-1.0[678]*)
    28     EXIT="val exit = System.Unix.exit;"
    28     EXIT="val exit = System.Unix.exit;"
    29     COMMIT="fun commit () = not (exportML\"$OUTFILE\");"
    29     COMMIT="fun commit () = not (exportML\"$OUTFILE\");"
    31     ;;
    31     ;;
    32   smlnj-1.09*)
    32   smlnj-1.09*)
    33     EXIT="fun exit 0 : unit = OS.Process.exit OS.Process.success | exit _ = OS.Process.exit OS.Process.failure;"
    33     EXIT="fun exit 0 : unit = OS.Process.exit OS.Process.success | exit _ = OS.Process.exit OS.Process.failure;"
    34     COMMIT="fun commit () = not (SMLofNJ.exportML\"$OUTFILE\");"
    34     COMMIT="fun commit () = not (SMLofNJ.exportML\"$OUTFILE\");"
    35     COMMIT_RO='fun commit () = (TextIO.output (TextIO.stdErr, "Error - Database is not opened for writing.\\n"); false);'
    35     COMMIT_RO='fun commit () = (TextIO.output (TextIO.stdErr, "Error - Database is not opened for writing.\\n"); false);'
    36     FIXNAME=true
    36     eval $($ML_HOME/.arch-n-opsys)
       
    37     SUFFIX=".$ARCH-$OPSYS"
    37     ;;
    38     ;;
    38 esac
    39 esac
    39 
    40 
    40 
    41 
    41 ## prepare databases
    42 ## prepare databases
    45 if [ -n "$DB" ]; then
    46 if [ -n "$DB" ]; then
    46   DB="@SMLload=$INFILE"
    47   DB="@SMLload=$INFILE"
    47   EXIT=""
    48   EXIT=""
    48 fi
    49 fi
    49 
    50 
    50 if [ -z "$OUTFILE" ]; then
    51 [ -z "$OUTFILE" ] && COMMIT="$COMMIT_RO"
    51   COMMIT="$COMMIT_RO"
       
    52 elif [ -n "$INFILE" -a ! "$INFILE" -ef "$OUTFILE" ]; then
       
    53   [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
       
    54   cp "$INFILE" "$OUTFILE" || fail_out
       
    55 fi
       
    56 
       
    57 [ -n "$OUTFILE" -a -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
    52 [ -n "$OUTFILE" -a -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
    58 
    53 
    59 MLTEXT="$EXIT $COMMIT $MLTEXT"
    54 MLTEXT="$EXIT $COMMIT $MLTEXT"
    60 MLEXIT="commit ();"
    55 MLEXIT="commit ();"
    61 
    56 
    63 ## run it!
    58 ## run it!
    64 
    59 
    65 START_SML="$ML_HOME/sml $ML_OPTIONS $DB"
    60 START_SML="$ML_HOME/sml $ML_OPTIONS $DB"
    66 
    61 
    67 if [ -n "$TERMINATE" ]; then
    62 if [ -n "$TERMINATE" ]; then
    68   echo "$MLTEXT" "$MLEXIT" | $START_SML
    63   sh -c "echo '$MLTEXT' '$MLEXIT' | $START_SML"
    69   RC=$?
    64   RC=$?
    70 elif [ -z "$MLTEXT" ]; then
    65 elif [ -z "$MLTEXT" ]; then
    71   sh -c "{ $ISABELLE_HOME/lib/scripts/ucat; echo '$MLEXIT'; } | $START_SML"
    66   sh -c "{ $ISABELLE_HOME/lib/scripts/ucat; echo '$MLEXIT'; } | $START_SML"
    72   RC=$?
    67   RC=$?
    73 else
    68 else
    74   sh -c "{ echo '$MLTEXT'; $ISABELLE_HOME/lib/scripts/ucat; echo '$MLEXIT'; } | $START_SML"
    69   sh -c "{ echo '$MLTEXT'; $ISABELLE_HOME/lib/scripts/ucat; echo '$MLEXIT'; } | $START_SML"
    75   RC=$?
    70   RC=$?
    76 fi
    71 fi
    77 
    72 
    78 #fix heap file name
    73 #fix heap file name
    79 if [ -n "$OUTFILE" -a -n "$FIXNAME" ]; then
    74 [ -n "$OUTFILE" -a -n "$SUFFIX" -a -f "$OUTFILE$SUFFIX" ] \
    80   eval $($ML_HOME/.arch-n-opsys)
    75   && mv "$OUTFILE$SUFFIX" "$OUTFILE"
    81   SUFFIX=$ARCH-$OPSYS
       
    82   [ -f $OUTFILE.$SUFFIX ] && mv $OUTFILE.$SUFFIX $OUTFILE
       
    83 fi
       
    84 
    76 
    85 exit $RC
    77 exit $RC