[PATCH] Setup: escape '%' in path in cygwin.bat
Igor Pechtchanski
pechtcha@cs.nyu.edu
Thu Jul 10 01:40:00 GMT 2003
On Wed, 28 May 2003, Igor Pechtchanski wrote:
> [snip]
> Setup should be able to handle %'s in root_dir, though... Line 185 of
> desktop.cc would be the place to put the fix in, but I don't have the time
> for this right now...
Well, I finally found the time, so here's the patch.
Igor
==============================================================================
2003-07-09 Igor Pechtchanski <pechtcha@cs.nyu.edu>
* String++.h (String::replace): New instance functions.
* String++.cc (String::replace): Implement.
* filemanip.cc (backslash): Change to use String::replace.
* desktop.cc (make_cygwin_bat): Escape '%' in path.
--
http://cs.nyu.edu/~pechtcha/
|\ _,,,---,,_ pechtcha@cs.nyu.edu
ZZZzz /,`.-'`' -. ;-;;,_ igor@watson.ibm.com
|,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski, Ph.D.
'---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow!
"I have since come to realize that being between your mentor and his route
to the bathroom is a major career booster." -- Patrick Naughton
-------------- next part --------------
Index: String++.h
===================================================================
RCS file: /cvs/cygwin-apps/setup/String++.h,v
retrieving revision 2.11
diff -u -p -r2.11 String++.h
--- String++.h 23 Jun 2003 20:48:59 -0000 2.11
+++ String++.h 10 Jul 2003 01:30:23 -0000
@@ -63,6 +63,8 @@ public:
return s1.casecompare (s2) < 0;
}};
bool matches (String const &pattern) const;
+ String replace (char pattern, char replacement) const;
+ String replace (String const &pattern, String const &replacement) const;
private:
class _data {
Index: String++.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/String++.cc,v
retrieving revision 2.10
diff -u -p -r2.10 String++.cc
--- String++.cc 18 Mar 2003 22:43:15 -0000 2.10
+++ String++.cc 10 Jul 2003 01:30:23 -0000
@@ -395,6 +395,63 @@ String::matches (String const &pattern)
theData->theString, theData->length);
}
+String
+String::replace (char pattern, char replacement) const
+{
+ unsigned char *tempcString = new unsigned char [theData->length];
+ // remove when exceptions are done
+ if (!tempcString)
+ exit (100);
+ unsigned char *s = theData->theString;
+ unsigned char *d = tempcString;
+ unsigned char *end = theData->theString + theData->length;
+ for (s = theData->theString; s < end; ++s)
+ {
+ if (*s == pattern)
+ *d++ = replacement;
+ else
+ *d++ = *s;
+ }
+ return absorb (tempcString, theData->length);
+}
+
+String
+String::replace (String const &pattern, String const &replacement) const
+{
+ int growth = replacement.theData->length - pattern.theData->length + 1;
+ if (growth < 1) growth = 1;
+ unsigned char *tempcString = new unsigned char [theData->length * growth];
+ // remove when exceptions are done
+ if (!tempcString)
+ exit (100);
+ unsigned char *s = theData->theString;
+ unsigned char *d = tempcString;
+ unsigned char *end = theData->theString + theData->length;
+ for (s = theData->theString; s < end - pattern.theData->length; )
+ {
+ if (memcmp(s, pattern.theData->theString, pattern.theData->length) == 0)
+ {
+ s += pattern.theData->length;
+ memcpy(d, replacement.theData->theString, replacement.theData->length);
+ d += replacement.theData->length;
+ }
+ else
+ *d++ = *s++;
+ }
+ for (; s < end; )
+ *d++ = *s++;
+ size_t length = d - tempcString;
+ // Avoid wasting space
+ unsigned char *newCopy = new unsigned char[length];
+ // remove when exceptions are done
+ if (!newCopy)
+ exit (100);
+ memcpy (newCopy, tempcString, length);
+ delete[] tempcString;
+
+ return absorb (newCopy, length);
+}
+
/* TODO: research how wide char and unicode interoperate with
* C++ streams
*/
Index: filemanip.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/filemanip.cc,v
retrieving revision 2.11
diff -u -p -r2.11 filemanip.cc
--- filemanip.cc 5 Jul 2002 01:59:34 -0000 2.11
+++ filemanip.cc 10 Jul 2003 01:30:23 -0000
@@ -166,11 +166,5 @@ trail (const char *haystack, const char
String
backslash (String const & aString)
{
- char * tempString = aString.cstr();
- for (char *t = tempString; *t; t++)
- if (*t == '/')
- *t = '\\';
- String theString(tempString);
- delete[] tempString;
- return theString;
+ return aString.replace ('/', '\\');
}
Index: desktop.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/desktop.cc,v
retrieving revision 2.35
diff -u -p -r2.35 desktop.cc
--- desktop.cc 25 Mar 2003 20:57:13 -0000 2.35
+++ desktop.cc 10 Jul 2003 01:30:23 -0000
@@ -182,7 +182,7 @@ make_cygwin_bat ()
fprintf (bat, "%.2s\n", get_root_dir ().cstr_oneuse());
fprintf (bat, "chdir %s\n\n",
- backslash (get_root_dir () + "/bin").cstr_oneuse());
+ backslash (get_root_dir () + "/bin").replace ("%", "%%").cstr_oneuse());
fprintf (bat, "bash --login -i\n");
More information about the Cygwin-apps
mailing list