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:
Richard Frith-Macdonald 2002-04-18 07:51:46 +00:00
parent df34be2951
commit 8b67cc4486
3 changed files with 85 additions and 29 deletions

View file

@ -1,6 +1,8 @@
2002-04-17 Richard Frith-Macdonald <rfm@gnu.org>
* 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>

View file

@ -1311,39 +1311,39 @@ static NSFileManager* defaultManager = nil;
{
#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
*/
NSString *newpath = path;
const char *c_path = [path cString];
int len = [path length];
int l = [path length];
if (c_path == 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 */
newpath = [NSString stringWithFormat: @"%c:%s", c_path[2],
&c_path[3]];
newpath = [newpath stringByReplacingString: @"/" withString: @"\\"];
}
else
{
/* Windows absolute UNC path "//name/" */
newpath = [newpath stringByReplacingString: @"/" withString: @"\\"];
newpath = path;
}
}
else if (isalpha(c_path[0]) && c_path[1] == ':')
{
/* Unix absolute path */
newpath = [newpath stringByReplacingString: @"/" withString: @"\\"];
/* Windows absolute path */
newpath = path;
}
else if (c_path[0] == '/')
{
#ifdef __CYGWIN__
NSDictionary *env;
NSString *cyghome;
@ -1354,10 +1354,29 @@ static NSFileManager* defaultManager = nil;
/* FIXME: Find cygwin drive? */
newpath = cyghome;
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];
#else
return [path cString];

View file

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