From 6c4dc81c1b5e78e05d6143805f0f95b8520fd578 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Sat, 14 Sep 2019 02:40:03 +0200 Subject: [PATCH] Add the `-R` option --- CHANGELOG.md | 2 ++ docs/api/command-line.md | 2 ++ docs/api/getting-started.md | 6 +++--- src/main/scala/millfork/Context.scala | 1 + src/main/scala/millfork/Main.scala | 9 +++++++-- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f763cf88..cc25f0fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Current version +* Added `-R` option for specifying extra commandline parameters for emulators. + * Added full 16-bit multiplication. * Added preliminary support for EasyFlash. diff --git a/docs/api/command-line.md b/docs/api/command-line.md index 005b9128..fae95dfa 100644 --- a/docs/api/command-line.md +++ b/docs/api/command-line.md @@ -60,6 +60,8 @@ Unlike `-I`, this does not replace the default include directory and allows usin * `-r ` – Run given program after successful compilation. Useful for automatically launching emulators without any external scripting. +* `-R ` – Adds a parameter to the command line of the program run with `-r`. All `-R` options are added in order, before the output file name. + * `-D =` – Defines a feature value for the preprocessor. * `-finput_intel_syntax`, `-finput_zilog_syntax` – diff --git a/docs/api/getting-started.md b/docs/api/getting-started.md index 67214134..76f561f8 100644 --- a/docs/api/getting-started.md +++ b/docs/api/getting-started.md @@ -37,9 +37,9 @@ x64 hello_world.prg The following options are obligatory when compiling your sources: -* `-o FILENAME` – specifies the base name for your output file, an appropriate file extension will be appended. +* `-o ` – specifies the base name for your output file, an appropriate file extension will be appended. -* `-t PLATFORM` – specifies the target platform. +* `-t ` – specifies the target platform. Each platform is defined in an `.ini` file in the include directory. For the list of supported platforms, see [Supported platforms](target-platforms.md) @@ -58,7 +58,7 @@ You may be also interested in the following: * `-g` – additionally generate a label file -* `-r PROGRAM` – automatically launch given program after successful compilation +* `-r ` – automatically launch given program after successful compilation; you can supply extra params for it with `-R ` * `-Wall` – enable all warnings diff --git a/src/main/scala/millfork/Context.scala b/src/main/scala/millfork/Context.scala index a5247763..18a637f6 100644 --- a/src/main/scala/millfork/Context.scala +++ b/src/main/scala/millfork/Context.scala @@ -10,6 +10,7 @@ case class Context(errorReporting: Logger, inputFileNames: List[String], outputFileName: Option[String] = None, runFileName: Option[String] = None, + runParams: Seq[String] = Vector(), optimizationLevel: Option[Int] = None, zpRegisterSize: Option[Int] = None, platform: Option[String] = None, diff --git a/src/main/scala/millfork/Main.scala b/src/main/scala/millfork/Main.scala index 68e5296c..aa842a1f 100644 --- a/src/main/scala/millfork/Main.scala +++ b/src/main/scala/millfork/Main.scala @@ -135,8 +135,9 @@ object Main { errorReporting.debug(s"Total time: ${Math.round((System.nanoTime() - startTime)/1e6)} ms") c.runFileName.foreach{ program => val outputAbsolutePath = Paths.get(defaultPrgOutput).toAbsolutePath.toString - errorReporting.debug(s"Running: $program $outputAbsolutePath") - new ProcessBuilder(program, outputAbsolutePath).start() + val cmdline = program +: c.runParams :+ outputAbsolutePath + errorReporting.debug(s"Running: ${cmdline.mkString(" ")}") + new ProcessBuilder(cmdline.toArray: _*).directory(new File(program).getParentFile).start() } if (platform.generateBbcMicroInfFile) { val start = platform.codeAllocators("default").startAt @@ -409,6 +410,10 @@ object Main { c.copy(runFileName = Some(p)) }.description("Program to run after successful compilation.") + parameter("-R", "--run-param").placeholder("").action { (p, c) => + c.copy(runParams = c.runParams :+ p) + }.description("Adds a commandline parameter to the program launched with -r") + parameter("-D", "--define").placeholder("=").action { (p, c) => val tokens = p.split('=') if (tokens.length == 2) {