summaryrefslogtreecommitdiffstats
path: root/bin/vervar
blob: ce907da70f6f30ed9534954962473cfac10fd1de (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
#!/usr/bin/awk -f
##
# Replaces version strings with the $pkgver variable or $_ver variable.
# If the ver field is the same as pkgver then ver is discarded (not printed)
# and version strings are replaced with $pkgver.
#
# The path and source fields are searched and replaced.

BEGIN {
	OFS = FS = "\n"
	RS = ""
	ORS = "\n\n"
	prog = "vervar"
	replflds["dir"] = replflds["source"] = 1
}

$1 == "ver" { ver = $2; next }
$1 == "pkgver" { pkgver = $2; next }
$1 in replflds {
	repl[$1] = $0
	next
}
1

END {
	if(error) {
		exit(error)
	}
	if(!ver){
		print prog ": error: ver field is missing (or zero)" | "cat 1>&2"
		exit(1)
	}

	if("" pkgver == ver){
		# Don't use the $_ver variable if $pkgver and $_ver are identical.
		skipver = 1
		vervar = "pkgver"
		ver = pkgver
	}else{
		# Print the $_ver variable if it is different
		print "ver", ver
		vervar = "_ver"
	}
	print "pkgver", pkgver

	# Replace the version string with the version parameter.
	gsub(/([.])/, "\\\\&", ver)
	for(f in repl){
		sub(ver, "$" vervar, repl[f])
		print repl[f]
	}
}