lib/Tools/getenv
author paulson <lp15@cam.ac.uk>
Sun, 12 Feb 2023 20:49:31 +0000
changeset 77234 61fba09a3456
parent 74644 549019b4a808
permissions -rwxr-xr-x
Simplification of proofs

#!/usr/bin/env bash
#
# Author: Markus Wenzel, TU Muenchen
#
# DESCRIPTION: get values from Isabelle settings environment


## diagnostics

PRG="$(basename "$0")"

function usage()
{
  echo
  echo "Usage: isabelle $PRG [OPTIONS] [VARNAMES ...]"
  echo
  echo "  Options are:"
  echo "    -a           display complete environment"
  echo "    -b           print values only (doesn't work for -a)"
  echo "    -d FILE      dump complete environment to file (NUL terminated entries)"
  echo
  echo "  Get value of VARNAMES from the Isabelle settings."
  echo
  exit 1
}


## process command line

# options

ALL=""
BASE=""
DUMP=""

while getopts "abd:" OPT
do
  case "$OPT" in
    a)
      ALL=true
      ;;
    b)
      BASE=true
      ;;
    d)
      DUMP="$OPTARG"
      ;;
    \?)
      usage
      ;;
  esac
done

shift $(($OPTIND - 1))


# args

[ -z "$ALL" -a -z "$DUMP" -a "$#" -eq 0 ] && usage
[ -n "$ALL" -a "$#" -ne 0 ] && usage


## main

if [ -n "$ALL" ]; then
  env
else
  for VAR in "$@"
  do
    if [ -n "$BASE" ]; then
      eval "echo \$$VAR"
    else
      eval "echo $VAR=\$$VAR"
    fi
  done
fi

if [ -n "$DUMP" ]; then
  export PATH_JVM="$(platform_path "$PATH")"
  if [ -e "$ISABELLE_PRINTENV" ]; then
    "$ISABELLE_PRINTENV" -0 > "$DUMP"
  else
    exit 2
  fi
fi