src/Pure/System/standard_system.scala
author wenzelm
Thu, 19 Jul 2012 22:32:52 +0200
changeset 48359 e544dbcdf097
parent 48277 f14e564fca1a
child 48373 527e2bad7cca
permissions -rw-r--r--
added eq_file / copy_file corresponding to File.eq / File.copy in ML;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/System/standard_system.scala
45673
cd41e3903fbf separate compilation of PIDE vs. Pure sources, which enables independent Scala library;
wenzelm
parents: 45667
diff changeset
     2
    Module:     PIDE
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
     4
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
     5
Standard system operations, with basic Cygwin/Posix compatibility.
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
     6
*/
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
     7
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
     8
package isabelle
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
     9
43520
cec9b95fa35d explicit import java.lang.System to prevent odd scope problems;
wenzelm
parents: 43516
diff changeset
    10
import java.lang.System
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    11
import java.util.regex.Pattern
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    12
import java.util.Locale
39705
41e9f69c553d added Standard_System.raw_untar;
wenzelm
parents: 39582
diff changeset
    13
import java.net.URL
41e9f69c553d added Standard_System.raw_untar;
wenzelm
parents: 39582
diff changeset
    14
import java.io.{BufferedWriter, OutputStreamWriter, FileOutputStream, BufferedOutputStream,
39578
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
    15
  BufferedInputStream, InputStream, FileInputStream, BufferedReader, InputStreamReader,
34298
13e9f1f4acd9 added find_files;
wenzelm
parents: 34258
diff changeset
    16
  File, FileFilter, IOException}
43516
1c4736b9396a prefer actual charset over charset name;
wenzelm
parents: 39732
diff changeset
    17
import java.nio.charset.Charset
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    18
48277
f14e564fca1a tuned imports;
wenzelm
parents: 48027
diff changeset
    19
import scala.io.Codec
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    20
import scala.util.matching.Regex
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    21
import scala.collection.mutable
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    22
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    23
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    24
object Standard_System
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    25
{
38264
205b74a1bb18 added string_bytes convenience;
wenzelm
parents: 36193
diff changeset
    26
  /* UTF-8 charset */
205b74a1bb18 added string_bytes convenience;
wenzelm
parents: 36193
diff changeset
    27
43516
1c4736b9396a prefer actual charset over charset name;
wenzelm
parents: 39732
diff changeset
    28
  val charset_name: String = "UTF-8"
1c4736b9396a prefer actual charset over charset name;
wenzelm
parents: 39732
diff changeset
    29
  val charset: Charset = Charset.forName(charset_name)
36015
6111de7c916a adapted to Scala 2.8.0 Beta 1;
wenzelm
parents: 36011
diff changeset
    30
  def codec(): Codec = Codec(charset)
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    31
38264
205b74a1bb18 added string_bytes convenience;
wenzelm
parents: 36193
diff changeset
    32
  def string_bytes(s: String): Array[Byte] = s.getBytes(charset)
205b74a1bb18 added string_bytes convenience;
wenzelm
parents: 36193
diff changeset
    33
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    34
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    35
  /* permissive UTF-8 decoding */
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    36
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    37
  // see also http://en.wikipedia.org/wiki/UTF-8#Description
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    38
  // overlong encodings enable byte-stuffing
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    39
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    40
  def decode_permissive_utf8(text: CharSequence): String =
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    41
  {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    42
    val buf = new java.lang.StringBuilder(text.length)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    43
    var code = -1
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    44
    var rest = 0
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    45
    def flush()
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    46
    {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    47
      if (code != -1) {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    48
        if (rest == 0 && Character.isValidCodePoint(code))
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    49
          buf.appendCodePoint(code)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    50
        else buf.append('\uFFFD')
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    51
        code = -1
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    52
        rest = 0
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    53
      }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    54
    }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    55
    def init(x: Int, n: Int)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    56
    {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    57
      flush()
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    58
      code = x
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    59
      rest = n
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    60
    }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    61
    def push(x: Int)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    62
    {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    63
      if (rest <= 0) init(x, -1)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    64
      else {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    65
        code <<= 6
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    66
        code += x
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    67
        rest -= 1
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    68
      }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    69
    }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    70
    for (i <- 0 until text.length) {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    71
      val c = text.charAt(i)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    72
      if (c < 128) { flush(); buf.append(c) }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    73
      else if ((c & 0xC0) == 0x80) push(c & 0x3F)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    74
      else if ((c & 0xE0) == 0xC0) init(c & 0x1F, 1)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    75
      else if ((c & 0xF0) == 0xE0) init(c & 0x0F, 2)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    76
      else if ((c & 0xF8) == 0xF0) init(c & 0x07, 3)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    77
    }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    78
    flush()
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    79
    buf.toString
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    80
  }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
    81
43746
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    82
  private class Decode_Chars(decode: String => String,
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    83
    buffer: Array[Byte], start: Int, end: Int) extends CharSequence
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    84
  {
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    85
    def length: Int = end - start
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    86
    def charAt(i: Int): Char = (buffer(start + i).asInstanceOf[Int] & 0xFF).asInstanceOf[Char]
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    87
    def subSequence(i: Int, j: Int): CharSequence =
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    88
      new Decode_Chars(decode, buffer, start + i, start + j)
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    89
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    90
    // toString with adhoc decoding: abuse of CharSequence interface
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    91
    override def toString: String = decode(decode_permissive_utf8(this))
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    92
  }
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    93
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    94
  def decode_chars(decode: String => String,
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    95
    buffer: Array[Byte], start: Int, end: Int): CharSequence =
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    96
  {
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    97
    require(0 <= start && start <= end && end <= buffer.length)
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    98
    new Decode_Chars(decode, buffer, start, end)
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
    99
  }
a41f618c641d some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents: 43695
diff changeset
   100
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   101
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   102
  /* basic file operations */
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   103
39578
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   104
  def slurp(reader: BufferedReader): String =
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   105
  {
39578
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   106
    val output = new StringBuilder(100)
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   107
    var c = -1
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   108
    while ({ c = reader.read; c != -1 }) output += c.toChar
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   109
    reader.close
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   110
    output.toString
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   111
  }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   112
39578
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   113
  def slurp(stream: InputStream): String =
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   114
    slurp(new BufferedReader(new InputStreamReader(stream, charset)))
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   115
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   116
  def read_file(file: File): String = slurp(new FileInputStream(file))
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   117
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   118
  def write_file(file: File, text: CharSequence)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   119
  {
43516
1c4736b9396a prefer actual charset over charset name;
wenzelm
parents: 39732
diff changeset
   120
    val writer =
1c4736b9396a prefer actual charset over charset name;
wenzelm
parents: 39732
diff changeset
   121
      new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset))
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   122
    try { writer.append(text) }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   123
    finally { writer.close }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   124
  }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   125
48359
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   126
  def eq_file(file1: File, file2: File): Boolean =
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   127
    file1.getCanonicalPath == file2.getCanonicalPath  // FIXME prefer java.nio.file.Files.isSameFile of Java 1.7
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   128
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   129
  def copy_file(src: File, dst: File) =
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   130
    if (!eq_file(src, dst)) {
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   131
      val in = new FileInputStream(src)
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   132
      try {
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   133
        val out = new FileOutputStream(dst)
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   134
        try {
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   135
          val buf = new Array[Byte](65536)
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   136
          var m = 0
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   137
          do {
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   138
            m = in.read(buf, 0, buf.length)
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   139
            if (m != -1) out.write(buf, 0, m)
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   140
          } while (m != -1)
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   141
        }
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   142
        finally { out.close }
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   143
      }
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   144
      finally { in.close }
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   145
    }
e544dbcdf097 added eq_file / copy_file corresponding to File.eq / File.copy in ML;
wenzelm
parents: 48277
diff changeset
   146
39578
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   147
  def with_tmp_file[A](prefix: String)(body: File => A): A =
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   148
  {
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   149
    val file = File.createTempFile(prefix, null)
39582
a873158542d0 Standard_System.with_tmp_file: deleteOnExit to make double sure;
wenzelm
parents: 39578
diff changeset
   150
    file.deleteOnExit
39578
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   151
    try { body(file) } finally { file.delete }
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   152
  }
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   153
34300
3f2e25dc99ab misc tuning;
wenzelm
parents: 34298
diff changeset
   154
  // FIXME handle (potentially cyclic) directory graph
34298
13e9f1f4acd9 added find_files;
wenzelm
parents: 34258
diff changeset
   155
  def find_files(start: File, ok: File => Boolean): List[File] =
13e9f1f4acd9 added find_files;
wenzelm
parents: 34258
diff changeset
   156
  {
13e9f1f4acd9 added find_files;
wenzelm
parents: 34258
diff changeset
   157
    val files = new mutable.ListBuffer[File]
13e9f1f4acd9 added find_files;
wenzelm
parents: 34258
diff changeset
   158
    val filter = new FileFilter { def accept(entry: File) = entry.isDirectory || ok(entry) }
13e9f1f4acd9 added find_files;
wenzelm
parents: 34258
diff changeset
   159
    def find_entry(entry: File)
13e9f1f4acd9 added find_files;
wenzelm
parents: 34258
diff changeset
   160
    {
13e9f1f4acd9 added find_files;
wenzelm
parents: 34258
diff changeset
   161
      if (ok(entry)) files += entry
13e9f1f4acd9 added find_files;
wenzelm
parents: 34258
diff changeset
   162
      if (entry.isDirectory) entry.listFiles(filter).foreach(find_entry)
13e9f1f4acd9 added find_files;
wenzelm
parents: 34258
diff changeset
   163
    }
13e9f1f4acd9 added find_files;
wenzelm
parents: 34258
diff changeset
   164
    find_entry(start)
13e9f1f4acd9 added find_files;
wenzelm
parents: 34258
diff changeset
   165
    files.toList
13e9f1f4acd9 added find_files;
wenzelm
parents: 34258
diff changeset
   166
  }
13e9f1f4acd9 added find_files;
wenzelm
parents: 34258
diff changeset
   167
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   168
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   169
  /* shell processes */
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   170
34219
d37cfca69887 Standard_System.raw_execute: optional cwd;
wenzelm
parents: 34202
diff changeset
   171
  def raw_execute(cwd: File, env: Map[String, String], redirect: Boolean, args: String*): Process =
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   172
  {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   173
    val cmdline = new java.util.LinkedList[String]
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   174
    for (s <- args) cmdline.add(s)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   175
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   176
    val proc = new ProcessBuilder(cmdline)
34219
d37cfca69887 Standard_System.raw_execute: optional cwd;
wenzelm
parents: 34202
diff changeset
   177
    if (cwd != null) proc.directory(cwd)
34202
99241daf807d ignore undefined environment;
wenzelm
parents: 34201
diff changeset
   178
    if (env != null) {
99241daf807d ignore undefined environment;
wenzelm
parents: 34201
diff changeset
   179
      proc.environment.clear
99241daf807d ignore undefined environment;
wenzelm
parents: 34201
diff changeset
   180
      for ((x, y) <- env) proc.environment.put(x, y)
99241daf807d ignore undefined environment;
wenzelm
parents: 34201
diff changeset
   181
    }
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   182
    proc.redirectErrorStream(redirect)
39522
01aade784da9 raw_execute: let IOException pass-through unhindered (again);
wenzelm
parents: 38264
diff changeset
   183
    proc.start
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   184
  }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   185
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   186
  def process_output(proc: Process): (String, Int) =
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   187
  {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   188
    proc.getOutputStream.close
39578
b75164153c37 added Standard_System.slurp convenience;
wenzelm
parents: 39522
diff changeset
   189
    val output = slurp(proc.getInputStream)
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   190
    val rc =
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   191
      try { proc.waitFor }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   192
      finally {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   193
        proc.getInputStream.close
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   194
        proc.getErrorStream.close
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   195
        proc.destroy
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   196
        Thread.interrupted
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   197
      }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   198
    (output, rc)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   199
  }
34258
e936d3c35ce0 Standard_System.raw_exec;
wenzelm
parents: 34219
diff changeset
   200
39522
01aade784da9 raw_execute: let IOException pass-through unhindered (again);
wenzelm
parents: 38264
diff changeset
   201
  def raw_exec(cwd: File, env: Map[String, String], redirect: Boolean, args: String*)
01aade784da9 raw_execute: let IOException pass-through unhindered (again);
wenzelm
parents: 38264
diff changeset
   202
    : (String, Int) = process_output(raw_execute(cwd, env, redirect, args: _*))
39705
41e9f69c553d added Standard_System.raw_untar;
wenzelm
parents: 39582
diff changeset
   203
41e9f69c553d added Standard_System.raw_untar;
wenzelm
parents: 39582
diff changeset
   204
47998
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   205
  /* cygwin_root */
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   206
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   207
  def cygwin_root(): String =
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   208
  {
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   209
    val cygwin_root1 = System.getenv("CYGWIN_ROOT")
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   210
    val cygwin_root2 = System.getProperty("cygwin.root")
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   211
    val root =
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   212
      if (cygwin_root1 != null && cygwin_root1 != "") cygwin_root1
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   213
      else if (cygwin_root2 != null && cygwin_root2 != "") cygwin_root2
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   214
      else error("Bad Cygwin installation: unknown root")
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   215
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   216
    val root_file = new File(root)
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   217
    if (!new File(root_file, "bin\\bash.exe").isFile ||
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   218
        !new File(root_file, "bin\\env.exe").isFile ||
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   219
        !new File(root_file, "bin\\tar.exe").isFile)
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   220
      error("Bad Cygwin installation: " + quote(root))
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   221
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   222
    root
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   223
  }
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   224
}
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   225
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   226
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   227
class Standard_System
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   228
{
43664
wenzelm
parents: 43661
diff changeset
   229
  /* platform_root */
wenzelm
parents: 43661
diff changeset
   230
47998
969457d93f75 discontinued obsolete Cygwin module;
wenzelm
parents: 47113
diff changeset
   231
  val platform_root = if (Platform.is_windows) Standard_System.cygwin_root() else "/"
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   232
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   233
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   234
  /* jvm_path */
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   235
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   236
  private val Cygdrive = new Regex("/cygdrive/([a-zA-Z])($|/.*)")
36136
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36015
diff changeset
   237
  private val Named_Root = new Regex("//+([^/]*)(.*)")
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   238
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   239
  def jvm_path(posix_path: String): String =
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   240
    if (Platform.is_windows) {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   241
      val result_path = new StringBuilder
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   242
      val rest =
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   243
        posix_path match {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   244
          case Cygdrive(drive, rest) =>
45072
e30442a2b3b2 standardize drive letters -- important for proper document node identification;
wenzelm
parents: 43746
diff changeset
   245
            result_path ++= (drive.toUpperCase(Locale.ENGLISH) + ":" + File.separator)
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   246
            rest
36136
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36015
diff changeset
   247
          case Named_Root(root, rest) =>
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36015
diff changeset
   248
            result_path ++= File.separator
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36015
diff changeset
   249
            result_path ++= File.separator
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36015
diff changeset
   250
            result_path ++= root
89b1a136edef more precise treatment of UNC server prefix, e.g. //foo;
wenzelm
parents: 36015
diff changeset
   251
            rest
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   252
          case path if path.startsWith("/") =>
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   253
            result_path ++= platform_root
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   254
            path
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   255
          case path => path
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   256
        }
43670
7f933761764b prefer space_explode/split_lines as in Isabelle/ML;
wenzelm
parents: 43664
diff changeset
   257
      for (p <- space_explode('/', rest) if p != "") {
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   258
        val len = result_path.length
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   259
        if (len > 0 && result_path(len - 1) != File.separatorChar)
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   260
          result_path += File.separatorChar
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   261
        result_path ++= p
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   262
      }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   263
      result_path.toString
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   264
    }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   265
    else posix_path
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   266
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   267
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   268
  /* posix_path */
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   269
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   270
  private val Platform_Root = new Regex("(?i)" +
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   271
    Pattern.quote(platform_root) + """(?:\\+|\z)(.*)""")
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   272
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   273
  private val Drive = new Regex("""([a-zA-Z]):\\*(.*)""")
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   274
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   275
  def posix_path(jvm_path: String): String =
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   276
    if (Platform.is_windows) {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   277
      jvm_path.replace('/', '\\') match {
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   278
        case Platform_Root(rest) => "/" + rest.replace('\\', '/')
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   279
        case Drive(letter, rest) =>
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   280
          "/cygdrive/" + letter.toLowerCase(Locale.ENGLISH) +
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   281
            (if (rest == "") "" else "/" + rest.replace('\\', '/'))
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   282
        case path => path.replace('\\', '/')
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   283
      }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   284
    }
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   285
    else jvm_path
36193
067a01827fca improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents: 36136
diff changeset
   286
067a01827fca improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents: 36136
diff changeset
   287
47113
b5a5662528fb ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents: 45673
diff changeset
   288
  /* JDK home of running JVM */
36193
067a01827fca improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents: 36136
diff changeset
   289
47113
b5a5662528fb ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents: 45673
diff changeset
   290
  def this_jdk_home(): String =
36193
067a01827fca improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents: 36136
diff changeset
   291
  {
067a01827fca improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents: 36136
diff changeset
   292
    val java_home = System.getProperty("java.home")
47113
b5a5662528fb ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents: 45673
diff changeset
   293
    val home = new File(java_home)
b5a5662528fb ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents: 45673
diff changeset
   294
    val parent = home.getParent
b5a5662528fb ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents: 45673
diff changeset
   295
    val jdk_home =
b5a5662528fb ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents: 45673
diff changeset
   296
      if (home.getName == "jre" && parent != null &&
b5a5662528fb ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents: 45673
diff changeset
   297
          (new File(new File(parent, "bin"), "javac")).exists) parent
b5a5662528fb ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents: 45673
diff changeset
   298
      else java_home
b5a5662528fb ISABELLE_JDK_HOME settings variable points to JDK with javac and jar (not just JRE);
wenzelm
parents: 45673
diff changeset
   299
    posix_path(jdk_home)
36193
067a01827fca improved ISABELLE_JAVA, based on THIS_JAVA of the actually running JVM;
wenzelm
parents: 36136
diff changeset
   300
  }
34201
c95dcd12f48a separate Standard_System (Cygwin/Posix compatibility) vs. Isabelle_System (settings environment etc.);
wenzelm
parents:
diff changeset
   301
}