#!/usr/bin/perl -w
# -*- perl -*-

#
# $Id: $
# Author: Slaven Rezic
#

use strict;
use File::Find;

my $new_root = shift;
if (!defined $new_root) {
   if (defined $ENV{CVSROOT}) {
       $new_root = $ENV{CVSROOT};
   } else {
       die "New CVS root is not specified in the command line.
Alternatively the value of CVSROOT will be used.\n";
   }
}

find(\&wanted, '.');

sub wanted {
   if ($File::Find::name =~ m|/CVS/Root|) {
       open(O, ">$_")
           or die "Can't write to $File::Find::name: $!";
       binmode O;
       warn "Changing $File::Find::name...\n";
       print O "$new_root\n";
       close O;
   }
}

__END__

=head1 NAME

newcvsroot - change the CVS root in a working directory

=head1 SYNOPSIS

   newcvsroot [newroot]

=head1 DESCRIPTION

C<newcvsroot> changes the CVS root in the current working directory
and all subdirectories. If C<newroot> is not specified, then the value
of the environment variable C<CVSROOT> is used as the new CVS root.

=head1 README

newcvsroot changes the CVS root in the current working directory and
all subdirectories.

=head1 PREREQUISITES

L<File::Find>

=head1 OSNAMES

OS independent

=head1 SCRIPT CATEGORIES

VersionControl:CVS

=head1 AUTHOR

Slaven Rezic <[email protected]>

=head1 SEE ALSO

cvs(1).

=cut