From 4085575669d9cff50194ced327056dd87e5fb8ad Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Fri, 8 Aug 2008 13:07:10 +0200
Subject: [PATCH] usage and argument handling for bin/rm* and bin/touch*
 utilities

---
 bin/rmclassall | 24 +++++++++++++++++++++++-
 bin/rmcore     | 26 ++++++++++++++++++++++++--
 bin/rmdepall   | 20 ++++++++++++--------
 bin/rmoall     | 24 +++++++++++++++++++++++-
 bin/rm~all     | 25 +++++++++++++++++++++++--
 bin/touchapp   | 16 +++++++++++++++-
 bin/touchdep   | 23 ++++++++++++++++++++++-
 bin/touchlib   | 16 +++++++++++++++-
 bin/toucho     | 23 ++++++++++++++++++++++-
 9 files changed, 179 insertions(+), 18 deletions(-)

diff --git a/bin/rmclassall b/bin/rmclassall
index 5ee1c736290..059306bee51 100755
--- a/bin/rmclassall
+++ b/bin/rmclassall
@@ -1,2 +1,24 @@
 #!/bin/sh
-find . \( -name '*.class' \) -print | xargs -t rm
+
+# default is pwd
+if [ "$#" -eq 0 ]
+then
+   set -- .
+elif [ "$1" = "-h" -o "$1" = "-help" ]
+then
+   echo "Usage: ${0##*/} [dir1] .. [dirN]"
+   echo "    remove all .class files"
+   exit 1
+fi
+
+for i
+do
+   if [ -d "$i" ]
+   then
+      echo "removing all .class files"
+      find $i -name '*.class' -print | xargs -t rm
+   else
+      echo "no directory: $i"
+   fi
+done
+#------------------------------------------------------------------------------
diff --git a/bin/rmcore b/bin/rmcore
index 1245878ff31..f34cae57a5c 100755
--- a/bin/rmcore
+++ b/bin/rmcore
@@ -1,3 +1,25 @@
 #!/bin/sh
-# find . \( -name 'core' \) -exec ls -l {} \; -exec rm {} \;
-find . \( -type f -name 'core' -o -name 'core.[1-9]*' -o -name 'vgcore.*' \) -print | xargs -t rm
+
+# default is pwd
+if [ "$#" -eq 0 ]
+then
+   set -- .
+elif [ "$1" = "-h" -o "$1" = "-help" ]
+then
+   echo "Usage: ${0##*/} [dir1] .. [dirN]"
+   echo "    remove all core files"
+   exit 1
+fi
+
+for i
+do
+   if [ -d "$i" ]
+   then
+      echo "removing all core files"
+      find $i \( -type f -name 'core' -o -name 'core.[1-9]*' -o -name 'vgcore.*' \) -print | xargs -t rm
+   else
+      echo "no directory: $i"
+   fi
+done
+#------------------------------------------------------------------------------
+
diff --git a/bin/rmdepall b/bin/rmdepall
index 84e65267410..4cfa1ad6801 100755
--- a/bin/rmdepall
+++ b/bin/rmdepall
@@ -1,15 +1,19 @@
 #!/bin/sh
 
-if [ $# -eq 0 ]
+if [ "$1" = "-h" -o "$1" = "-help" -o "$#" -gt 1 ]
 then
-   find . \( -name '*.dep' \) -print | xargs -t rm
-elif [ $# -eq 1 ]
+   echo "Usage: ${0##*/}         : remove all .dep files"
+   echo "       ${0##*/} <file>  : remove all .dep files referring to <file>"
+   exit 1
+fi
+
+if [ "$#" -eq 0 ]
 then
-   echo "Removing all dep files containing $1..."
-   find . -name '*.dep' -exec grep "$1" '{}' \; -exec rm '{}' \;
+   echo "removing all .dep files"
+   find . -name '*.dep' -print | xargs -t rm
 else
-   echo "Usage: ${0##/}        to remove all .dep files"
-   echo "       ${0##/} <file> to remove all .dep files referring to <file>"
-   exit 1
+   echo "removing all .dep files containing $1..."
+   find . -name '*.dep' -exec grep "$1" '{}' \; -exec rm '{}' \;
 fi
 
+#------------------------------------------------------------------------------
diff --git a/bin/rmoall b/bin/rmoall
index 636e055e5bc..32bd8047889 100755
--- a/bin/rmoall
+++ b/bin/rmoall
@@ -1,2 +1,24 @@
 #!/bin/sh
-find . \( -name '*.o' \) -print | xargs -t rm
+
+# default is pwd
+if [ "$#" -eq 0 ]
+then
+   set -- .
+elif [ "$1" = "-h" -o "$1" = "-help" ]
+then
+   echo "Usage: ${0##*/} [dir1] .. [dirN]"
+   echo "    remove all .o files"
+   exit 1
+fi
+
+for i
+do
+   if [ -d "$i" ]
+   then
+      echo "removing all .o files: $i"
+      find $i -name '*.o' -print | xargs -t rm
+   else
+      echo "no directory: $i"
+   fi
+done
+#------------------------------------------------------------------------------
diff --git a/bin/rm~all b/bin/rm~all
index 6ee2bad3700..0725382447a 100755
--- a/bin/rm~all
+++ b/bin/rm~all
@@ -1,3 +1,24 @@
 #!/bin/sh
-# find . \( -name '*~' -o -name '.*~'  \) -exec ls -l {} \; -exec rm {} \;
-find . \( -name '*~' -o -name '.*~' \) -print | xargs -t rm
+
+# default is pwd
+if [ "$#" -eq 0 ]
+then
+   set -- .
+elif [ "$1" = "-h" -o "$1" = "-help" ]
+then
+   echo "Usage: ${0##*/} [dir1] .. [dirN]"
+   echo "    remove all *~ files"
+   exit 1
+fi
+
+for i
+do
+   if [ -d "$i" ]
+   then
+      echo "removing all *~ files"
+      find $i \( -name '*~' -o -name '.*~' \) -print | xargs -t rm
+   else
+      echo "no directory: $i"
+   fi
+done
+#------------------------------------------------------------------------------
diff --git a/bin/touchapp b/bin/touchapp
index 38325105ef9..6c76f2208ad 100755
--- a/bin/touchapp
+++ b/bin/touchapp
@@ -1,3 +1,17 @@
 #!/bin/sh
 
-touch $FOAM_APPBIN/*
+if [ "$#" -ne 0 ]
+then
+   echo "Usage: ${0##*/}"
+   echo "    touch FOAM_APPBIN"
+   exit 1
+fi
+
+if [ -d "$FOAM_APPBIN" ]
+then
+   echo "touching FOAM_APPBIN: $FOAM_APPBIN"
+   touch $FOAM_APPBIN/*
+else
+   echo "no FOAM_APPBIN: $FOAM_APPBIN"
+fi
+#------------------------------------------------------------------------------
diff --git a/bin/touchdep b/bin/touchdep
index 25d4b75fa45..497fae79ee2 100755
--- a/bin/touchdep
+++ b/bin/touchdep
@@ -1,3 +1,24 @@
 #!/bin/sh
 
-find . \( -name '*.dep' \) -print | xargs -t touch
+# default is pwd
+if [ "$#" -eq 0 ]
+then
+   set -- .
+elif [ "$1" = "-h" -o "$1" = "-help" ]
+then
+   echo "Usage: ${0##*/} [dir1] .. [dirN]"
+   echo "    touch all .dep files"
+   exit 1
+fi
+
+for i
+do
+   if [ -d "$i" ]
+   then
+      echo "touching all .dep files: $i"
+      find $i -name '*.dep' -print | xargs -t touch
+   else
+      echo "no directory: $i"
+   fi
+done
+#------------------------------------------------------------------------------
diff --git a/bin/touchlib b/bin/touchlib
index bda6880c96e..ef4a7cc6fe1 100755
--- a/bin/touchlib
+++ b/bin/touchlib
@@ -1,3 +1,17 @@
 #!/bin/sh
 
-touch $FOAM_LIBBIN/*
+if [ "$#" -ne 0 ]
+then
+   echo "Usage: ${0##*/}"
+   echo "    touch FOAM_LIBBIN"
+   exit 1
+fi
+
+if [ -d "$FOAM_LIBBIN" ]
+then
+   echo "touching FOAM_LIBBIN: $FOAM_LIBBIN"
+   touch $FOAM_LIBBIN/* $FOAM_LIBBIN/*/*
+else
+   echo "no FOAM_LIBBIN: $FOAM_LIBBIN"
+fi
+#------------------------------------------------------------------------------
diff --git a/bin/toucho b/bin/toucho
index bf3a69f6d8e..0236225d73b 100755
--- a/bin/toucho
+++ b/bin/toucho
@@ -1,3 +1,24 @@
 #!/bin/sh
 
-find . \( -name '*.o' \) -print | xargs -t touch
+# default is pwd
+if [ "$#" -eq 0 ]
+then
+   set -- .
+elif [ "$1" = "-h" -o "$1" = "-help" ]
+then
+   echo "Usage: ${0##*/} [dir1] .. [dirN]"
+   echo "    touch all .o files"
+   exit 1
+fi
+
+for i
+do
+   if [ -d "$i" ]
+   then
+      echo "touching all .o files: $i"
+      find $i -name '*.o' -print | xargs -t touch
+   else
+      echo "no directory: $i"
+   fi
+done
+#------------------------------------------------------------------------------
-- 
GitLab