summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/compiler/scala/tools/ant/Scalac.scala2
-rw-r--r--src/compiler/scala/tools/ant/Scaladoc.scala4
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala66
-rw-r--r--src/partest/scala/tools/partest/nest/TestFile.scala2
4 files changed, 64 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/ant/Scalac.scala b/src/compiler/scala/tools/ant/Scalac.scala
index 40771d55a6..b01576315f 100644
--- a/src/compiler/scala/tools/ant/Scalac.scala
+++ b/src/compiler/scala/tools/ant/Scalac.scala
@@ -563,7 +563,7 @@ class Scalac extends MatchingTask {
log("Scalac params = '" + addParams + "'", Project.MSG_DEBUG)
// let CompilerCommand processes all params
- val command = new CompilerCommand(addParams.trim.split("""\s+""").toList, settings, error, false)
+ val command = new CompilerCommand(settings.splitParams(addParams), settings, error, false)
// resolve dependenciesFile path from project's basedir, so <ant antfile ...> call from other project works.
// the dependenciesFile may be relative path to basedir or absolute path, in either case, the following code
diff --git a/src/compiler/scala/tools/ant/Scaladoc.scala b/src/compiler/scala/tools/ant/Scaladoc.scala
index 94b50ab045..9dd96b0af5 100644
--- a/src/compiler/scala/tools/ant/Scaladoc.scala
+++ b/src/compiler/scala/tools/ant/Scaladoc.scala
@@ -496,9 +496,7 @@ class Scaladoc extends MatchingTask {
docSettings.deprecation.value = deprecation
docSettings.unchecked.value = unchecked
log("Scaladoc params = '" + addParams + "'", Project.MSG_DEBUG)
- var args =
- if (addParams.trim() == "") Nil
- else addParams.trim().split(" ").toList.map(_.trim())
+ var args = docSettings.splitParams(addParams)
while (!args.isEmpty) {
if (args.head startsWith "-") {
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
diff --git a/src/partest/scala/tools/partest/nest/TestFile.scala b/src/partest/scala/tools/partest/nest/TestFile.scala
index b8223a9202..9711b1ace8 100644
--- a/src/partest/scala/tools/partest/nest/TestFile.scala
+++ b/src/partest/scala/tools/partest/nest/TestFile.scala
@@ -34,7 +34,7 @@ class TestFile(kind: String, val file: File, val fileManager: FileManager, creat
val reader = new BufferedReader(new java.io.FileReader(flagsFile))
val flags = reader.readLine
if (flags ne null)
- settings.parseParams(flags)
+ settings.parseParams(settings.splitParams(flags))
}
}