#!/usr/bin/perl
################################################################################
##
##    Copyright 2001 Sistina Software, Inc.
##
##    This is free software released under the GNU General Public License.
##    There is no warranty for this software.  See the file COPYING for
##    details.
##
##    See the file CONTRIBUTORS for a list of contributors.
##
##    This file is maintained by:
##      AJ Lewis <lewis@sistina.com>
## 
##    File name: lvmver
##
##    Description: outputs the version of lvm in the src directory specified 
##                 to stdout
################################################################################

use Getopt::Std;

getopt('d');

$lvm_src = $opt_d;

# help message
if(defined($opt_h) || !defined($opt_d)) {
  $msg = "usage: $0 [OPTIONS]\n";
  $msg = $msg . "\t-d\tLVM src directory\n";
  $msg = $msg . "\t-h\tDisplay this help message\n";
  die $msg;
}

    # if there was an argument to linuxver, use it as the linux source directory
    if ($lvm_src) {
      $file = $lvm_src . '/tools/lib/lvm.h';
    }
    # otherwise, use the default 
    #else {
      #$file = '/usr/src/linux/Makefile';
      
    #}
      

    open(DATAFILE, "< $file") || die "platform: can't open $file\n";
    while ($line = <DATAFILE>)
    {
	if ($line =~ /_LVM.*H_VERSION\s*\"\s*LVM\s*([\w\d.]+).*/)
  	{
	    	$version = $1;
		#print "version = $version\n";
		#$major = ($version ~ s/(VERSION)(\s)*(=)(\s)*(\d)/$5/);
  	}
    }

    close(DATAFILE);

    die "linuxver can't determine Linux version\n" unless (defined($version));

print "$version\n";

