summaryrefslogtreecommitdiffstats
path: root/source/core/slang-command-line.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/core/slang-command-line.cpp')
-rw-r--r--source/core/slang-command-line.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/source/core/slang-command-line.cpp b/source/core/slang-command-line.cpp
new file mode 100644
index 000000000..419c031ab
--- /dev/null
+++ b/source/core/slang-command-line.cpp
@@ -0,0 +1,54 @@
+// slang-command-line.cpp
+#include "slang-command-line.h"
+
+#include "slang-process.h"
+
+#include "slang-string.h"
+#include "slang-string-escape-util.h"
+#include "slang-string-util.h"
+
+#include "../../slang-com-helper.h"
+
+namespace Slang {
+
+void CommandLine::addPrefixPathArg(const char* prefix, const String& path, const char* pathPostfix)
+{
+ StringBuilder builder;
+ builder << prefix << path;
+ if (pathPostfix)
+ {
+ // Work out the path with the postfix
+ builder << pathPostfix;
+ }
+ addArg(builder.ProduceString());
+}
+
+void CommandLine::setExecutable(const String& dir, const String& name)
+{
+ StringBuilder builder;
+ Path::combineIntoBuilder(dir.getUnownedSlice(), name.getUnownedSlice(), builder);
+ builder << Process::getExecutableSuffix();
+ setExecutablePath(builder.ProduceString());
+}
+
+void CommandLine::append(StringBuilder& out) const
+{
+ auto escapeHandler = Process::getEscapeHandler();
+
+ StringEscapeUtil::appendMaybeQuoted(escapeHandler, m_executable.getUnownedSlice(), out);
+
+ for (const auto& arg : m_args)
+ {
+ out << " ";
+ StringEscapeUtil::appendMaybeQuoted(escapeHandler, arg.getUnownedSlice(), out);
+ }
+}
+
+String CommandLine::toString() const
+{
+ StringBuilder buf;
+ append(buf);
+ return buf.ProduceString();
+}
+
+} // namespace Slang