xref: /aosp_15_r20/external/expat/expat/conftools/get-version.sh (revision 6be67779651aebaf20f11e5663acd1ae59e93f66)
1#!/bin/sh
2# USAGE: get-version.sh path/to/expat.h
3#
4# This script will print Expat's version number on stdout. For example:
5#
6#   $ ./conftools/get-version.sh ./lib/expat.h
7#   1.95.3
8#                          __  __            _
9#                       ___\ \/ /_ __   __ _| |_
10#                      / _ \\  /| '_ \ / _` | __|
11#                     |  __//  \| |_) | (_| | |_
12#                      \___/_/\_\ .__/ \__,_|\__|
13#                               |_| XML parser
14#
15# Copyright (c) 2002 Greg Stein <[email protected]>
16# Copyright (c) 2017 Kerin Millar <[email protected]>
17# Licensed under the MIT license:
18#
19# Permission is  hereby granted,  free of charge,  to any  person obtaining
20# a  copy  of  this  software   and  associated  documentation  files  (the
21# "Software"),  to  deal in  the  Software  without restriction,  including
22# without  limitation the  rights  to use,  copy,  modify, merge,  publish,
23# distribute, sublicense, and/or sell copies of the Software, and to permit
24# persons  to whom  the Software  is  furnished to  do so,  subject to  the
25# following conditions:
26#
27# The above copyright  notice and this permission notice  shall be included
28# in all copies or substantial portions of the Software.
29#
30# THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
31# EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
32# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
33# NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34# DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
35# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
36# USE OR OTHER DEALINGS IN THE SOFTWARE.
37
38if test $# = 0; then
39  echo "ERROR: pathname for expat.h was not provided."
40  echo ""
41  echo "USAGE: $0 path/to/expat.h"
42  exit 1
43fi
44if test $# != 1; then
45  echo "ERROR: too many arguments were provided."
46  echo ""
47  echo "USAGE: $0 path/to/expat.h"
48  exit 1
49fi
50
51hdr="$1"
52if test ! -r "$hdr"; then
53  echo "ERROR: '$hdr' does not exist, or is not readable."
54  exit 1
55fi
56
57MAJOR_VERSION=$(sed -n -e '/MAJOR_VERSION/s/[^0-9]*//gp' "$hdr")
58MINOR_VERSION=$(sed -n -e '/MINOR_VERSION/s/[^0-9]*//gp' "$hdr")
59MICRO_VERSION=$(sed -n -e '/MICRO_VERSION/s/[^0-9]*//gp' "$hdr")
60
61printf '%s.%s.%s' "$MAJOR_VERSION" "$MINOR_VERSION" "$MICRO_VERSION"
62