summaryrefslogtreecommitdiffstats
path: root/util.cxx
diff options
context:
space:
mode:
authorhunt <hunt>2007-08-20 17:55:03 +0000
committerhunt <hunt>2007-08-20 17:55:03 +0000
commit8c711d30367365fa6a036e468eba4401d26131a3 (patch)
treee277133ca28d48b7fb841d6866953576ec9dd544 /util.cxx
parent322566b3574d9cb452e20f9b74bc0b7d3d9dcfe6 (diff)
downloadsystemtap-steved-8c711d30367365fa6a036e468eba4401d26131a3.tar.gz
systemtap-steved-8c711d30367365fa6a036e468eba4401d26131a3.tar.xz
systemtap-steved-8c711d30367365fa6a036e468eba4401d26131a3.zip
2007-08-20 Martin Hunt <hunt@redhat.com>
PR2424 From Lai Jiangshan <laijs@cn.fujitsu.com> * util.cxx (cmdstr_quoted): New. Properly quote command string. * buildrun.cxx (run_pass): Call cmdstr_quoted().
Diffstat (limited to 'util.cxx')
-rw-r--r--util.cxx31
1 files changed, 31 insertions, 0 deletions
diff --git a/util.cxx b/util.cxx
index af953395..97425d76 100644
--- a/util.cxx
+++ b/util.cxx
@@ -197,3 +197,34 @@ find_executable(const char *name, string& retpath)
return false;
}
+
+const string cmdstr_quoted(const string& cmd)
+{
+ // original cmd : substr1
+ // or : substr1'substr2
+ // or : substr1'substr2'substr3......
+ // after quoted :
+ // every substr(even it's empty) is quoted by ''
+ // every single-quote(') is quoted by ""
+ // examples: substr1 --> 'substr1'
+ // substr1'substr2 --> 'substr1'"'"'substr2'
+
+ string quoted_cmd;
+ string quote("'");
+ string replace("'\"'\"'");
+ string::size_type pos = 0;
+
+ quoted_cmd += quote;
+ for (string::size_type quote_pos = cmd.find(quote, pos);
+ quote_pos != string::npos;
+ quote_pos = cmd.find(quote, pos)) {
+ quoted_cmd += cmd.substr(pos, quote_pos - pos);
+ quoted_cmd += replace;
+ pos = quote_pos + 1;
+ }
+ quoted_cmd += cmd.substr(pos, cmd.length() - pos);
+ quoted_cmd += quote;
+
+ return quoted_cmd;
+}
+