2005-03-15 04:24:26 +00:00
/ * Implementation of filesystem & path - related functions for GNUstep
2010-11-13 09:46:01 +00:00
Copyright ( C ) 1996 -2010 Free Software Foundation , Inc .
2005-03-15 06:36:21 +00:00
2005-03-15 04:24:26 +00:00
Written by : Andrew Kachites McCallum < address @ hidden >
2005-03-03 16:04:22 +00:00
Created : May 1996
2005-03-15 04:24:26 +00:00
Rewrite by : Sheldon Gill
Date : Jan 2004
2005-10-13 10:11:56 +00:00
Rewrites by : Richard Frith - Macdonald
Date : 2004 -2005
2005-03-15 06:36:21 +00:00
2005-03-03 16:04:22 +00:00
This file is part of the GNUstep Base Library .
This library is free software ; you can redistribute it and / or
2007-09-14 11:36:11 +00:00
modify it under the terms of the GNU Lesser General Public
2005-03-03 16:04:22 +00:00
License as published by the Free Software Foundation ; either
2008-06-08 10:38:33 +00:00
version 2 of the License , or ( at your option ) any later version .
2005-03-15 06:36:21 +00:00
2005-03-03 16:04:22 +00:00
This library is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
Library General Public License for more details .
2005-03-15 06:36:21 +00:00
2007-09-14 11:36:11 +00:00
You should have received a copy of the GNU Lesser General Public
2005-03-03 16:04:22 +00:00
License along with this library ; if not , write to the Free
2006-06-27 19:06:44 +00:00
Software Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
Boston , MA 02111 USA .
2005-03-03 16:04:22 +00:00
2005-03-15 04:24:26 +00:00
< title > NSPathUtilities function reference < / title >
2005-03-03 16:04:22 +00:00
$ Date $ $ Revision $
* /
2005-03-15 04:24:26 +00:00
/ * *
< unit >
< heading > Path Utility Functions < / heading >
< p >
Path utilities provides functions to dynamically discover paths
for the platform the application is running on .
This avoids the need for hard coding paths , making porting easier
and also allowing for places to change without breaking
applications .
( why do this ? Well imagine we ' re running GNUstep 1 and the new
wonderful GNUstep 2 becomes available but we ' re not sure of it
yet . You could install / GNUstep / System2 / and have applications
use which ever System you wanted at the time . . . )
< / p >
< p >
On unix systems , the paths are initialised by reading a configuration
file . Something like "/etc/GNUstep/GNUstep.conf" . This provides the basic
information required by the library to establish all locations required .
< / p >
< p >
2005-11-06 13:53:40 +00:00
See < REF "filesystem.pdf" > GNUstep File System Hierarchy < / REF > document
2005-03-15 04:24:26 +00:00
for more information and detailed descriptions . < / p >
< / unit >
* /
2007-12-21 10:50:37 +00:00
/ * The following define is needed for Solaris get ( pw / gr ) ( nam / uid ) _r declartions
which default to pre POSIX declaration . * /
# define _POSIX _PTHREAD _SEMANTICS
2010-02-19 08:12:46 +00:00
# import "common.h"
2005-10-16 14:20:14 +00:00
# include "objc-load.h"
2010-02-17 11:47:06 +00:00
# import "Foundation/NSPathUtilities.h"
# import "Foundation/NSException.h"
# import "Foundation/NSArray.h"
2014-01-13 15:15:51 +00:00
# import "Foundation/NSBundle.h"
2010-02-17 11:47:06 +00:00
# import "Foundation/NSDictionary.h"
# import "Foundation/NSFileManager.h"
# import "Foundation/NSProcessInfo.h"
# import "Foundation/NSValue.h"
# import "Foundation/NSLock.h"
# import "Foundation/NSUserDefaults.h"
2010-02-14 10:48:10 +00:00
# import "GNUstepBase/NSString+GNUstepBase.h"
2005-03-03 16:04:22 +00:00
2010-02-17 11:47:06 +00:00
# import "GSPrivate.h"
2005-03-03 16:04:22 +00:00
# ifdef HAVE_PWD _H
2007-12-19 14:39:44 +00:00
# include < pwd . h > // for getpwnam_r ( ) and getpwuid_r ( )
2005-03-03 16:04:22 +00:00
# endif
# include < sys / types . h >
# include < stdio . h >
2006-02-19 21:49:21 +00:00
NSMutableDictionary * GNUstepConfig ( NSDictionary * newConfig ) ;
void GNUstepUserConfig ( NSMutableDictionary * config , NSString * userName ) ;
2005-03-15 04:24:26 +00:00
/ * The global configuration file . The real value is read from config . h * /
2006-01-08 12:59:11 +00:00
# ifndef GNUSTEP_TARGET _CONFIG _FILE
# define GNUSTEP_TARGET _CONFIG _FILE "/etc/GNUstep/GNUstep.conf"
2005-03-15 04:24:26 +00:00
# endif
2005-03-17 14:48:32 +00:00
2005-07-31 08:18:19 +00:00
static NSString * gnustep_target _cpu =
# ifdef GNUSTEP_TARGET _CPU
@ GNUSTEP_TARGET _CPU ;
# else
nil ;
# endif
static NSString * gnustep_target _os =
# ifdef GNUSTEP_TARGET _OS
@ GNUSTEP_TARGET _OS ;
# else
nil ;
# endif
static NSString * library_combo =
# ifdef LIBRARY_COMBO
@ LIBRARY_COMBO ;
# else
nil ;
# endif
2006-10-02 16:06:37 +00:00
static NSString * gnustep_is _flattened =
# ifdef GNUSTEP_IS _FLATTENED
@ GNUSTEP_IS _FLATTENED ;
2005-07-31 08:18:19 +00:00
# else
nil ;
# endif
2010-03-19 12:10:11 +00:00
# if defined ( __MINGW __ )
2006-09-26 11:50:11 +00:00
2010-07-19 08:54:38 +00:00
# include < sddl . h >
2006-09-26 11:50:11 +00:00
# include < lmaccess . h >
2005-12-07 08:02:48 +00:00
/ *
* FIXME . . . should check access properly if the file is on an NTFS volume .
* /
2005-10-23 06:35:33 +00:00
# define ATTRMASK 0700
# else
# define ATTRMASK 0777
# endif
2005-03-17 14:48:32 +00:00
# define MGR ( ) [ NSFileManager defaultManager ]
2005-03-15 04:24:26 +00:00
/ * - - - - - - - - - - - - - - - - - - * /
/ * Internal variables * /
/ * - - - - - - - - - - - - - - - - - - * /
2005-03-17 14:48:32 +00:00
2005-10-16 11:48:54 +00:00
static NSString * gnustepConfigPath = nil ;
2005-03-15 04:24:26 +00:00
2005-10-15 07:19:11 +00:00
static NSString * gnustepUserHome = nil ;
2010-07-19 08:34:29 +00:00
static NSString * gnustepUserID = nil ;
static NSString * gnustepUserName = nil ;
2005-10-15 07:19:11 +00:00
static NSString * gnustepUserDefaultsDir = nil ;
2005-03-15 04:24:26 +00:00
2006-09-26 11:16:06 +00:00
static NSString * theUserName = nil ; / * The user ' s login name * /
static NSString * theFullUserName = nil ; / * The user ' s full login name * /
2005-03-15 04:24:26 +00:00
static NSString * tempDir = nil ; / * user ' s temporary directory * /
2007-02-15 03:06:33 +00:00
/ * The following list entirely describe our filesystem configuration . * /
static NSString * gnustepMakefiles = nil ;
2007-03-06 14:03:49 +00:00
static NSString * gnustepSystemUsersDir = nil ;
static NSString * gnustepNetworkUsersDir = nil ;
static NSString * gnustepLocalUsersDir = nil ;
2007-02-15 03:06:33 +00:00
static NSString * gnustepSystemApps = nil ;
2007-02-16 20:53:29 +00:00
static NSString * gnustepSystemAdminApps = nil ;
2007-03-05 17:58:02 +00:00
static NSString * gnustepSystemWebApps = nil ;
2007-02-15 03:06:33 +00:00
static NSString * gnustepSystemTools = nil ;
2007-02-16 20:53:29 +00:00
static NSString * gnustepSystemAdminTools = nil ;
2007-02-15 03:06:33 +00:00
static NSString * gnustepSystemLibrary = nil ;
static NSString * gnustepSystemLibraries = nil ;
static NSString * gnustepSystemHeaders = nil ;
static NSString * gnustepSystemDocumentation = nil ;
static NSString * gnustepSystemDocumentationInfo = nil ;
static NSString * gnustepSystemDocumentationMan = nil ;
static NSString * gnustepNetworkApps = nil ;
2007-02-16 20:53:29 +00:00
static NSString * gnustepNetworkAdminApps = nil ;
2007-03-05 17:58:02 +00:00
static NSString * gnustepNetworkWebApps = nil ;
2007-02-15 03:06:33 +00:00
static NSString * gnustepNetworkTools = nil ;
2007-02-16 20:53:29 +00:00
static NSString * gnustepNetworkAdminTools = nil ;
2007-02-15 03:06:33 +00:00
static NSString * gnustepNetworkLibrary = nil ;
static NSString * gnustepNetworkLibraries = nil ;
static NSString * gnustepNetworkHeaders = nil ;
static NSString * gnustepNetworkDocumentation = nil ;
static NSString * gnustepNetworkDocumentationInfo = nil ;
static NSString * gnustepNetworkDocumentationMan = nil ;
static NSString * gnustepLocalApps = nil ;
2007-02-16 20:53:29 +00:00
static NSString * gnustepLocalAdminApps = nil ;
2007-03-05 17:58:02 +00:00
static NSString * gnustepLocalWebApps = nil ;
2007-02-15 03:06:33 +00:00
static NSString * gnustepLocalTools = nil ;
2007-02-16 20:53:29 +00:00
static NSString * gnustepLocalAdminTools = nil ;
2007-02-15 03:06:33 +00:00
static NSString * gnustepLocalLibrary = nil ;
static NSString * gnustepLocalLibraries = nil ;
static NSString * gnustepLocalHeaders = nil ;
static NSString * gnustepLocalDocumentation = nil ;
static NSString * gnustepLocalDocumentationInfo = nil ;
static NSString * gnustepLocalDocumentationMan = nil ;
static NSString * gnustepUserApps = nil ;
2007-02-16 20:53:29 +00:00
static NSString * gnustepUserAdminApps = nil ;
2007-03-05 17:58:02 +00:00
static NSString * gnustepUserWebApps = nil ;
2007-02-15 03:06:33 +00:00
static NSString * gnustepUserTools = nil ;
2007-02-16 20:53:29 +00:00
static NSString * gnustepUserAdminTools = nil ;
2007-02-15 03:06:33 +00:00
static NSString * gnustepUserLibrary = nil ;
static NSString * gnustepUserLibraries = nil ;
static NSString * gnustepUserHeaders = nil ;
static NSString * gnustepUserDocumentation = nil ;
static NSString * gnustepUserDocumentationInfo = nil ;
static NSString * gnustepUserDocumentationMan = nil ;
/ * These are the same as the corresponding User variables , but
* they hold the path before GNUSTEP_HOME is prepended . It ' s what
* we read from config files .
* /
static NSString * gnustepUserDirApps = nil ;
2007-02-16 20:53:29 +00:00
static NSString * gnustepUserDirAdminApps = nil ;
2007-03-05 17:58:02 +00:00
static NSString * gnustepUserDirWebApps = nil ;
2007-02-15 03:06:33 +00:00
static NSString * gnustepUserDirTools = nil ;
2007-02-16 20:53:29 +00:00
static NSString * gnustepUserDirAdminTools = nil ;
2007-02-15 03:06:33 +00:00
static NSString * gnustepUserDirLibrary = nil ;
static NSString * gnustepUserDirLibraries = nil ;
static NSString * gnustepUserDirHeaders = nil ;
static NSString * gnustepUserDirDocumentation = nil ;
static NSString * gnustepUserDirDocumentationInfo = nil ;
static NSString * gnustepUserDirDocumentationMan = nil ;
2005-03-15 04:24:26 +00:00
2011-04-12 05:41:53 +00:00
static NSString * uninstalled = nil ;
2006-02-17 06:31:04 +00:00
static BOOL ParseConfigurationFile ( NSString * name , NSMutableDictionary * dict ,
NSString * userName ) ;
2005-03-15 04:24:26 +00:00
2005-03-17 15:27:52 +00:00
static void InitialisePathUtilities ( void ) ;
static void ShutdownPathUtilities ( void ) ;
2005-03-15 04:24:26 +00:00
2013-08-22 15:44:54 +00:00
@ interface GSPathUtilities : NSObject
@ end
2005-10-14 10:51:50 +00:00
/ * Conditionally assign an object from a dictionary to var
* We don ' t need to retain val before releasing var , because we
* can be sure that if var is val it is retained by the dictionary
* as well as being retained when it was first placed in var .
* /
2005-10-13 10:11:56 +00:00
# define ASSIGN_IF _SET ( var , dictionary , key ) ( { \
2005-10-14 10:51:50 +00:00
id val = [ dictionary objectForKey : key ] ; \
if ( val ! = nil ) \
{ \
RELEASE ( var ) ; \
var = RETAIN ( val ) ; \
2005-10-16 15:07:10 +00:00
[ dictionary removeObjectForKey : key ] ; \
2005-10-14 10:51:50 +00:00
} \
2005-10-16 15:07:10 +00:00
} )
2005-10-14 10:51:50 +00:00
2010-07-19 08:34:29 +00:00
/ * Grab a path from the config file , making it relative to the config
2011-10-17 09:10:18 +00:00
* file location if it is ' . ' or begins with ' . / ' or ' . . / ' , and checking
* that the result is an absolute path .
2010-07-19 08:34:29 +00:00
* /
2005-10-16 11:48:54 +00:00
# define ASSIGN_PATH ( var , dictionary , key ) ( { \
id val = getPathConfig ( dictionary , key ) ; \
if ( val ! = nil ) \
{ \
RELEASE ( var ) ; \
var = RETAIN ( val ) ; \
2005-10-16 15:07:10 +00:00
[ dictionary removeObjectForKey : key ] ; \
2005-10-16 11:48:54 +00:00
} \
2005-10-16 15:07:10 +00:00
} )
2005-10-16 11:48:54 +00:00
2010-07-19 08:34:29 +00:00
/ * Like ASSIGN_PATH ( ) , but permits the result to be a relative path as that
* is what we normally use ( the path is within the user ' s home directory ) .
* /
# define ASSIGN_USER ( var , dictionary , key ) ( { \
id val = [ dictionary objectForKey : key ] ; \
if ( val ! = nil ) \
{ \
val = getPath ( val ) ; \
} \
if ( val ! = nil ) \
{ \
RELEASE ( var ) ; \
var = RETAIN ( val ) ; \
[ dictionary removeObjectForKey : key ] ; \
} \
} )
2012-07-05 09:55:42 +00:00
/ * Conditionally assign lval to var only if var is nil
lval must be casted because Clang disallows ObjC literals comparison * /
2005-10-14 10:51:50 +00:00
# define TEST_ASSIGN ( var , lval ) ( { \
2012-07-05 09:55:42 +00:00
if ( ( var = = nil ) && ( ( NSString * ) lval ! = nil ) ) \
2005-10-14 10:51:50 +00:00
{ \
var = RETAIN ( lval ) ; \
} \
} )
2005-03-03 16:04:22 +00:00
2007-02-15 03:06:33 +00:00
# define ASSIGN_DEFAULT _PATH ( var , default ) ( { \
if ( var = = nil ) \
{ \
var = default ; \
var = RETAIN ( getPath ( var ) ) ; \
} \
} )
2010-07-19 08:34:29 +00:00
/ * The user domain paths are normally located within the user ' s home directory ,
* but if they are specified as absolute paths they can be anywhere you like .
*
* /
# define ASSIGN_USER _PATH ( var , val ) ( { \
if ( nil = = var ) \
{ \
ASSIGN ( var , ( [ val isAbsolutePath ] ? substUser ( val ) : \
[ gnustepUserHome stringByAppendingPathComponent : substUser ( val ) ] ) ) ; \
} \
} )
/ * For user domain paths , we allow ' % u ' as the username , ' % i ' as the userid ,
* and ' % % ' as a ' % ' in cases where it would otherwise be treated as a
* username or userid .
* /
static NSString *
substUser ( NSString * str )
{
if ( str ! = nil && [ str rangeOfString : @ "%" ] . length > 0 )
{
NSMutableString * m = [ [ str mutableCopy ] autorelease ] ;
int l = [ m length ] ;
int i = 0 ;
BOOL percent = NO ;
while ( i < l )
{
unichar c = [ m characterAtIndex : i ] ;
if ( YES = = percent )
{
NSString * s ;
if ( c = = ' % ' )
{
s = @ "%" ; // Escaped percent
}
else if ( c = = ' i ' )
{
s = gnustepUserID ; // User ID
}
else if ( c = = ' u ' )
{
s = gnustepUserName ; // User name
}
else
{
s = nil ; // No substitution
}
if ( s ! = nil )
{
int diff = [ s length ] - 2 ;
[ m replaceCharactersInRange : NSMakeRange ( i -1 , 2 )
withString : s ] ;
l + = diff ;
i + = diff ;
}
percent = NO ;
}
else if ( c = = ' % ' )
{
percent = YES ;
}
i + + ;
}
str = m ;
}
return str ;
}
2007-02-15 03:06:33 +00:00
2005-10-16 11:48:54 +00:00
/ * Get a full path string * /
2005-03-15 04:24:26 +00:00
static inline NSString *
2005-10-16 11:48:54 +00:00
getPath ( NSString * path )
2005-03-03 16:04:22 +00:00
{
2011-10-18 05:56:03 +00:00
if ( [ path hasPrefix : @ "./" ] = = YES )
2005-10-16 11:48:54 +00:00
{
path = [ gnustepConfigPath stringByAppendingPathComponent :
[ path substringFromIndex : 2 ] ] ;
2005-12-05 07:03:21 +00:00
path = [ path stringByStandardizingPath ] ;
2005-10-16 11:48:54 +00:00
}
2008-01-10 11:14:30 +00:00
else if ( [ path hasPrefix : @ "../" ] = = YES )
{
path = [ gnustepConfigPath stringByAppendingPathComponent : path ] ;
path = [ path stringByStandardizingPath ] ;
}
2005-10-16 11:48:54 +00:00
return path ;
}
2005-03-15 04:24:26 +00:00
2005-10-16 11:48:54 +00:00
/ * Get a full path string from a dictionary * /
static inline NSString *
getPathConfig ( NSDictionary * dict , NSString * key )
{
NSString * path ;
2005-03-03 16:04:22 +00:00
2005-03-15 04:24:26 +00:00
path = [ dict objectForKey : key ] ;
2005-11-22 07:57:07 +00:00
if ( path ! = nil )
{
path = getPath ( path ) ;
if ( [ path isAbsolutePath ] = = NO )
{
NSLog ( @ "GNUstep configuration file entry '%@' ('%@') is not "
@ "an absolute path. Please fix your configuration file" ,
key , [ dict objectForKey : key ] ) ;
# if defined ( __MINGW32 _ )
if ( [ path length ] > 2 )
{
unichar buf [ 3 ] ;
[ path getCharacters : buf range : NSMakeRange ( 0 , 3 ) ] ;
2010-07-19 08:34:29 +00:00
if ( ( buf [ 0 ] = = ' / ' || buf [ 0 ] = = ' \ \ ' ) && isalpha ( buf [ 1 ] )
&& ( buf [ 2 ] = = ' / ' || buf [ 2 ] = = ' \ \ ' ) )
2005-11-22 07:57:07 +00:00
{
path = [ NSString stringWithFormat : @ "%c:%@" , ( char ) buf [ 1 ] ,
[ path substringFromindex : 2 ] ] ;
2005-12-01 09:33:22 +00:00
path = [ path stringByReplacingString : @ "/"
withString : @ "\\" ] ;
2005-11-22 07:57:07 +00:00
NSLog ( @ "I am guessing that you meant '%@'" , path ) ;
}
}
# endif
}
}
2005-03-15 04:24:26 +00:00
return path ;
}
2005-10-15 07:19:11 +00:00
static void ExtractValuesFromConfig ( NSDictionary * config )
2005-03-15 04:24:26 +00:00
{
2005-10-16 15:07:10 +00:00
NSMutableDictionary * c = [ config mutableCopy ] ;
2011-11-14 10:01:24 +00:00
BOOL createLibraryPath ;
2008-01-10 11:14:30 +00:00
id extra ;
2005-10-15 07:19:11 +00:00
2005-10-16 15:07:10 +00:00
/ *
* Move values out of the dictionary and into variables for rapid reference .
* /
2011-11-14 10:01:24 +00:00
ASSIGN_IF _SET ( gnustepUserDefaultsDir , c ,
@ "GNUSTEP_USER_DEFAULTS_DIR" ) ;
ASSIGN_PATH ( gnustepMakefiles , c ,
@ "GNUSTEP_MAKEFILES" ) ;
ASSIGN_PATH ( gnustepSystemUsersDir , c ,
@ "GNUSTEP_SYSTEM_USERS_DIR" ) ;
ASSIGN_PATH ( gnustepNetworkUsersDir , c ,
@ "GNUSTEP_NETWORK_USERS_DIR" ) ;
ASSIGN_PATH ( gnustepLocalUsersDir , c ,
@ "GNUSTEP_LOCAL_USERS_DIR" ) ;
ASSIGN_PATH ( gnustepSystemApps , c ,
@ "GNUSTEP_SYSTEM_APPS" ) ;
ASSIGN_PATH ( gnustepSystemAdminApps , c ,
@ "GNUSTEP_SYSTEM_ADMIN_APPS" ) ;
ASSIGN_PATH ( gnustepSystemWebApps , c ,
@ "GNUSTEP_SYSTEM_WEB_APPS" ) ;
ASSIGN_PATH ( gnustepSystemTools , c ,
@ "GNUSTEP_SYSTEM_TOOLS" ) ;
ASSIGN_PATH ( gnustepSystemAdminTools , c ,
@ "GNUSTEP_SYSTEM_ADMIN_TOOLS" ) ;
ASSIGN_PATH ( gnustepSystemLibrary , c ,
@ "GNUSTEP_SYSTEM_LIBRARY" ) ;
ASSIGN_PATH ( gnustepSystemLibraries , c ,
@ "GNUSTEP_SYSTEM_LIBRARIES" ) ;
ASSIGN_PATH ( gnustepSystemHeaders , c ,
@ "GNUSTEP_SYSTEM_HEADERS" ) ;
ASSIGN_PATH ( gnustepSystemDocumentation , c ,
@ "GNUSTEP_SYSTEM_DOC" ) ;
ASSIGN_PATH ( gnustepSystemDocumentationMan , c ,
@ "GNUSTEP_SYSTEM_DOC_MAN" ) ;
ASSIGN_PATH ( gnustepSystemDocumentationInfo , c ,
@ "GNUSTEP_SYSTEM_DOC_INFO" ) ;
ASSIGN_PATH ( gnustepNetworkApps , c ,
@ "GNUSTEP_NETWORK_APPS" ) ;
ASSIGN_PATH ( gnustepNetworkAdminApps , c ,
@ "GNUSTEP_NETWORK_ADMIN_APPS" ) ;
ASSIGN_PATH ( gnustepNetworkWebApps , c ,
@ "GNUSTEP_NETWORK_WEB_APPS" ) ;
ASSIGN_PATH ( gnustepNetworkTools , c ,
@ "GNUSTEP_NETWORK_TOOLS" ) ;
ASSIGN_PATH ( gnustepNetworkAdminTools , c ,
@ "GNUSTEP_NETWORK_ADMIN_TOOLS" ) ;
ASSIGN_PATH ( gnustepNetworkLibrary , c ,
@ "GNUSTEP_NETWORK_LIBRARY" ) ;
ASSIGN_PATH ( gnustepNetworkLibraries , c ,
@ "GNUSTEP_NETWORK_LIBRARIES" ) ;
ASSIGN_PATH ( gnustepNetworkHeaders , c ,
@ "GNUSTEP_NETWORK_HEADERS" ) ;
ASSIGN_PATH ( gnustepNetworkDocumentation , c ,
@ "GNUSTEP_NETWORK_DOC" ) ;
ASSIGN_PATH ( gnustepNetworkDocumentationMan , c ,
@ "GNUSTEP_NETWORK_DOC_MAN" ) ;
ASSIGN_PATH ( gnustepNetworkDocumentationInfo , c ,
@ "GNUSTEP_NETWORK_DOC_INFO" ) ;
ASSIGN_PATH ( gnustepLocalApps , c ,
@ "GNUSTEP_LOCAL_APPS" ) ;
ASSIGN_PATH ( gnustepLocalAdminApps , c ,
@ "GNUSTEP_LOCAL_ADMIN_APPS" ) ;
ASSIGN_PATH ( gnustepLocalWebApps , c ,
@ "GNUSTEP_LOCAL_WEB_APPS" ) ;
ASSIGN_PATH ( gnustepLocalTools , c ,
@ "GNUSTEP_LOCAL_TOOLS" ) ;
ASSIGN_PATH ( gnustepLocalAdminTools , c ,
@ "GNUSTEP_LOCAL_ADMIN_TOOLS" ) ;
ASSIGN_PATH ( gnustepLocalLibrary , c ,
@ "GNUSTEP_LOCAL_LIBRARY" ) ;
ASSIGN_PATH ( gnustepLocalLibraries , c ,
@ "GNUSTEP_LOCAL_LIBRARIES" ) ;
ASSIGN_PATH ( gnustepLocalHeaders , c ,
@ "GNUSTEP_LOCAL_HEADERS" ) ;
ASSIGN_PATH ( gnustepLocalDocumentation , c ,
@ "GNUSTEP_LOCAL_DOC" ) ;
ASSIGN_PATH ( gnustepLocalDocumentationMan , c ,
@ "GNUSTEP_LOCAL_DOC_MAN" ) ;
ASSIGN_PATH ( gnustepLocalDocumentationInfo , c ,
@ "GNUSTEP_LOCAL_DOC_INFO" ) ;
ASSIGN_USER ( gnustepUserDirApps , c ,
@ "GNUSTEP_USER_DIR_APPS" ) ;
TEST_ASSIGN ( gnustepUserDirApps ,
@ GNUSTEP_TARGET _USER _DIR _APPS ) ;
ASSIGN_USER ( gnustepUserDirAdminApps , c ,
@ "GNUSTEP_USER_DIR_ADMIN_APPS" ) ;
TEST_ASSIGN ( gnustepUserDirAdminApps ,
@ GNUSTEP_TARGET _USER _DIR _ADMIN _APPS ) ;
ASSIGN_USER ( gnustepUserDirWebApps , c ,
@ "GNUSTEP_USER_DIR_WEB_APPS" ) ;
TEST_ASSIGN ( gnustepUserDirWebApps ,
@ GNUSTEP_TARGET _USER _DIR _WEB _APPS ) ;
ASSIGN_USER ( gnustepUserDirTools , c ,
@ "GNUSTEP_USER_DIR_TOOLS" ) ;
TEST_ASSIGN ( gnustepUserDirTools ,
@ GNUSTEP_TARGET _USER _DIR _TOOLS ) ;
ASSIGN_USER ( gnustepUserDirAdminTools , c ,
@ "GNUSTEP_USER_DIR_ADMIN_TOOLS" ) ;
TEST_ASSIGN ( gnustepUserDirAdminTools ,
@ GNUSTEP_TARGET _USER _DIR _ADMIN _TOOLS ) ;
ASSIGN_USER ( gnustepUserDirLibrary , c ,
@ "GNUSTEP_USER_DIR_LIBRARY" ) ;
TEST_ASSIGN ( gnustepUserDirLibrary ,
@ GNUSTEP_TARGET _USER _DIR _LIBRARY ) ;
ASSIGN_USER ( gnustepUserDirLibraries , c ,
@ "GNUSTEP_USER_DIR_LIBRARIES" ) ;
TEST_ASSIGN ( gnustepUserDirLibraries ,
@ GNUSTEP_TARGET _USER _DIR _LIBRARIES ) ;
ASSIGN_USER ( gnustepUserDirHeaders , c ,
@ "GNUSTEP_USER_DIR_HEADERS" ) ;
TEST_ASSIGN ( gnustepUserDirHeaders ,
@ GNUSTEP_TARGET _USER _DIR _HEADERS ) ;
ASSIGN_USER ( gnustepUserDirDocumentation , c ,
@ "GNUSTEP_USER_DIR_DOC" ) ;
TEST_ASSIGN ( gnustepUserDirDocumentation ,
@ GNUSTEP_TARGET _USER _DIR _DOC ) ;
ASSIGN_USER ( gnustepUserDirDocumentationMan , c ,
@ "GNUSTEP_USER_DIR_DOC_MAN" ) ;
TEST_ASSIGN ( gnustepUserDirDocumentationMan ,
@ GNUSTEP_TARGET _USER _DIR _DOC _MAN ) ;
ASSIGN_USER ( gnustepUserDirDocumentationInfo , c ,
@ "GNUSTEP_USER_DIR_DOC_INFO" ) ;
TEST_ASSIGN ( gnustepUserDirDocumentationInfo ,
@ GNUSTEP_TARGET _USER _DIR _DOC _INFO ) ;
2005-10-16 15:07:10 +00:00
2006-06-27 19:06:44 +00:00
/ *
* The GNUSTEP_EXTRA field may contain a list of extra keys which
* we permit in the dictionary without generating a warning .
* /
extra = [ c objectForKey : @ "GNUSTEP_EXTRA" ] ;
if ( extra ! = nil )
{
NSEnumerator * enumerator ;
NSString * key ;
2008-01-10 11:14:30 +00:00
if ( [ extra isKindOfClass : [ NSString class ] ] = = YES )
{
extra = [ extra componentsSeparatedByString : @ "," ] ;
}
enumerator = [ extra objectEnumerator ] ;
2006-06-27 19:06:44 +00:00
[ c removeObjectForKey : @ "GNUSTEP_EXTRA" ] ;
while ( ( key = [ enumerator nextObject ] ) ! = nil )
{
key = [ key stringByTrimmingSpaces ] ;
[ c removeObjectForKey : key ] ;
}
}
2008-01-10 11:14:30 +00:00
[ c removeObjectForKey : @ "GNUSTEP_SYSTEM_DEFAULTS_FILE" ] ;
2006-06-27 19:06:44 +00:00
2011-11-14 10:01:24 +00:00
/ * If GNUSTEP_CREATE _DIRECTORIES is YES then we should ensure that the
* per - user directory and the Library subdirectory exist so resources
* can safely be stored in them .
* /
createLibraryPath
= [ [ c objectForKey : @ "GNUSTEP_CREATE_LIBRARY_PATH" ] boolValue ] ;
[ c removeObjectForKey : @ "GNUSTEP_CREATE_LIBRARY_PATH" ] ;
2005-10-16 15:07:10 +00:00
/ *
* Remove any other dictionary entries we have used .
* /
[ c removeObjectForKey : @ "GNUSTEP_USER_CONFIG_FILE" ] ;
2007-03-01 13:46:01 +00:00
/ * FIXME . . . for the time being we just ignore obsolete keys * /
[ c removeObjectForKey : @ "GNUSTEP_USER_ROOT" ] ;
[ c removeObjectForKey : @ "GNUSTEP_LOCAL_ROOT" ] ;
[ c removeObjectForKey : @ "GNUSTEP_SYSTEM_ROOT" ] ;
[ c removeObjectForKey : @ "GNUSTEP_NETWORK_ROOT" ] ;
2008-01-14 10:39:21 +00:00
[ c removeObjectForKey : @ "GNUSTEP_USER_DIR" ] ;
2007-03-01 13:46:01 +00:00
2005-10-16 15:07:10 +00:00
if ( [ c count ] > 0 )
{
/ *
* The dictionary should be empty . . . report problems
* /
fprintf ( stderr , "Configuration contains unknown keys - %s\n" ,
[ [ [ c allKeys ] description ] UTF8String ] ) ;
}
DESTROY ( c ) ;
2005-10-15 07:19:11 +00:00
/ *
2005-10-16 11:48:54 +00:00
* Set default locations for user files if necessary .
2005-10-15 07:19:11 +00:00
* /
2005-10-16 04:08:12 +00:00
if ( gnustepUserDefaultsDir = = nil )
{
2005-10-27 12:00:38 +00:00
ASSIGN ( gnustepUserDefaultsDir , @ GNUSTEP_TARGET _USER _DEFAULTS _DIR ) ;
2005-10-16 04:08:12 +00:00
}
2007-02-15 03:06:33 +00:00
if ( gnustepUserDirApps = = nil )
{
ASSIGN ( gnustepUserDirApps , @ GNUSTEP_TARGET _USER _DIR _APPS ) ;
}
if ( gnustepUserDirTools = = nil )
{
ASSIGN ( gnustepUserDirTools , @ GNUSTEP_TARGET _USER _DIR _TOOLS ) ;
}
if ( gnustepUserDirLibrary = = nil )
{
ASSIGN ( gnustepUserDirLibrary , @ GNUSTEP_TARGET _USER _DIR _LIBRARY ) ;
}
if ( gnustepUserDirLibraries = = nil )
{
ASSIGN ( gnustepUserDirLibraries , @ GNUSTEP_TARGET _USER _DIR _LIBRARIES ) ;
}
if ( gnustepUserDirHeaders = = nil )
{
ASSIGN ( gnustepUserDirHeaders , @ GNUSTEP_TARGET _USER _DIR _HEADERS ) ;
}
if ( gnustepUserDirDocumentation = = nil )
{
2014-01-12 15:19:39 +00:00
ASSIGN ( gnustepUserDirDocumentation ,
2007-02-26 15:20:50 +00:00
@ GNUSTEP_TARGET _USER _DIR _DOC ) ;
2007-02-15 03:06:33 +00:00
}
if ( gnustepUserDirDocumentationMan = = nil )
{
2014-01-12 15:19:39 +00:00
ASSIGN ( gnustepUserDirDocumentationMan ,
2007-02-26 15:20:50 +00:00
@ GNUSTEP_TARGET _USER _DIR _DOC _MAN ) ;
2007-02-15 03:06:33 +00:00
}
if ( gnustepUserDirDocumentationInfo = = nil )
{
2014-01-12 15:19:39 +00:00
ASSIGN ( gnustepUserDirDocumentationInfo ,
2007-02-26 15:20:50 +00:00
@ GNUSTEP_TARGET _USER _DIR _DOC _INFO ) ;
2007-02-15 03:06:33 +00:00
}
2005-10-16 04:08:12 +00:00
/ *
2007-02-15 03:06:33 +00:00
* Set the GNUSTEP_USER _xxx variables from the user home and the
* GNUSTEP_USER _DIR _xxx variables .
2005-10-16 04:08:12 +00:00
* /
2010-07-19 08:34:29 +00:00
ASSIGN_USER _PATH ( gnustepUserApps , gnustepUserDirApps ) ;
ASSIGN_USER _PATH ( gnustepUserAdminApps , gnustepUserDirAdminApps ) ;
ASSIGN_USER _PATH ( gnustepUserWebApps , gnustepUserDirWebApps ) ;
ASSIGN_USER _PATH ( gnustepUserTools , gnustepUserDirTools ) ;
ASSIGN_USER _PATH ( gnustepUserAdminTools , gnustepUserDirAdminTools ) ;
ASSIGN_USER _PATH ( gnustepUserLibrary , gnustepUserDirLibrary ) ;
ASSIGN_USER _PATH ( gnustepUserLibraries , gnustepUserDirLibraries ) ;
ASSIGN_USER _PATH ( gnustepUserHeaders , gnustepUserDirHeaders ) ;
ASSIGN_USER _PATH ( gnustepUserDocumentation , gnustepUserDocumentation ) ;
ASSIGN_USER _PATH ( gnustepUserDocumentationMan , gnustepUserDocumentationMan ) ;
ASSIGN_USER _PATH ( gnustepUserDocumentationInfo , gnustepUserDocumentationInfo ) ;
2007-02-15 03:06:33 +00:00
2005-10-25 16:15:35 +00:00
/ *
2011-11-14 10:01:24 +00:00
* Try to ensure that essential user directories exist if we need to .
2005-10-25 16:15:35 +00:00
* /
2011-11-14 10:01:24 +00:00
if ( YES = = createLibraryPath )
2005-10-25 16:15:35 +00:00
{
NSFileManager * manager ;
NSString * path ;
NSDictionary * attr ;
BOOL flag ;
manager = [ NSFileManager defaultManager ] ;
attr = [ NSDictionary dictionaryWithObject : [ NSNumber numberWithInt : 0750 ]
forKey : NSFilePosixPermissions ] ;
2007-02-15 03:06:33 +00:00
// Make sure library directory exists ( to store resources ) .
path = gnustepUserLibrary ;
2005-10-25 16:15:35 +00:00
if ( [ manager fileExistsAtPath : path isDirectory : & flag ] = = NO
|| flag = = NO )
{
2012-08-10 08:36:09 +00:00
[ manager createDirectoryAtPath : path
withIntermediateDirectories : YES
attributes : attr
error : NULL ] ;
2005-10-25 16:15:35 +00:00
}
}
2005-10-16 04:08:12 +00:00
/ *
2005-10-16 11:48:54 +00:00
* Finally set default locations for the essential paths if required .
2005-10-16 04:08:12 +00:00
* /
2011-11-14 10:01:24 +00:00
ASSIGN_DEFAULT _PATH ( gnustepSystemApps ,
@ GNUSTEP_TARGET _SYSTEM _APPS ) ;
ASSIGN_DEFAULT _PATH ( gnustepSystemAdminApps ,
@ GNUSTEP_TARGET _SYSTEM _ADMIN _APPS ) ;
ASSIGN_DEFAULT _PATH ( gnustepSystemWebApps ,
@ GNUSTEP_TARGET _SYSTEM _WEB _APPS ) ;
ASSIGN_DEFAULT _PATH ( gnustepSystemTools ,
@ GNUSTEP_TARGET _SYSTEM _TOOLS ) ;
ASSIGN_DEFAULT _PATH ( gnustepSystemAdminTools ,
@ GNUSTEP_TARGET _SYSTEM _ADMIN _TOOLS ) ;
ASSIGN_DEFAULT _PATH ( gnustepSystemLibrary ,
@ GNUSTEP_TARGET _SYSTEM _LIBRARY ) ;
ASSIGN_DEFAULT _PATH ( gnustepSystemLibraries ,
@ GNUSTEP_TARGET _SYSTEM _LIBRARIES ) ;
ASSIGN_DEFAULT _PATH ( gnustepSystemHeaders ,
@ GNUSTEP_TARGET _SYSTEM _HEADERS ) ;
ASSIGN_DEFAULT _PATH ( gnustepSystemDocumentation ,
@ GNUSTEP_TARGET _SYSTEM _DOC ) ;
ASSIGN_DEFAULT _PATH ( gnustepSystemDocumentationMan ,
@ GNUSTEP_TARGET _SYSTEM _DOC _MAN ) ;
ASSIGN_DEFAULT _PATH ( gnustepSystemDocumentationInfo ,
@ GNUSTEP_TARGET _SYSTEM _DOC _INFO ) ;
ASSIGN_DEFAULT _PATH ( gnustepNetworkApps ,
@ GNUSTEP_TARGET _NETWORK _APPS ) ;
ASSIGN_DEFAULT _PATH ( gnustepNetworkAdminApps ,
@ GNUSTEP_TARGET _NETWORK _ADMIN _APPS ) ;
ASSIGN_DEFAULT _PATH ( gnustepNetworkWebApps ,
@ GNUSTEP_TARGET _NETWORK _WEB _APPS ) ;
ASSIGN_DEFAULT _PATH ( gnustepNetworkTools ,
@ GNUSTEP_TARGET _NETWORK _TOOLS ) ;
ASSIGN_DEFAULT _PATH ( gnustepNetworkAdminTools ,
@ GNUSTEP_TARGET _NETWORK _ADMIN _TOOLS ) ;
ASSIGN_DEFAULT _PATH ( gnustepNetworkLibrary ,
@ GNUSTEP_TARGET _NETWORK _LIBRARY ) ;
ASSIGN_DEFAULT _PATH ( gnustepNetworkLibraries ,
@ GNUSTEP_TARGET _NETWORK _LIBRARIES ) ;
ASSIGN_DEFAULT _PATH ( gnustepNetworkHeaders ,
@ GNUSTEP_TARGET _NETWORK _HEADERS ) ;
ASSIGN_DEFAULT _PATH ( gnustepNetworkDocumentation ,
@ GNUSTEP_TARGET _NETWORK _DOC ) ;
ASSIGN_DEFAULT _PATH ( gnustepNetworkDocumentationMan ,
@ GNUSTEP_TARGET _NETWORK _DOC _MAN ) ;
ASSIGN_DEFAULT _PATH ( gnustepNetworkDocumentationInfo ,
@ GNUSTEP_TARGET _NETWORK _DOC _INFO ) ;
ASSIGN_DEFAULT _PATH ( gnustepLocalApps ,
@ GNUSTEP_TARGET _LOCAL _APPS ) ;
ASSIGN_DEFAULT _PATH ( gnustepLocalAdminApps ,
@ GNUSTEP_TARGET _LOCAL _ADMIN _APPS ) ;
ASSIGN_DEFAULT _PATH ( gnustepLocalWebApps ,
@ GNUSTEP_TARGET _LOCAL _WEB _APPS ) ;
ASSIGN_DEFAULT _PATH ( gnustepLocalTools ,
@ GNUSTEP_TARGET _LOCAL _TOOLS ) ;
ASSIGN_DEFAULT _PATH ( gnustepLocalAdminTools ,
@ GNUSTEP_TARGET _LOCAL _ADMIN _TOOLS ) ;
ASSIGN_DEFAULT _PATH ( gnustepLocalLibrary ,
@ GNUSTEP_TARGET _LOCAL _LIBRARY ) ;
ASSIGN_DEFAULT _PATH ( gnustepLocalLibraries ,
@ GNUSTEP_TARGET _LOCAL _LIBRARIES ) ;
ASSIGN_DEFAULT _PATH ( gnustepLocalHeaders ,
@ GNUSTEP_TARGET _LOCAL _HEADERS ) ;
ASSIGN_DEFAULT _PATH ( gnustepLocalDocumentation ,
@ GNUSTEP_TARGET _LOCAL _DOC ) ;
ASSIGN_DEFAULT _PATH ( gnustepLocalDocumentationMan ,
@ GNUSTEP_TARGET _LOCAL _DOC _MAN ) ;
ASSIGN_DEFAULT _PATH ( gnustepLocalDocumentationInfo ,
@ GNUSTEP_TARGET _LOCAL _DOC _INFO ) ;
ASSIGN_DEFAULT _PATH ( gnustepMakefiles ,
@ GNUSTEP_TARGET _MAKEFILES ) ;
ASSIGN_DEFAULT _PATH ( gnustepSystemUsersDir ,
@ GNUSTEP_TARGET _SYSTEM _USERS _DIR ) ;
ASSIGN_DEFAULT _PATH ( gnustepNetworkUsersDir ,
@ GNUSTEP_TARGET _NETWORK _USERS _DIR ) ;
ASSIGN_DEFAULT _PATH ( gnustepLocalUsersDir ,
@ GNUSTEP_TARGET _LOCAL _USERS _DIR ) ;
2005-10-15 07:19:11 +00:00
}
2011-01-21 15:19:40 +00:00
static void
addDefaults ( NSString * defs , NSMutableDictionary * conf )
{
if ( [ MGR ( ) isReadableFileAtPath : defs ] = = YES )
{
NSDictionary * d ;
NSDictionary * attributes ;
attributes = [ MGR ( ) fileAttributesAtPath : defs
traverseLink : YES ] ;
if ( ( [ attributes filePosixPermissions ]
& ( 0022 & ATTRMASK ) ) ! = 0 )
{
# if defined ( __MINGW __ )
fprintf ( stderr ,
2011-10-20 07:09:57 +00:00
"\nThe file '%S' is writable by someone other than"
2011-01-21 15:19:40 +00:00
" its owner (permissions 0%lo).\nIgnoring it.\n" ,
[ defs fileSystemRepresentation ] ,
( long ) [ attributes filePosixPermissions ] ) ;
# else
fprintf ( stderr ,
2011-10-20 07:09:57 +00:00
"\nThe file '%s' is writable by someone other than"
2011-01-21 15:19:40 +00:00
" its owner (permissions 0%lo).\nIgnoring it.\n" ,
[ defs fileSystemRepresentation ] ,
( long ) [ attributes filePosixPermissions ] ) ;
# endif
d = nil ;
}
else
{
2011-10-19 21:38:52 +00:00
NSString * s ;
2011-10-20 07:09:57 +00:00
/ * Here we load the string and convert to a property list
* rather than using higher - level methods likely to raise
* an exception or otherwise use the NSUserDefaults
* system and cause recursion on error .
* /
2011-10-19 21:38:52 +00:00
s = [ [ NSString allocWithZone : NSDefaultMallocZone ( ) ]
initWithContentsOfFile : defs ] ;
if ( nil = = s )
{
d = nil ;
}
else
{
NS_DURING
{
d = [ s propertyList ] ;
2011-10-20 07:09:57 +00:00
if ( NO = = [ d isKindOfClass : [ NSDictionary class ] ] )
{
d = nil ;
}
2011-10-19 21:38:52 +00:00
}
NS_HANDLER
{
d = nil ;
}
NS_ENDHANDLER
RELEASE ( s ) ;
}
if ( nil = = d )
{
# if defined ( __MINGW __ )
fprintf ( stderr ,
2011-10-20 07:09:57 +00:00
"\nThe file '%S' is not parseable as a property list"
" containing a dictionary.\nIgnoring it.\n" ,
2011-10-19 21:38:52 +00:00
[ defs fileSystemRepresentation ] ) ;
# else
fprintf ( stderr ,
2011-10-20 07:09:57 +00:00
"\nThe file '%s' is not parseable as a property list"
" containing a dictionary.\nIgnoring it.\n" ,
2011-10-19 21:38:52 +00:00
[ defs fileSystemRepresentation ] ) ;
# endif
}
2011-01-21 15:19:40 +00:00
}
if ( d ! = nil )
{
NSEnumerator * enumerator ;
NSString * key ;
id extra ;
extra = [ conf objectForKey : @ "GNUSTEP_EXTRA" ] ;
if ( [ extra isKindOfClass : [ NSString class ] ] )
{
extra = [ extra componentsSeparatedByString : @ "," ] ;
}
extra = [ extra mutableCopy ] ;
if ( extra = = nil )
{
extra = [ NSMutableArray new ] ;
}
enumerator = [ d keyEnumerator ] ;
while ( ( key = [ enumerator nextObject ] ) ! = nil )
{
if ( [ conf objectForKey : key ] = = nil )
{
[ extra addObject : key ] ;
}
else
{
fprintf ( stderr , "Value for key '%s' in '%s' replaces"
" earlier setting.\n" , [ key UTF8String ] , [ defs UTF8String ] ) ;
}
}
[ conf addEntriesFromDictionary : d ] ;
if ( [ extra count ] > 0 )
{
NSArray * c = [ extra copy ] ;
[ conf setObject : c forKey : @ "GNUSTEP_EXTRA" ] ;
RELEASE ( c ) ;
}
RELEASE ( extra ) ;
}
}
}
2006-02-19 21:49:21 +00:00
NSMutableDictionary *
2005-11-22 20:01:57 +00:00
GNUstepConfig ( NSDictionary * newConfig )
2005-10-15 07:19:11 +00:00
{
static NSDictionary * config = nil ;
2013-08-22 15:44:54 +00:00
static BOOL beenHere = NO ;
2005-11-16 11:44:44 +00:00
NSMutableDictionary * conf = nil ;
BOOL changedSystemConfig = NO ;
2005-03-17 14:48:32 +00:00
2005-11-16 11:44:44 +00:00
[ gnustep_global _lock lock ] ;
2013-08-22 15:44:54 +00:00
if ( NO = = beenHere )
{
beenHere = YES ;
[ [ NSObject leakAt : & config ] release ] ;
}
2005-11-16 11:44:44 +00:00
if ( config = = nil || ( newConfig ! = nil && [ config isEqual : newConfig ] = = NO ) )
2005-10-15 07:19:11 +00:00
{
2005-11-16 11:44:44 +00:00
NS_DURING
2005-03-17 14:48:32 +00:00
{
2005-11-16 11:44:44 +00:00
if ( newConfig = = nil )
2005-03-17 14:48:32 +00:00
{
2011-10-19 13:32:50 +00:00
NSString * file = nil ;
NSString * path ;
NSEnumerator * e ;
NSString * defs ;
BOOL fromEnvironment = YES ;
BOOL bareDirectory = NO ;
2005-10-16 11:48:54 +00:00
2005-10-15 07:19:11 +00:00
conf = [ [ NSMutableDictionary alloc ] initWithCapacity : 32 ] ;
/ * Now we source the configuration file if it exists * /
2005-10-28 22:21:36 +00:00
# if ! OPTION_NO _ENVIRONMENT
2005-10-16 11:48:54 +00:00
file = [ [ [ NSProcessInfo processInfo ] environment ]
2005-10-15 07:19:11 +00:00
objectForKey : @ "GNUSTEP_CONFIG_FILE" ] ;
# endif
2005-10-16 11:48:54 +00:00
if ( file = = nil )
2005-10-12 06:15:15 +00:00
{
2005-12-01 09:33:22 +00:00
fromEnvironment = NO ;
2006-01-08 12:59:11 +00:00
file = @ GNUSTEP_TARGET _CONFIG _FILE ;
2005-10-12 06:15:15 +00:00
}
2005-12-05 14:43:46 +00:00
/ *
* Is the file missing from the path . . . if so we won ' t
* be reading it .
* /
if ( [ file hasSuffix : @ "/" ] || [ file hasSuffix : @ "\\" ] )
{
bareDirectory = YES ;
}
2005-10-16 14:20:14 +00:00
/ *
* Special case . . . if the config file location begins ' . / '
2008-01-10 11:14:30 +00:00
* or ' . . / ' then we determine it ' s actual path by working
* relative to the gnustep - base library .
2005-10-16 14:20:14 +00:00
* /
2008-01-10 11:14:30 +00:00
if ( [ file hasPrefix : @ "./" ] = = YES
|| [ file hasPrefix : @ "../" ] = = YES )
2005-10-16 14:20:14 +00:00
{
2005-10-16 15:24:51 +00:00
Class c = [ NSProcessInfo class ] ;
2005-10-16 15:07:10 +00:00
2011-10-19 13:32:50 +00:00
path = GSPrivateSymbolPath ( c , 0 ) ;
2005-10-16 15:24:51 +00:00
// Remove library name from path
path = [ path stringByDeletingLastPathComponent ] ;
2008-01-10 11:14:30 +00:00
if ( [ file hasPrefix : @ "./" ] = = YES )
{
file = [ file substringFromIndex : 2 ] ;
}
2005-10-16 15:24:51 +00:00
// Join the two together
file = [ path stringByAppendingPathComponent : file ] ;
2005-10-16 14:20:14 +00:00
}
2005-12-05 13:08:10 +00:00
file = [ file stringByStandardizingPath ] ;
2005-12-01 09:33:22 +00:00
if ( [ file isAbsolutePath ] = = NO )
{
if ( fromEnvironment = = YES )
{
NSLog ( @ "GNUSTEP_CONFIG_FILE value ('%@') is not "
@ "an absolute path. Please fix the environment "
@ "variable." , file ) ;
}
else
{
NSLog ( @ "GNUSTEP_CONFIG_FILE value ('%@') is not "
@ "an absolute path. Please rebuild GNUstep-base "
@ "specifying a valid path to the config file." , file ) ;
}
# if defined ( __MINGW32 _ )
if ( [ file length ] > 2 )
{
unichar buf [ 3 ] ;
[ file getCharacters : buf range : NSMakeRange ( 0 , 3 ) ] ;
if ( ( buf [ 0 ] = = ' / ' || bug [ 0 ] = = ' \ \ ' ) && isalpha ( buf [ 1 ] )
&& ( buf [ 2 ] = = ' / ' || bug [ 2 ] = = ' \ \ ' ) )
{
file = [ NSString stringWithFormat : @ "%c:%@" ,
( char ) buf [ 1 ] , [ file substringFromindex : 2 ] ] ;
file = [ file stringByReplacingString : @ "/"
withString : @ "\\" ] ;
NSLog ( @ "I am guessing that you meant '%@'" , file ) ;
}
}
# endif
}
2011-10-19 13:32:50 +00:00
2005-12-05 14:43:46 +00:00
if ( bareDirectory = = YES )
{
2011-10-19 13:32:50 +00:00
/ * Set the directory name , but don ' t try to read file .
* /
2005-12-05 14:43:46 +00:00
gnustepConfigPath = RETAIN ( file ) ;
}
else
{
gnustepConfigPath
= RETAIN ( [ file stringByDeletingLastPathComponent ] ) ;
2006-02-17 06:31:04 +00:00
ParseConfigurationFile ( file , conf , nil ) ;
2011-01-21 15:19:40 +00:00
if ( nil ! = [ conf objectForKey : @ "GNUSTEP_EXTRA" ] )
{
NSLog ( @ "Warning: use of GNUSTEP_EXTRA in your GNUstep.conf file is deprecated. Please use a GlobalDefaults.plist instead.\n" ) ;
}
2011-10-19 13:32:50 +00:00
}
2014-01-12 15:19:39 +00:00
/ * Merge in any values from property lists in the
2011-10-19 13:32:50 +00:00
* GlobalDefaults directory .
* /
path = [ gnustepConfigPath stringByAppendingPathComponent :
@ "GlobalDefaults" ] ;
e = [ [ MGR ( ) directoryContentsAtPath : path ] objectEnumerator ] ;
while ( ( defs = [ e nextObject ] ) ! = nil )
{
if ( [ [ defs pathExtension ] isEqualToString : @ "plist" ] )
2011-01-21 15:19:40 +00:00
{
2011-10-19 13:32:50 +00:00
defs = [ path stringByAppendingPathComponent : defs ] ;
addDefaults ( defs , conf ) ;
2011-01-21 15:19:40 +00:00
}
2005-12-05 14:43:46 +00:00
}
2011-10-19 13:32:50 +00:00
/ * And merge in value from GlobalDefaults . plist
* /
defs = [ gnustepConfigPath stringByAppendingPathComponent :
@ "GlobalDefaults.plist" ] ;
addDefaults ( defs , conf ) ;
2005-11-16 11:44:44 +00:00
}
else
{
conf = [ newConfig mutableCopy ] ;
}
/ * System admins may force the user and defaults paths by
* setting GNUSTEP_USER _CONFIG _FILE to be an empty string .
* If they simply don ' t define it at all , we assign a default .
* /
if ( [ conf objectForKey : @ "GNUSTEP_USER_CONFIG_FILE" ] = = nil )
{
2006-01-08 12:59:11 +00:00
[ conf setObject : @ GNUSTEP_TARGET _USER _CONFIG _FILE
forKey : @ "GNUSTEP_USER_CONFIG_FILE" ] ;
2005-10-15 07:19:11 +00:00
}
2005-11-16 11:44:44 +00:00
if ( config ! = nil )
2005-10-15 07:19:11 +00:00
{
2005-11-16 11:44:44 +00:00
changedSystemConfig = YES ;
2005-03-17 14:48:32 +00:00
}
2005-11-16 11:44:44 +00:00
config = [ conf copy ] ;
DESTROY ( conf ) ;
2005-11-15 12:11:47 +00:00
}
2005-11-16 11:44:44 +00:00
NS_HANDLER
{
[ gnustep_global _lock unlock ] ;
config = nil ;
DESTROY ( conf ) ;
[ localException raise ] ;
}
NS_ENDHANDLER
2005-11-15 12:11:47 +00:00
}
2005-11-16 11:44:44 +00:00
[ gnustep_global _lock unlock ] ;
2005-11-15 12:11:47 +00:00
2005-11-16 11:44:44 +00:00
if ( changedSystemConfig = = YES )
{
/ *
* The main configuration was changed by passing in a dictionary to
* this function , so we need to reset the path utilities system to use
* any new values from the config .
* /
ShutdownPathUtilities ( ) ;
InitialisePathUtilities ( ) ;
}
2005-11-22 20:01:57 +00:00
return AUTORELEASE ( [ config mutableCopy ] ) ;
}
2006-02-19 21:49:21 +00:00
void
GNUstepUserConfig ( NSMutableDictionary * config , NSString * userName )
2005-11-22 20:01:57 +00:00
{
2005-11-16 11:44:44 +00:00
# ifdef HAVE_GETEUID
if ( userName ! = nil )
{
/ *
* A program which is running setuid cannot be trusted
* to pick up user specific config , so we clear the userName
* to force the system configuration to be returned rather
* than a per - user config .
* /
if ( getuid ( ) ! = geteuid ( ) )
{
userName = nil ;
}
}
# endif
2005-11-22 20:01:57 +00:00
if ( userName ! = nil )
2005-11-16 11:44:44 +00:00
{
NSString * file ;
NSString * home ;
2005-11-22 20:01:57 +00:00
NSString * path ;
2005-11-16 11:44:44 +00:00
2005-11-22 20:01:57 +00:00
file = RETAIN ( [ config objectForKey : @ "GNUSTEP_USER_CONFIG_FILE" ] ) ;
2005-12-05 14:43:46 +00:00
if ( [ file length ] > 0 )
{
home = NSHomeDirectoryForUser ( userName ) ;
path = [ home stringByAppendingPathComponent : file ] ;
2006-02-17 06:31:04 +00:00
ParseConfigurationFile ( path , config , userName ) ;
2005-12-05 14:43:46 +00:00
}
2005-11-16 11:44:44 +00:00
/ *
* We don ' t let the user config file override the GNUSTEP_USER _CONFIG _FILE
* variable . . . that would be silly / pointless .
* /
2005-11-22 20:01:57 +00:00
[ config setObject : file forKey : @ "GNUSTEP_USER_CONFIG_FILE" ] ;
2005-11-16 11:44:44 +00:00
RELEASE ( file ) ;
}
2005-03-15 04:24:26 +00:00
}
/ * Initialise all things required by this module * /
2005-03-17 15:27:52 +00:00
static void InitialisePathUtilities ( void )
2005-03-15 04:24:26 +00:00
{
2007-02-15 03:06:33 +00:00
if ( gnustepMakefiles ! = nil )
2005-03-15 04:24:26 +00:00
{
2005-10-12 08:40:48 +00:00
return ; // Protect from multiple calls
}
2005-10-12 07:03:18 +00:00
2005-10-12 08:40:48 +00:00
/ * Set up our root paths * /
NS_DURING
{
2005-11-16 11:44:44 +00:00
NSMutableDictionary * config ;
2013-08-22 15:44:54 +00:00
static BOOL beenHere = NO ;
2005-11-15 13:07:09 +00:00
2005-11-16 11:44:44 +00:00
[ gnustep_global _lock lock ] ;
2013-08-22 15:44:54 +00:00
if ( NO = = beenHere )
{
beenHere = YES ;
if ( YES = = [ NSObject shouldCleanUp ] )
{
// Get path utilities shutdown called at process exit .
[ GSPathUtilities class ] ;
}
}
2011-04-12 05:41:53 +00:00
ASSIGNCOPY ( uninstalled , [ [ [ NSProcessInfo processInfo ] environment ]
objectForKey : @ "GNUSTEP_UNINSTALLED_LIBRARY_DIRECTORY" ] ) ;
2010-07-19 08:34:29 +00:00
gnustepUserName = [ NSUserName ( ) copy ] ;
# if defined ( __MINGW __ )
{
2010-07-21 08:24:32 +00:00
union {
SID sid ;
char dummy [ 1024 ] ;
} s ;
LPTSTR str ;
2010-07-19 08:34:29 +00:00
unichar buf [ 1024 ] ;
2010-07-21 08:24:32 +00:00
unichar dom [ 1024 ] ;
2010-07-19 08:34:29 +00:00
SID_NAME _USE use ;
2010-07-21 08:24:32 +00:00
DWORD bsize = 1024 ;
DWORD ssize = 1024 ;
2010-07-19 08:34:29 +00:00
2010-07-21 08:24:32 +00:00
if ( GetUserNameW ( buf , & bsize ) = = 0 || buf [ 0 ] = = ' \ 0 ' )
2010-07-19 08:34:29 +00:00
{
[ NSException raise : NSInternalInconsistencyException
2010-07-21 08:24:32 +00:00
format : @ "Unable to determine current user name: %@" ,
[ NSError _last ] ] ;
2010-07-19 08:34:29 +00:00
}
2010-07-21 08:24:32 +00:00
bsize = 1024 ;
if ( LookupAccountNameW ( 0 , buf , & s . sid , & ssize , dom , & bsize , & use ) = = 0 )
2010-07-19 08:34:29 +00:00
{
[ NSException raise : NSInternalInconsistencyException
2010-07-21 08:24:32 +00:00
format : @ "Unable to determine current account: %@" ,
[ NSError _last ] ] ;
2010-07-19 08:34:29 +00:00
}
2010-07-21 08:24:32 +00:00
if ( ConvertSidToStringSid ( & s . sid , & str ) = = 0 )
2010-07-19 08:54:38 +00:00
{
[ NSException raise : NSInternalInconsistencyException
2010-07-21 08:24:32 +00:00
format : @ "Unable to get current user ID string: %@" ,
[ NSError _last ] ] ;
2010-07-19 08:54:38 +00:00
}
gnustepUserID = [ [ NSString alloc ] initWithUTF8String : str ] ;
2010-07-19 08:34:29 +00:00
}
# else
gnustepUserID = [ [ NSString alloc ] initWithFormat : @ "%ld" , ( long ) getuid ( ) ] ;
# endif
2005-11-22 20:01:57 +00:00
config = GNUstepConfig ( nil ) ;
2010-07-19 08:34:29 +00:00
GNUstepUserConfig ( config , gnustepUserName ) ;
gnustepUserHome = [ NSHomeDirectoryForUser ( gnustepUserName ) copy ] ;
2005-11-16 11:44:44 +00:00
ExtractValuesFromConfig ( config ) ;
2005-10-12 17:40:40 +00:00
2005-10-12 08:40:48 +00:00
[ gnustep_global _lock unlock ] ;
2005-03-15 04:24:26 +00:00
}
2005-10-12 08:40:48 +00:00
NS_HANDLER
{
/ * unlock then re - raise the exception * /
[ gnustep_global _lock unlock ] ;
[ localException raise ] ;
}
NS_ENDHANDLER
2005-03-15 04:24:26 +00:00
}
/ *
* Close down and release all things allocated .
* /
2005-03-17 15:27:52 +00:00
static void ShutdownPathUtilities ( void )
2005-03-15 04:24:26 +00:00
{
2005-10-15 07:19:11 +00:00
DESTROY ( gnustepUserHome ) ;
2010-07-19 08:34:29 +00:00
DESTROY ( gnustepUserID ) ;
DESTROY ( gnustepUserName ) ;
2005-10-15 07:19:11 +00:00
DESTROY ( gnustepUserDefaultsDir ) ;
2005-03-15 04:24:26 +00:00
2007-02-15 03:06:33 +00:00
DESTROY ( gnustepMakefiles ) ;
2007-03-06 14:03:49 +00:00
DESTROY ( gnustepSystemUsersDir ) ;
DESTROY ( gnustepNetworkUsersDir ) ;
DESTROY ( gnustepLocalUsersDir ) ;
2007-02-15 03:06:33 +00:00
DESTROY ( gnustepSystemApps ) ;
2007-02-16 20:53:29 +00:00
DESTROY ( gnustepSystemAdminApps ) ;
2007-03-05 17:58:02 +00:00
DESTROY ( gnustepSystemWebApps ) ;
2007-02-15 03:06:33 +00:00
DESTROY ( gnustepSystemTools ) ;
2007-02-16 20:53:29 +00:00
DESTROY ( gnustepSystemAdminTools ) ;
2007-02-15 03:06:33 +00:00
DESTROY ( gnustepSystemLibrary ) ;
DESTROY ( gnustepSystemLibraries ) ;
DESTROY ( gnustepSystemHeaders ) ;
DESTROY ( gnustepSystemDocumentation ) ;
DESTROY ( gnustepSystemDocumentationMan ) ;
DESTROY ( gnustepSystemDocumentationInfo ) ;
DESTROY ( gnustepNetworkApps ) ;
2007-02-16 20:53:29 +00:00
DESTROY ( gnustepNetworkAdminApps ) ;
2007-03-05 17:58:02 +00:00
DESTROY ( gnustepNetworkWebApps ) ;
2007-02-15 03:06:33 +00:00
DESTROY ( gnustepNetworkTools ) ;
2007-02-16 20:53:29 +00:00
DESTROY ( gnustepNetworkAdminTools ) ;
2007-02-15 03:06:33 +00:00
DESTROY ( gnustepNetworkLibrary ) ;
DESTROY ( gnustepNetworkLibraries ) ;
DESTROY ( gnustepNetworkHeaders ) ;
DESTROY ( gnustepNetworkDocumentation ) ;
DESTROY ( gnustepNetworkDocumentationMan ) ;
DESTROY ( gnustepNetworkDocumentationInfo ) ;
DESTROY ( gnustepLocalApps ) ;
2007-02-16 20:53:29 +00:00
DESTROY ( gnustepLocalAdminApps ) ;
2007-03-05 17:58:02 +00:00
DESTROY ( gnustepLocalWebApps ) ;
2007-02-15 03:06:33 +00:00
DESTROY ( gnustepLocalTools ) ;
2007-02-16 20:53:29 +00:00
DESTROY ( gnustepLocalAdminTools ) ;
2007-02-15 03:06:33 +00:00
DESTROY ( gnustepLocalLibrary ) ;
DESTROY ( gnustepLocalLibraries ) ;
DESTROY ( gnustepLocalHeaders ) ;
DESTROY ( gnustepLocalDocumentation ) ;
DESTROY ( gnustepLocalDocumentationMan ) ;
DESTROY ( gnustepLocalDocumentationInfo ) ;
DESTROY ( gnustepUserApps ) ;
2007-02-16 20:53:29 +00:00
DESTROY ( gnustepUserAdminApps ) ;
2007-03-05 17:58:02 +00:00
DESTROY ( gnustepUserWebApps ) ;
2007-02-15 03:06:33 +00:00
DESTROY ( gnustepUserTools ) ;
2007-02-16 20:53:29 +00:00
DESTROY ( gnustepUserAdminTools ) ;
2007-02-15 03:06:33 +00:00
DESTROY ( gnustepUserLibrary ) ;
DESTROY ( gnustepUserLibraries ) ;
DESTROY ( gnustepUserHeaders ) ;
DESTROY ( gnustepUserDocumentation ) ;
DESTROY ( gnustepUserDocumentationMan ) ;
DESTROY ( gnustepUserDocumentationInfo ) ;
2005-03-15 04:24:26 +00:00
2005-10-12 07:03:18 +00:00
DESTROY ( tempDir ) ;
2005-03-03 16:04:22 +00:00
}
/ * *
2005-03-15 04:24:26 +00:00
* Reads a file and expects it to be in basic unix "conf" style format with
2005-10-13 10:11:56 +00:00
* one key = value per line ( the format a unix shell can ' source ' in order
* to define shell variables ) . < br / >
2005-10-26 13:13:29 +00:00
* This attempts to mimic the escape sequence and quoting conventions of
* the standard bourne shell , so that a config file sourced by the make
* package will produce the same results as one parsed by this function . < br / >
* Keys , by convention , consiste of uppercase letters , digits ,
* and underscores , and must not begin with a digit . < br / >
* A value may be any quoted string ( or an unquoted string containing no
2005-10-14 10:51:50 +00:00
* white space ) . < br / >
2005-03-15 04:24:26 +00:00
* Lines beginning with a hash ' # ' are deemed comment lines and ignored . < br / >
2005-10-13 10:11:56 +00:00
* The backslash character may be used as an escape character anywhere
* in the file except within a singly quoted string
2005-10-26 13:13:29 +00:00
* ( where it is taken literally ) . < br / >
2005-10-14 10:51:50 +00:00
* A backslash followed immediately by a newline ( except in a singly
* quoted string ) is removed completely along with the newline . . . it
* thus serves to join lines so that they are treated as a single line . < br / >
2005-10-27 08:39:53 +00:00
* NB . Since ms - windows uses backslash characters in paths , it is a good
2005-10-13 10:11:56 +00:00
* idea to specify path values in the config file as singly quoted
2005-11-06 13:53:40 +00:00
* strings to avoid having to double all occurrences of the backslash . < br / >
2005-10-14 10:51:50 +00:00
* Returns a dictionary of the ( key , value ) pairs . < br / >
2005-12-05 14:43:46 +00:00
* If the file does not exist ,
* the function makes no changes to dict and returns NO .
2005-03-03 16:04:22 +00:00
* /
2005-10-15 07:19:11 +00:00
static BOOL
2006-02-17 06:31:04 +00:00
ParseConfigurationFile ( NSString * fileName , NSMutableDictionary * dict ,
NSString * userName )
2005-03-03 16:04:22 +00:00
{
2005-03-17 14:48:32 +00:00
NSDictionary * attributes ;
2005-03-15 04:24:26 +00:00
NSString * file ;
2005-10-14 10:51:50 +00:00
unsigned l ;
unichar * src ;
unichar * dst ;
unichar * end ;
unichar * spos ;
unichar * dpos ;
BOOL newLine = YES ;
2005-10-14 14:03:13 +00:00
BOOL wantKey = YES ;
BOOL wantVal = NO ;
2005-10-14 10:51:50 +00:00
NSString * key = nil ;
2005-03-15 04:24:26 +00:00
2005-03-17 14:48:32 +00:00
if ( [ MGR ( ) isReadableFileAtPath : fileName ] = = NO )
{
2005-10-15 07:19:11 +00:00
return NO ;
2005-03-17 14:48:32 +00:00
}
attributes = [ MGR ( ) fileAttributesAtPath : fileName traverseLink : YES ] ;
2006-02-17 06:31:04 +00:00
if ( userName ! = nil )
{
NSString * fileOwner = [ attributes fileOwnerAccountName ] ;
2014-01-12 15:19:39 +00:00
2006-02-17 06:31:04 +00:00
if ( [ userName isEqual : fileOwner ] = = NO )
{
2010-03-19 12:10:11 +00:00
# if defined ( __MINGW __ )
2006-02-17 06:31:04 +00:00
fprintf ( stderr , "The file '%S' is owned by '%s' but we expect it"
" to be the personal config file of '%s'.\nIgnoring it.\n" ,
[ fileName fileSystemRepresentation ] ,
[ fileOwner UTF8String ] , [ userName UTF8String ] ) ;
# else
fprintf ( stderr , "The file '%s' is owned by '%s' but we expect it"
" to be the personal config file of '%s'.\nIgnoring it.\n" ,
[ fileName fileSystemRepresentation ] ,
[ fileOwner UTF8String ] , [ userName UTF8String ] ) ;
# endif
return NO ;
}
}
2005-10-23 06:35:33 +00:00
if ( ( [ attributes filePosixPermissions ] & ( 0022 & ATTRMASK ) ) ! = 0 )
2005-03-17 14:48:32 +00:00
{
2010-03-19 12:10:11 +00:00
# if defined ( __MINGW __ )
2005-10-09 10:41:53 +00:00
fprintf ( stderr , "The file '%S' is writable by someone other than"
2005-10-23 06:35:33 +00:00
" its owner (permissions 0%lo).\nIgnoring it.\n" ,
2006-02-17 06:31:04 +00:00
[ fileName fileSystemRepresentation ] ,
2009-03-18 10:02:49 +00:00
( long ) [ attributes filePosixPermissions ] ) ;
2005-10-09 10:41:53 +00:00
# else
2005-03-17 14:48:32 +00:00
fprintf ( stderr , "The file '%s' is writable by someone other than"
2005-10-23 06:35:33 +00:00
" its owner (permissions 0%lo).\nIgnoring it.\n" ,
[ fileName fileSystemRepresentation ] ,
2009-02-23 20:42:32 +00:00
( long ) [ attributes filePosixPermissions ] ) ;
2005-10-09 10:41:53 +00:00
# endif
2005-10-15 07:19:11 +00:00
return NO ;
2005-03-17 14:48:32 +00:00
}
2005-03-15 04:24:26 +00:00
if ( dict = = nil )
{
2005-10-15 07:19:11 +00:00
[ NSException raise : NSInvalidArgumentException
format : @ "No destination dictionary supplied" ] ;
2005-03-15 04:24:26 +00:00
}
file = [ NSString stringWithContentsOfFile : fileName ] ;
2005-10-14 10:51:50 +00:00
l = [ file length ] ;
src = ( unichar * ) NSZoneMalloc ( NSDefaultMallocZone ( ) , sizeof ( unichar ) * l ) ;
spos = src ;
end = src + l ;
dst = ( unichar * ) NSZoneMalloc ( NSDefaultMallocZone ( ) , sizeof ( unichar ) * l ) ;
dpos = dst ;
[ file getCharacters : src ] ;
while ( spos < end )
2005-03-03 16:04:22 +00:00
{
2005-10-14 10:51:50 +00:00
/ *
* Step past any whitespace . . . including blank lines
* /
while ( spos < end )
2005-03-17 14:48:32 +00:00
{
2005-10-14 10:51:50 +00:00
if ( * spos = = ' \ \ ' )
2005-03-17 14:48:32 +00:00
{
2005-10-14 10:51:50 +00:00
spos + + ;
if ( spos >= end )
{
break ; // At end of file . . . odd but not fatal
}
}
if ( * spos > ' ' )
{
break ; // OK . . . found a non space character .
}
if ( * spos = = ' \ r ' || * spos = = ' \ n ' )
{
newLine = YES ;
}
spos + + ;
}
2005-03-17 14:48:32 +00:00
2005-10-14 10:51:50 +00:00
/ *
* Handle any comments . . hash on a new line .
* /
if ( newLine = = YES )
{
2005-10-14 14:03:13 +00:00
if ( wantVal = = YES )
2005-10-14 10:51:50 +00:00
{
/ *
* On a newline . . . so the last key had no value set .
2005-10-14 14:03:13 +00:00
* Put an empty value in the dictionary .
2005-10-14 10:51:50 +00:00
* /
[ dict setObject : @ "" forKey : key ] ;
DESTROY ( key ) ;
2005-10-14 14:03:13 +00:00
wantVal = NO ;
2005-10-14 10:51:50 +00:00
}
if ( spos < end && * spos = = ' # ' )
{
// Got a comment . . . ignore remainder of line .
while ( spos < end && * spos ! = ' \ n ' && * spos ! = ' \ r ' )
{
spos + + ;
}
continue ; // restart loop . . . skip space at start of line
}
newLine = NO ;
2005-10-14 14:03:13 +00:00
wantKey = YES ;
2005-10-14 10:51:50 +00:00
}
2005-03-17 14:48:32 +00:00
2006-01-12 11:09:02 +00:00
if ( spos >= end )
{
break ; // At end of file . . . odd but not fatal
}
2005-10-14 10:51:50 +00:00
if ( * spos = = ' = ' )
{
2005-10-14 14:03:13 +00:00
if ( wantKey = = NO )
2005-10-14 10:51:50 +00:00
{
2005-10-14 14:03:13 +00:00
wantVal = YES ;
2005-10-14 10:51:50 +00:00
}
spos + + ;
}
else if ( * spos = = ' \ ' ' )
{
spos + + ;
while ( spos < end )
{
if ( * spos = = ' \ ' ' )
2005-10-13 10:11:56 +00:00
{
2005-10-14 10:51:50 +00:00
spos + + ;
break ;
}
* dpos + + = * spos + + ;
}
2005-10-14 14:03:13 +00:00
if ( wantVal = = YES )
2005-10-14 10:51:50 +00:00
{
2005-10-14 14:03:13 +00:00
NSString * val = [ NSString alloc ] ;
val = [ val initWithCharacters : dst length : dpos - dst ] ;
2005-10-16 15:07:10 +00:00
if ( val ! = nil )
{
[ dict setObject : val forKey : key ] ;
DESTROY ( key ) ;
DESTROY ( val ) ;
wantVal = NO ;
}
2005-10-14 10:51:50 +00:00
}
dpos = dst ; // reset output buffer
}
else if ( * spos = = ' " ' )
{
spos + + ;
while ( spos < end )
{
BOOL escaped = NO ;
2005-10-13 10:11:56 +00:00
2005-10-14 10:51:50 +00:00
if ( * spos = = ' \ \ ' )
{
spos + + ;
if ( spos >= end )
2005-10-13 10:11:56 +00:00
{
2005-10-14 10:51:50 +00:00
break ; // Unexpected end of file
}
if ( * spos = = ' \ n ' )
{
spos + + ;
continue ; // escaped newline is removed .
}
if ( * spos = = ' \ r ' )
{
spos + + ;
if ( spos < end && * spos = = ' \ n ' )
2005-10-13 10:11:56 +00:00
{
2005-10-14 10:51:50 +00:00
spos + + ;
2005-10-13 10:11:56 +00:00
}
2005-10-14 10:51:50 +00:00
continue ; // escaped newline is removed .
2005-10-13 10:11:56 +00:00
}
2005-10-14 10:51:50 +00:00
escaped = YES ;
}
if ( * spos = = ' " ' && escaped = = NO )
{
spos + + ;
break ;
}
* dpos + + = * spos + + ;
}
2005-10-14 14:03:13 +00:00
if ( wantVal = = YES )
2005-10-14 10:51:50 +00:00
{
2005-10-14 14:03:13 +00:00
NSString * val = [ NSString alloc ] ;
val = [ val initWithCharacters : dst length : dpos - dst ] ;
2005-10-16 15:07:10 +00:00
if ( val ! = nil )
{
[ dict setObject : val forKey : key ] ;
DESTROY ( key ) ;
DESTROY ( val ) ;
wantVal = NO ;
}
2005-10-14 10:51:50 +00:00
}
dpos = dst ; // reset output buffer
}
else
{
while ( spos < end )
{
if ( * spos = = ' \ \ ' )
{
spos + + ;
if ( spos >= end )
{
break ; // Unexpected end of file
}
if ( * spos = = ' \ n ' )
{
spos + + ;
continue ; // escaped newline is removed .
}
if ( * spos = = ' \ r ' )
2005-10-13 10:11:56 +00:00
{
2005-10-14 10:51:50 +00:00
spos + + ;
if ( spos < end && * spos = = ' \ n ' )
2005-10-13 10:11:56 +00:00
{
2005-10-14 10:51:50 +00:00
spos + + ;
2005-10-13 10:11:56 +00:00
}
2005-10-14 10:51:50 +00:00
continue ; // escaped newline is removed .
2005-10-13 10:11:56 +00:00
}
}
2005-10-26 13:13:29 +00:00
if ( isspace ( * spos ) || * spos = = ' = ' )
2005-10-12 08:40:48 +00:00
{
2005-10-14 10:51:50 +00:00
break ;
2005-10-12 08:40:48 +00:00
}
2005-10-14 10:51:50 +00:00
* dpos + + = * spos + + ;
2005-03-17 14:48:32 +00:00
}
2005-10-14 10:51:50 +00:00
2005-10-14 14:03:13 +00:00
if ( wantKey = = YES )
2005-03-17 14:48:32 +00:00
{
2005-10-14 14:03:13 +00:00
key = [ NSString alloc ] ;
key = [ key initWithCharacters : dst length : dpos - dst ] ;
2005-10-16 15:07:10 +00:00
if ( key ! = nil )
{
wantKey = NO ;
}
2005-10-14 14:03:13 +00:00
}
else if ( wantVal = = YES )
{
NSString * val = [ NSString alloc ] ;
val = [ val initWithCharacters : dst length : dpos - dst ] ;
2005-10-16 15:07:10 +00:00
if ( val ! = nil )
{
[ dict setObject : val forKey : key ] ;
DESTROY ( key ) ;
DESTROY ( val ) ;
wantVal = NO ;
}
2005-03-17 14:48:32 +00:00
}
2005-10-14 10:51:50 +00:00
dpos = dst ; // reset output buffer
2005-03-17 14:48:32 +00:00
}
2005-03-03 16:04:22 +00:00
}
2005-10-14 14:03:13 +00:00
if ( wantVal = = YES )
2005-10-14 10:51:50 +00:00
{
[ dict setObject : @ "" forKey : key ] ;
}
2011-02-10 12:11:03 +00:00
DESTROY ( key ) ;
2005-10-14 10:51:50 +00:00
NSZoneFree ( NSDefaultMallocZone ( ) , src ) ;
NSZoneFree ( NSDefaultMallocZone ( ) , dst ) ;
2005-10-15 07:19:11 +00:00
return YES ;
2005-03-15 04:24:26 +00:00
}
2005-10-17 05:44:18 +00:00
2005-03-15 04:24:26 +00:00
/ * See NSPathUtilities . h for description * /
void
GSSetUserName ( NSString * aName )
{
NSCParameterAssert ( [ aName length ] > 0 ) ;
2005-03-03 16:04:22 +00:00
/ *
2005-03-15 04:24:26 +00:00
* Do nothing if it ' s not a different user .
2005-03-03 16:04:22 +00:00
* /
2005-03-15 04:24:26 +00:00
if ( [ theUserName isEqualToString : aName ] )
{
return ;
}
/ *
* Release the memory
2005-03-15 06:36:21 +00:00
* /
2005-03-15 04:24:26 +00:00
[ gnustep_global _lock lock ] ;
ShutdownPathUtilities ( ) ;
2005-03-15 06:36:21 +00:00
2005-03-03 16:04:22 +00:00
/ *
2005-03-15 04:24:26 +00:00
* Reset things as new user
2005-03-03 16:04:22 +00:00
* /
2005-03-15 04:24:26 +00:00
ASSIGN ( theUserName , aName ) ;
2006-09-26 11:16:06 +00:00
DESTROY ( theFullUserName ) ;
2005-03-15 04:24:26 +00:00
InitialisePathUtilities ( ) ;
2005-03-03 16:04:22 +00:00
[ NSUserDefaults resetStandardUserDefaults ] ;
2005-03-15 04:24:26 +00:00
[ gnustep_global _lock unlock ] ;
2005-03-03 16:04:22 +00:00
}
/ * *
2005-03-15 04:24:26 +00:00
* Return the caller ' s login name as an NSString object . < br / >
2005-03-03 16:04:22 +00:00
* Under unix - like systems , the name associated with the current
2005-03-15 04:24:26 +00:00
* effective user ID is used . < br / >
2005-10-27 08:39:53 +00:00
* Under ms - windows , the ' LOGNAME ' environment is used , or if that fails , the
2006-09-26 11:16:06 +00:00
* GetUserName ( ) call is used to find the user name . < br / >
* Raises an exception on failure .
2005-03-03 16:04:22 +00:00
* /
/ * NOTE FOR DEVELOPERS .
* If you change the behavior of this method you must also change
* user_home . c in the makefiles package to match .
* /
NSString *
NSUserName ( void )
{
2010-03-19 12:10:11 +00:00
# if defined ( __MINGW __ )
2005-03-03 16:04:22 +00:00
if ( theUserName = = nil )
{
2005-11-16 11:44:44 +00:00
/ * Use the LOGNAME environment variable if set . * /
theUserName = [ [ [ NSProcessInfo processInfo ] environment ]
objectForKey : @ "LOGNAME" ] ;
if ( [ theUserName length ] > 0 )
{
RETAIN ( theUserName ) ;
}
2005-03-03 16:04:22 +00:00
else
2005-11-16 11:44:44 +00:00
{
/ * The GetUserName function returns the current user name * /
unichar buf [ 1024 ] ;
DWORD n = 1024 ;
if ( GetUserNameW ( buf , & n ) ! = 0 && buf [ 0 ] ! = ' \ 0 ' )
{
theUserName = [ [ NSString alloc ] initWithCharacters : buf
length : wcslen ( buf ) ] ;
}
else
{
theUserName = nil ;
[ NSException raise : NSInternalInconsistencyException
format : @ "Unable to determine current user name" ] ;
}
}
2005-03-03 16:04:22 +00:00
}
# else
/ * Set olduid to some invalid uid that we could never start off running
as . * /
static int olduid = -1 ;
# ifdef HAVE_GETEUID
int uid = geteuid ( ) ;
# else
int uid = getuid ( ) ;
# endif / * HAVE_GETEUID * /
if ( theUserName = = nil || uid ! = olduid )
{
const char * loginName = 0 ;
2008-02-20 09:22:43 +00:00
char buf [ BUFSIZ * 10 ] ;
2007-12-19 14:39:44 +00:00
# if defined ( HAVE_GETPWUID _R )
struct passwd pwent ;
2007-12-19 14:54:00 +00:00
struct passwd * p ;
2007-12-19 14:39:44 +00:00
2007-12-19 14:54:00 +00:00
if ( getpwuid_r ( uid , & pwent , buf , sizeof ( buf ) , & p ) = = 0 )
2007-12-19 14:39:44 +00:00
{
loginName = pwent . pw_name ;
}
# else
# if defined ( HAVE_GETPWUID )
2008-02-20 09:22:43 +00:00
struct passwd * pwent ;
[ gnustep_global _lock lock ] ;
pwent = getpwuid ( uid ) ;
2011-03-07 11:34:17 +00:00
strncpy ( buf , pwent -> pw_name , sizeof ( buf ) - 1 ) ;
buf [ sizeof ( buf ) - 1 ] = ' \ 0 ' ;
2008-02-20 09:22:43 +00:00
[ gnustep_global _lock unlock ] ;
loginName = buf ;
2005-03-03 16:04:22 +00:00
# endif / * HAVE_GETPWUID * /
2007-12-19 14:39:44 +00:00
# endif / * HAVE_GETPWUID _R * /
2005-03-03 16:04:22 +00:00
olduid = uid ;
if ( loginName )
theUserName = [ [ NSString alloc ] initWithCString : loginName ] ;
else
[ NSException raise : NSInternalInconsistencyException
format : @ "Unable to determine current user name" ] ;
}
# endif
return theUserName ;
}
2005-03-15 04:24:26 +00:00
2005-03-03 16:04:22 +00:00
/ * *
* Return the caller ' s home directory as an NSString object .
* Calls NSHomeDirectoryForUser ( ) to do this .
* /
NSString *
NSHomeDirectory ( void )
{
return NSHomeDirectoryForUser ( NSUserName ( ) ) ;
}
/ * *
2011-04-13 14:30:20 +00:00
* Returns loginName ' s home directory as an NSString object . < br / >
* On most systems this returns the directory specified in the system ' s
2011-04-13 14:34:39 +00:00
* password file ( ar at least whatever is returned by the standard
* operating system API for retrieving password file records ) ,
* but on ms - windows this is determined by examining the
2011-04-13 14:30:20 +00:00
* HOMEPATH and HOMEDRIVE environment variables or ( if those don ' t make
* sense ) the USERPROFILE environment variable .
2005-03-03 16:04:22 +00:00
* /
/ * NOTE FOR DEVELOPERS .
* If you change the behavior of this method you must also change
* user_home . c in the makefiles package to match .
* /
NSString *
NSHomeDirectoryForUser ( NSString * loginName )
{
NSString * s = nil ;
2010-03-19 12:10:11 +00:00
# if ! defined ( __MINGW __ )
2007-12-19 14:39:44 +00:00
# if defined ( HAVE_GETPWNAM _R )
struct passwd pw ;
2007-12-19 14:54:00 +00:00
struct passwd * p ;
2007-12-19 14:39:44 +00:00
char buf [ BUFSIZ * 10 ] ;
2007-12-19 14:54:00 +00:00
if ( getpwnam_r ( [ loginName cString ] , & pw , buf , sizeof ( buf ) , & p ) = = 0
2007-12-19 14:39:44 +00:00
&& pw . pw_dir ! = 0 )
{
s = [ NSString stringWithUTF8String : pw . pw_dir ] ;
}
# else
# if defined ( HAVE_GETPWNAM )
2005-10-17 05:44:18 +00:00
struct passwd * pw ;
2005-10-15 07:19:11 +00:00
2005-10-17 05:44:18 +00:00
[ gnustep_global _lock lock ] ;
pw = getpwnam ( [ loginName cString ] ) ;
if ( pw ! = 0 && pw -> pw_dir ! = NULL )
{
2006-10-09 14:00:01 +00:00
s = [ NSString stringWithUTF8String : pw -> pw_dir ] ;
2005-10-17 05:44:18 +00:00
}
[ gnustep_global _lock unlock ] ;
2007-12-19 14:39:44 +00:00
# endif
# endif
2005-03-03 16:04:22 +00:00
# else
2005-11-07 07:46:44 +00:00
if ( [ loginName isEqual : NSUserName ( ) ] = = YES )
{
NSDictionary * e = [ [ NSProcessInfo processInfo ] environment ] ;
/ *
* The environment variable HOMEPATH holds the home directory
* for the user on Windows NT ;
* For OPENSTEP compatibility ( and because USERPROFILE is usually
* unusable because it contains spaces ) , we use HOMEPATH in
2010-04-07 20:45:17 +00:00
* preference to USERPROFILE , except when MINGW has set HOMEPATH to ' \ '
* which isn ' t very useful , so we prefer USERPROFILE in that case .
2005-11-07 07:46:44 +00:00
* /
s = [ e objectForKey : @ "HOMEPATH" ] ;
2010-04-07 20:45:17 +00:00
if ( [ s isEqualToString : @ "\\" ] && [ e objectForKey : @ "USERPROFILE" ] ! = nil )
{
s = [ e objectForKey : @ "USERPROFILE" ] ;
}
else if ( s ! = nil && ( [ s length ] < 2 || [ s characterAtIndex : 1 ] ! = ' : ' ) )
2005-11-07 07:46:44 +00:00
{
s = [ [ e objectForKey : @ "HOMEDRIVE" ] stringByAppendingString : s ] ;
}
if ( s = = nil )
{
s = [ e objectForKey : @ "USERPROFILE" ] ;
}
if ( s = = nil )
{
; // FIXME : Talk to the NET API and get the profile path
}
}
else
{
s = nil ;
NSLog ( @ "Trying to get home for '%@' when user is '%@'" ,
2014-01-12 15:19:39 +00:00
loginName , NSUserName ( ) ) ;
NSLog ( @ "Can't determine other user home directories in Win32." ) ;
2005-11-07 07:46:44 +00:00
}
2014-01-12 15:19:39 +00:00
2005-11-07 07:46:44 +00:00
if ( [ s length ] = = 0 && [ loginName length ] ! = 1 )
{
s = nil ;
NSLog ( @ "NSHomeDirectoryForUser(%@) failed" , loginName ) ;
}
2005-03-03 16:04:22 +00:00
# endif
return s ;
}
NSString *
NSFullUserName ( void )
{
2006-09-26 11:16:06 +00:00
if ( theFullUserName = = nil )
{
2011-02-13 18:54:53 +00:00
NSString * userName = NSUserName ( ) ;
2010-03-19 12:10:11 +00:00
# if defined ( __MINGW __ )
2006-09-26 11:16:06 +00:00
struct _USER _INFO _2 * userInfo ;
2011-02-13 18:54:53 +00:00
if ( NetUserGetInfo ( NULL , ( unichar * ) [ userName cStringUsingEncoding :
2006-09-26 11:50:11 +00:00
NSUnicodeStringEncoding ] , 2 , ( LPBYTE * ) & userInfo ) = = 0 )
2006-09-26 11:16:06 +00:00
{
2011-02-13 18:54:53 +00:00
int length = wcslen ( userInfo -> usri2_full _name ) ;
if ( length > 0 )
{
userName = [ NSString
stringWithCharacters : userInfo -> usri2_full _name
length : length ] ;
}
2006-09-26 11:16:06 +00:00
}
2005-03-15 04:24:26 +00:00
# else
# ifdef HAVE_PWD _H
2007-12-19 14:39:44 +00:00
# if defined ( HAVE_GETPWNAM _R )
2013-03-16 05:25:49 +00:00
# if defined ( HAVE_PW _GECOS _IN _PASSWD )
2007-12-19 14:39:44 +00:00
struct passwd pw ;
2007-12-19 14:54:00 +00:00
struct passwd * p ;
2007-12-19 14:39:44 +00:00
char buf [ BUFSIZ * 10 ] ;
2011-02-13 18:54:53 +00:00
if ( getpwnam_r ( [ userName cString ] , & pw , buf , sizeof ( buf ) , & p ) = = 0 )
2007-12-19 14:39:44 +00:00
{
2011-02-13 18:54:53 +00:00
if ( * pw . pw_gecos )
{
userName = [ NSString stringWithUTF8String : pw . pw_gecos ] ;
}
2007-12-19 14:39:44 +00:00
}
2013-03-16 05:25:49 +00:00
# endif / * HAVE_PW _GECOS _IN _PASSWD * /
2007-12-19 14:39:44 +00:00
# else
# if defined ( HAVE_GETPWNAM )
2013-03-16 05:25:49 +00:00
# if defined ( HAVE_PW _GECOS _IN _PASSWD )
2006-09-26 11:16:06 +00:00
struct passwd * pw ;
2005-03-03 16:04:22 +00:00
2007-12-19 14:39:44 +00:00
[ gnustep_global _lock lock ] ;
2011-02-13 18:54:53 +00:00
pw = getpwnam ( [ userName cString ] ) ;
2011-03-28 08:50:45 +00:00
if ( pw -> pw_gecos )
2011-02-13 18:54:53 +00:00
{
userName = [ NSString stringWithUTF8String : pw -> pw_gecos ] ;
}
2007-12-19 14:39:44 +00:00
[ gnustep_global _lock lock ] ;
2013-03-16 05:25:49 +00:00
# endif / * HAVE_PW _GECOS _IN _PASSWD * /
2007-12-19 14:39:44 +00:00
# endif / * HAVE_GETPWNAM * /
# endif / * HAVE_GETPWNAM _R * /
2005-03-15 04:24:26 +00:00
# endif / * HAVE_PWD _H * /
# endif / * defined ( __Win32 __ ) else * /
2006-09-26 11:16:06 +00:00
ASSIGN ( theFullUserName , userName ) ;
}
return theFullUserName ;
2005-03-03 16:04:22 +00:00
}
/ * *
2005-03-15 04:24:26 +00:00
* Return the path of the defaults directory for userName . < br / >
2007-03-01 13:43:23 +00:00
* This examines the GNUSTEP_USER _CONFIG _FILE for the specified user ,
* with settings in it over - riding those in the main GNUstep . conf .
2005-03-03 16:04:22 +00:00
* /
2005-03-15 04:24:26 +00:00
NSString *
2005-03-03 16:04:22 +00:00
GSDefaultsRootForUser ( NSString * userName )
{
2005-10-19 05:52:48 +00:00
NSString * defaultsDir ;
2005-03-03 16:04:22 +00:00
2005-10-17 05:44:18 +00:00
InitialisePathUtilities ( ) ;
2005-03-17 15:27:52 +00:00
if ( [ userName length ] = = 0 )
{
userName = NSUserName ( ) ;
}
2005-03-15 04:24:26 +00:00
if ( [ userName isEqual : NSUserName ( ) ] )
2005-03-03 16:04:22 +00:00
{
2005-10-15 07:19:11 +00:00
defaultsDir = gnustepUserDefaultsDir ;
2005-03-03 16:04:22 +00:00
}
else
{
2005-11-22 20:01:57 +00:00
NSMutableDictionary * config ;
2005-03-03 16:04:22 +00:00
2005-11-22 20:01:57 +00:00
config = GNUstepConfig ( nil ) ;
2006-02-19 21:49:21 +00:00
GNUstepUserConfig ( config , userName ) ;
2005-10-15 07:19:11 +00:00
defaultsDir = [ config objectForKey : @ "GNUSTEP_USER_DEFAULTS_DIR" ] ;
2005-10-19 05:52:48 +00:00
if ( defaultsDir = = nil )
{
2005-10-27 12:00:38 +00:00
defaultsDir = @ GNUSTEP_TARGET _USER _DEFAULTS _DIR ;
2005-10-19 05:52:48 +00:00
}
2005-03-15 04:24:26 +00:00
}
2010-03-19 12:10:11 +00:00
# if defined ( __MINGW __ )
2005-11-06 06:51:28 +00:00
if ( [ defaultsDir rangeOfString : @ ":REGISTRY:" ] . length > 0 )
{
return defaultsDir ; // Just use windows registry .
}
# endif
2013-03-16 15:34:59 +00:00
if ( NO = = [ defaultsDir isAbsolutePath ] )
{
NSString * home = NSHomeDirectoryForUser ( userName ) ;
defaultsDir = [ home stringByAppendingPathComponent : defaultsDir ] ;
}
2005-03-15 06:36:21 +00:00
2013-03-16 15:34:59 +00:00
return defaultsDir ;
2005-03-03 16:04:22 +00:00
}
NSArray *
NSStandardApplicationPaths ( void )
{
return NSSearchPathForDirectoriesInDomains ( NSAllApplicationsDirectory ,
NSAllDomainsMask , YES ) ;
}
NSArray *
NSStandardLibraryPaths ( void )
{
return NSSearchPathForDirectoriesInDomains ( NSAllLibrariesDirectory ,
NSAllDomainsMask , YES ) ;
}
NSString *
NSTemporaryDirectory ( void )
{
NSFileManager * manager ;
NSString * tempDirName ;
NSString * baseTempDirName = nil ;
NSDictionary * attr ;
int perm ;
int owner ;
BOOL flag ;
2010-03-19 12:10:11 +00:00
# if ! defined ( __MINGW __ )
2005-03-03 16:04:22 +00:00
int uid ;
# else
2005-11-05 16:20:19 +00:00
unichar buffer [ 1024 ] ;
2005-03-03 16:04:22 +00:00
2005-11-05 16:20:19 +00:00
if ( GetTempPathW ( 1024 , buffer ) )
2005-03-03 16:04:22 +00:00
{
2005-11-05 16:20:19 +00:00
baseTempDirName = [ NSString stringWithCharacters : buffer
length : wcslen ( buffer ) ] ;
2005-03-03 16:04:22 +00:00
}
# endif
/ *
* If the user has supplied a directory name in the TEMP or TMP
* environment variable , attempt to use that unless we already
2005-04-12 17:01:30 +00:00
* have a temporary directory specified .
2005-03-03 16:04:22 +00:00
* /
if ( baseTempDirName = = nil )
{
NSDictionary * env = [ [ NSProcessInfo processInfo ] environment ] ;
baseTempDirName = [ env objectForKey : @ "TEMP" ] ;
if ( baseTempDirName = = nil )
{
baseTempDirName = [ env objectForKey : @ "TMP" ] ;
if ( baseTempDirName = = nil )
{
2006-02-22 09:30:55 +00:00
# if defined ( __CYGWIN __ )
2013-08-10 21:31:37 +00:00
# warning Basing temporary directory in / cygdrive / c ; any reason ?
2005-03-03 16:04:22 +00:00
baseTempDirName = @ "/cygdrive/c/" ;
2010-03-19 12:10:11 +00:00
# elif defined ( __MINGW __ )
2006-02-22 09:30:55 +00:00
baseTempDirName = @ "C:\\" ;
2008-11-14 21:59:13 +00:00
# elif defined ( __APPLE __ )
/ *
* Create temporary directory on / var / tmp since / tmp is
* cleaned regularly on Darwin by default
* /
baseTempDirName = @ "/var/tmp" ;
2005-03-03 16:04:22 +00:00
# else
baseTempDirName = @ "/tmp" ;
# endif
}
}
}
/ *
* Check that the base directory exists . . . if it doesn ' t we can ' t
* go any further .
* /
tempDirName = baseTempDirName ;
manager = [ NSFileManager defaultManager ] ;
if ( [ manager fileExistsAtPath : tempDirName isDirectory : & flag ] = = NO
|| flag = = NO )
{
2007-03-22 15:07:54 +00:00
NSWarnFLog ( @ "Temporary directory (%@) does not exist" , tempDirName ) ;
return nil ;
2005-03-03 16:04:22 +00:00
}
/ *
* Check that we are the directory owner , and that we , and nobody else ,
* have access to it . If other people have access , try to create a secure
* subdirectory .
* /
attr = [ manager fileAttributesAtPath : tempDirName traverseLink : YES ] ;
owner = [ [ attr objectForKey : NSFileOwnerAccountID ] intValue ] ;
perm = [ [ attr objectForKey : NSFilePosixPermissions ] intValue ] ;
perm = perm & 0777 ;
// Mateu Batle : secure temporary directories don ' t work in MinGW
2013-08-10 21:31:37 +00:00
// Ivan Vucica : there are also problems with Cygwin
// probable cause : http : // stackoverflow . com / q / 9561759 / 39974
# if ! defined ( __MINGW __ ) && ! defined ( __CYGWIN __ )
2005-03-03 16:04:22 +00:00
2010-03-19 12:10:11 +00:00
# if defined ( __MINGW __ )
2005-03-03 16:04:22 +00:00
uid = owner ;
# else
# ifdef HAVE_GETEUID
uid = geteuid ( ) ;
# else
uid = getuid ( ) ;
# endif / * HAVE_GETEUID * /
# endif
if ( ( perm ! = 0700 && perm ! = 0600 ) || owner ! = uid )
{
2005-04-12 17:01:30 +00:00
NSString * secure ;
2012-08-10 14:31:28 +00:00
NSNumber * p = [ NSNumber numberWithInt : 0700 ] ;
attr = [ NSDictionary dictionaryWithObject : p
forKey : NSFilePosixPermissions ] ;
2005-04-12 17:01:30 +00:00
/ *
* The name of the secure subdirectory reflects the user ID rather
* than the user name , since it is possible to have an account with
* lots of names on a unix system ( ie multiple entries in the password
* file but a single userid ) . The private directory is secure within
* the account , not to a particular user name .
* /
secure = [ NSString stringWithFormat : @ "GNUstepSecure%d" , uid ] ;
tempDirName
= [ baseTempDirName stringByAppendingPathComponent : secure ] ;
2007-03-22 15:07:54 +00:00
2005-03-03 16:04:22 +00:00
if ( [ manager fileExistsAtPath : tempDirName ] = = NO )
{
if ( [ manager createDirectoryAtPath : tempDirName
2012-08-10 08:36:09 +00:00
withIntermediateDirectories : YES
attributes : attr
error : NULL ] = = NO )
2005-03-03 16:04:22 +00:00
{
2007-03-22 15:07:54 +00:00
NSWarnFLog ( @ "Attempt to create a secure temporary"
@ " directory (%@) failed." , tempDirName ) ;
return nil ;
2005-03-03 16:04:22 +00:00
}
}
2012-08-10 14:31:28 +00:00
else
{
[ manager changeFileAttributes : attr atPath : tempDirName ] ;
}
2005-03-03 16:04:22 +00:00
/ *
* Check that the new directory is really secure .
* /
attr = [ manager fileAttributesAtPath : tempDirName traverseLink : YES ] ;
owner = [ [ attr objectForKey : NSFileOwnerAccountID ] intValue ] ;
perm = [ [ attr objectForKey : NSFilePosixPermissions ] intValue ] ;
perm = perm & 0777 ;
if ( ( perm ! = 0700 && perm ! = 0600 ) || owner ! = uid )
{
2007-03-22 15:07:54 +00:00
NSWarnFLog ( @ "Attempt to create a secure temporary"
@ " directory (%@) failed." , tempDirName ) ;
return nil ;
2005-03-03 16:04:22 +00:00
}
}
# endif
if ( [ manager isWritableFileAtPath : tempDirName ] = = NO )
{
2007-03-22 15:07:54 +00:00
NSWarnFLog ( @ "Temporary directory (%@) is not writable" , tempDirName ) ;
return nil ;
2005-03-03 16:04:22 +00:00
}
return tempDirName ;
}
NSString *
NSOpenStepRootDirectory ( void )
{
NSString * root ;
2005-11-13 08:02:26 +00:00
# if defined ( __CYGWIN __ )
2005-11-13 07:45:52 +00:00
root = @ "/cygdrive/c/" ;
2010-03-19 12:10:11 +00:00
# elif defined ( __MINGW __ )
2005-11-13 07:45:52 +00:00
root = @ "C:\\" ;
2005-03-03 16:04:22 +00:00
# else
2005-11-13 07:45:52 +00:00
root = @ "/" ;
2005-03-03 16:04:22 +00:00
# endif
return root ;
}
2014-01-12 15:19:39 +00:00
# if defined ( __MINGW __ )
/ * The developer root on a windows system ( where we have an msys environment
2014-01-13 16:32:12 +00:00
* set up ) is the point in the filesystem where we can reference bin / make . . .
* simple heuristic to let us find the native windows path to the msys root .
2014-01-12 15:19:39 +00:00
* /
static NSString *
devroot ( NSFileManager * manager , NSString * path )
{
NSString * tmp = @ "" ;
while ( NO = = [ tmp isEqual : path ] )
{
2014-01-13 16:32:12 +00:00
NSString * pb ;
2014-01-12 16:24:35 +00:00
2014-01-13 16:32:12 +00:00
pb = [ path stringByAppendingPathComponent : @ "bin/make.exe" ] ;
if ( [ manager isExecutableFileAtPath : pb ] )
2014-01-12 16:24:35 +00:00
{
2014-01-13 16:32:12 +00:00
return path ;
}
tmp = path ;
path = [ tmp stringByDeletingLastPathComponent ] ;
}
return nil ;
}
/ * Like devroot ( ) , but also checks for msys / version subdirectories
* as found inside the GNUstep windows package installations .
* /
static NSString *
idevroot ( NSFileManager * manager , NSString * path )
{
NSString * pb ;
NSString * tmp ;
NSString * msys ;
BOOL isDir ;
if ( nil ! = ( tmp = devroot ( manager , path ) ) )
{
return tmp ;
}
msys = [ path stringByAppendingPathComponent : @ "msys" ] ;
if ( YES = = [ manager fileExistsAtPath : msys isDirectory : & isDir ]
&& YES = = isDir )
{
NSEnumerator * e ;
NSString * best = nil ;
NSString * file ;
float maxVersion = 0.0 ;
2014-01-12 16:24:35 +00:00
2014-01-13 16:32:12 +00:00
e = [ [ manager directoryContentsAtPath : msys ] objectEnumerator ] ;
while ( nil ! = ( file = [ e nextObject ] ) )
{
if ( isdigit ( [ file characterAtIndex : 0 ] ) )
2014-01-12 16:24:35 +00:00
{
2014-01-13 16:32:12 +00:00
float v = atof ( [ file UTF8String ] ) ;
2014-01-12 16:24:35 +00:00
2014-01-13 16:32:12 +00:00
if ( v <= maxVersion )
{
continue ;
}
file = [ msys stringByAppendingPathComponent : file ] ;
pb = [ file stringByAppendingPathComponent : @ "bin/make.exe" ] ;
if ( [ manager isExecutableFileAtPath : pb ] )
{
best = file ;
2014-01-12 16:24:35 +00:00
}
}
}
2014-01-13 16:32:12 +00:00
if ( nil ! = best )
{
return [ best stringByStandardizingPath ] ;
}
2014-01-12 15:19:39 +00:00
}
return nil ;
}
# endif
2005-03-03 16:04:22 +00:00
NSArray *
2005-03-15 06:36:21 +00:00
NSSearchPathForDirectoriesInDomains ( NSSearchPathDirectory directoryKey ,
2005-03-03 16:04:22 +00:00
NSSearchPathDomainMask domainMask , BOOL expandTilde )
{
2011-11-14 10:01:24 +00:00
NSMutableArray * paths ;
2005-03-15 04:24:26 +00:00
NSString * path ;
unsigned i ;
unsigned count ;
2005-03-03 16:04:22 +00:00
2005-10-12 07:03:18 +00:00
InitialisePathUtilities ( ) ;
2007-02-15 03:06:33 +00:00
NSCAssert ( gnustepMakefiles ! = nil , @ "Path utilities without initialisation!" ) ;
2011-11-14 10:01:24 +00:00
paths = [ NSMutableArray array ] ;
2005-03-15 06:36:21 +00:00
2005-03-03 16:04:22 +00:00
/ *
* The order in which we return paths is important - user must come
* first , followed by local , followed by network , followed by system .
* The calling code can then loop on the returned paths , and stop as
* soon as it finds something . So things in user automatically
* override things in system etc .
* /
# define ADD_PATH ( mask , base_dir , add_dir ) \
if ( domainMask & mask ) \
{ \
path = [ base_dir stringByAppendingPathComponent : add_dir ] ; \
2007-03-30 07:03:35 +00:00
if ( [ path length ] > 0 && [ paths containsObject : path ] = = NO ) \
2005-03-03 16:04:22 +00:00
[ paths addObject : path ] ; \
}
2005-03-15 04:24:26 +00:00
# define ADD_PLATFORM _PATH ( mask , add_dir ) \
if ( domainMask & mask ) \
{ \
2007-03-30 07:03:35 +00:00
if ( [ add_dir length ] > 0 && [ paths containsObject : add_dir ] = = NO ) \
2005-03-15 04:24:26 +00:00
[ paths addObject : add_dir ] ; \
}
2005-03-03 16:04:22 +00:00
2005-07-25 05:18:19 +00:00
switch ( directoryKey )
2005-03-03 16:04:22 +00:00
{
2005-07-25 05:18:19 +00:00
case NSAllApplicationsDirectory :
{
2007-02-15 03:06:33 +00:00
ADD_PLATFORM _PATH ( NSUserDomainMask , gnustepUserApps ) ;
ADD_PLATFORM _PATH ( NSLocalDomainMask , gnustepLocalApps ) ;
ADD_PLATFORM _PATH ( NSNetworkDomainMask , gnustepNetworkApps ) ;
ADD_PLATFORM _PATH ( NSSystemDomainMask , gnustepSystemApps ) ;
2007-02-16 20:53:29 +00:00
ADD_PLATFORM _PATH ( NSUserDomainMask , gnustepUserAdminApps ) ;
ADD_PLATFORM _PATH ( NSLocalDomainMask , gnustepLocalAdminApps ) ;
ADD_PLATFORM _PATH ( NSNetworkDomainMask , gnustepNetworkAdminApps ) ;
ADD_PLATFORM _PATH ( NSSystemDomainMask , gnustepSystemAdminApps ) ;
2005-07-25 05:18:19 +00:00
}
break ;
2005-03-15 04:24:26 +00:00
2005-07-25 05:18:19 +00:00
case NSApplicationDirectory :
{
2007-02-15 03:06:33 +00:00
ADD_PLATFORM _PATH ( NSUserDomainMask , gnustepUserApps ) ;
ADD_PLATFORM _PATH ( NSLocalDomainMask , gnustepLocalApps ) ;
ADD_PLATFORM _PATH ( NSNetworkDomainMask , gnustepNetworkApps ) ;
ADD_PLATFORM _PATH ( NSSystemDomainMask , gnustepSystemApps ) ;
2005-07-25 05:18:19 +00:00
}
break ;
2005-03-15 04:24:26 +00:00
2005-07-25 05:18:19 +00:00
case NSDemoApplicationDirectory :
{
2007-02-15 03:06:33 +00:00
ADD_PLATFORM _PATH ( NSUserDomainMask , gnustepUserApps ) ;
ADD_PLATFORM _PATH ( NSLocalDomainMask , gnustepLocalApps ) ;
ADD_PLATFORM _PATH ( NSNetworkDomainMask , gnustepNetworkApps ) ;
ADD_PLATFORM _PATH ( NSSystemDomainMask , gnustepSystemApps ) ;
/ * I imagine if ever wanted a separate Demo directory , the
* only way for this to have some meaning across filesystems
* would be as a subdirectory of Applications , as follows .
* /
/ *
ADD_PATH ( NSUserDomainMask , gnustepUserApps , @ "Demos" ) ;
ADD_PATH ( NSLocalDomainMask , gnustepLocalApps , @ "Demos" ) ;
ADD_PATH ( NSNetworkDomainMask , gnustepNetworkApps , @ "Demos" ) ;
ADD_PATH ( NSSystemDomainMask , gnustepSystemApps , @ "Demos" ) ;
* /
2005-07-25 05:18:19 +00:00
}
break ;
2006-12-15 04:58:45 +00:00
case NSCoreServicesDirectory :
{
2007-02-15 03:06:33 +00:00
ADD_PATH ( NSSystemDomainMask , gnustepSystemLibrary , @ "CoreServices" ) ;
2006-12-15 04:58:45 +00:00
}
break ;
case NSDesktopDirectory :
{
2010-12-06 00:44:28 +00:00
ADD_PATH ( NSUserDomainMask , gnustepUserHome , @ "Desktop" ) ;
2006-12-15 04:58:45 +00:00
}
break ;
2005-07-25 05:18:19 +00:00
case NSDeveloperApplicationDirectory :
{
2014-01-11 08:58:57 +00:00
/ * Deprecated key . . . for now just point to normal apps .
* /
2007-02-15 03:06:33 +00:00
ADD_PLATFORM _PATH ( NSUserDomainMask , gnustepUserApps ) ;
ADD_PLATFORM _PATH ( NSLocalDomainMask , gnustepLocalApps ) ;
ADD_PLATFORM _PATH ( NSNetworkDomainMask , gnustepNetworkApps ) ;
ADD_PLATFORM _PATH ( NSSystemDomainMask , gnustepSystemApps ) ;
2005-07-25 05:18:19 +00:00
}
break ;
case NSAdminApplicationDirectory :
{
2007-02-16 20:53:29 +00:00
ADD_PLATFORM _PATH ( NSUserDomainMask , gnustepUserAdminApps ) ;
ADD_PLATFORM _PATH ( NSLocalDomainMask , gnustepLocalAdminApps ) ;
ADD_PLATFORM _PATH ( NSNetworkDomainMask , gnustepNetworkAdminApps ) ;
ADD_PLATFORM _PATH ( NSSystemDomainMask , gnustepSystemAdminApps ) ;
2005-07-25 05:18:19 +00:00
}
break ;
case NSAllLibrariesDirectory :
{
2007-02-15 03:29:46 +00:00
ADD_PLATFORM _PATH ( NSUserDomainMask , gnustepUserLibrary ) ;
ADD_PLATFORM _PATH ( NSLocalDomainMask , gnustepLocalLibrary ) ;
ADD_PLATFORM _PATH ( NSNetworkDomainMask , gnustepNetworkLibrary ) ;
ADD_PLATFORM _PATH ( NSSystemDomainMask , gnustepSystemLibrary ) ;
2005-07-25 05:18:19 +00:00
}
break ;
case NSLibraryDirectory :
{
2011-04-12 05:41:53 +00:00
/ * We allow the environment to be used to specify the location of
* the resources of uninstalled libraries so that we can run tests
* on software prior to installation .
* /
ADD_PLATFORM _PATH ( NSAllDomainsMask , uninstalled ) ;
2007-02-15 03:06:33 +00:00
ADD_PLATFORM _PATH ( NSUserDomainMask , gnustepUserLibrary ) ;
ADD_PLATFORM _PATH ( NSLocalDomainMask , gnustepLocalLibrary ) ;
ADD_PLATFORM _PATH ( NSNetworkDomainMask , gnustepNetworkLibrary ) ;
ADD_PLATFORM _PATH ( NSSystemDomainMask , gnustepSystemLibrary ) ;
2005-07-25 05:18:19 +00:00
}
break ;
case NSDeveloperDirectory :
{
2014-01-11 08:58:57 +00:00
static NSString * root = nil ;
# if defined ( __MINGW __ )
2014-01-12 15:19:39 +00:00
if ( nil = = root )
{
2014-01-12 15:23:33 +00:00
NSString * path = nil ;
2014-01-13 15:38:51 +00:00
NSString * bpath = nil ;
NSString * ipath = nil ;
2014-01-12 15:23:33 +00:00
NSFileManager * mgr ;
2014-01-12 15:19:39 +00:00
mgr = [ NSFileManager defaultManager ] ;
2014-01-13 15:15:51 +00:00
/ * First see if we can find the developer root above the
* system tools directory of the current running process .
2014-01-12 15:19:39 +00:00
* /
path = devroot ( mgr , gnustepSystemTools ) ;
2014-01-13 15:19:34 +00:00
/ * Failing that , try looking above the base library .
* /
if ( nil = = path )
{
2014-01-13 15:38:51 +00:00
NSBundle * baseBundle ;
baseBundle = [ NSBundle bundleForLibrary : @ "gnustep-base" ] ;
bpath = [ baseBundle bundlePath ] ;
path = devroot ( mgr , bpath ) ;
2014-01-13 15:19:34 +00:00
}
2014-01-13 15:15:51 +00:00
/ * If we havent found the developer area relative to the
* hierarchy used by the current process , look for the
* GNUstep package installation root in case we have the
* developer environment installed from a package .
2014-01-12 15:19:39 +00:00
* /
if ( nil = = path )
{
HKEY regKey ;
BOOL found = NO ;
/ * Open the key for the current user or local machine where
* the installation path for the GNUstep package is stored .
* /
if ( ERROR_SUCCESS = = RegOpenKeyExW ( HKEY_CURRENT _USER ,
L "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\GNUstep" ,
0 ,
KEY_READ ,
& regKey ) )
{
found = YES ;
}
else
{
if ( ERROR_SUCCESS = = RegOpenKeyExW ( HKEY_LOCAL _MACHINE ,
L "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\GNUstep" ,
0 ,
KEY_READ ,
& regKey ) )
{
found = YES ;
}
}
if ( found )
{
wchar_t buf [ 1024 ] ;
DWORD bufsize ;
DWORD type ;
bufsize = sizeof ( buf ) ;
if ( ERROR_SUCCESS = = RegQueryValueExW ( regKey ,
0 , 0 , & type , ( BYTE * ) buf , & bufsize ) )
{
2014-01-13 15:38:51 +00:00
ipath = [ NSString stringWithCharacters : buf
2014-01-12 15:19:39 +00:00
length : wcslen ( buf ) ] ;
2014-01-13 16:32:12 +00:00
path = idevroot ( mgr , ipath ) ;
2014-01-12 15:19:39 +00:00
}
RegCloseKey ( regKey ) ;
}
}
ASSIGNCOPY ( root , path ) ;
2014-01-13 15:38:51 +00:00
if ( nil = = root )
{
if ( nil = = ipath )
{
NSLog ( @ "Failed to locate NSDeveloperDirectory above system tools at %@, or base library at %@, and failed to find any installed GNUstep package." , gnustepSystemTools , bpath ) ;
}
else
{
NSLog ( @ "Failed to locate NSDeveloperDirectory above system tools at %@, or base library at %@, or installed package at %@" , gnustepSystemTools , bpath , ipath ) ;
}
}
2014-01-12 15:19:39 +00:00
}
2014-01-11 08:58:57 +00:00
# endif
if ( nil = = root )
{
root = RETAIN ( NSOpenStepRootDirectory ( ) ) ;
}
/ * The Developer directory is deprecated on OSX , but for GNUstep
* specific apps we return the root of the system containing the
* development environment . On most systems , that ' s the root
2014-01-12 15:19:39 +00:00
* directory , but on windows it can be anywhere the user has put it .
* If not found relative to the hierarchy of the running process ,
* with the GNUstep package installed , it ' s the location of the
* msys filesystem within the GNUstep package installation .
2007-02-15 03:06:33 +00:00
* /
2014-01-11 08:58:57 +00:00
ADD_PLATFORM _PATH ( NSUserDomainMask , root ) ;
ADD_PLATFORM _PATH ( NSLocalDomainMask , root ) ;
ADD_PLATFORM _PATH ( NSNetworkDomainMask , root ) ;
ADD_PLATFORM _PATH ( NSSystemDomainMask , root ) ;
2005-07-25 05:18:19 +00:00
}
break ;
case NSUserDirectory :
{
2007-03-06 14:03:49 +00:00
/ * This is the directory in which user directories are located .
* You can not have user directories in your own user directory ,
* so NSUserDomainMask will always return ' ' .
* /
ADD_PLATFORM _PATH ( NSLocalDomainMask , gnustepLocalUsersDir ) ;
ADD_PLATFORM _PATH ( NSNetworkDomainMask , gnustepNetworkUsersDir ) ;
ADD_PLATFORM _PATH ( NSSystemDomainMask , gnustepSystemUsersDir ) ;
2005-07-25 05:18:19 +00:00
}
break ;
case NSDocumentationDirectory :
{
2007-02-15 03:06:33 +00:00
ADD_PLATFORM _PATH ( NSUserDomainMask , gnustepUserDocumentation ) ;
ADD_PLATFORM _PATH ( NSLocalDomainMask , gnustepLocalDocumentation ) ;
ADD_PLATFORM _PATH ( NSNetworkDomainMask , gnustepNetworkDocumentation ) ;
ADD_PLATFORM _PATH ( NSSystemDomainMask , gnustepSystemDocumentation ) ;
2005-07-25 05:18:19 +00:00
}
break ;
2006-12-15 04:58:45 +00:00
case NSDocumentDirectory :
{
2010-11-13 09:46:01 +00:00
/ * this is relative to the user home annd for the user domain only
2014-01-12 15:19:39 +00:00
* verified on Macintosh
2010-11-13 09:46:01 +00:00
* despite the name it is Documents and not Document . . . .
* /
ADD_PATH ( NSUserDomainMask , gnustepUserHome , @ "Documents" ) ;
2006-12-15 04:58:45 +00:00
}
break ;
2008-06-06 13:57:06 +00:00
case NSDownloadsDirectory :
{
2010-11-13 09:46:01 +00:00
/ * Be consistent with NSDocumentDirectory * /
ADD_PATH ( NSUserDomainMask , gnustepUserHome , @ "Downloads" ) ;
2008-06-06 13:57:06 +00:00
}
break ;
2006-12-15 04:58:45 +00:00
case NSCachesDirectory :
{
2007-02-15 03:06:33 +00:00
/ * Uff - at the moment the only place to put Caches seems to
* be Library . Unfortunately under GNU / Linux Library will
* end up in / usr / lib / GNUstep which could be mounted
* read - only !
* /
ADD_PATH ( NSUserDomainMask , gnustepUserLibrary , @ "Caches" ) ;
ADD_PATH ( NSLocalDomainMask , gnustepLocalLibrary , @ "Caches" ) ;
ADD_PATH ( NSNetworkDomainMask , gnustepNetworkLibrary , @ "Caches" ) ;
ADD_PATH ( NSSystemDomainMask , gnustepSystemLibrary , @ "Caches" ) ;
2006-12-15 04:58:45 +00:00
}
break ;
case NSApplicationSupportDirectory :
2005-07-25 05:18:19 +00:00
{
2007-02-15 03:06:33 +00:00
ADD_PATH ( NSUserDomainMask , gnustepUserLibrary , @ "ApplicationSupport" ) ;
2007-03-01 13:43:23 +00:00
ADD_PATH ( NSLocalDomainMask , gnustepLocalLibrary ,
@ "ApplicationSupport" ) ;
ADD_PATH ( NSNetworkDomainMask , gnustepNetworkLibrary ,
@ "ApplicationSupport" ) ;
ADD_PATH ( NSSystemDomainMask , gnustepSystemLibrary ,
@ "ApplicationSupport" ) ;
2005-07-25 05:18:19 +00:00
}
break ;
2006-12-15 04:58:45 +00:00
/ * Now the GNUstep additions * /
2005-07-25 05:18:19 +00:00
case GSFrameworksDirectory :
{
2007-02-15 03:06:33 +00:00
ADD_PATH ( NSUserDomainMask , gnustepUserLibrary , @ "Frameworks" ) ;
ADD_PATH ( NSLocalDomainMask , gnustepLocalLibrary , @ "Frameworks" ) ;
ADD_PATH ( NSNetworkDomainMask , gnustepNetworkLibrary , @ "Frameworks" ) ;
ADD_PATH ( NSSystemDomainMask , gnustepSystemLibrary , @ "Frameworks" ) ;
2005-07-25 05:18:19 +00:00
}
break ;
case GSFontsDirectory :
{
2007-02-15 03:06:33 +00:00
ADD_PATH ( NSUserDomainMask , gnustepUserLibrary , @ "Fonts" ) ;
ADD_PATH ( NSLocalDomainMask , gnustepLocalLibrary , @ "Fonts" ) ;
ADD_PATH ( NSNetworkDomainMask , gnustepNetworkLibrary , @ "Fonts" ) ;
ADD_PATH ( NSSystemDomainMask , gnustepSystemLibrary , @ "Fonts" ) ;
2005-07-25 05:18:19 +00:00
}
break ;
case GSLibrariesDirectory :
{
2005-07-31 08:18:19 +00:00
NSString * full = nil ;
NSString * part = nil ;
2005-07-25 05:18:19 +00:00
2006-10-02 16:06:37 +00:00
if ( [ gnustep_is _flattened boolValue ] = = NO
2005-07-31 08:18:19 +00:00
&& gnustep_target _cpu ! = nil && gnustep_target _os ! = nil )
{
part = [ gnustep_target _cpu stringByAppendingPathComponent :
gnustep_target _os ] ;
if ( library_combo ! = nil )
{
full = [ part stringByAppendingPathComponent : library_combo ] ;
}
}
2007-02-15 03:06:33 +00:00
ADD_PLATFORM _PATH ( NSUserDomainMask , gnustepUserLibraries ) ;
2011-11-14 10:01:24 +00:00
if ( full )
ADD_PATH ( NSUserDomainMask , gnustepUserLibraries , full ) ;
if ( part )
ADD_PATH ( NSUserDomainMask , gnustepUserLibraries , part ) ;
2007-02-15 03:06:33 +00:00
ADD_PLATFORM _PATH ( NSLocalDomainMask , gnustepLocalLibraries ) ;
2011-11-14 10:01:24 +00:00
if ( full )
ADD_PATH ( NSLocalDomainMask , gnustepLocalLibraries , full ) ;
if ( part )
ADD_PATH ( NSLocalDomainMask , gnustepLocalLibraries , part ) ;
2007-02-15 03:06:33 +00:00
ADD_PLATFORM _PATH ( NSNetworkDomainMask , gnustepNetworkLibraries ) ;
2007-03-01 13:43:23 +00:00
if ( full )
ADD_PATH ( NSNetworkDomainMask , gnustepNetworkLibraries , full ) ;
if ( part )
ADD_PATH ( NSNetworkDomainMask , gnustepNetworkLibraries , part ) ;
2007-02-15 03:06:33 +00:00
ADD_PLATFORM _PATH ( NSSystemDomainMask , gnustepSystemLibraries ) ;
2011-11-14 10:01:24 +00:00
if ( full )
ADD_PATH ( NSSystemDomainMask , gnustepSystemLibraries , full ) ;
if ( part )
ADD_PATH ( NSSystemDomainMask , gnustepSystemLibraries , part ) ;
2005-07-25 05:18:19 +00:00
}
break ;
case GSToolsDirectory :
{
2005-07-31 08:18:19 +00:00
NSString * full = nil ;
NSString * part = nil ;
2006-10-02 16:06:37 +00:00
if ( [ gnustep_is _flattened boolValue ] = = NO
2005-07-31 08:18:19 +00:00
&& gnustep_target _cpu ! = nil && gnustep_target _os ! = nil )
{
part = [ gnustep_target _cpu stringByAppendingPathComponent :
gnustep_target _os ] ;
if ( library_combo ! = nil )
{
full = [ part stringByAppendingPathComponent : library_combo ] ;
}
}
2007-02-15 03:06:33 +00:00
ADD_PLATFORM _PATH ( NSUserDomainMask , gnustepUserTools ) ;
2011-11-14 10:01:24 +00:00
if ( full )
ADD_PATH ( NSUserDomainMask , gnustepUserTools , full ) ;
if ( part )
ADD_PATH ( NSUserDomainMask , gnustepUserTools , part ) ;
2007-02-15 03:06:33 +00:00
ADD_PLATFORM _PATH ( NSLocalDomainMask , gnustepLocalTools ) ;
2011-11-14 10:01:24 +00:00
if ( full )
ADD_PATH ( NSLocalDomainMask , gnustepLocalTools , full ) ;
if ( part )
ADD_PATH ( NSLocalDomainMask , gnustepLocalTools , part ) ;
2007-02-15 03:06:33 +00:00
ADD_PLATFORM _PATH ( NSNetworkDomainMask , gnustepNetworkTools ) ;
2011-11-14 10:01:24 +00:00
if ( full )
ADD_PATH ( NSNetworkDomainMask , gnustepNetworkTools , full ) ;
if ( part )
ADD_PATH ( NSNetworkDomainMask , gnustepNetworkTools , part ) ;
2007-02-15 03:06:33 +00:00
ADD_PLATFORM _PATH ( NSSystemDomainMask , gnustepSystemTools ) ;
2011-11-14 10:01:24 +00:00
if ( full )
ADD_PATH ( NSSystemDomainMask , gnustepSystemTools , full ) ;
if ( part )
ADD_PATH ( NSSystemDomainMask , gnustepSystemTools , part ) ;
2005-07-25 05:18:19 +00:00
}
break ;
2007-03-05 17:58:02 +00:00
2007-03-08 02:32:18 +00:00
case GSAdminToolsDirectory :
{
NSString * full = nil ;
NSString * part = nil ;
if ( [ gnustep_is _flattened boolValue ] = = NO
&& gnustep_target _cpu ! = nil && gnustep_target _os ! = nil )
{
part = [ gnustep_target _cpu stringByAppendingPathComponent :
gnustep_target _os ] ;
if ( library_combo ! = nil )
{
full = [ part stringByAppendingPathComponent : library_combo ] ;
}
}
ADD_PLATFORM _PATH ( NSUserDomainMask , gnustepUserAdminTools ) ;
2011-11-14 10:01:24 +00:00
if ( full )
ADD_PATH ( NSUserDomainMask , gnustepUserAdminTools , full ) ;
if ( part )
ADD_PATH ( NSUserDomainMask , gnustepUserAdminTools , part ) ;
2007-03-08 02:32:18 +00:00
ADD_PLATFORM _PATH ( NSLocalDomainMask , gnustepLocalAdminTools ) ;
2011-11-14 10:01:24 +00:00
if ( full )
ADD_PATH ( NSLocalDomainMask , gnustepLocalAdminTools , full ) ;
if ( part )
ADD_PATH ( NSLocalDomainMask , gnustepLocalAdminTools , part ) ;
2007-03-08 02:32:18 +00:00
ADD_PLATFORM _PATH ( NSNetworkDomainMask , gnustepNetworkAdminTools ) ;
2011-11-14 10:01:24 +00:00
if ( full )
ADD_PATH ( NSNetworkDomainMask , gnustepNetworkAdminTools , full ) ;
if ( part )
ADD_PATH ( NSNetworkDomainMask , gnustepNetworkAdminTools , part ) ;
2007-03-08 02:32:18 +00:00
ADD_PLATFORM _PATH ( NSSystemDomainMask , gnustepSystemAdminTools ) ;
2011-11-14 10:01:24 +00:00
if ( full )
ADD_PATH ( NSSystemDomainMask , gnustepSystemAdminTools , full ) ;
if ( part )
ADD_PATH ( NSSystemDomainMask , gnustepSystemAdminTools , part ) ;
2007-03-08 02:32:18 +00:00
}
break ;
2007-03-05 17:58:02 +00:00
case GSWebApplicationsDirectory :
{
ADD_PLATFORM _PATH ( NSUserDomainMask , gnustepUserWebApps ) ;
ADD_PLATFORM _PATH ( NSLocalDomainMask , gnustepLocalWebApps ) ;
ADD_PLATFORM _PATH ( NSNetworkDomainMask , gnustepNetworkWebApps ) ;
ADD_PLATFORM _PATH ( NSSystemDomainMask , gnustepSystemWebApps ) ;
}
break ;
2005-03-03 16:04:22 +00:00
}
# undef ADD_PATH
2005-03-15 04:24:26 +00:00
# undef ADD_PLATFORM _PATH
2005-03-03 16:04:22 +00:00
count = [ paths count ] ;
for ( i = 0 ; i < count ; i + + )
{
path = [ paths objectAtIndex : i ] ;
2005-03-15 04:24:26 +00:00
2006-12-15 04:58:45 +00:00
if ( expandTilde = = YES )
2005-03-15 04:24:26 +00:00
{
[ paths replaceObjectAtIndex : i
2006-12-15 04:58:45 +00:00
withObject : [ path stringByExpandingTildeInPath ] ] ;
2005-03-15 04:24:26 +00:00
}
2005-03-03 16:04:22 +00:00
else
2005-03-15 04:24:26 +00:00
{
[ paths replaceObjectAtIndex : i
withObject : [ path stringByAbbreviatingWithTildeInPath ] ] ;
}
2005-03-03 16:04:22 +00:00
}
return paths ;
}
2013-08-22 15:44:54 +00:00
@ implementation GSPathUtilities
+ ( void ) atExit
{
ShutdownPathUtilities ( ) ;
}
+ ( void ) initialize
{
[ self registerAtExit ] ;
}
@ end