#!/usr/bin/perl

# ex:set tabstop=3:
# ex:set expandtab:
use strict;

sub usage
{
   print <<EOP;

   usage: bump_version.pl <filename>

   reads in the file, and if it sees

      BUILD_NUMBER = "<number>";

   changes it to

      BUILD_NUMBER = "<number+1>";

   also, always puts in a string for

      BUILD_DATE = "2003.03.07.20:34:02";

EOP
   exit(0);
}

sub date_time
{
   my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());

   return sprintf("%04d.%02d.%02d-%02d:%02d:%02d",
                $year + 1900,
                $mon + 1,
                $mday,
                $hour,
                $min,
                $sec);
}


sub main
{
   my $version_file = shift;

   my $have_rcs = (-d "RCS");
   my $have_svn = (-d ".svn");

   usage() if(!$version_file);

   print ".\n";
   print ".\n";

   system("co -l -q -f $version_file") if $have_rcs;

   open F,$version_file or die "could not read $version_file";

   my $line;
   my $file;

   my $pluginMajorVersion;
   my $pluginMinorVersion;


   while($line = <F>)
   {
      if($line =~ /^(.*?)[\n\r]*$/)
      {
         $line = $1;
      }

      if($line =~ /^([A-Z_]+) = (.*);$/)
      {
         my $name = $1;
         my $value = $2;
         my $oValue = $value;

         if($name eq "BUILD_NUMBER")
         {
            $value++;
         }
         elsif($name eq "BUILD_DATE")
         {
            $value = "\"" . date_time() . "\"";
         }
         if($oValue ne $value)
         {
            print "setting $name from $oValue to $value\n";
            $line = "$name = $value;";
         }
      }

      $file .= $line . "\n";
   }

   close F;
   open F,">$version_file" or die "could not write $version_file";
   print F $file;
   close F;

   print ".\n";
   print ".\n";
}

main(@ARGV);

#end of file
