From 1a4d37e9438e3d4d02b1b87ccbbb6949184c1d55 Mon Sep 17 00:00:00 2001 From: CaS Date: Tue, 11 Feb 2003 15:48:41 +0000 Subject: [PATCH] task fixups for mingw git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@15938 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 6 +++++ Source/NSTask.m | 63 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17670b428..22785ae45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-02-11 Tom Koelman + + * Source/NSTask.m: Make arguments into windows quoted strings for + mingw. Adjustments to conform to GNUstep style and use static + functions to avoid adding methods by RFM. + 2003-02-11 Adam Fedor * configure (LDFLAGS): Remove extra spaces that cause problems diff --git a/Source/NSTask.m b/Source/NSTask.m index 7306ac0cb..ee5f508a8 100644 --- a/Source/NSTask.m +++ b/Source/NSTask.m @@ -28,8 +28,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -1008,6 +1010,58 @@ static DWORD WINAPI _threadFunction(LPVOID t) } } + +static NSString* +endSlashesDoubledFromString(NSString *aString) +{ + int i = [aString length] - 2; + NSMutableString *returnString; + + if (![aString hasSuffix:@"\\"]) + { + return aString; + } + returnString = [NSMutableString stringWithFormat: @"%@\\", aString]; + while ([aString characterAtIndex: i] == '\\' && i >= 0) + { + [returnString appendString:@"\\"]; + i--; + } + + return returnString; +} + +static NSString* +quotedFromString(NSString *aString) +{ + NSString *resultString; + NSMutableArray *components; + int i; + + /* First split on "'s */ + components = [NSMutableArray arrayWithArray: + [aString componentsSeparatedByString: @"\""]]; + + /* Iterate over all but the last component and double slashes if needed */ + i = [components count]; + while (i-- > 0) + { + [components replaceObjectAtIndex: i withObject: + endSlashesDoubledFromString([components objectAtIndex: i])]; + } + + /* Join them again with \" as separator */ + resultString = [components componentsJoinedByString: @"\\\""]; + + /* Put in in "'s if it contains spaces */ + if ([resultString rangeOfCharacterFromSet: + [NSCharacterSet whitespaceCharacterSet]].length > 0) + { + resultString = [NSString stringWithFormat: @"\"%@\"", resultString]; + } + return resultString; +} + - (void) launch { DWORD tid; @@ -1019,7 +1073,7 @@ static DWORD WINAPI _threadFunction(LPVOID t) char *c_args; int result; const char *executable; - + if (_hasLaunched) { return; @@ -1027,13 +1081,16 @@ static DWORD WINAPI _threadFunction(LPVOID t) lpath = [self _fullLaunchPath]; executable = [lpath fileSystemRepresentation]; - args = [[NSMutableString alloc] initWithCString: executable]; + + args = [[NSMutableString alloc] initWithString: + quotedFromString([NSString stringWithCString: executable])]; arg_enum = [[self arguments] objectEnumerator]; while ((arg = [arg_enum nextObject])) { [args appendString: @" "]; - [args appendString: arg]; + [args appendString: quotedFromString(arg)]; } + c_args = NSZoneMalloc(NSDefaultMallocZone(), [args cStringLength]+1); [args getCString: c_args];