From 7308242498b7a7daf956691dbced4ab71a2e7c0d Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Mon, 15 Mar 2010 15:15:38 +0100
Subject: [PATCH] BUG: prefs.sh was sourced in the wrong position in
 etc/{bashrc,cshrc}

---
 etc/apps/paraview3/bashrc |  4 +-
 etc/apps/paraview3/cshrc  |  6 +--
 etc/bashrc                | 83 ++++++++++++++++-----------------------
 etc/cshrc                 | 65 +++++++++++++++---------------
 4 files changed, 71 insertions(+), 87 deletions(-)

diff --git a/etc/apps/paraview3/bashrc b/etc/apps/paraview3/bashrc
index 6d64ee1be41..2062c389e0b 100644
--- a/etc/apps/paraview3/bashrc
+++ b/etc/apps/paraview3/bashrc
@@ -35,7 +35,7 @@
 #------------------------------------------------------------------------------
 
 # clean the PATH
-cleanedEnv=`$WM_PROJECT_DIR/bin/foamCleanPath "$PATH" "$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/cmake- $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/paraview-"` && PATH="$cleanedEnv"
+cleaned=`$WM_PROJECT_DIR/bin/foamCleanPath "$PATH" "$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/cmake- $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/paraview-"` && PATH="$cleaned"
 
 # determine the cmake to be used
 unset CMAKE_HOME
@@ -92,5 +92,5 @@ else
 fi
 
 
-unset cleanedEnv cmake paraviewInstDir paraviewPython
+unset cleaned cmake paraviewInstDir paraviewPython
 # -----------------------------------------------------------------------------
diff --git a/etc/apps/paraview3/cshrc b/etc/apps/paraview3/cshrc
index 70b296cce93..49a874c3cd6 100644
--- a/etc/apps/paraview3/cshrc
+++ b/etc/apps/paraview3/cshrc
@@ -35,8 +35,8 @@
 #------------------------------------------------------------------------------
 
 # clean the PATH
-set cleanedEnv=`$WM_PROJECT_DIR/bin/foamCleanPath -space "$path" "$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/cmake- $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/paraview-"`
-if ( $status == 0 ) set path=($cleanedEnv)
+set cleaned=`$WM_PROJECT_DIR/bin/foamCleanPath -space "$path" "$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/cmake- $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/paraview-"`
+if ( $status == 0 ) set path=($cleaned)
 
 # determine the cmake to be used
 unsetenv CMAKE_HOME
@@ -89,5 +89,5 @@ else
 endif
 
 
-unset cleanedEnv cmake paraviewInstDir paraviewPython
+unset cleaned cmake paraviewInstDir paraviewPython
 # -----------------------------------------------------------------------------
diff --git a/etc/bashrc b/etc/bashrc
index c5a42761fcb..d15c5324d56 100644
--- a/etc/bashrc
+++ b/etc/bashrc
@@ -2,7 +2,7 @@
 # =========                 |
 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
 #  \\    /   O peration     |
-#   \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
+#   \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
 # License
@@ -36,13 +36,13 @@ export WM_PROJECT=OpenFOAM
 [ -z "$WM_PROJECT_VERSION" ] && export WM_PROJECT_VERSION=1.6
 
 ################################################################################
-# USER EDITABLE PART
+# USER EDITABLE PART. Note changes made here may be lost with the next upgrade
 #
 # either set $FOAM_INST_DIR before sourcing this file or set
 #    $foamInstall below to where OpenFOAM is installed
 #
-# Location of FOAM installation
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# Location of the OpenFOAM installation
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 foamInstall=$HOME/$WM_PROJECT
 # foamInstall=~$WM_PROJECT
 # foamInstall=/usr/local/$WM_PROJECT
@@ -54,26 +54,6 @@ foamInstall=$HOME/$WM_PROJECT
 # note the location for later use (eg, in job scripts)
 : ${FOAM_INST_DIR:=$foamInstall}; export FOAM_INST_DIR
 
-# Source files, possibly with some verbosity
-_foamSource()
-{
-   while [ $# -ge 1 ]
-   do
-      [ "$FOAM_VERBOSE" -a "$PS1" ] && echo "Sourcing: $1"
-      . $1
-      shift
-   done
-}
-
-# Add in user or site preset preferences.
-foamPrefs=`$WM_PROJECT_DIR/bin/foamEtcFile prefs.sh`
-if [ $? -eq 0 ]
-then
-    _foamSource $foamPrefs
-fi
-unset foamPrefs
-
-
 # The old dirs to be cleaned from the various environment variables
 # - remove anything under top-level directory.
 # NB: the WM_PROJECT_INST_DIR might not be identical between versions
@@ -90,12 +70,28 @@ export WM_PROJECT_INST_DIR=$FOAM_INST_DIR
 export WM_PROJECT_DIR=$WM_PROJECT_INST_DIR/$WM_PROJECT-$WM_PROJECT_VERSION
 export WM_PROJECT_USER_DIR=$HOME/$WM_PROJECT/$USER-$WM_PROJECT_VERSION
 
-
 # Location of third-party software
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 export WM_THIRD_PARTY_DIR=$WM_PROJECT_INST_DIR/ThirdParty-$WM_PROJECT_VERSION
 
 
+# Source files, possibly with some verbosity
+_foamSource()
+{
+   while [ $# -ge 1 ]
+   do
+      [ "$FOAM_VERBOSE" -a "$PS1" ] && echo "Sourcing: $1"
+      . $1
+      shift
+   done
+}
+
+
+# Add in preset user or site preferences:
+foamPrefs=`$WM_PROJECT_DIR/bin/foamEtcFile prefs.sh` && _foamSource $foamPrefs
+unset foamPrefs
+
+
 # Operating System/Platform
 # ~~~~~~~~~~~~~~~~~~~~~~~~~
 # WM_OSTYPE = POSIX | ????
@@ -106,8 +102,7 @@ export WM_THIRD_PARTY_DIR=$WM_PROJECT_INST_DIR/ThirdParty-$WM_PROJECT_VERSION
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 : ${WM_COMPILER:=Gcc}; export WM_COMPILER
 
-export WM_COMPILER_ARCH=
-export WM_COMPILER_LIB_ARCH=
+unset WM_COMPILER_ARCH WM_COMPILER_LIB_ARCH
 
 
 # Compilation options (architecture, precision, optimised, debug or profiling)
@@ -225,32 +220,22 @@ esac
 
 # Clean standard environment variables (PATH, LD_LIBRARY_PATH, MANPATH)
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-cleanProg=$WM_PROJECT_DIR/bin/foamCleanPath
+foamClean=$WM_PROJECT_DIR/bin/foamCleanPath
 
 #- Clean PATH
-cleanedEnv=`$cleanProg "$PATH" "$foamOldDirs"` && PATH="$cleanedEnv"
+cleaned=`$foamClean "$PATH" "$foamOldDirs"` && PATH="$cleaned"
 
 #- Clean LD_LIBRARY_PATH
-cleanedEnv=`$cleanProg "$LD_LIBRARY_PATH" "$foamOldDirs"` && LD_LIBRARY_PATH="$cleanedEnv"
+cleaned=`$foamClean "$LD_LIBRARY_PATH" "$foamOldDirs"` && LD_LIBRARY_PATH="$cleaned"
 
 #- Clean MANPATH
-cleanedEnv=`$cleanProg "$MANPATH" "$foamCleanDirs"` && MANPATH="$cleanedEnv"
+cleaned=`$foamClean "$MANPATH" "$foamOldDirs"` && MANPATH="$cleaned"
 
 export PATH LD_LIBRARY_PATH MANPATH
 
+
 # Source project setup files
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~
-_foamSource()
-{
-   while [ $# -ge 1 ]
-   do
-      [ "$FOAM_VERBOSE" -a "$PS1" ] && echo "Sourcing: $1"
-      . $1
-      shift
-   done
-}
-
-
 _foamSource $WM_PROJECT_DIR/etc/settings.sh
 _foamSource $WM_PROJECT_DIR/etc/aliases.sh
 
@@ -264,27 +249,27 @@ _foamSource $WM_PROJECT_DIR/etc/apps/ensight/bashrc
 # Clean environment paths again. Only remove duplicates
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 #- Clean PATH
-cleanedEnv=`$cleanProg "$PATH"` && PATH="$cleanedEnv"
+cleaned=`$foamClean "$PATH"` && PATH="$cleaned"
 
 #- Clean LD_LIBRARY_PATH
-cleanedEnv=`$cleanProg "$LD_LIBRARY_PATH"` && LD_LIBRARY_PATH="$cleanedEnv"
+cleaned=`$foamClean "$LD_LIBRARY_PATH"` && LD_LIBRARY_PATH="$cleaned"
 
-#- Clean MANPATH
-cleanedEnv=`$cleanProg "$MANPATH"` && MANPATH="$cleanedEnv:"
+#- Clean MANPATH (trailing ':' to find system pages)
+cleaned=`$foamClean "$MANPATH"`: && MANPATH="$cleaned"
 
 export PATH LD_LIBRARY_PATH MANPATH
 
 #- Clean LD_PRELOAD
-if [ "$LD_PRELOAD" != "" ]
+if [ -n "$LD_PRELOAD" ]
 then
-    cleanedEnv=`$cleanProg "$LD_PRELOAD"` && LD_PRELOAD="$cleanedEnv"
+    cleaned=`$foamClean "$LD_PRELOAD"` && LD_PRELOAD="$cleaned"
     export LD_PRELOAD
 fi
 
 
 # cleanup environment:
 # ~~~~~~~~~~~~~~~~~~~~
-unset cleanedEnv cleanProg foamInstall foamOldDirs
+unset cleaned foamClean foamInstall foamOldDirs
 unset _foamSource
 
 # -----------------------------------------------------------------------------
diff --git a/etc/cshrc b/etc/cshrc
index e37bac6cbbc..96963952fa0 100644
--- a/etc/cshrc
+++ b/etc/cshrc
@@ -2,7 +2,7 @@
 # =========                 |
 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
 #  \\    /   O peration     |
-#   \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
+#   \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
 # License
@@ -35,13 +35,13 @@ setenv WM_PROJECT OpenFOAM
 if ( ! $?WM_PROJECT_VERSION ) setenv WM_PROJECT_VERSION 1.6
 
 ################################################################################
-# USER EDITABLE PART
+# USER EDITABLE PART. Note changes made here may be lost with the next upgrade
 #
 #    either setenv FOAM_INST_DIR before sourcing this file or set
 #    foamInstall below to where OpenFOAM is installed
 #
-# Location of FOAM installation
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# Location of the OpenFOAM installation
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 set foamInstall = $HOME/$WM_PROJECT
 # set foamInstall = ~$WM_PROJECT
 # set foamInstall = /usr/local/$WM_PROJECT
@@ -53,15 +53,6 @@ set foamInstall = $HOME/$WM_PROJECT
 # note the location for later use (eg, in job scripts)
 if ( ! $?FOAM_INST_DIR ) setenv FOAM_INST_DIR $foamInstall
 
-# Source files, possibly with some verbosity
-alias _foamSource 'if ($?FOAM_VERBOSE && $?prompt) echo "Sourcing: \!*"; source \!*'
-
-# Add in user or site preset preferences.
-set foamPrefs=`$WM_PROJECT_DIR/bin/foamEtcFile prefs.csh`
-if ( $status == 0 ) _foamSource $foamPrefs
-unset foamPrefs
-
-
 # The old dirs to be cleaned from the various environment variables
 # - remove anything under top-level directory.
 # NB: the WM_PROJECT_INST_DIR might not be identical between versions
@@ -73,12 +64,20 @@ setenv WM_PROJECT_INST_DIR $FOAM_INST_DIR
 setenv WM_PROJECT_DIR $WM_PROJECT_INST_DIR/$WM_PROJECT-$WM_PROJECT_VERSION
 setenv WM_PROJECT_USER_DIR $HOME/$WM_PROJECT/$LOGNAME-$WM_PROJECT_VERSION
 
-
 # Location of third-party software
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 setenv WM_THIRD_PARTY_DIR $WM_PROJECT_INST_DIR/ThirdParty-$WM_PROJECT_VERSION
 
 
+# Source files, possibly with some verbosity
+alias _foamSource 'if ($?FOAM_VERBOSE && $?prompt) echo "Sourcing: \!*"; source \!*'
+
+# Add in preset user or site preferences:
+set foamPrefs=`$WM_PROJECT_DIR/bin/foamEtcFile prefs.csh`
+if ( $status == 0 ) _foamSource $foamPrefs
+unset foamPrefs
+
+
 # Operating System/Platform
 # ~~~~~~~~~~~~~~~~~~~~~~~~~
 # WM_OSTYPE = POSIX | ????
@@ -210,29 +209,26 @@ endsw
 
 # Clean standard environment variables (path/PATH, LD_LIBRARY_PATH, MANPATH)
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-set cleanProg=$WM_PROJECT_DIR/bin/foamCleanPath
+set foamClean=$WM_PROJECT_DIR/bin/foamCleanPath
 
-if (! $?LD_LIBRARY_PATH ) then
-    setenv LD_LIBRARY_PATH ''
-endif
-if (! $?MANPATH) then
-    setenv MANPATH ''
-endif
+if (! $?LD_LIBRARY_PATH ) setenv LD_LIBRARY_PATH ''
+if (! $?MANPATH) setenv MANPATH ''
 
 #- Clean path/PATH
-set cleanedEnv=`$cleanProg -space "$path" "$foamOldDirs"`
-if ( $status == 0 ) set path=($cleanedEnv)
+set cleaned=`$foamClean -space "$path" "$foamOldDirs"`
+if ( $status == 0 ) set path=($cleaned)
 
 #- Clean LD_LIBRARY_PATH
-setenv LD_LIBRARY_PATH `$cleanProg "$LD_LIBRARY_PATH" "$foamOldDirs"`
+set cleaned=`$foamClean "$LD_LIBRARY_PATH" "$foamOldDirs"`
+if ( $status == 0 ) setenv LD_LIBRARY_PATH $cleaned
 
 #- Clean MANPATH
-setenv MANPATH `$cleanProg "$MANPATH" "$foamOldDirs"`
+set cleaned=`$foamClean "$MANPATH" "$foamOldDirs"`
+if ( $status == 0 ) setenv MANPATH $cleaned
 
 
 # Source project setup files
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~
-
 _foamSource $WM_PROJECT_DIR/etc/settings.csh
 _foamSource $WM_PROJECT_DIR/etc/aliases.csh
 
@@ -245,23 +241,26 @@ _foamSource $WM_PROJECT_DIR/etc/apps/paraview3/cshrc
 # Clean environment paths again. Only remove duplicates
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 #- Clean path/PATH
-set cleanedEnv=`$cleanProg -space "$colonPath"`
-if ( $status == 0 ) set path=($cleanedEnv)
+set cleaned=`$foamClean -space "$path"`
+if ( $status == 0 ) set path=($cleaned)
 
 #- Clean LD_LIBRARY_PATH
-setenv LD_LIBRARY_PATH `$cleanProg "$LD_LIBRARY_PATH"`
+set cleaned=`$foamClean "$LD_LIBRARY_PATH"`
+if ( $status == 0 ) setenv LD_LIBRARY_PATH $cleaned
 
-#- Clean MANPATH
-setenv MANPATH `$cleanProg "$MANPATH"`:
+#- Clean MANPATH (trailing ':' to find system pages)
+set cleaned=`$foamClean "$MANPATH"`:
+if ( $status == 0 ) setenv MANPATH "$cleaned"
 
 #- Clean LD_PRELOAD
 if ( $?LD_PRELOAD ) then
-    setenv LD_PRELOAD `$cleanProg "$LD_PRELOAD"`
+    set cleaned=`$foamClean "$LD_PRELOAD"`
+    if ( $status == 0 ) setenv LD_PRELOAD $cleaned
 endif
 
 # cleanup environment:
 # ~~~~~~~~~~~~~~~~~~~~
-unset cleanedEnv cleanProg colonPath foamInstall foamOldDirs
+unset cleaned foamClean foamInstall foamOldDirs
 unalias _foamSource
 
 # -----------------------------------------------------------------------------
-- 
GitLab