author | wenzelm |
Mon, 10 May 2010 22:27:58 +0200 | |
changeset 36788 | 1fd4f28e6ce1 |
parent 36785 | 55025bd6605f |
child 36991 | ccb8da7f76e6 |
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 |
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 | 13 |
File, IOException} |
34024 | 14 |
import java.awt.{GraphicsEnvironment, Font} |
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 |
|
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 | 22 |
{ |
31796 | 23 |
/** Isabelle environment **/ |
24 |
||
31498 | 25 |
private val environment: Map[String, String] = |
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 | 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 | 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 | 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 | 39 |
} |
29177 | 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 | 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 | 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 | 59 |
} |
27919 | 60 |
|
31796 | 61 |
|
34204 | 62 |
/* external processes */ |
63 |
||
64 |
def execute(redirect: Boolean, args: String*): Process = |
|
65 |
{ |
|
66 |
val cmdline = |
|
67 |
if (Platform.is_windows) List(platform_root + "\\bin\\env.exe") ++ args |
|
68 |
else args |
|
34219 | 69 |
Standard_System.raw_execute(null, environment, redirect, cmdline: _*) |
34204 | 70 |
} |
71 |
||
72 |
||
31796 | 73 |
/* getenv */ |
74 |
||
31498 | 75 |
def getenv(name: String): String = |
76 |
environment.getOrElse(if (name == "HOME") "HOME_JVM" else name, "") |
|
77 |
||
78 |
def getenv_strict(name: String): String = |
|
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 | 82 |
} |
83 |
||
31703 | 84 |
override def toString = getenv("ISABELLE_HOME") |
85 |
||
27936 | 86 |
|
31796 | 87 |
|
88 |
/** file path specifications **/ |
|
89 |
||
31820 | 90 |
/* expand_path */ |
31796 | 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 | 95 |
def expand_path(isabelle_path: String): String = |
31796 | 96 |
{ |
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 | 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 | 106 |
} |
107 |
} |
|
108 |
def append(path: String) |
|
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 | 112 |
if (p == "..") { |
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 | 125 |
} |
126 |
else { |
|
127 |
val len = result_path.length |
|
128 |
if (len > 0 && result_path(len - 1) != '/') |
|
129 |
result_path += '/' |
|
130 |
result_path ++= p |
|
131 |
} |
|
31796 | 132 |
} |
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 | 136 |
if (p.startsWith("$")) append(getenv_strict(p.substring(1))) |
137 |
else if (p == "~") append(getenv_strict("HOME")) |
|
138 |
else if (p == "~~") append(getenv_strict("ISABELLE_HOME")) |
|
139 |
else append(p) |
|
140 |
} |
|
141 |
result_path.toString |
|
142 |
} |
|
143 |
||
144 |
||
31820 | 145 |
/* platform_path */ |
27936 | 146 |
|
31820 | 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 | 149 |
|
31498 | 150 |
def platform_file(path: String) = new File(platform_path(path)) |
29152 | 151 |
|
27953 | 152 |
|
31436 | 153 |
/* source files */ |
154 |
||
155 |
private def try_file(file: File) = if (file.isFile) Some(file) else None |
|
156 |
||
31498 | 157 |
def source_file(path: String): Option[File] = |
158 |
{ |
|
159 |
if (path.startsWith("/") || path == "") |
|
31436 | 160 |
try_file(platform_file(path)) |
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 | 163 |
if (pure_file.isFile) Some(pure_file) |
164 |
else if (getenv("ML_SOURCES") != "") |
|
165 |
try_file(platform_file("$ML_SOURCES/" + path)) |
|
166 |
else None |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
||
32450 | 171 |
|
31796 | 172 |
/** system tools **/ |
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 | 185 |
def kill(strict: Boolean) = |
34198
ff5486262cd6
moved Library.decode_permissive_utf8 to Isabelle_System;
wenzelm
parents:
34196
diff
changeset
|
186 |
{ |
34199 | 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 | 189 |
catch { case _: IOException => None } |
190 |
if (pid.isDefined) { |
|
191 |
var running = true |
|
192 |
var count = 10 |
|
193 |
while (running && count > 0) { |
|
194 |
if (execute(true, "kill", "-INT", "-" + pid.get).waitFor != 0) |
|
195 |
running = false |
|
196 |
else { |
|
197 |
Thread.sleep(100) |
|
198 |
if (!strict) count -= 1 |
|
199 |
} |
|
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 | 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 | 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 | 235 |
{ |
34200 | 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 | 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 | 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 | 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 | 246 |
} |
247 |
||
248 |
||
249 |
/* named pipes */ |
|
250 |
||
31498 | 251 |
def mk_fifo(): String = |
252 |
{ |
|
28496
4cff10648928
renamed isatool to isabelle_tool in programming interfaces;
wenzelm
parents:
28063
diff
changeset
|
253 |
val (result, rc) = isabelle_tool("mkfifo") |
28063 | 254 |
if (rc == 0) result.trim |
255 |
else error(result) |
|
256 |
} |
|
257 |
||
31498 | 258 |
def rm_fifo(fifo: String) |
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 | 261 |
if (rc != 0) error(result) |
262 |
} |
|
263 |
||
34100 | 264 |
def fifo_stream(fifo: String): BufferedInputStream = |
31498 | 265 |
{ |
29177 | 266 |
// blocks until writer is ready |
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 | 274 |
else new FileInputStream(fifo) |
34100 | 275 |
new BufferedInputStream(stream) |
29177 | 276 |
} |
28063 | 277 |
|
29152 | 278 |
|
32450 | 279 |
|
31796 | 280 |
/** Isabelle resources **/ |
281 |
||
32328 | 282 |
/* components */ |
283 |
||
284 |
def components(): List[String] = |
|
285 |
getenv("ISABELLE_COMPONENTS").split(":").toList |
|
286 |
||
287 |
||
29152 | 288 |
/* find logics */ |
289 |
||
31498 | 290 |
def find_logics(): List[String] = |
291 |
{ |
|
29152 | 292 |
val ml_ident = getenv_strict("ML_IDENTIFIER") |
34163 | 293 |
val logics = new mutable.ListBuffer[String] |
29152 | 294 |
for (dir <- getenv_strict("ISABELLE_PATH").split(":")) { |
295 |
val files = platform_file(dir + "/" + ml_ident).listFiles() |
|
296 |
if (files != null) { |
|
297 |
for (file <- files if file.isFile) logics += file.getName |
|
298 |
} |
|
299 |
} |
|
36012 | 300 |
logics.toList.sortWith(_ < _) |
29152 | 301 |
} |
29570 | 302 |
|
303 |
||
304 |
/* symbols */ |
|
305 |
||
34137 | 306 |
private def read_symbols(path: String): List[String] = |
31498 | 307 |
{ |
34195 | 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 | 310 |
else Nil |
29570 | 311 |
} |
312 |
val symbols = new Symbol.Interpretation( |
|
34137 | 313 |
read_symbols("$ISABELLE_HOME/etc/symbols") ::: |
29570 | 314 |
read_symbols("$ISABELLE_HOME_USER/etc/symbols")) |
34024 | 315 |
|
316 |
||
317 |
/* fonts */ |
|
318 |
||
319 |
val font_family = "IsabelleText" |
|
320 |
||
36788 | 321 |
def get_font(size: Int = 1, bold: Boolean = false): Font = |
36785 | 322 |
new Font(font_family, if (bold) Font.BOLD else Font.PLAIN, size) |
34024 | 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 | 326 |
def create_font(bold: Boolean): Font = |
327 |
{ |
|
328 |
val name = |
|
329 |
if (bold) "$ISABELLE_HOME/lib/fonts/IsabelleTextBold.ttf" |
|
330 |
else "$ISABELLE_HOME/lib/fonts/IsabelleText.ttf" |
|
331 |
Font.createFont(Font.TRUETYPE_FONT, platform_file(name)) |
|
332 |
} |
|
36788 | 333 |
def check_font() = get_font().getFamily == font_family |
35006 | 334 |
|
34044
09afb1d49fe7
slightly more robust and less ambitious version of install_fonts;
wenzelm
parents:
34027
diff
changeset
|
335 |
if (!check_font()) { |
35006 | 336 |
val font = create_font(false) |
337 |
val bold_font = create_font(true) |
|
338 |
||
34044
09afb1d49fe7
slightly more robust and less ambitious version of install_fonts;
wenzelm
parents:
34027
diff
changeset
|
339 |
val ge = GraphicsEnvironment.getLocalGraphicsEnvironment() |
35006 | 340 |
ge.registerFont(font) |
341 |
// workaround strange problem with Apple's Java 1.6 font manager |
|
342 |
if (bold_font.getFamily == font_family) ge.registerFont(bold_font) |
|
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 | 345 |
} |
27919 | 346 |
} |