Improve path handling under MINGW/MSYS

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13491 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2002-04-18 07:51:46 +00:00
parent ea3257eefc
commit a4d46f6a67
3 changed files with 85 additions and 29 deletions

View file

@ -1,6 +1,8 @@
2002-04-17 Richard Frith-Macdonald <rfm@gnu.org> 2002-04-17 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/gdomap.c: re-order headers so config.h is used on windoze * Tools/gdomap.c: re-order headers so config.h is used on windoze
* Source/NSFileManager.m: ([-fileSystemRepresentationWithPath:])
modified to handle MSYS paths with '/drive/' prefix.
2002-04-16 Richard Frith-Macdonald <rfm@gnu.org> 2002-04-16 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -1311,39 +1311,39 @@ static NSFileManager* defaultManager = nil;
{ {
#ifdef __MINGW__ #ifdef __MINGW__
/* /*
* If path is in Unix format, transmorgrify it so Windows functions * If path is in Unix format, transmogrify it so Windows functions
* can handle it * can handle it
*/ */
NSString *newpath = path; NSString *newpath = path;
const char *c_path = [path cString]; const char *c_path = [path cString];
int len = [path length]; int l = [path length];
if (c_path == 0) if (c_path == 0)
{ {
return 0; return 0;
} }
if (len >= 3 && c_path[0] == '/' && c_path[1] == '/' && isalpha(c_path[2])) if (l >= 3 && c_path[0] == '/' && c_path[1] == '/' && isalpha(c_path[2]))
{ {
if (len == 3 || c_path[3] == '/') if (l == 3 || c_path[3] == '/')
{ {
/* Cygwin "//c/" type absolute path */ /* Cygwin "//c/" type absolute path */
newpath = [NSString stringWithFormat: @"%c:%s", c_path[2], newpath = [NSString stringWithFormat: @"%c:%s", c_path[2],
&c_path[3]]; &c_path[3]];
newpath = [newpath stringByReplacingString: @"/" withString: @"\\"];
} }
else else
{ {
/* Windows absolute UNC path "//name/" */ /* Windows absolute UNC path "//name/" */
newpath = [newpath stringByReplacingString: @"/" withString: @"\\"]; newpath = path;
} }
} }
else if (isalpha(c_path[0]) && c_path[1] == ':') else if (isalpha(c_path[0]) && c_path[1] == ':')
{ {
/* Unix absolute path */ /* Windows absolute path */
newpath = [newpath stringByReplacingString: @"/" withString: @"\\"]; newpath = path;
} }
else if (c_path[0] == '/') else if (c_path[0] == '/')
{ {
#ifdef __CYGWIN__
NSDictionary *env; NSDictionary *env;
NSString *cyghome; NSString *cyghome;
@ -1354,10 +1354,29 @@ static NSFileManager* defaultManager = nil;
/* FIXME: Find cygwin drive? */ /* FIXME: Find cygwin drive? */
newpath = cyghome; newpath = cyghome;
newpath = [newpath stringByAppendingPathComponent: path]; newpath = [newpath stringByAppendingPathComponent: path];
newpath = [newpath stringByReplacingString: @"/" withString: @"\\"];
} }
else
{
newpath = path;
}
#else
if (l >= 3 && c_path[0] == '/' && c_path[2] == '/' && isalpha(c_path[1]))
{
/* Mingw /drive/... format */
newpath = [NSString stringWithFormat: @"%c:%s", c_path[1],
&c_path[3]];
}
else
{
newpath = path;
}
#endif
} }
/* FIXME: Should we translate relative paths? */ else
{
newpath = path;
}
newpath = [newpath stringByReplacingString: @"/" withString: @"\\"];
return [newpath cString]; return [newpath cString];
#else #else
return [path cString]; return [path cString];

View file

@ -2478,7 +2478,7 @@ handle_printf_atsign (FILE *stream,
if (fm == nil) if (fm == nil)
{ {
fm = [NSFileManager defaultManager]; fm = RETAIN([NSFileManager defaultManager]);
} }
return [fm fileSystemRepresentationWithPath: self]; return [fm fileSystemRepresentationWithPath: self];
@ -2507,17 +2507,25 @@ handle_printf_atsign (FILE *stream,
range = [self rangeOfCharacterFromSet: pathSeps() options: NSBackwardsSearch]; range = [self rangeOfCharacterFromSet: pathSeps() options: NSBackwardsSearch];
if (range.length == 0) if (range.length == 0)
substring = AUTORELEASE([self copy]); {
substring = AUTORELEASE([self copy]);
}
else if (range.location == ([self length] - 1)) else if (range.location == ([self length] - 1))
{ {
if (range.location == 0) if (range.location == 0)
substring = @""; {
substring = @"";
}
else else
substring = [[self substringToIndex: range.location] {
lastPathComponent]; substring = [[self substringToIndex: range.location]
lastPathComponent];
}
} }
else else
substring = [self substringFromIndex: range.location + 1]; {
substring = [self substringFromIndex: range.location + 1];
}
return substring; return substring;
} }
@ -2533,19 +2541,28 @@ handle_printf_atsign (FILE *stream,
range = [self rangeOfString: @"." options: NSBackwardsSearch]; range = [self rangeOfString: @"." options: NSBackwardsSearch];
if (range.length == 0) if (range.length == 0)
substring = nil; {
substring = nil;
}
else else
{ {
NSRange range2 = [self rangeOfCharacterFromSet: pathSeps() NSRange range2 = [self rangeOfCharacterFromSet: pathSeps()
options: NSBackwardsSearch]; options: NSBackwardsSearch];
if (range2.length > 0 && range.location < range2.location) if (range2.length > 0 && range.location < range2.location)
substring = nil; {
substring = nil;
}
else else
substring = [self substringFromIndex: range.location + 1]; {
substring = [self substringFromIndex: range.location + 1];
}
} }
if (!substring) if (substring == nil)
substring = @""; {
substring = @"";
}
return substring; return substring;
} }
@ -2947,13 +2964,19 @@ handle_printf_atsign (FILE *stream,
r.location++; r.location++;
} }
if ((r.length = [s length]) > r.location) if ((r.length = [s length]) > r.location)
r.length -= r.location; {
r.length -= r.location;
}
else else
break; {
break;
}
} }
if ([s isAbsolutePath] == NO) if ([s isAbsolutePath] == NO)
return s; {
return s;
}
/* Remove `/private' */ /* Remove `/private' */
if ([s hasPrefix: @"/private"]) if ([s hasPrefix: @"/private"])
@ -2996,11 +3019,18 @@ handle_printf_atsign (FILE *stream,
[s deleteCharactersInRange: r]; [s deleteCharactersInRange: r];
} }
else else
r.location++; {
r.location++;
}
if ((r.length = [s length]) > r.location) if ((r.length = [s length]) > r.location)
r.length -= r.location; {
r.length -= r.location;
}
else else
break; {
break;
}
} }
return s; return s;
@ -3040,10 +3070,14 @@ handle_printf_atsign (FILE *stream,
c = [components count]; c = [components count];
if (c == 0) if (c == 0)
return @""; {
return @"";
}
s = [components objectAtIndex: 0]; s = [components objectAtIndex: 0];
if ([s length] == 0 || [s isEqualToString: pathSepString] == YES) if ([s length] == 0 || [s isEqualToString: pathSepString] == YES)
s = rootPath; {
s = rootPath;
}
for (i = 1; i < c; i++) for (i = 1; i < c; i++)
{ {
s = [s stringByAppendingPathComponent: [components objectAtIndex: i]]; s = [s stringByAppendingPathComponent: [components objectAtIndex: i]];
@ -3061,6 +3095,7 @@ handle_printf_atsign (FILE *stream,
if ([self indexOfString: @":"] == NSNotFound) if ([self indexOfString: @":"] == NSNotFound)
{ {
const char *cpath = [self fileSystemRepresentation]; const char *cpath = [self fileSystemRepresentation];
if (isalpha(cpath[0]) && cpath[1] == ':') if (isalpha(cpath[0]) && cpath[1] == ':')
{ {
return YES; return YES;