#!/usr/bin/perl

use strict;

sub usage
	{
	print <<EOP;

	usage: get_define.pl <filename> <what_to_find>

	reads in the file, and if it sees

		#define what_to_find x

    prints out x.


EOP
	exit(0);
	}

sub main
	{
	my $version_file = shift;
	my $what_to_find = shift;

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

	usage() if(!$version_file or !$what_to_find);

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

		if($line =~ /^(#define) ([^ ]+) (.+)$/)
			{
			my $def = $1;
			my $name = $2;
			my $value = $3;

            if($name eq $what_to_find)
                {
                # strip off enclosing quotes
                if($value =~ /^\"(.*)\"$/)
                {
                    $value = $1;
                }
                print($value);
                exit(0);
                }
            }
				
		}

	close F;

    exit(0);
	}

main(@ARGV);

#end of file
