1/* Title: Pure/System/command_line.scala 2 Author: Makarius 3 4Support for Isabelle/Scala command line tools. 5*/ 6 7package isabelle 8 9 10object Command_Line 11{ 12 object Chunks 13 { 14 private def chunks(list: List[String]): List[List[String]] = 15 list.indexWhere(_ == "\n") match { 16 case -1 => List(list) 17 case i => 18 val (chunk, rest) = list.splitAt(i) 19 chunk :: chunks(rest.tail) 20 } 21 def unapplySeq(list: List[String]): Option[List[List[String]]] = Some(chunks(list)) 22 } 23 24 var debug = false 25 26 def tool(body: => Int): Nothing = 27 { 28 val rc = 29 try { body } 30 catch { 31 case exn: Throwable => 32 if (debug) exn.printStackTrace 33 Output.error_message(Exn.message(exn)) 34 Exn.return_code(exn, 2) 35 } 36 sys.exit(rc) 37 } 38 39 def tool0(body: => Unit): Nothing = tool { body; 0 } 40} 41 42