Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlain Magloire2003-02-25 11:05:46 -0500
committerAlain Magloire2003-02-25 11:05:46 -0500
commit203cb53ced1d1464f0c9965e176604021ab7567f (patch)
tree9708cf0b4013533992b55e18a1a7b45f0b720f78 /core/org.eclipse.cdt.core.win32/library
parent7e0b8b204cd4e00616a0801e308e676af968c27d (diff)
downloadorg.eclipse.cdt-203cb53ced1d1464f0c9965e176604021ab7567f.tar.gz
org.eclipse.cdt-203cb53ced1d1464f0c9965e176604021ab7567f.tar.xz
org.eclipse.cdt-203cb53ced1d1464f0c9965e176604021ab7567f.zip
Fix embedded quotation.
Diffstat (limited to 'core/org.eclipse.cdt.core.win32/library')
-rw-r--r--core/org.eclipse.cdt.core.win32/library/Win32ProcessEx.c24
-rw-r--r--core/org.eclipse.cdt.core.win32/library/starter/starter.cpp26
2 files changed, 38 insertions, 12 deletions
diff --git a/core/org.eclipse.cdt.core.win32/library/Win32ProcessEx.c b/core/org.eclipse.cdt.core.win32/library/Win32ProcessEx.c
index 29b641fe50..af32311049 100644
--- a/core/org.eclipse.cdt.core.win32/library/Win32ProcessEx.c
+++ b/core/org.eclipse.cdt.core.win32/library/Win32ProcessEx.c
@@ -739,19 +739,32 @@ int copyTo(char * target, const char * source, int cpyLength, int availSpace)
BOOL bSlash = FALSE;
int i = 0, j = 0;
int totCpyLength = cpyLength;
- BOOL bQoutedTerm = FALSE;
+
+#define QUOTATION_DO 0
+#define QUOTATION_DONE 1
+#define QUOTATION_NONE 2
+
+ int nQuotationMode = 0;
+
if(availSpace <= cpyLength) // = to reserve space for final '\0'
return -1;
if(('\"' == *source) && ('\"' == *(source + cpyLength - 1)))
- bQoutedTerm = TRUE; // Already quoted
+ {
+ nQuotationMode = QUOTATION_DONE;
+ }
else
if(strchr(source, ' ') == NULL)
- bQoutedTerm = TRUE; // No reason to quotate term becase it doesn't have embedded spaces
+ {
+ // No reason to quotate term becase it doesn't have embedded spaces
+ nQuotationMode = QUOTATION_NONE;
+ }
else
{
+ // Needs to be quotated
+ nQuotationMode = QUOTATION_DO;
*target = '\"';
++j;
}
@@ -763,7 +776,8 @@ int copyTo(char * target, const char * source, int cpyLength, int availSpace)
bSlash = TRUE;
else
{
- if(source[i] == '\"' && (!bQoutedTerm || ((i != 0) && (i != (cpyLength - 1))) ) )
+ // Don't escape embracing quotation marks
+ if((source[i] == '\"') && !((nQuotationMode == QUOTATION_DONE) && ((i == 0) || (i == (cpyLength - 1))) ) )
{
if(!bSlash) // If still not escaped
{
@@ -781,7 +795,7 @@ int copyTo(char * target, const char * source, int cpyLength, int availSpace)
target[j] = source[i];
}
- if(!bQoutedTerm)
+ if(nQuotationMode == QUOTATION_DO)
{
if(j == availSpace)
return -1;
diff --git a/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp b/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp
index 5224412a06..81df10d894 100644
--- a/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp
+++ b/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp
@@ -187,29 +187,41 @@ int copyTo(LPTSTR target, LPCTSTR source, int cpyLength, int availSpace)
BOOL bSlash = FALSE;
int i = 0, j = 0;
int totCpyLength = cpyLength;
- BOOL bQoutedTerm = FALSE;
+
+#define QUOTATION_DO 0
+#define QUOTATION_DONE 1
+#define QUOTATION_NONE 2
+
+ int nQuotationMode = 0;
if(availSpace <= cpyLength) // = to reserve space for '\0'
return -1;
if((_T('\"') == *source) && (_T('\"') == *(source + cpyLength - 1)))
- bQoutedTerm = TRUE; // Already quoted
+ {
+ // Already done
+ nQuotationMode = QUOTATION_DONE;
+ }
else
if(_tcschr(source, _T(' ')) == NULL)
- bQoutedTerm = TRUE; // No reason to quotate term becase it doesn't have embedded spaces
+ {
+ // No reason to quotate term becase it doesn't have embedded spaces
+ nQuotationMode = QUOTATION_NONE;
+ }
else
{
+ // Needs to be quotated
+ nQuotationMode = QUOTATION_DO;
*target = _T('\"');
++j;
}
-
for(; i < cpyLength; ++i, ++j)
{
if(source[i] == _T('\\'))
bSlash = TRUE;
else
- // Escape double quote only if quotation mark is not start or end character
- if((source[i] == _T('\"')) && (!bQoutedTerm || ((i != 0) && (i != (cpyLength - 1)))) )
+ // Don't escape embracing quotation marks
+ if((source[i] == _T('\"')) && !((nQuotationMode == QUOTATION_DONE) && ((i == 0) || (i == (cpyLength - 1))) ) )
{
if(!bSlash)
{
@@ -228,7 +240,7 @@ int copyTo(LPTSTR target, LPCTSTR source, int cpyLength, int availSpace)
target[j] = source[i];
}
- if(!bQoutedTerm)
+ if(nQuotationMode == QUOTATION_DO)
{
if(j == availSpace)
return -1;

Back to the top