mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 00:50:49 +00:00
Tidied source.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3304 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
5735ef8ea1
commit
43092212c5
1 changed files with 529 additions and 442 deletions
273
Tools/gpbs.m
273
Tools/gpbs.m
|
@ -38,7 +38,6 @@
|
|||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSTimer.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSException.h>
|
||||
|
@ -50,8 +49,10 @@
|
|||
|
||||
#include <signal.h>
|
||||
// dummy definitions provided here to
|
||||
BOOL // avoid errors when not linking with
|
||||
initialize_gnustep_backend(void) // a back end
|
||||
// avoid errors when not linking with
|
||||
// a back end
|
||||
BOOL
|
||||
initialize_gnustep_backend(void)
|
||||
{
|
||||
return YES; // dummy define
|
||||
}
|
||||
|
@ -120,7 +121,8 @@ NSMutableDictionary* pasteboards = nil;
|
|||
{
|
||||
PasteboardData* d = [PasteboardData alloc];
|
||||
|
||||
if (d) {
|
||||
if (d)
|
||||
{
|
||||
d->type = [aType retain];
|
||||
d->owner = [anObject retain];
|
||||
d->pboard = [anotherObject retain];
|
||||
|
@ -135,7 +137,8 @@ NSMutableDictionary* pasteboards = nil;
|
|||
{
|
||||
id o;
|
||||
|
||||
if (owner && [owner isProxy] && [owner connectionForProxy] == c) {
|
||||
if (owner && [owner isProxy] && [owner connectionForProxy] == c)
|
||||
{
|
||||
o = owner;
|
||||
owner = nil;
|
||||
[o release];
|
||||
|
@ -143,7 +146,8 @@ NSMutableDictionary* pasteboards = nil;
|
|||
pboard = nil;
|
||||
[o release];
|
||||
}
|
||||
if (pboard && [pboard isProxy] && [pboard connectionForProxy] == c) {
|
||||
if (pboard && [pboard isProxy] && [pboard connectionForProxy] == c)
|
||||
{
|
||||
o = owner;
|
||||
owner = nil;
|
||||
[o release];
|
||||
|
@ -164,7 +168,8 @@ NSMutableDictionary* pasteboards = nil;
|
|||
|
||||
- (NSData*) data
|
||||
{
|
||||
if (verbose) {
|
||||
if (verbose)
|
||||
{
|
||||
printf("get data for %x\n", (unsigned)self);
|
||||
}
|
||||
return data;
|
||||
|
@ -172,12 +177,18 @@ NSMutableDictionary* pasteboards = nil;
|
|||
|
||||
- (NSData*) newDataWithVersion: (int)version
|
||||
{
|
||||
if (data == nil && (owner && pboard)) {
|
||||
if (hasGNUDataForType) {
|
||||
[owner pasteboard: pboard provideDataForType: type andVersion: version];
|
||||
if (data == nil && (owner && pboard))
|
||||
{
|
||||
if (hasGNUDataForType)
|
||||
{
|
||||
[owner pasteboard: pboard
|
||||
provideDataForType: type
|
||||
andVersion: version];
|
||||
}
|
||||
else if (hasStdDataForType) {
|
||||
[owner pasteboard: pboard provideDataForType: type];
|
||||
else if (hasStdDataForType)
|
||||
{
|
||||
[owner pasteboard: pboard
|
||||
provideDataForType: type];
|
||||
}
|
||||
}
|
||||
return [self data];
|
||||
|
@ -195,7 +206,8 @@ NSMutableDictionary* pasteboards = nil;
|
|||
|
||||
- (void) setData: (NSData*)d
|
||||
{
|
||||
if (verbose) {
|
||||
if (verbose)
|
||||
{
|
||||
printf("set data for %x\n", (unsigned)self);
|
||||
}
|
||||
[d retain];
|
||||
|
@ -250,27 +262,32 @@ NSMutableDictionary* pasteboards = nil;
|
|||
{
|
||||
PasteboardEntry* e = [PasteboardEntry alloc];
|
||||
|
||||
if (e) {
|
||||
if (e)
|
||||
{
|
||||
int i;
|
||||
|
||||
e->owner = [anOwner retain];
|
||||
e->pboard = [aPboard retain];
|
||||
|
||||
if (anOwner && [anOwner respondsToSelector:
|
||||
@selector(pasteboardChangedOwner:)]) {
|
||||
@selector(pasteboardChangedOwner:)])
|
||||
{
|
||||
e->wantsChangedOwner = YES;
|
||||
}
|
||||
if (anOwner && [anOwner respondsToSelector:
|
||||
@selector(pasteboard:provideDataForType:)]) {
|
||||
@selector(pasteboard:provideDataForType:)])
|
||||
{
|
||||
e->hasStdDataForType = YES;
|
||||
}
|
||||
if (anOwner && [anOwner respondsToSelector:
|
||||
@selector(pasteboard:provideDataForType:andVersion:)]) {
|
||||
@selector(pasteboard:provideDataForType:andVersion:)])
|
||||
{
|
||||
e->hasGNUDataForType = YES;
|
||||
}
|
||||
|
||||
e->items = [[NSMutableArray alloc] initWithCapacity:[someTypes count]];
|
||||
for (i = 0; i < [someTypes count]; i++) {
|
||||
for (i = 0; i < [someTypes count]; i++)
|
||||
{
|
||||
NSString* type = [someTypes objectAtIndex:i];
|
||||
PasteboardData* d;
|
||||
|
||||
|
@ -296,22 +313,27 @@ NSMutableDictionary* pasteboards = nil;
|
|||
BOOL GNUData = NO;
|
||||
|
||||
if (newOwner && [newOwner respondsToSelector:
|
||||
@selector(pasteboardChangedOwner:)]) {
|
||||
@selector(pasteboardChangedOwner:)])
|
||||
{
|
||||
wants = YES;
|
||||
}
|
||||
if (newOwner && [newOwner respondsToSelector:
|
||||
@selector(pasteboard:provideDataForType:)]) {
|
||||
@selector(pasteboard:provideDataForType:)])
|
||||
{
|
||||
StdData = YES;
|
||||
}
|
||||
if (newOwner && [newOwner respondsToSelector:
|
||||
@selector(pasteboard:provideDataForType:andVersion:)]) {
|
||||
@selector(pasteboard:provideDataForType:andVersion:)])
|
||||
{
|
||||
GNUData = YES;
|
||||
}
|
||||
|
||||
for (i = 0; i < [newTypes count]; i++) {
|
||||
for (i = 0; i < [newTypes count]; i++)
|
||||
{
|
||||
NSString* type = (NSString*)[newTypes objectAtIndex:i];
|
||||
|
||||
if ([self itemForType:type] == nil) {
|
||||
if ([self itemForType:type] == nil)
|
||||
{
|
||||
PasteboardData* d;
|
||||
|
||||
d = [PasteboardData newWithType: type
|
||||
|
@ -331,7 +353,8 @@ NSMutableDictionary* pasteboards = nil;
|
|||
unsigned int i;
|
||||
id o;
|
||||
|
||||
if (owner && [owner isProxy] && [owner connectionForProxy] == c) {
|
||||
if (owner && [owner isProxy] && [owner connectionForProxy] == c)
|
||||
{
|
||||
o = owner;
|
||||
owner = nil;
|
||||
[o release];
|
||||
|
@ -339,7 +362,8 @@ NSMutableDictionary* pasteboards = nil;
|
|||
pboard = nil;
|
||||
[o release];
|
||||
}
|
||||
if (pboard && [pboard isProxy] && [pboard connectionForProxy] == c) {
|
||||
if (pboard && [pboard isProxy] && [pboard connectionForProxy] == c)
|
||||
{
|
||||
o = owner;
|
||||
owner = nil;
|
||||
[o release];
|
||||
|
@ -348,11 +372,13 @@ NSMutableDictionary* pasteboards = nil;
|
|||
[o release];
|
||||
}
|
||||
|
||||
for (i = [items count]; i > 0; i--) {
|
||||
for (i = [items count]; i > 0; i--)
|
||||
{
|
||||
PasteboardData* d = [items objectAtIndex: i-1];
|
||||
|
||||
[d checkConnection: c];
|
||||
if ([d data] == nil && [d owner] == nil) {
|
||||
if ([d data] == nil && [d owner] == nil)
|
||||
{
|
||||
[items removeObjectAtIndex:i-1];
|
||||
}
|
||||
}
|
||||
|
@ -375,10 +401,12 @@ NSMutableDictionary* pasteboards = nil;
|
|||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < [items count]; i++) {
|
||||
for (i = 0; i < [items count]; i++)
|
||||
{
|
||||
PasteboardData* d = [items objectAtIndex:i];
|
||||
|
||||
if ([[d type] isEqual: type]) {
|
||||
if ([[d type] isEqual: type])
|
||||
{
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
@ -392,28 +420,34 @@ NSMutableDictionary* pasteboards = nil;
|
|||
|
||||
NS_DURING
|
||||
{
|
||||
if (wantsChangedOwner) {
|
||||
if (wantsChangedOwner)
|
||||
{
|
||||
[a addObject: owner];
|
||||
}
|
||||
|
||||
for (i = 0; i < [items count]; i++) {
|
||||
for (i = 0; i < [items count]; i++)
|
||||
{
|
||||
PasteboardData* d = [items objectAtIndex:i];
|
||||
|
||||
if ([d wantsChangedOwner] && [a containsObject: [d owner]] == NO) {
|
||||
if ([d wantsChangedOwner] && [a containsObject: [d owner]] == NO)
|
||||
{
|
||||
[a addObject: [d owner]];
|
||||
}
|
||||
}
|
||||
|
||||
if (wantsChangedOwner) {
|
||||
if (wantsChangedOwner)
|
||||
{
|
||||
[a removeObject: owner];
|
||||
[owner pasteboardChangedOwner: pboard];
|
||||
}
|
||||
|
||||
for (i = 0; i < [items count] && [a count] > 0; i++) {
|
||||
for (i = 0; i < [items count] && [a count] > 0; i++)
|
||||
{
|
||||
PasteboardData* d = [items objectAtIndex:i];
|
||||
id o = [d owner];
|
||||
|
||||
if ([a containsObject: o]) {
|
||||
if ([a containsObject: o])
|
||||
{
|
||||
[o pasteboardChangedOwner: [d pboard]];
|
||||
[a removeObject: o];
|
||||
}
|
||||
|
@ -437,7 +471,8 @@ NSMutableDictionary* pasteboards = nil;
|
|||
NSMutableArray* t = [NSMutableArray arrayWithCapacity: [items count]];
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < [items count]; i++) {
|
||||
for (i = 0; i < [items count]; i++)
|
||||
{
|
||||
PasteboardData* d = [items objectAtIndex:i];
|
||||
[t addObject: [d type]];
|
||||
}
|
||||
|
@ -499,18 +534,22 @@ NSMutableDictionary* pasteboards = nil;
|
|||
PasteboardObject* pb;
|
||||
|
||||
[dictionary_lock lock];
|
||||
while (aName == nil) {
|
||||
while (aName == nil)
|
||||
{
|
||||
aName = [NSString stringWithFormat: @"%dlocalName", number++];
|
||||
if ([pasteboards objectForKey:aName] == nil) {
|
||||
if ([pasteboards objectForKey:aName] == nil)
|
||||
{
|
||||
break; // This name is unique.
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
aName = nil; // Name already in use - try another.
|
||||
}
|
||||
}
|
||||
|
||||
pb = [pasteboards objectForKey: aName];
|
||||
if (pb == nil) {
|
||||
if (pb == nil)
|
||||
{
|
||||
pb = [PasteboardObject alloc];
|
||||
pb->name = [aName retain];
|
||||
pb->nextCount = 1;
|
||||
|
@ -531,7 +570,8 @@ NSMutableDictionary* pasteboards = nil;
|
|||
{
|
||||
PasteboardEntry *e = [self entryByCount:count];
|
||||
|
||||
if (e) {
|
||||
if (e)
|
||||
{
|
||||
[e addTypes: types owner: owner pasteboard: pb];
|
||||
return count;
|
||||
}
|
||||
|
@ -543,20 +583,25 @@ NSMutableDictionary* pasteboards = nil;
|
|||
{
|
||||
PasteboardEntry *e = nil;
|
||||
|
||||
if (*count <= 0) {
|
||||
if (*count <= 0)
|
||||
{
|
||||
e = current;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
e = [self entryByCount:*count];
|
||||
}
|
||||
if (e) {
|
||||
if (e)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
*count = [e refNum];
|
||||
for (i = 0; i < [types count]; i++) {
|
||||
for (i = 0; i < [types count]; i++)
|
||||
{
|
||||
NSString* key = [types objectAtIndex:i];
|
||||
|
||||
if ([e itemForType: key] != nil) {
|
||||
if ([e itemForType: key] != nil)
|
||||
{
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
@ -566,7 +611,8 @@ NSMutableDictionary* pasteboards = nil;
|
|||
|
||||
- (int) changeCount
|
||||
{
|
||||
if (current) {
|
||||
if (current)
|
||||
{
|
||||
return [current refNum];
|
||||
}
|
||||
return 0;
|
||||
|
@ -576,7 +622,8 @@ NSMutableDictionary* pasteboards = nil;
|
|||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < [history count]; i++) {
|
||||
for (i = 0; i < [history count]; i++)
|
||||
{
|
||||
[[history objectAtIndex: i] checkConnection: c];
|
||||
}
|
||||
}
|
||||
|
@ -587,20 +634,25 @@ NSMutableDictionary* pasteboards = nil;
|
|||
{
|
||||
PasteboardEntry *e = nil;
|
||||
|
||||
if (flag) {
|
||||
if (flag)
|
||||
{
|
||||
e = current;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
e = [self entryByCount:count];
|
||||
}
|
||||
if (verbose) {
|
||||
if (verbose)
|
||||
{
|
||||
printf("get data for type '%s' version %d\n",
|
||||
[type cString], e ? [e refNum] : -1);
|
||||
}
|
||||
if (e) {
|
||||
if (e)
|
||||
{
|
||||
PasteboardData* d = [e itemForType: type];
|
||||
|
||||
if (d) {
|
||||
if (d)
|
||||
{
|
||||
return [d newDataWithVersion: [e refNum]];
|
||||
}
|
||||
}
|
||||
|
@ -626,7 +678,8 @@ NSMutableDictionary* pasteboards = nil;
|
|||
ref:nextCount++];
|
||||
[history addObject:current];
|
||||
[current release];
|
||||
if ([history count] > histLength) {
|
||||
if ([history count] > histLength)
|
||||
{
|
||||
[history removeObjectAtIndex:0];
|
||||
}
|
||||
[old lostOwnership];
|
||||
|
@ -636,17 +689,22 @@ NSMutableDictionary* pasteboards = nil;
|
|||
|
||||
- (PasteboardEntry*) entryByCount: (int)count
|
||||
{
|
||||
if (current == nil) {
|
||||
if (current == nil)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
else if ([current refNum] == count) {
|
||||
else if ([current refNum] == count)
|
||||
{
|
||||
return current;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < [history count]; i++) {
|
||||
if ([[history objectAtIndex:i] refNum] == count) {
|
||||
for (i = 0; i < [history count]; i++)
|
||||
{
|
||||
if ([[history objectAtIndex:i] refNum] == count)
|
||||
{
|
||||
return (PasteboardEntry*)[history objectAtIndex:i];
|
||||
}
|
||||
}
|
||||
|
@ -676,48 +734,61 @@ NSMutableDictionary* pasteboards = nil;
|
|||
{
|
||||
PasteboardEntry* e;
|
||||
|
||||
if (verbose) {
|
||||
if (verbose)
|
||||
{
|
||||
printf("set data for type '%s' version %d\n",
|
||||
[type cString], count);
|
||||
}
|
||||
e = [self entryByCount: count];
|
||||
if (e) {
|
||||
if (e)
|
||||
{
|
||||
PasteboardData* d;
|
||||
|
||||
if (flag) {
|
||||
if (flag)
|
||||
{
|
||||
d = [e itemForType: NSFileContentsPboardType];
|
||||
if (d) {
|
||||
if (d)
|
||||
{
|
||||
[d setData: data];
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
if (type && [type isEqual: NSFileContentsPboardType] == NO) {
|
||||
if (type && [type isEqual: NSFileContentsPboardType] == NO)
|
||||
{
|
||||
d = [e itemForType: type];
|
||||
if (d) {
|
||||
if (d)
|
||||
{
|
||||
[d setData: data];
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
else if (type) {
|
||||
else if (type)
|
||||
{
|
||||
d = [e itemForType: type];
|
||||
if (d) {
|
||||
if (d)
|
||||
{
|
||||
[d setData: data];
|
||||
return YES;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
@ -728,8 +799,10 @@ NSMutableDictionary* pasteboards = nil;
|
|||
if (length > MAXHIST) length = MAXHIST;
|
||||
|
||||
histLength = length;
|
||||
if (length < histLength) {
|
||||
while ([history count] > histLength) {
|
||||
if (length < histLength)
|
||||
{
|
||||
while ([history count] > histLength)
|
||||
{
|
||||
[history removeObjectAtIndex:0];
|
||||
}
|
||||
}
|
||||
|
@ -739,13 +812,16 @@ NSMutableDictionary* pasteboards = nil;
|
|||
{
|
||||
PasteboardEntry *e = nil;
|
||||
|
||||
if (*count <= 0) {
|
||||
if (*count <= 0)
|
||||
{
|
||||
e = current;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
e = [self entryByCount:*count];
|
||||
}
|
||||
if (e) {
|
||||
if (e)
|
||||
{
|
||||
*count = [e refNum];
|
||||
return [e types];
|
||||
}
|
||||
|
@ -778,8 +854,7 @@ NSMutableDictionary* pasteboards = nil;
|
|||
|
||||
- (NSConnection*) connection: ancestor didConnect: newConn
|
||||
{
|
||||
[NotificationDispatcher
|
||||
addObserver: self
|
||||
[NotificationDispatcher addObserver: self
|
||||
selector: @selector(connectionBecameInvalid:)
|
||||
name: NSConnectionDidDieNotification
|
||||
object: newConn];
|
||||
|
@ -791,15 +866,18 @@ NSMutableDictionary* pasteboards = nil;
|
|||
{
|
||||
id connection = [notification object];
|
||||
|
||||
if (connection == conn) {
|
||||
if (connection == conn)
|
||||
{
|
||||
NSLog(@"Help - pasteboard server connection has died!\n");
|
||||
exit(1);
|
||||
}
|
||||
if ([connection isKindOf: [NSConnection class]]) {
|
||||
if ([connection isKindOf: [NSConnection class]])
|
||||
{
|
||||
NSEnumerator *e = [pasteboards objectEnumerator];
|
||||
PasteboardObject *o;
|
||||
|
||||
while ((o = [e nextObject]) != nil) {
|
||||
while ((o = [e nextObject]) != nil)
|
||||
{
|
||||
[o checkConnection: connection];
|
||||
}
|
||||
}
|
||||
|
@ -815,7 +893,8 @@ NSMutableDictionary* pasteboards = nil;
|
|||
- init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
if (self)
|
||||
{
|
||||
permenant = [[NSMutableArray alloc] initWithCapacity:5];
|
||||
/*
|
||||
* Create all the pasteboards which must persist forever and add them
|
||||
|
@ -876,14 +955,16 @@ init(int argc, char** argv)
|
|||
const char *options = "Hdv";
|
||||
int sym;
|
||||
|
||||
while ((sym = getopt(argc, argv, options)) != -1) {
|
||||
switch(sym) {
|
||||
while ((sym = getopt(argc, argv, options)) != -1)
|
||||
{
|
||||
switch(sym)
|
||||
{
|
||||
case 'H':
|
||||
printf("%s -[%s]\n", argv[0], options);
|
||||
printf("GNU Pasteboard server\n");
|
||||
printf("-H for help\n");
|
||||
printf("-d avoid fork() to make debugging easy\n");
|
||||
printf("-v More verbose debug output\n");
|
||||
printf("-H\tfor help\n");
|
||||
printf("-d\tavoid fork() to make debugging easy\n");
|
||||
printf("-v\tMore verbose debug output\n");
|
||||
exit(0);
|
||||
|
||||
case 'd':
|
||||
|
@ -901,7 +982,8 @@ init(int argc, char** argv)
|
|||
}
|
||||
}
|
||||
|
||||
for (sym = 0; sym < 32; sym++) {
|
||||
for (sym = 0; sym < 32; sym++)
|
||||
{
|
||||
signal(sym, ihandler);
|
||||
}
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
@ -910,11 +992,13 @@ init(int argc, char** argv)
|
|||
signal(SIGHUP, SIG_IGN);
|
||||
signal(SIGTERM, ihandler);
|
||||
|
||||
if (debug == 0) {
|
||||
if (debug == 0)
|
||||
{
|
||||
/*
|
||||
* Now fork off child process to run in background.
|
||||
*/
|
||||
switch (fork()) {
|
||||
switch (fork())
|
||||
{
|
||||
case -1:
|
||||
NSLog(@"gpbs - fork failed - bye.\n");
|
||||
exit(1);
|
||||
|
@ -931,7 +1015,8 @@ init(int argc, char** argv)
|
|||
break;
|
||||
|
||||
default:
|
||||
if (verbose) {
|
||||
if (verbose)
|
||||
{
|
||||
NSLog(@"Process backgrounded (running as daemon)\r\n");
|
||||
}
|
||||
exit(0);
|
||||
|
@ -943,6 +1028,8 @@ init(int argc, char** argv)
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||
|
||||
init(argc, argv);
|
||||
|
||||
// [NSObject enableDoubleReleaseCheck: YES];
|
||||
|
@ -976,7 +1063,7 @@ main(int argc, char** argv)
|
|||
NSLog(@"GNU pasteboard server startup.\n");
|
||||
}
|
||||
[[NSRunLoop currentRunLoop] run];
|
||||
|
||||
[pool release];
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue