summaryrefslogtreecommitdiff
path: root/cvslib.pl
blob: e809ea169cb56f9b3a710dd7a857ff6ab1a32261 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ident $Id: cvslib.pl,v 1.1 2009/11/06 10:27:49 lukeh Exp $

$CVSVERSIONDIR = $ENV{'CVSVERSIONDIR'};

$INFOFILE = $CVSVERSIONDIR ne "" ? $CVSVERSIONDIR."/CVSVersionInfo.txt" : "CVSVersionInfo.txt";

$DISTDIR = $ENV{'HOME'} . "/dist";

sub getSGSFile
{
	if (-f "version.h") { return "version.h"; }
	elsif (-f "vers.c") { return "vers.c"; }
	else { return; }
}

sub nameToTag
{
	local($tag) = shift;
	$tag =~ s/\./\~/g;
	return ($tag);
}

sub getCVSRepository
{
	if (!(-d "CVS"))
	{
		return;
	}

	open(ROOT, "CVS/Root") || return;
	open(REPOSITORY, "CVS/Repository") || return;
	local ($CVSROOT) = <ROOT>;
	chop ($CVSROOT);
	if ($CVSROOT =~ '^:') {
		local(@C) = split(/:/, $CVSROOT);
		$CVSROOT = $C[3];
	}
	local ($CVSREPOSITORY) = <REPOSITORY>;
	chop ($CVSREPOSITORY);
	close(ROOT);
	close(REPOSITORY);

	if ($CVSREPOSITORY =~ /^\//)
	{
		$CVSREPOSITORY =~ s/^$CVSROOT\///g;
	}
	return($CVSREPOSITORY);
}

sub getCVSVersionInfo
{
	local ($VERSION, $PROJECT);

	if (-f $INFOFILE)
	{
		open(INFOFILE, $INFOFILE) || return;
		while(<INFOFILE>)
		{
			if (/^#/) { next; }

			local ($key, $value) = split(/:\s+/);
			chop($value);

			if ($key eq "ProjectVersion")
			{
			        $VERSION = $value;
			}
			elsif ($key eq "ProjectName")
			{
			        $PROJECT = $value;
			}
		}
	}
	close(INFOFILE);
	return "$PROJECT-$VERSION";
}