2 #------------------------------------------------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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 path [wildcard] .. [wildcard]
32 # Prints its argument (which should be a ':' separated path)
34 # - duplicate elements
35 # - 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##*/} path [wildcard] .. [wildcard]
47 Prints its argument (which should be a ':' separated list) cleansed from
49 - non-accessible directories
50 - elements whose start matches one of the wildcard(s)
58 ##DEBUG echo "input>$dirList<" 1>&2
60 # preserve current IFS and split on whitespace
64 # "wildcard1 ... wildcardN" may have been passed as a single parameter
67 # strip out wildcards via sed
72 ##DEBUG echo "remove>$wildcard<" 1>&2
73 dirList
=`echo "$dirList" | sed -e "s@${wildcard}[^:]*:@@g"`
76 # split on ':' (and on space as well to avoid any surprises)
80 ##DEBUG echo "intermediate>$dirList<" 1>&2
82 # rebuild the list from scratch
86 ##DEBUG echo "check>$dir<" 1>&2
91 duplicate
=`echo " $dirList " | sed -ne "s@ $dir @DUP@p"`
95 dirList
="$dirList $dir"
100 # parse on whitespace
111 ##DEBUG echo "output>$dirList<" 1>&2
114 # -----------------------------------------------------------------------------