src/Pure/System/isabelle_system.scala
author wenzelm
Mon, 10 May 2010 22:27:58 +0200
changeset 36788 1fd4f28e6ce1
parent 36785 55025bd6605f
child 36991 ccb8da7f76e6
permissions -rw-r--r--
more convenient get_font;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30175
62ba490670e8 fixed headers;
wenzelm
parents: 30174
diff changeset
     1
/*  Title:      Pure/System/isabelle_system.scala
27919
1eb8a3902d49 Isabelle system support.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
1eb8a3902d49 Isabelle system support.
wenzelm
parents:
diff changeset
     3
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
     4
Isabelle system support (settings environment etc.).
27919
1eb8a3902d49 Isabelle system support.
wenzelm
parents:
diff changeset
     5
*/
1eb8a3902d49 Isabelle system support.
wenzelm
parents:
diff changeset
     6
1eb8a3902d49 Isabelle system support.
wenzelm
parents:
diff changeset
     7
package isabelle
1eb8a3902d49 Isabelle system support.
wenzelm
parents:
diff changeset
     8
31520
0a99c8716312 simplified IsabelleSystem.platform_path for cygwin;
wenzelm
parents: 31500
diff changeset
     9
import java.util.regex.Pattern
31820
8199c9a42941 added isabelle_path;
wenzelm
parents: 31818
diff changeset
    10
import java.util.Locale
34198
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
    11
import java.io.{BufferedWriter, OutputStreamWriter, FileOutputStream,
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
    12
  BufferedInputStream, FileInputStream, BufferedReader, InputStreamReader,
34162
610ec1e0c848 added plain read_file;
wenzelm
parents: 34137
diff changeset
    13
  File, IOException}
34024
0bae8702a7c5 basic support for IsabelleText fonts;
wenzelm
parents: 32450
diff changeset
    14
import java.awt.{GraphicsEnvironment, Font}
28063
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28057
diff changeset
    15
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28057
diff changeset
    16
import scala.io.Source
31520
0a99c8716312 simplified IsabelleSystem.platform_path for cygwin;
wenzelm
parents: 31500
diff changeset
    17
import scala.util.matching.Regex
34163
wenzelm
parents: 34162
diff changeset
    18
import scala.collection.mutable
27936
947cb8e3d313 added get_setting;
wenzelm
parents: 27919
diff changeset
    19
27919
1eb8a3902d49 Isabelle system support.
wenzelm
parents:
diff changeset
    20
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    21
class Isabelle_System extends Standard_System
31498
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
    22
{
31796
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
    23
  /** Isabelle environment **/
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
    24
31498
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
    25
  private val environment: Map[String, String] =
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
    26
  {
36011
3ff725ac13a4 adapted to Scala 2.8.0 Beta1 -- with notable changes to scala.collection;
wenzelm
parents: 35023
diff changeset
    27
    import scala.collection.JavaConversions._
31498
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
    28
36193
067a01827fca improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents: 36136
diff changeset
    29
    val env0 = Map(java.lang.System.getenv.toList: _*) +
067a01827fca improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents: 36136
diff changeset
    30
      ("THIS_JAVA" -> this_java())
27919
1eb8a3902d49 Isabelle system support.
wenzelm
parents:
diff changeset
    31
31927
9a0f28bcc81d init isabelle home from existing setting or hint via system property;
wenzelm
parents: 31829
diff changeset
    32
    val isabelle_home =
9a0f28bcc81d init isabelle home from existing setting or hint via system property;
wenzelm
parents: 31829
diff changeset
    33
      env0.get("ISABELLE_HOME") match {
31498
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
    34
        case None | Some("") =>
31927
9a0f28bcc81d init isabelle home from existing setting or hint via system property;
wenzelm
parents: 31829
diff changeset
    35
          val path = java.lang.System.getProperty("isabelle.home")
9a0f28bcc81d init isabelle home from existing setting or hint via system property;
wenzelm
parents: 31829
diff changeset
    36
          if (path == null || path == "") error("Unknown Isabelle home directory")
9a0f28bcc81d init isabelle home from existing setting or hint via system property;
wenzelm
parents: 31829
diff changeset
    37
          else path
9a0f28bcc81d init isabelle home from existing setting or hint via system property;
wenzelm
parents: 31829
diff changeset
    38
        case Some(path) => path
31498
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
    39
      }
29177
0e88d33e8d19 maintain initial process environment;
wenzelm
parents: 29174
diff changeset
    40
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    41
    Standard_System.with_tmp_file("settings") { dump =>
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    42
        val shell_prefix =
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    43
          if (Platform.is_windows) List(platform_root + "\\bin\\bash", "-l") else Nil
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    44
        val cmdline =
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    45
          shell_prefix ::: List(isabelle_home + "/bin/isabelle", "getenv", "-d", dump.toString)
34258
e936d3c35ce0 Standard_System.raw_exec;
wenzelm
parents: 34219
diff changeset
    46
        val (output, rc) = Standard_System.raw_exec(null, env0, true, cmdline: _*)
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    47
        if (rc != 0) error(output)
31498
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
    48
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    49
        val entries =
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    50
          for (entry <- Source.fromFile(dump).mkString split "\0" if entry != "") yield {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    51
            val i = entry.indexOf('=')
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    52
            if (i <= 0) (entry -> "")
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    53
            else (entry.substring(0, i) -> entry.substring(i + 1))
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    54
          }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    55
        Map(entries: _*) +
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    56
          ("HOME" -> java.lang.System.getenv("HOME")) +
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    57
          ("PATH" -> java.lang.System.getenv("PATH"))
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
    58
      }
27953
b2003c98897c added getenv;
wenzelm
parents: 27936
diff changeset
    59
  }
27919
1eb8a3902d49 Isabelle system support.
wenzelm
parents:
diff changeset
    60
31796
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
    61
34204
wenzelm
parents: 34201
diff changeset
    62
  /* external processes */
wenzelm
parents: 34201
diff changeset
    63
wenzelm
parents: 34201
diff changeset
    64
  def execute(redirect: Boolean, args: String*): Process =
wenzelm
parents: 34201
diff changeset
    65
  {
wenzelm
parents: 34201
diff changeset
    66
    val cmdline =
wenzelm
parents: 34201
diff changeset
    67
      if (Platform.is_windows) List(platform_root + "\\bin\\env.exe") ++ args
wenzelm
parents: 34201
diff changeset
    68
      else args
34219
d37cfca69887 Standard_System.raw_execute: optional cwd;
wenzelm
parents: 34204
diff changeset
    69
    Standard_System.raw_execute(null, environment, redirect, cmdline: _*)
34204
wenzelm
parents: 34201
diff changeset
    70
  }
wenzelm
parents: 34201
diff changeset
    71
wenzelm
parents: 34201
diff changeset
    72
31796
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
    73
  /* getenv */
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
    74
31498
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
    75
  def getenv(name: String): String =
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
    76
    environment.getOrElse(if (name == "HOME") "HOME_JVM" else name, "")
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
    77
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
    78
  def getenv_strict(name: String): String =
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
    79
  {
31234
6ce6801129de getenv_strict needs to be based on getenv (accidentally broken in 0e88d33e8d19);
wenzelm
parents: 30175
diff changeset
    80
    val value = getenv(name)
27993
6dd90ef9f927 simplified exceptions: use plain error function / RuntimeException;
wenzelm
parents: 27974
diff changeset
    81
    if (value != "") value else error("Undefined environment variable: " + name)
27919
1eb8a3902d49 Isabelle system support.
wenzelm
parents:
diff changeset
    82
  }
1eb8a3902d49 Isabelle system support.
wenzelm
parents:
diff changeset
    83
31703
4e6064759aeb added toString;
wenzelm
parents: 31520
diff changeset
    84
  override def toString = getenv("ISABELLE_HOME")
4e6064759aeb added toString;
wenzelm
parents: 31520
diff changeset
    85
27936
947cb8e3d313 added get_setting;
wenzelm
parents: 27919
diff changeset
    86
31796
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
    87
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
    88
  /** file path specifications **/
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
    89
31820
8199c9a42941 added isabelle_path;
wenzelm
parents: 31818
diff changeset
    90
  /* expand_path */
31796
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
    91
36136
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
    92
  private val Root = new Regex("(//+[^/]*|/)(.*)")
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
    93
  private val Only_Root = new Regex("//+[^/]*|/")
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
    94
31820
8199c9a42941 added isabelle_path;
wenzelm
parents: 31818
diff changeset
    95
  def expand_path(isabelle_path: String): String =
31796
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
    96
  {
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
    97
    val result_path = new StringBuilder
36136
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
    98
    def init(path: String): String =
31796
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
    99
    {
36136
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   100
      path match {
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   101
        case Root(root, rest) =>
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   102
          result_path.clear
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   103
          result_path ++= root
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   104
          rest
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   105
        case _ => path
31796
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   106
      }
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   107
    }
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   108
    def append(path: String)
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   109
    {
36136
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   110
      val rest = init(path)
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   111
      for (p <- rest.split("/") if p != "" && p != ".") {
31803
4aabae982988 expand_path: handle parent (..) elements;
wenzelm
parents: 31796
diff changeset
   112
        if (p == "..") {
4aabae982988 expand_path: handle parent (..) elements;
wenzelm
parents: 31796
diff changeset
   113
          val result = result_path.toString
36136
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   114
          if (!Only_Root.pattern.matcher(result).matches) {
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   115
            val i = result.lastIndexOf("/")
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   116
            if (result == "")
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   117
              result_path ++= ".."
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   118
            else if (result.substring(i + 1) == "..")
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   119
              result_path ++= "/.."
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   120
            else if (i < 0)
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   121
              result_path.length = 0
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   122
            else
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   123
              result_path.length = i
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   124
          }
31803
4aabae982988 expand_path: handle parent (..) elements;
wenzelm
parents: 31796
diff changeset
   125
        }
4aabae982988 expand_path: handle parent (..) elements;
wenzelm
parents: 31796
diff changeset
   126
        else {
4aabae982988 expand_path: handle parent (..) elements;
wenzelm
parents: 31796
diff changeset
   127
          val len = result_path.length
4aabae982988 expand_path: handle parent (..) elements;
wenzelm
parents: 31796
diff changeset
   128
          if (len > 0 && result_path(len - 1) != '/')
4aabae982988 expand_path: handle parent (..) elements;
wenzelm
parents: 31796
diff changeset
   129
            result_path += '/'
4aabae982988 expand_path: handle parent (..) elements;
wenzelm
parents: 31796
diff changeset
   130
          result_path ++= p
4aabae982988 expand_path: handle parent (..) elements;
wenzelm
parents: 31796
diff changeset
   131
        }
31796
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   132
      }
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   133
    }
36136
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   134
    val rest = init(isabelle_path)
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36012
diff changeset
   135
    for (p <- rest.split("/")) {
31796
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   136
      if (p.startsWith("$")) append(getenv_strict(p.substring(1)))
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   137
      else if (p == "~") append(getenv_strict("HOME"))
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   138
      else if (p == "~~") append(getenv_strict("ISABELLE_HOME"))
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   139
      else append(p)
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   140
    }
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   141
    result_path.toString
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   142
  }
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   143
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   144
31820
8199c9a42941 added isabelle_path;
wenzelm
parents: 31818
diff changeset
   145
  /* platform_path */
27936
947cb8e3d313 added get_setting;
wenzelm
parents: 27919
diff changeset
   146
31820
8199c9a42941 added isabelle_path;
wenzelm
parents: 31818
diff changeset
   147
  def platform_path(isabelle_path: String): String =
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
   148
    jvm_path(expand_path(isabelle_path))
27953
b2003c98897c added getenv;
wenzelm
parents: 27936
diff changeset
   149
31498
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
   150
  def platform_file(path: String) = new File(platform_path(path))
29152
89b0803404d7 added platform_file;
wenzelm
parents: 29140
diff changeset
   151
27953
b2003c98897c added getenv;
wenzelm
parents: 27936
diff changeset
   152
31436
dde1b4d1c95b retrieve ML source files;
wenzelm
parents: 31234
diff changeset
   153
  /* source files */
dde1b4d1c95b retrieve ML source files;
wenzelm
parents: 31234
diff changeset
   154
dde1b4d1c95b retrieve ML source files;
wenzelm
parents: 31234
diff changeset
   155
  private def try_file(file: File) = if (file.isFile) Some(file) else None
dde1b4d1c95b retrieve ML source files;
wenzelm
parents: 31234
diff changeset
   156
31498
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
   157
  def source_file(path: String): Option[File] =
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
   158
  {
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
   159
    if (path.startsWith("/") || path == "")
31436
dde1b4d1c95b retrieve ML source files;
wenzelm
parents: 31234
diff changeset
   160
      try_file(platform_file(path))
dde1b4d1c95b retrieve ML source files;
wenzelm
parents: 31234
diff changeset
   161
    else {
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
   162
      val pure_file = platform_file("$ISABELLE_HOME/src/Pure/" + path)
31436
dde1b4d1c95b retrieve ML source files;
wenzelm
parents: 31234
diff changeset
   163
      if (pure_file.isFile) Some(pure_file)
dde1b4d1c95b retrieve ML source files;
wenzelm
parents: 31234
diff changeset
   164
      else if (getenv("ML_SOURCES") != "")
dde1b4d1c95b retrieve ML source files;
wenzelm
parents: 31234
diff changeset
   165
        try_file(platform_file("$ML_SOURCES/" + path))
dde1b4d1c95b retrieve ML source files;
wenzelm
parents: 31234
diff changeset
   166
      else None
dde1b4d1c95b retrieve ML source files;
wenzelm
parents: 31234
diff changeset
   167
    }
dde1b4d1c95b retrieve ML source files;
wenzelm
parents: 31234
diff changeset
   168
  }
dde1b4d1c95b retrieve ML source files;
wenzelm
parents: 31234
diff changeset
   169
dde1b4d1c95b retrieve ML source files;
wenzelm
parents: 31234
diff changeset
   170
32450
375db037f4d2 misc tuning;
wenzelm
parents: 32328
diff changeset
   171
31796
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   172
  /** system tools **/
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   173
35010
d6e492cea6e4 renamed system/system_out to bash/bash_output -- to emphasized that this is really GNU bash, not some undefined POSIX sh;
wenzelm
parents: 35006
diff changeset
   174
  def bash_output(script: String): (String, Int) =
34198
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   175
  {
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
   176
    Standard_System.with_tmp_file("isabelle_script") { script_file =>
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
   177
      Standard_System.with_tmp_file("isabelle_pid") { pid_file =>
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
   178
        Standard_System.with_tmp_file("isabelle_output") { output_file =>
34198
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   179
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
   180
          Standard_System.write_file(script_file, script)
34198
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   181
35023
16f9877abf0b modernized perl scripts: prefer standalone executables;
wenzelm
parents: 35010
diff changeset
   182
          val proc = execute(true, expand_path("$ISABELLE_HOME/lib/scripts/bash"), "group",
34198
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   183
            script_file.getPath, pid_file.getPath, output_file.getPath)
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   184
34199
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   185
          def kill(strict: Boolean) =
34198
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   186
          {
34199
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   187
            val pid =
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
   188
              try { Some(Standard_System.read_file(pid_file)) }
34199
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   189
              catch { case _: IOException => None }
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   190
            if (pid.isDefined) {
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   191
              var running = true
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   192
              var count = 10
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   193
              while (running && count > 0) {
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   194
                if (execute(true, "kill", "-INT", "-" + pid.get).waitFor != 0)
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   195
                  running = false
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   196
                else {
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   197
                  Thread.sleep(100)
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   198
                  if (!strict) count -= 1
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   199
                }
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   200
              }
34198
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   201
            }
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   202
          }
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   203
34199
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   204
          val shutdown_hook = new Thread { override def run = kill(true) }
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
   205
          Runtime.getRuntime.addShutdownHook(shutdown_hook)  // FIXME tmp files during shutdown?!?
34198
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   206
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   207
          def cleanup() =
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   208
            try { Runtime.getRuntime.removeShutdownHook(shutdown_hook) }
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   209
            catch { case _: IllegalStateException => }
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   210
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   211
          val rc =
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   212
            try {
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   213
              try { proc.waitFor }  // FIXME read stderr (!??)
34199
1e40a1009ac1 system shutdown hook: strict kill;
wenzelm
parents: 34198
diff changeset
   214
              catch { case e: InterruptedException => Thread.interrupted; kill(false); throw e }
34198
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   215
            }
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   216
            finally {
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   217
              proc.getOutputStream.close
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   218
              proc.getInputStream.close
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   219
              proc.getErrorStream.close
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   220
              proc.destroy
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   221
              cleanup()
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   222
            }
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   223
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   224
          val output =
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
   225
            try { Standard_System.read_file(output_file) }
34198
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   226
            catch { case _: IOException => "" }
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   227
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   228
          (output, rc)
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   229
        }
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   230
      }
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   231
    }
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   232
  }
ff5486262cd6 moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents: 34196
diff changeset
   233
31818
f698f76a3713 builtin isabelle_tool for ML and Scala -- avoids excessive shell script (especially important for Cygwin);
wenzelm
parents: 31803
diff changeset
   234
  def isabelle_tool(name: String, args: String*): (String, Int) =
31498
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
   235
  {
34200
wenzelm
parents: 34199
diff changeset
   236
    getenv_strict("ISABELLE_TOOLS").split(":").find { dir =>
31818
f698f76a3713 builtin isabelle_tool for ML and Scala -- avoids excessive shell script (especially important for Cygwin);
wenzelm
parents: 31803
diff changeset
   237
      val file = platform_file(dir + "/" + name)
34025
7996b488a9b5 depend on Java 1.6 after all;
wenzelm
parents: 34024
diff changeset
   238
      try { file.isFile && file.canRead && file.canExecute }
31818
f698f76a3713 builtin isabelle_tool for ML and Scala -- avoids excessive shell script (especially important for Cygwin);
wenzelm
parents: 31803
diff changeset
   239
      catch { case _: SecurityException => false }
34200
wenzelm
parents: 34199
diff changeset
   240
    } match {
31818
f698f76a3713 builtin isabelle_tool for ML and Scala -- avoids excessive shell script (especially important for Cygwin);
wenzelm
parents: 31803
diff changeset
   241
      case Some(dir) =>
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents: 34200
diff changeset
   242
        Standard_System.process_output(
34195
d58da36d1a30 isabelle_tool: apply platform_path only once;
wenzelm
parents: 34194
diff changeset
   243
          execute(true, (List(expand_path(dir + "/" + name)) ++ args): _*))
31818
f698f76a3713 builtin isabelle_tool for ML and Scala -- avoids excessive shell script (especially important for Cygwin);
wenzelm
parents: 31803
diff changeset
   244
      case None => ("Unknown Isabelle tool: " + name, 2)
f698f76a3713 builtin isabelle_tool for ML and Scala -- avoids excessive shell script (especially important for Cygwin);
wenzelm
parents: 31803
diff changeset
   245
    }
28063
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28057
diff changeset
   246
  }
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28057
diff changeset
   247
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28057
diff changeset
   248
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28057
diff changeset
   249
  /* named pipes */
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28057
diff changeset
   250
31498
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
   251
  def mk_fifo(): String =
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
   252
  {
28496
4cff10648928 renamed isatool to isabelle_tool in programming interfaces;
wenzelm
parents: 28063
diff changeset
   253
    val (result, rc) = isabelle_tool("mkfifo")
28063
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28057
diff changeset
   254
    if (rc == 0) result.trim
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28057
diff changeset
   255
    else error(result)
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28057
diff changeset
   256
  }
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28057
diff changeset
   257
31498
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
   258
  def rm_fifo(fifo: String)
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
   259
  {
28496
4cff10648928 renamed isatool to isabelle_tool in programming interfaces;
wenzelm
parents: 28063
diff changeset
   260
    val (result, rc) = isabelle_tool("rmfifo", fifo)
28063
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28057
diff changeset
   261
    if (rc != 0) error(result)
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28057
diff changeset
   262
  }
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28057
diff changeset
   263
34100
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 34078
diff changeset
   264
  def fifo_stream(fifo: String): BufferedInputStream =
31498
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
   265
  {
29177
0e88d33e8d19 maintain initial process environment;
wenzelm
parents: 29174
diff changeset
   266
    // blocks until writer is ready
0e88d33e8d19 maintain initial process environment;
wenzelm
parents: 29174
diff changeset
   267
    val stream =
34194
001321ca185c slightly more paranoid cleanup of process (cf. http://kylecartmell.com/?p=9 "Five Common java.lang.Process Pitfalls");
wenzelm
parents: 34186
diff changeset
   268
      if (Platform.is_windows) {
001321ca185c slightly more paranoid cleanup of process (cf. http://kylecartmell.com/?p=9 "Five Common java.lang.Process Pitfalls");
wenzelm
parents: 34186
diff changeset
   269
        val proc = execute(false, "cat", fifo)
001321ca185c slightly more paranoid cleanup of process (cf. http://kylecartmell.com/?p=9 "Five Common java.lang.Process Pitfalls");
wenzelm
parents: 34186
diff changeset
   270
        proc.getOutputStream.close
001321ca185c slightly more paranoid cleanup of process (cf. http://kylecartmell.com/?p=9 "Five Common java.lang.Process Pitfalls");
wenzelm
parents: 34186
diff changeset
   271
        proc.getErrorStream.close
001321ca185c slightly more paranoid cleanup of process (cf. http://kylecartmell.com/?p=9 "Five Common java.lang.Process Pitfalls");
wenzelm
parents: 34186
diff changeset
   272
        proc.getInputStream
001321ca185c slightly more paranoid cleanup of process (cf. http://kylecartmell.com/?p=9 "Five Common java.lang.Process Pitfalls");
wenzelm
parents: 34186
diff changeset
   273
      }
29177
0e88d33e8d19 maintain initial process environment;
wenzelm
parents: 29174
diff changeset
   274
      else new FileInputStream(fifo)
34100
ea24958c2af5 fifo: raw byte stream;
wenzelm
parents: 34078
diff changeset
   275
    new BufferedInputStream(stream)
29177
0e88d33e8d19 maintain initial process environment;
wenzelm
parents: 29174
diff changeset
   276
  }
28063
3533485fc7b8 IsabelleSystem.mk_fifo, IsabelleSystem.rm_fifo;
wenzelm
parents: 28057
diff changeset
   277
29152
89b0803404d7 added platform_file;
wenzelm
parents: 29140
diff changeset
   278
32450
375db037f4d2 misc tuning;
wenzelm
parents: 32328
diff changeset
   279
31796
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   280
  /** Isabelle resources **/
117300d72398 renamed IsabelleSystem to Isabelle_System;
wenzelm
parents: 31704
diff changeset
   281
32328
f2fd9da84bac added Isabelle_System.components;
wenzelm
parents: 31927
diff changeset
   282
  /* components */
f2fd9da84bac added Isabelle_System.components;
wenzelm
parents: 31927
diff changeset
   283
f2fd9da84bac added Isabelle_System.components;
wenzelm
parents: 31927
diff changeset
   284
  def components(): List[String] =
f2fd9da84bac added Isabelle_System.components;
wenzelm
parents: 31927
diff changeset
   285
    getenv("ISABELLE_COMPONENTS").split(":").toList
f2fd9da84bac added Isabelle_System.components;
wenzelm
parents: 31927
diff changeset
   286
f2fd9da84bac added Isabelle_System.components;
wenzelm
parents: 31927
diff changeset
   287
29152
89b0803404d7 added platform_file;
wenzelm
parents: 29140
diff changeset
   288
  /* find logics */
89b0803404d7 added platform_file;
wenzelm
parents: 29140
diff changeset
   289
31498
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
   290
  def find_logics(): List[String] =
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
   291
  {
29152
89b0803404d7 added platform_file;
wenzelm
parents: 29140
diff changeset
   292
    val ml_ident = getenv_strict("ML_IDENTIFIER")
34163
wenzelm
parents: 34162
diff changeset
   293
    val logics = new mutable.ListBuffer[String]
29152
89b0803404d7 added platform_file;
wenzelm
parents: 29140
diff changeset
   294
    for (dir <- getenv_strict("ISABELLE_PATH").split(":")) {
89b0803404d7 added platform_file;
wenzelm
parents: 29140
diff changeset
   295
      val files = platform_file(dir + "/" + ml_ident).listFiles()
89b0803404d7 added platform_file;
wenzelm
parents: 29140
diff changeset
   296
      if (files != null) {
89b0803404d7 added platform_file;
wenzelm
parents: 29140
diff changeset
   297
        for (file <- files if file.isFile) logics += file.getName
89b0803404d7 added platform_file;
wenzelm
parents: 29140
diff changeset
   298
      }
89b0803404d7 added platform_file;
wenzelm
parents: 29140
diff changeset
   299
    }
36012
0614676f14d4 replaced some deprecated methods;
wenzelm
parents: 36011
diff changeset
   300
    logics.toList.sortWith(_ < _)
29152
89b0803404d7 added platform_file;
wenzelm
parents: 29140
diff changeset
   301
  }
29570
10fca82e688a IsabelleSystem: provide Symbol.Interpretation;
wenzelm
parents: 29180
diff changeset
   302
10fca82e688a IsabelleSystem: provide Symbol.Interpretation;
wenzelm
parents: 29180
diff changeset
   303
10fca82e688a IsabelleSystem: provide Symbol.Interpretation;
wenzelm
parents: 29180
diff changeset
   304
  /* symbols */
10fca82e688a IsabelleSystem: provide Symbol.Interpretation;
wenzelm
parents: 29180
diff changeset
   305
34137
6cc9a0cbaf55 refined some Symbol operations/signatures;
wenzelm
parents: 34100
diff changeset
   306
  private def read_symbols(path: String): List[String] =
31498
be0f7f4f9e12 static IsabelleSystem.charset;
wenzelm
parents: 31443
diff changeset
   307
  {
34195
d58da36d1a30 isabelle_tool: apply platform_path only once;
wenzelm
parents: 34194
diff changeset
   308
    val file = platform_file(path)
36784
cf36fd1e4cda explicit getLines(n) ensures platform-independence -- our files follow the POSIX standard, not DOS;
wenzelm
parents: 36193
diff changeset
   309
    if (file.isFile) Source.fromFile(file).getLines("\n").toList
34137
6cc9a0cbaf55 refined some Symbol operations/signatures;
wenzelm
parents: 34100
diff changeset
   310
    else Nil
29570
10fca82e688a IsabelleSystem: provide Symbol.Interpretation;
wenzelm
parents: 29180
diff changeset
   311
  }
10fca82e688a IsabelleSystem: provide Symbol.Interpretation;
wenzelm
parents: 29180
diff changeset
   312
  val symbols = new Symbol.Interpretation(
34137
6cc9a0cbaf55 refined some Symbol operations/signatures;
wenzelm
parents: 34100
diff changeset
   313
    read_symbols("$ISABELLE_HOME/etc/symbols") :::
29570
10fca82e688a IsabelleSystem: provide Symbol.Interpretation;
wenzelm
parents: 29180
diff changeset
   314
    read_symbols("$ISABELLE_HOME_USER/etc/symbols"))
34024
0bae8702a7c5 basic support for IsabelleText fonts;
wenzelm
parents: 32450
diff changeset
   315
0bae8702a7c5 basic support for IsabelleText fonts;
wenzelm
parents: 32450
diff changeset
   316
0bae8702a7c5 basic support for IsabelleText fonts;
wenzelm
parents: 32450
diff changeset
   317
  /* fonts */
0bae8702a7c5 basic support for IsabelleText fonts;
wenzelm
parents: 32450
diff changeset
   318
0bae8702a7c5 basic support for IsabelleText fonts;
wenzelm
parents: 32450
diff changeset
   319
  val font_family = "IsabelleText"
0bae8702a7c5 basic support for IsabelleText fonts;
wenzelm
parents: 32450
diff changeset
   320
36788
1fd4f28e6ce1 more convenient get_font;
wenzelm
parents: 36785
diff changeset
   321
  def get_font(size: Int = 1, bold: Boolean = false): Font =
36785
55025bd6605f more convenient get_font;
wenzelm
parents: 36784
diff changeset
   322
    new Font(font_family, if (bold) Font.BOLD else Font.PLAIN, size)
34024
0bae8702a7c5 basic support for IsabelleText fonts;
wenzelm
parents: 32450
diff changeset
   323
34044
09afb1d49fe7 slightly more robust and less ambitious version of install_fonts;
wenzelm
parents: 34027
diff changeset
   324
  def install_fonts()
09afb1d49fe7 slightly more robust and less ambitious version of install_fonts;
wenzelm
parents: 34027
diff changeset
   325
  {
35006
1ea6dba95b49 tuned font handling;
wenzelm
parents: 34258
diff changeset
   326
    def create_font(bold: Boolean): Font =
1ea6dba95b49 tuned font handling;
wenzelm
parents: 34258
diff changeset
   327
    {
1ea6dba95b49 tuned font handling;
wenzelm
parents: 34258
diff changeset
   328
      val name =
1ea6dba95b49 tuned font handling;
wenzelm
parents: 34258
diff changeset
   329
        if (bold) "$ISABELLE_HOME/lib/fonts/IsabelleTextBold.ttf"
1ea6dba95b49 tuned font handling;
wenzelm
parents: 34258
diff changeset
   330
        else "$ISABELLE_HOME/lib/fonts/IsabelleText.ttf"
1ea6dba95b49 tuned font handling;
wenzelm
parents: 34258
diff changeset
   331
      Font.createFont(Font.TRUETYPE_FONT, platform_file(name))
1ea6dba95b49 tuned font handling;
wenzelm
parents: 34258
diff changeset
   332
    }
36788
1fd4f28e6ce1 more convenient get_font;
wenzelm
parents: 36785
diff changeset
   333
    def check_font() = get_font().getFamily == font_family
35006
1ea6dba95b49 tuned font handling;
wenzelm
parents: 34258
diff changeset
   334
34044
09afb1d49fe7 slightly more robust and less ambitious version of install_fonts;
wenzelm
parents: 34027
diff changeset
   335
    if (!check_font()) {
35006
1ea6dba95b49 tuned font handling;
wenzelm
parents: 34258
diff changeset
   336
      val font = create_font(false)
1ea6dba95b49 tuned font handling;
wenzelm
parents: 34258
diff changeset
   337
      val bold_font = create_font(true)
1ea6dba95b49 tuned font handling;
wenzelm
parents: 34258
diff changeset
   338
34044
09afb1d49fe7 slightly more robust and less ambitious version of install_fonts;
wenzelm
parents: 34027
diff changeset
   339
      val ge = GraphicsEnvironment.getLocalGraphicsEnvironment()
35006
1ea6dba95b49 tuned font handling;
wenzelm
parents: 34258
diff changeset
   340
      ge.registerFont(font)
1ea6dba95b49 tuned font handling;
wenzelm
parents: 34258
diff changeset
   341
      // workaround strange problem with Apple's Java 1.6 font manager
1ea6dba95b49 tuned font handling;
wenzelm
parents: 34258
diff changeset
   342
      if (bold_font.getFamily == font_family) ge.registerFont(bold_font)
1ea6dba95b49 tuned font handling;
wenzelm
parents: 34258
diff changeset
   343
      if (!check_font()) error("Failed to install IsabelleText fonts")
34044
09afb1d49fe7 slightly more robust and less ambitious version of install_fonts;
wenzelm
parents: 34027
diff changeset
   344
    }
34024
0bae8702a7c5 basic support for IsabelleText fonts;
wenzelm
parents: 32450
diff changeset
   345
  }
27919
1eb8a3902d49 Isabelle system support.
wenzelm
parents:
diff changeset
   346
}