Skip to content

Commit df71f6f

Browse files
authored
Merge pull request #6091 from TGWDB/WIN32-run-fix
Unify shell_quote under util/run
2 parents 16f4f09 + 65ce94e commit df71f6f

File tree

3 files changed

+4
-75
lines changed

3 files changed

+4
-75
lines changed

src/ansi-c/c_preprocess.cpp

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -22,80 +22,6 @@ Author: Daniel Kroening, [email protected]
2222

2323
#include <fstream>
2424

25-
/// quote a string for bash and CMD
26-
static std::string shell_quote(const std::string &src)
27-
{
28-
#ifdef _WIN32
29-
// first check if quoting is needed at all
30-
31-
if(src.find(' ')==std::string::npos &&
32-
src.find('"')==std::string::npos &&
33-
src.find('&')==std::string::npos &&
34-
src.find('|')==std::string::npos &&
35-
src.find('(')==std::string::npos &&
36-
src.find(')')==std::string::npos &&
37-
src.find('<')==std::string::npos &&
38-
src.find('>')==std::string::npos &&
39-
src.find('^')==std::string::npos)
40-
{
41-
// seems fine -- return as is
42-
return src;
43-
}
44-
45-
std::string result;
46-
47-
result+='"';
48-
49-
for(const char ch : src)
50-
{
51-
if(ch=='"')
52-
result+='"'; // quotes are doubled
53-
result+=ch;
54-
}
55-
56-
result+='"';
57-
58-
return result;
59-
60-
#else
61-
62-
// first check if quoting is needed at all
63-
64-
if(src.find(' ')==std::string::npos &&
65-
src.find('"')==std::string::npos &&
66-
src.find('*')==std::string::npos &&
67-
src.find('$')==std::string::npos &&
68-
src.find('\\')==std::string::npos &&
69-
src.find('?')==std::string::npos &&
70-
src.find('&')==std::string::npos &&
71-
src.find('|')==std::string::npos &&
72-
src.find('>')==std::string::npos &&
73-
src.find('<')==std::string::npos &&
74-
src.find('^')==std::string::npos &&
75-
src.find('\'')==std::string::npos)
76-
{
77-
// seems fine -- return as is
78-
return src;
79-
}
80-
81-
std::string result;
82-
83-
// the single quotes catch everything but themselves!
84-
result+='\'';
85-
86-
for(const char ch : src)
87-
{
88-
if(ch=='\'')
89-
result+="'\\''";
90-
result+=ch;
91-
}
92-
93-
result+='\'';
94-
95-
return result;
96-
#endif
97-
}
98-
9925
static void error_parse_line(
10026
const std::string &line,
10127
bool warning_only,

src/util/run.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ int run(
448448
}
449449

450450
/// quote a string for bash and CMD
451-
static std::string shell_quote(const std::string &src)
451+
std::string shell_quote(const std::string &src)
452452
{
453453
#ifdef _WIN32
454454
// first check if quoting is needed at all

src/util/run.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Date: August 2012
1616
#include <string>
1717
#include <vector>
1818

19+
/// This performs shell quoting if necessary on input \p src.
20+
std::string shell_quote(const std::string &src);
21+
1922
int run(const std::string &what, const std::vector<std::string> &argv);
2023

2124
/// This runs the executable given by the file name \p what.

0 commit comments

Comments
 (0)