#! /usr/bin/env perl
#
# Andrew Janke - a.janke@gmail.com
# Simple script to dump history information from a minc file
#
# Thu Feb  3 14:00:26 EST 2000 - initial version
# Wed Oct 18 10:01:17 EST 2000 - rewrite and removed -clobber ommision
# Tue Dec  3 23:38:15 EST 2002 - rewritten to pretty-print entries <smr>
# Tue Dec  3 08:25:23 EST 2002 - shifted to CVS

my($n_columns) = 80;

use strict;
use warnings "all";
use Text::Format;
use File::Basename;

my($Usage, $me, $cmd_text, $text, $fname, $counter, @tmp, $c);

$me = &basename($0);
$Usage = "Usage: $me <file1.mnc> [<file2.mnc> ... ]\n\n";
die $Usage if ($#ARGV < 0);

# set up text objects
$text = new Text::Format( firstIndent => 0,
                          bodyIndent => 5,
                          columns => $n_columns );
$cmd_text = new Text::Format( firstIndent => 0,
                          bodyIndent => 5,
                          columns => ($n_columns - 2) );

# for each input file
foreach $fname (@ARGV){
   if(!-e $fname){
      warn "$me: Couldn't find $fname\n";
      next;
      }

   print STDOUT $text->format("--- History of $fname ---\n");

   $counter = 1;
   foreach (`mincinfo -attvalue :history $fname`){
      chomp;
      next if $_ eq '';
      
      # add the command number to the front
      $_ = sprintf("[%02d] ", $counter ++) . $_;
      
      # add \'s to the end of each line except the last
      @tmp = split(/\n/, $cmd_text->format($_));
      for($c=0; $c<$#tmp; $c++){
         print STDOUT "$tmp[$c] \\\n";
         }
      print STDOUT "$tmp[$#tmp]\n";
      }
   
   print STDOUT "\n";
   }

