summaryrefslogtreecommitdiff
path: root/Source/cmOutputConverter.h
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-07-07 15:06:44 -0400
committerBrad King <brad.king@kitware.com>2015-07-08 09:09:49 -0400
commitdf97bea2427706d56dc15587b88e0f268ee37622 (patch)
treeed65c202c02348119c6ca97a0442ddb4d67538ae /Source/cmOutputConverter.h
parentbb7eefe4dd4b1385b830ac0f784af883a3d91985 (diff)
downloadcmake-df97bea2427706d56dc15587b88e0f268ee37622.tar.gz
cmOutputConverter: Adopt command line escaping code
Port code from the KWSys System_Shell APIs into cmOutputConverter. Drop it from our copy of KWSys because upstream will drop it too, and by doing it in this commit 'git blame' may have an easier time connecting the history of the content.
Diffstat (limited to 'Source/cmOutputConverter.h')
-rw-r--r--Source/cmOutputConverter.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h
index 8739b979fe..ed7739edfe 100644
--- a/Source/cmOutputConverter.h
+++ b/Source/cmOutputConverter.h
@@ -64,6 +64,63 @@ public:
void SetLinkScriptShell(bool linkScriptShell);
+ /**
+ * Flags to pass to Shell_GetArgumentForWindows or
+ * Shell_GetArgumentForUnix. These modify the generated
+ * quoting and escape sequences to work under alternative
+ * environments.
+ */
+ enum Shell_Flag_e
+ {
+ /** The target shell is in a makefile. */
+ Shell_Flag_Make = (1<<0),
+
+ /** The target shell is in a VS project file. Do not use with
+ Shell_Flag_Make. */
+ Shell_Flag_VSIDE = (1<<1),
+
+ /** In a windows shell the argument is being passed to "echo". */
+ Shell_Flag_EchoWindows = (1<<2),
+
+ /** The target shell is in a Watcom WMake makefile. */
+ Shell_Flag_WatcomWMake = (1<<3),
+
+ /** The target shell is in a MinGW Make makefile. */
+ Shell_Flag_MinGWMake = (1<<4),
+
+ /** The target shell is in a NMake makefile. */
+ Shell_Flag_NMake = (1<<5),
+
+ /** Make variable reference syntax $(MAKEVAR) should not be escaped
+ to allow a build tool to replace it. Replacement values
+ containing spaces, quotes, backslashes, or other
+ non-alphanumeric characters that have significance to some makes
+ or shells produce undefined behavior. */
+ Shell_Flag_AllowMakeVariables = (1<<6),
+
+ /** The target shell quoting uses extra single Quotes for Watcom tools. */
+ Shell_Flag_WatcomQuote = (1<<7)
+ };
+
+ /**
+ * Transform the given command line argument for use in a Windows or
+ * Unix shell. Returns a pointer to the end of the command line
+ * argument in the provided output buffer. Flags may be passed to
+ * modify the generated quoting and escape sequences to work under
+ * alternative environments.
+ */
+ static char* Shell_GetArgumentForWindows(const char* in, char* out,
+ int flags);
+ static char* Shell_GetArgumentForUnix(const char* in, char* out, int flags);
+
+ /**
+ * Compute the size of the buffer required to store the output from
+ * Shell_GetArgumentForWindows or Shell_GetArgumentForUnix. The flags
+ * passed must be identical between the two calls.
+ */
+ static int Shell_GetArgumentSizeForWindows(const char* in, int flags);
+ static int Shell_GetArgumentSizeForUnix(const char* in, int flags);
+
std::string EscapeForShell(const std::string& str,
bool makeVars = false,
bool forEcho = false,
@@ -102,6 +159,19 @@ private:
std::string const& result,
OutputFormat format) const;
+ static int Shell__CharIsWhitespace(char c);
+ static int Shell__CharNeedsQuotesOnUnix(char c);
+ static int Shell__CharNeedsQuotesOnWindows(char c);
+ static int Shell__CharNeedsQuotes(char c, int isUnix, int flags);
+ static int Shell__CharIsMakeVariableName(char c);
+ static const char* Shell__SkipMakeVariables(const char* c);
+ static int Shell__ArgumentNeedsQuotes(const char* in,
+ int isUnix, int flags);
+ static int Shell__GetArgumentSize(const char* in,
+ int isUnix, int flags);
+ static char* Shell__GetArgument(const char* in, char* out,
+ int isUnix, int flags);
+
private:
cmState::Snapshot StateSnapshot;