1#ident $Id: cvslib.pl,v 1.1 2009/11/06 10:27:49 lukeh Exp $
2
3$CVSVERSIONDIR = $ENV{'CVSVERSIONDIR'};
4
5$INFOFILE = $CVSVERSIONDIR ne "" ? $CVSVERSIONDIR."/CVSVersionInfo.txt" : "CVSVersionInfo.txt";
6
7$DISTDIR = $ENV{'HOME'} . "/dist";
8
9sub getSGSFile
10{
11	if (-f "version.h") { return "version.h"; }
12	elsif (-f "vers.c") { return "vers.c"; }
13	else { return; }
14}
15
16sub nameToTag
17{
18	local($tag) = shift;
19	$tag =~ s/\./\~/g;
20	return ($tag);
21}
22
23sub getCVSRepository
24{
25	if (!(-d "CVS"))
26	{
27		return;
28	}
29
30	open(ROOT, "CVS/Root") || return;
31	open(REPOSITORY, "CVS/Repository") || return;
32	local ($CVSROOT) = <ROOT>;
33	chop ($CVSROOT);
34	if ($CVSROOT =~ '^:') {
35		local(@C) = split(/:/, $CVSROOT);
36		$CVSROOT = $C[3];
37	}
38	local ($CVSREPOSITORY) = <REPOSITORY>;
39	chop ($CVSREPOSITORY);
40	close(ROOT);
41	close(REPOSITORY);
42
43	if ($CVSREPOSITORY =~ /^\//)
44	{
45		$CVSREPOSITORY =~ s/^$CVSROOT\///g;
46	}
47	return($CVSREPOSITORY);
48}
49
50sub getCVSVersionInfo
51{
52	local ($VERSION, $PROJECT);
53
54	if (-f $INFOFILE)
55	{
56		open(INFOFILE, $INFOFILE) || return;
57		while(<INFOFILE>)
58		{
59			if (/^#/) { next; }
60
61			local ($key, $value) = split(/:\s+/);
62			chop($value);
63
64			if ($key eq "ProjectVersion")
65			{
66			        $VERSION = $value;
67			}
68			elsif ($key eq "ProjectName")
69			{
70			        $PROJECT = $value;
71			}
72		}
73	}
74	close(INFOFILE);
75	return "$PROJECT-$VERSION";
76}
77
78