2005-03-15 04:24:26 +00:00
|
|
|
/* Implementation of filesystem & path-related functions for GNUstep
|
|
|
|
Copyright (C) 1996-2004 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
|
2007-09-14 11:36:11 +00:00
|
|
|
version 3 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>
|
|
|
|
*/
|
|
|
|
|
2005-03-03 16:04:22 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "GNUstepBase/preface.h"
|
2005-10-16 14:20:14 +00:00
|
|
|
#include "objc-load.h"
|
2005-03-03 16:04:22 +00:00
|
|
|
#include "Foundation/NSObjCRuntime.h"
|
|
|
|
#include "Foundation/NSString.h"
|
|
|
|
#include "Foundation/NSPathUtilities.h"
|
|
|
|
#include "Foundation/NSException.h"
|
|
|
|
#include "Foundation/NSArray.h"
|
2005-03-15 04:24:26 +00:00
|
|
|
#include "Foundation/NSDebug.h"
|
2005-03-03 16:04:22 +00:00
|
|
|
#include "Foundation/NSDictionary.h"
|
|
|
|
#include "Foundation/NSFileManager.h"
|
|
|
|
#include "Foundation/NSProcessInfo.h"
|
|
|
|
#include "Foundation/NSString.h"
|
|
|
|
#include "Foundation/NSValue.h"
|
|
|
|
#include "Foundation/NSLock.h"
|
|
|
|
#include "Foundation/NSUserDefaults.h"
|
|
|
|
#include "GNUstepBase/GSCategories.h"
|
|
|
|
|
|
|
|
#include "GSPrivate.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2005-03-15 04:24:26 +00:00
|
|
|
#include <unistd.h> // for getuid()
|
2005-03-03 16:04:22 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
#include <pwd.h> // for getpwnam()
|
|
|
|
#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
|
|
|
|
|
2006-02-22 09:30:55 +00:00
|
|
|
#if defined(__MINGW32__)
|
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 *gnustepUserDir = nil;
|
|
|
|
static NSString *gnustepUserHome = nil;
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2005-10-14 10:51:50 +00:00
|
|
|
/* Conditionally assign lval to var only if var is nil */
|
|
|
|
#define TEST_ASSIGN(var, lval) ({\
|
|
|
|
if ((var == nil)&&(lval != nil))\
|
|
|
|
{\
|
|
|
|
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)); \
|
|
|
|
}\
|
|
|
|
})
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2005-10-16 11:48:54 +00:00
|
|
|
if ([path hasPrefix: @"./"] == YES)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
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)];
|
|
|
|
if ((buf[0] == '/' || bug[0] == '\\') && isalpha(buf[1])
|
|
|
|
&& (buf[2] == '/' || bug[2] == '\\'))
|
|
|
|
{
|
|
|
|
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];
|
2006-06-27 19:06:44 +00:00
|
|
|
NSString *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.
|
|
|
|
*/
|
|
|
|
ASSIGN_IF_SET(gnustepUserDir, c, @"GNUSTEP_USER_DIR");
|
|
|
|
ASSIGN_IF_SET(gnustepUserDefaultsDir, c, @"GNUSTEP_USER_DEFAULTS_DIR");
|
|
|
|
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_PATH(gnustepMakefiles, c, @"GNUSTEP_MAKEFILES");
|
|
|
|
|
2007-03-06 14:03:49 +00:00
|
|
|
ASSIGN_PATH(gnustepSystemUsersDir, c, @"GNUSTEP_SYSTEM_USERS_DIR");
|
|
|
|
ASSIGN_PATH(gnustepNetworkUsersDir, c, @"GNUSTEP_NETWORK_USERS_DIR");
|
|
|
|
ASSIGN_PATH(gnustepLocalUsersDir, c, @"GNUSTEP_LOCAL_USERS_DIR");
|
|
|
|
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_PATH(gnustepSystemApps, c, @"GNUSTEP_SYSTEM_APPS");
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN_PATH(gnustepSystemAdminApps, c, @"GNUSTEP_SYSTEM_ADMIN_APPS");
|
2007-03-05 17:58:02 +00:00
|
|
|
ASSIGN_PATH(gnustepSystemWebApps, c, @"GNUSTEP_SYSTEM_WEB_APPS");
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_PATH(gnustepSystemTools, c, @"GNUSTEP_SYSTEM_TOOLS");
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN_PATH(gnustepSystemAdminTools, c, @"GNUSTEP_SYSTEM_ADMIN_TOOLS");
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_PATH(gnustepSystemLibrary, c, @"GNUSTEP_SYSTEM_LIBRARY");
|
|
|
|
ASSIGN_PATH(gnustepSystemLibraries, c, @"GNUSTEP_SYSTEM_LIBRARIES");
|
|
|
|
ASSIGN_PATH(gnustepSystemHeaders, c, @"GNUSTEP_SYSTEM_HEADERS");
|
2007-02-26 15:20:50 +00:00
|
|
|
ASSIGN_PATH(gnustepSystemDocumentation, c, @"GNUSTEP_SYSTEM_DOC");
|
|
|
|
ASSIGN_PATH(gnustepSystemDocumentationMan, c, @"GNUSTEP_SYSTEM_DOC_MAN");
|
|
|
|
ASSIGN_PATH(gnustepSystemDocumentationInfo, c, @"GNUSTEP_SYSTEM_DOC_INFO");
|
2007-02-15 03:06:33 +00:00
|
|
|
|
|
|
|
ASSIGN_PATH(gnustepNetworkApps, c, @"GNUSTEP_NETWORK_APPS");
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN_PATH(gnustepNetworkAdminApps, c, @"GNUSTEP_NETWORK_ADMIN_APPS");
|
2007-03-05 17:58:02 +00:00
|
|
|
ASSIGN_PATH(gnustepNetworkWebApps, c, @"GNUSTEP_NETWORK_WEB_APPS");
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_PATH(gnustepNetworkTools, c, @"GNUSTEP_NETWORK_TOOLS");
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN_PATH(gnustepNetworkAdminTools, c, @"GNUSTEP_NETWORK_ADMIN_TOOLS");
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_PATH(gnustepNetworkLibrary, c, @"GNUSTEP_NETWORK_LIBRARY");
|
|
|
|
ASSIGN_PATH(gnustepNetworkLibraries, c, @"GNUSTEP_NETWORK_LIBRARIES");
|
|
|
|
ASSIGN_PATH(gnustepNetworkHeaders, c, @"GNUSTEP_NETWORK_HEADERS");
|
2007-02-26 15:20:50 +00:00
|
|
|
ASSIGN_PATH(gnustepNetworkDocumentation, c, @"GNUSTEP_NETWORK_DOC");
|
|
|
|
ASSIGN_PATH(gnustepNetworkDocumentationMan, c, @"GNUSTEP_NETWORK_DOC_MAN");
|
|
|
|
ASSIGN_PATH(gnustepNetworkDocumentationInfo, c, @"GNUSTEP_NETWORK_DOC_INFO");
|
2007-02-15 03:06:33 +00:00
|
|
|
|
|
|
|
ASSIGN_PATH(gnustepLocalApps, c, @"GNUSTEP_LOCAL_APPS");
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN_PATH(gnustepLocalAdminApps, c, @"GNUSTEP_LOCAL_ADMIN_APPS");
|
2007-03-05 17:58:02 +00:00
|
|
|
ASSIGN_PATH(gnustepLocalWebApps, c, @"GNUSTEP_LOCAL_WEB_APPS");
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_PATH(gnustepLocalTools, c, @"GNUSTEP_LOCAL_TOOLS");
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN_PATH(gnustepLocalAdminTools, c, @"GNUSTEP_LOCAL_ADMIN_TOOLS");
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_PATH(gnustepLocalLibrary, c, @"GNUSTEP_LOCAL_LIBRARY");
|
|
|
|
ASSIGN_PATH(gnustepLocalLibraries, c, @"GNUSTEP_LOCAL_LIBRARIES");
|
|
|
|
ASSIGN_PATH(gnustepLocalHeaders, c, @"GNUSTEP_LOCAL_HEADERS");
|
2007-02-26 15:20:50 +00:00
|
|
|
ASSIGN_PATH(gnustepLocalDocumentation, c, @"GNUSTEP_LOCAL_DOC");
|
|
|
|
ASSIGN_PATH(gnustepLocalDocumentationMan, c, @"GNUSTEP_LOCAL_DOC_MAN");
|
|
|
|
ASSIGN_PATH(gnustepLocalDocumentationInfo, c, @"GNUSTEP_LOCAL_DOC_INFO");
|
2007-02-15 03:06:33 +00:00
|
|
|
|
|
|
|
ASSIGN_IF_SET(gnustepUserDirApps, c, @"GNUSTEP_USER_DIR_APPS");
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN_IF_SET(gnustepUserDirAdminApps, c, @"GNUSTEP_USER_DIR_ADMIN_APPS");
|
2007-03-05 17:58:02 +00:00
|
|
|
ASSIGN_IF_SET(gnustepUserDirWebApps, c, @"GNUSTEP_USER_DIR_WEB_APPS");
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_IF_SET(gnustepUserDirTools, c, @"GNUSTEP_USER_DIR_TOOLS");
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN_IF_SET(gnustepUserDirAdminTools, c, @"GNUSTEP_USER_DIR_ADMIN_TOOLS");
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_IF_SET(gnustepUserDirLibrary, c, @"GNUSTEP_USER_DIR_LIBRARY");
|
|
|
|
ASSIGN_IF_SET(gnustepUserDirLibraries, c, @"GNUSTEP_USER_DIR_LIBRARIES");
|
|
|
|
ASSIGN_IF_SET(gnustepUserDirHeaders, c, @"GNUSTEP_USER_DIR_HEADERS");
|
2007-02-26 15:20:50 +00:00
|
|
|
ASSIGN_IF_SET(gnustepUserDirDocumentation, c, @"GNUSTEP_USER_DIR_DOC");
|
|
|
|
ASSIGN_IF_SET(gnustepUserDirDocumentationMan, c, @"GNUSTEP_USER_DIR_DOC_MAN");
|
|
|
|
ASSIGN_IF_SET(gnustepUserDirDocumentationInfo, c, @"GNUSTEP_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;
|
|
|
|
|
|
|
|
enumerator = [[extra componentsSeparatedByString: @","] objectEnumerator];
|
|
|
|
[c removeObjectForKey: @"GNUSTEP_EXTRA"];
|
|
|
|
while ((key = [enumerator nextObject]) != nil)
|
|
|
|
{
|
|
|
|
key = [key stringByTrimmingSpaces];
|
|
|
|
[c removeObjectForKey: key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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"];
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
if (gnustepUserDir == nil)
|
2005-03-15 04:24:26 +00:00
|
|
|
{
|
2005-10-27 12:00:38 +00:00
|
|
|
ASSIGN(gnustepUserDir, @GNUSTEP_TARGET_USER_DIR);
|
2005-03-15 04:24:26 +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)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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
|
|
|
*/
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN(gnustepUserApps,
|
|
|
|
[gnustepUserHome stringByAppendingPathComponent: gnustepUserDirApps]);
|
|
|
|
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN(gnustepUserAdminApps,
|
|
|
|
[gnustepUserHome stringByAppendingPathComponent: gnustepUserDirAdminApps]);
|
|
|
|
|
2007-03-05 17:58:02 +00:00
|
|
|
ASSIGN(gnustepUserWebApps,
|
|
|
|
[gnustepUserHome stringByAppendingPathComponent: gnustepUserDirWebApps]);
|
|
|
|
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN(gnustepUserTools,
|
|
|
|
[gnustepUserHome stringByAppendingPathComponent: gnustepUserDirTools]);
|
|
|
|
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN(gnustepUserAdminTools,
|
|
|
|
[gnustepUserHome stringByAppendingPathComponent: gnustepUserDirAdminTools]);
|
|
|
|
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN(gnustepUserLibrary,
|
|
|
|
[gnustepUserHome stringByAppendingPathComponent: gnustepUserDirLibrary]);
|
|
|
|
|
|
|
|
ASSIGN(gnustepUserLibraries,
|
|
|
|
[gnustepUserHome stringByAppendingPathComponent: gnustepUserDirLibraries]);
|
|
|
|
|
|
|
|
ASSIGN(gnustepUserHeaders,
|
|
|
|
[gnustepUserHome stringByAppendingPathComponent: gnustepUserDirHeaders]);
|
|
|
|
|
|
|
|
ASSIGN(gnustepUserDocumentation,
|
|
|
|
[gnustepUserHome stringByAppendingPathComponent:
|
|
|
|
gnustepUserDocumentation]);
|
|
|
|
|
|
|
|
ASSIGN(gnustepUserDocumentationMan,
|
|
|
|
[gnustepUserHome stringByAppendingPathComponent:
|
|
|
|
gnustepUserDocumentationMan]);
|
|
|
|
|
|
|
|
ASSIGN(gnustepUserDocumentationInfo,
|
|
|
|
[gnustepUserHome stringByAppendingPathComponent:
|
|
|
|
gnustepUserDocumentationInfo]);
|
|
|
|
|
2005-10-25 16:15:35 +00:00
|
|
|
/*
|
|
|
|
* Try to ensure that essential user directories exist.
|
|
|
|
* FIXME ... Check/creation should perhaps be configurable.
|
|
|
|
*/
|
|
|
|
if (1)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
[manager createDirectoryAtPath: path attributes: attr];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepSystemApps, @GNUSTEP_TARGET_SYSTEM_APPS);
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepSystemAdminApps, @GNUSTEP_TARGET_SYSTEM_ADMIN_APPS);
|
2007-03-05 17:58:02 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepSystemWebApps, @GNUSTEP_TARGET_SYSTEM_WEB_APPS);
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepSystemTools, @GNUSTEP_TARGET_SYSTEM_TOOLS);
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepSystemAdminTools, @GNUSTEP_TARGET_SYSTEM_ADMIN_TOOLS);
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepSystemLibrary, @GNUSTEP_TARGET_SYSTEM_LIBRARY);
|
|
|
|
ASSIGN_DEFAULT_PATH(gnustepSystemLibraries, @GNUSTEP_TARGET_SYSTEM_LIBRARIES);
|
|
|
|
ASSIGN_DEFAULT_PATH(gnustepSystemHeaders, @GNUSTEP_TARGET_SYSTEM_HEADERS);
|
2007-02-26 15:20:50 +00:00
|
|
|
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);
|
2007-02-15 03:06:33 +00:00
|
|
|
|
|
|
|
ASSIGN_DEFAULT_PATH(gnustepNetworkApps, @GNUSTEP_TARGET_NETWORK_APPS);
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepNetworkAdminApps, @GNUSTEP_TARGET_NETWORK_ADMIN_APPS);
|
2007-03-05 17:58:02 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepNetworkWebApps, @GNUSTEP_TARGET_NETWORK_WEB_APPS);
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepNetworkTools, @GNUSTEP_TARGET_NETWORK_TOOLS);
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepNetworkAdminTools, @GNUSTEP_TARGET_NETWORK_ADMIN_TOOLS);
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepNetworkLibrary, @GNUSTEP_TARGET_NETWORK_LIBRARY);
|
|
|
|
ASSIGN_DEFAULT_PATH(gnustepNetworkLibraries, @GNUSTEP_TARGET_NETWORK_LIBRARIES);
|
|
|
|
ASSIGN_DEFAULT_PATH(gnustepNetworkHeaders, @GNUSTEP_TARGET_NETWORK_HEADERS);
|
2007-02-26 15:20:50 +00:00
|
|
|
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);
|
2007-02-15 03:06:33 +00:00
|
|
|
|
|
|
|
ASSIGN_DEFAULT_PATH(gnustepLocalApps, @GNUSTEP_TARGET_LOCAL_APPS);
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepLocalAdminApps, @GNUSTEP_TARGET_LOCAL_ADMIN_APPS);
|
2007-03-05 17:58:02 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepLocalWebApps, @GNUSTEP_TARGET_LOCAL_WEB_APPS);
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepLocalTools, @GNUSTEP_TARGET_LOCAL_TOOLS);
|
2007-02-16 20:53:29 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepLocalAdminTools, @GNUSTEP_TARGET_LOCAL_ADMIN_TOOLS);
|
2007-02-15 03:06:33 +00:00
|
|
|
ASSIGN_DEFAULT_PATH(gnustepLocalLibrary, @GNUSTEP_TARGET_LOCAL_LIBRARY);
|
|
|
|
ASSIGN_DEFAULT_PATH(gnustepLocalLibraries, @GNUSTEP_TARGET_LOCAL_LIBRARIES);
|
|
|
|
ASSIGN_DEFAULT_PATH(gnustepLocalHeaders, @GNUSTEP_TARGET_LOCAL_HEADERS);
|
2007-02-26 15:20:50 +00:00
|
|
|
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);
|
2007-02-15 03:06:33 +00:00
|
|
|
|
|
|
|
ASSIGN_DEFAULT_PATH(gnustepMakefiles, @GNUSTEP_TARGET_MAKEFILES);
|
2007-03-06 14:03:49 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
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];
|
|
|
|
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
|
|
|
{
|
2005-10-27 08:39:53 +00:00
|
|
|
NSString *file = nil;
|
2005-12-01 09:33:22 +00:00
|
|
|
BOOL fromEnvironment = YES;
|
2005-12-05 14:43:46 +00:00
|
|
|
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 './'
|
2005-10-16 15:24:51 +00:00
|
|
|
* then we determine it's actual path by working relative
|
|
|
|
* to the gnustep-base library.
|
2005-10-16 14:20:14 +00:00
|
|
|
*/
|
|
|
|
if ([file hasPrefix: @"./"] == YES)
|
|
|
|
{
|
2005-10-16 15:24:51 +00:00
|
|
|
Class c = [NSProcessInfo class];
|
2006-10-23 14:47:37 +00:00
|
|
|
NSString *path = GSPrivateSymbolPath (c, 0);
|
2005-10-16 15:07:10 +00:00
|
|
|
|
2005-10-16 15:24:51 +00:00
|
|
|
// Remove library name from path
|
|
|
|
path = [path stringByDeletingLastPathComponent];
|
|
|
|
// Remove ./ prefix from filename
|
|
|
|
file = [file substringFromIndex: 2];
|
|
|
|
// 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
|
|
|
|
}
|
2005-12-05 14:43:46 +00:00
|
|
|
if (bareDirectory == YES)
|
|
|
|
{
|
|
|
|
gnustepConfigPath = RETAIN(file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gnustepConfigPath
|
|
|
|
= RETAIN([file stringByDeletingLastPathComponent]);
|
2006-02-17 06:31:04 +00:00
|
|
|
ParseConfigurationFile(file, conf, nil);
|
2005-12-05 14:43:46 +00:00
|
|
|
}
|
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
|
|
|
NSString *userName;
|
|
|
|
NSMutableDictionary *config;
|
2005-11-15 13:07:09 +00:00
|
|
|
|
2005-11-16 11:44:44 +00:00
|
|
|
[gnustep_global_lock lock];
|
|
|
|
userName = NSUserName();
|
2005-11-22 20:01:57 +00:00
|
|
|
config = GNUstepConfig(nil);
|
2006-02-19 21:49:21 +00:00
|
|
|
GNUstepUserConfig(config, userName);
|
2005-11-16 11:44:44 +00:00
|
|
|
ASSIGNCOPY(gnustepUserHome, NSHomeDirectoryForUser(userName));
|
|
|
|
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);
|
|
|
|
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];
|
|
|
|
|
|
|
|
if ([userName isEqual: fileOwner] == NO)
|
|
|
|
{
|
2006-02-22 09:30:55 +00:00
|
|
|
#if defined(__MINGW32__)
|
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
|
|
|
{
|
2006-02-22 09:30:55 +00:00
|
|
|
#if defined(__MINGW32__)
|
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],
|
2005-10-23 06:35:33 +00:00
|
|
|
[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],
|
|
|
|
[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];
|
|
|
|
DESTROY(key);
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2006-02-22 09:30:55 +00:00
|
|
|
#if defined(__MINGW32__)
|
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;
|
|
|
|
#ifdef HAVE_GETPWUID
|
|
|
|
struct passwd *pwent = getpwuid (uid);
|
|
|
|
loginName = pwent->pw_name;
|
|
|
|
#endif /* HAVE_GETPWUID */
|
|
|
|
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 ());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns loginName's home directory as an NSString object.
|
|
|
|
*/
|
|
|
|
/* 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;
|
|
|
|
|
2005-10-15 07:19:11 +00:00
|
|
|
#if !defined(__MINGW32__)
|
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];
|
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
|
|
|
|
* preference to USERPROFILE.
|
|
|
|
*/
|
|
|
|
s = [e objectForKey: @"HOMEPATH"];
|
|
|
|
if (s != nil && ([s length] < 2 || [s characterAtIndex: 1] != ':'))
|
|
|
|
{
|
|
|
|
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 '%@'",
|
|
|
|
loginName, NSUserName());
|
|
|
|
NSLog(@"Can't determine other user home directories in Win32.");
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
NSString *userName = NSUserName();
|
2006-02-22 09:30:55 +00:00
|
|
|
#if defined(__MINGW32__)
|
2006-09-26 11:16:06 +00:00
|
|
|
struct _USER_INFO_2 *userInfo;
|
|
|
|
|
2006-09-26 11:50:11 +00:00
|
|
|
if (NetUserGetInfo(NULL, (unichar*)[userName cStringUsingEncoding:
|
|
|
|
NSUnicodeStringEncoding], 2, (LPBYTE*)&userInfo) == 0)
|
2006-09-26 11:16:06 +00:00
|
|
|
{
|
|
|
|
userName = [NSString stringWithCharacters: userInfo->usri2_full_name
|
|
|
|
length: wcslen(userInfo->usri2_full_name)];
|
|
|
|
}
|
2005-03-15 04:24:26 +00:00
|
|
|
#else
|
|
|
|
#ifdef HAVE_PWD_H
|
2006-09-26 11:16:06 +00:00
|
|
|
struct passwd *pw;
|
2005-03-03 16:04:22 +00:00
|
|
|
|
2006-09-26 11:16:06 +00:00
|
|
|
pw = getpwnam([NSUserName() cString]);
|
2006-10-09 14:00:01 +00:00
|
|
|
userName = [NSString stringWithUTF8String: pw->pw_gecos];
|
2005-03-03 16:04:22 +00:00
|
|
|
#else
|
2006-09-26 11:16:06 +00:00
|
|
|
NSLog(@"Warning: NSFullUserName not implemented\n");
|
|
|
|
userName = NSUserName();
|
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-03-15 04:24:26 +00:00
|
|
|
NSString *home;
|
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-10-17 05:44:18 +00:00
|
|
|
home = NSHomeDirectoryForUser(userName);
|
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
|
|
|
}
|
2005-11-06 06:51:28 +00:00
|
|
|
#if defined(__MINGW32__)
|
|
|
|
if ([defaultsDir rangeOfString: @":REGISTRY:"].length > 0)
|
|
|
|
{
|
|
|
|
return defaultsDir; // Just use windows registry.
|
|
|
|
}
|
|
|
|
#endif
|
2005-10-15 07:19:11 +00:00
|
|
|
home = [home stringByAppendingPathComponent: defaultsDir];
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-10-13 10:11:56 +00:00
|
|
|
return home;
|
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;
|
2006-02-22 09:30:55 +00:00
|
|
|
#if !defined(__MINGW32__)
|
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__)
|
2005-03-03 16:04:22 +00:00
|
|
|
baseTempDirName = @"/cygdrive/c/";
|
2006-02-22 09:30:55 +00:00
|
|
|
#elif defined(__MINGW32__)
|
|
|
|
baseTempDirName = @"C:\\";
|
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
|
2005-10-11 19:09:26 +00:00
|
|
|
#ifndef __MINGW32__
|
2005-03-03 16:04:22 +00:00
|
|
|
|
2005-10-11 19:09:26 +00:00
|
|
|
#if defined(__MINGW32__)
|
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;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
NSNumber *p = [NSNumber numberWithInt: 0700];
|
|
|
|
|
|
|
|
attr = [NSDictionary dictionaryWithObject: p
|
|
|
|
forKey: NSFilePosixPermissions];
|
|
|
|
if ([manager createDirectoryAtPath: tempDirName
|
|
|
|
attributes: attr] == NO)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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/";
|
2005-11-13 08:02:26 +00:00
|
|
|
#elif defined(__MINGW32__)
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSArray *
|
2005-03-15 06:36:21 +00:00
|
|
|
NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory directoryKey,
|
2005-03-03 16:04:22 +00:00
|
|
|
NSSearchPathDomainMask domainMask, BOOL expandTilde)
|
|
|
|
{
|
2005-03-15 04:24:26 +00:00
|
|
|
NSMutableArray *paths = [NSMutableArray new];
|
|
|
|
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!");
|
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:
|
|
|
|
{
|
2007-02-15 03:06:33 +00:00
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserLibrary, @"Desktop");
|
2006-12-15 04:58:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-07-25 05:18:19 +00:00
|
|
|
case NSDeveloperApplicationDirectory:
|
|
|
|
{
|
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 Developer 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, @"Developer");
|
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalApps, @"Developer");
|
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkApps, @"Developer");
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemApps, @"Developer");
|
|
|
|
*/
|
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:
|
|
|
|
{
|
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:
|
|
|
|
{
|
2007-02-15 03:06:33 +00:00
|
|
|
/* The only way of having a Developer directory is as a
|
|
|
|
* sub-dir of Library.
|
|
|
|
*/
|
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserLibrary, @"Developer");
|
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalLibrary, @"Developer");
|
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkLibrary, @"Developer");
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemLibrary, @"Developer");
|
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:
|
|
|
|
{
|
2007-02-15 03:06:33 +00:00
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserLibrary, @"Document");
|
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalLibrary, @"Document");
|
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkLibrary, @"Document");
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemLibrary, @"Document");
|
2006-12-15 04:58:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (full) ADD_PATH(NSUserDomainMask, gnustepUserLibraries, full);
|
|
|
|
if (part) ADD_PATH(NSUserDomainMask, gnustepUserLibraries, part);
|
|
|
|
|
|
|
|
ADD_PLATFORM_PATH(NSLocalDomainMask, gnustepLocalLibraries);
|
|
|
|
if (full) ADD_PATH(NSLocalDomainMask, gnustepLocalLibraries, full);
|
|
|
|
if (part) ADD_PATH(NSLocalDomainMask, gnustepLocalLibraries, part);
|
|
|
|
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
if (full) ADD_PATH(NSUserDomainMask, gnustepUserTools, full);
|
|
|
|
if (part) ADD_PATH(NSUserDomainMask, gnustepUserTools, part);
|
|
|
|
|
|
|
|
ADD_PLATFORM_PATH(NSLocalDomainMask, gnustepLocalTools);
|
|
|
|
if (full) ADD_PATH(NSLocalDomainMask, gnustepLocalTools, full);
|
|
|
|
if (part) ADD_PATH(NSLocalDomainMask, gnustepLocalTools, part);
|
|
|
|
|
|
|
|
ADD_PLATFORM_PATH(NSNetworkDomainMask, gnustepNetworkTools);
|
|
|
|
if (full) ADD_PATH(NSNetworkDomainMask, gnustepNetworkTools, full);
|
|
|
|
if (part) ADD_PATH(NSNetworkDomainMask, gnustepNetworkTools, part);
|
|
|
|
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, gnustepSystemTools);
|
|
|
|
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);
|
|
|
|
if (full) ADD_PATH(NSUserDomainMask, gnustepUserAdminTools, full);
|
|
|
|
if (part) ADD_PATH(NSUserDomainMask, gnustepUserAdminTools, part);
|
|
|
|
|
|
|
|
ADD_PLATFORM_PATH(NSLocalDomainMask, gnustepLocalAdminTools);
|
|
|
|
if (full) ADD_PATH(NSLocalDomainMask, gnustepLocalAdminTools, full);
|
|
|
|
if (part) ADD_PATH(NSLocalDomainMask, gnustepLocalAdminTools, part);
|
|
|
|
|
|
|
|
ADD_PLATFORM_PATH(NSNetworkDomainMask, gnustepNetworkAdminTools);
|
|
|
|
if (full) ADD_PATH(NSNetworkDomainMask, gnustepNetworkAdminTools, full);
|
|
|
|
if (part) ADD_PATH(NSNetworkDomainMask, gnustepNetworkAdminTools, part);
|
|
|
|
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, gnustepSystemAdminTools);
|
|
|
|
if (full) ADD_PATH(NSSystemDomainMask, gnustepSystemAdminTools, full);
|
|
|
|
if (part) ADD_PATH(NSSystemDomainMask, gnustepSystemAdminTools, part);
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
AUTORELEASE (paths);
|
|
|
|
return paths;
|
|
|
|
}
|