Added client work scripts
[clearscm.git] / clients / LynuxWorks / bin / files4ecr
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # File:         files4ecr
5 # Description:  This script will go through CVS looking for files that have
6 #               the passed in ECR #.
7 # Author:       Andrew@DeFaria.com
8 # Created:      Fri Dec 17 12:18:21 PST 2004
9 # Language:     Perl
10 #
11 # (c) Copyright 2004, LynxWorks Inc., all rights reserved
12 #
13 ################################################################################
14 use warnings;
15 use strict;
16
17 # Options
18 my $verbose     = 0;
19 my $debug       = 0;
20 my $execute     = 0;
21 my $local       = "";
22
23 my $ecr;
24
25 sub verbose {
26   my $msg = shift;
27
28   print "$msg\n" if $verbose;
29 } # verbose
30
31 sub debug {
32   my $msg = shift;
33
34   print "DEBUG: $msg\n" if $debug;
35 } # debug
36
37 sub Usage {
38   my $msg = shift;
39
40   print "ERROR: $msg\n\n" if defined $msg;
41
42   print "Usage: files4ecr [-v] [-d] [-l] [-x] [-u] <ecr>\n";
43   print "\nWhere:\n\n";
44   print "\t-v:\t\tTurn on verbose mode (Default: off)\n";
45   print "\t-d:\t\tTurn on debug mode (Default: off)\n";
46   print "\t-l:\t\tLocal directory only, no recursion\n";
47   print "\t-x:\t\tTurn on execute mode (Default: off)\n";
48   print "\t-u:\t\tDisplay usage\n";
49   print "\tecr\t\tECR number to search for\n";
50   exit 1;
51 } # Usage
52
53 sub GetFiles4 {
54   my $ecr       = shift;
55   my $local     = shift;
56
57   # Perform a cvs log command and grep through the output
58   print "Gathering CVS info..." if $verbose;
59   my @output = grep {
60     /^Working file: /   or
61     /^revision /        or
62     /^\s*ECR#/          or
63     /^\s*ECR /
64   } `cvs -q log $local 2>/dev/null`;
65   verbose " done";
66
67   # Now process this array. Entries may look like:
68   #
69   # Working file: <filename>
70   # revision <revision>
71   # revision <revision>
72   # ECR Number: <ecr>
73   #
74   # It's quite possible that there are no ECR numbers for a file. It's also
75   # possible that there is the same ECR number for multiple revisions! For
76   # example:
77   #
78   # Working file: <filename>
79   # revision 10.2
80   # ECR Number: 1000
81   # revision 10.1
82   # ECR Number: 1000
83   #
84   # In this case we want to return the <filename> and 10.2.
85
86   my %files;
87   my $filename;
88   my $revision;
89
90   while ($_ = shift @output) {
91     chomp;
92     chop if /\r/;
93
94     if (/^Working file: (.*)/) {
95       $filename = $1;
96       debug "file: $filename";
97     } elsif (/^revision (.*)/) {
98       $revision = $1;
99       debug "revision: $revision";
100     } elsif (/^ECR Number: (\d*)$/      or
101              /^ECR# (\d*)$/             or
102              /^ECR # (\d*)$/            or
103              /^\s*ECR (\d*)/) {
104       debug "ECR: $1";
105       if ($ecr eq $1) {
106         $files{$filename} = $revision;
107         debug "Set $filename: $revision";
108
109         # Now skip to next file
110         do {
111           $_ = shift @output;
112         } while @output and !/Working file: /;
113         unshift @output, $_;
114       } # if
115     } else {
116       verbose "Unknown line encountered: $_\n";
117     } # if
118   } # foreach
119
120   return %files;
121 } # GetFiles4
122
123 sub GetWorkingRev {
124   my $filename = shift;
125
126   my @output = grep { /Working revision:/ } `cvs status $filename`;
127
128   if (defined $output [0] and $output [0] =~ /Working revision:\s*(\S*)/) {
129     return $1;
130   } # if
131
132   return undef;
133 } # GetWorkingRev
134
135 # Get args
136 while ($ARGV [0]) {
137   if ($ARGV [0] eq "-d") {
138     $debug = 1;
139   } elsif ($ARGV [0] eq "-v") {
140     $verbose = 1;
141   } elsif ($ARGV [0] eq "-l") {
142     $local = $ARGV [0];
143   } elsif ($ARGV [0] eq "-x") {
144     $execute = 1;
145   } elsif ($ARGV [0] eq "-u") {
146     Usage;
147   } # if
148
149   $ecr = $ARGV [0];
150
151   shift (@ARGV);
152 } # while
153
154 Usage "No ECR specified to process" if !defined $ecr;
155
156 my %files = GetFiles4 $ecr, $local;
157
158 foreach (keys %files) {
159   my $working_revision  = GetWorkingRev $_;
160   my $up_to_date        = 0;
161
162   if (defined $working_revision and $working_revision eq $files{$_}) {
163     $up_to_date = 1;
164   } # if
165
166   if ($execute) {
167     print "cvs update -r$files{$_}  $_";
168
169     if (!$up_to_date) {
170       `cvs update -r$files{$_} $_`;
171       print " - Updated\n";
172     } else {
173       print " - Already up to date\n";
174     } # if
175   } else {
176     print "$_: $files{$_}";
177
178     if ($up_to_date) {
179       print " - Already up to date\n";
180     } else {
181       print " - Out of date\n";
182     } # if
183   } # if
184 } # foreach
185