Cosmetic improvements.
[OpenFOAM-1.6.x.git] / bin / rmdepold
blobc633ce04c3db9d8c2a8fe5da5ba2a7fed25dc6ca
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 # \\/ M anipulation |
8 #-------------------------------------------------------------------------------
9 # License
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
20 # for more details.
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
26 # Script
27 # rmdepold
29 # Description
30 # Usage: rmdepold [dir1 .. dirN]
32 # Remove *.dep files that are without a corresponding .C or .L file.
33 # This often occurs when a directory has been moved.
34 # - print questionable directory and the *.dep file
35 # - optionally remove empty directories
36 #------------------------------------------------------------------------------
37 usage() {
38 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
39 cat<<USAGE 1>&2
40 Usage: ${0##*/} [OPTION] [dir1 .. dirN]
41 options:
42 -rmdir find and remove empty directories (recursively)
44 Remove *.dep files that are without a corresponding .C or .L file.
45 This often occurs when a directory has been moved.
46 - print questionable directory and file
47 - optionally remove empty directories
49 USAGE
50 exit 1
53 unset optRmdir
55 # parse options
56 while [ "$#" -gt 0 ]
58 case "$1" in
59 -h | -help)
60 usage
62 -rmdir)
63 optRmdir=true
64 shift
66 -*)
67 usage "unknown option: '$*'"
70 break
72 esac
73 done
75 # default is the current directory
76 [ "$#" -gt 0 ] || set -- .
78 for checkDir
80 if [ -d $checkDir ]
81 then
82 echo "searching: $checkDir"
83 else
84 echo "skipping non-dir: $checkDir"
85 continue
88 find $checkDir -name '*.dep' -print | while read depFile
90 # check C++ and Flex files
91 if [ ! -r "${depFile%dep}C" -a ! -r "${depFile%dep}L" ];
92 then
93 echo "rm $depFile"
94 rm -f $depFile 2>/dev/null
96 done
98 # remove empty dirs
99 if [ "$optRmdir" ]
100 then
101 # get subdirs ourselves so we can avoid particular directories
102 for dir in $(find $checkDir -mindepth 1 -maxdepth 1 -type d \( -name .git -prune -o -print \) )
104 echo "check dir: $dir"
105 find $dir -depth -type d -empty -exec rmdir {} \; -print
106 done
108 done
109 # -----------------------------------------------------------------------------