• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# USAGE: get-version.sh path/to/expat.h
4#
5# This script will print Expat's version number on stdout. For example:
6#
7#   $ ./conftools/get-version.sh ./lib/expat.h
8#   1.95.3
9#   $
10#
11
12if test $# = 0; then
13  echo "ERROR: pathname for expat.h was not provided."
14  echo ""
15  echo "USAGE: $0 path/to/expat.h"
16  exit 1
17fi
18if test $# != 1; then
19  echo "ERROR: too many arguments were provided."
20  echo ""
21  echo "USAGE: $0 path/to/expat.h"
22  exit 1
23fi
24
25hdr="$1"
26if test ! -r "$hdr"; then
27  echo "ERROR: '$hdr' does not exist, or is not readable."
28  exit 1
29fi
30
31MAJOR_VERSION=$(sed -n -e '/MAJOR_VERSION/s/[^0-9]*//gp' "$hdr")
32MINOR_VERSION=$(sed -n -e '/MINOR_VERSION/s/[^0-9]*//gp' "$hdr")
33MICRO_VERSION=$(sed -n -e '/MICRO_VERSION/s/[^0-9]*//gp' "$hdr")
34
35printf '%s.%s.%s' "$MAJOR_VERSION" "$MINOR_VERSION" "$MICRO_VERSION"
36