port method to windoze

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13552 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-04-28 15:33:30 +00:00
parent b4e2c1e961
commit 050fdde7c8
2 changed files with 93 additions and 12 deletions

View file

@ -1,3 +1,9 @@
2002-04-28 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSFileManager.m: Port
([-stringWithFileSystemRepresentation:length:]) to windoze...
Have it convert backslashes to slashes etc.
2002-04-25 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/AGSParser.m: Improve handling of identifier mapping so that

View file

@ -1344,20 +1344,28 @@ static NSFileManager* defaultManager = nil;
else if (c_path[0] == '/')
{
#ifdef __CYGWIN__
NSDictionary *env;
NSString *cyghome;
env = [[NSProcessInfo processInfo] environment];
cyghome = [env objectForKey: @"CYGWIN_HOME"];
if (cyghome != nil)
{
/* FIXME: Find cygwin drive? */
newpath = cyghome;
newpath = [newpath stringByAppendingPathComponent: path];
}
if (l > 11 && strncmp(c_path, "/cygdrive/", 10) == 0 && c_path[11] == '/')
{
newpath = [NSString stringWithFormat: @"%c:%s", c_path[10],
&c_path[11]];
}
else
{
newpath = path;
NSDictionary *env;
NSString *cyghome;
env = [[NSProcessInfo processInfo] environment];
cyghome = [env objectForKey: @"CYGWIN_HOME"];
if (cyghome != nil)
{
/* FIXME: Find cygwin drive? */
newpath = cyghome;
newpath = [newpath stringByAppendingPathComponent: path];
}
else
{
newpath = path;
}
}
#else
if (l >= 3 && c_path[0] == '/' && c_path[2] == '/' && isalpha(c_path[1]))
@ -1386,6 +1394,73 @@ static NSFileManager* defaultManager = nil;
- (NSString*) stringWithFileSystemRepresentation: (const char*)string
length: (unsigned int)len
{
#ifdef __MINGW__
char buf[len + 20];
unsigned i;
/*
* If path is in Windows format, transmogrify it so Unix functions
* can handle it
*/
if (len == 0)
{
return @"";
}
if (len >= 2 && string[1] == ':' && isalpha(string[0]))
{
/*
* Convert '<driveletter>:' to '/<driveletter>/' sequences on MSYS
* or '/cygdrive/<driveletter>/' on CYGWIN
*/
#ifdef __CYGWIN__
strcpy(buf, "/cygdrive/");
buf[10] = string[0];
buf[11] = '/';
string -= 9;
len += 9;
i = 11;
#else
buf[0] = '/';
buf[1] = string[0];
buf[2] = '/';
string--;
len++;
i = 3;
#endif
}
else
{
i = 0;
}
/*
* Convert backslashes to slashes.
*/
while (i < len)
{
if (string[i] == '\\')
{
buf[i] = '/';
}
else
{
buf[i] = string[i];
}
i++;
}
/*
* Coalesce multiple slashes into a single one.
*/
for (i = 1; i < len; i++)
{
if (buf[i] == '/' && buf[i - 1] == '/')
{
len--;
memmove(&buf[i], &buf[i+1], len - i);
i--;
}
}
return [NSString stringWithCString: buf length: len];
#endif
return [NSString stringWithCString: string length: len];
}