From 36982798f7aed3c7adcc25ba92192657ec1c02bf Mon Sep 17 00:00:00 2001
From: Jiri Malak <malak.jiri@gmail.com>
Date: Tue, 1 Apr 2014 18:53:17 +0200
Subject: [PATCH] SystemTools: add Watcom single Quote processing

Enable to add extra single quote used by some Watcom tools.

Change-Id: I257bafd1c09c02642e0d793caf7461454bc4b04a
---
 System.c    | 30 ++++++++++++++++++++++++++++--
 System.h.in |  9 +++++++--
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/System.c b/System.c
index 5d178bfa..1ee26fac 100644
--- a/System.c
+++ b/System.c
@@ -353,6 +353,10 @@ static int kwsysSystem_Shell__GetArgumentSize(const char* in,
   if(kwsysSystem_Shell__ArgumentNeedsQuotes(in, isUnix, flags))
     {
     /* Surrounding quotes are needed.  Allocate space for them.  */
+    if((flags & kwsysSystem_Shell_Flag_WatcomQuote) && (isUnix))
+      {
+        size += 2;
+      }
     size += 2;
 
     /* We must escape all ending backslashes when quoting on windows.  */
@@ -377,7 +381,18 @@ static char* kwsysSystem_Shell__GetArgument(const char* in, char* out,
   if(needQuotes)
     {
     /* Add the opening quote for this argument.  */
-    *out++ = '"';
+    if(flags & kwsysSystem_Shell_Flag_WatcomQuote)
+      {
+      if(isUnix)
+        {
+        *out++ = '"';
+        }
+      *out++ = '\'';
+      }
+    else
+      {
+      *out++ = '"';
+      }
     }
 
   /* Scan the string for characters that require escaping or quoting.  */
@@ -549,7 +564,18 @@ static char* kwsysSystem_Shell__GetArgument(const char* in, char* out,
       }
 
     /* Add the closing quote for this argument.  */
-    *out++ = '"';
+    if(flags & kwsysSystem_Shell_Flag_WatcomQuote)
+      {
+      *out++ = '\'';
+      if(isUnix)
+        {
+        *out++ = '"';
+        }
+      }
+    else
+      {
+      *out++ = '"';
+      }
     }
 
   /* Store a terminating null without incrementing.  */
diff --git a/System.h.in b/System.h.in
index 549db900..f21bf0dc 100644
--- a/System.h.in
+++ b/System.h.in
@@ -36,6 +36,7 @@
 # define kwsysSystem_Shell_Flag_MinGWMake             kwsys_ns(System_Shell_Flag_MinGWMake)
 # define kwsysSystem_Shell_Flag_NMake                 kwsys_ns(System_Shell_Flag_NMake)
 # define kwsysSystem_Shell_Flag_AllowMakeVariables    kwsys_ns(System_Shell_Flag_AllowMakeVariables)
+# define kwsysSystem_Shell_Flag_WatcomQuote           kwsys_ns(System_Shell_Flag_WatcomQuote)
 #endif
 
 #ifdef __VMS
@@ -102,14 +103,17 @@ enum kwsysSystem_Shell_Flag_e
   kwsysSystem_Shell_Flag_MinGWMake          = (1<<4),
 
   /** The target shell is in a NMake makefile.  */
-  kwsysSystem_Shell_Flag_NMake              = (1<<6),
+  kwsysSystem_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.  */
-  kwsysSystem_Shell_Flag_AllowMakeVariables = (1<<5)
+  kwsysSystem_Shell_Flag_AllowMakeVariables = (1<<6),
+
+  /** The target shell quoting uses extra single Quotes for Watcom tools.  */
+  kwsysSystem_Shell_Flag_WatcomQuote        = (1<<7)
 };
 
 /**
@@ -156,6 +160,7 @@ kwsysEXPORT char** kwsysSystem_Parse_CommandForUnix(const char* command,
 #  undef kwsysSystem_Shell_Flag_MinGWMake
 #  undef kwsysSystem_Shell_Flag_NMake
 #  undef kwsysSystem_Shell_Flag_AllowMakeVariables
+#  undef kwsysSystem_Shell_Flag_WatcomQuote
 # endif
 #endif
 
-- 
GitLab