2005-07-25 06:08:09 +00:00
|
|
|
/** This utility provides path/directory layout information for GNUstep.
|
|
|
|
Copyright (C) 2005 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
Created: July 2005
|
|
|
|
|
|
|
|
This file is part of the GNUstep Project
|
|
|
|
|
2008-06-08 10:38:33 +00:00
|
|
|
This program is free software; you can redistribute it and/or
|
2005-07-25 06:08:09 +00:00
|
|
|
modify it under the terms of the GNU General Public License
|
2008-06-08 10:38:33 +00:00
|
|
|
as published by the Free Software Foundation; either
|
|
|
|
version 3 of the License, or (at your option) any later version.
|
2005-07-25 06:08:09 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
2008-06-08 10:38:33 +00:00
|
|
|
License along with this program; see the file COPYINGv3.
|
2005-07-25 06:08:09 +00:00
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2010-02-19 14:21:02 +00:00
|
|
|
#import "common.h"
|
|
|
|
|
2010-02-14 14:30:02 +00:00
|
|
|
#import "Foundation/NSArray.h"
|
|
|
|
#import "Foundation/NSAutoreleasePool.h"
|
|
|
|
#import "Foundation/NSPathUtilities.h"
|
|
|
|
#import "Foundation/NSProcessInfo.h"
|
|
|
|
#import "Foundation/NSUserDefaults.h"
|
2005-07-25 06:08:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
<p>The 'gspath' utility prints out various items of path/directory
|
|
|
|
information (one item at a time).<br />
|
|
|
|
The program always takes a single argument ... selecting the information
|
|
|
|
to be printed.</p>
|
|
|
|
The arguments and their meanings are -<br />
|
|
|
|
<deflist>
|
|
|
|
<term>defaults</term>
|
|
|
|
<desc>The GNUstep defaults directory of the current user</desc>
|
2014-01-13 15:15:51 +00:00
|
|
|
<term>devpath</term>
|
|
|
|
<desc>A path specification which may be used to add the root(s) of
|
|
|
|
the GNUstep development environment on the current system.</desc>
|
2005-07-25 06:08:09 +00:00
|
|
|
<term>libpath</term>
|
|
|
|
<desc>A path specification which may be used to add all the standard
|
|
|
|
GNUstep directories where dynamic libraries are normally stored.<br />
|
|
|
|
you might do 'LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`gspath libpath`' to make
|
|
|
|
use of this.</desc>
|
|
|
|
<term>path</term>
|
|
|
|
<desc>A path specification which may be used to add all the standard
|
|
|
|
GNUstep directories where command-line programs are normally stored.<br />
|
|
|
|
you might do 'PATH=$PATH:`gspath path`' to make use of this.</desc>
|
|
|
|
<term>user</term>
|
|
|
|
<desc>The GNUstep home directory of the current user</desc>
|
|
|
|
</deflist>
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
main(int argc, char** argv, char **env)
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool;
|
|
|
|
NSProcessInfo *proc;
|
|
|
|
NSArray *args;
|
|
|
|
|
|
|
|
#ifdef GS_PASS_ARGUMENTS
|
2009-10-12 14:38:49 +00:00
|
|
|
GSInitializeProcess(argc, argv, env);
|
2005-07-25 06:08:09 +00:00
|
|
|
#endif
|
|
|
|
pool = [NSAutoreleasePool new];
|
|
|
|
proc = [NSProcessInfo processInfo];
|
|
|
|
if (proc == nil)
|
|
|
|
{
|
|
|
|
GSPrintf(stderr, @"gspath: unable to get process information!\n");
|
2011-05-27 11:48:44 +00:00
|
|
|
[pool drain];
|
2005-07-25 06:08:09 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
args = [proc arguments];
|
|
|
|
|
|
|
|
if ([args count] == 2)
|
|
|
|
{
|
|
|
|
BOOL ok = YES;
|
|
|
|
NSString *name = [[args objectAtIndex: 1] lowercaseString];
|
|
|
|
NSString *sep;
|
|
|
|
|
2010-03-19 12:10:11 +00:00
|
|
|
#ifdef __MINGW__
|
2005-07-25 06:08:09 +00:00
|
|
|
sep = @";";
|
|
|
|
#else
|
|
|
|
sep = @":";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ([name isEqualToString: @"defaults"] == YES)
|
|
|
|
{
|
|
|
|
GSPrintf(stdout, @"%@", GSDefaultsRootForUser(nil));
|
|
|
|
}
|
|
|
|
else if ([name isEqualToString: @"path"] == YES)
|
|
|
|
{
|
|
|
|
NSArray *directories;
|
|
|
|
NSString *path;
|
|
|
|
|
|
|
|
directories = NSSearchPathForDirectoriesInDomains
|
|
|
|
(GSToolsDirectory, NSAllDomainsMask, YES);
|
|
|
|
path = [directories componentsJoinedByString: sep];
|
|
|
|
GSPrintf(stdout, @"%@", path);
|
|
|
|
}
|
2014-01-13 15:15:51 +00:00
|
|
|
else if ([name isEqualToString: @"devpath"] == YES)
|
|
|
|
{
|
|
|
|
NSArray *directories;
|
|
|
|
NSString *path;
|
|
|
|
|
|
|
|
directories = NSSearchPathForDirectoriesInDomains
|
|
|
|
(NSDeveloperDirectory, NSAllDomainsMask, YES);
|
|
|
|
path = [directories componentsJoinedByString: sep];
|
|
|
|
GSPrintf(stdout, @"%@", path);
|
|
|
|
}
|
2005-07-25 06:08:09 +00:00
|
|
|
else if ([name isEqualToString: @"libpath"] == YES)
|
|
|
|
{
|
|
|
|
NSArray *directories;
|
|
|
|
NSString *path;
|
|
|
|
|
|
|
|
directories = NSSearchPathForDirectoriesInDomains
|
|
|
|
(GSLibrariesDirectory, NSAllDomainsMask, YES);
|
|
|
|
path = [directories componentsJoinedByString: sep];
|
|
|
|
GSPrintf(stdout, @"%@", path);
|
|
|
|
}
|
|
|
|
else if ([name isEqualToString: @"user"] == YES)
|
|
|
|
{
|
|
|
|
GSPrintf(stdout, @"%@", NSHomeDirectory());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok = NO; // Unrecognised option
|
|
|
|
}
|
|
|
|
if (ok == YES)
|
|
|
|
{
|
2011-05-27 11:48:44 +00:00
|
|
|
[pool drain];
|
2005-07-25 06:08:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GSPrintf(stderr,
|
|
|
|
@"The 'gspath' utility prints out various items of path/directory\n"
|
|
|
|
@"information (one item at a time).\n"
|
|
|
|
@"The program always takes a single argument ... selecting the information\n"
|
|
|
|
@"to be printed.\n\n"
|
|
|
|
@"The arguments and their meanings are -\n\n"
|
|
|
|
@"defaults\n"
|
2014-01-13 15:15:51 +00:00
|
|
|
@" The GNUstep defaults directory of the current user.\n\n"
|
|
|
|
@"devpath\n"
|
|
|
|
@" A path specification which may be used to add the root(s) of\n"
|
|
|
|
@" the GNUstep development environment on the current system.\n\n"
|
2005-07-25 06:08:09 +00:00
|
|
|
@"libpath\n"
|
|
|
|
@" A path specification which may be used to add all the standard GNUstep\n"
|
|
|
|
@" directories where dynamic libraries are normally stored.\n\n"
|
|
|
|
@" you might do 'LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`gspath libpath`' to make\n"
|
|
|
|
@" use of this.\n\n"
|
|
|
|
@"path\n"
|
|
|
|
@" A path specification which may be used to add all the standard GNUstep\n"
|
|
|
|
@" directories where command-line programs are normally stored.\n"
|
|
|
|
@" you might do 'PATH=$PATH:`gspath path`' to make use of this.\n\n"
|
|
|
|
@"user\n"
|
|
|
|
@" The GNUstep home directory of the current user\n\n"
|
|
|
|
);
|
2011-05-27 11:48:44 +00:00
|
|
|
[pool drain];
|
2005-07-25 06:08:09 +00:00
|
|
|
return 1;
|
|
|
|
}
|