author | wenzelm |
Wed, 22 Sep 2010 12:52:35 +0200 | |
changeset 39584 | f2a10986e85a |
parent 39583 | c1e9c6dfeff8 |
child 39586 | ea8f3ea13a95 |
permissions | -rw-r--r-- |
30175 | 1 |
/* Title: Pure/System/isabelle_system.scala |
27919 | 2 |
Author: Makarius |
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 | 5 |
*/ |
6 |
||
7 |
package isabelle |
|
8 |
||
31520
0a99c8716312
simplified IsabelleSystem.platform_path for cygwin;
wenzelm
parents:
31500
diff
changeset
|
9 |
import java.util.regex.Pattern |
31820 | 10 |
import java.util.Locale |
39576
48baf61cb888
refined ML/Scala bash wrapper, based on more general lib/scripts/process;
wenzelm
parents:
39574
diff
changeset
|
11 |
import java.io.{InputStream, FileInputStream, OutputStream, FileOutputStream, File, |
39583
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
12 |
BufferedReader, InputStreamReader, BufferedWriter, OutputStreamWriter, IOException} |
34024 | 13 |
import java.awt.{GraphicsEnvironment, Font} |
37367 | 14 |
import java.awt.font.TextAttribute |
28063 | 15 |
|
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 | 18 |
import scala.collection.mutable |
27936 | 19 |
|
27919 | 20 |
|
37013
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
21 |
class Isabelle_System(this_isabelle_home: String) extends Standard_System |
31498 | 22 |
{ |
37013
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
23 |
def this() = this(null) |
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
24 |
|
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
25 |
|
31796 | 26 |
/** Isabelle environment **/ |
27 |
||
37013
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
28 |
/* |
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
29 |
isabelle_home precedence: |
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
30 |
(1) this_isabelle_home as explicit argument |
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
31 |
(2) ISABELLE_HOME process environment variable (e.g. inherited from running isabelle tool) |
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
32 |
(3) isabelle.home system property (e.g. via JVM application boot process) |
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
33 |
*/ |
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
34 |
|
31498 | 35 |
private val environment: Map[String, String] = |
36 |
{ |
|
36011
3ff725ac13a4
adapted to Scala 2.8.0 Beta1 -- with notable changes to scala.collection;
wenzelm
parents:
35023
diff
changeset
|
37 |
import scala.collection.JavaConversions._ |
31498 | 38 |
|
36193
067a01827fca
improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents:
36136
diff
changeset
|
39 |
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
|
40 |
("THIS_JAVA" -> this_java()) |
27919 | 41 |
|
31927
9a0f28bcc81d
init isabelle home from existing setting or hint via system property;
wenzelm
parents:
31829
diff
changeset
|
42 |
val isabelle_home = |
37013
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
43 |
if (this_isabelle_home != null) this_isabelle_home |
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
44 |
else |
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
45 |
env0.get("ISABELLE_HOME") match { |
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
46 |
case None | Some("") => |
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
47 |
val path = java.lang.System.getProperty("isabelle.home") |
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
48 |
if (path == null || path == "") error("Unknown Isabelle home directory") |
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
49 |
else path |
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
50 |
case Some(path) => path |
641923374eba
Isabelle_System: allow explicit isabelle_home argument;
wenzelm
parents:
36991
diff
changeset
|
51 |
} |
29177 | 52 |
|
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
34200
diff
changeset
|
53 |
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
|
54 |
val shell_prefix = |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
34200
diff
changeset
|
55 |
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
|
56 |
val cmdline = |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
34200
diff
changeset
|
57 |
shell_prefix ::: List(isabelle_home + "/bin/isabelle", "getenv", "-d", dump.toString) |
34258 | 58 |
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
|
59 |
if (rc != 0) error(output) |
31498 | 60 |
|
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
34200
diff
changeset
|
61 |
val entries = |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
34200
diff
changeset
|
62 |
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
|
63 |
val i = entry.indexOf('=') |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
34200
diff
changeset
|
64 |
if (i <= 0) (entry -> "") |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
34200
diff
changeset
|
65 |
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
|
66 |
} |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
34200
diff
changeset
|
67 |
Map(entries: _*) + |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
34200
diff
changeset
|
68 |
("HOME" -> java.lang.System.getenv("HOME")) + |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
34200
diff
changeset
|
69 |
("PATH" -> java.lang.System.getenv("PATH")) |
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
34200
diff
changeset
|
70 |
} |
27953 | 71 |
} |
27919 | 72 |
|
31796 | 73 |
|
74 |
/* getenv */ |
|
75 |
||
31498 | 76 |
def getenv(name: String): String = |
77 |
environment.getOrElse(if (name == "HOME") "HOME_JVM" else name, "") |
|
78 |
||
79 |
def getenv_strict(name: String): String = |
|
80 |
{ |
|
31234
6ce6801129de
getenv_strict needs to be based on getenv (accidentally broken in 0e88d33e8d19);
wenzelm
parents:
30175
diff
changeset
|
81 |
val value = getenv(name) |
27993
6dd90ef9f927
simplified exceptions: use plain error function / RuntimeException;
wenzelm
parents:
27974
diff
changeset
|
82 |
if (value != "") value else error("Undefined environment variable: " + name) |
27919 | 83 |
} |
84 |
||
37058
c47653f3ec14
rendering information and style sheets via settings;
wenzelm
parents:
37013
diff
changeset
|
85 |
override def toString = getenv_strict("ISABELLE_HOME") |
31703 | 86 |
|
27936 | 87 |
|
31796 | 88 |
|
89 |
/** file path specifications **/ |
|
90 |
||
31820 | 91 |
/* expand_path */ |
31796 | 92 |
|
36136
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
93 |
private val Root = new Regex("(//+[^/]*|/)(.*)") |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
94 |
private val Only_Root = new Regex("//+[^/]*|/") |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
95 |
|
31820 | 96 |
def expand_path(isabelle_path: String): String = |
31796 | 97 |
{ |
98 |
val result_path = new StringBuilder |
|
36136
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
99 |
def init(path: String): String = |
31796 | 100 |
{ |
36136
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
101 |
path match { |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
102 |
case Root(root, rest) => |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
103 |
result_path.clear |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
104 |
result_path ++= root |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
105 |
rest |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
106 |
case _ => path |
31796 | 107 |
} |
108 |
} |
|
109 |
def append(path: String) |
|
110 |
{ |
|
36136
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
111 |
val rest = init(path) |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
112 |
for (p <- rest.split("/") if p != "" && p != ".") { |
31803 | 113 |
if (p == "..") { |
114 |
val result = result_path.toString |
|
36136
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
115 |
if (!Only_Root.pattern.matcher(result).matches) { |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
116 |
val i = result.lastIndexOf("/") |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
117 |
if (result == "") |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
118 |
result_path ++= ".." |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
119 |
else if (result.substring(i + 1) == "..") |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
120 |
result_path ++= "/.." |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
121 |
else if (i < 0) |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
122 |
result_path.length = 0 |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
123 |
else |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
124 |
result_path.length = i |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
125 |
} |
31803 | 126 |
} |
127 |
else { |
|
128 |
val len = result_path.length |
|
129 |
if (len > 0 && result_path(len - 1) != '/') |
|
130 |
result_path += '/' |
|
131 |
result_path ++= p |
|
132 |
} |
|
31796 | 133 |
} |
134 |
} |
|
36136
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
135 |
val rest = init(isabelle_path) |
89b1a136edef
more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents:
36012
diff
changeset
|
136 |
for (p <- rest.split("/")) { |
31796 | 137 |
if (p.startsWith("$")) append(getenv_strict(p.substring(1))) |
138 |
else if (p == "~") append(getenv_strict("HOME")) |
|
139 |
else if (p == "~~") append(getenv_strict("ISABELLE_HOME")) |
|
140 |
else append(p) |
|
141 |
} |
|
142 |
result_path.toString |
|
143 |
} |
|
144 |
||
145 |
||
31820 | 146 |
/* platform_path */ |
27936 | 147 |
|
31820 | 148 |
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
|
149 |
jvm_path(expand_path(isabelle_path)) |
27953 | 150 |
|
31498 | 151 |
def platform_file(path: String) = new File(platform_path(path)) |
29152 | 152 |
|
27953 | 153 |
|
36991 | 154 |
/* try_read */ |
155 |
||
37058
c47653f3ec14
rendering information and style sheets via settings;
wenzelm
parents:
37013
diff
changeset
|
156 |
def try_read(paths: Seq[String]): String = |
36991 | 157 |
{ |
37058
c47653f3ec14
rendering information and style sheets via settings;
wenzelm
parents:
37013
diff
changeset
|
158 |
val buf = new StringBuilder |
c47653f3ec14
rendering information and style sheets via settings;
wenzelm
parents:
37013
diff
changeset
|
159 |
for { |
c47653f3ec14
rendering information and style sheets via settings;
wenzelm
parents:
37013
diff
changeset
|
160 |
path <- paths |
c47653f3ec14
rendering information and style sheets via settings;
wenzelm
parents:
37013
diff
changeset
|
161 |
file = platform_file(path) if file.isFile |
c47653f3ec14
rendering information and style sheets via settings;
wenzelm
parents:
37013
diff
changeset
|
162 |
c <- (Source.fromFile(file) ++ Iterator.single('\n')) |
c47653f3ec14
rendering information and style sheets via settings;
wenzelm
parents:
37013
diff
changeset
|
163 |
} buf.append(c) |
c47653f3ec14
rendering information and style sheets via settings;
wenzelm
parents:
37013
diff
changeset
|
164 |
buf.toString |
36991 | 165 |
} |
166 |
||
167 |
||
31436 | 168 |
/* source files */ |
169 |
||
170 |
private def try_file(file: File) = if (file.isFile) Some(file) else None |
|
171 |
||
31498 | 172 |
def source_file(path: String): Option[File] = |
173 |
{ |
|
174 |
if (path.startsWith("/") || path == "") |
|
31436 | 175 |
try_file(platform_file(path)) |
176 |
else { |
|
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
34200
diff
changeset
|
177 |
val pure_file = platform_file("$ISABELLE_HOME/src/Pure/" + path) |
31436 | 178 |
if (pure_file.isFile) Some(pure_file) |
179 |
else if (getenv("ML_SOURCES") != "") |
|
180 |
try_file(platform_file("$ML_SOURCES/" + path)) |
|
181 |
else None |
|
182 |
} |
|
183 |
} |
|
184 |
||
185 |
||
32450 | 186 |
|
39583
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
187 |
/** external processes **/ |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
188 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
189 |
/* plain execute */ |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
190 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
191 |
def execute(redirect: Boolean, args: String*): Process = |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
192 |
{ |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
193 |
val cmdline = |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
194 |
if (Platform.is_windows) List(platform_root + "\\bin\\env.exe") ++ args |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
195 |
else args |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
196 |
Standard_System.raw_execute(null, environment, redirect, cmdline: _*) |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
197 |
} |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
198 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
199 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
200 |
/* managed process */ |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
201 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
202 |
class Managed_Process(redirect: Boolean, args: String*) |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
203 |
{ |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
204 |
private val params = |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
205 |
List(expand_path("$ISABELLE_HOME/lib/scripts/process"), "group", "-", "no_script") |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
206 |
private val proc = execute(redirect, (params ++ args):_*) |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
207 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
208 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
209 |
// channels |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
210 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
211 |
val stdin: BufferedWriter = |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
212 |
new BufferedWriter(new OutputStreamWriter(proc.getOutputStream, Standard_System.charset)) |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
213 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
214 |
val stdout: BufferedReader = |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
215 |
new BufferedReader(new InputStreamReader(proc.getInputStream, Standard_System.charset)) |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
216 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
217 |
val stderr: BufferedReader = |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
218 |
new BufferedReader(new InputStreamReader(proc.getErrorStream, Standard_System.charset)) |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
219 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
220 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
221 |
// signals |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
222 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
223 |
private val pid = stdout.readLine |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
224 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
225 |
private def kill(signal: String): Boolean = |
39584
f2a10986e85a
more robust Managed_Process.kill: check after sending signal;
wenzelm
parents:
39583
diff
changeset
|
226 |
{ |
f2a10986e85a
more robust Managed_Process.kill: check after sending signal;
wenzelm
parents:
39583
diff
changeset
|
227 |
execute(true, "kill", "-" + signal, "-" + pid).waitFor |
f2a10986e85a
more robust Managed_Process.kill: check after sending signal;
wenzelm
parents:
39583
diff
changeset
|
228 |
execute(true, "kill", "-0", "-" + pid).waitFor == 0 |
f2a10986e85a
more robust Managed_Process.kill: check after sending signal;
wenzelm
parents:
39583
diff
changeset
|
229 |
} |
39583
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
230 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
231 |
private def multi_kill(signal: String): Boolean = |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
232 |
{ |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
233 |
var running = true |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
234 |
var count = 10 |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
235 |
while (running && count > 0) { |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
236 |
if (kill(signal)) { |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
237 |
Thread.sleep(100) |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
238 |
count -= 1 |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
239 |
} |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
240 |
else running = false |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
241 |
} |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
242 |
running |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
243 |
} |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
244 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
245 |
def interrupt() { multi_kill("INT") } |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
246 |
def terminate() { multi_kill("INT") && multi_kill("TERM") && kill("KILL"); proc.destroy } |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
247 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
248 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
249 |
// JVM shutdown hook |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
250 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
251 |
private val shutdown_hook = new Thread { override def run = terminate() } |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
252 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
253 |
try { Runtime.getRuntime.addShutdownHook(shutdown_hook) } |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
254 |
catch { case _: IllegalStateException => } |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
255 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
256 |
private def cleanup() = |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
257 |
try { Runtime.getRuntime.removeShutdownHook(shutdown_hook) } |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
258 |
catch { case _: IllegalStateException => } |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
259 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
260 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
261 |
/* result */ |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
262 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
263 |
def join: Int = { val rc = proc.waitFor; cleanup(); rc } |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
264 |
} |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
265 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
266 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
267 |
/* bash */ |
31796 | 268 |
|
39581
430ff865089b
refined Isabelle_System.bash_output: pass pid via stdout, separate stdout/stderr;
wenzelm
parents:
39576
diff
changeset
|
269 |
def bash(script: String): (String, String, Int) = |
34198
ff5486262cd6
moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents:
34196
diff
changeset
|
270 |
{ |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
34200
diff
changeset
|
271 |
Standard_System.with_tmp_file("isabelle_script") { script_file => |
39581
430ff865089b
refined Isabelle_System.bash_output: pass pid via stdout, separate stdout/stderr;
wenzelm
parents:
39576
diff
changeset
|
272 |
Standard_System.write_file(script_file, script) |
39583
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
273 |
val proc = new Managed_Process(false, "bash", posix_path(script_file.getPath)) |
39581
430ff865089b
refined Isabelle_System.bash_output: pass pid via stdout, separate stdout/stderr;
wenzelm
parents:
39576
diff
changeset
|
274 |
|
39583
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
275 |
proc.stdin.close |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
276 |
val stdout = Simple_Thread.future { Standard_System.slurp(proc.stdout) } |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
277 |
val stderr = Simple_Thread.future { Standard_System.slurp(proc.stderr) } |
34198
ff5486262cd6
moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents:
34196
diff
changeset
|
278 |
|
39581
430ff865089b
refined Isabelle_System.bash_output: pass pid via stdout, separate stdout/stderr;
wenzelm
parents:
39576
diff
changeset
|
279 |
val rc = |
39583
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
280 |
try { proc.join } |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
281 |
catch { case e: InterruptedException => Thread.interrupted; proc.terminate; 130 } |
39581
430ff865089b
refined Isabelle_System.bash_output: pass pid via stdout, separate stdout/stderr;
wenzelm
parents:
39576
diff
changeset
|
282 |
(stdout.join, stderr.join, rc) |
34198
ff5486262cd6
moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents:
34196
diff
changeset
|
283 |
} |
ff5486262cd6
moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents:
34196
diff
changeset
|
284 |
} |
ff5486262cd6
moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents:
34196
diff
changeset
|
285 |
|
39583
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
286 |
|
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
287 |
/* system tools */ |
c1e9c6dfeff8
more robust lib/scripts/process, with explicit script/no_script mode;
wenzelm
parents:
39581
diff
changeset
|
288 |
|
31818
f698f76a3713
builtin isabelle_tool for ML and Scala -- avoids excessive shell script (especially important for Cygwin);
wenzelm
parents:
31803
diff
changeset
|
289 |
def isabelle_tool(name: String, args: String*): (String, Int) = |
31498 | 290 |
{ |
34200 | 291 |
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
|
292 |
val file = platform_file(dir + "/" + name) |
34025 | 293 |
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
|
294 |
catch { case _: SecurityException => false } |
34200 | 295 |
} match { |
31818
f698f76a3713
builtin isabelle_tool for ML and Scala -- avoids excessive shell script (especially important for Cygwin);
wenzelm
parents:
31803
diff
changeset
|
296 |
case Some(dir) => |
34201
c95dcd12f48a
separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
34200
diff
changeset
|
297 |
Standard_System.process_output( |
34195 | 298 |
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
|
299 |
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
|
300 |
} |
28063 | 301 |
} |
302 |
||
303 |
||
304 |
/* named pipes */ |
|
305 |
||
39520
bad14b7d0520
Isabelle_System.mk_fifo: more robust enumeration of unique names, based on persisting JVM pid (parent of shell process);
wenzelm
parents:
38371
diff
changeset
|
306 |
private var fifo_count: Long = 0 |
bad14b7d0520
Isabelle_System.mk_fifo: more robust enumeration of unique names, based on persisting JVM pid (parent of shell process);
wenzelm
parents:
38371
diff
changeset
|
307 |
private def next_fifo(): String = synchronized { |
bad14b7d0520
Isabelle_System.mk_fifo: more robust enumeration of unique names, based on persisting JVM pid (parent of shell process);
wenzelm
parents:
38371
diff
changeset
|
308 |
require(fifo_count < java.lang.Long.MAX_VALUE) |
bad14b7d0520
Isabelle_System.mk_fifo: more robust enumeration of unique names, based on persisting JVM pid (parent of shell process);
wenzelm
parents:
38371
diff
changeset
|
309 |
fifo_count += 1 |
bad14b7d0520
Isabelle_System.mk_fifo: more robust enumeration of unique names, based on persisting JVM pid (parent of shell process);
wenzelm
parents:
38371
diff
changeset
|
310 |
fifo_count.toString |
bad14b7d0520
Isabelle_System.mk_fifo: more robust enumeration of unique names, based on persisting JVM pid (parent of shell process);
wenzelm
parents:
38371
diff
changeset
|
311 |
} |
bad14b7d0520
Isabelle_System.mk_fifo: more robust enumeration of unique names, based on persisting JVM pid (parent of shell process);
wenzelm
parents:
38371
diff
changeset
|
312 |
|
31498 | 313 |
def mk_fifo(): String = |
314 |
{ |
|
39529
4e466a5f67f3
simplified Isabelle_System.mk_fifo: inlined script, append PPID and PID uniformly;
wenzelm
parents:
39523
diff
changeset
|
315 |
val i = next_fifo() |
4e466a5f67f3
simplified Isabelle_System.mk_fifo: inlined script, append PPID and PID uniformly;
wenzelm
parents:
39523
diff
changeset
|
316 |
val script = |
4e466a5f67f3
simplified Isabelle_System.mk_fifo: inlined script, append PPID and PID uniformly;
wenzelm
parents:
39523
diff
changeset
|
317 |
"FIFO=\"/tmp/isabelle-fifo-${PPID}-$$-" + i + "\"\n" + |
4e466a5f67f3
simplified Isabelle_System.mk_fifo: inlined script, append PPID and PID uniformly;
wenzelm
parents:
39523
diff
changeset
|
318 |
"mkfifo -m 600 \"$FIFO\" || { echo \"Failed to create fifo: $FIFO\" >&2; exit 2; }\n" + |
4e466a5f67f3
simplified Isabelle_System.mk_fifo: inlined script, append PPID and PID uniformly;
wenzelm
parents:
39523
diff
changeset
|
319 |
"echo -n \"$FIFO\"\n" |
39581
430ff865089b
refined Isabelle_System.bash_output: pass pid via stdout, separate stdout/stderr;
wenzelm
parents:
39576
diff
changeset
|
320 |
val (out, err, rc) = bash(script) |
430ff865089b
refined Isabelle_System.bash_output: pass pid via stdout, separate stdout/stderr;
wenzelm
parents:
39576
diff
changeset
|
321 |
if (rc == 0) out else error(err) |
28063 | 322 |
} |
323 |
||
39574
91b23d141dbf
more robust Isabelle_System.rm_fifo: avoid external bash invocation, which might not work in JVM shutdown phase (due to Runtime.addShutdownHook);
wenzelm
parents:
39529
diff
changeset
|
324 |
def rm_fifo(fifo: String): Boolean = |
91b23d141dbf
more robust Isabelle_System.rm_fifo: avoid external bash invocation, which might not work in JVM shutdown phase (due to Runtime.addShutdownHook);
wenzelm
parents:
39529
diff
changeset
|
325 |
(new File(jvm_path(if (Platform.is_windows) fifo + ".lnk" else fifo))).delete |
28063 | 326 |
|
38371
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
327 |
def fifo_input_stream(fifo: String): InputStream = |
31498 | 328 |
{ |
38371
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
329 |
if (Platform.is_windows) { // Cygwin fifo as Windows/Java input stream |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
330 |
val proc = execute(false, expand_path("$ISABELLE_HOME/lib/scripts/raw_dump"), fifo, "-") |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
331 |
proc.getOutputStream.close |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
332 |
proc.getErrorStream.close |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
333 |
proc.getInputStream |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
334 |
} |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
335 |
else new FileInputStream(fifo) |
29177 | 336 |
} |
28063 | 337 |
|
38371
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
338 |
def fifo_output_stream(fifo: String): OutputStream = |
38253
3d4e521014f7
Isabelle_Process: separate input fifo for commands (still using the old tty protocol);
wenzelm
parents:
37367
diff
changeset
|
339 |
{ |
38371
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
340 |
if (Platform.is_windows) { // Cygwin fifo as Windows/Java output stream |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
341 |
val proc = execute(false, expand_path("$ISABELLE_HOME/lib/scripts/raw_dump"), "-", fifo) |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
342 |
proc.getInputStream.close |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
343 |
proc.getErrorStream.close |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
344 |
val out = proc.getOutputStream |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
345 |
new OutputStream { |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
346 |
override def close() { out.close(); proc.waitFor() } |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
347 |
override def flush() { out.flush() } |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
348 |
override def write(b: Array[Byte]) { out.write(b) } |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
349 |
override def write(b: Array[Byte], off: Int, len: Int) { out.write(b, off, len) } |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
350 |
override def write(b: Int) { out.write(b) } |
38253
3d4e521014f7
Isabelle_Process: separate input fifo for commands (still using the old tty protocol);
wenzelm
parents:
37367
diff
changeset
|
351 |
} |
38371
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
352 |
} |
5b615a4a3a68
do not buffer fifo streams here -- done in Isabelle_Process;
wenzelm
parents:
38255
diff
changeset
|
353 |
else new FileOutputStream(fifo) |
38253
3d4e521014f7
Isabelle_Process: separate input fifo for commands (still using the old tty protocol);
wenzelm
parents:
37367
diff
changeset
|
354 |
} |
3d4e521014f7
Isabelle_Process: separate input fifo for commands (still using the old tty protocol);
wenzelm
parents:
37367
diff
changeset
|
355 |
|
29152 | 356 |
|
32450 | 357 |
|
31796 | 358 |
/** Isabelle resources **/ |
359 |
||
32328 | 360 |
/* components */ |
361 |
||
362 |
def components(): List[String] = |
|
37058
c47653f3ec14
rendering information and style sheets via settings;
wenzelm
parents:
37013
diff
changeset
|
363 |
getenv_strict("ISABELLE_COMPONENTS").split(":").toList |
32328 | 364 |
|
365 |
||
29152 | 366 |
/* find logics */ |
367 |
||
31498 | 368 |
def find_logics(): List[String] = |
369 |
{ |
|
29152 | 370 |
val ml_ident = getenv_strict("ML_IDENTIFIER") |
34163 | 371 |
val logics = new mutable.ListBuffer[String] |
29152 | 372 |
for (dir <- getenv_strict("ISABELLE_PATH").split(":")) { |
373 |
val files = platform_file(dir + "/" + ml_ident).listFiles() |
|
374 |
if (files != null) { |
|
375 |
for (file <- files if file.isFile) logics += file.getName |
|
376 |
} |
|
377 |
} |
|
36012 | 378 |
logics.toList.sortWith(_ < _) |
29152 | 379 |
} |
29570 | 380 |
|
381 |
||
382 |
/* symbols */ |
|
383 |
||
384 |
val symbols = new Symbol.Interpretation( |
|
37058
c47653f3ec14
rendering information and style sheets via settings;
wenzelm
parents:
37013
diff
changeset
|
385 |
try_read(getenv_strict("ISABELLE_SYMBOLS").split(":").toList).split("\n").toList) |
34024 | 386 |
|
387 |
||
388 |
/* fonts */ |
|
389 |
||
37058
c47653f3ec14
rendering information and style sheets via settings;
wenzelm
parents:
37013
diff
changeset
|
390 |
val font_family = getenv_strict("ISABELLE_FONT_FAMILY") |
37367 | 391 |
val font_family_default = "IsabelleText" |
34024 | 392 |
|
36788 | 393 |
def get_font(size: Int = 1, bold: Boolean = false): Font = |
36785 | 394 |
new Font(font_family, if (bold) Font.BOLD else Font.PLAIN, size) |
34024 | 395 |
|
37367 | 396 |
def create_default_font(bold: Boolean = false): Font = |
397 |
if (bold) |
|
398 |
Font.createFont(Font.TRUETYPE_FONT, |
|
399 |
platform_file("$ISABELLE_HOME/lib/fonts/IsabelleTextBold.ttf")) |
|
400 |
else |
|
401 |
Font.createFont(Font.TRUETYPE_FONT, |
|
402 |
platform_file("$ISABELLE_HOME/lib/fonts/IsabelleText.ttf")) |
|
403 |
||
34044
09afb1d49fe7
slightly more robust and less ambitious version of install_fonts;
wenzelm
parents:
34027
diff
changeset
|
404 |
def install_fonts() |
09afb1d49fe7
slightly more robust and less ambitious version of install_fonts;
wenzelm
parents:
34027
diff
changeset
|
405 |
{ |
37367 | 406 |
val ge = GraphicsEnvironment.getLocalGraphicsEnvironment() |
407 |
ge.registerFont(create_default_font(bold = false)) |
|
408 |
ge.registerFont(create_default_font(bold = true)) |
|
34024 | 409 |
} |
27919 | 410 |
} |