/usr/share/perl5/Rcs.pm is in librcs-perl 1.05-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 | package Rcs;
require 5.002;
use strict;
use Exporter;
use Carp;
use Time::Local;
use vars qw($VERSION $revision);
use subs qw(_rcsError);
# Even though I don't really export anything, I use Exporter
# to look for 'nonFatal' 'Verbose' tags.
use vars qw(@ISA @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(nonFatal Verbose);
#------------------------------------------------------------------
# global stuff
#------------------------------------------------------------------
$VERSION = '1.05';
$revision = '$Id: Rcs.pm,v 1.28 2003/12/12 00:53:34 freter Exp $';
my $Dir_Sep = ($^O eq 'MSWin32') ? '\\' : '/';
my $Exe_Ext = ($^O eq 'MSWin32') ? '.exe' : '';
my $Rcs_Bin_Dir = '/usr/local/bin';
my $Rcs_Dir = '.' . $Dir_Sep . 'RCS';
my $Work_Dir = '.';
my $Quiet = 1; # RCS quiet mode
my $nonFatal = 0; # default to fatal
my $Arc_Ext = ',v';
#------------------------------------------------------------------
# RCS object constructor
#------------------------------------------------------------------
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
# provide default values for system stuff
$self->{"_BINDIR"} = \$Rcs_Bin_Dir;
$self->{"_QUIET"} = \$Quiet;
$self->{"_RCSDIR"} = \$Rcs_Dir;
$self->{"_WORKDIR"} = \$Work_Dir;
$self->{"_ARCEXT"} = \$Arc_Ext;
$self->{FILE} = undef;
$self->{ARCFILE} = undef;
$self->{AUTHOR} = undef;
$self->{COMMENTS} = undef;
$self->{DATE} = undef;
$self->{LOCK} = undef;
$self->{ACCESS} = [];
$self->{REVISIONS} = [];
$self->{REVINFO} = undef;
$self->{STATE} = undef;
$self->{SYMBOLS} = undef;
bless($self, $class);
# Allow user to pass archive file to object constructor
# Example: Rcs->new('RCS/diskio.c,v')
if (@_) {
$self->pathname(shift);
}
return $self;
}
#------------------------------------------------------------------
# Use import function to check for 'nonFatal' Tag.
#------------------------------------------------------------------
sub import {
my $pkg = shift;
$nonFatal = 1 if scalar grep /^nonFatal$/, @_;
$Quiet = 0 if scalar grep /^Verbose$/, @_;
}
#------------------------------------------------------------------
# access
# Access list of archive file.
#------------------------------------------------------------------
sub access {
my $self = shift;
if (not @{ $self->{ACCESS} }) {
_parse_rcs_header($self);
}
# dereference revisions list
my @access = @{ $self->{ACCESS} };
return @access;
}
#------------------------------------------------------------------
# arcext
# Set the RCS archive file extension (default is ',v').
#------------------------------------------------------------------
sub arcext {
my $self = shift;
# called as object method
if (ref $self) {
if (@_) { $self->{"_ARCEXT"} = shift };
return ref $self->{"_ARCEXT"} ? ${ $self->{"_ARCEXT"} } : $self->{"_ARCEXT"};
}
# called as class method
else {
if (@_) { $Arc_Ext = shift; }
return $Arc_Ext;
}
}
#------------------------------------------------------------------
# arcfile
# Name of RCS archive file.
# If not set then return name of working file with RCS
# extension (',v').
#------------------------------------------------------------------
sub arcfile {
my $self = shift;
if (@_) { $self->{ARCFILE} = shift }
return $self->{ARCFILE} || $self->file . $self->arcext;
}
#------------------------------------------------------------------
# author
# Return the author of an RCS revision.
# If revision is not provided, default to 'head' revision.
#------------------------------------------------------------------
sub author {
my $self = shift;
if (not defined $self->{AUTHOR}) {
_parse_rcs_header($self);
}
my $revision = shift || $self->head;
# dereference author hash
my %author_array = %{ $self->{AUTHOR} };
return $author_array{$revision};
}
#------------------------------------------------------------------
# bindir
# Set the bin directory in which the RCS distribution programs
# reside.
#------------------------------------------------------------------
sub bindir {
my $self = shift;
# called as object method
if (ref $self) {
if (@_) { $self->{"_BINDIR"} = shift };
return ref $self->{"_BINDIR"} ? ${ $self->{"_BINDIR"} } : $self->{"_BINDIR"};
}
# called as class method
else {
if (@_) { $Rcs_Bin_Dir = shift };
return $Rcs_Bin_Dir;
}
}
#------------------------------------------------------------------
# ci
# Execute RCS 'ci' program.
# Make archive filename same as working filename unless
# specifically set.
#------------------------------------------------------------------
sub ci {
my $self = shift;
my @param = @_;
my $ciprog = $self->bindir . $Dir_Sep . 'ci' . $Exe_Ext;
my $rcsdir = $self->rcsdir;
my $workdir = $self->workdir;
my $file = $self->file;
my $arcfile = $self->arcfile;
my $archive_file = $rcsdir . $Dir_Sep . $arcfile;
my $workfile = $workdir . $Dir_Sep . $file;
push @param, $archive_file, $workfile;
unshift @param, "-q" if $self->quiet; # quiet mode
# run program
return(_rcsError "ci program $ciprog not found") unless -e $ciprog;
return(_rcsError "ci program $ciprog not executable") unless -x $ciprog;
system($ciprog, @param) == 0 or return(_rcsError "$?");
# re-parse RCS file and clear comments hash
_parse_rcs_header($self);
$self->{COMMENTS} = undef;
return 1;
}
#------------------------------------------------------------------
# co
# Execute RCS 'co' program.
# Make archive filename same as working filename unless
# specifically set.
#------------------------------------------------------------------
sub co {
my $self = shift;
my @param = @_;
my $coprog = $self->bindir . $Dir_Sep . 'co' . $Exe_Ext;
my $rcsdir = $self->rcsdir;
my $workdir = $self->workdir;
my $file = $self->file;
my $arcfile = $self->arcfile;
my $archive_file = $rcsdir . $Dir_Sep . $arcfile;
my $workfile = $workdir . $Dir_Sep . $file;
push @param, $archive_file, $workfile;
unshift @param, "-q" if $self->quiet; # quiet mode
# run program
return(_rcsError "co program $coprog not found") unless -e $coprog;
return(_rcsError "co program $coprog not executable") unless -x $coprog;
system($coprog, @param) == 0 or return(_rcsError "$?");
# re-parse RCS file and clear comments hash
_parse_rcs_header($self);
$self->{COMMENTS} = undef;
return 1;
}
#------------------------------------------------------------------
# comments
#------------------------------------------------------------------
sub comments {
my $self = shift;
if (not defined $self->{COMMENTS}) {
_parse_rcs_body($self);
}
return %{$self->{COMMENTS}};
}
#------------------------------------------------------------------
# daterev
#
# Returns revisions which were created before a specified date.
#
# Method takes one or six arguments.
#
# If one argument, then argument is date number.
#
# If six arguments, then year (4 digit year), month (1-12), day
# of month (1-31), hour (0-23), minute (0-59) and second (0-59).
#------------------------------------------------------------------
sub daterev {
my $self = shift;
my $target_time;
# validate arguments
unless (@_ == 1 or @_ == 6) {
croak "daterev must have either 1 or 6 arguments";
}
# string date passed
if (@_ == 6) {
my($year, $mon, $mday, $hour, $min, $sec) = @_;
if($year !~ /^\d{4}$/) {
croak "year (1st param) must be 4 digit number";
}
$mon--; # convert to 0-11 range
$target_time = timegm($sec, $min, $hour, $mday, $mon, $year);
}
# system date passed
else {
$target_time = shift;
if ($target_time !~ /^\d+$/) {
croak "system date must be an integer";
}
}
if (not defined $self->{DATE}) {
_parse_rcs_header($self);
}
my @revisions = ();
my %dates;
my %dates_hash = %{$self->{DATE}};
my $revision;
foreach $revision (keys %dates_hash) {
my $date = $dates_hash{$revision};
$dates{$date}{$revision} = 1;
}
my $date;
foreach $date (reverse sort keys %dates) {
foreach $revision (keys %{ $dates{$date} }) {
push @revisions, $revision if $date <= $target_time;
}
}
return wantarray ? @revisions : $revisions[0];
}
#------------------------------------------------------------------
# dates
# Return a hash of revision dates, keyed on revision, when called
# in list mode.
# Return the most recent date when called in scalar mode.
#
# RCS stores dates in GMT.
# The date values are system dates.
#------------------------------------------------------------------
sub dates {
my $self = shift;
if (not defined $self->{DATE}) {
_parse_rcs_header($self);
}
my %DatesHash = %{$self->{DATE}};
my @dates_list = sort {$b<=>$a} values %DatesHash;
my $MostRecent = $dates_list[0];
return wantarray ? %DatesHash : $MostRecent;
}
#------------------------------------------------------------------
# file
# Name of working file.
#------------------------------------------------------------------
sub file {
my $self = shift;
if (@_) { $self->{FILE} = shift }
return $self->{FILE};
}
#------------------------------------------------------------------
# pathname
# Full name of working file, including path to it and RCS file extension.
# Sets the location of 'RCS' archive directory.
#------------------------------------------------------------------
sub pathname {
my $self = shift;
if (@_) {
my $filename = shift;
if ($filename =~ m/(.*)$Dir_Sep(.*)/) {
$self->rcsdir($1);
$filename = $2;
}
else {
$self->rcsdir('.');
}
# Strip off archive extension if exists
my $arcext = $self->arcext;
$filename =~ s/$arcext$//;
$self->file($filename);
}
return $self->rcsdir . $Dir_Sep . $self->file;
}
#------------------------------------------------------------------
# head
# Return the head revision.
#------------------------------------------------------------------
sub head {
my $self = shift;
if (not defined $self->{HEAD}) {
_parse_rcs_header($self);
}
return $self->{HEAD};
}
#------------------------------------------------------------------
# lock
# Return user who has file locked.
#------------------------------------------------------------------
sub lock {
my $self = shift;
if (not defined $self->{LOCK}) {
_parse_rcs_header($self);
}
my $revision = shift || $self->{HEAD};
return wantarray ? %{ $self->{LOCK} } : ${ $self->{LOCK} }{$revision};
}
#------------------------------------------------------------------
# quiet
# Set or un-set RCS quiet mode.
#------------------------------------------------------------------
sub quiet {
my $self = shift;
# called as object method
if (ref $self) {
# set/un-set quiet mode
if (@_) {
my $mode = shift;
croak "Passed parameter must be either '0' or '1'"
unless $mode == 0 or $mode == 1;
$self->{"_QUIET"} = $mode;
return ref $self->{"_QUIET"} ? ${ $self->{"_QUIET"} } : $self->{"_QUIET"};
}
# access quiet mode
else {
return ref $self->{"_QUIET"} ? ${ $self->{"_QUIET"} } : $self->{"_QUIET"};
}
}
# called as class method
else {
# set/un-set quiet mode
if (@_) {
my $mode = shift;
croak "Passed parameter must be either '0' or '1'"
unless $mode == 0 or $mode == 1;
$Quiet = $mode;
return $Quiet;
}
# access quiet mode
else {
return $Quiet;
}
}
}
#------------------------------------------------------------------
# rcs
# Execute RCS 'rcs' program.
# Make archive filename same as working filename unless
# specifically set.
#------------------------------------------------------------------
sub rcs {
my $self = shift;
my @param = @_;
my $rcsprog = $self->bindir . $Dir_Sep . 'rcs' . $Exe_Ext;
my $rcsdir = $self->rcsdir;
my $workdir = $self->workdir;
my $file = $self->file;
my $arcfile = $self->arcfile;
my $archive_file = $rcsdir . $Dir_Sep . $arcfile;
my $workfile = $workdir . $Dir_Sep . $file;
push @param, $archive_file, $workfile;
unshift @param, "-q" if $self->quiet; # quiet mode
# run program
return(_rcsError "rcs program $rcsprog not found") unless -e $rcsprog;
return(_rcsError "rcs program $rcsprog not executable") unless -x $rcsprog;
system($rcsprog, @param) == 0 or return(_rcsError "$?");
# re-parse RCS file and clear comments hash
_parse_rcs_header($self);
$self->{COMMENTS} = undef;
return 1;
}
#------------------------------------------------------------------
# rcsclean
# Execute RCS 'rcsclean' program.
#------------------------------------------------------------------
sub rcsclean {
my $self = shift;
my @param = @_;
my $rcscleanprog = $self->bindir . $Dir_Sep . 'rcsclean' . $Exe_Ext;
my $rcsdir = $self->rcsdir;
my $workdir = $self->workdir;
my $file = $self->file;
my $arcfile = $self->arcfile;
my $archive_file = $rcsdir . $Dir_Sep . $arcfile;
my $workfile = $workdir . $Dir_Sep . $file;
push @param, $archive_file, $workfile;
# run program
return(_rcsError "rcsclean program $rcscleanprog not found") unless -e $rcscleanprog;
return(_rcsError "rcsclean program $rcscleanprog not executable") unless -x $rcscleanprog;
system($rcscleanprog, @param) == 0 or return(_rcsError "$?");
# re-parse RCS file and clear comments hash
_parse_rcs_header($self);
$self->{COMMENTS} = undef;
return 1;
}
#------------------------------------------------------------------
# rcsdiff
# Execute RCS 'rcsdiff' program.
# Calling in list context returns the output of rcsdiff, while
# calling in scalar context returns the return status of the
# rcsdiff program.
#------------------------------------------------------------------
sub rcsdiff {
my $self = shift;
my @param = @_;
my $rcsdiff_prog = $self->bindir . $Dir_Sep . 'rcsdiff' . $Exe_Ext;
my $rcsdir = $self->rcsdir;
my $arcfile = $self->arcfile;
$arcfile = $rcsdir . $Dir_Sep . $arcfile;
my $workfile = $self->workdir . $Dir_Sep . $self->file;
# un-taint parameter string
unshift @param, "-q" if $self->quiet; # quiet mode
my $param_str = join(' ', @param);
$param_str =~ s/([\w-]+)/$1/g;
return(_rcsError "rcsdiff program $rcsdiff_prog not found")
unless -e $rcsdiff_prog;
return(_rcsError "rcsdiff program $rcsdiff_prog not executable")
unless -x $rcsdiff_prog;
open(DIFF, "$rcsdiff_prog $param_str '$arcfile' '$workfile' |")
or return(_rcsError "Can't fork $rcsdiff_prog: $!");
my @diff_output = <DIFF>;
# rcsdiff returns exit status 0 for no differences, 1 for differences,
# and 2 for error condition.
close DIFF;
my $status = $?;
$status >>= 8;
return(_rcsError "$rcsdiff_prog failed") if $status == 2;
return wantarray ? @diff_output : $status;
}
#------------------------------------------------------------------
# rcsdir
# Location of 'RCS' archive directory.
#------------------------------------------------------------------
sub rcsdir {
my $self = shift;
# called as object method
if (ref $self) {
if (@_) { $self->{"_RCSDIR"} = shift }
return ref $self->{"_RCSDIR"} ? ${ $self->{"_RCSDIR"} } : $self->{"_RCSDIR"};
}
# called as class method
else {
if (@_) { $Rcs_Dir = shift }
return $Rcs_Dir;
}
}
#------------------------------------------------------------------
# revdate
# Return the revision date of an RCS revision.
# If revision is not provided, default to 'head' revision.
#
# RCS stores dates in GMT. This method will return dates relative
# to the local time zone.
#------------------------------------------------------------------
sub revdate {
my $self = shift;
if (not defined $self->{DATE}) {
_parse_rcs_header($self);
}
my $revision = shift || $self->head;
# dereference date hash
my %date_array = %{ $self->{DATE} };
my $date_str = $date_array{$revision};
return wantarray ? localtime($date_str) : $date_str;
}
#------------------------------------------------------------------
# revisions
#------------------------------------------------------------------
sub revisions {
my $self = shift;
if (not @{ $self->{REVISIONS} }) {
_parse_rcs_header($self);
}
# dereference revisions list
my @revisions = @{ $self->{REVISIONS} };
@revisions;
}
#------------------------------------------------------------------
# rlog
# Execute RCS 'rlog' program.
# Make archive filename same as working filename unless
# specifically set.
#------------------------------------------------------------------
sub rlog {
my $self = shift;
my @param = @_;
my $rlogprog = $self->bindir . $Dir_Sep . 'rlog' . $Exe_Ext;
my $rcsdir = $self->rcsdir;
my $arcfile = $self->arcfile || $self->file;
# un-taint parameter string
my $param_str = join(' ', @param);
$param_str =~ s/([\w-]+)/$1/g;
my $archive_file = $rcsdir . $Dir_Sep . $arcfile;
return(_rcsError "rlog program $rlogprog not found") unless -e $rlogprog;
return(_rcsError "rlog program $rlogprog not executable") unless -x $rlogprog;
open(RLOG, "$rlogprog $param_str '$archive_file' |")
or return(_rcsError "Can't fork $rlogprog: $!");
my @logoutput = <RLOG>;
close RLOG;
return(_rcsError "$rlogprog failed") if $?;
@logoutput;
}
#------------------------------------------------------------------
# rcsmerge
# Execute RCS 'rcsmerge' program.
#------------------------------------------------------------------
sub rcsmerge {
my $self = shift;
my @param = @_;
my $rcsmergeprog = $self->bindir . $Dir_Sep . 'rcsmerge' . $Exe_Ext;
my $rcsdir = $self->rcsdir;
my $arcfile = $self->arcfile || $self->file;
# un-taint parameter string
my $param_str = join(' ', @param);
$param_str =~ s/([\w-]+)/$1/g;
my $archive_file = $rcsdir . $Dir_Sep . $arcfile;
return(_rcsError "rcsmerge program $rcsmergeprog not found") unless -e $rcsmergeprog;
return(_rcsError "rcsmerge program $rcsmergeprog not executable") unless -x $rcsmergeprog;
open(RCSMERGE, "$rcsmergeprog $param_str '$archive_file' |")
or return(_rcsError "Can't fork $rcsmergeprog $!");
my @logoutput = <RCSMERGE>;
close RCSMERGE;
return(_rcsError "$rcsmergeprog failed") if $?;
@logoutput;
}
#------------------------------------------------------------------
# state
# If revision is not provided, default to 'head' revision
#------------------------------------------------------------------
sub state {
my $self = shift;
if (not defined $self->{STATE}) {
_parse_rcs_header($self);
}
my $revision = shift || $self->head;
# dereference author hash
my %state_array = %{ $self->{STATE} };
return $state_array{$revision};
}
#------------------------------------------------------------------
# symbol
# Return symbol(s) based on revision.
#------------------------------------------------------------------
sub symbol {
my $self = shift;
my $sym;
my @sym_array;
if (not defined $self->{SYMBOLS}) {
_parse_rcs_header($self);
}
my $revision = shift || $self->head;
# dereference symbols hash
my %symbols = %{ $self->{SYMBOLS} };
foreach $sym (keys %symbols) {
my $rev = $symbols{$sym};
push @sym_array, $sym if $rev eq $revision;
}
# return only first array element if user wants scalar
return wantarray ? @sym_array : $sym_array[0];
}
#------------------------------------------------------------------
# symbols
# Returns hash of all revisions keyed on symbol defined against file.
#------------------------------------------------------------------
sub symbols {
my $self = shift;
if(not defined $self->{SYMBOLS}) {
_parse_rcs_header($self);
}
return %{$self->{SYMBOLS}};
}
#------------------------------------------------------------------
# symrev
# Returns the revision against which a specified symbol was
# defined. If the symbol was not defined against any version
# of this file, 0 is returned.
#------------------------------------------------------------------
sub symrev {
my $self = shift;
my $sym = shift or croak "You must supply a symbol to symrev";;
if (not defined $self->{SYMBOLS}) {
_parse_rcs_header($self);
}
my %symbols = %{ $self->{SYMBOLS} };
my $revision = $symbols{$sym} ? $symbols{$sym} : 0;
my %matched_symbols = map { $_ => $symbols{$_} } grep(/$sym/, keys %symbols);
return wantarray ? %matched_symbols : $revision;
}
#------------------------------------------------------------------
# workdir
# Location of working directory.
#------------------------------------------------------------------
sub workdir {
my $self = shift;
# called as object method
if (ref $self) {
if (@_) { $self->{"_WORKDIR"} = shift }
return ref $self->{"_WORKDIR"} ? ${ $self->{"_WORKDIR"} } : $self->{"_WORKDIR"};
}
# called as class method
else {
if (@_) { $Work_Dir = shift }
return $Work_Dir;
}
}
#------------------------------------------------------------------
# _parse_rcs_body
# Private function
#------------------------------------------------------------------
sub _parse_rcs_body {
my $self = shift;
local $_;
my %comments;
my $rcsdir = $self->rcsdir;
my $file = $self->file;
my $rcs_file = $rcsdir . $Dir_Sep . $file . $self->arcext;
# parse RCS archive file
open RCS_FILE, $rcs_file
or return(_rcsError "Unable to open $rcs_file: $!");
# skip header info and get description
DESC: while (<RCS_FILE>) {
if (/^desc$/) {
$comments{0} = '';
$_ = <RCS_FILE>; # read first line
s/^\@//; # remove leading '@'
while (1) {
last DESC if /^\@$/;
s/\@\@/\@/g; # RCS replaces single '@' with '@@'
$comments{0} .= $_;
$_ = <RCS_FILE>;
}
}
}
# parse revision comments
my $revision;
REVISION: while (<RCS_FILE>) {
if (/^[\d\.]+$/) {
chomp($revision = $_);
$_ = <RCS_FILE>;
if (/^log$/) {
$comments{$revision} = '';
$_ = <RCS_FILE>; # read first line
s/^\@//; # remove leading '@'
while (1) {
next REVISION if /^\@$/;
s/\@\@/\@/g; # RCS replaces single '@' with '@@'
$comments{$revision} .= $_;
$_ = <RCS_FILE>;
}
}
}
}
# loop through 'text' section to avoid capturing bogus info
continue {
if (/^text$/) { # 'text' tag should always be there, but check anyway
$_ = <RCS_FILE>; # read first line
if (not /^\@\@$/) { # forced revisions have single '@@' in text section
while (<RCS_FILE>) {
s/\@\@//g; # RCS replaces single '@' with '@@'
last if /\@$/
}
}
}
}
close RCS_FILE;
$self->{COMMENTS} = \%comments;
}
#------------------------------------------------------------------
# _parse_rcs_header
# Private function
# Directly parse the RCS archive file.
#------------------------------------------------------------------
sub _parse_rcs_header {
my $self = shift;
local $_;
my ($head, %lock);
my (@access_list, @revisions);
my (%author, %date, %state, %symbols);
my $rcsdir = $self->rcsdir;
my $file = $self->file;
my $rcs_file = $rcsdir . $Dir_Sep . $file . $self->arcext;
# parse RCS archive file
open RCS_FILE, $rcs_file
or return(_rcsError "Unable to open $rcs_file: $!");
while (<RCS_FILE>) {
next if /^\s*$/; # skip blank lines
last if /^desc$/; # end of header info
# get head revision
if (/^head\s/) {
($head) = /^head\s+(.*?);$/;
next;
}
# get access list
if (/^access$/) {
while (<RCS_FILE>) {
chomp;
s/\s//g; # remove all whitespace
push @access_list, (split(/;/))[0];
last if /;$/;
}
next;
}
# get symbols
if (/^symbols$/) {
while (<RCS_FILE>) {
chomp;
s/\s//g; # remove all whitespace
my ($sym, $rev) = split(/:/);
$rev =~ s/;$//;
$symbols{$sym} = $rev;
last if /;$/;
}
next;
}
# get locker
if (/^locks/) {
# file not locked
if (/;$/) {
%lock = ();
next;
}
# get user who has file locked
while(<RCS_FILE>) {
s/\s+//g; # remove all white space
next unless $_ ; # skip blank line (now empty string)
last if /^;/; # end of locks
my ($locker, $rev) = split(/:/);
$rev =~ s/;.*//;
$lock{$rev} = $locker;
last if /;$/; # end of locks
}
next;
}
# get all revisions
if (/^\d+\.\d+/) {
chomp;
push @revisions, $_;
# get author, state and date of each revision
my $next_line = <RCS_FILE>;
chop(my $author = (split(/\s+/, $next_line))[3]);
chop(my $state = (split(/\s+/, $next_line))[5]);
chop(my $date = (split(/\s+/, $next_line))[1]);
# store date as date number
my ($year, $mon, $mday, $hour, $min, $sec) = split(/\./, $date);
$mon--; # convert to 0-11 range
my @date = ($sec,$min,$hour,$mday,$mon,$year);
# store value in hash using revision as key
$author{$_} = $author;
$state{$_} = $state;
$date{$_} = timegm(@date);
}
}
close RCS_FILE;
$self->{HEAD} = $head;
$self->{LOCK} = \%lock;
$self->{ACCESS} = \@access_list;
$self->{REVISIONS} = \@revisions;
$self->{AUTHOR} = \%author;
$self->{DATE} = \%date;
$self->{STATE} = \%state;
$self->{SYMBOLS} = \%symbols;
}
#------------------------------------------------------------------
# _rcsError
#------------------------------------------------------------------
sub _rcsError {
my $error_msg = shift;
not $nonFatal and croak $error_msg;
$nonFatal and not $Quiet and carp $error_msg and return 0;
$nonFatal and $Quiet and return 0;
}
1;
__END__
=head1 NAME
Rcs - Perl Object Class for Revision Control System (RCS).
=head1 SYNOPSIS
use Rcs;
# Use tags to control how the rcs programs handle errors
# and the use of the rcs -q (quiet) flag.
use Rcs qw(nonFatal Verbose);
The default behavior is to run rcs programs with the -q (quiet) flag,
and to die if any rcs program returns an error.
=head1 DESCRIPTION
This Perl module provides an object oriented interface to access
B<Revision Control System (RCS)> utilities. RCS must be installed on
the system prior to using this module. This module should simplify
the creation of an RCS front-end.
=head2 OBJECT CONSTRUCTOR
The B<new> method may be used as either a class method or an object
method to create a new object.
# called as class method
$obj = Rcs->new;
# called as object method
$newobj = $obj->new;
Note: You may now set the pathname of the working file through the object
constructor. This is the same as calling the pathname method after
calling the new method.
Thus
$obj = Rcs->new($pathname);
is the same as
$obj = Rcs->new;
$obj->pathname($pathname);
See B<pathname> method for additional details.
=head2 CLASS METHODS
Besides the object constructor, there are three class methods provided
which effect any newly created objects.
The B<arcext> method sets the RCS archive extension, which is ',v' by
default.
# set/unset RCS archive extension
Rcs->arcext(''); # set no archive extension
Rcs->arcext(',v'); # set archive extension to ',v'
$arc_ext = Rcs->arcext(); # get current archive extension
The B<bindir> method sets the directory path where the RCS executables
(i.e. rcs, ci, co) are located. The default location is '/usr/local/bin'.
# set RCS bin directory
Rcs->bindir('/usr/bin');
# access RCS bin directory
$bin_dir = Rcs->bindir;
The B<quiet> method sets/unsets the quiet mode for the RCS executables.
Quiet mode is set by default.
# set/unset RCS quiet mode
Rcs->quiet(0); # unset quiet mode
Rcs->quiet(1); # set quiet mode
# access RCS quiet mode
$quiet_mode = Rcs->quiet;
These methods may also be called as object methods.
$obj->arcext('');
$obj->bindir('/usr/bin');
$obj->quiet(0);
=head2 OBJECT ATTRIBUTE METHODS
These methods set the attributes of the RCS object.
The B<file> method is used to set the name of the RCS working file. The
filename must be set before invoking any access of modifier methods on the
object.
$obj->file('mr_anderson.pl');
The B<arcfile> method is used to set the name of the RCS archive file.
Using this method is optional, as the other methods will assume the archive
filename is the same as the working file unless specified otherwise. The
RCS archive extension (default ',v') is automatically added to the filename.
$obj->arcfile('principle_mcvicker.pl');
The B<workdir> methods set the path of the RCS working directory. If not
specified, default path is '.' (current working directory).
$obj->workdir('/usr/local/source');
The B<rcsdir> methods set the path of the RCS archive directory. If not
specified, default path is './RCS'.
$obj->rcsdir('/usr/local/archive');
The B<pathname> method will set both the working filename and archive
directory.
$obj->pathname($RCS_DIR . '/' . 'butthead.c');
and
$obj->pathname($RCS_DIR . '/' . 'butthead.c,v');
are the same as
$obj->rcsdir($RCS_DIR);
$obj->file('butthead.c');
=head2 RCS PARSE METHODS
This class provides methods to directly parse the RCS archive file.
The B<access> method returns a list of all user on the access list.
@access_list = $obj->access;
The B<author> method returns the author of the revision. The head revision
is used if no revision argument is passed to method.
# returns the author of revision '1.3'
$author = $obj->author('1.3');
# returns the authos of the head revision
$author = $obj->author;
The B<head> method returns the head revision.
$head = $obj->head;
The B<lock> method returns the locker of the revision. The method returns
null if the revision is unlocked. The head revision is used if no revision
argument is passed to method. When called in list context the lock method
returns a hash of all locks.
# returns locker of revision '1.3'
$locker = $obj->lock('1.3');
# returns locker of head revision
$locker = $obj->lock;
# return hash of all locks
%locks = $obj->lock; # called in list context
foreach $rev (keys %locks) {
$locker = $locks{$rev};
print "User $locker has revision $rev locked\n";
}
The B<revisions> method returns a list of all revisions of archive file.
@revisions = $obj->revisions;
The B<state> method returns the state of the revision. The head revision
is used if no revision argument is passed to method.
# returns state of revision '1.3'
$state = $obj->state('1.3');
# returns state of head revision
$state = $obj->state;
The B<symbol> method returns the symbol(s) associated with a revision.
If called in list context, method returns all symbols associated with
revision. If called in scalar context, method returns last symbol
assciated with a revision. The head revision is used if no revision argument
is passed to method.
# list context, returns all symbols associated with revision 1.3
@symbols = $obj->symbol('1.3');
# list context, returns all symbols associated with head revision
@symbols = $obj->symbol;
# scalar context, returns last symbol associated with revision 1.3
$symbol = $obj->symbol('1.3');
# scalar context, returns last symbol associated with head revision
$symbol = $obj->symbol;
The B<symbols> method returns a hash, keyed by symbol, of all of the revisions
associated with the file.
%symbols = $obj->symbols;
foreach $sym (keys %symbols) {
$rev = $symbols{$sym};
}
The B<revdate> method returns the date of a revision. The returned date format
is the same as the localtime format. When called as a scalar, it returns the
system date number. If called is list context, the list
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) is returned.
# scalar mode
$scalar_date = $obj->revdate;
print "Scalar date number = $scalar_date\n";
$date_str = localtime($scalar_date);
print "Scalar date string = $date_str\n";
# list mode
@list_date = $obj->revdate;
print "List date = @list_date\n";
The B<dates> method returns a hash of revision dates, keyed on revision. The
hash values are system date numbers. When called in scalar mode, the method
returns the most recent revision date.
# list mode
%DatesHash = obj->dates;
@dates_list = sort {$b<=>$a} values %DatesHash;
$MostRecent = $dates_list[0];
# scalar mode
$most_recent = $obj->dates;
print "Most recent date = $most_recent\n";
$most_recent_str = localtime($most_recent);
print "Most recent date string = $most_recent_str\n";
The B<symrev> method returns the revision against which a specified symbol was
defined. If the symbol was not defined against any version of this file, 0 is
returned.
# gets revision that has 'MY_SYMBOL' defined against it
$rev = $obj->symrev('MY_SYMBOL');
The B<daterev> method returns revisions which were created before a specified
date. Method may take one or six arguments. If one arguments is passed, then
the argument is a date number. If six arguments are passed, then they represent
a date string.
# one argument, date number
# gets revisions created before Sun Sep 6 22:23:47 1998
@revs = $obj->daterev(841436420);
# six argument
# gets revisions created before 25th June 1998 16:45:30
@revs = $obj->daterev(1998, 6, 25, 16, 45, 30);
The B<comments> method returns a hash of revision comments, keyed on revision.
A key value of 0 returns the description.
%comments = $obj->comments;
$description = $comments{0};
$comment_1_3 = $comments{'1.3'};
=head2 RCS SYSTEM METHODS
These methods invoke the RCS system utilities.
The B<ci> method calls the RCS ci program.
# check in, and then check out in unlocked state
$obj->ci('-u');
The B<co> method calls the RCS co program.
# check out in locked state
$obj->co('-l');
The B<rcs> method calls the RCS rcs program.
# lock file
$obj->rcs('-l');
The B<rcsdiff> method calls the RCS rcsdiff program. When called in
list context, this method returns the outpout of the rcsdiff program.
When called in scalar context, this method returns the return status of
the rcsdiff program. The return status is 0 for the same, 1 for some
differences, and 2 for error condition.
When called without parameters, rcsdiff does a diff between the current
working file, and the last revision checked in.
# call in list context
@diff_output = $obj->rcsdiff;
# call in scalar context
$changed = $obj->rcsdiff;
if ($changed) {
print "Working file has changed\n";
}
Call rcsdiff with parameters to do a diff between any two revisions.
@diff_output = $obj->rcsdiff('-r1.2', '-r1.1');
The B<rlog> method calls the RCS rlog program. This method returns the
output of the rlog program.
# get complete log output
@rlog_complete = $obj->rlog;
# called with '-h' switch outputs only header information
@rlog_header = $obj->rlog('-h');
print @rlog_header;
The B<rcsclean> method calls the RCS rcsclean program.
# remove working file
$obj->rcsclean;
=head1 EXAMPLES
=head2 CREATE ACCESS LIST
Using method B<rcs> with the B<-a> switch allows you to add users to
the access list of an RCS archive file.
use Rcs;
$obj = Rcs->new;
$obj->rcsdir("./project_tree/archive");
$obj->workdir("./project_tree/src");
$obj->file("cornholio.pl");
Methos B<rcs> invokes the RCS utility rcs with the same parameters.
@users = qw(beavis butthead);
$obj->rcs("-a@users");
Calling method B<access> returns list of users on access list.
$filename = $obj->file;
@access_list = $obj->access;
print "Users @access_list are on the access list of $filename\n";
=head2 PARSE RCS ARCHIVE FILE
Set class variables and create 'RCS' object.
Set bin directory where RCS programs (e.g. rcs, ci, co) reside. The
default is '/usr/local/bin'. This sets the bin directory for all objects.
use Rcs;
Rcs->bindir('/usr/bin');
$obj = Rcs->new;
Set information regarding RCS object. This information includes name of the
working file, directory of working file ('.' by default), and RCS archive
directory ('./RCS' by default).
$obj->rcsdir("./project_tree/archive");
$obj->workdir("./project_tree/src");
$obj->file("cornholio.pl");
$head_rev = $obj->head;
$locker = $obj->lock;
$author = $obj->author;
@access = $obj->access;
@revisions = $obj->revisions;
$filename = $obj->file;
if ($locker) {
print "Head revision $head_rev is locked by $locker\n";
}
else {
print "Head revision $head_rev is unlocked\n";
}
if (@access) {
print "\nThe following users are on the access list of file $filename\n";
map { print "User: $_\n"} @access;
}
print "\nList of all revisions of $filename\n";
foreach $rev (@revisions) {
print "Revision: $rev\n";
}
=head2 CHECK-IN FILE
Set class variables and create 'RCS' object.
Set bin directory where RCS programs (e.g. rcs, ci, co) reside. The
default is '/usr/local/bin'. This sets the bin directory for all objects.
use Rcs;
Rcs->bindir('/usr/bin');
Rcs->quiet(0); # turn off quiet mode
$obj = Rcs->new;
Set information regarding RCS object. This information includes name of
working file, directory of working file ('.' by default), and RCS archive
directory ('./RCS' by default).
$obj->file('cornholio.pl');
# Set RCS archive directory, is './RCS' by default
$obj->rcsdir("./project_tree/archive");
# Set working directory, is '.' by default
$obj->workdir("./project_tree/src");
Check in file using B<-u> switch. This will check in the file, and will then
check out the file in an unlocked state. The B<-m> switch is used to set the
revision comment.
Command:
$obj->ci('-u', '-mRevision Comment');
is equivalent to commands:
$obj->ci('-mRevision Comment');
$obj->co;
=head2 CHECK-OUT FILE
Set class variables and create 'RCS' object.
Set bin directory where RCS programs (e.g. rcs, ci, co) reside. The
default is '/usr/local/bin'. This sets the bin directory for all objects.
use Rcs;
Rcs->bindir('/usr/bin');
Rcs->quiet(0); # turn off quiet mode
$obj = Rcs->new;
Set information regarding RCS object. This information includes name of
working file, directory of working file ('.' by default), and RCS archive
directory ('./RCS' by default).
$obj->file('cornholio.pl');
# Set RCS archive directory, is './RCS' by default
$obj->rcsdir("./project_tree/archive");
# Set working directory, is '.' by default
$obj->workdir("./project_tree/src");
Check out file read-only:
$obj->co;
or check out and lock file:
$obj->co('-l');
=head2 RCSDIFF
Method B<rcsdiff> does an diff between revisions.
$obj = Rcs->new;
$obj->bindir('/usr/bin');
$obj->rcsdir("./project_tree/archive");
$obj->workdir("./project_tree/src");
$obj->file("cornholio.pl");
print "Diff of current working file\n";
if ($obj->rcsdiff) { # scalar context
print $obj->rcsdiff; # list context
}
else {
print "Versions are Equal\n";
}
print "\n\nDiff of revisions 1.2 and 1.1\n";
print $obj->rcsdiff('-r1.2', '-r1.1');
=head2 RCSCLEAN
Method B<rcsclean> will remove an unlocked working file.
use Rcs;
Rcs->bindir('/usr/bin');
Rcs->quiet(0); # turn off quiet mode
$obj = Rcs->new;
$obj->rcsdir("./project_tree/archive");
$obj->workdir("./project_tree/src");
$obj->file("cornholio.pl");
print "Quiet mode NOT set\n" unless Rcs->quiet;
$obj->rcsclean;
=head1 AUTHOR
Craig Freter, E<lt>F<craig@freter.com>E<gt>
=head1 CONTRIBUTORS
David Green, E<lt>F<greendjf@cvhp152.gpt.marconicomms.com>E<gt>
Jamie O'Shaughnessy, E<lt>F<jamie@thanatar.demon.co.uk>E<gt>
Raju Krishnamurthy, E<lt>F<raju_k@iname.com>E<gt>
=head1 COPYRIGHT
Copyright (C) 1997,2003 Craig Freter. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
|