lib/Tools/keywords
changeset 52439 4cf3f6153eb8
parent 35022 c844b93dd147
child 52443 725916b7dee5
equal deleted inserted replaced
52438:7b5a5116f3af 52439:4cf3f6153eb8
     1 #!/usr/bin/env bash
     1 #!/usr/bin/env bash
     2 #
     2 #
     3 # Author: Makarius
     3 # Author: Makarius
     4 #
     4 #
     5 # DESCRIPTION: generate outer syntax keyword files from session logs
     5 # DESCRIPTION: generate keyword files for Emacs Proof General
     6 
     6 
     7 
     7 
     8 ## diagnostics
     8 ## diagnostics
     9 
     9 
    10 PRG="$(basename "$0")"
    10 PRG="$(basename "$0")"
    11 
    11 
    12 function usage()
    12 function usage()
    13 {
    13 {
    14   echo
    14   echo
    15   echo "Usage: isabelle $PRG [OPTIONS] [LOGS ...]"
    15   echo "Usage: isabelle $PRG [OPTIONS] [SESSIONS ...]"
    16   echo
    16   echo
    17   echo "  Options are:"
    17   echo "  Options are:"
       
    18   echo "    -d DIR       include session directory"
    18   echo "    -k NAME      specific name of keywords collection (default: empty)"
    19   echo "    -k NAME      specific name of keywords collection (default: empty)"
    19   echo
    20   echo
    20   echo "  Generate outer syntax keyword files from (compressed) session LOGS."
    21   echo "  Generate keyword files for Emacs Proof General from Isabelle sessions."
    21   echo "  Targets Emacs Proof General."
       
    22   echo
    22   echo
    23   exit 1
    23   exit 1
    24 }
    24 }
    25 
    25 
    26 
    26 
    27 ## process command line
    27 ## process command line
    28 
    28 
    29 # options
    29 # options
    30 
    30 
       
    31 declare -a DIRS=()
    31 KEYWORDS_NAME=""
    32 KEYWORDS_NAME=""
    32 
    33 
    33 while getopts "k:" OPT
    34 while getopts "d:k:" OPT
    34 do
    35 do
    35   case "$OPT" in
    36   case "$OPT" in
       
    37     d)
       
    38       DIRS["${#DIRS[@]}"]="$OPTARG"
       
    39       ;;
    36     k)
    40     k)
    37       KEYWORDS_NAME="$OPTARG"
    41       KEYWORDS_NAME="$OPTARG"
    38       ;;
    42       ;;
    39     \?)
    43     \?)
    40       usage
    44       usage
    45 shift $(($OPTIND - 1))
    49 shift $(($OPTIND - 1))
    46 
    50 
    47 
    51 
    48 ## main
    52 ## main
    49 
    53 
    50 SESSIONS=""
    54 [ -e "$ISABELLE_HOME/Admin/build" ] && { "$ISABELLE_HOME/Admin/build" jars || exit $?; }
    51 for LOG in "$@"
       
    52 do
       
    53   NAME="$(basename "$LOG" .gz)"
       
    54   if [ -z "$SESSIONS" ]; then
       
    55     SESSIONS="$NAME"
       
    56   else
       
    57     SESSIONS="$SESSIONS + $NAME"
       
    58   fi
       
    59 done
       
    60 
    55 
    61 for LOG in "$@"
    56 declare -a JAVA_ARGS; eval "JAVA_ARGS=($ISABELLE_BUILD_JAVA_OPTIONS)"
    62 do
    57 
    63   if [ "${LOG%.gz}" = "$LOG" ]; then
    58 "$ISABELLE_TOOL" java "${JAVA_ARGS[@]}" isabelle.Keywords keywords \
    64     cat "$LOG"
    59   "$KEYWORDS_NAME" "${DIRS[@]}" $'\n' "$@"
    65   else
    60 
    66     gzip -dc "$LOG"
       
    67   fi
       
    68   echo
       
    69 done | "$ISABELLE_HOME/lib/scripts/keywords" "$KEYWORDS_NAME" "$SESSIONS"