2009-06-26 03:26:06 +02:00
|
|
|
package sbt
|
|
|
|
|
|
2010-07-05 18:53:37 +02:00
|
|
|
import java.io.{File, FileNotFoundException, IOException}
|
2009-06-26 03:26:06 +02:00
|
|
|
|
|
|
|
|
object exit
|
|
|
|
|
{
|
|
|
|
|
def main(args: Array[String])
|
|
|
|
|
{
|
|
|
|
|
System.exit(java.lang.Integer.parseInt(args(0)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
object cat
|
|
|
|
|
{
|
|
|
|
|
def main(args: Array[String])
|
|
|
|
|
{
|
2010-07-05 18:53:37 +02:00
|
|
|
try {
|
2009-06-26 03:26:06 +02:00
|
|
|
if(args.length == 0)
|
2010-07-05 18:53:37 +02:00
|
|
|
IO.transfer(System.in, System.out)
|
2009-06-26 03:26:06 +02:00
|
|
|
else
|
|
|
|
|
catFiles(args.toList)
|
2010-07-05 18:53:37 +02:00
|
|
|
System.exit(0)
|
|
|
|
|
} catch {
|
|
|
|
|
case e =>
|
|
|
|
|
e.printStackTrace()
|
|
|
|
|
System.err.println("Error: " + e.toString)
|
|
|
|
|
System.exit(1)
|
2009-06-26 03:26:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private def catFiles(filenames: List[String]): Option[String] =
|
|
|
|
|
{
|
|
|
|
|
filenames match
|
|
|
|
|
{
|
|
|
|
|
case head :: tail =>
|
|
|
|
|
val file = new File(head)
|
|
|
|
|
if(file.isDirectory)
|
2010-07-05 18:53:37 +02:00
|
|
|
throw new IOException("Is directory: " + file)
|
2009-06-26 03:26:06 +02:00
|
|
|
else if(file.exists)
|
|
|
|
|
{
|
2010-07-05 18:53:37 +02:00
|
|
|
Using.fileInputStream(file) { stream =>
|
|
|
|
|
IO.transfer(stream, System.out)
|
2009-06-26 03:26:06 +02:00
|
|
|
}
|
|
|
|
|
catFiles(tail)
|
|
|
|
|
}
|
|
|
|
|
else
|
2010-07-05 18:53:37 +02:00
|
|
|
throw new FileNotFoundException("No such file or directory: " + file)
|
2009-06-26 03:26:06 +02:00
|
|
|
case Nil => None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
object echo
|
|
|
|
|
{
|
|
|
|
|
def main(args: Array[String])
|
|
|
|
|
{
|
|
|
|
|
System.out.println(args.mkString(" "))
|
|
|
|
|
}
|
|
|
|
|
}
|