~ubuntu-branches/ubuntu/trusty/gnustep-base/trusty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/** 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

   This program 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 3 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 program; see the file COPYINGv3.
   If not, write to the Free Software Foundation,
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

   */

#import "common.h"

#import	"Foundation/NSArray.h"
#import	"Foundation/NSAutoreleasePool.h"
#import	"Foundation/NSPathUtilities.h"
#import	"Foundation/NSProcessInfo.h"
#import	"Foundation/NSUserDefaults.h"


/**
 <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>
   <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
  GSInitializeProcess(argc, argv, env);
#endif
  pool = [NSAutoreleasePool new];
  proc = [NSProcessInfo processInfo];
  if (proc == nil)
    {
      GSPrintf(stderr, @"gspath: unable to get process information!\n");
      [pool drain];
      return 1;
    }

  args = [proc arguments];

  if ([args count] == 2)
    {
      BOOL	ok = YES;
      NSString	*name = [[args objectAtIndex: 1] lowercaseString];
      NSString	*sep;

#ifdef	__MINGW__
      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);
	}
      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)
	{
	  [pool drain];
	  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"
@"  The GNUstep defaults directory of the current user\n\n"
@"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"
);
  [pool drain];
  return 1;
}