mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-20 20:26:42 +00:00
New string functions, patches from Richard and Wacko.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2676 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
5bbd6ca292
commit
cc39cb890a
10 changed files with 168 additions and 36 deletions
32
ChangeLog
32
ChangeLog
|
@ -1,3 +1,35 @@
|
|||
Fri Dec 19 13:09:28 1997 Adam Fedor <fedor@doc.com>
|
||||
|
||||
* src/NSGeometry.m (NSPointFromString, NSSizeFromString,
|
||||
NSRectFromString): New functions.
|
||||
* src/include/NSGeometry.h: New function defs.
|
||||
* NSCTemplateValue.m (-description): Use them.
|
||||
|
||||
Tue Dec 16 22:35:00 1997 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* src/Decoder.m: Modified to use a single, class-wide dummy object
|
||||
as a placeholder in cross-reference tables. This gives a slight
|
||||
speed and memory usage improvement.
|
||||
|
||||
* src/MemoryStream.m: Avoid using autorelease where possible in order
|
||||
to improve efficiency.
|
||||
|
||||
* src/NSConnection.m: ([+rootProxyAtPort:]) modified to refrain from
|
||||
creating a new connection when we already have one for the given
|
||||
output port.
|
||||
|
||||
* src/Random.m: ([-randomDie:]) Fixed to confirm to description in
|
||||
comments.
|
||||
|
||||
* src/TcpPort.m: Changed size field in packets to be 4 bytes long
|
||||
rather than 2. This allows messages to be more than 64K bytes long
|
||||
and is essential for things like pasteboard operations.
|
||||
|
||||
Thu Dec 18 16:17:22 1997 Yoo C. Chung <wacko@laplace.snu.ac.kr>
|
||||
|
||||
* src/NSProcessInfo.m (_gnu_process_noobjc_args): Use malloc().
|
||||
(_gnu_noobjc_free_vars): Use free().
|
||||
|
||||
Thu Dec 11 13:58:39 1997 Adam Fedor <fedor@doc.com>
|
||||
|
||||
* configure.in: Remove unneeded tests.
|
||||
|
|
|
@ -135,7 +135,7 @@ NSOffsetRect(NSRect aRect, float dx, float dy);
|
|||
|
||||
/* Divides ARECT into two rectangles (namely SLICE and REMAINDER) by
|
||||
* "cutting" ARECT---parallel to, and a distance AMOUNT from the edge
|
||||
* of ARECT determined by EDGE. You may pass 0 in as either of SLICE or
|
||||
v * of ARECT determined by EDGE. You may pass 0 in as either of SLICE or
|
||||
* REMAINDER to avoid obtaining either of the created rectangles. */
|
||||
extern void
|
||||
NSDivideRect(NSRect aRect,
|
||||
|
@ -222,6 +222,11 @@ NSStringFromRect(NSRect aRect);
|
|||
* W and H are the width and height of ASIZE, respectively. */
|
||||
extern NSString *
|
||||
NSStringFromSize(NSSize aSize);
|
||||
|
||||
extern NSPoint NSPointFromString(NSString* string);
|
||||
extern NSSize NSSizeFromString(NSString* string);
|
||||
extern NSRect NSRectFromString(NSString* string);
|
||||
|
||||
#endif /* __OBJC__ */
|
||||
|
||||
#endif /* __NSGeometry_h_GNUSTEP_BASE_INCLUDE */
|
||||
|
|
|
@ -35,6 +35,19 @@ static int debug_coder = 0;
|
|||
|
||||
@implementation Decoder
|
||||
|
||||
static id dummyObject;
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
BOOL beenHere = NO;
|
||||
|
||||
if (beenHere == NO)
|
||||
{
|
||||
beenHere = YES;
|
||||
dummyObject = [NSObject new];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Signature Handling. */
|
||||
|
||||
|
@ -123,8 +136,7 @@ static int debug_coder = 0;
|
|||
xref_2_object = [Array new];
|
||||
/* Append an object so our xref numbers are in sync with the
|
||||
Encoders, which start at 1. */
|
||||
/* xxx Change this to make it more efficient. */
|
||||
[xref_2_object appendObject: [[NSObject new] autorelease]];
|
||||
[xref_2_object appendObject: dummyObject];
|
||||
}
|
||||
if (debug_coder)
|
||||
fprintf (stderr, "Decoder registering object xref %u\n",
|
||||
|
@ -175,7 +187,7 @@ static int debug_coder = 0;
|
|||
xref_2_object_root = [Array new];
|
||||
/* Append an object so our xref numbers are in sync with the
|
||||
Encoders, which start at 1. */
|
||||
[xref_2_object_root appendObject: [[NSObject new] autorelease]];
|
||||
[xref_2_object_root appendObject: dummyObject];
|
||||
}
|
||||
[xref_2_object_root appendObject: anObj];
|
||||
/* This return value should be the same as the index of anObj
|
||||
|
|
|
@ -83,19 +83,18 @@ static BOOL debug_memory_stream = NO;
|
|||
{
|
||||
if (b)
|
||||
if (f)
|
||||
data = [NSMutableData dataWithBytesNoCopy: b length: s];
|
||||
data = [[NSMutableData alloc] initWithBytesNoCopy: b length: s];
|
||||
else
|
||||
data = [NSMutableData dataWithBytes: b length: s];
|
||||
data = [[NSMutableData alloc] initWithBytes: b length: s];
|
||||
else
|
||||
{
|
||||
data = [NSMutableData dataWithCapacity: s];
|
||||
data = [[NSMutableData alloc] initWithCapacity: s];
|
||||
if (data)
|
||||
[data setLength: s];
|
||||
}
|
||||
|
||||
if (data)
|
||||
{
|
||||
[data retain];
|
||||
prefix = p;
|
||||
position = i;
|
||||
eof_position = l;
|
||||
|
|
|
@ -93,16 +93,13 @@
|
|||
#if TYPE_ORDER == 0
|
||||
return [NSString stringWithFormat: @"{object = %@;}", [data description]];
|
||||
#elif TYPE_ORDER == 1
|
||||
return [NSString stringWithFormat: @"{x = %g; y = %g;}", data.x, data.y];
|
||||
return NSStringFromPoint(data);
|
||||
#elif TYPE_ORDER == 2
|
||||
return [NSString stringWithFormat: @"{pointer = %p;}", data];
|
||||
#elif TYPE_ORDER == 3
|
||||
return [NSString stringWithFormat:
|
||||
@"{x = %g; y = %g; width = %g; height = %g;}", NSMinX(data), NSMinY(data),
|
||||
NSWidth(data), NSHeight(data)];
|
||||
return NSStringFromRect(data);
|
||||
#elif TYPE_ORDER == 4
|
||||
return [NSString stringWithFormat: @"{width = %g; height = %g;}",
|
||||
data.width, data.height];
|
||||
return NSStringFromSize(data);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -730,11 +730,18 @@ static int messages_received_count;
|
|||
}
|
||||
|
||||
+ (NSDistantObject*) rootProxyAtPort: (NSPort*)anOutPort
|
||||
{
|
||||
NSConnection *c = [self connectionByOutPort: anOutPort];
|
||||
|
||||
if (c)
|
||||
return [c rootProxy];
|
||||
else
|
||||
{
|
||||
id newInPort = [default_receive_port_class newForReceiving];
|
||||
return [self rootProxyAtPort: anOutPort
|
||||
withInPort: [newInPort autorelease]];
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSDistantObject*) rootProxyAtPort: (NSPort*)anOutPort
|
||||
withInPort: (NSPort *)anInPort
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <gnustep/base/preface.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSGeometry.h>
|
||||
#include <Foundation/NSScanner.h>
|
||||
|
||||
/**** Type, Constant, and Macro Definitions **********************************/
|
||||
|
||||
|
@ -425,3 +426,71 @@ NSStringFromSize(NSSize aSize)
|
|||
aSize.width, aSize.height];
|
||||
}
|
||||
|
||||
NSPoint NSPointFromString(NSString* string)
|
||||
{
|
||||
NSScanner* scanner = [NSScanner scannerWithString:string];
|
||||
NSPoint point;
|
||||
|
||||
if ([scanner scanString:@"{" intoString:NULL]
|
||||
&& [scanner scanString:@"x" intoString:NULL]
|
||||
&& [scanner scanString:@"=" intoString:NULL]
|
||||
&& [scanner scanFloat:&point.x]
|
||||
&& [scanner scanString:@";" intoString:NULL]
|
||||
&& [scanner scanString:@"y" intoString:NULL]
|
||||
&& [scanner scanString:@"=" intoString:NULL]
|
||||
&& [scanner scanFloat:&point.y]
|
||||
&& [scanner scanString:@"}" intoString:NULL])
|
||||
return point;
|
||||
else
|
||||
return NSMakePoint(0, 0);
|
||||
}
|
||||
|
||||
NSSize NSSizeFromString(NSString* string)
|
||||
{
|
||||
NSScanner* scanner = [NSScanner scannerWithString:string];
|
||||
NSSize size;
|
||||
|
||||
if ([scanner scanString:@"{" intoString:NULL]
|
||||
&& [scanner scanString:@"width" intoString:NULL]
|
||||
&& [scanner scanString:@"=" intoString:NULL]
|
||||
&& [scanner scanFloat:&size.width]
|
||||
&& [scanner scanString:@";" intoString:NULL]
|
||||
&& [scanner scanString:@"height" intoString:NULL]
|
||||
&& [scanner scanString:@"=" intoString:NULL]
|
||||
&& [scanner scanFloat:&size.height]
|
||||
&& [scanner scanString:@"}" intoString:NULL])
|
||||
return size;
|
||||
else
|
||||
return NSMakeSize(0, 0);
|
||||
}
|
||||
|
||||
NSRect NSRectFromString(NSString* string)
|
||||
{
|
||||
NSScanner* scanner = [NSScanner scannerWithString:string];
|
||||
NSRect rect;
|
||||
|
||||
if ([scanner scanString:@"{" intoString:NULL]
|
||||
&& [scanner scanString:@"x" intoString:NULL]
|
||||
&& [scanner scanString:@"=" intoString:NULL]
|
||||
&& [scanner scanFloat:&rect.origin.x]
|
||||
&& [scanner scanString:@";" intoString:NULL]
|
||||
|
||||
&& [scanner scanString:@"y" intoString:NULL]
|
||||
&& [scanner scanString:@"=" intoString:NULL]
|
||||
&& [scanner scanFloat:&rect.origin.y]
|
||||
&& [scanner scanString:@";" intoString:NULL]
|
||||
|
||||
&& [scanner scanString:@"width" intoString:NULL]
|
||||
&& [scanner scanString:@"=" intoString:NULL]
|
||||
&& [scanner scanFloat:&rect.size.width]
|
||||
&& [scanner scanString:@";" intoString:NULL]
|
||||
|
||||
&& [scanner scanString:@"height" intoString:NULL]
|
||||
&& [scanner scanString:@"=" intoString:NULL]
|
||||
&& [scanner scanFloat:&rect.size.height]
|
||||
&& [scanner scanString:@"}" intoString:NULL])
|
||||
return rect;
|
||||
else
|
||||
return NSMakeRect(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,8 @@
|
|||
#include <netdb.h>
|
||||
#endif /* !__WIN32__ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
|
@ -191,7 +193,8 @@ static char **_gnu_noobjc_argv;
|
|||
static char **_gnu_noobjc_env;
|
||||
|
||||
static void
|
||||
_gnu_process_noobjc_args(int argc, char *argv[], char *env[]) {
|
||||
_gnu_process_noobjc_args(int argc, char *argv[], char *env[])
|
||||
{
|
||||
int i;
|
||||
|
||||
/* We have to copy these in case the main() modifies their values
|
||||
|
@ -202,12 +205,14 @@ _gnu_process_noobjc_args(int argc, char *argv[], char *env[]) {
|
|||
i=0;
|
||||
while(argv[i])
|
||||
i++;
|
||||
_gnu_noobjc_argv =
|
||||
NSZoneMalloc(NSDefaultMallocZone(),sizeof(char *)*(i+1));
|
||||
_gnu_noobjc_argv = malloc(sizeof(char *)*(i+1));
|
||||
if (_gnu_noobjc_argv == NULL)
|
||||
goto error;
|
||||
i=0;
|
||||
while(*argv) {
|
||||
_gnu_noobjc_argv[i] =
|
||||
NSZoneMalloc(NSDefaultMallocZone(),strlen(*argv)+1);
|
||||
_gnu_noobjc_argv[i] = malloc(strlen(*argv)+1);
|
||||
if (_gnu_noobjc_argv[i] == NULL)
|
||||
goto error;
|
||||
strcpy(_gnu_noobjc_argv[i],*argv);
|
||||
argv++;
|
||||
i++;
|
||||
|
@ -216,18 +221,24 @@ _gnu_process_noobjc_args(int argc, char *argv[], char *env[]) {
|
|||
i=0;
|
||||
while(env[i])
|
||||
i++;
|
||||
_gnu_noobjc_env =
|
||||
NSZoneMalloc(NSDefaultMallocZone(),sizeof(char *)*(i+1));
|
||||
_gnu_noobjc_env = malloc(sizeof(char *)*(i+1));
|
||||
if (_gnu_noobjc_env == NULL)
|
||||
goto error;
|
||||
i=0;
|
||||
while(*env) {
|
||||
_gnu_noobjc_env[i] =
|
||||
NSZoneMalloc(NSDefaultMallocZone(),strlen(*env)+1);
|
||||
_gnu_noobjc_env[i] = malloc(strlen(*env)+1);
|
||||
if (_gnu_noobjc_env[i] == NULL)
|
||||
goto error;
|
||||
strcpy(_gnu_noobjc_env[i],*env);
|
||||
env++;
|
||||
i++;
|
||||
}
|
||||
_gnu_noobjc_env[i] = 0;
|
||||
return;
|
||||
|
||||
error:
|
||||
fputs("malloc() error when starting gstep-base\n", stderr);
|
||||
abort();
|
||||
}
|
||||
|
||||
static void _gnu_noobjc_free_vars(void)
|
||||
|
@ -236,18 +247,18 @@ static void _gnu_noobjc_free_vars(void)
|
|||
|
||||
p = _gnu_noobjc_argv;
|
||||
while (*p) {
|
||||
NSZoneFree(NSDefaultMallocZone(),*p);
|
||||
free(*p);
|
||||
p++;
|
||||
}
|
||||
NSZoneFree(NSDefaultMallocZone(),_gnu_noobjc_argv);
|
||||
free(_gnu_noobjc_argv);
|
||||
_gnu_noobjc_argv = 0;
|
||||
|
||||
p = _gnu_noobjc_env;
|
||||
while (*p) {
|
||||
NSZoneFree(NSDefaultMallocZone(),*p);
|
||||
free(*p);
|
||||
p++;
|
||||
}
|
||||
NSZoneFree(NSDefaultMallocZone(),_gnu_noobjc_env);
|
||||
free(_gnu_noobjc_env);
|
||||
_gnu_noobjc_env = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -217,7 +217,7 @@ static id defaultRNG = nil;
|
|||
/* return between 0 and numSides-1 */
|
||||
- (long) randomDie: (long)numSides
|
||||
{
|
||||
return ([rng nextRandom] % (numSides+1) - 1);
|
||||
return ([rng nextRandom] % numSides);
|
||||
}
|
||||
|
||||
- (BOOL) randomCoin
|
||||
|
|
|
@ -1770,9 +1770,9 @@ static NSMapTable *out_port_bag = NULL;
|
|||
|
||||
/* In and Out Packet classes. */
|
||||
|
||||
/* If you change this "unsigned short", you must change the use
|
||||
of ntohs() and htons() below. */
|
||||
#define PREFIX_LENGTH_TYPE unsigned short
|
||||
/* If you change this "unsigned long", you must change the use
|
||||
of ntohl() and htonl() below. */
|
||||
#define PREFIX_LENGTH_TYPE unsigned long
|
||||
#define PREFIX_LENGTH_SIZE sizeof (PREFIX_LENGTH_TYPE)
|
||||
#define PREFIX_ADDRESS_TYPE struct sockaddr_in
|
||||
#define PREFIX_ADDRESS_SIZE sizeof (PREFIX_ADDRESS_TYPE)
|
||||
|
@ -1815,7 +1815,7 @@ static NSMapTable *out_port_bag = NULL;
|
|||
|
||||
/* *size is the number of bytes in the packet, not including
|
||||
the PREFIX_SIZE-byte header. */
|
||||
*packet_size = ntohs (*(PREFIX_LENGTH_TYPE*) prefix_buffer);
|
||||
*packet_size = ntohl (*(PREFIX_LENGTH_TYPE*) prefix_buffer);
|
||||
assert (packet_size);
|
||||
|
||||
/* If the reply address is non-zero, and the TcpOutPort for this socket
|
||||
|
@ -1875,9 +1875,9 @@ static NSMapTable *out_port_bag = NULL;
|
|||
{
|
||||
int c;
|
||||
|
||||
/* Put the packet size in the first two bytes of the packet. */
|
||||
/* Put the packet size in the first four bytes of the packet. */
|
||||
assert (prefix == PREFIX_SIZE);
|
||||
*(PREFIX_LENGTH_TYPE*)[data mutableBytes] = htons (eof_position);
|
||||
*(PREFIX_LENGTH_TYPE*)[data mutableBytes] = htonl (eof_position);
|
||||
|
||||
/* Put the sockaddr_in for replies in the next bytes of the prefix
|
||||
region. If there is no reply address specified, fill it with zeros. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue