mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-20 20:26:42 +00:00
Minor fixes for cygwin
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3580 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d4f2f56b87
commit
205e47ed25
3 changed files with 81 additions and 91 deletions
|
@ -104,14 +104,10 @@ static BOOL debug = NO;
|
|||
|
||||
return interval;
|
||||
#else
|
||||
TIME_ZONE_INFORMATION sys_time_zone;
|
||||
SYSTEMTIME sys_time;
|
||||
NSCalendarDate *d;
|
||||
NSTimeInterval t;
|
||||
|
||||
// Get the time zone information
|
||||
GetTimeZoneInformation(&sys_time_zone);
|
||||
|
||||
// Get the system time
|
||||
GetLocalTime(&sys_time);
|
||||
|
||||
|
@ -123,10 +119,10 @@ static BOOL debug = NO;
|
|||
hour: sys_time.wHour
|
||||
minute: sys_time.wMinute
|
||||
second: sys_time.wSecond
|
||||
timeZone: [NSTimeZone defaultTimeZone]];
|
||||
timeZone: [NSTimeZone localTimeZone]];
|
||||
t = [d timeIntervalSinceReferenceDate];
|
||||
[d release];
|
||||
return t;
|
||||
return t + sys_time.wMilliseconds / 1000.0;
|
||||
#endif /* __WIN32__ */
|
||||
}
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@ static NSFileManager* defaultManager = nil;
|
|||
attributes:(NSDictionary*)attributes
|
||||
{
|
||||
#if defined(__WIN32__) || defined(_WIN32)
|
||||
return CreateDirectory([path cString], NULL);
|
||||
return CreateDirectory([self fileSystemRepresentationWithPath: path], NULL);
|
||||
#else
|
||||
const char* cpath;
|
||||
char dirpath[PATH_MAX+1];
|
||||
|
@ -536,7 +536,7 @@ static NSFileManager* defaultManager = nil;
|
|||
- (BOOL)fileExistsAtPath:(NSString*)path isDirectory:(BOOL*)isDirectory
|
||||
{
|
||||
#if defined(__WIN32__) || defined(_WIN32)
|
||||
DWORD res = GetFileAttributes([path cString]);
|
||||
DWORD res = GetFileAttributes([self fileSystemRepresentationWithPath: path]);
|
||||
if (res == -1)
|
||||
return NO;
|
||||
|
||||
|
@ -941,7 +941,7 @@ static NSFileManager* defaultManager = nil;
|
|||
}
|
||||
return [[NSString stringWithCString: cpath] cString];
|
||||
#else
|
||||
return [[[path copy] autorelease] cString];
|
||||
return [[[path copy] autorelease] cString];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1091,14 +1091,15 @@ static NSFileManager* defaultManager = nil;
|
|||
|
||||
- (void)dealloc
|
||||
{
|
||||
while ([pathStack count])
|
||||
[self backtrack];
|
||||
while ([pathStack count])
|
||||
[self backtrack];
|
||||
|
||||
[pathStack release];
|
||||
[enumStack release];
|
||||
[currentFileName release];
|
||||
[currentFilePath release];
|
||||
[topPath release];
|
||||
[pathStack release];
|
||||
[enumStack release];
|
||||
[currentFileName release];
|
||||
[currentFilePath release];
|
||||
[topPath release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
// Getting attributes
|
||||
|
|
|
@ -99,20 +99,32 @@
|
|||
0
|
||||
};
|
||||
|
||||
static Class NSString_class; /* For speed */
|
||||
|
||||
static unichar pathSepChar = (unichar)'/';
|
||||
static NSString *pathSepString = @"/";
|
||||
|
||||
/*
|
||||
* We can't have a 'pathSeps' variable initialized in the +initialize
|
||||
* method 'cos that would cause recursion.
|
||||
*/
|
||||
static NSCharacterSet*
|
||||
pathSeps()
|
||||
{
|
||||
static NSCharacterSet *pathSeps = nil;
|
||||
|
||||
if (pathSeps == nil)
|
||||
{
|
||||
#if defined(__WIN32__) || defined(_WIN32)
|
||||
|
||||
#define PATH_COMPONENT @"\\"
|
||||
#define PATH_COMPONENT_LEN 1
|
||||
#define PATH_COMPONENT2 @"/"
|
||||
#define PATH_COMPONENT_LEN2 1
|
||||
|
||||
pathSeps = [NSCharacterSet characterSetWithCharactersInString: @"/\\"];
|
||||
#else
|
||||
pathSeps = [NSCharacterSet characterSetWithCharactersInString: @"/"];
|
||||
#endif
|
||||
[pathSeps retain];
|
||||
}
|
||||
return pathSeps;
|
||||
}
|
||||
|
||||
#define PATH_COMPONENT @"/"
|
||||
#define PATH_COMPONENT_LEN 1
|
||||
|
||||
#endif /* Path components */
|
||||
|
||||
@implementation NSString
|
||||
|
||||
|
@ -231,6 +243,7 @@ handle_printf_atsign (FILE *stream,
|
|||
if (self == [NSString class])
|
||||
{
|
||||
_DefaultStringEncoding = GetDefEncoding();
|
||||
NSString_class = self;
|
||||
NSString_concrete_class = [NSGString class];
|
||||
NSString_c_concrete_class = [NSGCString class];
|
||||
NSMutableString_concrete_class = [NSGMutableString class];
|
||||
|
@ -1456,7 +1469,7 @@ else
|
|||
Class c = fastClassOfInstance(anObject);
|
||||
|
||||
if (c != nil) {
|
||||
if (fastClassIsKindOfClass(c, _fastCls._NSString)) {
|
||||
if (fastClassIsKindOfClass(c, NSString_class)) {
|
||||
return [self isEqualToString: anObject];
|
||||
}
|
||||
}
|
||||
|
@ -2246,10 +2259,10 @@ else
|
|||
NSRange range;
|
||||
NSString *substring = nil;
|
||||
|
||||
range = [self rangeOfString: PATH_COMPONENT options:NSBackwardsSearch];
|
||||
range = [self rangeOfCharacterFromSet: pathSeps() options: NSBackwardsSearch];
|
||||
if (range.length == 0)
|
||||
substring = [[self copy] autorelease];
|
||||
else if (range.location == ([self length] - PATH_COMPONENT_LEN))
|
||||
else if (range.location == ([self length] - 1))
|
||||
{
|
||||
if (range.location == 0)
|
||||
substring = [[NSString new] autorelease];
|
||||
|
@ -2258,28 +2271,7 @@ else
|
|||
lastPathComponent];
|
||||
}
|
||||
else
|
||||
substring = [self substringFromIndex:range.location + PATH_COMPONENT_LEN];
|
||||
|
||||
#ifdef PATH_COMPONENT2
|
||||
if (substring == self)
|
||||
{
|
||||
NSRange range2 = [self rangeOfString: PATH_COMPONENT2
|
||||
options:NSBackwardsSearch];
|
||||
if (range2.length == 0)
|
||||
substring = [[self copy] autorelease];
|
||||
else if (range2.location == ([self length] - PATH_COMPONENT_LEN2))
|
||||
{
|
||||
if (range2.location == 0)
|
||||
substring = [[NSString new] autorelease];
|
||||
else
|
||||
substring = [[self substringToIndex:range2.location]
|
||||
lastPathComponent];
|
||||
}
|
||||
else
|
||||
substring = [self substringFromIndex:
|
||||
range2.location + PATH_COMPONENT_LEN2];
|
||||
}
|
||||
#endif /* PATH_COMPONENT2 */
|
||||
substring = [self substringFromIndex:range.location + 1];
|
||||
|
||||
return substring;
|
||||
}
|
||||
|
@ -2295,24 +2287,11 @@ else
|
|||
|
||||
range = [self rangeOfString:@"." options:NSBackwardsSearch];
|
||||
if (range.length == 0
|
||||
|| range.location < ([self rangeOfString: PATH_COMPONENT
|
||||
options:NSBackwardsSearch]).location)
|
||||
|| range.location < ([self rangeOfCharacterFromSet: pathSeps()
|
||||
options: NSBackwardsSearch]).location)
|
||||
substring = nil;
|
||||
else
|
||||
substring = [self substringFromIndex:range.location + PATH_COMPONENT_LEN];
|
||||
|
||||
#ifdef PATH_COMPONENT2
|
||||
if (!substring)
|
||||
{
|
||||
if (range.length == 0
|
||||
|| range.location < ([self rangeOfString: PATH_COMPONENT2
|
||||
options:NSBackwardsSearch]).location)
|
||||
substring = nil;
|
||||
else
|
||||
substring = [self substringFromIndex:
|
||||
range.location + PATH_COMPONENT_LEN2];
|
||||
}
|
||||
#endif
|
||||
substring = [self substringFromIndex:range.location + 1];
|
||||
|
||||
if (!substring)
|
||||
substring = [[NSString new] autorelease];
|
||||
|
@ -2331,19 +2310,19 @@ else
|
|||
if ([aString length] == 0)
|
||||
return [[self copy] autorelease];
|
||||
|
||||
range = [aString rangeOfString:@"/"];
|
||||
range = [aString rangeOfCharacterFromSet: pathSeps()];
|
||||
if (range.length != 0 && range.location == 0)
|
||||
[NSException raise: NSGenericException
|
||||
format: @"attempt to append illegal path component"];
|
||||
|
||||
range = [self rangeOfString:@"/" options:NSBackwardsSearch];
|
||||
range = [self rangeOfCharacterFromSet: pathSeps() options: NSBackwardsSearch];
|
||||
if ((range.length == 0 || range.location != [self length] - 1) && [self length] > 0)
|
||||
|
||||
newstring = [self stringByAppendingString:@"/"];
|
||||
newstring = [self stringByAppendingString: pathSepString];
|
||||
else
|
||||
newstring = self;
|
||||
|
||||
return [newstring stringByAppendingString:aString];
|
||||
return [newstring stringByAppendingString: aString];
|
||||
}
|
||||
|
||||
/* Returns a new string with the path extension given in aString
|
||||
|
@ -2379,17 +2358,17 @@ else
|
|||
NSRange range;
|
||||
NSString *substring;
|
||||
|
||||
range = [self rangeOfString:[self lastPathComponent]
|
||||
options:NSBackwardsSearch];
|
||||
range = [self rangeOfString: [self lastPathComponent]
|
||||
options: NSBackwardsSearch];
|
||||
|
||||
if (range.length == 0)
|
||||
substring = [[self copy] autorelease];
|
||||
else if (range.location == 0)
|
||||
substring = [[NSString new] autorelease];
|
||||
else if (range.location > 1)
|
||||
substring = [self substringToIndex:range.location-1];
|
||||
substring = [self substringToIndex:range.location-1];
|
||||
else
|
||||
substring = PATH_COMPONENT;
|
||||
substring = pathSepString;
|
||||
return substring;
|
||||
}
|
||||
|
||||
|
@ -2402,9 +2381,9 @@ else
|
|||
|
||||
range = [self rangeOfString:[self pathExtension] options:NSBackwardsSearch];
|
||||
if (range.length != 0)
|
||||
substring = [self substringToIndex:range.location-1];
|
||||
substring = [self substringToIndex:range.location-1];
|
||||
else
|
||||
substring = [[self copy] autorelease];
|
||||
substring = [[self copy] autorelease];
|
||||
return substring;
|
||||
}
|
||||
|
||||
|
@ -2419,7 +2398,7 @@ else
|
|||
if ([self characterAtIndex: 0] != 0x007E)
|
||||
return [[self copy] autorelease];
|
||||
|
||||
first_slash_range = [self rangeOfString: @"/"];
|
||||
first_slash_range = [self rangeOfString: pathSepString];
|
||||
|
||||
if (first_slash_range.location != 1)
|
||||
{
|
||||
|
@ -2453,7 +2432,7 @@ else
|
|||
if (![self hasPrefix: homedir])
|
||||
return [[self copy] autorelease];
|
||||
|
||||
return [NSString stringWithFormat: @"~/%@",
|
||||
return [NSString stringWithFormat: @"~%c%@", (char)pathSepChar,
|
||||
[self substringFromIndex: [homedir length] + 1]];
|
||||
}
|
||||
|
||||
|
@ -2507,9 +2486,10 @@ else
|
|||
|
||||
/* BREAK CONDITION */
|
||||
if ([first_half length] == 0) break;
|
||||
else if ([first_half isEqual: @"/"])
|
||||
else if ([first_half length] == 1
|
||||
&& [pathSeps() characterIsMember: [first_half characterAtIndex: 0]])
|
||||
{
|
||||
second_half = [@"/" stringByAppendingPathComponent: second_half];
|
||||
second_half = [pathSepString stringByAppendingPathComponent: second_half];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2530,28 +2510,41 @@ else
|
|||
[s deleteCharactersInRange: ((NSRange){0,7})];
|
||||
|
||||
/* Condense `//' */
|
||||
while ((r = [s rangeOfString: @"//"]).length)
|
||||
while ((r = [s rangeOfCharacterFromSet: pathSeps()]).length
|
||||
&& r.location + r.length < [s length]
|
||||
&& [pathSeps() characterIsMember: [s characterAtIndex: r.location + 1]])
|
||||
[s deleteCharactersInRange: r];
|
||||
|
||||
/* Condense `/./' */
|
||||
while ((r = [s rangeOfString: @"/./"]).length)
|
||||
while ((r = [s rangeOfCharacterFromSet: pathSeps()]).length
|
||||
&& r.location + r.length < [s length] + 1
|
||||
&& [s characterAtIndex: r.location + 1] == (unichar)'.'
|
||||
&& [pathSeps() characterIsMember: [s characterAtIndex: r.location + 2]])
|
||||
{
|
||||
r.length--;
|
||||
r.length++;
|
||||
[s deleteCharactersInRange: r];
|
||||
}
|
||||
|
||||
/* Condense `/../' */
|
||||
while ((r = [s rangeOfString: @"/../"]).length)
|
||||
while ((r = [s rangeOfCharacterFromSet: pathSeps()]).length
|
||||
&& r.location + r.length < [s length] + 2
|
||||
&& [s characterAtIndex: r.location + 1] == (unichar)'.'
|
||||
&& [s characterAtIndex: r.location + 2] == (unichar)'.'
|
||||
&& [pathSeps() characterIsMember: [s characterAtIndex: r.location + 3]])
|
||||
{
|
||||
NSRange r2 = {0, r.length-1};
|
||||
r = [s rangeOfString: @"/"
|
||||
options: NSBackwardsSearch
|
||||
range: r2];
|
||||
r.length += 4; /* Add the `/../' */
|
||||
if (r.location > 0)
|
||||
{
|
||||
NSRange r2 = {0, r.location};
|
||||
r = [s rangeOfCharacterFromSet: pathSeps()
|
||||
options: NSBackwardsSearch
|
||||
range: r2];
|
||||
if (r.length == 0)
|
||||
r = r2;
|
||||
r.length += 4; /* Add the `/../' */
|
||||
}
|
||||
[s deleteCharactersInRange: r];
|
||||
}
|
||||
|
||||
/* xxx Should we not return a mutable string? */
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue