summaryrefslogtreecommitdiff
path: root/libs/pbd/system_exec.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2018-11-20 23:56:12 +0100
committerRobin Gareus <robin@gareus.org>2018-11-20 23:56:12 +0100
commitd169864b5bd08c9dbd064e8543ebd074e5695216 (patch)
tree2ebc2c31e6ee0f72cb5476d30fbb26045c41cce5 /libs/pbd/system_exec.cc
parent0268489c7853780a91f289a409ec00c6e561526c (diff)
Prepare session-metadata export to external command
Diffstat (limited to 'libs/pbd/system_exec.cc')
-rw-r--r--libs/pbd/system_exec.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/libs/pbd/system_exec.cc b/libs/pbd/system_exec.cc
index cc5d8d99fe..26f50146c8 100644
--- a/libs/pbd/system_exec.cc
+++ b/libs/pbd/system_exec.cc
@@ -236,6 +236,39 @@ SystemExec::SystemExec (std::string command, const std::map<char, std::string> s
make_envp();
}
+char*
+SystemExec::format_key_value_parameter (std::string key, std::string value)
+{
+ size_t start_pos = 0;
+ std::string v1 = value;
+ while((start_pos = v1.find_first_not_of(
+ "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789(),.\"'",
+ start_pos)) != std::string::npos)
+ {
+ v1.replace(start_pos, 1, "_");
+ start_pos += 1;
+ }
+
+ start_pos = 0;
+ while((start_pos = v1.find("\"", start_pos)) != std::string::npos) {
+ v1.replace(start_pos, 1, "\\\"");
+ start_pos += 2;
+ }
+
+ size_t len = key.length() + v1.length() + 4;
+ char *mds = (char*) calloc(len, sizeof(char));
+#ifdef PLATFORM_WINDOWS
+ /* SystemExec::make_wargs() adds quotes around the complete argument
+ * windows uses CreateProcess() with a parameter string
+ * (and not an array list of separate arguments)
+ */
+ snprintf(mds, len, "%s=%s", key.c_str(), v1.c_str());
+#else
+ snprintf(mds, len, "%s=\"%s\"", key.c_str(), v1.c_str());
+#endif
+ return mds;
+}
+
void
SystemExec::make_argp_escaped(std::string command, const std::map<char, std::string> subs)
{