aboutsummaryrefslogtreecommitdiffhomepage
path: root/isar/interface
blob: c9568c291656dbba58256816ba6fb67915afabf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env bash
#
# $Id$
#
# Proof General interface wrapper for Isabelle.


## self references

THIS=$(cd "$(dirname "$0")"; pwd)
SUPER=$(cd "$THIS/.."; pwd)


## diagnostics

usage()
{
  echo
  echo "Usage: Isabelle [OPTIONS] [FILES ...]"
  echo
  echo "  Options are:"
  echo "    -I BOOL      use Isabelle/Isar (default: true, implied by -P true)"
  echo "    -L NAME      abbreviates -l NAME -k NAME"
  echo "    -P BOOL      actually start Proof General (default true), otherwise"
  echo "                 run plain tty session"
  echo "    -U BOOL      enable Unicode (UTF-8) communication (default true)"
  echo "    -X BOOL      configure the X-Symbol package on startup (default true)"
  echo "    -f SIZE      set X-Symbol font size (default 12)"
  echo "    -g GEOMETRY  specify Emacs geometry"
  echo "    -k NAME      use specific isar-keywords for named logic"
  echo "    -l NAME      logic image name (default \$ISABELLE_LOGIC=$ISABELLE_LOGIC)"
  echo "    -m MODE      add print mode for output"
  echo "    -p NAME      Emacs program name (default xemacs)"
  echo "    -u BOOL      use personal .emacs file (default true)"
  echo "    -w BOOL      use window system (default true)"
  echo "    -x BOOL      enable the X-Symbol package on startup (default false)"
  echo
  echo "Starts Proof General for Isabelle with theory and proof FILES"
  echo "(default Scratch.thy)."
  echo
  echo "  PROOFGENERAL_OPTIONS=$PROOFGENERAL_OPTIONS"
  echo
  exit 1
}

fail()
{
  echo "$1" >&2
  exit 2
}


## process command line

# options

ISABELLE_OPTIONS=""
ISAR="true"
START_PG="true"
GEOMETRY=""
KEYWORDS=""
LOGIC="$ISABELLE_LOGIC"
PROGNAME="xemacs"
INITFILE="true"
WINDOWSYSTEM="true"
XSYMBOL=""
XSYMBOL_SETUP=true
XSYMBOL_FONTSIZE="12"
UNICODE=""

getoptions()
{
  OPTIND=1
  while getopts "I:L:P:U:X:f:g:k:l:m:p:u:w:x:" OPT
  do
    case "$OPT" in
      I)
        ISAR="$OPTARG"
        ;;
      L)
        KEYWORDS="$OPTARG"
        LOGIC="$OPTARG"
        ;;
      P)
        START_PG="$OPTARG"
        ;;
      U)
        UNICODE="$OPTARG"
        ;;
      X)
        XSYMBOL_SETUP="$OPTARG"
        ;;
      f)
        XSYMBOL_FONTSIZE="$OPTARG"
        ;;
      g)
        GEOMETRY="$OPTARG"
        ;;
      k)
        KEYWORDS="$OPTARG"
        ;;
      l)
        LOGIC="$OPTARG"
        ;;
      m)
        if [ -z "$ISABELLE_OPTIONS" ]; then
          ISABELLE_OPTIONS="-m $OPTARG"
        else
          ISABELLE_OPTIONS="$ISABELLE_OPTIONS -m $OPTARG"
        fi
        ;;
      p)
        PROGNAME="$OPTARG"
        ;;
      u)
        INITFILE="$OPTARG"
        ;;
      w)
        WINDOWSYSTEM="$OPTARG"
        ;;
      x)
        XSYMBOL="$OPTARG"
        ;;
      \?)
        usage
        ;;
    esac
  done
}

getoptions $PROOFGENERAL_OPTIONS

getoptions "$@"
shift $(($OPTIND - 1))


# args

if [ "$#" -eq 0 ]; then
  FILES="Scratch.thy"
else
  FILES=""
  while [ "$#" -gt 0 ]; do
    FILES="$FILES '$1'"
    shift
  done
fi


## smart X11 font installation

function checkfonts ()
{
  XLSFONTS=$(xlsfonts -fn "-xsymb-xsymb0-*" 2>&1) || return 1

  case "$XLSFONTS" in
    xlsfonts:*)
      return 1
      ;;
  esac

  return 0
}

function installfonts ()
{
  checkfonts "$XSYMBOL_PATTERN" || eval $XSYMBOL_INSTALLFONTS
}


## main

if [ "$START_PG" = false ]; then

  [ "$ISAR" = true ] && ISABELLE_OPTIONS="$ISABELLE_OPTIONS -I"
  exec "$ISABELLE" $ISABELLE_OPTIONS "$LOGIC"

else

  ARGS=""

  [ -n "$GEOMETRY" ] && ARGS="$ARGS -geometry '$GEOMETRY'"

  [ "$INITFILE" = false ] && ARGS="$ARGS -q"

  if [ "$WINDOWSYSTEM" = true -a -n "$DISPLAY" ]; then
    [ -n "$XSYMBOL_INSTALLFONTS" -a "$XSYMBOL_SETUP" = true ] && installfonts
  else
    ARGS="$ARGS -nw"
    XSYMBOL=false
  fi

  ARGS="$ARGS -l '$SUPER/isar/interface-setup.el'"

  if [ -n "$KEYWORDS" ]; then
    if [ -f "$ISABELLE_HOME_USER/etc/isar-keywords-$KEYWORDS.el" ]; then
      ARGS="$ARGS -l '$ISABELLE_HOME_USER/etc/isar-keywords-$KEYWORDS.el'"
    elif [ -f "$ISABELLE_HOME/etc/isar-keywords-$KEYWORDS.el" ]; then
      ARGS="$ARGS -l '$ISABELLE_HOME/etc/isar-keywords-$KEYWORDS.el'"
    else
      fail "No isar-keywords file for '$KEYWORDS'"
    fi
  elif [ -f "$ISABELLE_HOME_USER/etc/isar-keywords.el" ]; then
    ARGS="$ARGS -l '$ISABELLE_HOME_USER/etc/isar-keywords.el'"
  elif [ -f "$ISABELLE_HOME/etc/isar-keywords.el" ]; then
    ARGS="$ARGS -l '$ISABELLE_HOME/etc/isar-keywords.el'"
  fi

  for FILE in "$ISABELLE_HOME/etc/proofgeneral-settings.el" \
      "$ISABELLE_HOME_USER/etc/proofgeneral-settings.el"
  do
    [ -f "$FILE" ] && ARGS="$ARGS -l '$FILE'"
  done

  case "$LOGIC" in
    /*)
      ;;
    */*)
      LOGIC="$(pwd -P)/$LOGIC"
      ;;
  esac

  export PROOFGENERAL_HOME="$SUPER"
  export PROOFGENERAL_ASSISTANTS="isar"
  export PROOFGENERAL_LOGIC="$LOGIC"
  export PROOFGENERAL_XSYMBOL="$XSYMBOL"
  export PROOFGENERAL_UNICODE="$UNICODE"

  export ISABELLE_OPTIONS XSYMBOL_FONTSIZE

  eval exec "$PROGNAME" "$ARGS" "$FILES"

fi