diff -r f8c1a5b9488f -r 3a6c03b15916 lib/Tools/mkroot --- a/lib/Tools/mkroot Wed Aug 08 17:49:56 2012 +0200 +++ b/lib/Tools/mkroot Wed Aug 08 20:35:34 2012 +0200 @@ -12,10 +12,13 @@ function usage() { echo - echo "Usage: isabelle $PRG NAME" + echo "Usage: isabelle $PRG [OPTIONS] [DIR]" echo - echo " Prepare session root directory, adding session NAME with" - echo " built-in document preparation." + echo " Options are:" + echo " -d enable document preparation" + echo " -n NAME alternative session name (default: DIR base name)" + echo + echo " Prepare session root DIR (default: current directory)." echo exit 1 } @@ -29,48 +32,91 @@ ## process command line -[ "$#" -ne 1 -o "$1" = "-?" ] && usage +# options + +DOC="" +NAME="" -DIR_NAME="$1"; shift +while getopts "n:d" OPT +do + case "$OPT" in + d) + DOC="true" + ;; + n) + NAME="$OPTARG" + ;; + \?) + usage + ;; + esac +done -DIR="$(dirname "$DIR_NAME")" -NAME="$(basename "$DIR_NAME")" +shift $(($OPTIND - 1)) + + +# args + +if [ "$#" -eq 0 ]; then + DIR="." +elif [ "$#" -eq 1 ]; then + DIR="$1" + shift +else + usage +fi ## main -[ -e "$DIR_NAME" ] && fail "Cannot overwrite existing \"$DIR_NAME\"" +mkdir -p "$DIR" || fail "Bad directory: \"$DIR\"" + +[ -z "$NAME" ] && NAME="$(basename "$(cd "$DIR"; pwd -P)")" + +[ -e "$DIR/ROOT" ] && fail "Cannot overwrite existing $DIR/ROOT" + +[ "$DOC" = true -a -e "$DIR/document" ] && \ + fail "Cannot overwrite existing $DIR/document" echo -echo "Preparing session \"$NAME\" ..." - -mkdir -p "$DIR_NAME" || fail "Bad directory: \"$DIR_NAME\"" +echo "Preparing session \"$NAME\" in \"$DIR\"" -# example theory +# ROOT -echo "creating $DIR_NAME/Ex.thy" -cat > "$DIR_NAME/Ex.thy" < "$DIR/ROOT" < "$DIR/ROOT" < "$DIR_NAME/document/root.tex" < "$DIR/document/root.tex" <> "$DIR/ROOT" -else - echo "creating ROOT" fi -cat >> "$DIR/ROOT" <