diff --git a/Source/GNUmakefile.preamble b/Source/GNUmakefile.preamble index 8ceb95d9e..8594971e2 100644 --- a/Source/GNUmakefile.preamble +++ b/Source/GNUmakefile.preamble @@ -38,10 +38,20 @@ # Flags dealing with compiling and linking # +# GNUSTEP_INSTALL_PREFIX must be defined here and not in config.h because +# the installing person may set it on the `make' command line. +GNUSTEP_INSTALL_PREFIX=$(GNUSTEP_SYSTEM_ROOT) + # Additional flags to pass to the preprocessor GNUSTEP_INSTALL_LIBDIR=$(GNUSTEP_LIBRARIES_ROOT) ADDITIONAL_CPPFLAGS = -DGNUSTEP_INSTALL_LIBDIR=\"$(GNUSTEP_INSTALL_LIBDIR)\" \ - ${DPS_DEFINE} + ${DPS_DEFINE} \ + -DGNUSTEP_INSTALL_PREFIX=$(GNUSTEP_INSTALL_PREFIX) \ + -DGNUSTEP_TARGET_DIR=\"$(GNUSTEP_TARGET_DIR)\" \ + -DGNUSTEP_TARGET_CPU=\"$(GNUSTEP_TARGET_CPU)\" \ + -DGNUSTEP_TARGET_OS=\"$(GNUSTEP_TARGET_OS)\" \ + -DLIBRARY_COMBO=\"$(LIBRARY_COMBO)\" + # Additional flags to pass to the Objective-C compiler ADDITIONAL_OBJCFLAGS = -g -Wall diff --git a/Source/NSPasteboard.m b/Source/NSPasteboard.m index eda3174e1..77ec84341 100644 --- a/Source/NSPasteboard.m +++ b/Source/NSPasteboard.m @@ -29,6 +29,7 @@ #include #include +#include #include "../Tools/PasteboardServer.h" #include #include @@ -38,10 +39,15 @@ #include #include #include +#include #include #include #include +#define stringify_it(X) #X +#define prog_path(X,Y) \ + stringify_it(X) "/Tools/" GNUSTEP_TARGET_DIR "/" LIBRARY_COMBO Y + @interface NSPasteboard (Private) + (id) _pbs; + (NSPasteboard*) _pasteboardWithTarget: (id)aTarget @@ -84,30 +90,47 @@ static id the_server = nil; + (id) _pbs { - if (the_server == nil) { - NSString* host; + if (the_server == nil) + { + NSString* host; - host = [[NSUserDefaults standardUserDefaults] stringForKey: @"NSHost"]; - if (host == nil) { - host = [[NSProcessInfo processInfo] hostName]; - } - the_server = (id)[NSConnection - rootProxyForConnectionWithRegisteredName: PBSNAME - host: host]; - if ([(id)the_server retain]) { - NSConnection* conn = [(id)the_server connectionForProxy]; + host = [[NSUserDefaults standardUserDefaults] stringForKey: @"NSHost"]; + if (host == nil) + { + host = [[NSProcessInfo processInfo] hostName]; + } + the_server = (id)[NSConnection + rootProxyForConnectionWithRegisteredName: PBSNAME + host: host]; + if ([(id)the_server retain]) + { + NSConnection* conn = [(id)the_server connectionForProxy]; - [NSNotificationCenter - addObserver: self - selector: @selector(_lostServer:) - name: NSConnectionDidDieNotification - object: conn]; + [NSNotificationCenter addObserver: self + selector: @selector(_lostServer:) + name: NSConnectionDidDieNotification + object: conn]; + } + else + { + static BOOL recursion = NO; + + if (recursion) + { + NSLog(@"Unable to contact pasteboard server - " + @"please ensure that gpbs is running.\n"); + return nil; + } + else + { + system(prog_path(GNUSTEP_INSTALL_PREFIX, "/gpbs &")); + sleep(5); + recursion = YES; + [self _pbs]; + recursion = NO; + } + } } - else { - NSLog(@"Unable to contact pasteboard server - " - @"please ensure that gpbs is running.\n"); - } - } return the_server; } @@ -132,7 +155,7 @@ static id the_server = nil; * If this is the case, our proxy for the object on the server will be * out of date, so we swap it for the newly created one. */ - if (p->target != aTarget) { + if (p->target != (id)aTarget) { [p->target autorelease]; p->target = [(id)aTarget retain]; } @@ -660,17 +683,20 @@ provideDataForType:(NSString *)type static NSString* contentsPrefix = @"NSTypedFileContentsPboardType:"; static NSString* namePrefix = @"NSTypedFilenamesPboardType:"; -NSString *NSCreateFileContentsPboardType(NSString *fileType) +NSString* +NSCreateFileContentsPboardType(NSString *fileType) { return [NSString stringWithFormat:@"%@%@", contentsPrefix, fileType]; } -NSString *NSCreateFilenamePboardType(NSString *filename) +NSString* +NSCreateFilenamePboardType(NSString *filename) { return [NSString stringWithFormat:@"%@%@", namePrefix, filename]; } -NSString *NSGetFileType(NSString *pboardType) +NSString* +NSGetFileType(NSString *pboardType) { if ([pboardType hasPrefix: contentsPrefix]) { return [pboardType substringFromIndex: [contentsPrefix length]]; @@ -681,7 +707,8 @@ NSString *NSGetFileType(NSString *pboardType) return nil; } -NSArray *NSGetFileTypes(NSArray *pboardTypes) +NSArray* +NSGetFileTypes(NSArray *pboardTypes) { NSMutableArray *a = [NSMutableArray arrayWithCapacity: [pboardTypes count]]; unsigned int i; @@ -699,5 +726,29 @@ NSArray *NSGetFileTypes(NSArray *pboardTypes) return nil; } +void +NSUpdateDynamicServices() +{ + system(prog_path(GNUSTEP_INSTALL_PREFIX, "/make_services")); +} +static NSConnection *listener = nil; + +void +NSRegisterServicesProvider(id provider, NSString *name) +{ + if (listener) + { + /* + * Ensure there is no previous listener and nothing else using + * the given port name. + */ + [[NSPortNameServer defaultPortNameServer] removePortForName: name]; + [listener release]; + } + listener = [NSConnection newRegisteringAtName: name + withRootObject: provider]; + [listener retain]; +} +