From ac16f41d6f3aa21487f3e3c6f25dba08e18e5cf5 Mon Sep 17 00:00:00 2001 From: CaS Date: Fri, 24 Oct 2003 09:29:43 +0000 Subject: [PATCH] Fix for opening files with relative paths. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@17964 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 8 ++++++++ Source/NSWorkspace.m | 9 +++++---- Tools/gopen.m | 35 ++++++++++++++++++++++++++--------- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index b25eebdcb..2954f77fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2003-10-24 Richard Frith-Macdonald + + * Source/NSWorkspace.m: Change a few uses of '/' in stgrings to + use stringByAppendingPatchComponent: + * Tools/gopen.m: Fix to pass the full path of the file to the + app being used to open it, so relative paths in the arguments + work properly. + 2003-10-21 Bjorn Giesler * Source/GSServicesManager.m: Fix NSPerformService() to work for diff --git a/Source/NSWorkspace.m b/Source/NSWorkspace.m index 41f75ba14..9555bd1bf 100644 --- a/Source/NSWorkspace.m +++ b/Source/NSWorkspace.m @@ -1105,7 +1105,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath } /** - *

Launches the specified application (unless it is alreeady running).
+ *

Launches the specified application (unless it is already running).
* If the autolaunch flag is yes, sets the autolaunch user default for the * newly launched application, so that applications which understand the * concept of being autolaunched at system startup time can modify their @@ -1528,7 +1528,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath } else { - path = [path stringByAppendingFormat: @"/%@", file]; + path = [path stringByAppendingPathComponent: file]; } } @@ -1644,7 +1644,8 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath */ if (iconPath == nil) { - iconPath = [[bundle bundlePath] stringByAppendingPathComponent: file]; + iconPath = [[bundle bundlePath] + stringByAppendingPathComponent: file]; } file = iconPath; } @@ -1712,7 +1713,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath absolute = [[NSURL fileURLWithPath: [file stringByStandardizingPath]] absoluteString]; - // This compensates for a bug we have in NSURL, that is there to have + // This compensates for a feature we have in NSURL, that is there to have // MacOSX compatibility. if ([absolute hasPrefix: @"file://localhost/"]) { diff --git a/Tools/gopen.m b/Tools/gopen.m index 2e6c6d775..920f6be7b 100644 --- a/Tools/gopen.m +++ b/Tools/gopen.m @@ -35,6 +35,17 @@ #include #include +static NSString* +absolutePath(NSFileManager *fm, NSString *path) +{ + path = [path stringByStandardizingPath]; + if ([path isAbsolutePath] == NO) + { + path = [[fm currentDirectoryPath] stringByAppendingPathComponent: path]; + } + return path; +} + int main(int argc, char** argv, char **env_c) { @@ -79,12 +90,14 @@ main(int argc, char** argv, char **env_c) if (filetoopen) { + filetoopen = absolutePath(fm, filetoopen); [workspace openFile: filetoopen - withApplication: application]; + withApplication: application]; } if (filetoprint) { + filetoprint = absolutePath(fm, filetoprint); puts("Not implemented"); } @@ -95,11 +108,11 @@ main(int argc, char** argv, char **env_c) if (argc == 1) { - NSFileHandle *fh = [NSFileHandle fileHandleWithStandardInput]; - NSData *data = [fh readDataToEndOfFile]; - NSString *tempFile = [NSTemporaryDirectory() + NSFileHandle *fh = [NSFileHandle fileHandleWithStandardInput]; + NSData *data = [fh readDataToEndOfFile]; + NSString *tempFile = [NSTemporaryDirectory() stringByAppendingPathComponent: @"openfiletmp"]; - NSNumber *processId = [NSNumber numberWithInt: + NSNumber *processId = [NSNumber numberWithInt: [[NSProcessInfo processInfo] processIdentifier]]; tempFile = [tempFile stringByAppendingString: [processId stringValue]]; @@ -140,6 +153,10 @@ main(int argc, char** argv, char **env_c) BOOL isDir = NO, exists = NO; exists = [fm fileExistsAtPath: arg isDirectory: &isDir]; + if (exists == YES) + { + arg = absolutePath(fm, arg); + } if (exists && !isDir && [fm isExecutableFileAtPath: arg]) { [workspace openFile: arg withApplication: terminal]; @@ -147,9 +164,9 @@ main(int argc, char** argv, char **env_c) else // no argument specified { // First check to see if it's an application - if ([ext isEqualToString: @"app"] || - [ext isEqualToString: @"debug"] || - [ext isEqualToString: @"profile"]) + if ([ext isEqualToString: @"app"] + || [ext isEqualToString: @"debug"] + || [ext isEqualToString: @"profile"]) { NSString *appName = [[arg lastPathComponent] stringByDeletingPathExtension]; @@ -172,7 +189,7 @@ main(int argc, char** argv, char **env_c) else { if (![workspace openFile: arg - withApplication: application]) + withApplication: application]) { // no recognized extension, // run application indicated by environment var.