mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Fosdem updates.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@20805 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
2e9ff3b23b
commit
8c80371455
8 changed files with 200 additions and 98 deletions
21
ChangeLog
21
ChangeLog
|
@ -1,3 +1,24 @@
|
|||
2005-02-27 08:45 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* NSCharacterSets/dataToheader.c: new file to convert data files to
|
||||
constant values in a new header (NSCharacterSetData.h).
|
||||
* NSCharacterSets/GNUmakefile: build header from data files, and
|
||||
don't create resource set, since we no longer use the files at runtime.
|
||||
* Source/NSCharacterSet.m: include NSCharacterSetData.h and use it to
|
||||
create the standard charactersets rather than reading from data files.
|
||||
This has two advantages - It avoids the need to install characterset
|
||||
data files with the library, and it means that we have characterset
|
||||
data available immediately (before we need to access the filesystem)
|
||||
so we can use charactersets and NSString methods which depend upon them
|
||||
earlier on in the system initialisation.
|
||||
|
||||
2005-02-27 00:50 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSAutoreleasePool.m: ([-dealloc]) cache method implementations
|
||||
for release calls on the assumption that many of the objects in the
|
||||
pool will be of the same class.
|
||||
Optimisation suggested by Georg Wallmann
|
||||
|
||||
2005-02-23 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* configure.ac: Add test to check for poll emulation
|
||||
|
|
|
@ -50,7 +50,7 @@ PACKAGE_NAME = gnustep-base
|
|||
#
|
||||
# The list of subproject directories
|
||||
#
|
||||
SUBPROJECTS = Source SSL Tools NSCharacterSets NSTimeZones Resources
|
||||
SUBPROJECTS = NSCharacterSets Source SSL Tools NSTimeZones Resources
|
||||
|
||||
-include Makefile.preamble
|
||||
|
||||
|
|
|
@ -26,13 +26,6 @@ GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT)
|
|||
GNUSTEP_LOCAL_ADDITIONAL_MAKEFILES=../base.make
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
RESOURCE_SET_NAME = base-resources
|
||||
base-resources_RESOURCE_FILES_INSTALL_DIR = Library/Libraries/Resources/gnustep-base/NSCharacterSets
|
||||
base-resources_LANGUAGES =
|
||||
base-resources_LOCALIZED_RESOURCE_FILES =
|
||||
base-resources_RESOURCE_DIRS =
|
||||
base-resources_RESOURCE_FILES = $(CHARSET_FILES)
|
||||
|
||||
CHARSET_FILES = \
|
||||
alphanumericCharSet.dat \
|
||||
controlCharSet.dat \
|
||||
|
@ -48,8 +41,13 @@ uppercaseLetterCharSet.dat \
|
|||
whitespaceAndNlCharSet.dat \
|
||||
whitespaceCharSet.dat
|
||||
|
||||
-include Makefile.preamble
|
||||
CTOOL_NAME = dataToHeader
|
||||
dataToHeader_C_FILES = dataToHeader.c
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/resource-set.make
|
||||
include $(GNUSTEP_MAKEFILES)/ctool.make
|
||||
|
||||
after-all:: NSCharacterSetData.h
|
||||
|
||||
NSCharacterSetData.h: $(CHARSET_FILES)
|
||||
obj/dataToHeader $(CHARSET_FILES)
|
||||
|
||||
-include Makefile.postamble
|
||||
|
|
|
@ -7,6 +7,12 @@
|
|||
of the Unicode character set as of Feb. 27, 2001. The Unicode character
|
||||
set can be obtained from http://www.unicode.org
|
||||
|
||||
The NSCharacterSetData.h file is generated from the binary bitmap
|
||||
data in the individual .dat files, and is compiled in to the
|
||||
NSCharacterSet class.
|
||||
|
||||
The binary data files are no longer used at runtime.
|
||||
|
||||
The current character sets are based on UnicodeData.txt version 3.0.1.
|
||||
|
||||
NOTE: There are a number of differences between these sets and the
|
||||
|
|
55
NSCharacterSets/dataToHeader.c
Normal file
55
NSCharacterSets/dataToHeader.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* A trivial C program to read characterset data files and produce a C
|
||||
* header file to be included into NSCharacterSet.m
|
||||
* Pass it the names of the data files as arguments.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int c;
|
||||
FILE *o;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
fprintf(stderr, "Expecting names of data files to convert\n");
|
||||
return 1;
|
||||
}
|
||||
o = fopen("NSCharacterSetData.h", "w");
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
FILE *f;
|
||||
char name[BUFSIZ];
|
||||
int j;
|
||||
int sep = '{';
|
||||
|
||||
strcpy(name, argv[i]);
|
||||
j = strlen(name) - 4;
|
||||
if (j < 0 || strcmp(&name[j], ".dat") != 0)
|
||||
{
|
||||
fprintf(stderr, "Bad file name '%s'\n", name);
|
||||
return 1;
|
||||
}
|
||||
f = fopen(name, "r");
|
||||
if (f == NULL)
|
||||
{
|
||||
fprintf(stderr, "Unable to read '%s'\n", name);
|
||||
return 1;
|
||||
}
|
||||
name[j] = '\0';
|
||||
fprintf(o, "static unsigned char %s[8192] = ", name);
|
||||
while ((c = fgetc(f)) != EOF)
|
||||
{
|
||||
fprintf(o, "%c\n'\\x%02x'", sep, c);
|
||||
sep = ',';
|
||||
}
|
||||
fprintf(o,"};\n");
|
||||
fclose(f);
|
||||
}
|
||||
fclose(o);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -112,6 +112,8 @@ pop_pool_from_cache (struct autorelease_thread_vars *tv)
|
|||
return tv->pool_cache[--(tv->pool_cache_count)];
|
||||
}
|
||||
|
||||
static SEL releaseSel = 0;
|
||||
|
||||
|
||||
@implementation NSAutoreleasePool
|
||||
|
||||
|
@ -122,6 +124,7 @@ static IMP initImp;
|
|||
{
|
||||
if (self == [NSAutoreleasePool class])
|
||||
{
|
||||
releaseSel = @selector(release);
|
||||
allocImp = [self methodForSelector: @selector(allocWithZone:)];
|
||||
initImp = [self instanceMethodForSelector: @selector(init)];
|
||||
}
|
||||
|
@ -341,15 +344,31 @@ static IMP initImp;
|
|||
releasing. */
|
||||
{
|
||||
struct autorelease_array_list *released = _released_head;
|
||||
unsigned int i;
|
||||
unsigned i;
|
||||
Class classes[16];
|
||||
IMP imps[16];
|
||||
|
||||
while (released)
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
classes[i] = 0;
|
||||
imps[i] = 0;
|
||||
}
|
||||
|
||||
while (released != 0)
|
||||
{
|
||||
for (i = 0; i < released->count; i++)
|
||||
{
|
||||
id anObject = released->objects[i];
|
||||
id anObject = released->objects[i];
|
||||
Class c = GSObjCClass(anObject);
|
||||
unsigned hash = (((unsigned)c) >> 3) & 0x0f;
|
||||
|
||||
released->objects[i] = nil;
|
||||
[anObject release];
|
||||
if (classes[hash] != c)
|
||||
{
|
||||
classes[hash] = c;
|
||||
imps[hash] = [c methodForSelector: releaseSel];
|
||||
}
|
||||
(imps[hash])(anObject, releaseSel);
|
||||
}
|
||||
released->count = 0;
|
||||
released = released->next;
|
||||
|
|
|
@ -63,6 +63,11 @@
|
|||
return ISSET(_data[aCharacter/8], aCharacter % 8);
|
||||
}
|
||||
|
||||
- (Class) classForCoder
|
||||
{
|
||||
return [self class];
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[aCoder encodeObject: [self bitmapRepresentation]];
|
||||
|
|
|
@ -28,16 +28,15 @@
|
|||
#include "GNUstepBase/GSLock.h"
|
||||
#include "Foundation/NSArray.h"
|
||||
#include "Foundation/NSBitmapCharSet.h"
|
||||
#include "Foundation/NSCoder.h"
|
||||
#include "Foundation/NSException.h"
|
||||
#include "Foundation/NSBundle.h"
|
||||
#include "Foundation/NSData.h"
|
||||
#include "Foundation/NSLock.h"
|
||||
#include "Foundation/NSPathUtilities.h"
|
||||
#include "Foundation/NSDictionary.h"
|
||||
#include "Foundation/NSThread.h"
|
||||
#include "Foundation/NSNotification.h"
|
||||
|
||||
static NSString *NSCharacterSet_PATH = @"NSCharacterSets";
|
||||
#include "../NSCharacterSets/NSCharacterSetData.h"
|
||||
|
||||
/* A simple array for caching standard bitmap sets */
|
||||
#define MAX_STANDARD_SETS 15
|
||||
|
@ -45,6 +44,50 @@ static NSCharacterSet *cache_set[MAX_STANDARD_SETS];
|
|||
static NSLock *cache_lock = nil;
|
||||
static Class abstractClass = nil;
|
||||
|
||||
@interface GSStaticCharSet : NSCharacterSet
|
||||
{
|
||||
const unsigned char *_data;
|
||||
int _index;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation GSStaticCharSet
|
||||
|
||||
- (id) init
|
||||
{
|
||||
DESTROY(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id) initWithIndex: (int)index bytes: (const unsigned char*)bitmap
|
||||
{
|
||||
_index = index;
|
||||
_data = bitmap;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSData*) bitmapRepresentation
|
||||
{
|
||||
return [NSData dataWithBytes: _data length: BITMAP_SIZE];
|
||||
}
|
||||
|
||||
- (BOOL) characterIsMember: (unichar)aCharacter
|
||||
{
|
||||
return ISSET(_data[aCharacter/8], aCharacter % 8);
|
||||
}
|
||||
|
||||
- (Class) classForCoder
|
||||
{
|
||||
return [NSCharacterSet class];
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[aCoder encodeValueOfObjCType: @encode(int) at: &_index];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* Represents a set of unicode characters. Used by [NSScanner] and [NSString]
|
||||
* for parsing-related methods.
|
||||
|
@ -72,77 +115,23 @@ static Class abstractClass = nil;
|
|||
return NSAllocateObject(self, 0, zone);
|
||||
}
|
||||
|
||||
// Creating standard character sets
|
||||
|
||||
+ (NSCharacterSet*) _bitmapForSet: (NSString*)setname number: (int)number
|
||||
/**
|
||||
* Creat and cache (or retrieve from cache) a characterset
|
||||
* using static bitmap data.
|
||||
* Return nil if no data is supplied and the cache is empty.
|
||||
*/
|
||||
+ (NSCharacterSet*) _staticSet: (unsigned char*)bytes number: (int)number
|
||||
{
|
||||
NSCharacterSet *set;
|
||||
NSString *set_path;
|
||||
NSBundle *bundle;
|
||||
|
||||
[cache_lock lock];
|
||||
|
||||
set = nil; /* Quiet warnings */
|
||||
if (cache_set[number] == nil)
|
||||
if (cache_set[number] == nil && bytes != 0)
|
||||
{
|
||||
NS_DURING
|
||||
|
||||
bundle = [NSBundle bundleForLibrary: @"gnustep-base"];
|
||||
set_path = [bundle pathForResource: setname
|
||||
ofType: @"dat"
|
||||
inDirectory: NSCharacterSet_PATH];
|
||||
if (set_path != nil)
|
||||
{
|
||||
NS_DURING
|
||||
{
|
||||
NSData *data;
|
||||
|
||||
/* Load the character set file */
|
||||
data = [NSData dataWithContentsOfFile: set_path];
|
||||
set = [NSCharacterSet characterSetWithBitmapRepresentation:
|
||||
data];
|
||||
}
|
||||
NS_HANDLER
|
||||
NSLog(@"Unable to read NSCharacterSet file %@", set_path);
|
||||
set = nil;
|
||||
NS_ENDHANDLER
|
||||
}
|
||||
|
||||
/* If we didn't load a set then raise an exception */
|
||||
if (!set)
|
||||
{
|
||||
[NSException raise: NSGenericException
|
||||
format: @"Could not find bitmap file %@", setname];
|
||||
/* NOT REACHED */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Else cache the set */
|
||||
cache_set[number] = RETAIN(set);
|
||||
}
|
||||
NS_HANDLER
|
||||
[cache_lock unlock];
|
||||
[localException raise];
|
||||
abort (); /* quiet warnings about `set' clobbered by longjmp. */
|
||||
NS_ENDHANDLER
|
||||
cache_set[number]
|
||||
= [[GSStaticCharSet alloc] initWithIndex: number bytes: bytes];
|
||||
}
|
||||
else
|
||||
set = cache_set[number];
|
||||
|
||||
[cache_lock unlock];
|
||||
|
||||
if (self != abstractClass && self != [set class])
|
||||
{
|
||||
NSData *data;
|
||||
|
||||
data = [set bitmapRepresentation];
|
||||
set = [self characterSetWithBitmapRepresentation: data];
|
||||
}
|
||||
|
||||
return set;
|
||||
return cache_set[number];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a character set containing letters, numbers, and diacritical
|
||||
* marks. Note that "letters" includes all alphabetic as well as Chinese
|
||||
|
@ -150,7 +139,7 @@ static Class abstractClass = nil;
|
|||
*/
|
||||
+ (NSCharacterSet*) alphanumericCharacterSet
|
||||
{
|
||||
return [self _bitmapForSet: @"alphanumericCharSet" number: 0];
|
||||
return [self _staticSet: alphanumericCharSet number: 0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -158,7 +147,7 @@ static Class abstractClass = nil;
|
|||
*/
|
||||
+ (NSCharacterSet*) controlCharacterSet
|
||||
{
|
||||
return [self _bitmapForSet: @"controlCharSet" number: 1];
|
||||
return [self _staticSet: controlCharSet number: 1];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,7 +156,7 @@ static Class abstractClass = nil;
|
|||
*/
|
||||
+ (NSCharacterSet*) decimalDigitCharacterSet
|
||||
{
|
||||
return [self _bitmapForSet: @"decimalDigitCharSet" number: 2];
|
||||
return [self _staticSet: decimalDigitCharSet number: 2];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,7 +165,7 @@ static Class abstractClass = nil;
|
|||
*/
|
||||
+ (NSCharacterSet*) decomposableCharacterSet
|
||||
{
|
||||
return [self _bitmapForSet: @"decomposableCharSet" number: 3];
|
||||
return [self _staticSet: decomposableCharSet number: 3];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -185,7 +174,7 @@ static Class abstractClass = nil;
|
|||
*/
|
||||
+ (NSCharacterSet*) illegalCharacterSet
|
||||
{
|
||||
return [self _bitmapForSet: @"illegalCharSet" number: 4];
|
||||
return [self _staticSet: illegalCharSet number: 4];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -194,7 +183,7 @@ static Class abstractClass = nil;
|
|||
*/
|
||||
+ (NSCharacterSet*) letterCharacterSet
|
||||
{
|
||||
return [self _bitmapForSet: @"letterCharSet" number: 5];
|
||||
return [self _staticSet: letterCharSet number: 5];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -204,7 +193,7 @@ static Class abstractClass = nil;
|
|||
*/
|
||||
+ (NSCharacterSet*) lowercaseLetterCharacterSet
|
||||
{
|
||||
return [self _bitmapForSet: @"lowercaseLetterCharSet" number: 6];
|
||||
return [self _staticSet: lowercaseLetterCharSet number: 6];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -213,7 +202,7 @@ static Class abstractClass = nil;
|
|||
*/
|
||||
+ (NSCharacterSet*) nonBaseCharacterSet
|
||||
{
|
||||
return [self _bitmapForSet: @"nonBaseCharSet" number: 7];
|
||||
return [self _staticSet: nonBaseCharSet number: 7];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -221,7 +210,7 @@ static Class abstractClass = nil;
|
|||
*/
|
||||
+ (NSCharacterSet*) punctuationCharacterSet
|
||||
{
|
||||
return [self _bitmapForSet: @"punctuationCharSet" number: 8];
|
||||
return [self _staticSet: punctuationCharSet number: 8];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -229,7 +218,7 @@ static Class abstractClass = nil;
|
|||
*/
|
||||
+ (NSCharacterSet*) symbolAndOperatorCharacterSet
|
||||
{
|
||||
return [self _bitmapForSet: @"symbolAndOperatorCharSet" number: 9];
|
||||
return [self _staticSet: symbolAndOperatorCharSet number: 9];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -239,7 +228,7 @@ static Class abstractClass = nil;
|
|||
*/
|
||||
+ (NSCharacterSet*) uppercaseLetterCharacterSet
|
||||
{
|
||||
return [self _bitmapForSet: @"uppercaseLetterCharSet" number: 10];
|
||||
return [self _staticSet: uppercaseLetterCharSet number: 10];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -248,7 +237,7 @@ static Class abstractClass = nil;
|
|||
*/
|
||||
+ (NSCharacterSet*) whitespaceAndNewlineCharacterSet
|
||||
{
|
||||
return [self _bitmapForSet: @"whitespaceAndNlCharSet" number: 11];
|
||||
return [self _staticSet: whitespaceAndNlCharSet number: 11];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -256,7 +245,7 @@ static Class abstractClass = nil;
|
|||
*/
|
||||
+ (NSCharacterSet*) whitespaceCharacterSet
|
||||
{
|
||||
return [self _bitmapForSet: @"whitespaceCharSet" number: 12];
|
||||
return [self _staticSet: whitespaceCharSet number: 12];
|
||||
}
|
||||
|
||||
// Creating custom character sets
|
||||
|
@ -363,13 +352,22 @@ static Class abstractClass = nil;
|
|||
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return nil;
|
||||
if ([self class] == [NSCharacterSet class])
|
||||
{
|
||||
int index;
|
||||
|
||||
/*
|
||||
* Abstract class returns characterset from cache.
|
||||
*/
|
||||
DESTROY(self);
|
||||
[aCoder decodeValueOfObjCType: @encode(int) at: &index];
|
||||
self = RETAIN([NSCharacterSet _staticSet: 0 number: index]);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (id)anObject
|
||||
|
|
Loading…
Reference in a new issue