crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs

e-ver (1669B)


      1 #!/usr/bin/perl
      2 
      3 use strict;
      4 use Getopt::Std;
      5 
      6 # ChangeLog
      7 # 1.03  Revamp to Perl. Support for RPM's spec files.
      8 # 1.02	-V shows more info.
      9 # 1.01	-V flag implemented
     10 # 1.00	First version
     11 
     12 my $VER=1.03;
     13 my %opts;
     14 
     15 # Show usage and stop.
     16 sub usage () {
     17     die ("\n",
     18 	 "Copyright (c) e-tunity 2000 ff. All rights reserved.\n",
     19 	 "Contact e-tunity <info\@e-tunity.com> for more info.\n",
     20 	 "Usage: e-ver file(s) VERSION\n",
     21 	 "The files are checked for ChangeLog-style entries or RPM-style\n",
     22 	 "entries. The stated versions must match VERSION.\n\n");
     23 }
     24 
     25 # Check a version in a file.
     26 sub checkversion ($$) {
     27     my $f = shift;
     28     my $v = shift;
     29 
     30     open (IF, $f) or die ("e-ver: cannot read $f: $!\n");
     31     while (<IF>) {
     32 	chomp ();
     33 	if (/^[0-9]/) {
     34 	    # ChangeLog style entry.
     35 	    my $curver = sprintf ("%g", $_);
     36 	    die ("e-ver: ChangeLog-style version $curver is not the\n",
     37 		 "       required $v. You should probably update $f\n")
     38 		if ($curver != $v);
     39 	    close (IF);
     40 	    return;
     41 	}
     42 
     43 	if (/^Version: */) {
     44 	    s/^Version: *//;
     45 	    my $curver = sprintf ("%g", $_);
     46 	    die ("e-ver: RPM-spec style version $curver is not the\n",
     47 		 "       required $v. You should probably update $f.\n")
     48 		if ($curver != $v);
     49 	    close (IF);
     50 	    return;
     51 	}
     52     }
     53 
     54     close (IF);
     55     die ("e-ver: failed to find version ID in $f, cannot check\n");
     56 }
     57 
     58 # Main starts here.
     59 usage() unless (getopts ("V", \%opts));
     60 if ($opts{V}) {
     61     print ("$VER Version ID Checker\n");
     62     exit (0);
     63 }
     64 usage() if ($#ARGV < 1);
     65 
     66 my $version_to_check = pop (@ARGV);
     67 foreach my $f (@ARGV) {
     68     die ("e-ver: no such file $f\n") unless (-f $f);
     69     checkversion ($f, $version_to_check);
     70 }