diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:30 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:30 +0000 |
commit | c44379cc7d9c7aa113989237ab0f56db12aa5219 (patch) | |
tree | 66a84b20d47f2269d8bdc6e0323f338763424d3a /ACE/bin/ChangeLogEditor/ChangeLogEdit.pm | |
parent | 3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c (diff) | |
download | ATCD-c44379cc7d9c7aa113989237ab0f56db12aa5219.tar.gz |
Repo restructuring
Diffstat (limited to 'ACE/bin/ChangeLogEditor/ChangeLogEdit.pm')
-rw-r--r-- | ACE/bin/ChangeLogEditor/ChangeLogEdit.pm | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/ACE/bin/ChangeLogEditor/ChangeLogEdit.pm b/ACE/bin/ChangeLogEditor/ChangeLogEdit.pm new file mode 100644 index 00000000000..b7831ae2e5b --- /dev/null +++ b/ACE/bin/ChangeLogEditor/ChangeLogEdit.pm @@ -0,0 +1,121 @@ +package ChangeLogEdit; + +# ************************************************************ +# Description : Edit the existing ChangeLog. +# Author : Chad Elliott +# Create Date : 9/10/2002 +# ************************************************************ + +# ************************************************************ +# Pragmas +# ************************************************************ + +use strict; +use FileHandle; +use File::Copy; + +use ChangeLogEntry; + +# ************************************************************ +# Subroutine Section +# ************************************************************ + +sub new { + my($class) = shift; + my($name) = shift; + my($email) = shift; + my($self) = bless {'name' => $name, + 'email' => $email, + }, $class; + return $self; +} + + +sub edit { + my($self) = shift; + my($ofile) = shift; + my(@dirs) = @_; + my($tfile) = "$ofile.$<.$$"; + my($status) = 0; + my($error) = ''; + my($rh) = new FileHandle(); + my($unknown) = undef; + + if (open($rh, $ofile)) { + my($creator) = new ChangeLogEntry($self->{'name'}, + $self->{'email'}); + my($entry) = ''; + ($entry, $unknown) = $creator->create(@dirs); + if (defined $entry) { + if ($entry =~ /^ERROR:/) { + $error = $entry; + } + else { + my($oh) = new FileHandle(); + if (open($oh, ">$tfile")) { + $status = print $oh $entry; + if ($status) { + while(<$rh>) { + my($line) = $_; + $line =~ s/\s+$//; + if ($line =~ /\t/) { + $line = $self->convertTabs($line); + } + $status = print $oh "$line\n"; + if ($status == 0) { + $error = "Unable to copy $ofile"; + last; + } + } + } + else { + $error = 'Unable to print the first entry'; + } + close($oh); + } + else { + $error = "Unable to open $tfile for writing"; + } + close($rh); + + if ($status) { + $status = 0; + if (unlink($ofile)) { + if (rename($tfile, $ofile)) { + $status = 1; + } + else { + $error = "Unable to rename $tfile to $ofile"; + } + } + else { + $error = "Unable to remove $ofile"; + } + } + } + } + else { + $error = "Either there are no modified/removed files files or " . + "there is a revision\ncontrol system problem."; + } + } + else { + $error = "Unable to open $ofile for reading"; + } + + return $status, $error, $unknown; +} + + +sub convertTabs { + my($self) = shift; + my($line) = shift; + while($line =~ /\t/) { + my($spaces) = 8 - (index($line, "\t") % 8); + $line =~ s/\t/sprintf("%${spaces}s", ' ')/e; + } + return $line; +} + + +1; |