MacOS-X compatibility stuff.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7495 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2000-09-13 12:32:19 +00:00
parent eb642b39e2
commit 9f18a77807
5 changed files with 124 additions and 46 deletions

View file

@ -1,3 +1,12 @@
2000-09-12 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSCompatibility.m: new file for MacOSX compatibility flags
* Source/GNUmakefile: add GSCompatibility.m
* Source/NSGeometry.m: Use GSMacOSXCompatibleGeometry() function to
decide whether to produce MacOS-X format strings.
* Source/propList.h: Parse MacOS-X format property lists as well as
OpenStep format ones.
2000-09-12 Adam Fedor <fedor@gnu.org>
* configure.in: Check for symlin, readlink.

View file

@ -70,6 +70,7 @@ FILE_AUTHORS = \
GNU_MFILES = \
GetDefEncoding.m \
GSCompatibility.m \
Unicode.m \
behavior.m \
o_array.m \

108
Source/GSCompatibility.m Normal file
View file

@ -0,0 +1,108 @@
/* Runtime MacOSX compatibility functionality
Copyright (C) 2000 Free Software Foundation, Inc.
Written by: Richard frith-Macdonald <rfm@gnu.org>
Date: August 1994
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include <config.h>
#include <Foundation/Foundation.h>
/*
* Runtime MacOS-X compatibility flags.
*/
static BOOL setupDone = NO;
static BOOL MacOSXCompatible = NO;
static BOOL MacOSXCompatibleGeometry = NO;
static BOOL MacOSXCompatiblePropertyLists = NO;
/*
* A trivial class to monitor user defaults to see how we should be
* producing strings describing geometry structures.
*/
@interface GSBaseDefaultObserver : NSObject
+ (void) defaultsChanged: (NSNotification*)aNotification;
@end
@implementation GSBaseDefaultObserver
+ (void) defaultsChanged: (NSNotification*)aNotification
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
id def;
Class sClass = [NSString class];
MacOSXCompatible = [defaults boolForKey: @"GSMacOSXCompatible"];
def = [defaults objectForKey: @"GSMacOSXCompatibleGeometry"];
if (def != nil && [def isKindOfClass: sClass] == YES)
{
MacOSXCompatibleGeometry = [def boolValue];
}
else
{
MacOSXCompatibleGeometry = MacOSXCompatible;
}
def = [defaults objectForKey: @"GSMacOSXCompatiblePropertyLists"];
if (def != nil && [def isKindOfClass: sClass] == YES)
{
MacOSXCompatiblePropertyLists = [def boolValue];
}
else
{
MacOSXCompatiblePropertyLists = MacOSXCompatible;
}
}
@end
static void
compatibilitySetup()
{
if (setupDone == NO)
{
setupDone = YES;
[[NSNotificationCenter defaultCenter]
addObserver: [GSBaseDefaultObserver class]
selector: @selector(defaultsChanged:)
name: NSUserDefaultsDidChangeNotification
object: nil];
[[GSBaseDefaultObserver class] defaultsChanged: nil];
}
}
BOOL GSMacOSXCompatible()
{
if (setupDone == NO)
compatibilitySetup();
return MacOSXCompatible;
}
BOOL GSMacOSXCompatibleGeometry()
{
if (setupDone == NO)
compatibilitySetup();
return MacOSXCompatibleGeometry;
}
BOOL GSMacOSXCompatiblePropertyLists()
{
if (setupDone == NO)
compatibilitySetup();
return MacOSXCompatiblePropertyLists;
}

View file

@ -37,7 +37,8 @@
#include <Foundation/NSNotification.h>
#include <Foundation/NSUserDefaults.h>
static BOOL MacOSX = NO; // Compatibility mode
extern BOOL GSMacOSXCompatibleGeometry(); // Compatibility mode
static Class NSStringClass = 0;
static Class NSScannerClass = 0;
static SEL scanFloatSel = @selector(scanFloat:);
@ -47,36 +48,6 @@ static BOOL (*scanFloatImp)(NSScanner*, SEL, float*);
static BOOL (*scanStringImp)(NSScanner*, SEL, NSString*, NSString**);
static id (*scannerImp)(Class, SEL, NSString*);
/*
* A trivial class to monitor user defaults to see how we should be
* producing strings describing geometry structures.
*/
@interface GSGeometryDefaultObserver : NSObject
+ (void) defaultsChanged: (NSNotification*)aNotification;
@end
@implementation GSGeometryDefaultObserver
+ (void) defaultsChanged: (NSNotification*)aNotification
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
id def;
def = [defaults objectForKey: @"GSMacOSXCompatibleGeometry"];
if (def == nil)
{
def = [defaults objectForKey: @"GSMacOSXCompatible"];
}
if (def != nil && [def isKindOfClass: NSStringClass] == YES)
{
MacOSX = [def boolValue];
}
else
{
MacOSX = NO;
}
}
@end
static inline void
setupCache()
{
@ -90,13 +61,6 @@ setupCache()
[NSScannerClass instanceMethodForSelector: scanStringSel];
scannerImp = (id (*)(Class, SEL, NSString*))
[NSScannerClass methodForSelector: scannerSel];
[[NSNotificationCenter defaultCenter]
addObserver: [GSGeometryDefaultObserver class]
selector: @selector(defaultsChanged:)
name: NSUserDefaultsDidChangeNotification
object: nil];
[[GSGeometryDefaultObserver class] defaultsChanged: nil];
}
}
@ -238,7 +202,7 @@ NSString*
NSStringFromPoint(NSPoint aPoint)
{
setupCache();
if (MacOSX == YES)
if (GSMacOSXCompatibleGeometry() == YES)
return [NSStringClass stringWithFormat:
@"{%g, %g}", aPoint.x, aPoint.y];
else
@ -250,7 +214,7 @@ NSString*
NSStringFromRect(NSRect aRect)
{
setupCache();
if (MacOSX == YES)
if (GSMacOSXCompatibleGeometry() == YES)
return [NSStringClass stringWithFormat:
@"{{%g, %g}, {%g, %g}}",
aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height];
@ -264,7 +228,7 @@ NSString*
NSStringFromSize(NSSize aSize)
{
setupCache();
if (MacOSX == YES)
if (GSMacOSXCompatibleGeometry() == YES)
return [NSStringClass stringWithFormat:
@"{%g, %g}", aSize.width, aSize.height];
else

View file

@ -731,7 +731,6 @@ nodeToObject(GSXMLNode* node)
id val;
val = nodeToObject(children);
NSLog(@"Array item %@", [children name], val);
[container addObject: val];
children = elementNode([children next]);
}
@ -747,10 +746,8 @@ NSLog(@"Array item %@", [children name], val);
id val;
key = nodeToObject(children);
NSLog(@"Key name (%@) %@", [children name], key);
children = elementNode([children next]);
val = nodeToObject(children);
NSLog(@"Val name (%@) %@", [children name], val);
children = elementNode([children next]);
[container setObject: val forKey: key];
}
@ -783,7 +780,6 @@ static id parsePl(pldata* pld)
memcpy(buf, pld->ptr, pld->end);
buf[pld->end] = '\0';
data = [NSData dataWithBytesNoCopy: buf length: pld->end+1];
NSLog(@"Parsing '%s'", buf);
parser = [GSXMLParser parser: data];
if ([parser parse] == YES)
{
@ -793,7 +789,7 @@ static id parsePl(pldata* pld)
[[[parser doc] root] name]);
return nil;
}
return nodeToObject([[[parser doc] root] children]);
return RETAIN(nodeToObject([[[parser doc] root] children]));
}
else
{