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