Adding gopen tool which works like the "open" command under OPENSTEP4.2/Mach

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@11419 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2001-11-18 19:01:07 +00:00
parent e5f5cda54a
commit b6480b88bb
3 changed files with 105 additions and 2 deletions

View file

@ -35,12 +35,16 @@ include ../config.make
include ../Version
# The applications to be compiled
TOOL_NAME = make_services set_show_service
TOOL_NAME = make_services set_show_service gopen
SERVICE_NAME = example GSspell
# The source files to be compiled
gopen_OBJC_FILES = gopen.m
gpbs_OBJC_FILES = gpbs.m
make_services_OBJC_FILES = make_services.m
set_show_service_OBJC_FILES = set_show_service.m
example_OBJC_FILES = example.m

View file

@ -24,7 +24,7 @@
ADDITIONAL_INCLUDE_DIRS += -I../Headers -I$(GNUSTEP_SYSTEM_ROOT)/Headers
# Additional LDFLAGS to pass to the linker
# ADDITIONAL_LDFLAGS +=
# ADDITIONAL_LDFLAGS +=
# Additional library directories the linker should search
ADDITIONAL_LIB_DIRS += -L../Source/$(GNUSTEP_OBJ_DIR) -L../Model/$(GNUSTEP_OBJ_DIR)
@ -32,6 +32,7 @@ ADDITIONAL_LIB_DIRS += -L../Source/$(GNUSTEP_OBJ_DIR) -L../Model/$(GNUSTEP_OBJ_D
# Additional libraries when linking tools
gpbs_TOOL_LIBS += -lgnustep-gui $(SYSTEM_LIBS)
set_show_service_TOOL_LIBS += -lgnustep-gui $(SYSTEM_LIBS)
gopen_TOOL_LIBS += -lgnustep-gui $(SYSTEM_LIBS)
# Additional libraries when linking applications
# ADDITIONAL_GUI_LIBS +=

98
Tools/gopen.m Normal file
View file

@ -0,0 +1,98 @@
/* This tool opens the appropriate application from the command line
based on what type of file is being accessed.
Copyright (C) 2001 Free Software Foundation, Inc.
Written by: Gregory Casamento <greg_casamento@yahoo.com>
Created: November 2001
This file is part of the GNUstep Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
You should have received a copy of the GNU General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <Foundation/NSArray.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSString.h>
#include <Foundation/NSProcessInfo.h>
#include <Foundation/NSTask.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSException.h>
#include <AppKit/NSApplication.h>
#include <AppKit/NSWorkspace.h>
// This is being redefined here to prevent NSWorkspace from
// complaining when no application event-loop is running.
int
NSRunAlertPanel(
NSString *title,
NSString *msg,
NSString *defaultButton,
NSString *alternateButton,
NSString *otherButton, ...)
{
return 0;
}
int
main(int argc, char** argv, char **env_c)
{
NSAutoreleasePool *pool;
NSArray *arguments = nil;
NSEnumerator *argEnumerator = nil;
NSString *file = nil;
NSWorkspace *workspace = nil;
#ifdef GS_PASS_ARGUMENTS
[NSProcessInfo initializeWithArguments:argv count:argc environment:env_c];
#endif
pool = [NSAutoreleasePool new];
argEnumerator = [[[NSProcessInfo processInfo] arguments] objectEnumerator];
workspace = [NSWorkspace sharedWorkspace];
[argEnumerator nextObject]; // skip the first element, which is empty.
while((file = [argEnumerator nextObject]) != nil)
{
NSString *ext = [file pathExtension];
NSString *appName = nil;
NS_DURING
if( ![workspace openFile: file] )
{
if( [ext isEqualToString: @"app"] )
{
NSString *appName =
[[file lastPathComponent] stringByDeletingPathExtension];
NSString *executable =
[file stringByAppendingPathComponent: appName];
NSTask *task = nil;
if ([NSTask launchedTaskWithLaunchPath: executable arguments: nil] == nil)
printf("Unable to launch application at path %s.\n",[file cString]);
}
else
{
printf("No application for extension %s\n",[ext cString]);
}
}
NS_HANDLER
NSLog(@"Exception while attempting open file %@ - %@: %@",
file, [localException name], [localException reason]);
NS_ENDHANDLER
}
[pool release];
exit(0);
}