]> err.no Git - sope/blob - GNUstep-reset.sh
83739487c4b7d03ab99687d302245f1c93e42662
[sope] / GNUstep-reset.sh
1 #! /bin/echo This file must be sourced inside (ba)sh using: .
2 #
3 #   GNUstep-reset.sh
4 #
5 #   Shell script resetting the GNUstep environment variables
6 #
7 #   Copyright (C) 2002 Free Software Foundation, Inc.
8 #
9 #   Author:  Nicola Pero <n.pero@mi.flashnet.it>
10 #
11 #   This file is part of the GNUstep Makefile Package.
12 #
13 #   This library is free software; you can redistribute it and/or
14 #   modify it under the terms of the GNU General Public License
15 #   as published by the Free Software Foundation; either version 2
16 #   of the License, or (at your option) any later version.
17 #   
18 #   You should have received a copy of the GNU General Public
19 #   License along with this library; see the file COPYING.LIB.
20 #   If not, write to the Free Software Foundation,
21 #   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #
23
24 # This file is used to reset your environment.  This is needed if you
25 # want to change LIBRARY_COMBO.  You first reset your environment, then
26 # set a new LIBRARY_COMBO variable, then source GNUstep.sh again.
27
28 # This file resets variables in reverse order as they are set in the
29 # GNUstep.sh file.
30
31 # This function resets a path.
32 # The only argument is the name of the path variable to be reset.  All
33 # paths beginning with GNUSTEP_SYSTEM_ROOT, GNUSTEP_LOCAL_ROOT,
34 # GNUSTEP_NETWORK_ROOT and GNUSTEP_USER_ROOT are removed from the path
35 # variable (yes, we are rather crude).  All other paths are kept
36 # unchanged.
37 function reset_path 
38 {
39   # Declare local variables
40   local original_path tmp_IFS temp_path dir gnustep_dir found
41
42   # NB: We need to use eval because we want to access a variable
43   # whose name is another variable!
44   original_path=$(eval echo \$$1)
45   tmp_IFS="$IFS"
46   IFS=:
47   temp_path=
48   # Loop on the paths
49   for dir in $original_path; do
50     # For each of them, keep it only if it's not beginning with
51     # a path in GNUSTEP_PATHLIST as prefix
52     found=no;
53     for gnustep_dir in $GNUSTEP_PATHLIST; do
54       if [ -n "$gnustep_dir" ]; then
55         case "$dir" in
56           $gnustep_dir*)  found=yes; break;;
57           *);;
58         esac;
59       fi;
60     done;
61     if [ "$found" = "no" ]; then
62       if [ -z "$temp_path" ]; then
63         temp_path="$dir"
64       else
65         temp_path="$temp_path:$dir"
66       fi;
67     fi
68   done
69   IFS="$tmp_IFS"
70
71   # Not set the path variable.
72   eval "$1=\$temp_path"
73   # Export it only if non empty, otherwise remove it completely from
74   # the shell environment.
75   temp_path=`eval echo \$"$1"`
76   if [ -z "$temp_path" ]; then
77     eval "unset $1"
78   else
79     eval "export $1"
80   fi
81 }
82
83 reset_path CLASSPATH
84 reset_path GUILE_LOAD_PATH
85 reset_path LD_LIBRARY_PATH
86 reset_path DYLD_LIBRARY_PATH
87 reset_path DYLD_FRAMEWORK_PATH
88 reset_path PATH
89
90 # Make sure we destroy the reset_path function after using it - we don't
91 # want to pollute the environment with it.
92 unset -f reset_path
93
94 unset GNUSTEP_PATHLIST
95 unset GNUSTEP_USER_ROOT
96 unset GNUSTEP_HOST_OS
97 unset GNUSTEP_HOST_VENDOR
98 unset GNUSTEP_HOST_CPU
99 unset GNUSTEP_HOST
100 unset GNUSTEP_NETWORK_ROOT
101 unset GNUSTEP_LOCAL_ROOT
102 unset GNUSTEP_MAKEFILES
103 unset GNUSTEP_FLATTENED
104 unset GNUSTEP_SYSTEM_ROOT
105 unset GNUSTEP_ROOT
106 unset LIBRARY_COMBO