#! /bin/sh

# Copyright (C) 1999, 2000,  Free Software Foundation
# Originally by Alexandre Oliva <oliva@gnu.org>

# This script is Free Software, and it can be copied, distributed and
# modified as defined in the GNU General Public License.  A copy of
# its license can be downloaded from http://www.gnu.org/copyleft/gpl.html

# List files generated by CVS merges, by installing patches and by
# checking out old versions within emacs.  It is useful for removing
# them from a cvs tree.

# A list of directories can be specified as arguments.  The current
# directory is assumed by default.

# Usage: cvsclean | xargs rm
#        cvsclean /some/dir /another/dir | xargs rm

# Since the command-line arguments are passed directly to a `find'
# command, it is possible to impose additional restrictions on matched
# files, by using appropriate find syntax.  For example:
#        cvsclean . -name \*~ -o -mtime +1
# will *not* print files whose names end with `~', because there's no
# -print command, and will only print files modified at least one day
# ago, because the -mtime arg will be followed immediately by the
# standard file name matching rules used by this script.

# If the first argument is `-~', any files ended with ~ will also be
# matched.

if test "x$1" = 'x-~'; then
  bkpat=
  shift
else
  bkpat=*.*~
fi

test $# = 0 && set .

exec find ${1+"$@"} \( -name ".#*" -o -name "*.orig" -o -name ".*.orig" -o -name "*.rej" -o -name ".*.rej" -o -name "*~$bkpat" -o -name ".*~$bkpat" \) -print
