File: getver.sh

package info (click to toggle)
libgd2 2.3.3-13
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,396 kB
  • sloc: ansic: 49,708; sh: 5,660; javascript: 1,859; cpp: 1,308; makefile: 345; perl: 197; tcl: 45
file content (48 lines) | stat: -rwxr-xr-x 994 bytes parent folder | download | duplicates (2)
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
#!/bin/sh

# Simple script to extract the version number parts from src/gd.h.  If
# called with the middle word of the version macro, it prints the
# value of that macro.  If called with no argument, it outputs a
# human-readable version string.  This must be run in the project
# root.  It is used by configure.ac and docs/naturaldocs/run_docs.sh.

TOPDIR="${0%/*}/.."
HEADER="${TOPDIR}/src/gd.h"
SENTINEL="/*version605b5d1778*/"

getpart() {
	awk -v field="GD_${1}_VERSION" -v sentinel="${SENTINEL}" '
		$1 == "#define" && $2 == field && $NF == sentinel {
			gsub(/^"/, "", $3)
			gsub(/"$/, "", $3)
			print $3
		}
	' "${HEADER}"
}

case $# in
0)
	printf '%s.%s.%s%s\n' \
		"$(getpart MAJOR)" \
		"$(getpart MINOR)" \
		"$(getpart RELEASE)" \
		"$(getpart EXTRA)"
	;;
1)
	case $1 in
	MAJOR|MINOR|RELEASE|EXTRA)
		part=$(getpart "$1")
		if [ -n "${part}" ]; then
			printf '%s' "${part}"
		fi
		;;
	*)
		exit 1
		;;
	esac
	;;
*)
	echo "$0: error: script takes at most 1 arg"
	exit 1
	;;
esac