summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/Settings.scala
diff options
context:
space:
mode:
authordcaoyuan <dcaoyuan@epfl.ch>2009-12-05 07:21:25 +0000
committerdcaoyuan <dcaoyuan@epfl.ch>2009-12-05 07:21:25 +0000
commit70ff72a16ae116e0f2844051424127ac994686c9 (patch)
tree7e950abaf686a2e416016546a7312ea3b985e53a /src/compiler/scala/tools/nsc/Settings.scala
parentff2a9b4c589fb22566359a149b7e76d372676d02 (diff)
downloadscala-70ff72a16ae116e0f2844051424127ac994686c9.tar.gz
scala-70ff72a16ae116e0f2844051424127ac994686c9.tar.bz2
scala-70ff72a16ae116e0f2844051424127ac994686c9.zip
Split command line parameters by space, properl...
Split command line parameters by space, properly process quoted parameter
Diffstat (limited to 'src/compiler/scala/tools/nsc/Settings.scala')
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala66
1 files changed, 61 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala
index 83dc88eff0..6d3771b681 100644
--- a/src/compiler/scala/tools/nsc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/Settings.scala
@@ -93,12 +93,68 @@ class Settings(errorFn: String => Unit) extends ScalacSettings {
*/
lazy val outputDirs = new OutputDirs
-
- /** Try to add additional command line parameters.
- * Returns unconsumed arguments.
+ /**
+ * Split command line parameters by space, properly process quoted parameter
*/
- def parseParams(line: String): List[String] =
- parseParams(line.trim.split("""\s+""").toList)
+ def splitParams(line: String): List[String] = {
+ def parse(from: Int, i: Int, args: List[String]): List[String] = {
+ if (i < line.length) {
+ line.charAt(i) match {
+ case ' ' =>
+ val args1 = fetchArg(from, i) :: args
+ val j = skipS(i + 1)
+ if (j >= 0) {
+ parse(j, j, args1)
+ } else args1
+ case '"' =>
+ val j = skipTillQuote(i + 1)
+ if (j > 0) {
+ parse(from, j + 1, args)
+ } else {
+ errorFn("Parameters '" + line + "' with unmatched quote at " + i + ".")
+ Nil
+ }
+ case _ => parse(from, i + 1, args)
+ }
+ } else { // done
+ if (i >= from) {
+ fetchArg(from, i) :: args
+ } else args
+ }
+ }
+
+ def fetchArg(from: Int, until: Int) = {
+ if (line.charAt(from) == '"') {
+ line.substring(from + 1, until - 1)
+ } else {
+ line.substring(from, until)
+ }
+ }
+
+ def skipTillQuote(i: Int): Int = {
+ if (i < line.length) {
+ line.charAt(i) match {
+ case '"' => i
+ case _ => skipTillQuote(i + 1)
+ }
+ } else -1
+ }
+
+ def skipS(i: Int): Int = {
+ if (i < line.length) {
+ line.charAt(i) match {
+ case ' ' => skipS(i + 1)
+ case _ => i
+ }
+ } else -1
+ }
+
+ // begin split
+ val j = skipS(0)
+ if (j >= 0) {
+ parse(j, j, Nil).reverse
+ } else Nil
+ }
def parseParams(args: List[String]): List[String] = {
// verify command exists and call setter