diff --git a/Tools/gpbs.m b/Tools/gpbs.m index f26745d22..c964f11fa 100644 --- a/Tools/gpbs.m +++ b/Tools/gpbs.m @@ -17,7 +17,7 @@ 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 + 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 @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -49,49 +48,51 @@ #include "PasteboardServer.h" #include - // dummy definitions provided here to -BOOL // avoid errors when not linking with -initialize_gnustep_backend(void) // a back end + // dummy definitions provided here to + // avoid errors when not linking with + // a back end +BOOL +initialize_gnustep_backend(void) { - return YES; // dummy define + return YES; // dummy define } -void NSHighlightRect(NSRect aRect) // dummy define +void NSHighlightRect(NSRect aRect) // dummy define {} -void NSRectFill(NSRect aRect) // dummy define +void NSRectFill(NSRect aRect) // dummy define {} -void NSBeep(void) // dummy define +void NSBeep(void) // dummy define {} -@interface GMModel: NSObject +@interface GMModel: NSObject { } @end -@implementation GMModel +@implementation GMModel @end @class PasteboardServer; -int debug = 0; -int verbose = 0; +int debug = 0; +int verbose = 0; -#define MAXHIST 100 +#define MAXHIST 100 -PasteboardServer *server = nil; -NSConnection *conn = nil; -NSLock *dictionary_lock = nil; +PasteboardServer *server = nil; +NSConnection *conn = nil; +NSLock *dictionary_lock = nil; NSMutableDictionary* pasteboards = nil; @interface PasteboardData: NSObject { - NSData* data; - NSString* type; - id owner; - id pboard; - BOOL wantsChangedOwner; - BOOL hasGNUDataForType; - BOOL hasStdDataForType; + NSData* data; + NSString* type; + id owner; + id pboard; + BOOL wantsChangedOwner; + BOOL hasGNUDataForType; + BOOL hasStdDataForType; } + (PasteboardData*) newWithType: (NSString*)aType owner: (id)anObject @@ -118,16 +119,17 @@ NSMutableDictionary* pasteboards = nil; hasStdDataForType: (BOOL)StdData hasGNUDataForType: (BOOL)GNUData; { - PasteboardData* d = [PasteboardData alloc]; + PasteboardData* d = [PasteboardData alloc]; - if (d) { - d->type = [aType retain]; - d->owner = [anObject retain]; - d->pboard = [anotherObject retain]; - d->wantsChangedOwner = wants; - d->hasStdDataForType = StdData; - d->hasGNUDataForType = GNUData; - } + if (d) + { + d->type = [aType retain]; + d->owner = [anObject retain]; + d->pboard = [anotherObject retain]; + d->wantsChangedOwner = wants; + d->hasStdDataForType = StdData; + d->hasGNUDataForType = GNUData; + } return d; } @@ -135,22 +137,24 @@ NSMutableDictionary* pasteboards = nil; { id o; - if (owner && [owner isProxy] && [owner connectionForProxy] == c) { - o = owner; - owner = nil; - [o release]; - o = pboard; - pboard = nil; - [o release]; - } - if (pboard && [pboard isProxy] && [pboard connectionForProxy] == c) { - o = owner; - owner = nil; - [o release]; - o = pboard; - pboard = nil; - [o release]; - } + if (owner && [owner isProxy] && [owner connectionForProxy] == c) + { + o = owner; + owner = nil; + [o release]; + o = pboard; + pboard = nil; + [o release]; + } + if (pboard && [pboard isProxy] && [pboard connectionForProxy] == c) + { + o = owner; + owner = nil; + [o release]; + o = pboard; + pboard = nil; + [o release]; + } } - (void) dealloc @@ -164,22 +168,29 @@ NSMutableDictionary* pasteboards = nil; - (NSData*) data { - if (verbose) { - printf("get data for %x\n", (unsigned)self); - } + if (verbose) + { + printf("get data for %x\n", (unsigned)self); + } return data; } - (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,9 +206,10 @@ NSMutableDictionary* pasteboards = nil; - (void) setData: (NSData*)d { - if (verbose) { - printf("set data for %x\n", (unsigned)self); - } + if (verbose) + { + printf("set data for %x\n", (unsigned)self); + } [d retain]; [data release]; data = d; @@ -219,14 +231,14 @@ NSMutableDictionary* pasteboards = nil; @interface PasteboardEntry: NSObject { - int refNum; - BOOL hasBeenFiltered; - id owner; - id pboard; - NSMutableArray *items; - BOOL wantsChangedOwner; - BOOL hasGNUDataForType; - BOOL hasStdDataForType; + int refNum; + BOOL hasBeenFiltered; + id owner; + id pboard; + NSMutableArray *items; + BOOL wantsChangedOwner; + BOOL hasGNUDataForType; + BOOL hasStdDataForType; } + (PasteboardEntry*) newWithTypes: (NSArray*)someTypes owner: (id)anOwner @@ -248,43 +260,48 @@ NSMutableDictionary* pasteboards = nil; pboard: (id)aPboard ref: (int)count { - PasteboardEntry* e = [PasteboardEntry alloc]; + PasteboardEntry* e = [PasteboardEntry alloc]; - if (e) { - int i; + if (e) + { + int i; - e->owner = [anOwner retain]; - e->pboard = [aPboard retain]; + e->owner = [anOwner retain]; + e->pboard = [aPboard retain]; - if (anOwner && [anOwner respondsToSelector: - @selector(pasteboardChangedOwner:)]) { - e->wantsChangedOwner = YES; + if (anOwner && [anOwner respondsToSelector: + @selector(pasteboardChangedOwner:)]) + { + e->wantsChangedOwner = YES; + } + if (anOwner && [anOwner respondsToSelector: + @selector(pasteboard:provideDataForType:)]) + { + e->hasStdDataForType = YES; + } + if (anOwner && [anOwner respondsToSelector: + @selector(pasteboard:provideDataForType:andVersion:)]) + { + e->hasGNUDataForType = YES; + } + + e->items = [[NSMutableArray alloc] initWithCapacity:[someTypes count]]; + for (i = 0; i < [someTypes count]; i++) + { + NSString* type = [someTypes objectAtIndex:i]; + PasteboardData* d; + + d = [PasteboardData newWithType: type + owner: anOwner + pboard: aPboard + wantsChangedOwner: e->wantsChangedOwner + hasStdDataForType: e->hasStdDataForType + hasGNUDataForType: e->hasGNUDataForType]; + [e->items addObject:d]; + [d release]; + } + e->refNum = count; } - if (anOwner && [anOwner respondsToSelector: - @selector(pasteboard:provideDataForType:)]) { - e->hasStdDataForType = YES; - } - if (anOwner && [anOwner respondsToSelector: - @selector(pasteboard:provideDataForType:andVersion:)]) { - e->hasGNUDataForType = YES; - } - - e->items = [[NSMutableArray alloc] initWithCapacity:[someTypes count]]; - for (i = 0; i < [someTypes count]; i++) { - NSString* type = [someTypes objectAtIndex:i]; - PasteboardData* d; - - d = [PasteboardData newWithType: type - owner: anOwner - pboard: aPboard - wantsChangedOwner: e->wantsChangedOwner - hasStdDataForType: e->hasStdDataForType - hasGNUDataForType: e->hasGNUDataForType]; - [e->items addObject:d]; - [d release]; - } - e->refNum = count; - } return e; } @@ -296,34 +313,39 @@ NSMutableDictionary* pasteboards = nil; BOOL GNUData = NO; if (newOwner && [newOwner respondsToSelector: - @selector(pasteboardChangedOwner:)]) { - wants = YES; - } - if (newOwner && [newOwner respondsToSelector: - @selector(pasteboard:provideDataForType:)]) { - StdData = YES; - } - if (newOwner && [newOwner respondsToSelector: - @selector(pasteboard:provideDataForType:andVersion:)]) { - GNUData = YES; - } - - for (i = 0; i < [newTypes count]; i++) { - NSString* type = (NSString*)[newTypes objectAtIndex:i]; - - if ([self itemForType:type] == nil) { - PasteboardData* d; - - d = [PasteboardData newWithType: type - owner: newOwner - pboard: pb - wantsChangedOwner: wants - hasStdDataForType: StdData - hasGNUDataForType: GNUData]; - [items addObject:d]; - [d release]; + @selector(pasteboardChangedOwner:)]) + { + wants = YES; + } + if (newOwner && [newOwner respondsToSelector: + @selector(pasteboard:provideDataForType:)]) + { + StdData = YES; + } + if (newOwner && [newOwner respondsToSelector: + @selector(pasteboard:provideDataForType:andVersion:)]) + { + GNUData = YES; + } + + for (i = 0; i < [newTypes count]; i++) + { + NSString* type = (NSString*)[newTypes objectAtIndex:i]; + + if ([self itemForType:type] == nil) + { + PasteboardData* d; + + d = [PasteboardData newWithType: type + owner: newOwner + pboard: pb + wantsChangedOwner: wants + hasStdDataForType: StdData + hasGNUDataForType: GNUData]; + [items addObject:d]; + [d release]; + } } - } } - (void) checkConnection: (NSConnection*)c @@ -331,31 +353,35 @@ NSMutableDictionary* pasteboards = nil; unsigned int i; id o; - if (owner && [owner isProxy] && [owner connectionForProxy] == c) { - o = owner; - owner = nil; - [o release]; - o = pboard; - pboard = nil; - [o release]; - } - if (pboard && [pboard isProxy] && [pboard connectionForProxy] == c) { - o = owner; - owner = nil; - [o release]; - o = pboard; - pboard = nil; - [o release]; - } - - for (i = [items count]; i > 0; i--) { - PasteboardData* d = [items objectAtIndex: i-1]; - - [d checkConnection: c]; - if ([d data] == nil && [d owner] == nil) { - [items removeObjectAtIndex:i-1]; + if (owner && [owner isProxy] && [owner connectionForProxy] == c) + { + o = owner; + owner = nil; + [o release]; + o = pboard; + pboard = nil; + [o release]; + } + if (pboard && [pboard isProxy] && [pboard connectionForProxy] == c) + { + o = owner; + owner = nil; + [o release]; + o = pboard; + pboard = nil; + [o release]; + } + + for (i = [items count]; i > 0; i--) + { + PasteboardData* d = [items objectAtIndex: i-1]; + + [d checkConnection: c]; + if ([d data] == nil && [d owner] == nil) + { + [items removeObjectAtIndex:i-1]; + } } - } } - (void) dealloc @@ -375,55 +401,63 @@ NSMutableDictionary* pasteboards = nil; { unsigned i; - for (i = 0; i < [items count]; i++) { - PasteboardData* d = [items objectAtIndex:i]; + for (i = 0; i < [items count]; i++) + { + PasteboardData* d = [items objectAtIndex:i]; - if ([[d type] isEqual: type]) { - return d; + if ([[d type] isEqual: type]) + { + return d; + } } - } return nil; } - (void) lostOwnership { - NSMutableArray* a = [NSMutableArray arrayWithCapacity:4]; + NSMutableArray* a = [NSMutableArray arrayWithCapacity:4]; unsigned i; NS_DURING - { - if (wantsChangedOwner) { - [a addObject: owner]; + { + if (wantsChangedOwner) + { + [a addObject: owner]; + } + + for (i = 0; i < [items count]; i++) + { + PasteboardData* d = [items objectAtIndex:i]; + + if ([d wantsChangedOwner] && [a containsObject: [d owner]] == NO) + { + [a addObject: [d owner]]; + } + } + + if (wantsChangedOwner) + { + [a removeObject: owner]; + [owner pasteboardChangedOwner: pboard]; + } + + for (i = 0; i < [items count] && [a count] > 0; i++) + { + PasteboardData* d = [items objectAtIndex:i]; + id o = [d owner]; + + if ([a containsObject: o]) + { + [o pasteboardChangedOwner: [d pboard]]; + [a removeObject: o]; + } + } } - - for (i = 0; i < [items count]; i++) { - PasteboardData* d = [items objectAtIndex:i]; - - if ([d wantsChangedOwner] && [a containsObject: [d owner]] == NO) { - [a addObject: [d owner]]; - } - } - - if (wantsChangedOwner) { - [a removeObject: owner]; - [owner pasteboardChangedOwner: pboard]; - } - - for (i = 0; i < [items count] && [a count] > 0; i++) { - PasteboardData* d = [items objectAtIndex:i]; - id o = [d owner]; - - if ([a containsObject: o]) { - [o pasteboardChangedOwner: [d pboard]]; - [a removeObject: o]; - } - } - } NS_HANDLER - { - NSLog(@"Error informing objects of ownership change - %@\n", - [localException reason]); - } + { + NSLog(@"Error informing objects of ownership change - %@\n", + [localException reason]); + } NS_ENDHANDLER } @@ -434,13 +468,14 @@ NSMutableDictionary* pasteboards = nil; - (NSArray*) types { - NSMutableArray* t = [NSMutableArray arrayWithCapacity: [items count]]; - unsigned int i; + NSMutableArray* t = [NSMutableArray arrayWithCapacity: [items count]]; + unsigned int i; - for (i = 0; i < [items count]; i++) { - PasteboardData* d = [items objectAtIndex:i]; - [t addObject: [d type]]; - } + for (i = 0; i < [items count]; i++) + { + PasteboardData* d = [items objectAtIndex:i]; + [t addObject: [d type]]; + } return t; } @@ -450,36 +485,36 @@ NSMutableDictionary* pasteboards = nil; @interface PasteboardObject: NSObject { - NSString *name; - int nextCount; - unsigned histLength; - NSMutableArray *history; - PasteboardEntry *current; + NSString *name; + int nextCount; + unsigned histLength; + NSMutableArray *history; + PasteboardEntry *current; } + (PasteboardObject*) pasteboardWithName: (NSString*)name; - (int) addTypes: (NSArray*)types - owner: (id)owner + owner: (id)owner pasteboard: (id)pboard - oldCount: (int)count; + oldCount: (int)count; - (NSString*) availableTypeFromArray: (NSArray*)types - changeCount: (int*)count; + changeCount: (int*)count; - (int) changeCount; - (void) checkConnection: (NSConnection*)c; - (NSData*) dataForType: (NSString*)type - oldCount: (int)count - mustBeCurrent: (BOOL)flag; + oldCount: (int)count + mustBeCurrent: (BOOL)flag; - (int) declareTypes: (NSArray*)types - owner: (id)owner - pasteboard: (id)pboard; + owner: (id)owner + pasteboard: (id)pboard; - (PasteboardEntry*) entryByCount: (int)count; - (NSString*) name; - (void) releaseGlobally; - (BOOL) setData: (NSData*)data - forType: (NSString*)type - isFile: (BOOL)flag - oldCount: (int)count; + forType: (NSString*)type + isFile: (BOOL)flag + oldCount: (int)count; - (void) setHistory: (unsigned)length; - (NSArray*) typesAndChangeCount: (int*)count; @@ -495,46 +530,51 @@ NSMutableDictionary* pasteboards = nil; + (PasteboardObject*) pasteboardWithName: (NSString*)aName { - static int number = 0; - PasteboardObject* pb; + static int number = 0; + PasteboardObject* pb; [dictionary_lock lock]; - while (aName == nil) { - aName = [NSString stringWithFormat: @"%dlocalName", number++]; - if ([pasteboards objectForKey:aName] == nil) { - break; // This name is unique. + while (aName == nil) + { + aName = [NSString stringWithFormat: @"%dlocalName", number++]; + if ([pasteboards objectForKey:aName] == nil) + { + break; // This name is unique. + } + else + { + aName = nil; // Name already in use - try another. + } } - else { - aName = nil; // Name already in use - try another. - } - } pb = [pasteboards objectForKey: aName]; - if (pb == nil) { - pb = [PasteboardObject alloc]; - pb->name = [aName retain]; - pb->nextCount = 1; - pb->histLength = 1; - pb->history = [[NSMutableArray alloc] initWithCapacity:2]; - pb->current = nil; - [pasteboards setObject: pb forKey: aName]; - [pb autorelease]; - } + if (pb == nil) + { + pb = [PasteboardObject alloc]; + pb->name = [aName retain]; + pb->nextCount = 1; + pb->histLength = 1; + pb->history = [[NSMutableArray alloc] initWithCapacity:2]; + pb->current = nil; + [pasteboards setObject: pb forKey: aName]; + [pb autorelease]; + } [dictionary_lock unlock]; return pb; } - (int) addTypes: (NSArray*)types - owner: (id)owner + owner: (id)owner pasteboard: (NSPasteboard*)pb - oldCount: (int)count + oldCount: (int)count { PasteboardEntry *e = [self entryByCount:count]; - if (e) { - [e addTypes: types owner: owner pasteboard: pb]; - return count; - } + if (e) + { + [e addTypes: types owner: owner pasteboard: pb]; + return count; + } return 0; } @@ -543,67 +583,79 @@ NSMutableDictionary* pasteboards = nil; { PasteboardEntry *e = nil; - if (*count <= 0) { - e = current; - } - else { - e = [self entryByCount:*count]; - } - if (e) { - unsigned i; - - *count = [e refNum]; - for (i = 0; i < [types count]; i++) { - NSString* key = [types objectAtIndex:i]; - - if ([e itemForType: key] != nil) { - return key; - } + if (*count <= 0) + { + e = current; + } + else + { + e = [self entryByCount:*count]; + } + if (e) + { + unsigned i; + + *count = [e refNum]; + for (i = 0; i < [types count]; i++) + { + NSString* key = [types objectAtIndex:i]; + + if ([e itemForType: key] != nil) + { + return key; + } + } } - } return nil; } - (int) changeCount { - if (current) { - return [current refNum]; - } + if (current) + { + return [current refNum]; + } return 0; } - (void) checkConnection: (NSConnection*)c { - unsigned int i; + unsigned int i; - for (i = 0; i < [history count]; i++) { + for (i = 0; i < [history count]; i++) + { [[history objectAtIndex: i] checkConnection: c]; } } - (NSData*) dataForType: (NSString*)type - oldCount: (int)count - mustBeCurrent: (BOOL)flag + oldCount: (int)count + mustBeCurrent: (BOOL)flag { PasteboardEntry *e = nil; - if (flag) { - e = current; - } - else { - e = [self entryByCount:count]; - } - if (verbose) { - printf("get data for type '%s' version %d\n", - [type cString], e ? [e refNum] : -1); - } - if (e) { - PasteboardData* d = [e itemForType: type]; - - if (d) { - return [d newDataWithVersion: [e refNum]]; + if (flag) + { + e = current; + } + else + { + e = [self entryByCount:count]; + } + if (verbose) + { + printf("get data for type '%s' version %d\n", + [type cString], e ? [e refNum] : -1); + } + if (e) + { + PasteboardData* d = [e itemForType: type]; + + if (d) + { + return [d newDataWithVersion: [e refNum]]; + } } - } return nil; } @@ -615,10 +667,10 @@ NSMutableDictionary* pasteboards = nil; } - (int) declareTypes: (bycopy NSArray*)types - owner: (id)owner - pasteboard: (NSPasteboard*)pb + owner: (id)owner + pasteboard: (NSPasteboard*)pb { - PasteboardEntry* old = [current retain]; + PasteboardEntry* old = [current retain]; current = [PasteboardEntry newWithTypes:types owner:owner @@ -626,9 +678,10 @@ NSMutableDictionary* pasteboards = nil; ref:nextCount++]; [history addObject:current]; [current release]; - if ([history count] > histLength) { - [history removeObjectAtIndex:0]; - } + if ([history count] > histLength) + { + [history removeObjectAtIndex:0]; + } [old lostOwnership]; [old release]; return [current refNum]; @@ -636,22 +689,27 @@ NSMutableDictionary* pasteboards = nil; - (PasteboardEntry*) entryByCount: (int)count { - if (current == nil) { - return nil; - } - else if ([current refNum] == count) { - return current; - } - else { - int i; - - for (i = 0; i < [history count]; i++) { - if ([[history objectAtIndex:i] refNum] == count) { - return (PasteboardEntry*)[history objectAtIndex:i]; - } + if (current == nil) + { + return nil; + } + else if ([current refNum] == count) + { + return current; + } + else + { + int i; + + for (i = 0; i < [history count]; i++) + { + if ([[history objectAtIndex:i] refNum] == count) + { + return (PasteboardEntry*)[history objectAtIndex:i]; + } + } + return nil; } - return nil; - } } - (NSString*) name @@ -670,56 +728,69 @@ NSMutableDictionary* pasteboards = nil; } - (BOOL) setData: (NSData*)data - forType: (NSString*)type - isFile: (BOOL)flag - oldCount: (int)count + forType: (NSString*)type + isFile: (BOOL)flag + oldCount: (int)count { PasteboardEntry* e; - if (verbose) { - printf("set data for type '%s' version %d\n", - [type cString], count); - } + if (verbose) + { + printf("set data for type '%s' version %d\n", + [type cString], count); + } e = [self entryByCount: count]; - if (e) { - PasteboardData* d; + if (e) + { + PasteboardData* d; - if (flag) { - d = [e itemForType: NSFileContentsPboardType]; - if (d) { - [d setData: data]; - } - else { - return NO; - } - if (type && [type isEqual: NSFileContentsPboardType] == NO) { - d = [e itemForType: type]; - if (d) { - [d setData: data]; - } - else { - return NO; - } - } - return YES; + if (flag) + { + d = [e itemForType: NSFileContentsPboardType]; + if (d) + { + [d setData: data]; + } + else + { + return NO; + } + if (type && [type isEqual: NSFileContentsPboardType] == NO) + { + d = [e itemForType: type]; + if (d) + { + [d setData: data]; + } + else + { + return NO; + } + } + return YES; + } + else if (type) + { + d = [e itemForType: type]; + if (d) + { + [d setData: data]; + return YES; + } + else + { + return NO; + } + } + else + { + return NO; + } } - else if (type) { - d = [e itemForType: type]; - if (d) { - [d setData: data]; - return YES; - } - else { - return NO; - } - } - else { + else + { return NO; } - } - else { - return NO; - } } - (void) setHistory: (unsigned)length @@ -728,27 +799,32 @@ NSMutableDictionary* pasteboards = nil; if (length > MAXHIST) length = MAXHIST; histLength = length; - if (length < histLength) { - while ([history count] > histLength) { - [history removeObjectAtIndex:0]; + if (length < histLength) + { + while ([history count] > histLength) + { + [history removeObjectAtIndex:0]; + } } - } } - (NSArray*) typesAndChangeCount: (int*)count { PasteboardEntry *e = nil; - if (*count <= 0) { - e = current; - } - else { - e = [self entryByCount:*count]; - } - if (e) { - *count = [e refNum]; - return [e types]; - } + if (*count <= 0) + { + e = current; + } + else + { + e = [self entryByCount:*count]; + } + if (e) + { + *count = [e refNum]; + return [e types]; + } return nil; } @@ -760,14 +836,14 @@ NSMutableDictionary* pasteboards = nil; @interface PasteboardServer : NSObject { - NSMutableArray* permenant; + NSMutableArray* permenant; } - (NSConnection*) connection: ancestor didConnect: newConn; - connectionBecameInvalid: notification; - (id) pasteboardByFilteringData: (NSData*)data - ofType: (NSString*)type - isFile: (BOOL)flag; + ofType: (NSString*)type + isFile: (BOOL)flag; - (id) pasteboardByFilteringTypesInPasteboard: pb; - (id) pasteboardWithName: (NSString*)name; - (id) pasteboardWithUniqueName; @@ -778,11 +854,10 @@ NSMutableDictionary* pasteboards = nil; - (NSConnection*) connection: ancestor didConnect: newConn { - [NotificationDispatcher - addObserver: self - selector: @selector(connectionBecameInvalid:) - name: NSConnectionDidDieNotification - object: newConn]; + [NotificationDispatcher addObserver: self + selector: @selector(connectionBecameInvalid:) + name: NSConnectionDidDieNotification + object: newConn]; [newConn setDelegate: self]; return newConn; } @@ -791,18 +866,21 @@ NSMutableDictionary* pasteboards = nil; { id connection = [notification object]; - if (connection == conn) { - NSLog(@"Help - pasteboard server connection has died!\n"); - exit(1); - } - if ([connection isKindOf: [NSConnection class]]) { - NSEnumerator *e = [pasteboards objectEnumerator]; - PasteboardObject *o; - - while ((o = [e nextObject]) != nil) { - [o checkConnection: connection]; + if (connection == conn) + { + NSLog(@"Help - pasteboard server connection has died!\n"); + exit(1); + } + if ([connection isKindOf: [NSConnection class]]) + { + NSEnumerator *e = [pasteboards objectEnumerator]; + PasteboardObject *o; + + while ((o = [e nextObject]) != nil) + { + [o checkConnection: connection]; + } } - } return self; } @@ -815,24 +893,25 @@ NSMutableDictionary* pasteboards = nil; - init { self = [super init]; - if (self) { - permenant = [[NSMutableArray alloc] initWithCapacity:5]; - /* - * Create all the pasteboards which must persist forever and add them - * to a local array. - */ - [permenant addObject: [self pasteboardWithName: NSGeneralPboard]]; - [permenant addObject: [self pasteboardWithName: NSFontPboard]]; - [permenant addObject: [self pasteboardWithName: NSRulerPboard]]; - [permenant addObject: [self pasteboardWithName: NSFindPboard]]; - [permenant addObject: [self pasteboardWithName: NSDragPboard]]; - } + if (self) + { + permenant = [[NSMutableArray alloc] initWithCapacity:5]; + /* + * Create all the pasteboards which must persist forever and add them + * to a local array. + */ + [permenant addObject: [self pasteboardWithName: NSGeneralPboard]]; + [permenant addObject: [self pasteboardWithName: NSFontPboard]]; + [permenant addObject: [self pasteboardWithName: NSRulerPboard]]; + [permenant addObject: [self pasteboardWithName: NSFindPboard]]; + [permenant addObject: [self pasteboardWithName: NSDragPboard]]; + } return self; } - (id) pasteboardByFilteringData: (NSData*)data - ofType: (NSString*)type - isFile: (BOOL)flag + ofType: (NSString*)type + isFile: (BOOL)flag { [self notImplemented: _cmd]; return nil; @@ -867,74 +946,80 @@ NSMutableDictionary* pasteboards = nil; static int ihandler(int sig) { - abort(); + abort(); } static void init(int argc, char** argv) { - const char *options = "Hdv"; - int sym; + const char *options = "Hdv"; + int 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"); - exit(0); + 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\tfor help\n"); + printf("-d\tavoid fork() to make debugging easy\n"); + printf("-v\tMore verbose debug output\n"); + exit(0); - case 'd': - debug++; - break; + case 'd': + debug++; + break; - case 'v': - verbose++; - break; + case 'v': + verbose++; + break; - default: - printf("%s - GNU Pasteboard server\n", argv[0]); - printf("-H for help\n"); - exit(0); + default: + printf("%s - GNU Pasteboard server\n", argv[0]); + printf("-H for help\n"); + exit(0); } } - for (sym = 0; sym < 32; sym++) { - signal(sym, ihandler); + for (sym = 0; sym < 32; sym++) + { + signal(sym, ihandler); } - signal(SIGPIPE, SIG_IGN); - signal(SIGTTOU, SIG_IGN); - signal(SIGTTIN, SIG_IGN); - signal(SIGHUP, SIG_IGN); - signal(SIGTERM, ihandler); + signal(SIGPIPE, SIG_IGN); + signal(SIGTTOU, SIG_IGN); + signal(SIGTTIN, SIG_IGN); + signal(SIGHUP, SIG_IGN); + signal(SIGTERM, ihandler); - if (debug == 0) { - /* - * Now fork off child process to run in background. - */ - switch (fork()) { - case -1: - NSLog(@"gpbs - fork failed - bye.\n"); - exit(1); + if (debug == 0) + { + /* + * Now fork off child process to run in background. + */ + switch (fork()) + { + case -1: + NSLog(@"gpbs - fork failed - bye.\n"); + exit(1); - case 0: - /* - * Try to run in background. - */ + case 0: + /* + * Try to run in background. + */ #ifdef NeXT - setpgrp(0, getpid()); + setpgrp(0, getpid()); #else - setsid(); + setsid(); #endif - break; + break; - default: - if (verbose) { - NSLog(@"Process backgrounded (running as daemon)\r\n"); - } - exit(0); + default: + 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]; @@ -957,7 +1044,7 @@ main(int argc, char** argv) /* Register a connection that provides the server object to the network */ conn = [NSConnection newRegisteringAtName:PBSNAME - withRootObject:server]; + withRootObject:server]; if (conn == nil) { @@ -967,16 +1054,16 @@ main(int argc, char** argv) [conn setDelegate:server]; [NotificationDispatcher addObserver: server - selector: @selector(connectionBecameInvalid:) - name: NSConnectionDidDieNotification - object: conn]; + selector: @selector(connectionBecameInvalid:) + name: NSConnectionDidDieNotification + object: conn]; if (verbose) { NSLog(@"GNU pasteboard server startup.\n"); } [[NSRunLoop currentRunLoop] run]; - + [pool release]; exit(0); }