Get rid of user_home in favour of configuration files

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/tools/make/trunk@21818 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Nicola Pero 2005-10-13 02:42:10 +00:00
parent f96d467f3f
commit afd1d69f43
6 changed files with 195 additions and 501 deletions

View file

@ -1,3 +1,16 @@
2005-10-13 Nicola Pero <n.pero@mi.flashnet.it>
* GNUstep.sh.in: Read system, local, network, user paths from
configuration files and use the configuration files settings in
preference to the hardcoded ones.
* GNUstep.csh.in: Same changes, where we use sed to convert on the
fly the sh syntax of config files to csh syntax, then we eval the
result.
* GNUmakefile.in: Do not compile, install and clean user_home.
* user_home.c: Removed.
* GNUstep-reset.sh (GNUSTEP_USER_CONFIG_FILE, GNUSTEP_USER_DIR,
GNUSTEP_USER_DEFAULTS_DIR, GNUSTEP_CONFIG_FILE): Unset.
2005-10-13 Nicola Pero <n.pero@mi.flashnet.it>
* GNUmakefile.in (GNUSTEP_CONFIG_FILE): Fixed replacing this variable.

View file

@ -105,7 +105,7 @@ INSTANCE_SHARED_MAKE_FILES = bundle.make headers.make java.make \
INSTANCE_DOC_MAKE_FILES = autogsdoc.make gsdoc.make install_files.make \
javadoc.make latex.make texi.make
all: generated-files which_lib$(EXEEXT) user_home$(EXEEXT)
all: generated-files which_lib$(EXEEXT)
# Please note that you should use a bit of care in the following rule,
# because it must work in a directory which is not the source
@ -115,10 +115,6 @@ all: generated-files which_lib$(EXEEXT) user_home$(EXEEXT)
which_lib$(EXEEXT): which_lib.c config.h
$(CC) @CFLAGS@ -Wall -I. -o $@ $<
user_home$(EXEEXT): user_home.c config.h
$(CC) @CFLAGS@ -DGNUSTEP_SYSTEM_ROOT=$(GNUSTEP_SYSTEM_ROOT) \
-Wall -I. -o $@ $<
ifeq ($(messages),yes)
EC =
else
@ -151,8 +147,6 @@ install: all @GNUSTEP_MOVE_OBSOLETE@
-$(EC) rm -f $(GNUSTEP_SYSTEM_ROOT)/Makefiles
$(EC)(echo "Installing gnustep-make support software"; \
$(INSTALL_PROGRAM) -m 755 which_lib$(EXEEXT) \
$(makedir)/$(GNUSTEP_TARGET_DIR); \
$(INSTALL_PROGRAM) -m 755 user_home$(EXEEXT) \
$(makedir)/$(GNUSTEP_TARGET_DIR))
$(EC)(for f in config.guess config.sub install-sh mkinstalldirs \
clean_cpu.sh clean_os.sh \
@ -161,7 +155,7 @@ install: all @GNUSTEP_MOVE_OBSOLETE@
ld_lib_path.csh relative_path.sh strip_makefiles.sh; do \
$(INSTALL_PROGRAM) -m 755 $(srcdir)/$$f $(makedir); \
done)
$(EC)($(INSTALL_PROGRAM) -m 755 GNUstep.sh $(makedir); \
$(EC)($(INSTALL_PROGRAM) -m 755 GNUstep.sh $(makedir); \
$(INSTALL_PROGRAM) -m 755 GNUstep.csh $(makedir); \
$(INSTALL_PROGRAM) -m 755 fixpath.sh $(makedir); \
$(INSTALL_PROGRAM) -m 755 openapp $(tooldir); \
@ -209,7 +203,6 @@ install: all @GNUSTEP_MOVE_OBSOLETE@
uninstall:
rm -f $(makedir)/$(GNUSTEP_TARGET_DIR)/which_lib$(EXEEXT)
rm -f $(makedir)/$(GNUSTEP_TARGET_DIR)/user_home$(EXEEXT)
for f in config.guess config.sub install-sh mkinstalldirs \
clean_cpu.sh clean_os.sh \
clean_vendor.sh cpu.sh ld_lib_path.sh os.sh \
@ -253,7 +246,7 @@ uninstall:
# To really uninstall all of GNUstep, a 'rm -Rf ${GNUSTEP_ROOT}' should do.
clean:
rm -f *~ which_lib$(EXEEXT) user_home$(EXEEXT) \
rm -f *~ which_lib$(EXEEXT) \
Master/*~ Instance/*~ Instance/Shared/*~
distclean: clean

View file

@ -105,3 +105,8 @@ unset GNUSTEP_FLATTENED
unset GNUSTEP_SYSTEM_ROOT
unset GNUSTEP_ROOT
unset LIBRARY_COMBO
unset GNUSTEP_CONFIG_FILE
unset GNUSTEP_USER_CONFIG_FILE
unset GNUSTEP_USER_DIR
unset GNUSTEP_USER_DEFAULTS_DIR

View file

@ -4,7 +4,7 @@
#
# Shell initialization for the GNUstep environment.
#
# Copyright (C) 1998-2002 Free Software Foundation, Inc.
# Copyright (C) 1998-2005 Free Software Foundation, Inc.
#
# Author: Scott Christley <scottc@net-community.com>
# Author: Adam Fedor <fedor@gnu.org>
@ -27,17 +27,113 @@
#
# Set the GNUstep system root and local root
#
## FIXME - those should be taken from GNUstep.conf
setenv GNUSTEP_SYSTEM_ROOT "@GNUSTEP_SYSTEM_ROOT@"
#
# Read our configuration files
#
# Determine the location of the system configuration file
if ( ! ${?GNUSTEP_CONFIG_FILE} ) then
setenv GNUSTEP_CONFIG_FILE "@GNUSTEP_CONFIG_FILE@"
endif
# Determine the location of the user configuration file
if ( ! ${?GNUSTEP_USER_CONFIG_FILE} ) then
setenv GNUSTEP_USER_CONFIG_FILE "@GNUSTEP_USER_CONFIG_FILE@"
endif
# Read the system configuration file
if ( -e "${GNUSTEP_CONFIG_FILE}" ) then
#
# Convert the config file from sh syntax to csh syntax, and execute it.
#
# We want to convert every line of the type ^xxx=yyy$ into setenv xxx yyy;
# and ignore any other line.
#
# This sed expression will first delete all lines that don't match
# the pattern ^[^#=][^#=]*=.*$ -- which means "start of line (^),
# followed by a character that is not # and not = ([^#=]), followed
# by 0 or more characters that are not # and not = ([^#=]*),
# followed by a = (=), followed by some characters until end of the
# line (.*$). It will then replace each occurrence of the same
# pattern (where the first and second relevant parts are now tagged
# -- that's what the additional \(...\) do) with 'setenv \1 \2'.
#
# The result of all this is ... something that we want to execute!
# We use eval to execute the results of `...`.
#
# Please note that ! must always be escaped in csh, which is why we
# write \\!
#
# Also note that we add a ';' at the end of each setenv command so
# that we can pipe all the commands through a single eval.
#
eval `sed -e '/^[^#=][^#=]*=.*$/\\!d' -e 's/^\([^#=][^#=]*\)=\(.*\)$/setenv \1 \2;/' "${GNUSTEP_CONFIG_FILE}"`
endif
# FIXME: determining GNUSTEP_HOME
set GNUSTEP_HOME = ~
# Read the user configuration file ... unless it is disabled (ie, set
# to an empty string)
if ( ${?GNUSTEP_USER_CONFIG_FILE} ) then
switch ("${GNUSTEP_USER_CONFIG_FILE}")
case /*: # An absolute path
if ( -e "${GNUSTEP_USER_CONFIG_FILE}" ) then
# See above for an explanation of the sed expression
eval `sed -e '/^[^#=][^#=]*=.*$/\\!d' -e 's/^\([^#=][^#=]*\)=\(.*\)$/setenv \1 \2;/' "${GNUSTEP_USER_CONFIG_FILE}"``
endif
breaksw
default: # Something else
if ( -e "${GNUSTEP_HOME}/${GNUSTEP_USER_CONFIG_FILE}" ) then
eval `sed -e '/^[^#=][^#=]*=.*$/\\!d' -e 's/^\([^#=][^#=]*\)=\(.*\)$/setenv \1 \2;/' "${GNUSTEP_HOME}/${GNUSTEP_USER_CONFIG_FILE}"`
endif
breaksw
endsw
endif
# Now, set any essential variable (that is not already set) to the
# built-in values.
if ( ! ${?GNUSTEP_SYSTEM_ROOT} ) then
setenv GNUSTEP_SYSTEM_ROOT "@GNUSTEP_SYSTEM_ROOT@"
endif
if ( ! ${?GNUSTEP_LOCAL_ROOT} ) then
setenv GNUSTEP_LOCAL_ROOT "@GNUSTEP_LOCAL_ROOT@"
endif
if ( ! ${?GNUSTEP_NETWORK_ROOT} ) then
setenv GNUSTEP_NETWORK_ROOT "@GNUSTEP_NETWORK_ROOT@"
endif
setenv GNUSTEP_FLATTENED "@GNUSTEP_FLATTENED@"
if ( ! ${?LIBRARY_COMBO} ) then
setenv LIBRARY_COMBO "@ac_cv_library_combo@"
endif
setenv GNUSTEP_LOCAL_ROOT "@GNUSTEP_LOCAL_ROOT@"
setenv GNUSTEP_NETWORK_ROOT "@GNUSTEP_NETWORK_ROOT@"
if ( ! ${?GNUSTEP_MAKEFILES} ) then
setenv GNUSTEP_MAKEFILES "${GNUSTEP_SYSTEM_ROOT}/Library/Makefiles"
endif
setenv GNUSTEP_MAKEFILES "@GNUSTEP_MAKEFILES@"
if ( ! ${?GNUSTEP_USER_DIR} ) then
setenv GNUSTEP_USER_DIR "@GNUSTEP_USER_DIR@"
endif
#
# Set GNUSTEP_USER_ROOT which is the variable used in practice
#
switch ("${GNUSTEP_USER_DIR}")
case /*: # An absolute path
setenv GNUSTEP_USER_ROOT "${GNUSTEP_USER_DIR}"
breaksw
default: # Something else
setenv GNUSTEP_USER_ROOT "${GNUSTEP_HOME}/${GNUSTEP_USER_DIR}"
breaksw
endsw
# No longer needed
unset GNUSTEP_HOME
if ( "@GNUSTEP_MULTI_PLATFORM@" == "" ) then
setenv GNUSTEP_HOST "@target@"
@ -71,12 +167,6 @@ if ( ! ${?GNUSTEP_HOST_OS} ) then
setenv GNUSTEP_HOST_OS `${GNUSTEP_MAKEFILES}/clean_os.sh ${GNUSTEP_HOST_OS}`
endif
if ( "${GNUSTEP_FLATTENED}" == "" ) then
setenv GNUSTEP_USER_ROOT `${GNUSTEP_MAKEFILES}/${GNUSTEP_HOST_CPU}/${GNUSTEP_HOST_OS}/user_home user`
else
setenv GNUSTEP_USER_ROOT `${GNUSTEP_MAKEFILES}/user_home user`
endif
#
# Add the GNUstep tools directories to the path
#

View file

@ -4,7 +4,7 @@
#
# Shell initialization for the GNUstep environment.
#
# Copyright (C) 1997-2002 Free Software Foundation, Inc.
# Copyright (C) 1997-2005 Free Software Foundation, Inc.
#
# Author: Scott Christley <scottc@net-community.com>
# Author: Adam Fedor <fedor@gnu.org>
@ -73,22 +73,85 @@ fi
#
#
# FIXME - Paths should not be hardcoded in here. We need to include GNUstep.conf
# instead where the paths are configured!
# Read our configuration files
#
GNUSTEP_SYSTEM_ROOT=@GNUSTEP_SYSTEM_ROOT@
# Determine the location of the system configuration file
if [ -z "$GNUSTEP_CONFIG_FILE" ]; then
GNUSTEP_CONFIG_FILE=@GNUSTEP_CONFIG_FILE@
fi
# Determine the location of the user configuration file
if [ -z "$GNUSTEP_USER_CONFIG_FILE" ]; then
GNUSTEP_USER_CONFIG_FILE=@GNUSTEP_USER_CONFIG_FILE@
fi
# Read the system configuration file
if [ -f "$GNUSTEP_CONFIG_FILE" ]; then
. "$GNUSTEP_CONFIG_FILE"
fi
# FIXME: determining GNUSTEP_HOME
GNUSTEP_HOME=~
# Read the user configuration file ... unless it is disabled (ie, set
# to an empty string)
if [ -n "$GNUSTEP_USER_CONFIG_FILE" ]; then
case "$GNUSTEP_USER_CONFIG_FILE" in
/*) # An absolute path
if [ -f "$GNUSTEP_USER_CONFIG_FILE" ]; then
. "$GNUSTEP_USER_CONFIG_FILE"
fi;;
*) # Something else
if [ -f "$GNUSTEP_HOME/$GNUSTEP_USER_CONFIG_FILE" ]; then
. "$GNUSTEP_HOME/$GNUSTEP_USER_CONFIG_FILE"
fi;;
esac
fi
# Now, set any essential variable (that is not already set) to the
# built-in values.
if [ -z "$GNUSTEP_SYSTEM_ROOT" ]; then
GNUSTEP_SYSTEM_ROOT=@GNUSTEP_SYSTEM_ROOT@
fi
if [ -z "$GNUSTEP_LOCAL_ROOT" ]; then
GNUSTEP_LOCAL_ROOT=@GNUSTEP_LOCAL_ROOT@
fi
if [ -z "$GNUSTEP_NETWORK_ROOT" ]; then
GNUSTEP_NETWORK_ROOT=@GNUSTEP_NETWORK_ROOT@
fi
export GNUSTEP_SYSTEM_ROOT GNUSTEP_LOCAL_ROOT GNUSTEP_NETWORK_ROOT
GNUSTEP_FLATTENED=@GNUSTEP_FLATTENED@
if [ -z "$LIBRARY_COMBO" ]; then
LIBRARY_COMBO=@ac_cv_library_combo@
fi
export GNUSTEP_SYSTEM_ROOT GNUSTEP_FLATTENED LIBRARY_COMBO
export GNUSTEP_FLATTENED LIBRARY_COMBO
GNUSTEP_MAKEFILES=@GNUSTEP_MAKEFILES@
if [ -z "$GNUSTEP_MAKEFILES" ]; then
GNUSTEP_MAKEFILES=$GNUSTEP_SYSTEM_ROOT/Library/Makefiles
fi
export GNUSTEP_MAKEFILES
GNUSTEP_LOCAL_ROOT=@GNUSTEP_LOCAL_ROOT@
GNUSTEP_NETWORK_ROOT=@GNUSTEP_NETWORK_ROOT@
export GNUSTEP_LOCAL_ROOT GNUSTEP_NETWORK_ROOT
if [ -z "$GNUSTEP_USER_DIR" ]; then
GNUSTEP_USER_DIR=@GNUSTEP_USER_DIR@
fi
#
# Set GNUSTEP_USER_ROOT which is the variable used in practice
#
case "$GNUSTEP_USER_DIR" in
/*) # An absolute path
GNUSTEP_USER_ROOT="$GNUSTEP_USER_DIR";;
*) # Something else
GNUSTEP_USER_ROOT="$GNUSTEP_HOME/$GNUSTEP_USER_DIR";;
esac
# No longer needed
unset GNUSTEP_HOME
# If multi-platform support is disabled, just use the hardcoded cpu,
# vendor and os determined when gnustep-make was configured. The
@ -136,17 +199,6 @@ fi
export GNUSTEP_HOST GNUSTEP_HOST_CPU GNUSTEP_HOST_VENDOR GNUSTEP_HOST_OS
#
# Ask the user_home tool for the root path.
#
if [ -z "$GNUSTEP_FLATTENED" ]; then
GNUSTEP_USER_ROOT=`$GNUSTEP_MAKEFILES/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/user_home user`
else
GNUSTEP_USER_ROOT=`$GNUSTEP_MAKEFILES/user_home user`
fi
export GNUSTEP_USER_ROOT
#
# GNUSTEP_PATHLIST is like an abstract path-like shell
# variable, which can be used to search the gnustep directories - and

View file

@ -1,459 +0,0 @@
/*
user_home.c
Copyright (C) 2002 Free Software Foundation, Inc.
Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Date: February 2002
This file is part of the GNUstep Makefile Package.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
You should have received a copy of the GNU General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include "config.h"
#ifdef __MINGW32__
#ifndef __MINGW__
#define __MINGW__
#endif
#ifndef __WIN32__
#define __WIN32__
#endif
#endif
#include <stdio.h>
#include <ctype.h>
#if defined(__MINGW__)
# include <windows.h>
#endif
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#if HAVE_STRING_H
# include <string.h>
#endif
#if HAVE_PWD_H
# include <pwd.h>
#endif
#define lowlevelstringify(X) #X
#define stringify(X) lowlevelstringify(X)
#define SEP "/"
/*
* This tool is intended to produce a definitive form of the
* user specific root directories for a GNUstep user. It must
* remain consistent with the code in the GNUstep base library
* which provides path information for all GNUstep applications.
*
*
* How to run this tool ...
*
* 1. With no arguments ... the tool should print the home directory of
* the current user to stdout.
*
* 2. With a 'user' argument ... the tool should print the
* GNUSTEP_USER_ROOT directory to stdout.
*
* 3. With a 'defaults' argument ... the tool should print the
* GNUSTEP_DEFAULTS_ROOT directory to stdout.
*
* Any other arguments will be ignored.
* On success the tool will terminate with an exit status of zero
* On failure, the tool will terminate with an exit status of one
* and will print an error message to stderr.
*/
/* NOTE FOR DEVELOPERS.
* If you change the behavior of this method you must also change
* NSUser.m in the base library package to match.
*/
int main (int argc, char** argv)
{
char buf0[1024];
char path[2048];
char home[2048];
char *loginName = 0;
enum { NONE, DEFS, USER } type = NONE;
#if defined(__MINGW__)
char buf1[1024];
int len0;
int len1;
#else
struct passwd *pw;
#endif
if (argc > 1)
{
if (strcmp(argv[1], "defaults") == 0)
{
type = DEFS;
}
else if (strcmp(argv[1], "user") == 0)
{
type = USER;
}
}
if (loginName == 0)
{
#if defined(__WIN32__)
/* The GetUserName function returns the current user name */
DWORD n = 1024;
len0 = GetEnvironmentVariable("LOGNAME", buf0, 1024);
if (len0 > 0 && len0 < 1024)
{
loginName = buf0;
loginName[len0] = '\0';
}
else if (GetUserName(buf0, &n))
{
loginName = buf0;
}
#else
#if HAVE_GETPWUID
#if HAVE_GETEUID
int uid = geteuid();
#else
int uid = getuid();
#endif /* HAVE_GETEUID */
struct passwd *pwent = getpwuid (uid);
loginName = pwent->pw_name;
#endif /* HAVE_GETPWUID */
#endif
if (loginName == 0)
{
fprintf(stderr, "Unable to determine current user name.\n");
return 1;
}
}
#if !defined(__MINGW__)
pw = getpwnam (loginName);
if (pw == 0)
{
fprintf(stderr, "Unable to locate home directory for '%s'\n", loginName);
return 1;
}
strncpy(home, pw->pw_dir, sizeof(home));
#else
home[0] = '\0';
/*
* The environment variable HOMEPATH holds the home directory
* for the user on Windows NT; Win95 has no concept of home.
* For OPENSTEP compatibility (and because USERPROFILE is usually
* unusable because it contains spaces), we use HOMEPATH in
* preference to USERPROFILE.
*/
len0 = GetEnvironmentVariable("HOMEPATH", buf0, 1024);
if (len0 > 0 && len0 < 1024)
{
buf0[len0] = '\0';
/*
* Only use HOMEDRIVE is HOMEPATH does not already contain drive.
*/
if (len0 < 2 || buf0[1] != ':')
{
len1 = GetEnvironmentVariable("HOMEDRIVE", buf1, 128);
if (len1 > 0 && len1 < 128)
{
buf1[len1] = '\0';
sprintf(home, "%s%s", buf1, buf0);
}
else
{
sprintf(home, "C:%s", buf0);
}
}
else
{
strcpy(home, buf0);
}
}
else
{
/* The environment variable USERPROFILE may hold the home directory
for the user on modern versions of windoze. */
len0 = GetEnvironmentVariable("USERPROFILE", buf0, 1024);
if (len0 > 0 && len0 < 1024)
{
buf0[len0] = '\0';
strcpy(home, buf0);
}
}
if (home[0] != '\0')
{
int i;
for (i = 0; i < strlen(home); i++)
{
if (isspace((unsigned int)home[i]))
{
/*
* GNU make doesn't handle spaces in paths.
* Broken, wrong and totally unfixable.
*/
fprintf(stderr, "Make cannot handle spaces in paths so the " \
"home directory '%s' may cause problems!\n", home);
break;
}
}
}
#endif
if (type == NONE)
{
strcpy(path, home);
}
else
{
FILE *fptr;
char *user = "";
char *defs = "";
int forceD = 0;
int forceU = 0;
#if defined (__MINGW32__)
len0 = GetEnvironmentVariable("GNUSTEP_SYSTEM_ROOT", buf0, sizeof(buf0));
if (len0 > 0)
{
strcpy(path, buf0);
}
#else
{
const char *gnustep_system_root = (const char*)getenv("GNUSTEP_SYSTEM_ROOT");
if (gnustep_system_root != 0)
{
strcpy(path, gnustep_system_root);
}
else
{
/* On my machine the strcpy was segfaulting when
* gnustep_system_root == 0. */
path[0] = '\0';
}
}
#endif
strcat(path, SEP);
strcat(path, ".GNUsteprc");
fptr = fopen(path, "r");
if (fptr != 0)
{
while (fgets(buf0, sizeof(buf0), fptr) != 0)
{
char *pos = strchr(buf0, '=');
char *key = buf0;
char *val;
if (pos != 0)
{
val = pos;
*val++ = '\0';
while (isspace((int)*key))
key++;
while (strlen(key) > 0 && isspace((int)key[strlen(key)-1]))
key[strlen(key)-1] = '\0';
while (isspace(*val))
val++;
while (strlen(val) > 0 && isspace((int)val[strlen(val)-1]))
val[strlen(val)-1] = '\0';
}
else
{
while (isspace((int)*key))
key++;
while (strlen(key) > 0 && isspace((int)key[strlen(key)-1]))
key[strlen(key)-1] = '\0';
val = "";
}
if (strcmp(key, "GNUSTEP_USER_ROOT") == 0)
{
if (*val == '~')
{
user = malloc(strlen(val) + strlen(home));
strcpy(user, home);
strcat(user, &val[1]);
}
else
{
user = malloc(strlen(val) + 1);
strcpy(user, val);
}
}
else if (strcmp(key, "GNUSTEP_DEFAULTS_ROOT") == 0)
{
if (*val == '~')
{
defs = malloc(strlen(val) + strlen(home));
strcpy(defs, home);
strcat(defs, &val[1]);
}
else
{
defs = malloc(strlen(val) + 1);
strcpy(defs, val);
}
}
else if (strcmp(key, "FORCE_USER_ROOT") == 0)
{
forceU = 1;
}
else if (strcmp(key, "FORCE_DEFAULTS_ROOT") == 0)
{
forceD = 1;
}
}
fclose(fptr);
}
if (*user == '\0' || forceU == 0 || *defs == '\0' || forceD == 0)
{
strcpy(path, home);
strcat(path, SEP);
strcat(path, ".GNUsteprc");
fptr = fopen(path, "r");
if (fptr != 0)
{
while (fgets(buf0, sizeof(buf0), fptr) != 0)
{
char *pos = strchr(buf0, '=');
if (pos != 0)
{
char *key = buf0;
char *val = pos;
*val++ = '\0';
while (isspace((int)*key))
key++;
while (strlen(key) > 0
&& isspace((int)key[strlen(key)-1]))
key[strlen(key)-1] = '\0';
while (isspace((int)*val))
val++;
while (strlen(val) > 0
&& isspace((int)val[strlen(val)-1]))
val[strlen(val)-1] = '\0';
if (strcmp(key, "GNUSTEP_USER_ROOT") == 0)
{
if (*user == '\0' || forceU == 0)
{
if (*val == '~')
{
user = malloc(strlen(val) + strlen(home));
strcpy(user, home);
strcat(user, &val[1]);
}
else
{
user = malloc(strlen(val) + 1);
strcpy(user, val);
}
}
}
else if (strcmp(key, "GNUSTEP_DEFAULTS_ROOT") == 0)
{
if (*defs == '\0' || forceD == 0)
{
if (*val == '~')
{
defs = malloc(strlen(val) + strlen(home));
strcpy(defs, home);
strcat(defs, &val[1]);
}
else
{
defs = malloc(strlen(val) + 1);
strcpy(defs, val);
}
}
}
}
}
fclose(fptr);
}
}
if (type == DEFS)
{
strcpy(path, defs);
if (*path == '\0')
{
strcpy(path, user);
}
}
else
{
strcpy(path, user);
}
if (*path == '\0')
{
strcpy(path, home);
strcat(path, SEP);
strcat(path, "GNUstep");
}
}
#if defined(__MINGW__)
/*
* We always want to use unix style paths.
*/
if (strlen(path) > 1 && path[1] == ':')
{
char *ptr = path;
while (*ptr != '\0')
{
if (*ptr == '\\')
{
*ptr = '/';
}
if (*ptr == '/' && ptr > path && ptr[-1] == '/')
{
memmove(ptr, &ptr[1], strlen(ptr)+1);
}
else
{
ptr++;
}
}
if (path[2] == '/' || path[2] == '\0')
{
path[1] = path[0];
}
else
{
memmove(&path[1], path, strlen(path)+1);
path[2] = '/';
}
path[0] = '/';
}
#endif
printf("%s", path);
return 0;
}