2 #------------------------------------------------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright held by original author
8 #------------------------------------------------------------------------------
10 # This file is part of OpenFOAM.
12 # OpenFOAM is free software; you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by the
14 # Free Software Foundation; either version 2 of the License, or (at your
15 # option) any later version.
17 # OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 # You should have received a copy of the GNU General Public License
23 # along with OpenFOAM; if not, write to the Free Software Foundation,
24 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 # Usage: foamCleanPath [-strip] path [wildcard] .. [wildcard]
32 # Prints its argument (which should be a ':' separated path)
34 # - duplicate elements
35 # - (if '-strip') non-accessible directories
36 # - elements whose start matches a wildcard
39 # - this routine will fail when directories have embedded spaces
40 # - false matches possible if a wildcard contains '.' (sed regex)
41 #------------------------------------------------------------------------------
42 if [ "$#" -lt 1 -o "$1" = "-h" -o "$1" = "-help" ]
45 Usage: ${0##*/} [-strip] path [wildcard] .. [wildcard]
47 Prints its argument (which should be a ':' separated list) cleansed from
49 - elements whose start matches one of the wildcard(s)
50 - (if '-strip') non-accessible directories
57 if [ "$1" = "-strip" ]
67 ##DEBUG echo "input>$dirList<" 1>&2
69 # preserve current IFS and split on whitespace
73 # "wildcard1 ... wildcardN" may have been passed as a single parameter
76 # strip out wildcards via sed
81 ##DEBUG echo "remove>$wildcard<" 1>&2
82 dirList
=`echo "$dirList" | sed -e "s@${wildcard}[^:]*:@@g"`
85 # split on ':' (and on space as well to avoid any surprises)
89 ##DEBUG echo "intermediate>$dirList<" 1>&2
91 # rebuild the list from scratch
95 ##DEBUG echo "check>$dir<" 1>&2
100 duplicate
=`echo " $dirList " | sed -ne "s@ $dir @DUP@p"`
102 if [ ! "$duplicate" ]
104 dirList
="$dirList $dir"
106 elif [ "$strip" != "true" ]
108 # Print non-existing directories if not in 'strip' mode.
109 dirList
="$dirList $dir"
113 # parse on whitespace
124 ##DEBUG echo "output>$dirList<" 1>&2
127 # -----------------------------------------------------------------------------