src/Pure/System/isabelle_system.scala
changeset 45027 f459e93a038e
parent 44184 49501dc1a7b8
child 45100 0971c3ee3cdf
equal deleted inserted replaced
45026:5c0b0d67f9b1 45027:f459e93a038e
     8 package isabelle
     8 package isabelle
     9 
     9 
    10 import java.lang.System
    10 import java.lang.System
    11 import java.util.regex.Pattern
    11 import java.util.regex.Pattern
    12 import java.util.Locale
    12 import java.util.Locale
    13 import java.io.{InputStream, FileInputStream, OutputStream, FileOutputStream, File,
    13 import java.io.{InputStream, OutputStream, File, BufferedReader, InputStreamReader,
    14   BufferedReader, InputStreamReader, BufferedWriter, OutputStreamWriter, IOException}
    14   BufferedWriter, OutputStreamWriter, IOException}
    15 import java.awt.{GraphicsEnvironment, Font}
    15 import java.awt.{GraphicsEnvironment, Font}
    16 import java.awt.font.TextAttribute
    16 import java.awt.font.TextAttribute
    17 
    17 
    18 import scala.io.Source
    18 import scala.io.Source
    19 import scala.util.matching.Regex
    19 import scala.util.matching.Regex
   106   /* path specifications */
   106   /* path specifications */
   107 
   107 
   108   def standard_path(path: Path): String = path.expand.implode
   108   def standard_path(path: Path): String = path.expand.implode
   109 
   109 
   110   def platform_path(path: Path): String = standard_system.jvm_path(standard_path(path))
   110   def platform_path(path: Path): String = standard_system.jvm_path(standard_path(path))
   111   def platform_file(path: Path) = new File(platform_path(path))
   111   def platform_file(path: Path): File = new File(platform_path(path))
   112 
   112 
   113   def posix_path(jvm_path: String): String = standard_system.posix_path(jvm_path)
   113   def posix_path(jvm_path: String): String = standard_system.posix_path(jvm_path)
   114 
   114 
   115 
   115 
   116   /* try_read */
   116   /* try_read */
   264       case None => ("Unknown Isabelle tool: " + name, 2)
   264       case None => ("Unknown Isabelle tool: " + name, 2)
   265     }
   265     }
   266   }
   266   }
   267 
   267 
   268 
   268 
   269   /* named pipes */
       
   270 
       
   271   private val next_fifo = new Counter
       
   272 
       
   273   def mk_fifo(): String =
       
   274   {
       
   275     val i = next_fifo()
       
   276     val script =
       
   277       "FIFO=\"/tmp/isabelle-fifo-${PPID}-$$" + i + "\"\n" +
       
   278       "echo -n \"$FIFO\"\n" +
       
   279       "mkfifo -m 600 \"$FIFO\"\n"
       
   280     val (out, err, rc) = bash(script)
       
   281     if (rc == 0) out else error(err.trim)
       
   282   }
       
   283 
       
   284   def rm_fifo(fifo: String): Boolean =
       
   285     (new File(standard_system.jvm_path(if (Platform.is_windows) fifo + ".lnk" else fifo))).delete
       
   286 
       
   287   def fifo_input_stream(fifo: String): InputStream =
       
   288   {
       
   289     if (Platform.is_windows) { // Cygwin fifo as Windows/Java input stream
       
   290       val proc = execute(false, standard_path(Path.explode("~~/lib/scripts/raw_dump")), fifo, "-")
       
   291       proc.getOutputStream.close
       
   292       proc.getErrorStream.close
       
   293       proc.getInputStream
       
   294     }
       
   295     else new FileInputStream(fifo)
       
   296   }
       
   297 
       
   298   def fifo_output_stream(fifo: String): OutputStream =
       
   299   {
       
   300     if (Platform.is_windows) { // Cygwin fifo as Windows/Java output stream
       
   301       val proc = execute(false, standard_path(Path.explode("~~/lib/scripts/raw_dump")), "-", fifo)
       
   302       proc.getInputStream.close
       
   303       proc.getErrorStream.close
       
   304       val out = proc.getOutputStream
       
   305       new OutputStream {
       
   306         override def close() { out.close(); proc.waitFor() }
       
   307         override def flush() { out.flush() }
       
   308         override def write(b: Array[Byte]) { out.write(b) }
       
   309         override def write(b: Array[Byte], off: Int, len: Int) { out.write(b, off, len) }
       
   310         override def write(b: Int) { out.write(b) }
       
   311       }
       
   312     }
       
   313     else new FileOutputStream(fifo)
       
   314   }
       
   315 
       
   316 
       
   317 
   269 
   318   /** Isabelle resources **/
   270   /** Isabelle resources **/
   319 
   271 
   320   /* components */
   272   /* components */
   321 
   273