--- /dev/null
+#!/usr/bin/perl
+################################################################################
+#
+# File: files4ecr
+# Description: This script will go through CVS looking for files that have
+# the passed in ECR #.
+# Author: Andrew@DeFaria.com
+# Created: Fri Dec 17 12:18:21 PST 2004
+# Language: Perl
+#
+# (c) Copyright 2004, LynxWorks Inc., all rights reserved
+#
+################################################################################
+use warnings;
+use strict;
+
+# Options
+my $verbose = 0;
+my $debug = 0;
+my $execute = 0;
+my $local = "";
+
+my $ecr;
+
+sub verbose {
+ my $msg = shift;
+
+ print "$msg\n" if $verbose;
+} # verbose
+
+sub debug {
+ my $msg = shift;
+
+ print "DEBUG: $msg\n" if $debug;
+} # debug
+
+sub Usage {
+ my $msg = shift;
+
+ print "ERROR: $msg\n\n" if defined $msg;
+
+ print "Usage: files4ecr [-v] [-d] [-l] [-x] [-u] <ecr>\n";
+ print "\nWhere:\n\n";
+ print "\t-v:\t\tTurn on verbose mode (Default: off)\n";
+ print "\t-d:\t\tTurn on debug mode (Default: off)\n";
+ print "\t-l:\t\tLocal directory only, no recursion\n";
+ print "\t-x:\t\tTurn on execute mode (Default: off)\n";
+ print "\t-u:\t\tDisplay usage\n";
+ print "\tecr\t\tECR number to search for\n";
+ exit 1;
+} # Usage
+
+sub GetFiles4 {
+ my $ecr = shift;
+ my $local = shift;
+
+ # Perform a cvs log command and grep through the output
+ print "Gathering CVS info..." if $verbose;
+ my @output = grep {
+ /^Working file: / or
+ /^revision / or
+ /^\s*ECR#/ or
+ /^\s*ECR /
+ } `cvs -q log $local 2>/dev/null`;
+ verbose " done";
+
+ # Now process this array. Entries may look like:
+ #
+ # Working file: <filename>
+ # revision <revision>
+ # revision <revision>
+ # ECR Number: <ecr>
+ #
+ # It's quite possible that there are no ECR numbers for a file. It's also
+ # possible that there is the same ECR number for multiple revisions! For
+ # example:
+ #
+ # Working file: <filename>
+ # revision 10.2
+ # ECR Number: 1000
+ # revision 10.1
+ # ECR Number: 1000
+ #
+ # In this case we want to return the <filename> and 10.2.
+
+ my %files;
+ my $filename;
+ my $revision;
+
+ while ($_ = shift @output) {
+ chomp;
+ chop if /\r/;
+
+ if (/^Working file: (.*)/) {
+ $filename = $1;
+ debug "file: $filename";
+ } elsif (/^revision (.*)/) {
+ $revision = $1;
+ debug "revision: $revision";
+ } elsif (/^ECR Number: (\d*)$/ or
+ /^ECR# (\d*)$/ or
+ /^ECR # (\d*)$/ or
+ /^\s*ECR (\d*)/) {
+ debug "ECR: $1";
+ if ($ecr eq $1) {
+ $files{$filename} = $revision;
+ debug "Set $filename: $revision";
+
+ # Now skip to next file
+ do {
+ $_ = shift @output;
+ } while @output and !/Working file: /;
+ unshift @output, $_;
+ } # if
+ } else {
+ verbose "Unknown line encountered: $_\n";
+ } # if
+ } # foreach
+
+ return %files;
+} # GetFiles4
+
+sub GetWorkingRev {
+ my $filename = shift;
+
+ my @output = grep { /Working revision:/ } `cvs status $filename`;
+
+ if (defined $output [0] and $output [0] =~ /Working revision:\s*(\S*)/) {
+ return $1;
+ } # if
+
+ return undef;
+} # GetWorkingRev
+
+# Get args
+while ($ARGV [0]) {
+ if ($ARGV [0] eq "-d") {
+ $debug = 1;
+ } elsif ($ARGV [0] eq "-v") {
+ $verbose = 1;
+ } elsif ($ARGV [0] eq "-l") {
+ $local = $ARGV [0];
+ } elsif ($ARGV [0] eq "-x") {
+ $execute = 1;
+ } elsif ($ARGV [0] eq "-u") {
+ Usage;
+ } # if
+
+ $ecr = $ARGV [0];
+
+ shift (@ARGV);
+} # while
+
+Usage "No ECR specified to process" if !defined $ecr;
+
+my %files = GetFiles4 $ecr, $local;
+
+foreach (keys %files) {
+ my $working_revision = GetWorkingRev $_;
+ my $up_to_date = 0;
+
+ if (defined $working_revision and $working_revision eq $files{$_}) {
+ $up_to_date = 1;
+ } # if
+
+ if ($execute) {
+ print "cvs update -r$files{$_} $_";
+
+ if (!$up_to_date) {
+ `cvs update -r$files{$_} $_`;
+ print " - Updated\n";
+ } else {
+ print " - Already up to date\n";
+ } # if
+ } else {
+ print "$_: $files{$_}";
+
+ if ($up_to_date) {
+ print " - Already up to date\n";
+ } else {
+ print " - Out of date\n";
+ } # if
+ } # if
+} # foreach
+