#! /usr/bin/perl -w
use strict;
=head1 Notices
Originally developed for Perforce by VIZIM (www.vizim.com)
Copyright (c) 2014 Perforce Software, Inc. and VIZIM Worldwide, Inc.
All rights reserved.
Please see LICENSE.txt in top-level folder of this distribution for
license information
=cut
use v5.14.0; # Earliest version testing was performed against
my $APPNAME = 'ctrlList.pl';
my $APPWHAT = 'ctrl file item lister; version 1.03';
my $APPNOTICES = "Copyright (c) 2014 Perforce Software, Inc. and VIZIM Worldwide, Inc.
All rights reserved.
See LICENSE.txt for license information.";
=head1 ctrl file item lister
Tool to list items from a ctrl file.
Primary use is creating control files for import recovery.
Secondary uses include breaking a large control file into smaller units and
to isolate a single entry from a larger ctrl file for analysis.
By default, a TFSCONTROL header tag is copied to the output.
Copy of this tag can be suppressed with the -n option.
=cut
if( defined $ARGV[0] && (uc $ARGV[0] eq '-V') ) {
print "$APPWHAT\n";
exit(0);
}
if( ! defined $ARGV[0]
|| $ARGV[0] =~ m!^\-+[h\?]! ) {
print "$APPWHAT
$APPNOTICES
Usage:
$APPNAME -V
$APPNAME [-h|-?]
$APPNAME [-n] CTRL first [last]
-n - no listing of TFSCONTROL tag\n";
exit( 0 );
}
my $listHeader = 1;
if( $ARGV[0] =~ m!^\-+[n]! ) {
$listHeader = 0;
shift @ARGV;
}
my $fileName = $ARGV[0];
die "ctrl file $fileName does not exist" unless -e $fileName;
shift @ARGV;
my $first = $ARGV[0];
shift @ARGV;
my $last = $first;
$last = $ARGV[0]
if defined $ARGV[0];
my $hCtrl;
open $hCtrl, '<', $fileName or die "Can't open $fileName - $!";
my $list = 0;
while(<$hCtrl>) {
if( m!^\<TFSCONTROL! && $listHeader ) {
print $_;
} elsif( m!^\<CC seq\=\"(\d+)\"! ) {
last if $1 > $last;
$list = $1 >= $first && $1 <= $last;
}
print $_ if $list;
$list = 0
if m!^\<CS !;
}
close $hCtrl;